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

#include <GarrisonMgr.h>

Public Member Functions

void Initialize ()
 
GarrSiteLevelEntry constGetGarrSiteLevelEntry (uint32 garrSiteId, uint32 level) const
 
std::vector
< GarrSiteLevelPlotInstEntry
const * > const
GetGarrPlotInstForSiteLevel (uint32 garrSiteLevelId) const
 
GameObjectsEntry constGetPlotGameObject (uint32 mapId, uint32 garrPlotInstanceId) const
 
bool IsPlotMatchingBuilding (uint32 garrPlotId, uint32 garrBuildingId) const
 
uint32 GetGarrBuildingPlotInst (uint32 garrBuildingId, uint32 garrSiteLevelPlotInstId) const
 
GarrBuildingEntry constGetPreviousLevelBuilding (uint32 buildingType, uint32 currentLevel) const
 
FinalizeGarrisonPlotGOInfo constGetPlotFinalizeGOInfo (uint32 garrPlotInstanceID) const
 
uint64 GenerateFollowerDbId ()
 
std::list< GarrAbilityEntry
const * > 
RollFollowerAbilities (GarrFollowerEntry const *follower, uint32 quality, uint32 faction, bool initial) const
 
std::list< GarrAbilityEntry
const * > 
GetClassSpecAbilities (GarrFollowerEntry const *follower, uint32 faction) const
 

Static Public Member Functions

static GarrisonMgrInstance ()
 

Private Member Functions

void InitializeDbIdSequences ()
 
void LoadPlotFinalizeGOInfo ()
 
void LoadFollowerClassSpecAbilities ()
 

Private Attributes

std::unordered_map< uint32,
std::vector
< GarrSiteLevelPlotInstEntry
const * > > 
_garrisonPlotInstBySiteLevel
 
std::unordered_map< uint32,
std::unordered_map< uint32,
GameObjectsEntry const * > > 
_garrisonPlots
 
std::unordered_map< uint32,
std::unordered_set< uint32 > > 
_garrisonBuildingsByPlot
 
std::unordered_map< uint64,
uint32
_garrisonBuildingPlotInstances
 
std::unordered_map< uint32,
std::vector< GarrBuildingEntry
const * > > 
_garrisonBuildingsByType
 
std::unordered_map< uint32,
FinalizeGarrisonPlotGOInfo
_finalizePlotGOInfo
 
std::unordered_map< uint32,
GarrAbilities
_garrisonFollowerAbilities [2]
 
std::unordered_map< uint32,
std::list< GarrAbilityEntry
const * > > 
_garrisonFollowerClassSpecAbilities
 
std::set< GarrAbilityEntry
const * > 
_garrisonFollowerRandomTraits
 
uint64 _followerDbIdGenerator = UI64LIT(1)
 

Member Function Documentation

uint64 GarrisonMgr::GenerateFollowerDbId ( )
146 {
148  {
149  TC_LOG_ERROR("misc", "Garrison follower db id overflow! Can't continue, shutting down server. ");
151  }
152 
153  return _followerDbIdGenerator++;
154 }
uint64 _followerDbIdGenerator
Definition: GarrisonMgr.h:74
T max(const T &x, const T &y)
Definition: g3dmath.h:320
Definition: World.h:74
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
static void StopNow(uint8 exitcode)
Definition: World.h:662

+ Here is the call graph for this function:

std::list< GarrAbilityEntry const * > GarrisonMgr::GetClassSpecAbilities ( GarrFollowerEntry const follower,
uint32  faction 
) const
305 {
306  std::list<GarrAbilityEntry const*> abilities;
307  uint32 classSpecId;
308  switch (faction)
309  {
311  classSpecId = follower->HordeGarrClassSpecID;
312  break;
314  classSpecId = follower->AllianceGarrClassSpecID;
315  break;
316  default:
317  return abilities;
318  }
319 
320  if (!sGarrClassSpecStore.LookupEntry(classSpecId))
321  return abilities;
322 
323  auto itr = _garrisonFollowerClassSpecAbilities.find(classSpecId);
324  if (itr != _garrisonFollowerClassSpecAbilities.end())
325  abilities = itr->second;
326 
327  return abilities;
328 }
std::unordered_map< uint32, std::list< GarrAbilityEntry const * > > _garrisonFollowerClassSpecAbilities
Definition: GarrisonMgr.h:71
DB2Storage< GarrClassSpecEntry > sGarrClassSpecStore("GarrClassSpec.db2", GarrClassSpecFormat, HOTFIX_SEL_GARR_CLASS_SPEC)
uint32_t uint32
Definition: Define.h:150
Definition: Garrison.h:27
Definition: Garrison.h:26

