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

#include <Garrison.h>

Classes

struct  Building
 
struct  Follower
 
struct  Plot
 

Public Member Functions

 Garrison (Player *owner)
 
bool LoadFromDB (PreparedQueryResult garrison, PreparedQueryResult blueprints, PreparedQueryResult buildings, PreparedQueryResult followers, PreparedQueryResult abilities)
 
void SaveToDB (SQLTransaction trans)
 
bool Create (uint32 garrSiteId)
 
void Delete ()
 
void Upgrade ()
 
void Enter () const
 
void Leave () const
 
GarrisonFactionIndex GetFaction () const
 
std::vector< Plot * > GetPlots ()
 
PlotGetPlot (uint32 garrPlotInstanceId)
 
Plot constGetPlot (uint32 garrPlotInstanceId) const
 
void LearnBlueprint (uint32 garrBuildingId)
 
void UnlearnBlueprint (uint32 garrBuildingId)
 
void PlaceBuilding (uint32 garrPlotInstanceId, uint32 garrBuildingId)
 
void CancelBuildingConstruction (uint32 garrPlotInstanceId)
 
void ActivateBuilding (uint32 garrPlotInstanceId)
 
void AddFollower (uint32 garrFollowerId)
 
Follower constGetFollower (uint64 dbId) const
 
void SendInfo ()
 
void SendRemoteInfo () const
 
void SendBlueprintAndSpecializationData ()
 
void SendBuildingLandmarks (Player *receiver) const
 
void ResetFollowerActivationLimit ()
 

Static Public Member Functions

static void DeleteFromDB (ObjectGuid::LowType ownerGuid, SQLTransaction trans)
 

Private Member Functions

MapFindMap () const
 
void InitializePlots ()
 
GarrisonError CheckBuildingPlacement (uint32 garrPlotInstanceId, uint32 garrBuildingId) const
 
GarrisonError CheckBuildingRemoval (uint32 garrPlotInstanceId) const
 

Private Attributes

Player_owner
 
GarrSiteLevelEntry const_siteLevel
 
uint32 _followerActivationsRemainingToday
 
std::unordered_map< uint32, Plot_plots
 
std::unordered_set< uint32_knownBuildings
 
std::unordered_map< uint64,
Follower
_followers
 
std::unordered_set< uint32_followerIds
 

Constructor & Destructor Documentation

Garrison::Garrison ( Player owner)
explicit
27 {
28 }
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
Player * _owner
Definition: Garrison.h:159
uint32 _followerActivationsRemainingToday
Definition: Garrison.h:161

Member Function Documentation

void Garrison::ActivateBuilding ( uint32  garrPlotInstanceId)
465 {
466  if (Plot* plot = GetPlot(garrPlotInstanceId))
467  {
468  if (plot->BuildingInfo.CanActivate() && plot->BuildingInfo.PacketInfo && !plot->BuildingInfo.PacketInfo->Active)
469  {
470  plot->BuildingInfo.PacketInfo->Active = true;
471  if (Map* map = FindMap())
472  {
473  plot->DeleteGameObject(map);
474  if (GameObject* go = plot->CreateGameObject(map, GetFaction()))
475  map->AddToMap(go);
476  }
477 
479  buildingActivated.GarrPlotInstanceID = garrPlotInstanceId;
480  _owner->SendDirectMessage(buildingActivated.Write());
481  }
482  }
483 }
Definition: GarrisonPackets.h:315
Plot * GetPlot(uint32 garrPlotInstanceId)
Definition: Garrison.cpp:319
Player * _owner
Definition: Garrison.h:159
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:290
Definition: GameObject.h:880
uint32 GarrPlotInstanceID
Definition: GarrisonPackets.h:322
Definition: Map.h:259
Map * FindMap() const
Definition: Garrison.cpp:588
GarrisonFactionIndex GetFaction() const
Definition: Garrison.cpp:304

+ Here is the call graph for this function:

void Garrison::AddFollower ( uint32  garrFollowerId)
486 {
488  GarrFollowerEntry const* followerEntry = sGarrFollowerStore.LookupEntry(garrFollowerId);
489  if (_followerIds.count(garrFollowerId) || !followerEntry)
490  {
491  addFollowerResult.Result = GARRISON_GENERIC_UNKNOWN_ERROR;
492  _owner->SendDirectMessage(addFollowerResult.Write());
493  return;
494  }
495 
496  _followerIds.insert(garrFollowerId);
497  uint64 dbId = sGarrisonMgr.GenerateFollowerDbId();
498  Follower& follower = _followers[dbId];
499  follower.PacketInfo.DbID = dbId;
500  follower.PacketInfo.GarrFollowerID = garrFollowerId;
501  follower.PacketInfo.Quality = followerEntry->Quality; // TODO: handle magic upgrades
502  follower.PacketInfo.FollowerLevel = followerEntry->Level;
503  follower.PacketInfo.ItemLevelWeapon = followerEntry->ItemLevelWeapon;
504  follower.PacketInfo.ItemLevelArmor = followerEntry->ItemLevelArmor;
505  follower.PacketInfo.Xp = 0;
506  follower.PacketInfo.CurrentBuildingID = 0;
507  follower.PacketInfo.CurrentMissionID = 0;
508  follower.PacketInfo.AbilityID = sGarrisonMgr.RollFollowerAbilities(followerEntry, follower.PacketInfo.Quality, GetFaction(), true);
509  follower.PacketInfo.FollowerStatus = 0;
510 
511  addFollowerResult.Follower = follower.PacketInfo;
512  _owner->SendDirectMessage(addFollowerResult.Write());
513 
514  _owner->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECRUIT_GARRISON_FOLLOWER, follower.PacketInfo.DbID);
515 }
std::unordered_set< uint32 > _followerIds
Definition: Garrison.h:166
DB2Storage< GarrFollowerEntry > sGarrFollowerStore("GarrFollower.db2", GarrFollowerFormat, HOTFIX_SEL_GARR_FOLLOWER)
uint32 Result
Definition: GarrisonPackets.h:300
uint32 Level
Definition: DB2Structure.h:499
uint32 ItemLevelWeapon
Definition: DB2Structure.h:500
Player * _owner
Definition: Garrison.h:159
Definition: Garrison.h:70
uint64_t uint64
Definition: Define.h:149
#define sGarrisonMgr
Definition: GarrisonMgr.h:77
uint32 ItemLevelArmor
Definition: DB2Structure.h:501
std::unordered_map< uint64, Follower > _followers
Definition: Garrison.h:165
Definition: DB2Structure.h:486
uint32 Quality
Definition: DB2Structure.h:494
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:273
GarrisonFollower Follower
Definition: GarrisonPackets.h:299
Definition: GarrisonPackets.h:292
GarrisonFactionIndex GetFaction() const
Definition: Garrison.cpp:304

+ Here is the call graph for this function:

void Garrison::CancelBuildingConstruction ( uint32  garrPlotInstanceId)
417 {
419  buildingRemoved.Result = CheckBuildingRemoval(garrPlotInstanceId);
420  if (buildingRemoved.Result == GARRISON_SUCCESS)
421  {
422  Plot* plot = GetPlot(garrPlotInstanceId);
423 
424  buildingRemoved.GarrPlotInstanceID = garrPlotInstanceId;
425  buildingRemoved.GarrBuildingID = plot->BuildingInfo.PacketInfo->GarrBuildingID;
426 
427  Map* map = FindMap();
428  if (map)
429  plot->DeleteGameObject(map);
430 
431  plot->ClearBuildingInfo(_owner);
432  _owner->SendDirectMessage(buildingRemoved.Write());
433 
434  GarrBuildingEntry const* constructing = sGarrBuildingStore.AssertEntry(buildingRemoved.GarrBuildingID);
435  // Refund construction/upgrade cost
436  _owner->ModifyCurrency(constructing->CostCurrencyID, constructing->CostCurrencyAmount, false, true);
437  _owner->ModifyMoney(constructing->CostMoney * GOLD, false);
438 
439  if (constructing->Level > 1)
440  {
441  // Restore previous level building
442  GarrBuildingEntry const* restored = sGarrisonMgr.GetPreviousLevelBuilding(constructing->Type, constructing->Level);
443  ASSERT(restored);
444 
446  placeBuildingResult.Result = GARRISON_SUCCESS;
447  placeBuildingResult.BuildingInfo.GarrPlotInstanceID = garrPlotInstanceId;
448  placeBuildingResult.BuildingInfo.GarrBuildingID = restored->ID;
449  placeBuildingResult.BuildingInfo.TimeBuilt = time(nullptr);
450  placeBuildingResult.BuildingInfo.Active = true;
451 
452  plot->SetBuildingInfo(placeBuildingResult.BuildingInfo, _owner);
453  _owner->SendDirectMessage(placeBuildingResult.Write());
454  }
455 
456  if (map)
457  if (GameObject* go = plot->CreateGameObject(map, GetFaction()))
458  map->AddToMap(go);
459  }
460  else
461  _owner->SendDirectMessage(buildingRemoved.Write());
462 }
time_t TimeBuilt
Definition: GarrisonPackets.h:72
DB2Storage< GarrBuildingEntry > sGarrBuildingStore("GarrBuilding.db2", GarrBuildingFormat, HOTFIX_SEL_GARR_BUILDING)
Definition: DB2Structure.h:439
uint32 ID
Definition: DB2Structure.h:441
Plot * GetPlot(uint32 garrPlotInstanceId)
Definition: Garrison.cpp:319
Definition: GarrisonPackets.h:192
uint32 GarrBuildingID
Definition: GarrisonPackets.h:201
GarrisonError CheckBuildingRemoval(uint32 garrPlotInstanceId) const
Definition: Garrison.cpp:646
Player * _owner
Definition: Garrison.h:159
bool Active
Definition: GarrisonPackets.h:75
uint32 Type
Definition: DB2Structure.h:445
Definition: Garrison.h:58
bool AddToMap(T *)
Definition: Map.cpp:566
#define sGarrisonMgr
Definition: GarrisonMgr.h:77
Definition: GameObject.h:880
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:186
Definition: Map.h:259
Definition: SharedDefines.h:232
int32 CostMoney
Definition: DB2Structure.h:464
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:202
uint32 Level
Definition: DB2Structure.h:446
uint32 Result
Definition: GarrisonPackets.h:199
#define ASSERT
Definition: Errors.h:55
uint32 GarrPlotInstanceID
Definition: GarrisonPackets.h:70
GarrisonBuildingInfo BuildingInfo
Definition: GarrisonPackets.h:177
uint32 Result
Definition: GarrisonPackets.h:176
int32 CostCurrencyAmount
Definition: DB2Structure.h:453
Map * FindMap() const
Definition: Garrison.cpp:588
uint32 CostCurrencyID
Definition: DB2Structure.h:452
GarrisonFactionIndex GetFaction() const
Definition: Garrison.cpp:304
uint32 GarrPlotInstanceID
Definition: GarrisonPackets.h:200
uint32 GarrBuildingID
Definition: GarrisonPackets.h:71

+ Here is the call graph for this function:

