TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PoolMgr Class Reference

#include <PoolMgr.h>

Public Member Functions

void LoadFromDB ()
 
void LoadQuestPools ()
 
void SaveQuestsToDB ()
 
void Initialize ()
 
template<typename T >
uint32 IsPartOfAPool (uint64 db_guid_or_pool_id) const
 
template<typename T >
bool IsSpawnedObject (uint64 db_guid_or_pool_id) const
 
bool CheckPool (uint32 pool_id) const
 
void SpawnPool (uint32 pool_id)
 
void DespawnPool (uint32 pool_id)
 
template<typename T >
void UpdatePool (uint32 pool_id, uint64 db_guid_or_pool_id)
 
void ChangeDailyQuests ()
 
void ChangeWeeklyQuests ()
 
template<>
uint32 IsPartOfAPool (uint64 db_guid) const
 
template<>
uint32 IsPartOfAPool (uint64 db_guid) const
 
template<>
uint32 IsPartOfAPool (uint64 pool_id) const
 
template<>
uint32 IsPartOfAPool (uint64 pool_id) const
 

Static Public Member Functions

static PoolMgrinstance ()
 

Public Attributes

PooledQuestRelation mQuestCreatureRelation
 
PooledQuestRelation mQuestGORelation
 

Private Types

typedef std::vector
< PoolTemplateData
PoolTemplateDataMap
 
typedef std::vector< PoolGroup
< Creature > > 
PoolGroupCreatureMap
 
typedef std::vector< PoolGroup
< GameObject > > 
PoolGroupGameObjectMap
 
typedef std::vector< PoolGroup
< Pool > > 
PoolGroupPoolMap
 
typedef std::vector< PoolGroup
< Quest > > 
PoolGroupQuestMap
 
typedef std::pair< uint64, uint32SearchPair
 
typedef std::map< uint64, uint32SearchMap
 

Private Member Functions

 PoolMgr ()
 
 ~PoolMgr ()
 
template<typename T >
void SpawnPool (uint32 pool_id, uint64 db_guid_or_pool_id)
 
template<>
void SpawnPool (uint32 pool_id, uint64 db_guid)
 
template<>
void SpawnPool (uint32 pool_id, uint64 db_guid)
 
template<>
void SpawnPool (uint32 pool_id, uint64 sub_pool_id)
 
template<>
void SpawnPool (uint32 pool_id, uint64 quest_id)
 

Private Attributes

uint32 max_pool_id
 
PoolTemplateDataMap mPoolTemplate
 
PoolGroupCreatureMap mPoolCreatureGroups
 
PoolGroupGameObjectMap mPoolGameobjectGroups
 
PoolGroupPoolMap mPoolPoolGroups
 
PoolGroupQuestMap mPoolQuestGroups
 
SearchMap mCreatureSearchMap
 
SearchMap mGameobjectSearchMap
 
SearchMap mPoolSearchMap
 
SearchMap mQuestSearchMap
 
ActivePoolData mSpawnedData
 

Member Typedef Documentation

typedef std::vector<PoolGroup<Creature> > PoolMgr::PoolGroupCreatureMap
private
typedef std::vector<PoolGroup<GameObject> > PoolMgr::PoolGroupGameObjectMap
private
typedef std::vector<PoolGroup<Pool> > PoolMgr::PoolGroupPoolMap
private
typedef std::vector<PoolGroup<Quest> > PoolMgr::PoolGroupQuestMap
private
typedef std::vector<PoolTemplateData> PoolMgr::PoolTemplateDataMap
private
typedef std::map<uint64, uint32> PoolMgr::SearchMap
private
typedef std::pair<uint64, uint32> PoolMgr::SearchPair
private

Constructor & Destructor Documentation

PoolMgr::PoolMgr ( )
private
556 : max_pool_id(0) { }
uint32 max_pool_id
Definition: PoolMgr.h:143
PoolMgr::~PoolMgr ( )
inlineprivate
108 { };

Member Function Documentation

void PoolMgr::ChangeDailyQuests ( )
992 {
993  for (PoolGroupQuestMap::iterator itr = mPoolQuestGroups.begin(); itr != mPoolQuestGroups.end(); ++itr)
994  {
995  if (Quest const* quest = sObjectMgr->GetQuestTemplate(itr->GetFirstEqualChancedObjectId()))
996  {
997  if (quest->IsWeekly())
998  continue;
999 
1000  UpdatePool<Quest>(itr->GetPoolId(), 1); // anything non-zero means don't load from db
1001  }
1002  }
1003 
1004  SaveQuestsToDB();
1005 }
Definition: QuestDef.h:279
PoolGroupQuestMap mPoolQuestGroups
Definition: PoolMgr.h:156
#define sObjectMgr
Definition: ObjectMgr.h:1567
void SaveQuestsToDB()
Definition: PoolMgr.cpp:964

