mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-12-22 19:30:05 +00:00
Merge pull request #46 from dongresource/mobs2
Populated the future with scraped mobs
This commit is contained in:
commit
c9badae526
@ -18,7 +18,8 @@ randomcharacters=true
|
||||
port=8002
|
||||
ip=127.0.0.1
|
||||
# distance at which other players and NPCs become visible
|
||||
view=20000
|
||||
playerdistance=20000
|
||||
npcdistance=16000
|
||||
# little message players see when they enter the game
|
||||
motd=Welcome to OpenFusion!
|
||||
# NPC json data
|
||||
@ -30,6 +31,6 @@ gm=true
|
||||
|
||||
# spawn coordinates (Z is height)
|
||||
# the supplied defaults are at City Hall
|
||||
spawnx=179213
|
||||
spawny=268451
|
||||
spawnz=-4210
|
||||
spawnx=632032
|
||||
spawny=187177
|
||||
spawnz=-5500
|
||||
|
19
src/NPC.hpp
19
src/NPC.hpp
@ -1,5 +1,4 @@
|
||||
#ifndef _NPCCLASS_HPP
|
||||
#define _NPCCLASS_HPP
|
||||
#pragma once
|
||||
|
||||
#include "CNStructs.hpp"
|
||||
|
||||
@ -21,6 +20,18 @@ public:
|
||||
// hopefully no collisions happen :eyes:
|
||||
appearanceData.iNPC_ID = (int32_t)rand();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
BaseNPC(int x, int y, int z, int type, int hp, int cond, int angle, int barker) {
|
||||
appearanceData.iX = x;
|
||||
appearanceData.iY = y;
|
||||
appearanceData.iZ = z;
|
||||
appearanceData.iNPCType = type;
|
||||
appearanceData.iHP = hp;
|
||||
appearanceData.iAngle = angle;
|
||||
appearanceData.iConditionBitFlag = cond;
|
||||
appearanceData.iBarkerType = barker;
|
||||
|
||||
// hopefully no collisions happen :eyes:
|
||||
appearanceData.iNPC_ID = (int32_t)rand();
|
||||
}
|
||||
};
|
||||
|
@ -31,11 +31,30 @@ void NPCManager::init() {
|
||||
RespawnPoints.push_back({npc.value()["x"], npc.value()["y"], ((int)npc.value()["z"]) + RESURRECT_HEIGHT});
|
||||
}
|
||||
|
||||
std::cout << "[INFO] populated " << NPCs.size() << " NPCs" << std::endl;
|
||||
} catch (const std::exception& err) {
|
||||
std::cerr << "[WARN] Malformed NPCs.json file! Reason:" << err.what() << std::endl;
|
||||
}
|
||||
|
||||
// load temporary mob dump
|
||||
try {
|
||||
std::ifstream inFile("mobs.json"); // not in settings, since it's temp
|
||||
nlohmann::json npcData;
|
||||
|
||||
// read file into json
|
||||
inFile >> npcData;
|
||||
|
||||
for (nlohmann::json::iterator npc = npcData.begin(); npc != npcData.end(); npc++) {
|
||||
BaseNPC tmp(npc.value()["iX"], npc.value()["iY"], npc.value()["iZ"], npc.value()["iNPCType"],
|
||||
npc.value()["iHP"], npc.value()["iConditionBitFlag"], npc.value()["iAngle"], npc.value()["iBarkerType"]);
|
||||
|
||||
NPCs[tmp.appearanceData.iNPC_ID] = tmp;
|
||||
}
|
||||
|
||||
std::cout << "[INFO] populated " << NPCs.size() << " NPCs" << std::endl;
|
||||
} catch (const std::exception& err) {
|
||||
std::cerr << "[WARN] Malformed mobs.json file! Reason:" << err.what() << std::endl;
|
||||
}
|
||||
|
||||
try {
|
||||
std::ifstream infile(settings::WARPJSON);
|
||||
nlohmann::json warpData;
|
||||
@ -67,7 +86,7 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
|
||||
int diffX = abs(view.plr->x - pair.second.appearanceData.iX);
|
||||
int diffY = abs(view.plr->y - pair.second.appearanceData.iY);
|
||||
|
||||
if (diffX < settings::VIEWDISTANCE && diffY < settings::VIEWDISTANCE) {
|
||||
if (diffX < settings::NPCDISTANCE && diffY < settings::NPCDISTANCE) {
|
||||
yesView.push_back(pair.first);
|
||||
} else {
|
||||
noView.push_back(pair.first);
|
||||
@ -81,10 +100,10 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
|
||||
|
||||
if (std::find(noView.begin(), noView.end(), id) != noView.end()) {
|
||||
// it shouldn't be visible, send NPC_EXIT
|
||||
|
||||
|
||||
exitData.iNPC_ID = id;
|
||||
sock->sendPacket((void*)&exitData, P_FE2CL_NPC_EXIT, sizeof(sP_FE2CL_NPC_EXIT));
|
||||
|
||||
|
||||
// remove from view
|
||||
view.viewableNPCs.erase(i++);
|
||||
}
|
||||
@ -99,7 +118,7 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
|
||||
|
||||
enterData.NPCAppearanceData = NPCs[id].appearanceData;
|
||||
sock->sendPacket((void*)&enterData, P_FE2CL_NPC_ENTER, sizeof(sP_FE2CL_NPC_ENTER));
|
||||
|
||||
|
||||
// add to viewable
|
||||
view.viewableNPCs.push_back(id);
|
||||
}
|
||||
@ -128,7 +147,7 @@ void NPCManager::npcWarpHandler(CNSocket* sock, CNPacketData* data) {
|
||||
// force player & NPC reload
|
||||
plrv.viewable.clear();
|
||||
plrv.viewableNPCs.clear();
|
||||
|
||||
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC));
|
||||
|
||||
}
|
||||
@ -142,7 +161,7 @@ void NPCManager::npcSummonHandler(CNSocket *sock, CNPacketData *data) {
|
||||
Player *plr = PlayerManager::getPlayer(sock);
|
||||
|
||||
// permission & sanity check
|
||||
if (!plr->IsGM || req->iNPCType >= NPCs.size())
|
||||
if (!plr->IsGM || req->iNPCType >= 3314)
|
||||
return;
|
||||
|
||||
resp.NPCAppearanceData.iNPC_ID = rand(); // cpunch-style
|
||||
|
@ -85,7 +85,7 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) {
|
||||
int diffX = abs(pair.second.plr->x - X); // the map is like a grid, X and Y are your position on the map, Z is the height. very different from other games...
|
||||
int diffY = abs(pair.second.plr->y - Y);
|
||||
|
||||
if (diffX < settings::VIEWDISTANCE && diffY < settings::VIEWDISTANCE) {
|
||||
if (diffX < settings::PLAYERDISTANCE && diffY < settings::PLAYERDISTANCE) {
|
||||
yesView.push_back(pair.first);
|
||||
}
|
||||
else {
|
||||
@ -203,6 +203,7 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) {
|
||||
response.PCLoadData2CL.iX = plr.x;
|
||||
response.PCLoadData2CL.iY = plr.y;
|
||||
response.PCLoadData2CL.iZ = plr.z;
|
||||
response.PCLoadData2CL.iAngle = 130;
|
||||
response.PCLoadData2CL.iActiveNanoSlotNum = -1;
|
||||
response.PCLoadData2CL.iFatigue = 50;
|
||||
response.PCLoadData2CL.PCStyle = plr.PCStyle;
|
||||
|
@ -10,7 +10,8 @@ bool settings::LOGINRANDCHARACTERS = false;
|
||||
|
||||
int settings::SHARDPORT = 8002;
|
||||
std::string settings::SHARDSERVERIP = "127.0.0.1";
|
||||
int settings::VIEWDISTANCE = 20000;
|
||||
int settings::PLAYERDISTANCE = 20000;
|
||||
int settings::NPCDISTANCE = 16000;
|
||||
|
||||
// default spawn point is city hall
|
||||
int settings::SPAWN_X = 179213;
|
||||
@ -39,7 +40,8 @@ void settings::init() {
|
||||
LOGINRANDCHARACTERS = reader.GetBoolean("login", "randomcharacters", LOGINRANDCHARACTERS);
|
||||
SHARDPORT = reader.GetInteger("shard", "port", SHARDPORT);
|
||||
SHARDSERVERIP = reader.Get("shard", "ip", "127.0.0.1");
|
||||
VIEWDISTANCE = reader.GetInteger("shard", "view", VIEWDISTANCE);
|
||||
PLAYERDISTANCE = reader.GetInteger("shard", "playerdistance", PLAYERDISTANCE);
|
||||
NPCDISTANCE = reader.GetInteger("shard", "npcdistance", NPCDISTANCE);
|
||||
SPAWN_X = reader.GetInteger("shard", "spawnx", SPAWN_X);
|
||||
SPAWN_Y = reader.GetInteger("shard", "spawny", SPAWN_Y);
|
||||
SPAWN_Z = reader.GetInteger("shard", "spawnz", SPAWN_Z);
|
||||
|
@ -6,7 +6,8 @@ namespace settings {
|
||||
extern bool LOGINRANDCHARACTERS;
|
||||
extern int SHARDPORT;
|
||||
extern std::string SHARDSERVERIP;
|
||||
extern int VIEWDISTANCE;
|
||||
extern int PLAYERDISTANCE;
|
||||
extern int NPCDISTANCE;
|
||||
extern int SPAWN_X;
|
||||
extern int SPAWN_Y;
|
||||
extern int SPAWN_Z;
|
||||
|
Loading…
Reference in New Issue
Block a user