GarrisonError Garrison::CheckBuildingPlacement ( uint32  garrPlotInstanceId,
uint32  garrBuildingId 
) const
private
594 {
595  GarrPlotInstanceEntry const* plotInstance = sGarrPlotInstanceStore.LookupEntry(garrPlotInstanceId);
596  Plot const* plot = GetPlot(garrPlotInstanceId);
597  if (!plotInstance || !plot)
599 
600  GarrBuildingEntry const* building = sGarrBuildingStore.LookupEntry(garrBuildingId);
601  if (!building)
603 
604  if (!sGarrisonMgr.IsPlotMatchingBuilding(plotInstance->GarrPlotID, garrBuildingId))
606 
607  // Cannot place buldings of higher level than garrison level
608  if (building->Level > _siteLevel->Level)
610 
612  {
613  if (!_knownBuildings.count(garrBuildingId))
615  }
616  else // Building is built as a quest reward
618 
619  // Check all plots to find if we already have this building
620  GarrBuildingEntry const* existingBuilding;
621  for (auto const& p : _plots)
622  {
623  if (p.second.BuildingInfo.PacketInfo)
624  {
625  existingBuilding = sGarrBuildingStore.AssertEntry(p.second.BuildingInfo.PacketInfo->GarrBuildingID);
626  if (existingBuilding->Type == building->Type)
627  if (p.first != garrPlotInstanceId || existingBuilding->Level + 1 != building->Level) // check if its an upgrade in same plot
629  }
630  }
631 
632  if (!_owner->HasCurrency(building->CostCurrencyID, building->CostCurrencyAmount))
634 
635  if (!_owner->HasEnoughMoney(uint64(building->CostMoney) * GOLD))
637 
638  // New building cannot replace another building currently under construction
639  if (plot->BuildingInfo.PacketInfo)
640  if (!plot->BuildingInfo.PacketInfo->Active)
642 
643  return GARRISON_SUCCESS;
644 }
Definition: Garrison.h:60
DB2Storage< GarrBuildingEntry > sGarrBuildingStore("GarrBuilding.db2", GarrBuildingFormat, HOTFIX_SEL_GARR_BUILDING)
Definition: DB2Structure.h:439
uint32 Level
Definition: DB2Structure.h:552
DB2Storage< GarrPlotInstanceEntry > sGarrPlotInstanceStore("GarrPlotInstance.db2", GarrPlotInstanceFormat, HOTFIX_SEL_GARR_PLOT_INSTANCE)
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
Plot * GetPlot(uint32 garrPlotInstanceId)
Definition: Garrison.cpp:319
std::unordered_set< uint32 > _knownBuildings
Definition: Garrison.h:164
uint32 GarrPlotID
Definition: DB2Structure.h:545
Player * _owner
Definition: Garrison.h:159
Definition: Garrison.h:66
uint32 Type
Definition: DB2Structure.h:445
Definition: Garrison.h:58
Definition: Garrison.h:68
std::unordered_map< uint32, Plot > _plots
Definition: Garrison.h:163
uint64_t uint64
Definition: Define.h:149
#define sGarrisonMgr
Definition: GarrisonMgr.h:77
Definition: Garrison.h:65
Definition: Garrison.h:67
Definition: SharedDefines.h:232
int32 CostMoney
Definition: DB2Structure.h:464
Definition: DB2Structure.h:542
Definition: Garrison.h:61
Definition: Garrison.h:62
uint32 Level
Definition: DB2Structure.h:446
Definition: Garrison.h:32
Definition: Garrison.h:59
uint32 Flags
Definition: DB2Structure.h:458
int32 CostCurrencyAmount
Definition: DB2Structure.h:453
uint32 CostCurrencyID
Definition: DB2Structure.h:452

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GarrisonError Garrison::CheckBuildingRemoval ( uint32  garrPlotInstanceId) const
private
647 {
648  Plot const* plot = GetPlot(garrPlotInstanceId);
649  if (!plot)
651 
652  if (!plot->BuildingInfo.PacketInfo)
654 
655  if (plot->BuildingInfo.CanActivate())
657 
658  return GARRISON_SUCCESS;
659 }
Plot * GetPlot(uint32 garrPlotInstanceId)
Definition: Garrison.cpp:319
Definition: Garrison.h:66
Definition: Garrison.h:58
Definition: Garrison.h:62
Definition: Garrison.h:59

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Garrison::Create ( uint32  garrSiteId)
221 {
222  _siteLevel = sGarrisonMgr.GetGarrSiteLevelEntry(garrSiteId, 1);
223  if (!_siteLevel)
224  return false;
225 
226  InitializePlots();
227 
229  garrisonCreateResult.GarrSiteLevelID = _siteLevel->ID;
230  _owner->SendDirectMessage(garrisonCreateResult.Write());
231  _owner->SendUpdatePhasing();
232  SendRemoteInfo();
233  return true;
234 }
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
Player * _owner
Definition: Garrison.h:159
void SendRemoteInfo() const
Definition: Garrison.cpp:547
Definition: GarrisonPackets.h:31
#define sGarrisonMgr
Definition: GarrisonMgr.h:77
void InitializePlots()
Definition: Garrison.cpp:248
uint32 GarrSiteLevelID
Definition: GarrisonPackets.h:38
uint32 ID
Definition: DB2Structure.h:551
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:20

+ Here is the call graph for this function:

void Garrison::Delete ( )
237 {
239  DeleteFromDB(_owner->GetGUID().GetCounter(), trans);
241 
243  garrisonDelete.Result = GARRISON_SUCCESS;
244  garrisonDelete.GarrSiteID = _siteLevel->SiteID;
245  _owner->SendDirectMessage(garrisonDelete.Write());
246 }
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:28
uint32 Result
Definition: GarrisonPackets.h:49
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
Player * _owner
Definition: Garrison.h:159
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
uint32 GarrSiteID
Definition: GarrisonPackets.h:50
Definition: Garrison.h:58
uint32 SiteID
Definition: DB2Structure.h:554
Definition: GarrisonPackets.h:42
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
static void DeleteFromDB(ObjectGuid::LowType ownerGuid, SQLTransaction trans)
Definition: Garrison.cpp:201
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

+ Here is the call graph for this function:

