18#ifndef SpellHistory_h__
19#define SpellHistory_h__
27#include <unordered_map>
49 using Clock = std::chrono::system_clock;
51 using TimePoint = std::chrono::time_point<Clock, Duration>;
88 template<
class OwnerType>
91 template<
class OwnerType>
96 void HandleCooldowns(
SpellInfo const* spellInfo,
Item const* item,
Spell* spell =
nullptr);
99 template<
class PacketType>
100 void WritePacket(PacketType* packet)
const;
106 void SendCooldownEvent(
SpellInfo const* spellInfo,
uint32 itemId = 0,
Spell* spell =
nullptr,
bool startCooldown =
true);
110 TimePoint now = time_point_cast<Duration>(GameTime::GetTime<Clock>());
111 AddCooldown(spellId, itemId, now + cooldownDuration, 0, now);
115 void ModifyCooldown(
uint32 spellId,
Duration cooldownMod,
bool withoutCategoryCooldown =
false);
116 void ModifyCooldown(
SpellInfo const* spellInfo,
Duration cooldownMod,
bool withoutCategoryCooldown =
false);
117 template<
typename Predicate>
120 for (
auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();)
123 ModifySpellCooldown(itr, cooldownMod, withoutCategoryCooldown);
129 void ResetCooldown(
uint32 spellId,
bool update =
false);
130 template<
typename Predicate>
133 std::vector<int32> resetCooldowns;
134 resetCooldowns.reserve(_spellCooldowns.size());
135 for (
auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();)
139 resetCooldowns.push_back(
int32(itr->first));
140 ResetCooldown(itr,
false);
146 if (update && !resetCooldowns.empty())
147 SendClearCooldowns(resetCooldowns);
150 void ResetAllCooldowns();
152 bool HasCooldown(
uint32 spellId,
uint32 itemId = 0)
const;
162 bool ConsumeCharge(
uint32 chargeCategoryId);
163 void ModifyChargeRecoveryTime(
uint32 chargeCategoryId,
Duration cooldownMod);
164 void RestoreCharge(
uint32 chargeCategoryId);
165 void ResetCharges(
uint32 chargeCategoryId);
166 void ResetAllCharges();
167 bool HasCharge(
uint32 chargeCategoryId)
const;
168 int32 GetMaxCharges(
uint32 chargeCategoryId)
const;
169 int32 GetChargeRecoveryTime(
uint32 chargeCategoryId)
const;
172 bool HasGlobalCooldown(
SpellInfo const* spellInfo)
const;
174 void CancelGlobalCooldown(
SpellInfo const* spellInfo);
177 bool IsPaused()
const {
return _pauseTime.has_value(); }
178 void PauseCooldowns();
179 void ResumeCooldowns();
181 void SaveCooldownStateBeforeDuel();
182 void RestoreCooldownStateAfterDuel();
185 Player* GetPlayerOwner()
const;
186 void ModifySpellCooldown(
uint32 spellId,
Duration cooldownMod,
bool withoutCategoryCooldown);
187 void ModifySpellCooldown(CooldownStorageType::iterator& itr,
Duration cooldownMod,
bool withoutCategoryCooldown);
188 void ResetCooldown(CooldownStorageType::iterator& itr,
bool update =
false);
189 void SendClearCooldowns(std::vector<int32>
const& cooldowns)
const;
190 CooldownStorageType::iterator
EraseCooldown(CooldownStorageType::iterator itr)
192 _categoryCooldowns.erase(itr->second.CategoryId);
193 return _spellCooldowns.erase(itr);
196 void SendSetSpellCharges(
uint32 chargeCategoryId, ChargeEntryCollection
const& chargeCollection);
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
std::shared_ptr< PreparedResultSet > PreparedQueryResult
std::chrono::steady_clock::time_point TimePoint
time_point shorthand typedefs
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
std::unordered_map< uint32, TimePoint > GlobalCooldownStorageType
static Duration const InfinityCooldownDelay
Optional< TimePoint > _pauseTime
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
CooldownStorageType _spellCooldownsBeforeDuel
std::chrono::time_point< Clock, Duration > TimePoint
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
void Update(VignetteData &vignette, WorldObject const *owner)
ChargeEntry(TimePoint startTime, Duration rechargeTime)
ChargeEntry(TimePoint startTime, TimePoint endTime)