TrinityCore
SpellHistory Class Reference

#include <SpellHistory.h>

Classes

struct  ChargeEntry
 
struct  CooldownEntry
 
struct  PersistenceHelper
 
struct  PersistenceHelper< Pet >
 
struct  PersistenceHelper< Player >
 

Public Types

using Clock = std::chrono::system_clock
 
using Duration = Milliseconds
 
using TimePoint = std::chrono::time_point< Clock, Duration >
 
using ChargeEntryCollection = std::deque< ChargeEntry >
 
using CooldownStorageType = std::unordered_map< uint32, CooldownEntry >
 
using CategoryCooldownStorageType = std::unordered_map< uint32, CooldownEntry * >
 
using ChargeStorageType = std::unordered_map< uint32, ChargeEntryCollection >
 
using GlobalCooldownStorageType = std::unordered_map< uint32, TimePoint >
 

Public Member Functions

 SpellHistory (Unit *owner)
 
 ~SpellHistory ()
 
 SpellHistory (SpellHistory const &)=delete
 
 SpellHistory (SpellHistory &&)=delete
 
SpellHistoryoperator= (SpellHistory const &)=delete
 
SpellHistoryoperator= (SpellHistory &&)=delete
 
template<class OwnerType >
void LoadFromDB (PreparedQueryResult cooldownsResult, PreparedQueryResult chargesResult)
 
template<class OwnerType >
void SaveToDB (CharacterDatabaseTransaction trans)
 
void Update ()
 
void HandleCooldowns (SpellInfo const *spellInfo, Item const *item, Spell *spell=nullptr)
 
void HandleCooldowns (SpellInfo const *spellInfo, uint32 itemId, Spell *spell=nullptr)
 
bool IsReady (SpellInfo const *spellInfo, uint32 itemId=0) const
 
void WritePacket (WorldPackets::Spells::SendSpellHistory *sendSpellHistory) const
 
void WritePacket (WorldPackets::Spells::SendSpellCharges *sendSpellCharges) const
 
void WritePacket (WorldPackets::Pet::PetSpells *petSpells) const
 
void StartCooldown (SpellInfo const *spellInfo, uint32 itemId, Spell *spell=nullptr, bool onHold=false, Optional< Duration > forcedCooldown={})
 
void SendCooldownEvent (SpellInfo const *spellInfo, uint32 itemId=0, Spell *spell=nullptr, bool startCooldown=true)
 
void AddCooldown (uint32 spellId, uint32 itemId, Duration cooldownDuration)
 
void AddCooldown (uint32 spellId, uint32 itemId, TimePoint cooldownEnd, uint32 categoryId, TimePoint categoryEnd, bool onHold=false)
 
void ModifyCooldown (uint32 spellId, Duration cooldownMod, bool withoutCategoryCooldown=false)
 
void ModifyCooldown (SpellInfo const *spellInfo, Duration cooldownMod, bool withoutCategoryCooldown=false)
 
template<Trinity::invocable_r< bool, CooldownEntry const & > Predicate>
void ModifyCoooldowns (Predicate &&predicate, Duration cooldownMod, bool withoutCategoryCooldown=false)
 
template<Trinity::invocable_r< bool, CooldownEntry const & > Predicate>
void UpdateCooldownRecoveryRate (Predicate &&predicate, float modChange, bool apply)
 
void ResetCooldown (uint32 spellId, bool update=false)
 
template<Trinity::invocable_r< bool, CooldownEntry const & > Predicate>
void ResetCooldowns (Predicate &&predicate, bool update=false)
 
void ResetAllCooldowns ()
 
bool HasCooldown (SpellInfo const *spellInfo, uint32 itemId=0) const
 
bool HasCooldown (uint32 spellId, uint32 itemId=0) const
 
Duration GetRemainingCooldown (SpellInfo const *spellInfo) const
 
Duration GetRemainingCategoryCooldown (uint32 categoryId) const
 
Duration GetRemainingCategoryCooldown (SpellInfo const *spellInfo) const
 
void LockSpellSchool (SpellSchoolMask schoolMask, Duration lockoutTime)
 
bool IsSchoolLocked (SpellSchoolMask schoolMask) const
 
bool ConsumeCharge (uint32 chargeCategoryId)
 