+ Here is the caller graph for this function:

uint32 GarrisonMgr::GetGarrBuildingPlotInst ( uint32  garrBuildingId,
uint32  garrSiteLevelPlotInstId 
) const
117 {
118  auto itr = _garrisonBuildingPlotInstances.find(MAKE_PAIR64(garrBuildingId, garrSiteLevelPlotInstId));
119  if (itr != _garrisonBuildingPlotInstances.end())
120  return itr->second;
121 
122  return 0;
123 }
uint64 MAKE_PAIR64(uint32 l, uint32 h)
Definition: ObjectDefines.h:34
std::unordered_map< uint64, uint32 > _garrisonBuildingPlotInstances
Definition: GarrisonMgr.h:67

+ Here is the call graph for this function:

std::vector< GarrSiteLevelPlotInstEntry const * > const * GarrisonMgr::GetGarrPlotInstForSiteLevel ( uint32  garrSiteLevelId) const
86 {
87  auto itr = _garrisonPlotInstBySiteLevel.find(garrSiteLevelId);
88  if (itr != _garrisonPlotInstBySiteLevel.end())
89  return &itr->second;
90 
91  return nullptr;
92 }
std::unordered_map< uint32, std::vector< GarrSiteLevelPlotInstEntry const * > > _garrisonPlotInstBySiteLevel
Definition: GarrisonMgr.h:64
GarrSiteLevelEntry const * GarrisonMgr::GetGarrSiteLevelEntry ( uint32  garrSiteId,
uint32  level 
) const
77 {
78  for (GarrSiteLevelEntry const* garrSiteLevel : sGarrSiteLevelStore)
79  if (garrSiteLevel->SiteID == garrSiteId && garrSiteLevel->Level == level)
80  return garrSiteLevel;
81 
82  return nullptr;
83 }
DB2Storage< GarrSiteLevelEntry > sGarrSiteLevelStore("GarrSiteLevel.db2", GarrSiteLevelFormat, HOTFIX_SEL_GARR_SITE_LEVEL)
Definition: DB2Structure.h:549
FinalizeGarrisonPlotGOInfo const * GarrisonMgr::GetPlotFinalizeGOInfo ( uint32  garrPlotInstanceID) const
137 {
138  auto itr = _finalizePlotGOInfo.find(garrPlotInstanceID);
139  if (itr != _finalizePlotGOInfo.end())
140  return &itr->second;
141 
142  return nullptr;
143 }
std::unordered_map< uint32, FinalizeGarrisonPlotGOInfo > _finalizePlotGOInfo
Definition: GarrisonMgr.h:69
GameObjectsEntry const * GarrisonMgr::GetPlotGameObject ( uint32  mapId,
uint32  garrPlotInstanceId 
) const
95 {
96  auto mapItr = _garrisonPlots.find(mapId);
97  if (mapItr != _garrisonPlots.end())
98  {
99  auto plotItr = mapItr->second.find(garrPlotInstanceId);
100  if (plotItr != mapItr->second.end())
101  return plotItr->second;
102  }
103 
104  return nullptr;
105 }
std::unordered_map< uint32, std::unordered_map< uint32, GameObjectsEntry const * > > _garrisonPlots
Definition: GarrisonMgr.h:65
GarrBuildingEntry const * GarrisonMgr::GetPreviousLevelBuilding ( uint32  buildingType,
uint32  currentLevel 
) const
126 {
127  auto itr = _garrisonBuildingsByType.find(buildingType);
128  if (itr != _garrisonBuildingsByType.end())
129  for (GarrBuildingEntry const* building : itr->second)
130  if (building->Level == currentLevel - 1)
131  return building;
132 
133  return nullptr;
134 }
Definition: DB2Structure.h:439
std::unordered_map< uint32, std::vector< GarrBuildingEntry const * > > _garrisonBuildingsByType
Definition: GarrisonMgr.h:68
uint32 Level
Definition: DB2Structure.h:446
void GarrisonMgr::Initialize ( )
34 {
36  _garrisonPlotInstBySiteLevel[plotInstance->GarrSiteLevelID].push_back(plotInstance);
37 
38  for (GameObjectsEntry const* gameObject : sGameObjectsStore)
39  if (gameObject->Type == GAMEOBJECT_TYPE_GARRISON_PLOT)
40  _garrisonPlots[gameObject->MapID][gameObject->Data[0]] = gameObject;
41 
42  for (GarrPlotBuildingEntry const* plotBuilding : sGarrPlotBuildingStore)
43  _garrisonBuildingsByPlot[plotBuilding->GarrPlotID].insert(plotBuilding->GarrBuildingID);
44 
45  for (GarrBuildingPlotInstEntry const* buildingPlotInst : sGarrBuildingPlotInstStore)
46  _garrisonBuildingPlotInstances[MAKE_PAIR64(buildingPlotInst->GarrBuildingID, buildingPlotInst->GarrSiteLevelPlotInstID)] = buildingPlotInst->ID;
47 
48  for (GarrBuildingEntry const* building : sGarrBuildingStore)
49  _garrisonBuildingsByType[building->Type].push_back(building);
50 
51  for (GarrFollowerXAbilityEntry const* followerAbility : sGarrFollowerXAbilityStore)
52  {
53  if (GarrAbilityEntry const* ability = sGarrAbilityStore.LookupEntry(followerAbility->GarrAbilityID))
54  {
55  if (ability->FollowerTypeID != FOLLOWER_TYPE_GARRISON)
56  continue;
57 
58  if (!(ability->Flags & GARRISON_ABILITY_CANNOT_ROLL) && ability->Flags & GARRISON_ABILITY_FLAG_TRAIT)
59  _garrisonFollowerRandomTraits.insert(ability);
60 
61  if (followerAbility->FactionIndex < 2)
62  {
63  if (ability->Flags & GARRISON_ABILITY_FLAG_TRAIT)
64  _garrisonFollowerAbilities[followerAbility->FactionIndex][followerAbility->GarrFollowerID].Traits.insert(ability);
65  else
66  _garrisonFollowerAbilities[followerAbility->FactionIndex][followerAbility->GarrFollowerID].Counters.insert(ability);
67  }
68  }
69  }
70 
74 }
std::unordered_map< uint32, std::unordered_map< uint32, GameObjectsEntry const * > > _garrisonPlots
Definition: GarrisonMgr.h:65
Definition: DB2Structure.h:563
DB2Storage< GarrBuildingEntry > sGarrBuildingStore("GarrBuilding.db2", GarrBuildingFormat, HOTFIX_SEL_GARR_BUILDING)
Definition: DB2Structure.h:439
Definition: Garrison.h:49
DB2Storage< GarrBuildingPlotInstEntry > sGarrBuildingPlotInstStore("GarrBuildingPlotInst.db2", GarrBuildingPlotInstFormat, HOTFIX_SEL_GARR_BUILDING_PLOT_INST)
Definition: Garrison.h:48
DB2Storage< GameObjectsEntry > sGameObjectsStore("GameObjects.db2", GameObjectsFormat, HOTFIX_SEL_GAMEOBJECTS)
Definition: DB2Structure.h:535
DB2Storage< GarrAbilityEntry > sGarrAbilityStore("GarrAbility.db2", GarrAbilityFormat, HOTFIX_SEL_GARR_ABILITY)
DB2Storage< GarrPlotBuildingEntry > sGarrPlotBuildingStore("GarrPlotBuilding.db2", GarrPlotBuildingFormat, HOTFIX_SEL_GARR_PLOT_BUILDING)
void LoadFollowerClassSpecAbilities()
Definition: GarrisonMgr.cpp:422
Definition: DB2Structure.h:400
uint64 MAKE_PAIR64(uint32 l, uint32 h)
Definition: ObjectDefines.h:34
Definition: Garrison.h:42
std::unordered_map< uint32, GarrAbilities > _garrisonFollowerAbilities[2]
Definition: GarrisonMgr.h:70
DB2Storage< GarrFollowerXAbilityEntry > sGarrFollowerXAbilityStore("GarrFollowerXAbility.db2", GarrFollowerXAbilityFormat, HOTFIX_SEL_GARR_FOLLOWER_X_ABILITY)
std::set< GarrAbilityEntry const * > _garrisonFollowerRandomTraits
Definition: GarrisonMgr.h:72
void LoadPlotFinalizeGOInfo()
Definition: GarrisonMgr.cpp:336
std::unordered_map< uint32, std::vector< GarrBuildingEntry const * > > _garrisonBuildingsByType
Definition: GarrisonMgr.h:68
Definition: DB2Structure.h:467
DB2Storage< GarrSiteLevelPlotInstEntry > sGarrSiteLevelPlotInstStore("GarrSiteLevelPlotInst.db2", GarrSiteLevelPlotInstFormat, HOTFIX_SEL_GARR_SITE_LEVEL_PLOT_INST)
std::unordered_map< uint32, std::unordered_set< uint32 > > _garrisonBuildingsByPlot
Definition: GarrisonMgr.h:66
Definition: DB2Structure.h:427
std::unordered_map< uint32, std::vector< GarrSiteLevelPlotInstEntry const * > > _garrisonPlotInstBySiteLevel
Definition: GarrisonMgr.h:64
void InitializeDbIdSequences()
Definition: GarrisonMgr.cpp:330
Definition: SharedDefines.h:2104
Definition: DB2Structure.h:514
std::unordered_map< uint64, uint32 > _garrisonBuildingPlotInstances
Definition: GarrisonMgr.h:67

+ Here is the call graph for this function:

void GarrisonMgr::InitializeDbIdSequences ( )
private
331 {
332  if (QueryResult result = CharacterDatabase.Query("SELECT MAX(dbId) FROM character_garrison_followers"))
333  _followerDbIdGenerator = (*result)[0].GetUInt64() + 1;
334 }
uint64 _followerDbIdGenerator
Definition: GarrisonMgr.h:74
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GarrisonMgr & GarrisonMgr::Instance ( )
static
28 {
29  static GarrisonMgr instance;
30  return instance;
31 }
Definition: GarrisonMgr.h:41
bool GarrisonMgr::IsPlotMatchingBuilding ( uint32  garrPlotId,
uint32  garrBuildingId 
) const
108 {
109  auto plotItr = _garrisonBuildingsByPlot.find(garrPlotId);
110  if (plotItr != _garrisonBuildingsByPlot.end())
111  return plotItr->second.count(garrBuildingId) > 0;
112 
113  return false;
114 }
std::unordered_map< uint32, std::unordered_set< uint32 > > _garrisonBuildingsByPlot
Definition: GarrisonMgr.h:66
void GarrisonMgr::LoadFollowerClassSpecAbilities ( )
private
423 {
424  QueryResult result = WorldDatabase.Query("SELECT classSpecId, abilityId FROM garrison_follower_class_spec_abilities");
425  if (!result)
426  {
427  TC_LOG_INFO("server.loading", ">> Loaded 0 garrison follower class spec abilities. DB table `garrison_follower_class_spec_abilities` is empty.");
428  return;
429  }
430 
431  uint32 msTime = getMSTime();
432  uint32 count = 0;
433  do
434  {
435  Field* fields = result->Fetch();
436  uint32 classSpecId = fields[0].GetUInt32();
437  uint32 abilityId = fields[1].GetUInt32();
438 
439  if (!sGarrClassSpecStore.LookupEntry(classSpecId))
440  {
441  TC_LOG_ERROR("sql.sql", "Non-existing GarrClassSpec.db2 entry %u was referenced in `garrison_follower_class_spec_abilities` by row (%u, %u).", classSpecId, classSpecId, abilityId);
442  continue;
443  }
444 
445  GarrAbilityEntry const* ability = sGarrAbilityStore.LookupEntry(abilityId);
446  if (!ability)
447  {
448  TC_LOG_ERROR("sql.sql", "Non-existing GarrAbility.db2 entry %u was referenced in `garrison_follower_class_spec_abilities` by row (%u, %u).", abilityId, classSpecId, abilityId);
449  continue;
450  }
451 
452  _garrisonFollowerClassSpecAbilities[classSpecId].push_back(ability);
453  ++count;
454 
455  } while (result->NextRow());
456 
457  for (auto& pair : _garrisonFollowerClassSpecAbilities)
458  pair.second.sort();
459 
460  TC_LOG_INFO("server.loading", ">> Loaded %u garrison follower class spec abilities in %u.", count, GetMSTimeDiffToNow(msTime));
461 }
std::unordered_map< uint32, std::list< GarrAbilityEntry const * > > _garrisonFollowerClassSpecAbilities
Definition: GarrisonMgr.h:71
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32 getMSTime()
Definition: Timer.h:24
DB2Storage< GarrAbilityEntry > sGarrAbilityStore("GarrAbility.db2", GarrAbilityFormat, HOTFIX_SEL_GARR_ABILITY)
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
DB2Storage< GarrClassSpecEntry > sGarrClassSpecStore("GarrClassSpec.db2", GarrClassSpecFormat, HOTFIX_SEL_GARR_CLASS_SPEC)
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
Definition: DB2Structure.h:427
uint32 GetUInt32() const
Definition: Field.h:146
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void GarrisonMgr::LoadPlotFinalizeGOInfo ( )
private
337 {
338  // 0 1 2 3 4 5 6
339  QueryResult result = WorldDatabase.Query("SELECT garrPlotInstanceId, hordeGameObjectId, hordeX, hordeY, hordeZ, hordeO, hordeAnimKitId, "
340  // 7 8 9 10 11 12
341  "allianceGameObjectId, allianceX, allianceY, allianceZ, allianceO, allianceAnimKitId FROM garrison_plot_finalize_info");
342  if (!result)
343  {
344  TC_LOG_INFO("server.loading", ">> Loaded 0 garrison follower class spec abilities. DB table `garrison_plot_finalize_info` is empty.");
345  return;
346  }
347 
348  uint32 msTime = getMSTime();
349  do
350  {
351  Field* fields = result->Fetch();
352  uint32 garrPlotInstanceId = fields[0].GetUInt32();
353  uint32 hordeGameObjectId = fields[1].GetUInt32();
354  uint32 allianceGameObjectId = fields[7].GetUInt32();
355  uint16 hordeAnimKitId = fields[6].GetUInt16();
356  uint16 allianceAnimKitId = fields[12].GetUInt16();
357 
358  if (!sGarrPlotInstanceStore.LookupEntry(garrPlotInstanceId))
359  {
360  TC_LOG_ERROR("sql.sql", "Non-existing GarrPlotInstance.db2 entry %u was referenced in `garrison_plot_finalize_info`.", garrPlotInstanceId);
361  continue;
362  }
363 
364  GameObjectTemplate const* goTemplate = sObjectMgr->GetGameObjectTemplate(hordeGameObjectId);
365  if (!goTemplate)
366  {
367  TC_LOG_ERROR("sql.sql", "Non-existing gameobject_template entry %u was referenced in `garrison_plot_finalize_info`.`hordeGameObjectId` for garrPlotInstanceId %u.",
368  hordeGameObjectId, garrPlotInstanceId);
369  continue;
370  }
371 
372  if (goTemplate->type != GAMEOBJECT_TYPE_GOOBER)
373  {
374  TC_LOG_ERROR("sql.sql", "Invalid gameobject type %u (entry %u) was referenced in `garrison_plot_finalize_info`.`hordeGameObjectId` for garrPlotInstanceId %u.",
375  goTemplate->type, hordeGameObjectId, garrPlotInstanceId);
376  continue;
377  }
378 
379  goTemplate = sObjectMgr->GetGameObjectTemplate(allianceGameObjectId);
380  if (!goTemplate)
381  {
382  TC_LOG_ERROR("sql.sql", "Non-existing gameobject_template entry %u was referenced in `garrison_plot_finalize_info`.`allianceGameObjectId` for garrPlotInstanceId %u.",
383  allianceGameObjectId, garrPlotInstanceId);
384  continue;
385  }
386 
387  if (goTemplate->type != GAMEOBJECT_TYPE_GOOBER)
388  {
389  TC_LOG_ERROR("sql.sql", "Invalid gameobject type %u (entry %u) was referenced in `garrison_plot_finalize_info`.`allianceGameObjectId` for garrPlotInstanceId %u.",
390  goTemplate->type, allianceGameObjectId, garrPlotInstanceId);
391  continue;
392  }
393 
394  if (hordeAnimKitId && !sAnimKitStore.LookupEntry(hordeAnimKitId))
395  {
396  TC_LOG_ERROR("sql.sql", "Non-existing AnimKit.dbc entry %u was referenced in `garrison_plot_finalize_info`.`hordeAnimKitId` for garrPlotInstanceId %u.",
397  hordeAnimKitId, garrPlotInstanceId);
398  continue;
399  }
400 
401  if (allianceAnimKitId && !sAnimKitStore.LookupEntry(allianceAnimKitId))
402  {
403  TC_LOG_ERROR("sql.sql", "Non-existing AnimKit.dbc entry %u was referenced in `garrison_plot_finalize_info`.`allianceAnimKitId` for garrPlotInstanceId %u.",
404  allianceAnimKitId, garrPlotInstanceId);
405  continue;
406  }
407 
408  FinalizeGarrisonPlotGOInfo& info = _finalizePlotGOInfo[garrPlotInstanceId];
409  info.FactionInfo[GARRISON_FACTION_INDEX_HORDE].GameObjectId = hordeGameObjectId;
410  info.FactionInfo[GARRISON_FACTION_INDEX_HORDE].Pos.Relocate(fields[2].GetFloat(), fields[3].GetFloat(), fields[4].GetFloat(), fields[5].GetFloat());
411  info.FactionInfo[GARRISON_FACTION_INDEX_HORDE].AnimKitId = hordeAnimKitId;
412 
413  info.FactionInfo[GARRISON_FACTION_INDEX_ALLIANCE].GameObjectId = allianceGameObjectId;
414  info.FactionInfo[GARRISON_FACTION_INDEX_ALLIANCE].Pos.Relocate(fields[8].GetFloat(), fields[9].GetFloat(), fields[10].GetFloat(), fields[11].GetFloat());
415  info.FactionInfo[GARRISON_FACTION_INDEX_ALLIANCE].AnimKitId = allianceAnimKitId;
416 
417  } while (result->NextRow());
418 
419  TC_LOG_INFO("server.loading", ">> Loaded %u garrison plot finalize entries in %u.", uint32(_finalizePlotGOInfo.size()), GetMSTimeDiffToNow(msTime));
420 }
uint32 GameObjectId
Definition: GarrisonMgr.h:29
DB2Storage< GarrPlotInstanceEntry > sGarrPlotInstanceStore("GarrPlotInstance.db2", GarrPlotInstanceFormat, HOTFIX_SEL_GARR_PLOT_INSTANCE)
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32 getMSTime()
Definition: Timer.h:24
Definition: GameObject.h:34
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
#define sObjectMgr
Definition: ObjectMgr.h:1567
void Relocate(float x, float y)
Definition: Position.h:67
struct FinalizeGarrisonPlotGOInfo::@279 FactionInfo[2]
std::unordered_map< uint32, FinalizeGarrisonPlotGOInfo > _finalizePlotGOInfo
Definition: GarrisonMgr.h:69
Position Pos
Definition: GarrisonMgr.h:30
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
uint16_t uint16
Definition: Define.h:151
uint16 GetUInt16() const
Definition: Field.h:108
Definition: Garrison.h:27
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
Definition: SharedDefines.h:2075
uint32 GetUInt32() const
Definition: Field.h:146
DBCStorage< AnimKitEntry > sAnimKitStore(AnimKitfmt)
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint32_t uint32
Definition: g3dmath.h:168
Definition: Garrison.h:26
Definition: GarrisonMgr.h:25
uint32 type
Definition: GameObject.h:37
uint16 AnimKitId
Definition: GarrisonMgr.h:31

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::list< GarrAbilityEntry const * > GarrisonMgr::RollFollowerAbilities ( GarrFollowerEntry const follower,
uint32  quality,
uint32  faction,
bool  initial 
) const
168 {
169  ASSERT(faction < 2);
170 
171  bool hasForcedExclusiveTrait = false;
172  std::list<GarrAbilityEntry const*> result;
173  uint32 slots[2] = { AbilitiesForQuality[quality][0], AbilitiesForQuality[quality][1] };
174 
175  GarrAbilities const* abilities = nullptr;
176  auto itr = _garrisonFollowerAbilities[faction].find(follower->ID);
177  if (itr != _garrisonFollowerAbilities[faction].end())
178  abilities = &itr->second;
179 
180  std::list<GarrAbilityEntry const*> abilityList, forcedAbilities, traitList, forcedTraits;
181  if (abilities)
182  {
183  for (GarrAbilityEntry const* ability : abilities->Counters)
184  {
186  continue;
187  else if (ability->Flags & GARRISON_ABILITY_ALLIANCE_ONLY && faction != GARRISON_FACTION_INDEX_ALLIANCE)
188  continue;
189 
191  forcedAbilities.push_back(ability);
192  else
193  abilityList.push_back(ability);
194  }
195 
196  for (GarrAbilityEntry const* ability : abilities->Traits)
197  {
199  continue;
200  else if (ability->Flags & GARRISON_ABILITY_ALLIANCE_ONLY && faction != GARRISON_FACTION_INDEX_ALLIANCE)
201  continue;
202 
204  forcedTraits.push_back(ability);
205  else
206  traitList.push_back(ability);
207  }
208  }
209 
210  Trinity::Containers::RandomResizeList(abilityList, std::max<int32>(0, slots[0] - forcedAbilities.size()));
211  Trinity::Containers::RandomResizeList(traitList, std::max<int32>(0, slots[1] - forcedTraits.size()));
212 
213  // Add abilities specified in GarrFollowerXAbility.db2 before generic classspec ones on follower creation
214  if (initial)
215  {
216  forcedAbilities.splice(forcedAbilities.end(), abilityList);
217  forcedTraits.splice(forcedTraits.end(), traitList);
218  }
219 
220  forcedAbilities.sort();
221  abilityList.sort();
222  forcedTraits.sort();
223  traitList.sort();
224 
225  // check if we have a trait from exclusive category
226  for (GarrAbilityEntry const* ability : forcedTraits)
227  {
228  if (ability->Flags & GARRISON_ABILITY_FLAG_EXCLUSIVE)
229  {
230  hasForcedExclusiveTrait = true;
231  break;
232  }
233  }
234 
235  if (slots[0] > forcedAbilities.size() + abilityList.size())
236  {
237  std::list<GarrAbilityEntry const*> classSpecAbilities = GetClassSpecAbilities(follower, faction);
238  std::list<GarrAbilityEntry const*> classSpecAbilitiesTemp, classSpecAbilitiesTemp2;
239  classSpecAbilitiesTemp2.swap(abilityList);
240  std::set_difference(classSpecAbilities.begin(), classSpecAbilities.end(), forcedAbilities.begin(), forcedAbilities.end(), std::back_inserter(classSpecAbilitiesTemp));
241  std::set_union(classSpecAbilitiesTemp.begin(), classSpecAbilitiesTemp.end(), classSpecAbilitiesTemp2.begin(), classSpecAbilitiesTemp2.end(), std::back_inserter(abilityList));
242 
243  Trinity::Containers::RandomResizeList(abilityList, std::max<int32>(0, slots[0] - forcedAbilities.size()));
244  }
245 
246  if (slots[1] > forcedTraits.size() + traitList.size())
247  {
248  std::list<GarrAbilityEntry const*> genericTraits, genericTraitsTemp;
249  for (GarrAbilityEntry const* ability : _garrisonFollowerRandomTraits)
250  {
252  continue;
253  else if (ability->Flags & GARRISON_ABILITY_ALLIANCE_ONLY && faction != GARRISON_FACTION_INDEX_ALLIANCE)
254  continue;
255 
256  // forced exclusive trait exists, skip other ones entirely
257  if (hasForcedExclusiveTrait && ability->Flags & GARRISON_ABILITY_FLAG_EXCLUSIVE)
258  continue;
259 
260  genericTraitsTemp.push_back(ability);
261  }
262 
263  std::set_difference(genericTraitsTemp.begin(), genericTraitsTemp.end(), forcedTraits.begin(), forcedTraits.end(), std::back_inserter(genericTraits));
264  genericTraits.splice(genericTraits.begin(), traitList);
265  // "split" the list into two parts [nonexclusive, exclusive] to make selection later easier
266  genericTraits.sort([](GarrAbilityEntry const* a1, GarrAbilityEntry const* a2)
267  {
270  if (e1 != e2)
271  return e1 < e2;
272 
273  return a1->ID < a2->ID;
274  });
275  genericTraits.unique();
276 
277  std::size_t firstExclusive = 0, total = genericTraits.size();
278  for (auto genericTraitItr = genericTraits.begin(); genericTraitItr != genericTraits.end(); ++genericTraitItr, ++firstExclusive)
279  if ((*genericTraitItr)->Flags & GARRISON_ABILITY_FLAG_EXCLUSIVE)
280  break;
281 
282  while (traitList.size() < size_t(std::max<int32>(0, slots[1] - forcedTraits.size())) && total)
283  {
284  auto genericTraitItr = genericTraits.begin();
285  std::advance(genericTraitItr, urand(0, total-- - 1));
286  if ((*genericTraitItr)->Flags & GARRISON_ABILITY_FLAG_EXCLUSIVE)
287  total = firstExclusive; // selected exclusive trait - no other can be selected now
288  else
289  --firstExclusive;
290 
291  traitList.push_back(*genericTraitItr);
292  genericTraits.erase(genericTraitItr);
293  }
294  }
295 
296  result.splice(result.end(), forcedAbilities);
297  result.splice(result.end(), abilityList);
298  result.splice(result.end(), forcedTraits);
299  result.splice(result.end(), traitList);
300 
301  return result;
302 }
std::unordered_set< GarrAbilityEntry const * > Traits
Definition: GarrisonMgr.h:38
uint32 Flags
Definition: DB2Structure.h:430
void RandomResizeList(std::list< T > &list, uint32 size)
Definition: Containers.h:34
Definition: Garrison.h:51
void advance(octet_iterator &it, distance_type n, octet_iterator end)
Definition: checked.h:190
Definition: Garrison.h:50
std::unordered_map< uint32, GarrAbilities > _garrisonFollowerAbilities[2]
Definition: GarrisonMgr.h:70
std::set< GarrAbilityEntry const * > _garrisonFollowerRandomTraits
Definition: GarrisonMgr.h:72
std::unordered_set< GarrAbilityEntry const * > Counters
Definition: GarrisonMgr.h:37
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
std::list< GarrAbilityEntry const * > GetClassSpecAbilities(GarrFollowerEntry const *follower, uint32 faction) const
Definition: GarrisonMgr.cpp:304
uint32_t uint32
Definition: Define.h:150
uint32 ID
Definition: DB2Structure.h:429
Definition: Garrison.h:27
Definition: DB2Structure.h:427
uint32 const AbilitiesForQuality[][2]
Definition: GarrisonMgr.cpp:156
#define ASSERT
Definition: Errors.h:55
Definition: Garrison.h:52
Definition: Garrison.h:26
Definition: Garrison.h:53
Definition: GarrisonMgr.h:35

+ Here is the call graph for this function:

Member Data Documentation

std::unordered_map<uint32 , FinalizeGarrisonPlotGOInfo> GarrisonMgr::_finalizePlotGOInfo
private
uint64 GarrisonMgr::_followerDbIdGenerator = UI64LIT(1)
private
std::unordered_map<uint64 , uint32 > GarrisonMgr::_garrisonBuildingPlotInstances
private
std::unordered_map<uint32 , std::unordered_set<uint32> > GarrisonMgr::_garrisonBuildingsByPlot
private
std::unordered_map<uint32 , std::vector<GarrBuildingEntry const*> > GarrisonMgr::_garrisonBuildingsByType
private
std::unordered_map<uint32 , GarrAbilities> GarrisonMgr::_garrisonFollowerAbilities[2]
private
std::unordered_map<uint32 , std::list<GarrAbilityEntry const*> > GarrisonMgr::_garrisonFollowerClassSpecAbilities
private
std::set<GarrAbilityEntry const*> GarrisonMgr::_garrisonFollowerRandomTraits
private
std::unordered_map<uint32 , std::vector<GarrSiteLevelPlotInstEntry const*> > GarrisonMgr::_garrisonPlotInstBySiteLevel
private
std::unordered_map<uint32 , std::unordered_map<uint32 , GameObjectsEntry const*> > GarrisonMgr::_garrisonPlots
private

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