/* * 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 #include class Creature; class GameObject; class Map; class Quest; struct PoolTemplateData { uint32 MaxLimit; int32 MapId; }; struct PoolObject { uint64 guid; float chance; PoolObject(uint64 _guid, float _chance); }; class Pool // for Pool of Pool case { }; typedef std::set SpawnedPoolObjects; typedef std::map SpawnedPoolPools; class TC_GAME_API SpawnedPoolData { public: explicit SpawnedPoolData(Map* owner); ~SpawnedPoolData(); SpawnedPoolData(SpawnedPoolData const& right) = delete; SpawnedPoolData(SpawnedPoolData&& right) = delete; SpawnedPoolData& operator=(SpawnedPoolData const& right) = delete; SpawnedPoolData& operator=(SpawnedPoolData&& right) = delete; Map* GetMap() const { return mOwner; } template bool IsSpawnedObject(uint64 db_guid_or_pool_id) const; bool IsSpawnedObject(SpawnObjectType type, uint64 db_guid_or_pool_id) const; uint32 GetSpawnedObjects(uint32 pool_id) const; template void AddSpawn(uint64 db_guid_or_pool_id, uint32 pool_id); template void RemoveSpawn(uint64 db_guid_or_pool_id, uint32 pool_id); private: Map* mOwner; SpawnedPoolObjects mSpawnedCreatures; SpawnedPoolObjects mSpawnedGameobjects; SpawnedPoolPools 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(); } bool isEmptyDeepCheck() const; void AddEntry(PoolObject& poolitem, uint32 maxentries); bool CheckPool() const; void DespawnObject(SpawnedPoolData& spawns, uint64 guid=0, bool alwaysDeleteRespawnTime = false); void Despawn1Object(SpawnedPoolData& spawns, uint64 guid, bool alwaysDeleteRespawnTime = false, bool saveRespawnTime = true); void SpawnObject(SpawnedPoolData& spawns, uint32 limit, uint64 triggerFrom); void RemoveRespawnTimeFromDB(SpawnedPoolData& spawns, uint64 guid); void Spawn1Object(SpawnedPoolData& spawns, PoolObject* obj); void ReSpawn1Object(SpawnedPoolData& spawns, PoolObject* obj); void RemoveOneRelation(uint32 child_pool_id); 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(SpawnedPoolData& spawnedPoolData, uint64 db_guid_or_pool_id) const { return spawnedPoolData.IsSpawnedObject(db_guid_or_pool_id); } bool IsEmpty(uint32 pool_id) const; bool CheckPool(uint32 pool_id) const; void SpawnPool(SpawnedPoolData& spawnedPoolData, uint32 pool_id); void DespawnPool(SpawnedPoolData& spawnedPoolData, uint32 pool_id, bool alwaysDeleteRespawnTime = false); template void UpdatePool(SpawnedPoolData& spawnedPoolData, uint32 pool_id, uint64 db_guid_or_pool_id); void UpdatePool(SpawnedPoolData& spawnedPoolData, uint32 pool_id, SpawnObjectType type, uint64 spawnId); std::unique_ptr InitPoolsForMap(Map* map); PoolTemplateData const* GetPoolTemplate(uint16 pool_id) const; private: template void SpawnPool(SpawnedPoolData& spawnedPoolData, 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; std::unordered_map> mAutoSpawnPoolsPerMap; }; #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