void ModifyChargeRecoveryTime (uint32 chargeCategoryId, Duration cooldownMod)
 
void UpdateChargeRecoveryRate (uint32 chargeCategoryId, float modChange, bool apply)
 
void RestoreCharge (uint32 chargeCategoryId)
 
void ResetCharges (uint32 chargeCategoryId)
 
void ResetAllCharges ()
 
bool HasCharge (uint32 chargeCategoryId) const
 
int32 GetMaxCharges (uint32 chargeCategoryId) const
 
int32 GetChargeRecoveryTime (uint32 chargeCategoryId) const
 
bool HasGlobalCooldown (SpellInfo const *spellInfo) const
 
void AddGlobalCooldown (SpellInfo const *spellInfo, Duration duration)
 
void CancelGlobalCooldown (SpellInfo const *spellInfo)
 
Duration GetRemainingGlobalCooldown (SpellInfo const *spellInfo) const
 
bool IsPaused () const
 
void PauseCooldowns ()
 
void ResumeCooldowns ()
 
void SaveCooldownStateBeforeDuel ()
 
void RestoreCooldownStateAfterDuel ()
 

Static Public Member Functions

static void GetCooldownDurations (SpellInfo const *spellInfo, uint32 itemId, Duration *cooldown, uint32 *categoryId, Duration *categoryCooldown)
 

Static Public Attributes

static Duration const InfinityCooldownDelay = Seconds(MONTH)
 

Private Member Functions

PlayerGetPlayerOwner () const
 
void ModifySpellCooldown (uint32 spellId, Duration cooldownMod, bool withoutCategoryCooldown)
 
void ModifySpellCooldown (CooldownStorageType::iterator &itr, Duration cooldownMod, bool withoutCategoryCooldown)
 
void UpdateCooldownRecoveryRate (CooldownStorageType::iterator &itr, float modChange, bool apply)
 
void ResetCooldown (CooldownStorageType::iterator &itr, bool update=false)
 
void SendClearCooldowns (std::vector< int32 > const &cooldowns) const
 
CooldownStorageType::iterator EraseCooldown (CooldownStorageType::iterator itr)
 
void SendSetSpellCharges (uint32 chargeCategoryId, ChargeEntryCollection const &chargeCollection) const
 

Private Attributes

Unit_owner
 
CooldownStorageType _spellCooldowns
 
CooldownStorageType _spellCooldownsBeforeDuel
 
CategoryCooldownStorageType _categoryCooldowns
 
TimePoint _schoolLockouts [MAX_SPELL_SCHOOL]
 
ChargeStorageType _categoryCharges
 
GlobalCooldownStorageType _globalCooldowns
 
Optional< TimePoint_pauseTime
 

Detailed Description

Definition at line 58 of file SpellHistory.h.

Member Typedef Documentation

◆ CategoryCooldownStorageType

Definition at line 87 of file SpellHistory.h.

◆ ChargeEntryCollection

Definition at line 85 of file SpellHistory.h.

◆ ChargeStorageType

Definition at line 88 of file SpellHistory.h.

◆ Clock

using SpellHistory::Clock = std::chrono::system_clock

Definition at line 61 of file SpellHistory.h.

◆ CooldownStorageType

Definition at line 86 of file SpellHistory.h.

◆ Duration

Definition at line 62 of file SpellHistory.h.

◆ GlobalCooldownStorageType

Definition at line 89 of file SpellHistory.h.

◆ TimePoint

using SpellHistory::TimePoint = std::chrono::time_point<Clock, Duration>

Definition at line 63 of file SpellHistory.h.

Constructor & Destructor Documentation

◆ SpellHistory() [1/3]

SpellHistory::SpellHistory ( Unit owner)
explicit

Definition at line 141 of file SpellHistory.cpp.

◆ ~SpellHistory()

SpellHistory::~SpellHistory ( )
default

◆ SpellHistory() [2/3]

SpellHistory::SpellHistory ( SpellHistory const &  )
delete

◆ SpellHistory() [3/3]

SpellHistory::SpellHistory ( SpellHistory &&  )
delete

Member Function Documentation

◆ AddCooldown() [1/2]

void SpellHistory::AddCooldown ( uint32  spellId,
uint32  itemId,
Duration  cooldownDuration 
)
inline

Definition at line 121 of file SpellHistory.h.

