18#ifndef SpellHistory_h__
19#define SpellHistory_h__
28#include <unordered_map>
49 using Clock = std::chrono::system_clock;
55 Clock::time_point CooldownEnd = Clock::time_point::min();
58 Clock::time_point CategoryEnd = Clock::time_point::min();
65 ChargeEntry(Clock::time_point startTime,
Duration rechargeTime) : RechargeStart(startTime), RechargeEnd(startTime + rechargeTime) { }
66 ChargeEntry(Clock::time_point startTime, Clock::time_point endTime) : RechargeStart(startTime), RechargeEnd(endTime) { }
87 template<
class OwnerType>
90 template<
class OwnerType>
95 void HandleCooldowns(
SpellInfo const* spellInfo,
Item const* item,
Spell* spell =
nullptr);
98 template<
class PacketType>
99 void WritePacket(PacketType* packet)
const;
105 void SendCooldownEvent(
SpellInfo const* spellInfo,
uint32 itemId = 0,
Spell* spell =
nullptr,
bool startCooldown =
true);
109 Clock::time_point now = GameTime::GetTime<Clock>();
110 AddCooldown(spellId, itemId, now + cooldownDuration, 0, now);
113 void AddCooldown(
uint32 spellId,
uint32 itemId, Clock::time_point cooldownEnd,
uint32 categoryId, Clock::time_point categoryEnd,
bool onHold =
false);
114 void ModifyCooldown(
uint32 spellId,
Duration cooldownMod,
bool withoutCategoryCooldown =
false);
115 void ModifyCooldown(
SpellInfo const* spellInfo,
Duration cooldownMod,
bool withoutCategoryCooldown =
false);
116 template<
typename Predicate>
119 for (
auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();)
122 ModifySpellCooldown(itr, cooldownMod, withoutCategoryCooldown);
128 void ResetCooldown(
uint32 spellId,
bool update =
false);
129 template<
typename Predicate>
132 std::vector<int32> resetCooldowns;
133 resetCooldowns.reserve(_spellCooldowns.size());
134 for (
auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();)
138 resetCooldowns.push_back(
int32(itr->first));
139 ResetCooldown(itr,
false);
145 if (update && !resetCooldowns.empty())
146 SendClearCooldowns(resetCooldowns);
149 void ResetAllCooldowns();
151 bool HasCooldown(
uint32 spellId,
uint32 itemId = 0)
const;
161 bool ConsumeCharge(
uint32 chargeCategoryId);
162 void ModifyChargeRecoveryTime(
uint32 chargeCategoryId,
Duration cooldownMod);
163 void RestoreCharge(
uint32 chargeCategoryId);
164 void ResetCharges(
uint32 chargeCategoryId);
165 void ResetAllCharges();
166 bool HasCharge(
uint32 chargeCategoryId)
const;
167 int32 GetMaxCharges(
uint32 chargeCategoryId)
const;
168 int32 GetChargeRecoveryTime(
uint32 chargeCategoryId)
const;
171 bool HasGlobalCooldown(
SpellInfo const* spellInfo)
const;
173 void CancelGlobalCooldown(
SpellInfo const* spellInfo);
175 void SaveCooldownStateBeforeDuel();
176 void RestoreCooldownStateAfterDuel();
179 Player* GetPlayerOwner()
const;
180 void ModifySpellCooldown(
uint32 spellId,
Duration cooldownMod,
bool withoutCategoryCooldown);
181 void ModifySpellCooldown(CooldownStorageType::iterator& itr,
Duration cooldownMod,
bool withoutCategoryCooldown);
182 void ResetCooldown(CooldownStorageType::iterator& itr,
bool update =
false);
183 void SendClearCooldowns(std::vector<int32>
const& cooldowns)
const;
184 CooldownStorageType::iterator
EraseCooldown(CooldownStorageType::iterator itr)
186 _categoryCooldowns.erase(itr->second.CategoryId);
187 return _spellCooldowns.erase(itr);
190 void SendSetSpellCharges(
uint32 chargeCategoryId, ChargeEntryCollection
const& chargeCollection);
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
std::shared_ptr< PreparedResultSet > PreparedQueryResult
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
std::optional< T > Optional
Optional helper class to wrap optional values within.
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_LOSS_OF_CONTROL_UI
Shows interrupt cooldown in loss of control ui.
@ SPELL_COOLDOWN_FLAG_NONE
@ SPELL_COOLDOWN_FLAG_ON_HOLD
Forces cooldown to behave as if SpellInfo::IsCooldownStartedOnEvent was true.
void AddCooldown(uint32 spellId, uint32 itemId, Duration cooldownDuration)
SpellHistory & operator=(SpellHistory const &)=delete
GlobalCooldownStorageType _globalCooldowns
std::unordered_map< uint32, CooldownEntry * > CategoryCooldownStorageType
std::chrono::system_clock Clock
static Duration const InfinityCooldownDelay
std::deque< ChargeEntry > ChargeEntryCollection
SpellHistory(SpellHistory const &)=delete
CooldownStorageType _spellCooldowns
void ModifyCoooldowns(Predicate &&predicate, Duration cooldownMod, bool withoutCategoryCooldown=false)
std::unordered_map< uint32, CooldownEntry > CooldownStorageType
std::unordered_map< uint32, Clock::time_point > GlobalCooldownStorageType
CooldownStorageType _spellCooldownsBeforeDuel
CooldownStorageType::iterator EraseCooldown(CooldownStorageType::iterator itr)
std::unordered_map< uint32, ChargeEntryCollection > ChargeStorageType
SpellHistory(SpellHistory &&)=delete
void ResetCooldowns(Predicate predicate, bool update=false)
SpellHistory & operator=(SpellHistory &&)=delete
ChargeStorageType _categoryCharges
CategoryCooldownStorageType _categoryCooldowns
Clock::time_point RechargeStart
Clock::time_point RechargeEnd
ChargeEntry(Clock::time_point startTime, Duration rechargeTime)
ChargeEntry(Clock::time_point startTime, Clock::time_point endTime)