From 51363865bcd1e31fd19a506b953e16215606187e Mon Sep 17 00:00:00 2001 From: Shauren Date: Mon, 26 Dec 2022 12:18:54 +0100 Subject: [PATCH] Core/OutdoorPvP: Remove manual spawn management functions from OutdoorPvP --- src/server/game/OutdoorPvP/OutdoorPvP.cpp | 158 +--------------------- src/server/game/OutdoorPvP/OutdoorPvP.h | 26 ---- 2 files changed, 2 insertions(+), 182 deletions(-) diff --git a/src/server/game/OutdoorPvP/OutdoorPvP.cpp b/src/server/game/OutdoorPvP/OutdoorPvP.cpp index f737bd3c66..d66586764b 100644 --- a/src/server/game/OutdoorPvP/OutdoorPvP.cpp +++ b/src/server/game/OutdoorPvP/OutdoorPvP.cpp @@ -88,56 +88,6 @@ void OPvPCapturePoint::SendChangePhase() SendUpdateWorldState(m_capturePoint->GetGOInfo()->capturePoint.worldstate3, m_neutralValuePct); } -void OPvPCapturePoint::AddGO(uint32 type, ObjectGuid::LowType guid, uint32 entry) -{ - if (!entry) - { - GameObjectData const* data = sObjectMgr->GetGameObjectData(guid); - if (!data) - return; - entry = data->id; - } - - m_Objects[type] = guid; - m_ObjectTypes[m_Objects[type]] = type; -} - -void OPvPCapturePoint::AddCre(uint32 type, ObjectGuid::LowType guid, uint32 entry) -{ - if (!entry) - { - CreatureData const* data = sObjectMgr->GetCreatureData(guid); - if (!data) - return; - entry = data->id; - } - - m_Creatures[type] = guid; - m_CreatureTypes[m_Creatures[type]] = type; -} - -bool OPvPCapturePoint::AddObject(uint32 type, uint32 entry, uint32 map, Position const& pos, QuaternionData const& rot) -{ - if (ObjectGuid::LowType guid = sObjectMgr->AddGameObjectData(entry, map, pos, rot, 0)) - { - AddGO(type, guid, entry); - return true; - } - - return false; -} - -bool OPvPCapturePoint::AddCreature(uint32 type, uint32 entry, uint32 map, Position const& pos, TeamId /*teamId = TEAM_NEUTRAL*/, uint32 spawntimedelay /*= 0*/) -{ - if (ObjectGuid::LowType guid = sObjectMgr->AddCreatureData(entry, map, pos, spawntimedelay)) - { - AddCre(type, guid, entry); - return true; - } - - return false; -} - bool OPvPCapturePoint::SetCapturePointData(uint32 entry) { TC_LOG_DEBUG("outdoorpvp", "Creating capture point %u", entry); @@ -158,109 +108,9 @@ bool OPvPCapturePoint::SetCapturePointData(uint32 entry) return true;; } -bool OPvPCapturePoint::SetCapturePointData(uint32 entry, uint32 map, Position const& pos, QuaternionData const& rot) -{ - TC_LOG_DEBUG("outdoorpvp", "Creating capture point %u", entry); - - // check info existence - GameObjectTemplate const* goinfo = sObjectMgr->GetGameObjectTemplate(entry); - if (!goinfo || goinfo->type != GAMEOBJECT_TYPE_CAPTURE_POINT) - { - TC_LOG_ERROR("outdoorpvp", "OutdoorPvP: GO %u is not capture point!", entry); - return false; - } - - m_capturePointSpawnId = sObjectMgr->AddGameObjectData(entry, map, pos, rot, 0); - if (!m_capturePointSpawnId) - return false; - - SetCapturePointData(entry); - return true; -} - -bool OPvPCapturePoint::DelCreature(uint32 type) -{ - ObjectGuid::LowType spawnId = m_Creatures[type]; - if (!spawnId) - { - TC_LOG_DEBUG("outdoorpvp", "opvp creature type %u was already deleted", type); - return false; - } - - TC_LOG_DEBUG("outdoorpvp", "deleting opvp creature type %u", type); - m_CreatureTypes[m_Creatures[type]] = 0; - m_Creatures[type] = 0; - - return Creature::DeleteFromDB(spawnId); -} - -bool OPvPCapturePoint::DelObject(uint32 type) -{ - uint32 spawnId = m_Objects[type]; - if (!spawnId) - return false; - - sObjectMgr->DeleteGameObjectData(spawnId); - m_ObjectTypes[m_Objects[type]] = 0; - m_Objects[type] = 0; - - return GameObject::DeleteFromDB(spawnId); -} - -bool OPvPCapturePoint::DelCapturePoint() -{ - sObjectMgr->DeleteGameObjectData(m_capturePointSpawnId); - m_capturePointSpawnId = 0; - - if (m_capturePoint) - { - m_capturePoint->SetRespawnTime(0); // not save respawn time - m_capturePoint->Delete(); - } - - return true; -} - -void OPvPCapturePoint::DeleteSpawns() -{ - for (std::map::iterator i = m_Objects.begin(); i != m_Objects.end(); ++i) - DelObject(i->first); - for (std::map::iterator i = m_Creatures.begin(); i != m_Creatures.end(); ++i) - DelCreature(i->first); - DelCapturePoint(); -} - -void OutdoorPvP::DeleteSpawns() -{ - // Remove script from any registered gameobjects/creatures - for (auto itr = m_GoScriptStore.begin(); itr != m_GoScriptStore.end(); ++itr) - { - if (GameObject* go = itr->second) - go->ClearZoneScript(); - } - m_GoScriptStore.clear(); - - for (auto itr = m_CreatureScriptStore.begin(); itr != m_CreatureScriptStore.end(); ++itr) - { - if (Creature* creature = itr->second) - creature->ClearZoneScript(); - } - m_CreatureScriptStore.clear(); - - for (OPvPCapturePointMap::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr) - { - itr->second->DeleteSpawns(); - delete itr->second; - } - m_capturePoints.clear(); -} - OutdoorPvP::OutdoorPvP() : m_TypeId(0), m_map(nullptr) { } -OutdoorPvP::~OutdoorPvP() -{ - DeleteSpawns(); -} +OutdoorPvP::~OutdoorPvP() = default; void OutdoorPvP::HandlePlayerEnterZone(Player* player, uint32 /*zone*/) { @@ -567,12 +417,8 @@ bool OPvPCapturePoint::HandleDropFlag(Player* /*player*/, uint32 /*id*/) return false; } -int32 OPvPCapturePoint::HandleOpenGo(Player* /*player*/, GameObject* go) +int32 OPvPCapturePoint::HandleOpenGo(Player* /*player*/, GameObject* /*go*/) { - std::map::iterator itr = m_ObjectTypes.find(go->GetSpawnId()); - if (itr != m_ObjectTypes.end()) - return itr->second; - return -1; } diff --git a/src/server/game/OutdoorPvP/OutdoorPvP.h b/src/server/game/OutdoorPvP/OutdoorPvP.h index 0d332d703e..4001b16466 100644 --- a/src/server/game/OutdoorPvP/OutdoorPvP.h +++ b/src/server/game/OutdoorPvP/OutdoorPvP.h @@ -122,27 +122,11 @@ class TC_GAME_API OPvPCapturePoint virtual bool HandleDropFlag(Player* player, uint32 spellId); - virtual void DeleteSpawns(); - ObjectGuid::LowType m_capturePointSpawnId; GameObject* m_capturePoint; - void AddGO(uint32 type, ObjectGuid::LowType guid, uint32 entry = 0); - void AddCre(uint32 type, ObjectGuid::LowType guid, uint32 entry = 0); - bool SetCapturePointData(uint32 entry); - bool SetCapturePointData(uint32 entry, uint32 map, Position const& pos, QuaternionData const& rot); - - protected: - - bool AddObject(uint32 type, uint32 entry, uint32 map, Position const& pos, QuaternionData const& rot); - bool AddCreature(uint32 type, uint32 entry, uint32 map, Position const& pos, TeamId teamId = TEAM_NEUTRAL, uint32 spawntimedelay = 0); - - bool DelObject(uint32 type); - bool DelCreature(uint32 type); - - bool DelCapturePoint(); protected: @@ -170,13 +154,6 @@ class TC_GAME_API OPvPCapturePoint // pointer to the OutdoorPvP this objective belongs to OutdoorPvP* m_PvP; - - // map to store the various gameobjects and creatures spawned by the objective - // type, guid - std::map m_Objects; - std::map m_Creatures; - std::map m_ObjectTypes; - std::map m_CreatureTypes; }; // base class for specific outdoor pvp handlers @@ -192,9 +169,6 @@ class TC_GAME_API OutdoorPvP : public ZoneScript // dtor virtual ~OutdoorPvP(); - // deletes all gos/creatures spawned by the pvp - void DeleteSpawns(); - typedef std::map OPvPCapturePointMap; typedef std::pair GoScriptPair; typedef std::pair CreatureScriptPair;