+ Here is the caller graph for this function:

◆ AddCooldown() [2/2]

void SpellHistory::AddCooldown ( uint32  spellId,
uint32  itemId,
TimePoint  cooldownEnd,
uint32  categoryId,
TimePoint  categoryEnd,
bool  onHold = false 
)

Definition at line 576 of file SpellHistory.cpp.

◆ AddGlobalCooldown()

void SpellHistory::AddGlobalCooldown ( SpellInfo const *  spellInfo,
Duration  duration 
)

Definition at line 1049 of file SpellHistory.cpp.

+ Here is the caller graph for this function:

◆ CancelGlobalCooldown()

void SpellHistory::CancelGlobalCooldown ( SpellInfo const *  spellInfo)

Definition at line 1054 of file SpellHistory.cpp.

+ Here is the caller graph for this function:

◆ ConsumeCharge()

bool SpellHistory::ConsumeCharge ( uint32  chargeCategoryId)

Definition at line 854 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ EraseCooldown()

CooldownStorageType::iterator SpellHistory::EraseCooldown ( CooldownStorageType::iterator  itr)
inlineprivate

Definition at line 217 of file SpellHistory.h.

+ Here is the caller graph for this function:

◆ GetChargeRecoveryTime()

int32 SpellHistory::GetChargeRecoveryTime ( uint32  chargeCategoryId) const

Definition at line 1005 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetCooldownDurations()

void SpellHistory::GetCooldownDurations ( SpellInfo const *  spellInfo,
uint32  itemId,
Duration cooldown,
uint32 categoryId,
Duration categoryCooldown 
)
static

Definition at line 1128 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetMaxCharges()

int32 SpellHistory::GetMaxCharges ( uint32  chargeCategoryId) const

Definition at line 994 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPlayerOwner()

Player * SpellHistory::GetPlayerOwner ( ) const
private

Definition at line 1098 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetRemainingCategoryCooldown() [1/2]

SpellHistory::Duration SpellHistory::GetRemainingCategoryCooldown ( SpellInfo const *  spellInfo) const

Definition at line 779 of file SpellHistory.cpp.

+ Here is the call graph for this function:

◆ GetRemainingCategoryCooldown() [2/2]

SpellHistory::Duration SpellHistory::GetRemainingCategoryCooldown ( uint32  categoryId) const

Definition at line 763 of file SpellHistory.cpp.

+ Here is the caller graph for this function:

◆ GetRemainingCooldown()

SpellHistory::Duration SpellHistory::GetRemainingCooldown ( SpellInfo const *  spellInfo) const

Definition at line 740 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetRemainingGlobalCooldown()

SpellHistory::Duration SpellHistory::GetRemainingGlobalCooldown ( SpellInfo const *  spellInfo) const

Definition at line 1059 of file SpellHistory.cpp.

+ Here is the caller graph for this function:

◆ HandleCooldowns() [1/2]

void SpellHistory::HandleCooldowns ( SpellInfo const *  spellInfo,
Item const *  item,
Spell spell = nullptr 
)

Definition at line 245 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HandleCooldowns() [2/2]

void SpellHistory::HandleCooldowns ( SpellInfo const *  spellInfo,
uint32  itemId,
Spell spell = nullptr 
)

Definition at line 250 of file SpellHistory.cpp.

+ Here is the call graph for this function:

◆ HasCharge()

bool SpellHistory::HasCharge ( uint32  chargeCategoryId) const

Definition at line 980 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasCooldown() [1/2]

bool SpellHistory::HasCooldown ( SpellInfo const *  spellInfo,
uint32  itemId = 0 
) const

Definition at line 716 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasCooldown() [2/2]

bool SpellHistory::HasCooldown ( uint32  spellId,
uint32  itemId = 0 
) const

Definition at line 735 of file SpellHistory.cpp.

+ Here is the call graph for this function:

◆ HasGlobalCooldown()

bool SpellHistory::HasGlobalCooldown ( SpellInfo const *  spellInfo) const

Definition at line 1043 of file SpellHistory.cpp.

+ Here is the caller graph for this function:

◆ IsPaused()

bool SpellHistory::IsPaused ( ) const
inline

Definition at line 201 of file SpellHistory.h.

◆ IsReady()

bool SpellHistory::IsReady ( SpellInfo const *  spellInfo,
uint32  itemId = 0 
) const

Definition at line 280 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsSchoolLocked()

bool SpellHistory::IsSchoolLocked ( SpellSchoolMask  schoolMask) const

Definition at line 843 of file SpellHistory.cpp.

+ Here is the caller graph for this function:

◆ LoadFromDB()

template<class OwnerType >
template void SpellHistory::LoadFromDB< Pet > ( PreparedQueryResult  cooldownsResult,
PreparedQueryResult  chargesResult 
)

Definition at line 148 of file SpellHistory.cpp.

+ Here is the caller graph for this function:

◆ LockSpellSchool()

void SpellHistory::LockSpellSchool ( SpellSchoolMask  schoolMask,
Duration  lockoutTime 
)

Definition at line 784 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ModifyChargeRecoveryTime()

void SpellHistory::ModifyChargeRecoveryTime ( uint32  chargeCategoryId,
Duration  cooldownMod 
)

Definition at line 879 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ModifyCooldown() [1/2]

void SpellHistory::ModifyCooldown ( SpellInfo const *  spellInfo,
Duration  cooldownMod,
bool  withoutCategoryCooldown = false 
)

Definition at line 663 of file SpellHistory.cpp.

+ Here is the call graph for this function:

◆ ModifyCooldown() [2/2]

void SpellHistory::ModifyCooldown ( uint32  spellId,
Duration  cooldownMod,
bool  withoutCategoryCooldown = false 
)

Definition at line 657 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ModifyCoooldowns()

template<Trinity::invocable_r< bool, CooldownEntry const & > Predicate>
void SpellHistory::ModifyCoooldowns ( Predicate &&  predicate,
Duration  cooldownMod,
bool  withoutCategoryCooldown = false 
)
inline

Definition at line 131 of file SpellHistory.h.

+ Here is the caller graph for this function:

◆ ModifySpellCooldown() [1/2]

void SpellHistory::ModifySpellCooldown ( CooldownStorageType::iterator &  itr,
Duration  cooldownMod,
bool  withoutCategoryCooldown 
)
private

Definition at line 603 of file SpellHistory.cpp.

+ Here is the call graph for this function:

◆ ModifySpellCooldown() [2/2]

void SpellHistory::ModifySpellCooldown ( uint32  spellId,
Duration  cooldownMod,
bool  withoutCategoryCooldown 
)
private

Definition at line 594 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=() [1/2]

SpellHistory & SpellHistory::operator= ( SpellHistory &&  )
delete

◆ operator=() [2/2]

SpellHistory & SpellHistory::operator= ( SpellHistory const &  )
delete

◆ PauseCooldowns()

void SpellHistory::PauseCooldowns ( )

Definition at line 1074 of file SpellHistory.cpp.

◆ ResetAllCharges()

void SpellHistory::ResetAllCharges ( )

Definition at line 968 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ResetAllCooldowns()

void SpellHistory::ResetAllCooldowns ( )

Definition at line 700 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ResetCharges()

void SpellHistory::ResetCharges ( uint32  chargeCategoryId)

Definition at line 951 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ResetCooldown() [1/2]

void SpellHistory::ResetCooldown ( CooldownStorageType::iterator &  itr,
bool  update = false 
)
private

Definition at line 683 of file SpellHistory.cpp.

+ Here is the call graph for this function:

◆ ResetCooldown() [2/2]

void SpellHistory::ResetCooldown ( uint32  spellId,
bool  update = false 
)

Definition at line 674 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ResetCooldowns()

template<Trinity::invocable_r< bool, CooldownEntry const & > Predicate>
void SpellHistory::ResetCooldowns ( Predicate &&  predicate,
bool  update = false 
)
inline

Definition at line 154 of file SpellHistory.h.

+ Here is the caller graph for this function:

◆ RestoreCharge()

void SpellHistory::RestoreCharge ( uint32  chargeCategoryId)

Definition at line 940 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RestoreCooldownStateAfterDuel()

void SpellHistory::RestoreCooldownStateAfterDuel ( )

Definition at line 1174 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ResumeCooldowns()

void SpellHistory::ResumeCooldowns ( )

Definition at line 1079 of file SpellHistory.cpp.

+ Here is the call graph for this function:

◆ SaveCooldownStateBeforeDuel()

