mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 21:40:05 +00:00
Instance Stuff
custom instance commands warping takes you into instances npcs show up only in the instance they are supposed to be inside.
This commit is contained in:
parent
5a80c53e79
commit
bd34bb294c
@ -177,6 +177,12 @@ void NPCManager::updateNPCPosition(int32_t id, int X, int Y, int Z) {
|
|||||||
npc->currentChunks = allChunks;
|
npc->currentChunks = allChunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NPCManager::updateNPCInstance(int32_t npcID, int instanceID) {
|
||||||
|
BaseNPC* npc = NPCs[npcID];
|
||||||
|
npc->instanceID = instanceID;
|
||||||
|
updateNPCPosition(npcID, npc->appearanceData.iX, npc->appearanceData.iY, npc->appearanceData.iZ);
|
||||||
|
}
|
||||||
|
|
||||||
void NPCManager::sendToViewable(BaseNPC *npc, void *buf, uint32_t type, size_t size) {
|
void NPCManager::sendToViewable(BaseNPC *npc, void *buf, uint32_t type, size_t size) {
|
||||||
for (Chunk *chunk : npc->currentChunks) {
|
for (Chunk *chunk : npc->currentChunks) {
|
||||||
for (CNSocket *s : chunk->players) {
|
for (CNSocket *s : chunk->players) {
|
||||||
@ -577,26 +583,29 @@ void NPCManager::npcWarpTimeMachine(CNSocket* sock, CNPacketData* data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NPCManager::handleWarp(CNSocket* sock, int32_t warpId) {
|
void NPCManager::handleWarp(CNSocket* sock, int32_t warpId) {
|
||||||
|
PlayerView& plrv = PlayerManager::players[sock];
|
||||||
// sanity check
|
// sanity check
|
||||||
if (Warps.find(warpId) == Warps.end())
|
if (Warps.find(warpId) == Warps.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PlayerView& plrv = PlayerManager::players[sock];
|
// std::cerr << "Warped to Map Num:" << Warps[warpId].instanceID << " NPC ID " << Warps[warpId].npcID << std::endl;
|
||||||
|
if (Warps[warpId].isInstance)
|
||||||
// send to client
|
{
|
||||||
INITSTRUCT(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC, resp);
|
PlayerManager::sendPlayerTo(sock, Warps[warpId].x, Warps[warpId].y, Warps[warpId].z, Warps[warpId].instanceID);
|
||||||
resp.iX = Warps[warpId].x;
|
}
|
||||||
resp.iY = Warps[warpId].y;
|
else
|
||||||
resp.iZ = Warps[warpId].z;
|
{
|
||||||
resp.iCandy = plrv.plr->money;
|
INITSTRUCT(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC, resp); //Can only be used for exiting instances because it sets the instance flag to false
|
||||||
resp.eIL = 4; // do not take away any items
|
resp.iX = Warps[warpId].x;
|
||||||
|
resp.iY = Warps[warpId].y;
|
||||||
// force player & NPC reload
|
resp.iZ = Warps[warpId].z;
|
||||||
PlayerManager::removePlayerFromChunks(plrv.currentChunks, sock);
|
resp.iCandy = plrv.plr->money;
|
||||||
plrv.currentChunks.clear();
|
resp.eIL = 4; // do not take away any items
|
||||||
plrv.chunkPos = std::make_tuple(0, 0, plrv.plr->instanceID);
|
PlayerManager::removePlayerFromChunks(plrv.currentChunks, sock);
|
||||||
|
plrv.currentChunks.clear();
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC));
|
plrv.plr->instanceID = 0;
|
||||||
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
// this should really be called vec3 or something...
|
// this should really be called vec3 or something...
|
||||||
struct WarpLocation {
|
struct WarpLocation {
|
||||||
int x, y, z;
|
int x, y, z, instanceID, isInstance, limitTaskID, npcID;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace NPCManager {
|
namespace NPCManager {
|
||||||
@ -29,6 +29,7 @@ namespace NPCManager {
|
|||||||
void destroyNPC(int32_t);
|
void destroyNPC(int32_t);
|
||||||
void updateNPCPosition(int32_t, int X, int Y, int Z, int angle);
|
void updateNPCPosition(int32_t, int X, int Y, int Z, int angle);
|
||||||
void updateNPCPosition(int32_t, int X, int Y, int Z);
|
void updateNPCPosition(int32_t, int X, int Y, int Z);
|
||||||
|
void updateNPCInstance(int32_t, int instanceID);
|
||||||
|
|
||||||
void sendToViewable(BaseNPC* npc, void* buf, uint32_t type, size_t size);
|
void sendToViewable(BaseNPC* npc, void* buf, uint32_t type, size_t size);
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ void PlayerManager::addPlayer(CNSocket* key, Player plr) {
|
|||||||
memcpy(p, &plr, sizeof(Player));
|
memcpy(p, &plr, sizeof(Player));
|
||||||
|
|
||||||
players[key] = PlayerView();
|
players[key] = PlayerView();
|
||||||
players[key].chunkPos = std::make_tuple(0, 0, p->instanceID);
|
players[key].chunkPos = std::make_tuple(0, 0, 0);
|
||||||
players[key].currentChunks = std::vector<Chunk*>();
|
players[key].currentChunks = std::vector<Chunk*>();
|
||||||
players[key].plr = p;
|
players[key].plr = p;
|
||||||
players[key].lastHeartbeat = 0;
|
players[key].lastHeartbeat = 0;
|
||||||
@ -191,10 +191,10 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) {
|
|||||||
view.plr->x = X;
|
view.plr->x = X;
|
||||||
view.plr->y = Y;
|
view.plr->y = Y;
|
||||||
view.plr->z = Z;
|
view.plr->z = Z;
|
||||||
updatePlayerChunk(sock, X, Y);
|
updatePlayerChunk(sock, X, Y, view.plr->instanceID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerManager::updatePlayerChunk(CNSocket* sock, int X, int Y) {
|
void PlayerManager::updatePlayerChunk(CNSocket* sock, int X, int Y,int mapNum) {
|
||||||
PlayerView& view = players[sock];
|
PlayerView& view = players[sock];
|
||||||
std::tuple<int, int, int> newPos = ChunkManager::grabChunk(X, Y, view.plr->instanceID);
|
std::tuple<int, int, int> newPos = ChunkManager::grabChunk(X, Y, view.plr->instanceID);
|
||||||
|
|
||||||
@ -223,8 +223,27 @@ void PlayerManager::updatePlayerChunk(CNSocket* sock, int X, int Y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PlayerManager::sendPlayerTo(CNSocket* sock, int X, int Y, int Z, int I) {
|
void PlayerManager::sendPlayerTo(CNSocket* sock, int X, int Y, int Z, int I) {
|
||||||
getPlayer(sock)->instanceID = I;
|
PlayerView& plrv = PlayerManager::players[sock];
|
||||||
sendPlayerTo(sock, X, Y, Z);
|
Player* plr = plrv.plr;
|
||||||
|
plr->instanceID = I;
|
||||||
|
if (I != INSTANCE_OVERWORLD) {
|
||||||
|
INITSTRUCT(sP_FE2CL_INSTANCE_MAP_INFO, pkt);
|
||||||
|
pkt.iInstanceMapNum = I;
|
||||||
|
sock->sendPacket((void*)&pkt, P_FE2CL_INSTANCE_MAP_INFO, sizeof(sP_FE2CL_INSTANCE_MAP_INFO));
|
||||||
|
sendPlayerTo(sock, X, Y, Z);
|
||||||
|
} else {
|
||||||
|
// annoying but necessary to set the flag back
|
||||||
|
INITSTRUCT(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC, resp);
|
||||||
|
resp.iX = X;
|
||||||
|
resp.iY = Y;
|
||||||
|
resp.iZ = Z;
|
||||||
|
resp.iCandy = plrv.plr->money;
|
||||||
|
resp.eIL = 4; // do not take away any items
|
||||||
|
PlayerManager::removePlayerFromChunks(plrv.currentChunks, sock);
|
||||||
|
plrv.currentChunks.clear();
|
||||||
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerManager::sendPlayerTo(CNSocket* sock, int X, int Y, int Z) {
|
void PlayerManager::sendPlayerTo(CNSocket* sock, int X, int Y, int Z) {
|
||||||
|
@ -32,7 +32,7 @@ namespace PlayerManager {
|
|||||||
|
|
||||||
void updatePlayerPosition(CNSocket* sock, int X, int Y, int Z);
|
void updatePlayerPosition(CNSocket* sock, int X, int Y, int Z);
|
||||||
void updatePlayerPosition(CNSocket* sock, int X, int Y, int Z, int angle);
|
void updatePlayerPosition(CNSocket* sock, int X, int Y, int Z, int angle);
|
||||||
void updatePlayerChunk(CNSocket* sock, int X, int Y);
|
void updatePlayerChunk(CNSocket* sock, int X, int Y, int instanceID);
|
||||||
|
|
||||||
void sendPlayerTo(CNSocket* sock, int X, int Y, int Z, int I);
|
void sendPlayerTo(CNSocket* sock, int X, int Y, int Z, int I);
|
||||||
void sendPlayerTo(CNSocket* sock, int X, int Y, int Z);
|
void sendPlayerTo(CNSocket* sock, int X, int Y, int Z);
|
||||||
|
@ -23,11 +23,19 @@ void TableData::init() {
|
|||||||
try {
|
try {
|
||||||
std::ifstream inFile(settings::NPCJSON);
|
std::ifstream inFile(settings::NPCJSON);
|
||||||
nlohmann::json npcData;
|
nlohmann::json npcData;
|
||||||
|
nlohmann::json nullExample;
|
||||||
|
|
||||||
// read file into json
|
// read file into json
|
||||||
inFile >> npcData;
|
inFile >> npcData;
|
||||||
|
int null = 0;
|
||||||
for (nlohmann::json::iterator _npc = npcData.begin(); _npc != npcData.end(); _npc++) {
|
for (nlohmann::json::iterator _npc = npcData.begin(); _npc != npcData.end(); _npc++) {
|
||||||
|
if (npcData[_npc.key()]["mapNum"] == nullExample)
|
||||||
|
{
|
||||||
|
npcData[_npc.key()]["mapNum"] = 0;
|
||||||
|
_npc.value()["mapNum"] = 0;
|
||||||
|
null = 1;
|
||||||
|
//return;
|
||||||
|
}
|
||||||
auto npc = _npc.value();
|
auto npc = _npc.value();
|
||||||
BaseNPC *tmp = new BaseNPC(npc["x"], npc["y"], npc["z"], npc["angle"], INSTANCE_OVERWORLD, npc["id"], nextId);
|
BaseNPC *tmp = new BaseNPC(npc["x"], npc["y"], npc["z"], npc["angle"], INSTANCE_OVERWORLD, npc["id"], nextId);
|
||||||
|
|
||||||
@ -38,7 +46,13 @@ void TableData::init() {
|
|||||||
if (npc["id"] == 641 || npc["id"] == 642)
|
if (npc["id"] == 641 || npc["id"] == 642)
|
||||||
NPCManager::RespawnPoints.push_back({ npc["x"], npc["y"], ((int)npc["z"]) + RESURRECT_HEIGHT });
|
NPCManager::RespawnPoints.push_back({ npc["x"], npc["y"], ((int)npc["z"]) + RESURRECT_HEIGHT });
|
||||||
}
|
}
|
||||||
|
if (null == 1)
|
||||||
|
{
|
||||||
|
std::cout << "Updated Json to include Map Num" << std::endl;
|
||||||
|
std::ofstream outFile(settings::NPCJSON);
|
||||||
|
outFile << npcData << std::endl;
|
||||||
|
outFile.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& err) {
|
catch (const std::exception& err) {
|
||||||
std::cerr << "[WARN] Malformed NPCs.json file! Reason:" << err.what() << std::endl;
|
std::cerr << "[WARN] Malformed NPCs.json file! Reason:" << err.what() << std::endl;
|
||||||
@ -61,7 +75,7 @@ void TableData::init() {
|
|||||||
|
|
||||||
for (nlohmann::json::iterator _warp = warpData.begin(); _warp != warpData.end(); _warp++) {
|
for (nlohmann::json::iterator _warp = warpData.begin(); _warp != warpData.end(); _warp++) {
|
||||||
auto warp = _warp.value();
|
auto warp = _warp.value();
|
||||||
WarpLocation warpLoc = { warp["m_iToX"], warp["m_iToY"], warp["m_iToZ"] };
|
WarpLocation warpLoc = { warp["m_iToX"], warp["m_iToY"], warp["m_iToZ"],warp["m_iToMapNum"],warp["m_iIsInstance"],warp["m_iLimit_TaskID"],warp["m_iNpcNumber"] };
|
||||||
int warpID = warp["m_iWarpNumber"];
|
int warpID = warp["m_iWarpNumber"];
|
||||||
NPCManager::Warps[warpID] = warpLoc;
|
NPCManager::Warps[warpID] = warpLoc;
|
||||||
}
|
}
|
||||||
|
@ -255,7 +255,7 @@ void TransportManager::stepSkywaySystem() {
|
|||||||
bmstk.iToZ = point.z;
|
bmstk.iToZ = point.z;
|
||||||
it->first->sendPacket((void*)&bmstk, P_FE2CL_PC_BROOMSTICK_MOVE, sizeof(sP_FE2CL_PC_BROOMSTICK_MOVE));
|
it->first->sendPacket((void*)&bmstk, P_FE2CL_PC_BROOMSTICK_MOVE, sizeof(sP_FE2CL_PC_BROOMSTICK_MOVE));
|
||||||
// set player location to point to update viewables
|
// set player location to point to update viewables
|
||||||
PlayerManager::updatePlayerChunk(it->first, point.x, point.y);
|
PlayerManager::updatePlayerChunk(it->first, point.x, point.y, plr->instanceID);
|
||||||
// send packet to players in view
|
// send packet to players in view
|
||||||
PlayerManager::sendToViewable(it->first, (void*)&bmstk, P_FE2CL_PC_BROOMSTICK_MOVE, sizeof(sP_FE2CL_PC_BROOMSTICK_MOVE));
|
PlayerManager::sendToViewable(it->first, (void*)&bmstk, P_FE2CL_PC_BROOMSTICK_MOVE, sizeof(sP_FE2CL_PC_BROOMSTICK_MOVE));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user