mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-04 22:40:05 +00:00
Delete instances with no players
This commit is contained in:
parent
6473951b9a
commit
da725d21e6
@ -85,7 +85,8 @@ void ChunkManager::destroyChunk(std::tuple<int, int, uint64_t> chunkPos) {
|
||||
Chunk* chunk = chunks[chunkPos];
|
||||
|
||||
// unspawn all of the mobs/npcs
|
||||
for (uint32_t id : chunk->NPCs) {
|
||||
std::set npcIDs(chunk->NPCs);
|
||||
for (uint32_t id : npcIDs) {
|
||||
NPCManager::destroyNPC(id);
|
||||
}
|
||||
|
||||
|
@ -15,9 +15,9 @@ public:
|
||||
};
|
||||
|
||||
enum {
|
||||
INSTANCE_OVERWORLD, // default instance every player starts in
|
||||
//INSTANCE_IZ, // all infected zones share an instance
|
||||
//INSTANCE_UNIQUE // fusion lairs are generated as requested (+ uid)
|
||||
INSTANCE_OVERWORLD // default instance every player starts in
|
||||
//INSTANCE_IZ, // these aren't actually used
|
||||
//INSTANCE_UNIQUE
|
||||
};
|
||||
|
||||
namespace ChunkManager {
|
||||
|
@ -592,6 +592,8 @@ void NPCManager::handleWarp(CNSocket* sock, int32_t warpId) {
|
||||
|
||||
MissionManager::failInstancedMissions(sock); // fail any missions that require the player's current instance
|
||||
|
||||
uint64_t fromInstance = plrv.plr->instanceID; // saved for post-warp
|
||||
|
||||
if (plrv.plr->instanceID == 0) {
|
||||
// save last uninstanced coords
|
||||
plrv.plr->lastX = plrv.plr->x;
|
||||
@ -624,6 +626,18 @@ void NPCManager::handleWarp(CNSocket* sock, int32_t warpId) {
|
||||
plrv.plr->instanceID = INSTANCE_OVERWORLD;
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC));
|
||||
}
|
||||
|
||||
// post-warp: check if the source instance has no more players in it and delete it if so
|
||||
if ((fromInstance >> 32) == 0)
|
||||
return; // don't clean up overworld/IZ chunks
|
||||
|
||||
std::vector<std::tuple<int, int, uint64_t>> sourceChunkCoords = ChunkManager::getChunksInMap(fromInstance);
|
||||
for (std::tuple<int, int, uint64_t>& coords : sourceChunkCoords) {
|
||||
Chunk* chunk = ChunkManager::chunks[coords];
|
||||
if (chunk->players.size() > 0)
|
||||
return; // there are still players inside
|
||||
}
|
||||
ChunkManager::destroyInstance(fromInstance);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user