void SpellHistory::SaveCooldownStateBeforeDuel ( )

Definition at line 1169 of file SpellHistory.cpp.

+ Here is the caller graph for this function:

◆ SaveToDB()

template<class OwnerType >
template void SpellHistory::SaveToDB< Pet > ( CharacterDatabaseTransaction  trans)

Definition at line 183 of file SpellHistory.cpp.

+ Here is the caller graph for this function:

◆ SendClearCooldowns()

void SpellHistory::SendClearCooldowns ( std::vector< int32 > const &  cooldowns) const
private

Definition at line 1103 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SendCooldownEvent()

void SpellHistory::SendCooldownEvent ( SpellInfo const *  spellInfo,
uint32  itemId = 0,
Spell spell = nullptr,
bool  startCooldown = true 
)

Definition at line 551 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SendSetSpellCharges()

void SpellHistory::SendSetSpellCharges ( uint32  chargeCategoryId,
ChargeEntryCollection const &  chargeCollection 
) const
private

Definition at line 1114 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StartCooldown()

void SpellHistory::StartCooldown ( SpellInfo const *  spellInfo,
uint32  itemId,
Spell spell = nullptr,
bool  onHold = false,
Optional< Duration forcedCooldown = {} 
)

Definition at line 398 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Update()

void SpellHistory::Update ( )

Definition at line 221 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UpdateChargeRecoveryRate()

void SpellHistory::UpdateChargeRecoveryRate ( uint32  chargeCategoryId,
float  modChange,
bool  apply 
)

Definition at line 903 of file SpellHistory.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UpdateCooldownRecoveryRate() [1/2]

void SpellHistory::UpdateCooldownRecoveryRate ( CooldownStorageType::iterator &  itr,
float  modChange,
bool  apply 
)
private

Definition at line 633 of file SpellHistory.cpp.

+ Here is the call graph for this function:

◆ UpdateCooldownRecoveryRate() [2/2]

template<Trinity::invocable_r< bool, CooldownEntry const & > Predicate>
void SpellHistory::UpdateCooldownRecoveryRate ( Predicate &&  predicate,
float  modChange,
bool  apply 
)
inline

Definition at line 143 of file SpellHistory.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WritePacket() [1/3]

void SpellHistory::WritePacket ( WorldPackets::Pet::PetSpells petSpells) const

Definition at line 351 of file SpellHistory.cpp.

◆ WritePacket() [2/3]

void SpellHistory::WritePacket ( WorldPackets::Spells::SendSpellCharges sendSpellCharges) const

Definition at line 329 of file SpellHistory.cpp.

◆ WritePacket() [3/3]

void SpellHistory::WritePacket ( WorldPackets::Spells::SendSpellHistory sendSpellHistory) const

Definition at line 295 of file SpellHistory.cpp.

+ Here is the caller graph for this function:

Member Data Documentation

◆ _categoryCharges

ChargeStorageType SpellHistory::_categoryCharges
private

Definition at line 230 of file SpellHistory.h.

◆ _categoryCooldowns

CategoryCooldownStorageType SpellHistory::_categoryCooldowns
private

Definition at line 228 of file SpellHistory.h.

◆ _globalCooldowns

GlobalCooldownStorageType SpellHistory::_globalCooldowns
private

Definition at line 231 of file SpellHistory.h.

◆ _owner

Unit* SpellHistory::_owner
private

Definition at line 225 of file SpellHistory.h.

◆ _pauseTime

Optional<TimePoint> SpellHistory::_pauseTime
private

Definition at line 232 of file SpellHistory.h.

◆ _schoolLockouts

TimePoint SpellHistory::_schoolLockouts[MAX_SPELL_SCHOOL]
private

Definition at line 229 of file SpellHistory.h.

◆ _spellCooldowns

CooldownStorageType SpellHistory::_spellCooldowns
private

Definition at line 226 of file SpellHistory.h.

◆ _spellCooldownsBeforeDuel

CooldownStorageType SpellHistory::_spellCooldownsBeforeDuel
private

Definition at line 227 of file SpellHistory.h.

◆ InfinityCooldownDelay

SpellHistory::Duration const SpellHistory::InfinityCooldownDelay = Seconds(MONTH)
static

Definition at line 116 of file SpellHistory.h.


The documentation for this class was generated from the following files: