/* * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #ifndef TRINITY_POOLHANDLER_H #define TRINITY_POOLHANDLER_H #include "Define.h" #include "SpawnData.h" #include #include #include #include class Creature; class GameObject; class Quest; struct PoolTemplateData { uint32 MaxLimit; }; struct PoolObject { uint64 guid; float chance; PoolObject(uint64 _guid, float _chance); }; class Pool // for Pool of Pool case { }; typedef std::set ActivePoolObjects; typedef std::map ActivePoolPools; class TC_GAME_API ActivePoolData { public: explicit ActivePoolData(); ~ActivePoolData(); ActivePoolData(ActivePoolData const& right) = delete; ActivePoolData(ActivePoolData&& right) = delete; ActivePoolData& operator=(ActivePoolData const& right) = delete; ActivePoolData& operator=(ActivePoolData&& right) = delete; template bool IsActiveObject(uint64 db_guid_or_pool_id) const; uint32 GetActiveObjectCount(uint32 pool_id) const; template void ActivateObject(uint64 db_guid_or_pool_id, uint32 pool_id); template void RemoveObject(uint64 db_guid_or_pool_id, uint32 pool_id); private: ActivePoolObjects mSpawnedCreatures; ActivePoolObjects mSpawnedGameobjects; ActivePoolPools mSpawnedPools; }; template class TC_GAME_API PoolGroup { typedef std::vector PoolObjectList; public: explicit PoolGroup(); ~PoolGroup(); PoolGroup(PoolGroup const& right) = delete; PoolGroup(PoolGroup&& right) = delete; PoolGroup& operator=(PoolGroup const& right) = delete; PoolGroup& operator=(PoolGroup&& right) = delete; void SetPoolId(uint32 pool_id) { poolId = pool_id; } bool isEmpty() const { return ExplicitlyChanced.empty() && EqualChanced.empty(); } void AddEntry(PoolObject& poolitem, uint32 maxentries); bool CheckPool() const; void DespawnObject(ActivePoolData& spawns, uint64 guid=0, bool alwaysDeleteRespawnTime = false); void Despawn1Object(uint64 guid, bool alwaysDeleteRespawnTime = false, bool saveRespawnTime = true); void SpawnObject(ActivePoolData& spawns, uint32 limit, uint64 triggerFrom); void RemoveRespawnTimeFromDB(uint64 guid); void Spawn1Object(PoolObject* obj); void ReSpawn1Object(PoolObject* obj); void RemoveOneRelation(uint32 child_pool_id); uint64 GetFirstEqualChancedObjectId() { if (EqualChanced.empty()) return 0; return EqualChanced.front().guid; } uint32 GetPoolId() const { return poolId; } private: uint32 poolId; PoolObjectList ExplicitlyChanced; PoolObjectList EqualChanced; }; class TC_GAME_API PoolMgr { private: PoolMgr(); ~PoolMgr(); public: PoolMgr(PoolMgr const& right) = delete; PoolMgr(PoolMgr&& right) = delete; PoolMgr& operator=(PoolMgr const& right) = delete; PoolMgr& operator=(PoolMgr&& right) = delete; static PoolMgr* instance(); void LoadFromDB(); void Initialize(); template uint32 IsPartOfAPool(uint64 db_guid_or_pool_id) const; uint32 IsPartOfAPool(SpawnObjectType type, uint64 spawnId) const; template bool IsSpawnedObject(uint64 db_guid_or_pool_id) const { return mSpawnedData.IsActiveObject(db_guid_or_pool_id); } bool CheckPool(uint32 pool_id) const; void SpawnPool(uint32 pool_id); void DespawnPool(uint32 pool_id, bool alwaysDeleteRespawnTime = false); template void UpdatePool(uint32 pool_id, uint64 db_guid_or_pool_id); void UpdatePool(uint32 pool_id, SpawnObjectType type, uint64 spawnId); private: template void SpawnPool(uint32 pool_id, uint64 db_guid_or_pool_id); typedef std::unordered_map PoolTemplateDataMap; typedef std::unordered_map> PoolGroupCreatureMap; typedef std::unordered_map> PoolGroupGameObjectMap; typedef std::unordered_map> PoolGroupPoolMap; typedef std::pair SearchPair; typedef std::map SearchMap; PoolTemplateDataMap mPoolTemplate; PoolGroupCreatureMap mPoolCreatureGroups; PoolGroupGameObjectMap mPoolGameobjectGroups; PoolGroupPoolMap mPoolPoolGroups; SearchMap mCreatureSearchMap; SearchMap mGameobjectSearchMap; SearchMap mPoolSearchMap; // dynamic data ActivePoolData mSpawnedData; }; #define sPoolMgr PoolMgr::instance() // Method that tell if the creature is part of a pool and return the pool id if yes template<> inline uint32 PoolMgr::IsPartOfAPool(uint64 db_guid) const { SearchMap::const_iterator itr = mCreatureSearchMap.find(db_guid); if (itr != mCreatureSearchMap.end()) return itr->second; return 0; } // Method that tell if the gameobject is part of a pool and return the pool id if yes template<> inline uint32 PoolMgr::IsPartOfAPool(uint64 db_guid) const { SearchMap::const_iterator itr = mGameobjectSearchMap.find(db_guid); if (itr != mGameobjectSearchMap.end()) return itr->second; return 0; } // Method that tell if the pool is part of another pool and return the pool id if yes template<> inline uint32 PoolMgr::IsPartOfAPool(uint64 pool_id) const { SearchMap::const_iterator itr = mPoolSearchMap.find(pool_id); if (itr != mPoolSearchMap.end()) return itr->second; return 0; } #endif