+ Here is the call graph for this function:

void PoolMgr::ChangeWeeklyQuests ( )
1008 {
1009  for (PoolGroupQuestMap::iterator itr = mPoolQuestGroups.begin(); itr != mPoolQuestGroups.end(); ++itr)
1010  {
1011  if (Quest const* quest = sObjectMgr->GetQuestTemplate(itr->GetFirstEqualChancedObjectId()))
1012  {
1013  if (quest->IsDaily())
1014  continue;
1015 
1016  UpdatePool<Quest>(itr->GetPoolId(), 1);
1017  }
1018  }
1019 
1020  SaveQuestsToDB();
1021 }
Definition: QuestDef.h:279
PoolGroupQuestMap mPoolQuestGroups
Definition: PoolMgr.h:156
#define sObjectMgr
Definition: ObjectMgr.h:1567
void SaveQuestsToDB()
Definition: PoolMgr.cpp:964

+ Here is the call graph for this function:

bool PoolMgr::CheckPool ( uint32  pool_id) const
1084 {
1085  return pool_id <= max_pool_id &&
1086  mPoolGameobjectGroups[pool_id].CheckPool() &&
1087  mPoolCreatureGroups[pool_id].CheckPool() &&
1088  mPoolPoolGroups[pool_id].CheckPool() &&
1089  mPoolQuestGroups[pool_id].CheckPool();
1090 }
uint32 max_pool_id
Definition: PoolMgr.h:143
PoolGroupPoolMap mPoolPoolGroups
Definition: PoolMgr.h:155
PoolGroupQuestMap mPoolQuestGroups
Definition: PoolMgr.h:156
PoolGroupCreatureMap mPoolCreatureGroups
Definition: PoolMgr.h:153
PoolGroupGameObjectMap mPoolGameobjectGroups
Definition: PoolMgr.h:154

+ Here is the caller graph for this function:

void PoolMgr::DespawnPool ( uint32  pool_id)
1068 {
1069  if (!mPoolCreatureGroups[pool_id].isEmpty())
1070  mPoolCreatureGroups[pool_id].DespawnObject(mSpawnedData);
1071 
1072  if (!mPoolGameobjectGroups[pool_id].isEmpty())
1073  mPoolGameobjectGroups[pool_id].DespawnObject(mSpawnedData);
1074 
1075  if (!mPoolPoolGroups[pool_id].isEmpty())
1076  mPoolPoolGroups[pool_id].DespawnObject(mSpawnedData);
1077 
1078  if (!mPoolQuestGroups[pool_id].isEmpty())
1079  mPoolQuestGroups[pool_id].DespawnObject(mSpawnedData);
1080 }
PoolGroupPoolMap mPoolPoolGroups
Definition: PoolMgr.h:155
PoolGroupQuestMap mPoolQuestGroups
Definition: PoolMgr.h:156
ActivePoolData mSpawnedData
Definition: PoolMgr.h:163
PoolGroupCreatureMap mPoolCreatureGroups
Definition: PoolMgr.h:153
PoolGroupGameObjectMap mPoolGameobjectGroups
Definition: PoolMgr.h:154
void PoolMgr::Initialize ( void  )
559 {
560  QueryResult result = WorldDatabase.Query("SELECT MAX(entry) FROM pool_template");
561  if (result)
562  {
563  Field* fields = result->Fetch();
564  max_pool_id = fields[0].GetUInt32();
565  }
566 
567  mPoolTemplate.resize(max_pool_id + 1);
568  mPoolCreatureGroups.resize(max_pool_id + 1);
570  mPoolPoolGroups.resize(max_pool_id + 1);
571  mPoolQuestGroups.resize(max_pool_id + 1);
572 
573  mQuestSearchMap.clear();
574  mGameobjectSearchMap.clear();
575  mCreatureSearchMap.clear();
576 }
SearchMap mCreatureSearchMap
Definition: PoolMgr.h:157
SearchMap mGameobjectSearchMap
Definition: PoolMgr.h:158
uint32 max_pool_id
Definition: PoolMgr.h:143
Class used to access individual fields of database query result.
Definition: Field.h:56
PoolGroupPoolMap mPoolPoolGroups
Definition: PoolMgr.h:155
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
PoolGroupQuestMap mPoolQuestGroups
Definition: PoolMgr.h:156
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
PoolTemplateDataMap mPoolTemplate
Definition: PoolMgr.h:152
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32 GetUInt32() const
Definition: Field.h:146
PoolGroupCreatureMap mPoolCreatureGroups
Definition: PoolMgr.h:153
PoolGroupGameObjectMap mPoolGameobjectGroups
Definition: PoolMgr.h:154
SearchMap mQuestSearchMap
Definition: PoolMgr.h:160

