18#ifndef TRINITYCORE_SPELL_HISTORY_H
19#define TRINITYCORE_SPELL_HISTORY_H
28#include <unordered_map>
44class SendSpellHistory;
45class SendSpellCharges;
61 using Clock = std::chrono::system_clock;
63 using TimePoint = std::chrono::time_point<Clock, Duration>;
100 template<
class OwnerType>
103 template<
class OwnerType>
108 void HandleCooldowns(
SpellInfo const* spellInfo,
Item const* item,
Spell* spell =
nullptr);
119 void SendCooldownEvent(
SpellInfo const* spellInfo,
uint32 itemId = 0,
Spell* spell =
nullptr,
bool startCooldown =
true);
123 TimePoint now = time_point_cast<Duration>(GameTime::GetTime<Clock>());
124 AddCooldown(spellId, itemId, now + cooldownDuration, 0, now);
128 void ModifyCooldown(
uint32 spellId,
Duration cooldownMod,
bool withoutCategoryCooldown =
false);
129 void ModifyCooldown(
SpellInfo const* spellInfo,
Duration cooldownMod,
bool withoutCategoryCooldown =
false);
130 template <Trinity::invocable_r<
bool, CooldownEntry const&> Predicate>
133 for (
auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();)
135 if (std::forward<Predicate>(predicate)(itr->second))
136 ModifySpellCooldown(itr, cooldownMod, withoutCategoryCooldown);
142 template <Trinity::invocable_r<
bool, CooldownEntry const&> Predicate>
145 for (
auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end(); ++itr)
147 if (std::forward<Predicate>(predicate)(itr->second))
148 UpdateCooldownRecoveryRate(itr, modChange,
apply);
152 void ResetCooldown(
uint32 spellId,
bool update =
false);
153 template <Trinity::invocable_r<
bool, CooldownEntry const&> Predicate>
156 std::vector<int32> resetCooldowns;
157 resetCooldowns.reserve(_spellCooldowns.size());
158 for (
auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();)
160 if (std::forward<Predicate>(predicate)(itr->second))
162 resetCooldowns.push_back(
int32(itr->first));
163 ResetCooldown(itr,
false);
169 if (update && !resetCooldowns.empty())
170 SendClearCooldowns(resetCooldowns);
173 void ResetAllCooldowns();
175 bool HasCooldown(
uint32 spellId,
uint32 itemId = 0)
const;
185 bool ConsumeCharge(
uint32 chargeCategoryId);
186 void ModifyChargeRecoveryTime(
uint32 chargeCategoryId,
Duration cooldownMod);
187 void UpdateChargeRecoveryRate(
uint32 chargeCategoryId,
float modChange,
bool apply);
188 void RestoreCharge(
uint32 chargeCategoryId);
189 void ResetCharges(
uint32 chargeCategoryId);
190 void ResetAllCharges();
191 bool HasCharge(
uint32 chargeCategoryId)
const;
192 int32 GetMaxCharges(
uint32 chargeCategoryId)
const;
193 int32 GetChargeRecoveryTime(
uint32 chargeCategoryId)
const;
196 bool HasGlobalCooldown(
SpellInfo const* spellInfo)
const;
198 void CancelGlobalCooldown(
SpellInfo const* spellInfo);
201 bool IsPaused()
const {
return _pauseTime.has_value(); }
202 void PauseCooldowns();
203 void ResumeCooldowns();
207 void SaveCooldownStateBeforeDuel();
208 void RestoreCooldownStateAfterDuel();
211 Player* GetPlayerOwner()
const;
212 void ModifySpellCooldown(
uint32 spellId,
Duration cooldownMod,
bool withoutCategoryCooldown);
213 void ModifySpellCooldown(CooldownStorageType::iterator& itr,
Duration cooldownMod,
bool withoutCategoryCooldown);
214 void UpdateCooldownRecoveryRate(CooldownStorageType::iterator& itr,
float modChange,
bool apply);
215 void ResetCooldown(CooldownStorageType::iterator& itr,
bool update =
false);
216 void SendClearCooldowns(std::vector<int32>
const& cooldowns)
const;
217 CooldownStorageType::iterator
EraseCooldown(CooldownStorageType::iterator itr)
219 _categoryCooldowns.erase(itr->second.CategoryId);
220 return _spellCooldowns.erase(itr);
223 void SendSetSpellCharges(
uint32 chargeCategoryId, ChargeEntryCollection
const& chargeCollection)
const;
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
std::shared_ptr< PreparedResultSet > PreparedQueryResult
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
std::chrono::steady_clock::time_point TimePoint
time_point shorthand typedefs
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)
void UpdateCooldownRecoveryRate(Predicate &&predicate, float modChange, bool apply)
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
void ResetCooldowns(Predicate &&predicate, bool update=false)
SpellHistory(SpellHistory &&)=delete
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)