18 #ifndef SpellHistory_h__
19 #define SpellHistory_h__
45 typedef std::chrono::system_clock
Clock;
61 ChargeEntry(Clock::time_point startTime, Clock::time_point endTime) : RechargeStart(startTime), RechargeEnd(endTime) { }
74 template<
class OwnerType>
77 template<
class OwnerType>
82 void HandleCooldowns(
SpellInfo const* spellInfo,
Item const* item,
Spell* spell =
nullptr);
83 void HandleCooldowns(
SpellInfo const* spellInfo, uint32 itemID,
Spell* spell =
nullptr);
84 bool IsReady(
SpellInfo const* spellInfo, uint32 itemId = 0,
bool ignoreCategoryCooldown =
false)
const;
85 template<
class PacketType>
86 void WritePacket(PacketType* packet)
const;
91 void StartCooldown(
SpellInfo const* spellInfo, uint32 itemId,
Spell* spell =
nullptr,
bool onHold =
false);
92 void SendCooldownEvent(
SpellInfo const* spellInfo, uint32 itemId = 0,
Spell* spell =
nullptr,
bool startCooldown =
true);
94 template<
class Type,
class Period>
95 void AddCooldown(uint32 spellId, uint32 itemId, std::chrono::duration<Type, Period> cooldownDuration)
97 Clock::time_point now = Clock::now();
98 AddCooldown(spellId, itemId, now + std::chrono::duration_cast<Clock::duration>(cooldownDuration), 0, now);
101 void AddCooldown(uint32 spellId, uint32 itemId, Clock::time_point cooldownEnd, uint32 categoryId, Clock::time_point categoryEnd,
bool onHold =
false);
102 void ModifyCooldown(uint32 spellId,
int32 cooldownModMs);
103 void ResetCooldown(uint32 spellId,
bool update =
false);
104 void ResetCooldown(CooldownStorageType::iterator& itr,
bool update =
false);
105 template<
typename Predicate>
108 std::vector<int32> resetCooldowns;
109 resetCooldowns.reserve(_spellCooldowns.size());
110 for (
auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();)
114 resetCooldowns.push_back(
int32(itr->first));
115 ResetCooldown(itr,
false);
121 if (update && !resetCooldowns.empty())
122 SendClearCooldowns(resetCooldowns);
125 void ResetAllCooldowns();
126 bool HasCooldown(
SpellInfo const* spellInfo, uint32 itemId = 0,
bool ignoreCategoryCooldown =
false)
const;
127 bool HasCooldown(uint32 spellId, uint32 itemId = 0,
bool ignoreCategoryCooldown =
false)
const;
128 uint32 GetRemainingCooldown(
SpellInfo const* spellInfo)
const;
138 void ResetAllCharges();
144 bool HasGlobalCooldown(
SpellInfo const* spellInfo)
const;
145 void AddGlobalCooldown(
SpellInfo const* spellInfo, uint32 duration);
146 void CancelGlobalCooldown(
SpellInfo const* spellInfo);
148 uint16 GetArenaCooldownsSize();
149 void SaveCooldownStateBeforeDuel();
150 void RestoreCooldownStateAfterDuel();
153 Player* GetPlayerOwner()
const;
154 void SendClearCooldowns(std::vector<int32>
const& cooldowns)
const;
155 CooldownStorageType::iterator
EraseCooldown(CooldownStorageType::iterator itr)
157 _categoryCooldowns.erase(itr->second.CategoryId);
158 return _spellCooldowns.erase(itr);
161 static void GetCooldownDurations(
SpellInfo const* spellInfo, uint32 itemId,
int32* cooldown, uint32* categoryId,
int32* categoryCooldown);
175 #endif // SpellHistory_h__
ChargeEntry(Clock::time_point startTime, Clock::time_point endTime)
Definition: SpellHistory.h:61
Definition: SpellHistory.h:172
ChargeStorageType _categoryCharges
Definition: SpellHistory.h:168
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
void AddCooldown(uint32 spellId, uint32 itemId, std::chrono::duration< Type, Period > cooldownDuration)
Definition: SpellHistory.h:95
Unit * _owner
Definition: SpellHistory.h:163
Definition: SpellHistory.h:57
SpellSchoolMask
Definition: SharedDefines.h:285
Definition: SpellInfo.h:326
CategoryCooldownStorageType _categoryCooldowns
Definition: SpellHistory.h:166
void LoadFromDB()
Definition: AddonMgr.cpp:40
GlobalCooldownStorageType _globalCooldowns
Definition: SpellHistory.h:169
#define MAX_SPELL_SCHOOL
Definition: SharedDefines.h:283
Definition: SpellHistory.h:47
Clock::time_point RechargeEnd
Definition: SpellHistory.h:64
Definition: SpellHistory.h:42
std::unordered_map< uint32, CooldownEntry * > CategoryCooldownStorageType
Definition: SpellHistory.h:68
std::unordered_map< uint32, std::deque< ChargeEntry > > ChargeStorageType
Definition: SpellHistory.h:69
ChargeEntry(Clock::time_point startTime, std::chrono::milliseconds rechargeTime)
Definition: SpellHistory.h:60
Clock::time_point RechargeStart
Definition: SpellHistory.h:63
Clock::time_point CategoryEnd
Definition: SpellHistory.h:53
Definition: DBCStructure.h:1097
int32_t int32
Definition: Define.h:146
std::unordered_map< uint32, CooldownEntry > CooldownStorageType
Definition: SpellHistory.h:67
SpellCooldownFlags
Spell cooldown flags sent in SMSG_SPELL_COOLDOWN.
Definition: SpellHistory.h:35
uint32_t uint32
Definition: Define.h:150
Starts GCD for spells that should start their cooldown on events, requires SPELL_COOLDOWN_FLAG_INCLUD...
Definition: SpellHistory.h:39
uint16_t uint16
Definition: Define.h:151
ChargeEntry()
Definition: SpellHistory.h:59
float milliseconds()
Definition: units.h:92
std::unordered_map< uint32, Clock::time_point > GlobalCooldownStorageType
Definition: SpellHistory.h:70
Definition: SpellHistory.h:37
Starts GCD in addition to normal cooldown specified in the packet.
Definition: SpellHistory.h:38
CooldownStorageType _spellCooldowns
Definition: SpellHistory.h:164
CooldownStorageType _spellCooldownsBeforeDuel
Definition: SpellHistory.h:165
SpellHistory(Unit *owner)
Definition: SpellHistory.h:72
#define TC_GAME_API
Definition: Define.h:134
static Clock::duration const InfinityCooldownDelay
Definition: SpellHistory.h:89
int32_t int32
Definition: g3dmath.h:167
void ResetCooldowns(Predicate predicate, bool update=false)
Definition: SpellHistory.h:106
Clock::time_point CooldownEnd
Definition: SpellHistory.h:50
std::chrono::system_clock Clock
Definition: SpellHistory.h:45
void Update(uint32 diff)
Definition: WeatherMgr.cpp:150
CooldownStorageType::iterator EraseCooldown(CooldownStorageType::iterator itr)
Definition: SpellHistory.h:155
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58