diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp index 8e86d4658..96a340f9c 100644 --- a/src/server/game/AI/CoreAI/PetAI.cpp +++ b/src/server/game/AI/CoreAI/PetAI.cpp @@ -16,6 +16,7 @@ */ #include "PetAI.h" +#include "CharmInfo.h" #include "Creature.h" #include "Errors.h" #include "Group.h" diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index 6968600b1..117b8f6a5 100644 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -17,6 +17,7 @@ #include "Pet.h" #include "ArenaSpectator.h" +#include "CharmInfo.h" #include "Common.h" #include "DatabaseEnv.h" #include "GameTime.h" diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index c888310b0..3633ebf3f 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -20,6 +20,7 @@ #include "ArenaTeam.h" #include "Battleground.h" +#include "CharmInfo.h" #include "CharacterCache.h" #include "CinematicMgr.h" #include "DBCStores.h" diff --git a/src/server/game/Entities/Unit/CharmInfo.cpp b/src/server/game/Entities/Unit/CharmInfo.cpp index 6ef15a907..4e0664304 100644 --- a/src/server/game/Entities/Unit/CharmInfo.cpp +++ b/src/server/game/Entities/Unit/CharmInfo.cpp @@ -17,6 +17,7 @@ #include "CharmInfo.h" #include "Creature.h" +#include "GameTime.h" #include "Map.h" #include "SpellInfo.h" #include "Player.h" @@ -390,3 +391,21 @@ bool CharmInfo::IsReturning() { return _isReturning; } + +//////////////////////////////////////////////////////////// +// Methods of class GlobalCooldownMgr +bool GlobalCooldownMgr::HasGlobalCooldown(SpellInfo const* spellInfo) const +{ + GlobalCooldownList::const_iterator itr = m_GlobalCooldowns.find(spellInfo->StartRecoveryCategory); + return itr != m_GlobalCooldowns.end() && itr->second.duration && getMSTimeDiff(itr->second.cast_time, GameTime::GetGameTimeMS().count()) < itr->second.duration; +} + +void GlobalCooldownMgr::AddGlobalCooldown(SpellInfo const* spellInfo, uint32 gcd) +{ + m_GlobalCooldowns[spellInfo->StartRecoveryCategory] = GlobalCooldown(gcd, GameTime::GetGameTimeMS().count()); +} + +void GlobalCooldownMgr::CancelGlobalCooldown(SpellInfo const* spellInfo) +{ + m_GlobalCooldowns[spellInfo->StartRecoveryCategory].duration = 0; +} diff --git a/src/server/game/Entities/Unit/CharmInfo.h b/src/server/game/Entities/Unit/CharmInfo.h index 9246394b4..6a62c6ef8 100644 --- a/src/server/game/Entities/Unit/CharmInfo.h +++ b/src/server/game/Entities/Unit/CharmInfo.h @@ -65,6 +65,30 @@ enum ActiveStates : uint8 ACT_DECIDE = 0x00 // custom }; +struct GlobalCooldown +{ + explicit GlobalCooldown(uint32 _dur = 0, uint32 _time = 0) : duration(_dur), cast_time(_time) {} + + uint32 duration; + uint32 cast_time; +}; + +typedef std::unordered_map GlobalCooldownList; + +class GlobalCooldownMgr // Shared by Player and CharmInfo +{ +public: + GlobalCooldownMgr() = default; + +public: + bool HasGlobalCooldown(SpellInfo const* spellInfo) const; + void AddGlobalCooldown(SpellInfo const* spellInfo, uint32 gcd); + void CancelGlobalCooldown(SpellInfo const* spellInfo); + +private: + GlobalCooldownList m_GlobalCooldowns; +}; + struct UnitActionBarEntry { UnitActionBarEntry() : packedData(uint32(ACT_DISABLED) << 24) {} @@ -131,7 +155,7 @@ public: CharmSpellInfo* GetCharmSpell(uint8 index) { return &(_charmspells[index]); } - GlobalCooldownMgr& GetGlobalCooldownMgr() { return *_GlobalCooldownMgr; } + GlobalCooldownMgr& GetGlobalCooldownMgr() { return _GlobalCooldownMgr; } void SetIsCommandAttack(bool val); bool IsCommandAttack(); @@ -178,7 +202,7 @@ private: float _stayY; float _stayZ; - std::unique_ptr _GlobalCooldownMgr; + GlobalCooldownMgr _GlobalCooldownMgr; }; #endif // _CHARMINFO_H diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 1400e2d39..7f8c1649a 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -334,24 +334,6 @@ Unit::Unit(bool isWorldObject) : WorldObject(isWorldObject), _lastExtraAttackSpell = 0; } -//////////////////////////////////////////////////////////// -// Methods of class GlobalCooldownMgr -bool GlobalCooldownMgr::HasGlobalCooldown(SpellInfo const* spellInfo) const -{ - GlobalCooldownList::const_iterator itr = m_GlobalCooldowns.find(spellInfo->StartRecoveryCategory); - return itr != m_GlobalCooldowns.end() && itr->second.duration && getMSTimeDiff(itr->second.cast_time, GameTime::GetGameTimeMS().count()) < itr->second.duration; -} - -void GlobalCooldownMgr::AddGlobalCooldown(SpellInfo const* spellInfo, uint32 gcd) -{ - m_GlobalCooldowns[spellInfo->StartRecoveryCategory] = GlobalCooldown(gcd, GameTime::GetGameTimeMS().count()); -} - -void GlobalCooldownMgr::CancelGlobalCooldown(SpellInfo const* spellInfo) -{ - m_GlobalCooldowns[spellInfo->StartRecoveryCategory].duration = 0; -} - //////////////////////////////////////////////////////////// // Methods of class Unit Unit::~Unit() diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 61c6b29fa..bdd01d230 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -543,30 +543,6 @@ enum CurrentSpellTypes #define CURRENT_FIRST_NON_MELEE_SPELL 1 #define CURRENT_MAX_SPELL 4 -struct GlobalCooldown -{ - explicit GlobalCooldown(uint32 _dur = 0, uint32 _time = 0) : duration(_dur), cast_time(_time) {} - - uint32 duration; - uint32 cast_time; -}; - -typedef std::unordered_map GlobalCooldownList; - -class GlobalCooldownMgr // Shared by Player and CharmInfo -{ -public: - GlobalCooldownMgr() = default; - -public: - bool HasGlobalCooldown(SpellInfo const* spellInfo) const; - void AddGlobalCooldown(SpellInfo const* spellInfo, uint32 gcd); - void CancelGlobalCooldown(SpellInfo const* spellInfo); - -private: - GlobalCooldownList m_GlobalCooldowns; -}; - enum ReactStates : uint8 { REACT_PASSIVE = 0, diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index a57ceca6c..9bd266e11 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -20,6 +20,7 @@ #include "BattlefieldMgr.h" #include "Battleground.h" #include "BattlegroundIC.h" +#include "CharmInfo.h" #include "CellImpl.h" #include "Common.h" #include "ConditionMgr.h"