+ Here is the call graph for this function:

PoolMgr * PoolMgr::instance ( )
static
579 {
580  static PoolMgr instance;
581  return &instance;
582 }
Definition: PoolMgr.h:104
static PoolMgr * instance()
Definition: PoolMgr.cpp:578
template<typename T >
uint32 PoolMgr::IsPartOfAPool ( uint64  db_guid_or_pool_id) const
template<>
uint32 PoolMgr::IsPartOfAPool ( uint64  db_guid) const
inline
171 {
172  SearchMap::const_iterator itr = mCreatureSearchMap.find(db_guid);
173  if (itr != mCreatureSearchMap.end())
174  return itr->second;
175 
176  return 0;
177 }
SearchMap mCreatureSearchMap
Definition: PoolMgr.h:157
template<>
uint32 PoolMgr::IsPartOfAPool ( uint64  db_guid) const
inline
182 {
183  SearchMap::const_iterator itr = mGameobjectSearchMap.find(db_guid);
184  if (itr != mGameobjectSearchMap.end())
185  return itr->second;
186 
187  return 0;
188 }
SearchMap mGameobjectSearchMap
Definition: PoolMgr.h:158
template<>
uint32 PoolMgr::IsPartOfAPool ( uint64  pool_id) const
inline
193 {
194  SearchMap::const_iterator itr = mQuestSearchMap.find(pool_id);
195  if (itr != mQuestSearchMap.end())
196  return itr->second;
197 
198  return 0;
199 }
SearchMap mQuestSearchMap
Definition: PoolMgr.h:160
template<>
uint32 PoolMgr::IsPartOfAPool ( uint64  pool_id) const
inline
204 {
205  SearchMap::const_iterator itr = mPoolSearchMap.find(pool_id);
206  if (itr != mPoolSearchMap.end())
207  return itr->second;
208 
209  return 0;
210 }
SearchMap mPoolSearchMap
Definition: PoolMgr.h:159
template<typename T >
bool PoolMgr::IsSpawnedObject ( uint64  db_guid_or_pool_id) const
inline
123 { return mSpawnedData.IsActiveObject<T>(db_guid_or_pool_id); }
bool IsActiveObject(uint64 db_guid_or_pool_id) const
ActivePoolData mSpawnedData
Definition: PoolMgr.h:163
void PoolMgr::LoadFromDB ( )
585 {
586  // Pool templates
587  {
588  uint32 oldMSTime = getMSTime();
589 
590  QueryResult result = WorldDatabase.Query("SELECT entry, max_limit FROM pool_template");
591  if (!result)
592  {
593  mPoolTemplate.clear();
594  TC_LOG_INFO("server.loading", ">> Loaded 0 object pools. DB table `pool_template` is empty.");
595  return;
596  }
597 
598  uint32 count = 0;
599  do
600  {
601  Field* fields = result->Fetch();
602 
603  uint32 pool_id = fields[0].GetUInt32();
604 
605  PoolTemplateData& pPoolTemplate = mPoolTemplate[pool_id];
606  pPoolTemplate.MaxLimit = fields[1].GetUInt32();
607 
608  ++count;
609  }
610  while (result->NextRow());
611 
612  TC_LOG_INFO("server.loading", ">> Loaded %u objects pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
613  }
614 
615  // Creatures
616 
617  TC_LOG_INFO("server.loading", "Loading Creatures Pooling Data...");
618  {
619  uint32 oldMSTime = getMSTime();
620 
621  // 1 2 3
622  QueryResult result = WorldDatabase.Query("SELECT guid, pool_entry, chance FROM pool_creature");
623 
624  if (!result)
625  {
626  TC_LOG_INFO("server.loading", ">> Loaded 0 creatures in pools. DB table `pool_creature` is empty.");
627  }
628  else
629  {
630  uint32 count = 0;
631  do
632  {
633  Field* fields = result->Fetch();
634 
635  uint64 guid = fields[0].GetUInt64();
636  uint32 pool_id = fields[1].GetUInt32();
637  float chance = fields[2].GetFloat();
638 
639  CreatureData const* data = sObjectMgr->GetCreatureData(guid);
640  if (!data)
641  {
642  TC_LOG_ERROR("sql.sql", "`pool_creature` has a non existing creature spawn (GUID: " UI64FMTD ") defined for pool id (%u), skipped.", guid, pool_id);
643  continue;
644  }
645  if (pool_id > max_pool_id)
646  {
647  TC_LOG_ERROR("sql.sql", "`pool_creature` pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.", pool_id);
648  continue;
649  }
650  if (chance < 0 || chance > 100)
651  {
652  TC_LOG_ERROR("sql.sql", "`pool_creature` has an invalid chance (%f) for creature guid (" UI64FMTD ") in pool id (%u), skipped.", chance, guid, pool_id);
653  continue;
654  }
655  PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id];
656  PoolObject plObject = PoolObject(guid, chance);
657  PoolGroup<Creature>& cregroup = mPoolCreatureGroups[pool_id];
658  cregroup.SetPoolId(pool_id);
659  cregroup.AddEntry(plObject, pPoolTemplate->MaxLimit);
660  SearchPair p(guid, pool_id);
661  mCreatureSearchMap.insert(p);
662 
663  ++count;
664  }
665  while (result->NextRow());
666 
667  TC_LOG_INFO("server.loading", ">> Loaded %u creatures in pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
668  }
669  }
670 
671  // Gameobjects
672 
673  TC_LOG_INFO("server.loading", "Loading Gameobject Pooling Data...");
674  {
675  uint32 oldMSTime = getMSTime();
676 
677  // 1 2 3
678  QueryResult result = WorldDatabase.Query("SELECT guid, pool_entry, chance FROM pool_gameobject");
679 
680  if (!result)
681  {
682  TC_LOG_INFO("server.loading", ">> Loaded 0 gameobjects in pools. DB table `pool_gameobject` is empty.");
683  }
684  else
685  {
686  uint32 count = 0;
687  do
688  {
689  Field* fields = result->Fetch();
690 
691  uint64 guid = fields[0].GetUInt64();
692  uint32 pool_id = fields[1].GetUInt32();
693  float chance = fields[2].GetFloat();
694 
695  GameObjectData const* data = sObjectMgr->GetGOData(guid);
696  if (!data)
697  {
698  TC_LOG_ERROR("sql.sql", "`pool_gameobject` has a non existing gameobject spawn (GUID: " UI64FMTD ") defined for pool id (%u), skipped.", guid, pool_id);
699  continue;
700  }
701 
702  GameObjectTemplate const* goinfo = sObjectMgr->GetGameObjectTemplate(data->id);
703  if (goinfo->type != GAMEOBJECT_TYPE_CHEST &&
704  goinfo->type != GAMEOBJECT_TYPE_GOOBER &&
706  {
707  TC_LOG_ERROR("sql.sql", "`pool_gameobject` has a not lootable gameobject spawn (GUID: " UI64FMTD ", type: %u) defined for pool id (%u), skipped.", guid, goinfo->type, pool_id);
708  continue;
709  }
710 
711  if (pool_id > max_pool_id)
712  {
713  TC_LOG_ERROR("sql.sql", "`pool_gameobject` pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.", pool_id);
714  continue;
715  }
716 
717  if (chance < 0 || chance > 100)
718  {
719  TC_LOG_ERROR("sql.sql", "`pool_gameobject` has an invalid chance (%f) for gameobject guid (" UI64FMTD ") in pool id (%u), skipped.", chance, guid, pool_id);
720  continue;
721  }
722 
723  PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id];
724  PoolObject plObject = PoolObject(guid, chance);
725  PoolGroup<GameObject>& gogroup = mPoolGameobjectGroups[pool_id];
726  gogroup.SetPoolId(pool_id);
727  gogroup.AddEntry(plObject, pPoolTemplate->MaxLimit);
728  SearchPair p(guid, pool_id);
729  mGameobjectSearchMap.insert(p);
730 
731  ++count;
732  }
733  while (result->NextRow());
734 
735  TC_LOG_INFO("server.loading", ">> Loaded %u gameobject in pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
736  }
737  }
738 
739  // Pool of pools
740 
741  TC_LOG_INFO("server.loading", "Loading Mother Pooling Data...");
742  {
743  uint32 oldMSTime = getMSTime();
744 
745  // 1 2 3
746  QueryResult result = WorldDatabase.Query("SELECT pool_id, mother_pool, chance FROM pool_pool");
747 
748  if (!result)
749  {
750  TC_LOG_INFO("server.loading", ">> Loaded 0 pools in pools");
751  }
752  else
753  {
754  uint32 count = 0;
755  do
756  {
757  Field* fields = result->Fetch();
758 
759  uint32 child_pool_id = fields[0].GetUInt32();
760  uint32 mother_pool_id = fields[1].GetUInt32();
761  float chance = fields[2].GetFloat();
762 
763  if (mother_pool_id > max_pool_id)
764  {
765  TC_LOG_ERROR("sql.sql", "`pool_pool` mother_pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.", mother_pool_id);
766  continue;
767  }
768  if (child_pool_id > max_pool_id)
769  {
770  TC_LOG_ERROR("sql.sql", "`pool_pool` included pool_id (%u) is out of range compared to max pool id in `pool_template`, skipped.", child_pool_id);
771  continue;
772  }
773  if (mother_pool_id == child_pool_id)
774  {
775  TC_LOG_ERROR("sql.sql", "`pool_pool` pool_id (%u) includes itself, dead-lock detected, skipped.", child_pool_id);
776  continue;
777  }
778  if (chance < 0 || chance > 100)
779  {
780  TC_LOG_ERROR("sql.sql", "`pool_pool` has an invalid chance (%f) for pool id (%u) in mother pool id (%u), skipped.", chance, child_pool_id, mother_pool_id);
781  continue;
782  }
783  PoolTemplateData* pPoolTemplateMother = &mPoolTemplate[mother_pool_id];
784  PoolObject plObject = PoolObject(child_pool_id, chance);
785  PoolGroup<Pool>& plgroup = mPoolPoolGroups[mother_pool_id];
786  plgroup.SetPoolId(mother_pool_id);
787  plgroup.AddEntry(plObject, pPoolTemplateMother->MaxLimit);
788  SearchPair p(child_pool_id, mother_pool_id);
789  mPoolSearchMap.insert(p);
790 
791  ++count;
792  }
793  while (result->NextRow());
794 
795  // Now check for circular reference
796  for (uint32 i=0; i < max_pool_id; ++i)
797  {
798  std::set<uint32> checkedPools;
799  for (SearchMap::iterator poolItr = mPoolSearchMap.find(i); poolItr != mPoolSearchMap.end(); poolItr = mPoolSearchMap.find(poolItr->second))
800  {
801  checkedPools.insert(poolItr->first);
802  if (checkedPools.find(poolItr->second) != checkedPools.end())
803  {
804  std::ostringstream ss;
805  ss<< "The pool(s) ";
806  for (std::set<uint32>::const_iterator itr=checkedPools.begin(); itr != checkedPools.end(); ++itr)
807  ss << *itr << ' ';
808  ss << "create(s) a circular reference, which can cause the server to freeze.\nRemoving the last link between mother pool "
809  << poolItr->first << " and child pool " << poolItr->second;
810  TC_LOG_ERROR("sql.sql", "%s", ss.str().c_str());
811  mPoolPoolGroups[poolItr->second].RemoveOneRelation(poolItr->first);
812  mPoolSearchMap.erase(poolItr);
813  --count;
814  break;
815  }
816  }
817  }
818 
819  TC_LOG_INFO("server.loading", ">> Loaded %u pools in mother pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
820  }
821  }
822 
823  TC_LOG_INFO("server.loading", "Loading Quest Pooling Data...");
824  {
825  uint32 oldMSTime = getMSTime();
826 
828  PreparedQueryResult result = WorldDatabase.Query(stmt);
829 
830  if (!result)
831  {
832  TC_LOG_INFO("server.loading", ">> Loaded 0 quests in pools");
833  }
834  else
835  {
836  PooledQuestRelationBounds creBounds;
837  PooledQuestRelationBounds goBounds;
838 
839  enum eQuestTypes
840  {
841  QUEST_NONE = 0,
842  QUEST_DAILY = 1,
843  QUEST_WEEKLY = 2
844  };
845 
846  std::map<uint32, int32> poolTypeMap;
847  uint32 count = 0;
848  do
849  {
850  Field* fields = result->Fetch();
851 
852  uint32 entry = fields[0].GetUInt32();
853  uint32 pool_id = fields[1].GetUInt32();
854 
855  Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
856  if (!quest)
857  {
858  TC_LOG_ERROR("sql.sql", "`pool_quest` has a non existing quest template (Entry: %u) defined for pool id (%u), skipped.", entry, pool_id);
859  continue;
860  }
861 
862  if (pool_id > max_pool_id)
863  {
864  TC_LOG_ERROR("sql.sql", "`pool_quest` pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.", pool_id);
865  continue;
866  }
867 
868  if (!quest->IsDailyOrWeekly())
869  {
870  TC_LOG_ERROR("sql.sql", "`pool_quest` has an quest (%u) which is not daily or weekly in pool id (%u), use ExclusiveGroup instead, skipped.", entry, pool_id);
871  continue;
872  }
873 
874  if (poolTypeMap[pool_id] == QUEST_NONE)
875  poolTypeMap[pool_id] = quest->IsDaily() ? QUEST_DAILY : QUEST_WEEKLY;
876 
877  int32 currType = quest->IsDaily() ? QUEST_DAILY : QUEST_WEEKLY;
878 
879  if (poolTypeMap[pool_id] != currType)
880  {
881  TC_LOG_ERROR("sql.sql", "`pool_quest` quest %u is %s but pool (%u) is specified for %s, mixing not allowed, skipped.",
882  entry, currType == QUEST_DAILY ? "QUEST_DAILY" : "QUEST_WEEKLY", pool_id, poolTypeMap[pool_id] == QUEST_DAILY ? "QUEST_DAILY" : "QUEST_WEEKLY");
883  continue;
884  }
885 
886  creBounds = mQuestCreatureRelation.equal_range(entry);
887  goBounds = mQuestGORelation.equal_range(entry);
888 
889  if (creBounds.first == creBounds.second && goBounds.first == goBounds.second)
890  {
891  TC_LOG_ERROR("sql.sql", "`pool_quest` lists entry (%u) as member of pool (%u) but is not started anywhere, skipped.", entry, pool_id);
892  continue;
893  }
894 
895  PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id];
896  PoolObject plObject = PoolObject(entry, 0.0f);
897  PoolGroup<Quest>& questgroup = mPoolQuestGroups[pool_id];
898  questgroup.SetPoolId(pool_id);
899  questgroup.AddEntry(plObject, pPoolTemplate->MaxLimit);
900  SearchPair p(entry, pool_id);
901  mQuestSearchMap.insert(p);
902 
903  ++count;
904  }
905  while (result->NextRow());
906 
907  TC_LOG_INFO("server.loading", ">> Loaded %u quests in pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
908  }
909  }
910 
911  // The initialize method will spawn all pools not in an event and not in another pool, this is why there is 2 left joins with 2 null checks
912  TC_LOG_INFO("server.loading", "Starting objects pooling system...");
913  {
914  uint32 oldMSTime = getMSTime();
915 
916  QueryResult result = WorldDatabase.Query("SELECT DISTINCT pool_template.entry, pool_pool.pool_id, pool_pool.mother_pool FROM pool_template"
917  " LEFT JOIN game_event_pool ON pool_template.entry=game_event_pool.pool_entry"
918  " LEFT JOIN pool_pool ON pool_template.entry=pool_pool.pool_id WHERE game_event_pool.pool_entry IS NULL");
919 
920  if (!result)
921  {
922  TC_LOG_INFO("server.loading", ">> Pool handling system initialized, 0 pools spawned.");
923  }
924  else
925  {
926  uint32 count = 0;
927  do
928  {
929  Field* fields = result->Fetch();
930  uint32 pool_entry = fields[0].GetUInt32();
931  uint32 pool_pool_id = fields[1].GetUInt32();
932 
933  if (!CheckPool(pool_entry))
934  {
935  if (pool_pool_id)
936  // The pool is a child pool in pool_pool table. Ideally we should remove it from the pool handler to ensure it never gets spawned,
937  // however that could recursively invalidate entire chain of mother pools. It can be done in the future but for now we'll do nothing.
938  TC_LOG_ERROR("sql.sql", "Pool Id %u has no equal chance pooled entites defined and explicit chance sum is not 100. This broken pool is a child pool of Id %u and cannot be safely removed.", pool_entry, fields[2].GetUInt32());
939  else
940  TC_LOG_ERROR("sql.sql", "Pool Id %u has no equal chance pooled entites defined and explicit chance sum is not 100. The pool will not be spawned.", pool_entry);
941  continue;
942  }
943 
944  // Don't spawn child pools, they are spawned recursively by their parent pools
945  if (!pool_pool_id)
946  {
947  SpawnPool(pool_entry);
948  count++;
949  }
950  }
951  while (result->NextRow());
952 
953  TC_LOG_DEBUG("pool", "Pool handling system initialized, %u pools spawned in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
954 
955  }
956  }
957 }
PooledQuestRelation mQuestGORelation
Definition: PoolMgr.h:137
Definition: Creature.h:287
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
uint64 GetUInt64() const
Definition: Field.h:184
SearchMap mCreatureSearchMap
Definition: PoolMgr.h:157
Definition: QuestDef.h:279
float GetFloat() const
Definition: Field.h:222
SearchMap mGameobjectSearchMap
Definition: PoolMgr.h:158
Definition: PoolMgr.h:27
uint32 max_pool_id
Definition: PoolMgr.h:143
Class used to access individual fields of database query result.
Definition: Field.h:56
PooledQuestRelation mQuestCreatureRelation
Definition: PoolMgr.h:136
uint32 getMSTime()
Definition: Timer.h:24
Definition: GameObject.h:34
PoolGroupPoolMap mPoolPoolGroups
Definition: PoolMgr.h:155
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
PoolGroupQuestMap mPoolQuestGroups
Definition: PoolMgr.h:156
Definition: WorldDatabase.h:32
bool IsDaily() const
Definition: QuestDef.h:375
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: PreparedStatement.h:74
Definition: PoolMgr.h:32
#define UI64FMTD
Definition: Define.h:137
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
void AddEntry(PoolObject &poolitem, uint32 maxentries)
Definition: PoolMgr.cpp:137
uint64_t uint64
Definition: Define.h:149
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
uint32 id
Definition: GameObject.h:838
PoolTemplateDataMap mPoolTemplate
Definition: PoolMgr.h:152
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
Definition: SharedDefines.h:2090
Definition: GameObject.h:833
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
Definition: SharedDefines.h:2075
std::pair< PooledQuestRelation::const_iterator, PooledQuestRelation::const_iterator > PooledQuestRelationBounds
Definition: PoolMgr.h:101
uint32 GetUInt32() const
Definition: Field.h:146
uint32 MaxLimit
Definition: PoolMgr.h:29
Definition: SharedDefines.h:2068
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
std::pair< uint64, uint32 > SearchPair
Definition: PoolMgr.h:149
PoolGroupCreatureMap mPoolCreatureGroups
Definition: PoolMgr.h:153
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
void SpawnPool(uint32 pool_id)
Definition: PoolMgr.cpp:1058
void SetPoolId(uint32 pool_id)
Definition: PoolMgr.h:74
PoolGroupGameObjectMap mPoolGameobjectGroups
Definition: PoolMgr.h:154
SearchMap mQuestSearchMap
Definition: PoolMgr.h:160
SearchMap mPoolSearchMap
Definition: PoolMgr.h:159
bool CheckPool(uint32 pool_id) const
Definition: PoolMgr.cpp:1083
uint32 type
Definition: GameObject.h:37
bool IsDailyOrWeekly() const
Definition: QuestDef.h:379

+ Here is the call graph for this function:

void PoolMgr::LoadQuestPools ( )
960 {
961 
962 }
void PoolMgr::SaveQuestsToDB ( )
965 {
967 
968  for (PoolGroupQuestMap::iterator itr = mPoolQuestGroups.begin(); itr != mPoolQuestGroups.end(); ++itr)
969  {
970  if (itr->isEmpty())
971  continue;
973  stmt->setUInt32(0, itr->GetPoolId());
974  trans->Append(stmt);
975  }
976 
977  for (SearchMap::iterator itr = mQuestSearchMap.begin(); itr != mQuestSearchMap.end(); ++itr)
978  {
979  if (IsSpawnedObject<Quest>(itr->first))
980  {
982  stmt->setUInt32(0, itr->second);
983  stmt->setUInt32(1, itr->first);
984  trans->Append(stmt);
985  }
986  }
987 
989 }
Definition: CharacterDatabase.h:33
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
PoolGroupQuestMap mPoolQuestGroups
Definition: PoolMgr.h:156
Definition: PreparedStatement.h:74
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
Definition: CharacterDatabase.h:32
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
SearchMap mQuestSearchMap
Definition: PoolMgr.h:160
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void PoolMgr::SpawnPool ( uint32  pool_id)
1059 {
1060  SpawnPool<Pool>(pool_id, 0);
1061  SpawnPool<GameObject>(pool_id, 0);
1062  SpawnPool<Creature>(pool_id, 0);
1063  SpawnPool<Quest>(pool_id, 0);
1064 }

+ Here is the caller graph for this function:

template<typename T >
void PoolMgr::SpawnPool ( uint32  pool_id,
uint64  db_guid_or_pool_id 
)
private
template<>
void PoolMgr::SpawnPool ( uint32  pool_id,
uint64  db_guid 
)
private
1027 {
1028  if (!mPoolCreatureGroups[pool_id].isEmpty())
1029  mPoolCreatureGroups[pool_id].SpawnObject(mSpawnedData, mPoolTemplate[pool_id].MaxLimit, db_guid);
1030 }
PoolTemplateDataMap mPoolTemplate
Definition: PoolMgr.h:152
ActivePoolData mSpawnedData
Definition: PoolMgr.h:163
PoolGroupCreatureMap mPoolCreatureGroups
Definition: PoolMgr.h:153
template<>
void PoolMgr::SpawnPool ( uint32  pool_id,
uint64  db_guid 
)
private
1036 {
1037  if (!mPoolGameobjectGroups[pool_id].isEmpty())
1038  mPoolGameobjectGroups[pool_id].SpawnObject(mSpawnedData, mPoolTemplate[pool_id].MaxLimit, db_guid);
1039 }
PoolTemplateDataMap mPoolTemplate
Definition: PoolMgr.h:152
ActivePoolData mSpawnedData
Definition: PoolMgr.h:163
PoolGroupGameObjectMap mPoolGameobjectGroups
Definition: PoolMgr.h:154
template<>
void PoolMgr::SpawnPool ( uint32  pool_id,
uint64  sub_pool_id 
)
private
1045 {
1046  if (!mPoolPoolGroups[pool_id].isEmpty())
1047  mPoolPoolGroups[pool_id].SpawnObject(mSpawnedData, mPoolTemplate[pool_id].MaxLimit, sub_pool_id);
1048 }
PoolGroupPoolMap mPoolPoolGroups
Definition: PoolMgr.h:155
PoolTemplateDataMap mPoolTemplate
Definition: PoolMgr.h:152
ActivePoolData mSpawnedData
Definition: PoolMgr.h:163
template<>
void PoolMgr::SpawnPool ( uint32  pool_id,
uint64  quest_id 
)
private
1053 {
1054  if (!mPoolQuestGroups[pool_id].isEmpty())
1055  mPoolQuestGroups[pool_id].SpawnObject(mSpawnedData, mPoolTemplate[pool_id].MaxLimit, quest_id);
1056 }
PoolGroupQuestMap mPoolQuestGroups
Definition: PoolMgr.h:156
PoolTemplateDataMap mPoolTemplate
Definition: PoolMgr.h:152
ActivePoolData mSpawnedData
Definition: PoolMgr.h:163
template<typename T >
template void PoolMgr::UpdatePool< Quest > ( uint32  pool_id,
uint64  db_guid_or_pool_id 
)
1097 {
1098  if (uint32 motherpoolid = IsPartOfAPool<Pool>(pool_id))
1099  SpawnPool<Pool>(motherpoolid, pool_id);
1100  else
1101  SpawnPool<T>(pool_id, db_guid_or_pool_id);
1102 }
uint32_t uint32
Definition: Define.h:150

Member Data Documentation

uint32 PoolMgr::max_pool_id
private
SearchMap PoolMgr::mCreatureSearchMap
private
SearchMap PoolMgr::mGameobjectSearchMap
private
PoolGroupCreatureMap PoolMgr::mPoolCreatureGroups
private
PoolGroupGameObjectMap PoolMgr::mPoolGameobjectGroups
private
PoolGroupPoolMap PoolMgr::mPoolPoolGroups
private
PoolGroupQuestMap PoolMgr::mPoolQuestGroups
private
SearchMap PoolMgr::mPoolSearchMap
private
PoolTemplateDataMap PoolMgr::mPoolTemplate
private
PooledQuestRelation PoolMgr::mQuestCreatureRelation
PooledQuestRelation PoolMgr::mQuestGORelation
SearchMap PoolMgr::mQuestSearchMap
private
ActivePoolData PoolMgr::mSpawnedData
private

The documentation for this class was generated from the following files: