18#ifndef SpellHistory_h__
19#define SpellHistory_h__
25#include <unordered_map>
51 typedef std::chrono::system_clock
Clock;
69 template<
class OwnerType>
72 template<
class OwnerType>
77 void HandleCooldowns(
SpellInfo const* spellInfo,
Item const* item,
Spell* spell =
nullptr);
79 bool IsReady(
SpellInfo const* spellInfo,
uint32 itemId = 0,
bool ignoreCategoryCooldown =
false)
const;
80 template<
class OwnerType>
88 void StartCooldown(
SpellInfo const* spellInfo,
uint32 itemId,
Spell* spell =
nullptr,
bool onHold =
false);
89 void SendCooldownEvent(
SpellInfo const* spellInfo,
uint32 itemId = 0,
Spell* spell =
nullptr,
bool startCooldown =
true);
91 template<
class Type,
class Period>
95 AddCooldown(spellId, itemId, now + std::chrono::duration_cast<Clock::duration>(cooldownDuration), 0, now);
98 void AddCooldown(
uint32 spellId,
uint32 itemId, Clock::time_point cooldownEnd,
uint32 categoryId, Clock::time_point categoryEnd,
bool onHold =
false);
99 void ModifyCooldown(
uint32 spellId,
int32 cooldownModMs);
100 void ResetCooldown(
uint32 spellId,
bool update =
false);
101 void ResetCooldown(CooldownStorageType::iterator& itr,
bool update =
false);
102 template<
typename Predicate>
105 std::vector<int32> resetCooldowns;
106 resetCooldowns.reserve(_spellCooldowns.size());
107 for (
auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();)
111 resetCooldowns.push_back(itr->first);
112 ResetCooldown(itr,
false);
118 if (update && !resetCooldowns.empty())
119 SendClearCooldowns(resetCooldowns);
122 void ResetAllCooldowns();
123 bool HasCooldown(
SpellInfo const* spellInfo,
uint32 itemId = 0,
bool ignoreCategoryCooldown =
false)
const;
124 bool HasCooldown(
uint32 spellId,
uint32 itemId = 0,
bool ignoreCategoryCooldown =
false)
const;
132 bool HasGlobalCooldown(
SpellInfo const* spellInfo)
const;
134 void CancelGlobalCooldown(
SpellInfo const* spellInfo);
141 void SaveCooldownStateBeforeDuel();
142 void RestoreCooldownStateAfterDuel();
145 Player* GetPlayerOwner()
const;
146 void SendClearCooldowns(std::vector<int32>
const& cooldowns)
const;
147 CooldownStorageType::iterator
EraseCooldown(CooldownStorageType::iterator itr)
149 _categoryCooldowns.erase(itr->second.CategoryId);
150 return _spellCooldowns.erase(itr);
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
std::shared_ptr< PreparedResultSet > PreparedQueryResult
static void SaveToDB(QuestPool const &pool, CharacterDatabaseTransaction trans)
SpellCooldownFlags
Spell cooldown flags sent in SMSG_SPELL_COOLDOWN.
@ SPELL_COOLDOWN_FLAG_INCLUDE_EVENT_COOLDOWNS
Starts GCD for spells that should start their cooldown on events, requires SPELL_COOLDOWN_FLAG_INCLUD...
@ SPELL_COOLDOWN_FLAG_INCLUDE_GCD
Starts GCD in addition to normal cooldown specified in the packet.
@ SPELL_COOLDOWN_FLAG_NONE
static Clock::duration const InfinityCooldownDelay
GlobalCooldownStorageType _globalCooldowns
CooldownStorageType::size_type GetCooldownsSizeForPacket() const
std::unordered_map< uint32, Clock::time_point > GlobalCooldownStorageType
static Clock::duration const InfinityCooldownDelayCheck
void AddCooldown(uint32 spellId, uint32 itemId, std::chrono::duration< Type, Period > cooldownDuration)
std::unordered_map< uint32, CooldownEntry * > CategoryCooldownStorageType
SpellHistory(Unit *owner)
CooldownStorageType _spellCooldowns
void WritePacket(WorldPacket &packet) const
std::chrono::system_clock Clock
CooldownStorageType _spellCooldownsBeforeDuel
std::unordered_map< uint32, CooldownEntry > CooldownStorageType
std::unordered_map< uint32, uint32 > PacketCooldowns
CooldownStorageType::iterator EraseCooldown(CooldownStorageType::iterator itr)
void ResetCooldowns(Predicate predicate, bool update=false)
CategoryCooldownStorageType _categoryCooldowns
SystemTimePoint GetSystemTime()
Current chrono system_clock time point.
Clock::time_point CooldownEnd
Clock::time_point CategoryEnd