void Garrison::DeleteFromDB ( ObjectGuid::LowType  ownerGuid,
SQLTransaction  trans 
)
static
202 {
204  stmt->setUInt64(0, ownerGuid);
205  trans->Append(stmt);
206 
208  stmt->setUInt64(0, ownerGuid);
209  trans->Append(stmt);
210 
212  stmt->setUInt64(0, ownerGuid);
213  trans->Append(stmt);
214 
216  stmt->setUInt64(0, ownerGuid);
217  trans->Append(stmt);
218 }
Definition: PreparedStatement.h:74
Definition: CharacterDatabase.h:587
Definition: CharacterDatabase.h:593
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
Definition: CharacterDatabase.h:583
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
Definition: CharacterDatabase.h:590

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Garrison::Enter ( ) const
279 {
280  if (MapEntry const* map = sMapStore.LookupEntry(_siteLevel->MapID))
281  {
282  if (int32(_owner->GetMapId()) == map->ParentMapID)
283  {
285  loc.Relocate(_owner);
286  _owner->TeleportTo(loc, TELE_TO_SEAMLESS);
287  }
288  }
289 }
Definition: Position.h:228
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
Definition: DBCStructure.h:830
Player * _owner
Definition: Garrison.h:159
DBCStorage< MapEntry > sMapStore(Mapfmt)
int32_t int32
Definition: g3dmath.h:167
uint32 MapID
Definition: DB2Structure.h:553

+ Here is the call graph for this function:

Map * Garrison::FindMap ( ) const
private
589 {
590  return sMapMgr->FindMap(_siteLevel->MapID, _owner->GetGUID().GetCounter());
591 }
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
Player * _owner
Definition: Garrison.h:159
#define sMapMgr
Definition: MapManager.h:194
uint32 MapID
Definition: DB2Structure.h:553

+ Here is the caller graph for this function:

GarrisonFactionIndex Garrison::GetFaction ( ) const
305 {
307 }
Player * _owner
Definition: Garrison.h:159
Definition: Garrison.h:27
Definition: SharedDefines.h:999
Definition: Garrison.h:26

+ Here is the caller graph for this function:

Garrison::Follower const * Garrison::GetFollower ( uint64  dbId) const
518 {
519  auto itr = _followers.find(dbId);
520  if (itr != _followers.end())
521  return &itr->second;
522 
523  return nullptr;
524 }
std::unordered_map< uint64, Follower > _followers
Definition: Garrison.h:165

+ Here is the caller graph for this function:

Garrison::Plot * Garrison::GetPlot ( uint32  garrPlotInstanceId)
320 {
321  auto itr = _plots.find(garrPlotInstanceId);
322  if (itr != _plots.end())
323  return &itr->second;
324 
325  return nullptr;
326 }
std::unordered_map< uint32, Plot > _plots
Definition: Garrison.h:163

+ Here is the caller graph for this function:

Garrison::Plot const * Garrison::GetPlot ( uint32  garrPlotInstanceId) const
329 {
330  auto itr = _plots.find(garrPlotInstanceId);
331  if (itr != _plots.end())
332  return &itr->second;
333 
334  return nullptr;
335 }
std::unordered_map< uint32, Plot > _plots
Definition: Garrison.h:163
std::vector< Garrison::Plot * > Garrison::GetPlots ( )
310 {
311  std::vector<Plot*> plots;
312  plots.reserve(_plots.size());
313  for (auto& p : _plots)
314  plots.push_back(&p.second);
315 
316  return plots;
317 }
std::unordered_map< uint32, Plot > _plots
Definition: Garrison.h:163

+ Here is the caller graph for this function:

void Garrison::InitializePlots ( )
private
249 {
250  if (std::vector<GarrSiteLevelPlotInstEntry const*> const* plots = sGarrisonMgr.GetGarrPlotInstForSiteLevel(_siteLevel->ID))
251  {
252  for (std::size_t i = 0; i < plots->size(); ++i)
253  {
254  uint32 garrPlotInstanceId = plots->at(i)->GarrPlotInstanceID;
255  GarrPlotInstanceEntry const* plotInstance = sGarrPlotInstanceStore.LookupEntry(garrPlotInstanceId);
256  GameObjectsEntry const* gameObject = sGarrisonMgr.GetPlotGameObject(_siteLevel->MapID, garrPlotInstanceId);
257  if (!plotInstance || !gameObject)
258  continue;
259 
260  GarrPlotEntry const* plot = sGarrPlotStore.LookupEntry(plotInstance->GarrPlotID);
261  if (!plot)
262  continue;
263 
264  Plot& plotInfo = _plots[garrPlotInstanceId];
265  plotInfo.PacketInfo.GarrPlotInstanceID = garrPlotInstanceId;
266  plotInfo.PacketInfo.PlotPos.Relocate(gameObject->Position.X, gameObject->Position.Y, gameObject->Position.Z, 2 * std::acos(gameObject->RotationW));
267  plotInfo.PacketInfo.PlotType = plot->PlotType;
268  plotInfo.EmptyGameObjectId = gameObject->ID;
269  plotInfo.GarrSiteLevelPlotInstId = plots->at(i)->ID;
270  }
271  }
272 }
float Z
Definition: DBCEnums.h:36
float Y
Definition: DBCEnums.h:35
DB2Storage< GarrPlotInstanceEntry > sGarrPlotInstanceStore("GarrPlotInstance.db2", GarrPlotInstanceFormat, HOTFIX_SEL_GARR_PLOT_INSTANCE)
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
Definition: DB2Structure.h:400
uint32 GarrPlotID
Definition: DB2Structure.h:545
Definition: DB2Structure.h:522
uint32 ID
Definition: DB2Structure.h:402
std::unordered_map< uint32, Plot > _plots
Definition: Garrison.h:163
uint32_t uint32
Definition: Define.h:150
#define sGarrisonMgr
Definition: GarrisonMgr.h:77
float X
Definition: DBCEnums.h:34
DB2Storage< GarrPlotEntry > sGarrPlotStore("GarrPlot.db2", GarrPlotFormat, HOTFIX_SEL_GARR_PLOT)
uint32 PlotType
Definition: DB2Structure.h:526
float acos(float fValue)
Definition: g3dmath.h:633
Definition: DB2Structure.h:542
DBCPosition3D Position
Definition: DB2Structure.h:405
float RotationW
Definition: DB2Structure.h:409
uint32 ID
Definition: DB2Structure.h:551
uint32 MapID
Definition: DB2Structure.h:553

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Garrison::LearnBlueprint ( uint32  garrBuildingId)
338 {
340  learnBlueprintResult.BuildingID = garrBuildingId;
341  learnBlueprintResult.Result = GARRISON_SUCCESS;
342 
343  if (!sGarrBuildingStore.LookupEntry(garrBuildingId))
344  learnBlueprintResult.Result = GARRISON_ERROR_INVALID_BUILDINGID;
345  else if (_knownBuildings.count(garrBuildingId))
346  learnBlueprintResult.Result = GARRISON_ERROR_BLUEPRINT_KNOWN;
347  else
348  _knownBuildings.insert(garrBuildingId);
349 
350  _owner->SendDirectMessage(learnBlueprintResult.Write());
351 }
Definition: Garrison.h:60
DB2Storage< GarrBuildingEntry > sGarrBuildingStore("GarrBuilding.db2", GarrBuildingFormat, HOTFIX_SEL_GARR_BUILDING)
uint32 BuildingID
Definition: GarrisonPackets.h:211
std::unordered_set< uint32 > _knownBuildings
Definition: Garrison.h:164
Definition: Garrison.h:64
Player * _owner
Definition: Garrison.h:159
Definition: Garrison.h:58
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:211
uint32 Result
Definition: GarrisonPackets.h:212

+ Here is the call graph for this function:

void Garrison::Leave ( ) const
292 {
293  if (MapEntry const* map = sMapStore.LookupEntry(_siteLevel->MapID))
294  {
295  if (_owner->GetMapId() == _siteLevel->MapID)
296  {
297  WorldLocation loc(map->ParentMapID);
298  loc.Relocate(_owner);
299  _owner->TeleportTo(loc, TELE_TO_SEAMLESS);
300  }
301  }
302 }
Definition: Position.h:228
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
Definition: DBCStructure.h:830
Player * _owner
Definition: Garrison.h:159
DBCStorage< MapEntry > sMapStore(Mapfmt)
uint32 MapID
Definition: DB2Structure.h:553

+ Here is the call graph for this function:

bool Garrison::LoadFromDB ( PreparedQueryResult  garrison,
PreparedQueryResult  blueprints,
PreparedQueryResult  buildings,
PreparedQueryResult  followers,
PreparedQueryResult  abilities 
)
32 {
33  if (!garrison)
34  return false;
35 
36  Field* fields = garrison->Fetch();
37  _siteLevel = sGarrSiteLevelStore.LookupEntry(fields[0].GetUInt32());
39  if (!_siteLevel)
40  return false;
41 
43 
44  if (blueprints)
45  {
46  do
47  {
48  fields = blueprints->Fetch();
49  if (GarrBuildingEntry const* building = sGarrBuildingStore.LookupEntry(fields[0].GetUInt32()))
50  _knownBuildings.insert(building->ID);
51 
52  } while (blueprints->NextRow());
53  }
54 
55  if (buildings)
56  {
57  do
58  {
59  fields = buildings->Fetch();
60  uint32 plotInstanceId = fields[0].GetUInt32();
61  uint32 buildingId = fields[1].GetUInt32();
62  time_t timeBuilt = time_t(fields[2].GetUInt64());
63  bool active = fields[3].GetBool();
64 
65 
66  Plot* plot = GetPlot(plotInstanceId);
67  if (!plot)
68  continue;
69 
70  if (!sGarrBuildingStore.LookupEntry(buildingId))
71  continue;
72 
73  plot->BuildingInfo.PacketInfo = boost::in_place();
74  plot->BuildingInfo.PacketInfo->GarrPlotInstanceID = plotInstanceId;
75  plot->BuildingInfo.PacketInfo->GarrBuildingID = buildingId;
76  plot->BuildingInfo.PacketInfo->TimeBuilt = timeBuilt;
77  plot->BuildingInfo.PacketInfo->Active = active;
78 
79  } while (buildings->NextRow());
80  }
81 
82  // 0 1 2 3 4 5 6 7 8 9
83  // SELECT dbId, followerId, quality, level, itemLevelWeapon, itemLevelArmor, xp, currentBuilding, currentMission, status FROM character_garrison_followers WHERE guid = ?
84  if (followers)
85  {
86  do
87  {
88  fields = followers->Fetch();
89 
90  uint64 dbId = fields[0].GetUInt64();
91  uint32 followerId = fields[1].GetUInt32();
92  if (!sGarrFollowerStore.LookupEntry(followerId))
93  continue;
94 
95  _followerIds.insert(followerId);
96  Follower& follower = _followers[dbId];
97  follower.PacketInfo.DbID = dbId;
98  follower.PacketInfo.GarrFollowerID = followerId;
99  follower.PacketInfo.Quality = fields[2].GetUInt32();
100  follower.PacketInfo.FollowerLevel = fields[3].GetUInt32();
101  follower.PacketInfo.ItemLevelWeapon = fields[4].GetUInt32();
102  follower.PacketInfo.ItemLevelArmor = fields[5].GetUInt32();
103  follower.PacketInfo.Xp = fields[6].GetUInt32();
104  follower.PacketInfo.CurrentBuildingID = fields[7].GetUInt32();
105  follower.PacketInfo.CurrentMissionID = fields[8].GetUInt32();
106  follower.PacketInfo.FollowerStatus = fields[9].GetUInt32();
107  if (!sGarrBuildingStore.LookupEntry(follower.PacketInfo.CurrentBuildingID))
108  follower.PacketInfo.CurrentBuildingID = 0;
109 
110  //if (!sGarrMissionStore.LookupEntry(follower.PacketInfo.CurrentMissionID))
111  // follower.PacketInfo.CurrentMissionID = 0;
112 
113  } while (followers->NextRow());
114 
115  if (abilities)
116  {
117  do
118  {
119  fields = abilities->Fetch();
120  uint64 dbId = fields[0].GetUInt64();
121  GarrAbilityEntry const* ability = sGarrAbilityStore.LookupEntry(fields[1].GetUInt32());
122 
123  if (!ability)
124  continue;
125 
126  auto itr = _followers.find(dbId);
127  if (itr == _followers.end())
128  continue;
129 
130  itr->second.PacketInfo.AbilityID.push_back(ability);
131  } while (abilities->NextRow());
132  }
133  }
134 
135  return true;
136 }
std::unordered_set< uint32 > _followerIds
Definition: Garrison.h:166
DB2Storage< GarrFollowerEntry > sGarrFollowerStore("GarrFollower.db2", GarrFollowerFormat, HOTFIX_SEL_GARR_FOLLOWER)
uint64 GetUInt64() const
Definition: Field.h:184
DB2Storage< GarrBuildingEntry > sGarrBuildingStore("GarrBuilding.db2", GarrBuildingFormat, HOTFIX_SEL_GARR_BUILDING)
Definition: DB2Structure.h:439
Class used to access individual fields of database query result.
Definition: Field.h:56
DB2Storage< GarrSiteLevelEntry > sGarrSiteLevelStore("GarrSiteLevel.db2", GarrSiteLevelFormat, HOTFIX_SEL_GARR_SITE_LEVEL)
DB2Storage< GarrAbilityEntry > sGarrAbilityStore("GarrAbility.db2", GarrAbilityFormat, HOTFIX_SEL_GARR_ABILITY)
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
Plot * GetPlot(uint32 garrPlotInstanceId)
Definition: Garrison.cpp:319
std::unordered_set< uint32 > _knownBuildings
Definition: Garrison.h:164
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
void InitializePlots()
Definition: Garrison.cpp:248
std::unordered_map< uint64, Follower > _followers
Definition: Garrison.h:165
Definition: DB2Structure.h:427
uint32 GetUInt32() const
Definition: Field.h:146
uint32 _followerActivationsRemainingToday
Definition: Garrison.h:161
bool GetBool() const
Definition: Field.h:65

+ Here is the call graph for this function:

void Garrison::PlaceBuilding ( uint32  garrPlotInstanceId,
uint32  garrBuildingId 
)
370 {
372  placeBuildingResult.Result = CheckBuildingPlacement(garrPlotInstanceId, garrBuildingId);
373  if (placeBuildingResult.Result == GARRISON_SUCCESS)
374  {
375  placeBuildingResult.BuildingInfo.GarrPlotInstanceID = garrPlotInstanceId;
376  placeBuildingResult.BuildingInfo.GarrBuildingID = garrBuildingId;
377  placeBuildingResult.BuildingInfo.TimeBuilt = time(nullptr);
378 
379  Plot* plot = GetPlot(garrPlotInstanceId);
380  uint32 oldBuildingId = 0;
381  Map* map = FindMap();
382  GarrBuildingEntry const* building = sGarrBuildingStore.AssertEntry(garrBuildingId);
383  if (map)
384  plot->DeleteGameObject(map);
385 
386  if (plot->BuildingInfo.PacketInfo)
387  {
388  oldBuildingId = plot->BuildingInfo.PacketInfo->GarrBuildingID;
389  if (sGarrBuildingStore.AssertEntry(oldBuildingId)->Type != building->Type)
390  plot->ClearBuildingInfo(_owner);
391  }
392 
393  plot->SetBuildingInfo(placeBuildingResult.BuildingInfo, _owner);
394  if (map)
395  if (GameObject* go = plot->CreateGameObject(map, GetFaction()))
396  map->AddToMap(go);
397 
398  _owner->ModifyCurrency(building->CostCurrencyID, -building->CostCurrencyAmount, false, true);
399  _owner->ModifyMoney(-building->CostMoney * GOLD, false);
400 
401  if (oldBuildingId)
402  {
404  buildingRemoved.Result = GARRISON_SUCCESS;
405  buildingRemoved.GarrPlotInstanceID = garrPlotInstanceId;
406  buildingRemoved.GarrBuildingID = oldBuildingId;
407  _owner->SendDirectMessage(buildingRemoved.Write());
408  }
409 
410  _owner->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_PLACE_GARRISON_BUILDING, garrBuildingId);
411  }
412 
413  _owner->SendDirectMessage(placeBuildingResult.Write());
414 }
time_t TimeBuilt
Definition: GarrisonPackets.h:72
DB2Storage< GarrBuildingEntry > sGarrBuildingStore("GarrBuilding.db2", GarrBuildingFormat, HOTFIX_SEL_GARR_BUILDING)
Definition: DB2Structure.h:439
Plot * GetPlot(uint32 garrPlotInstanceId)
Definition: Garrison.cpp:319
Definition: GarrisonPackets.h:192
uint32 GarrBuildingID
Definition: GarrisonPackets.h:201
Player * _owner
Definition: Garrison.h:159
uint32 Type
Definition: DB2Structure.h:445
Definition: Garrison.h:58
bool AddToMap(T *)
Definition: Map.cpp:566
uint32_t uint32
Definition: Define.h:150
Definition: GameObject.h:880
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:186
Definition: Map.h:259
Definition: SharedDefines.h:232
int32 CostMoney
Definition: DB2Structure.h:464
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:202
uint32 Result
Definition: GarrisonPackets.h:199
uint32 GarrPlotInstanceID
Definition: GarrisonPackets.h:70
GarrisonBuildingInfo BuildingInfo
Definition: GarrisonPackets.h:177
uint32 Result
Definition: GarrisonPackets.h:176
int32 CostCurrencyAmount
Definition: DB2Structure.h:453
Map * FindMap() const
Definition: Garrison.cpp:588
uint32 CostCurrencyID
Definition: DB2Structure.h:452
GarrisonFactionIndex GetFaction() const
Definition: Garrison.cpp:304
GarrisonError CheckBuildingPlacement(uint32 garrPlotInstanceId, uint32 garrBuildingId) const
Definition: Garrison.cpp:593
uint32 GarrPlotInstanceID
Definition: GarrisonPackets.h:200
uint32 GarrBuildingID
Definition: GarrisonPackets.h:71

+ Here is the call graph for this function:

void Garrison::ResetFollowerActivationLimit ( )
inline
uint32 _followerActivationsRemainingToday
Definition: Garrison.h:161
void Garrison::SaveToDB ( SQLTransaction  trans)
139 {
140  DeleteFromDB(_owner->GetGUID().GetCounter(), trans);
141 
143  stmt->setUInt64(0, _owner->GetGUID().GetCounter());
144  stmt->setUInt32(1, _siteLevel->ID);
145  stmt->setUInt32(2, _followerActivationsRemainingToday);
146  trans->Append(stmt);
147 
148  for (uint32 building : _knownBuildings)
149  {
151  stmt->setUInt64(0, _owner->GetGUID().GetCounter());
152  stmt->setUInt32(1, building);
153  trans->Append(stmt);
154  }
155 
156  for (auto const& p : _plots)
157  {
158  Plot const& plot = p.second;
159  if (plot.BuildingInfo.PacketInfo)
160  {
162  stmt->setUInt64(0, _owner->GetGUID().GetCounter());
163  stmt->setUInt32(1, plot.BuildingInfo.PacketInfo->GarrPlotInstanceID);
164  stmt->setUInt32(2, plot.BuildingInfo.PacketInfo->GarrBuildingID);
165  stmt->setUInt64(3, plot.BuildingInfo.PacketInfo->TimeBuilt);
166  stmt->setBool(4, plot.BuildingInfo.PacketInfo->Active);
167  trans->Append(stmt);
168  }
169  }
170 
171  for (auto const& p : _followers)
172  {
173  Follower const& follower = p.second;
174  uint8 index = 0;
176  stmt->setUInt64(index++, follower.PacketInfo.DbID);
177  stmt->setUInt64(index++, _owner->GetGUID().GetCounter());
178  stmt->setUInt32(index++, follower.PacketInfo.GarrFollowerID);
179  stmt->setUInt32(index++, follower.PacketInfo.Quality);
180  stmt->setUInt32(index++, follower.PacketInfo.FollowerLevel);
181  stmt->setUInt32(index++, follower.PacketInfo.ItemLevelWeapon);
182  stmt->setUInt32(index++, follower.PacketInfo.ItemLevelArmor);
183  stmt->setUInt32(index++, follower.PacketInfo.Xp);
184  stmt->setUInt32(index++, follower.PacketInfo.CurrentBuildingID);
185  stmt->setUInt32(index++, follower.PacketInfo.CurrentMissionID);
186  stmt->setUInt32(index++, follower.PacketInfo.FollowerStatus);
187  trans->Append(stmt);
188 
189  uint8 slot = 0;
190  for (GarrAbilityEntry const* ability : follower.PacketInfo.AbilityID)
191  {
193  stmt->setUInt64(0, follower.PacketInfo.DbID);
194  stmt->setUInt32(1, ability->ID);
195  stmt->setUInt8(2, slot++);
196  trans->Append(stmt);
197  }
198  }
199 }
Definition: CharacterDatabase.h:592
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
std::unordered_set< uint32 > _knownBuildings
Definition: Garrison.h:164
Definition: PreparedStatement.h:74
Player * _owner
Definition: Garrison.h:159
Definition: CharacterDatabase.h:582
std::unordered_map< uint32, Plot > _plots
Definition: Garrison.h:163
uint32_t uint32
Definition: Define.h:150
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
uint32 ID
Definition: DB2Structure.h:429
std::unordered_map< uint64, Follower > _followers
Definition: Garrison.h:165
Definition: DB2Structure.h:427
uint32 ID
Definition: DB2Structure.h:551
Definition: CharacterDatabase.h:586
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
uint32 _followerActivationsRemainingToday
Definition: Garrison.h:161
uint8_t uint8
Definition: Define.h:152
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
Definition: CharacterDatabase.h:589
static void DeleteFromDB(ObjectGuid::LowType ownerGuid, SQLTransaction trans)
Definition: Garrison.cpp:201
Definition: CharacterDatabase.h:595

+ Here is the call graph for this function:

void Garrison::SendBlueprintAndSpecializationData ( )
566 {
569  _owner->SendDirectMessage(data.Write());
570 }
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:227
std::unordered_set< uint32 > const * BlueprintsKnown
Definition: GarrisonPackets.h:242
std::unordered_set< uint32 > _knownBuildings
Definition: Garrison.h:164
Player * _owner
Definition: Garrison.h:159

+ Here is the call graph for this function:

void Garrison::SendBuildingLandmarks ( Player receiver) const
573 {
575  buildingLandmarks.Landmarks.reserve(_plots.size());
576 
577  for (auto const& p : _plots)
578  {
579  Plot const& plot = p.second;
580  if (plot.BuildingInfo.PacketInfo)
581  if (uint32 garrBuildingPlotInstId = sGarrisonMgr.GetGarrBuildingPlotInst(plot.BuildingInfo.PacketInfo->GarrBuildingID, plot.GarrSiteLevelPlotInstId))
582  buildingLandmarks.Landmarks.emplace_back(garrBuildingPlotInstId, plot.PacketInfo.PlotPos);
583  }
584 
585  receiver->SendDirectMessage(buildingLandmarks.Write());
586 }
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:250
std::unordered_map< uint32, Plot > _plots
Definition: Garrison.h:163
uint32_t uint32
Definition: Define.h:150
#define sGarrisonMgr
Definition: GarrisonMgr.h:77
Definition: GarrisonPackets.h:262
std::vector< GarrisonBuildingLandmark > Landmarks
Definition: GarrisonPackets.h:269

+ Here is the call graph for this function:

void Garrison::SendInfo ( )
527 {
529  garrisonInfo.GarrSiteID = _siteLevel->SiteID;
530  garrisonInfo.GarrSiteLevelID = _siteLevel->ID;
531  garrisonInfo.FactionIndex = GetFaction();
533  for (auto& p : _plots)
534  {
535  Plot& plot = p.second;
536  garrisonInfo.Plots.push_back(&plot.PacketInfo);
537  if (plot.BuildingInfo.PacketInfo)
538  garrisonInfo.Buildings.push_back(plot.BuildingInfo.PacketInfo.get_ptr());
539  }
540 
541  for (auto const& p : _followers)
542  garrisonInfo.Followers.push_back(&p.second.PacketInfo);
543 
544  _owner->SendDirectMessage(garrisonInfo.Write());
545 }
uint32 NumFollowerActivationsRemaining
Definition: GarrisonPackets.h:122
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:103
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
uint32 FactionIndex
Definition: GarrisonPackets.h:121
std::vector< GarrisonPlotInfo * > Plots
Definition: GarrisonPackets.h:123
Player * _owner
Definition: Garrison.h:159
uint32 GarrSiteID
Definition: GarrisonPackets.h:119
uint32 GarrSiteLevelID
Definition: GarrisonPackets.h:120
Definition: GarrisonPackets.h:112
std::unordered_map< uint32, Plot > _plots
Definition: Garrison.h:163
uint32 SiteID
Definition: DB2Structure.h:554
std::vector< GarrisonFollower const * > Followers
Definition: GarrisonPackets.h:125
std::unordered_map< uint64, Follower > _followers
Definition: Garrison.h:165
uint32 ID
Definition: DB2Structure.h:551
uint32 _followerActivationsRemainingToday
Definition: Garrison.h:161
std::vector< GarrisonBuildingInfo const * > Buildings
Definition: GarrisonPackets.h:124
GarrisonFactionIndex GetFaction() const
Definition: Garrison.cpp:304

+ Here is the call graph for this function:

void Garrison::SendRemoteInfo ( ) const
548 {
549  MapEntry const* garrisonMap = sMapStore.LookupEntry(_siteLevel->MapID);
550  if (!garrisonMap || int32(_owner->GetMapId()) != garrisonMap->ParentMapID)
551  return;
552 
554  remoteInfo.Sites.resize(1);
555 
556  WorldPackets::Garrison::GarrisonRemoteSiteInfo& remoteSiteInfo = remoteInfo.Sites[0];
557  remoteSiteInfo.GarrSiteLevelID = _siteLevel->ID;
558  for (auto const& p : _plots)
559  if (p.second.BuildingInfo.PacketInfo)
560  remoteSiteInfo.Buildings.emplace_back(p.first, p.second.BuildingInfo.PacketInfo->GarrBuildingID);
561 
562  _owner->SendDirectMessage(remoteInfo.Write());
563 }
Definition: GarrisonPackets.h:141
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
Definition: DBCStructure.h:830
Player * _owner
Definition: Garrison.h:159
Definition: GarrisonPackets.h:147
int32 ParentMapID
Definition: DBCStructure.h:850
uint32 GarrSiteLevelID
Definition: GarrisonPackets.h:143
std::vector< GarrisonRemoteSiteInfo > Sites
Definition: GarrisonPackets.h:154
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:170
std::unordered_map< uint32, Plot > _plots
Definition: Garrison.h:163
std::vector< GarrisonRemoteBuildingInfo > Buildings
Definition: GarrisonPackets.h:144
DBCStorage< MapEntry > sMapStore(Mapfmt)
uint32 ID
Definition: DB2Structure.h:551
int32_t int32
Definition: g3dmath.h:167
uint32 MapID
Definition: DB2Structure.h:553

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Garrison::UnlearnBlueprint ( uint32  garrBuildingId)
354 {
356  unlearnBlueprintResult.BuildingID = garrBuildingId;
357  unlearnBlueprintResult.Result = GARRISON_SUCCESS;
358 
359  if (!sGarrBuildingStore.LookupEntry(garrBuildingId))
360  unlearnBlueprintResult.Result = GARRISON_ERROR_INVALID_BUILDINGID;
361  else if (!_knownBuildings.count(garrBuildingId))
362  unlearnBlueprintResult.Result = GARRISON_ERROR_BLUEPRINT_NOT_KNOWN;
363  else
364  _knownBuildings.erase(garrBuildingId);
365 
366  _owner->SendDirectMessage(unlearnBlueprintResult.Write());
367 }
Definition: Garrison.h:60
DB2Storage< GarrBuildingEntry > sGarrBuildingStore("GarrBuilding.db2", GarrBuildingFormat, HOTFIX_SEL_GARR_BUILDING)
std::unordered_set< uint32 > _knownBuildings
Definition: Garrison.h:164
Player * _owner
Definition: Garrison.h:159
WorldPacket const * Write() override
Definition: GarrisonPackets.cpp:219
Definition: Garrison.h:58
Definition: Garrison.h:65
uint32 Result
Definition: GarrisonPackets.h:223
uint32 BuildingID
Definition: GarrisonPackets.h:222

+ Here is the call graph for this function:

void Garrison::Upgrade ( )
275 {
276 }

Member Data Documentation

uint32 Garrison::_followerActivationsRemainingToday
private
std::unordered_set<uint32> Garrison::_followerIds
private
std::unordered_map<uint64 , Follower> Garrison::_followers
private
std::unordered_set<uint32 > Garrison::_knownBuildings
private
Player* Garrison::_owner
private
std::unordered_map<uint32 , Plot> Garrison::_plots
private
GarrSiteLevelEntry const* Garrison::_siteLevel
private

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