AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
SpellHistory Class Reference

#include "SpellHistory.h"

Classes

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

Public Types

typedef std::chrono::system_clock Clock
 
typedef std::unordered_map< uint32, CooldownEntry > CooldownStorageType
 
typedef std::unordered_map< uint64, CooldownEntry * > CategoryCooldownStorageType
 
typedef std::unordered_map< uint32, Clock::time_point > GlobalCooldownStorageType
 

Public Member Functions

 SpellHistory (Unit *owner)
 
template<class OwnerType >
void LoadFromDB (PreparedQueryResult cooldownsResult)
 
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, bool ignoreCategoryCooldown=false) const
 
template<class OwnerType >
void WritePacket (WorldPacket &packet) const
 
void StartCooldown (SpellInfo const *spellInfo, uint32 itemId, Spell *spell=nullptr, bool onHold=false)
 
void SendCooldownEvent (SpellInfo const *spellInfo, uint32 itemId=0, Spell *spell=nullptr, bool startCooldown=true)
 
template<class Type , class Period >
void AddCooldown (uint32 spellId, uint32 itemId, std::chrono::duration< Type, Period > cooldownDuration)
 
void AddCooldown (uint32 spellId, uint32 itemId, Clock::time_point cooldownEnd, uint32 categoryId, Clock::time_point categoryEnd, bool onHold=false)
 
void AnnounceToSpectators (uint32 spellId, uint32 durationMs)
 
void ModifyCooldown (uint32 spellId, int32 cooldownModMs)
 
void ResetCooldown (uint32 spellId, bool update=false)
 
void ResetCooldown (CooldownStorageType::iterator &itr, bool update=false)
 
template<typename Predicate >
void ResetCooldowns (Predicate predicate, bool update=false)
 
void ResetAllCooldowns ()
 
bool HasCooldown (SpellInfo const *spellInfo, uint32 itemId=0, bool ignoreCategoryCooldown=false) const
 
bool HasCooldown (uint32 spellId, uint32 itemId=0, bool ignoreCategoryCooldown=false) const
 
bool HasItemCooldown (uint32 spellId, uint32 itemId) const
 
uint32 GetRemainingCooldown (SpellInfo const *spellInfo, uint32 itemId=0) const
 
uint32 GetRemainingCooldown (uint32 spellId) const
 
void LockSpellSchool (SpellSchoolMask schoolMask, uint32 lockoutTime)
 
bool IsSchoolLocked (SpellSchoolMask schoolMask) const
 
void ResetSchoolLockouts ()
 
bool HasGlobalCooldown (SpellInfo const *spellInfo) const
 
uint32 GetRemainingGlobalCooldown (SpellInfo const *spellInfo) const
 
void AddGlobalCooldown (SpellInfo const *spellInfo, uint32 duration)
 
void CancelGlobalCooldown (SpellInfo const *spellInfo)
 
CooldownStorageType const & GetSpellCooldowns () const
 
CooldownStorageType::size_type GetCooldownsSizeForPacket () const
 
void SaveCooldownStateBeforeDuel ()
 
void RestoreCooldownStateAfterDuel ()
 
template<>
void WritePacket (WorldPacket &packet) const
 
template<>
void WritePacket (WorldPacket &packet) const
 
template<>
AC_GAME_API void WritePacket (WorldPacket &packet) const
 
template<>
AC_GAME_API void WritePacket (WorldPacket &packet) const
 

Static Public Member Functions

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

Static Public Attributes

static Clock::duration const InfinityCooldownDelay = std::chrono::duration_cast<SpellHistory::Clock::duration>(std::chrono::seconds(MONTH))
 

Private Member Functions

Player * GetPlayerOwner () const
 
void SendClearCooldowns (std::vector< int32 > const &cooldowns) const
 
void SendCreatureCooldowns (SpellInfo const *spellInfo, uint32 categoryId) const
 
CooldownEntry const * GetBlockingCategoryCooldown (SpellInfo const *spellInfo, uint32 itemId) const
 
void LinkCategoryCooldown (CooldownEntry &entry)
 
void UnlinkCategoryCooldown (CooldownEntry const &entry)
 
CooldownStorageType::iterator EraseCooldown (CooldownStorageType::iterator itr)
 

Static Private Member Functions

static uint64 CategoryKey (uint32 categoryId, uint32 spellId, uint32 itemId)
 

Private Attributes

Unit * _owner
 
CooldownStorageType _spellCooldowns
 
CooldownStorageType _spellCooldownsBeforeDuel
 
CategoryCooldownStorageType _categoryCooldowns
 
Clock::time_point _schoolLockouts [MAX_SPELL_SCHOOL]
 
GlobalCooldownStorageType _globalCooldowns
 

Detailed Description

Member Typedef Documentation

◆ CategoryCooldownStorageType

◆ Clock

typedef std::chrono::system_clock SpellHistory::Clock

◆ CooldownStorageType

◆ GlobalCooldownStorageType

typedef std::unordered_map<uint32 , Clock::time_point> SpellHistory::GlobalCooldownStorageType

Constructor & Destructor Documentation

◆ SpellHistory()

SpellHistory::SpellHistory ( Unit *  owner)
inlineexplicit
56: _owner(owner), _schoolLockouts() { }
Unit * _owner
Definition SpellHistory.h:153
Clock::time_point _schoolLockouts[MAX_SPELL_SCHOOL]
Definition SpellHistory.h:157

Member Function Documentation

◆ AddCooldown() [1/2]

void SpellHistory::AddCooldown ( uint32  spellId,
uint32  itemId,
Clock::time_point  cooldownEnd,
uint32  categoryId,
Clock::time_point  categoryEnd,
bool  onHold = false 
)
438{
439 CooldownEntry& cooldownEntry = _spellCooldowns[spellId];
440 UnlinkCategoryCooldown(cooldownEntry);
441
442 cooldownEntry.SpellId = spellId;
443 cooldownEntry.CooldownEnd = cooldownEnd;
444 cooldownEntry.ItemId = itemId;
445 cooldownEntry.CategoryId = categoryId;
446 cooldownEntry.CategoryEnd = categoryEnd;
447 cooldownEntry.OnHold = onHold;
448 cooldownEntry.SpectatorDuration = 0;
449
450 LinkCategoryCooldown(cooldownEntry);
451}
void UnlinkCategoryCooldown(CooldownEntry const &entry)
Definition SpellHistory.cpp:564
void LinkCategoryCooldown(CooldownEntry &entry)
Definition SpellHistory.cpp:558
CooldownStorageType _spellCooldowns
Definition SpellHistory.h:154

References _spellCooldowns, SpellHistory::CooldownEntry::CategoryEnd, SpellHistory::CooldownEntry::CategoryId, SpellHistory::CooldownEntry::CooldownEnd, SpellHistory::CooldownEntry::ItemId, LinkCategoryCooldown(), SpellHistory::CooldownEntry::OnHold, SpellHistory::CooldownEntry::SpectatorDuration, SpellHistory::CooldownEntry::SpellId, and UnlinkCategoryCooldown().

◆ AddCooldown() [2/2]

template<class Type , class Period >
void SpellHistory::AddCooldown ( uint32  spellId,
uint32  itemId,
std::chrono::duration< Type, Period >  cooldownDuration 
)
inline

◆ AddGlobalCooldown()

void SpellHistory::AddGlobalCooldown ( SpellInfo const *  spellInfo,
uint32  duration 
)
723{
724 _globalCooldowns[spellInfo->StartRecoveryCategory] = GameTime::GetSystemTime() + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(duration));
725}
GlobalCooldownStorageType _globalCooldowns
Definition SpellHistory.h:158

References _globalCooldowns, GameTime::GetSystemTime(), and SpellInfo::StartRecoveryCategory.

Referenced by Player::EquipItem(), and Spell::TriggerGlobalCooldown().

◆ AnnounceToSpectators()

void SpellHistory::AnnounceToSpectators ( uint32  spellId,
uint32  durationMs 
)
454{
455 Player* player = _owner->ToPlayer();
456 if (!player || durationMs < SPECTATOR_COOLDOWN_MIN * IN_MILLISECONDS || durationMs > SPECTATOR_COOLDOWN_MAX * IN_MILLISECONDS)
457 return;
458
459 auto itr = _spellCooldowns.find(spellId);
460 if (itr == _spellCooldowns.end() || !player->NeedSendSpectatorData() || (!itr->second.ItemId && !player->HasActiveSpell(spellId)))
461 return;
462
463 itr->second.SpectatorDuration = durationMs;
464 ArenaSpectator::SendCommand_Cooldown(player->FindMap(), player->GetGUID(), "ACD", spellId, durationMs / IN_MILLISECONDS, durationMs / IN_MILLISECONDS);
465}
#define SPECTATOR_COOLDOWN_MAX
Definition ArenaSpectator.h:37
constexpr auto IN_MILLISECONDS
Definition Common.h:53
Player * ToPlayer()
Definition Object.h:208
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:120
Definition Player.h:1077
bool NeedSendSpectatorData() const
Definition Player.cpp:15525
bool HasActiveSpell(uint32 spell) const
Definition Player.cpp:3931
Map * FindMap() const
Definition Object.h:638
void SendCommand_Cooldown(T *o, ObjectGuid targetGUID, char const *prefix, uint32 id, uint32 dur, uint32 maxdur)
Definition ArenaSpectator.h:89

References _owner, _spellCooldowns, WorldObject::FindMap(), Object::GetGUID(), Player::HasActiveSpell(), IN_MILLISECONDS, Player::NeedSendSpectatorData(), ArenaSpectator::SendCommand_Cooldown(), SPECTATOR_COOLDOWN_MAX, and Object::ToPlayer().

Referenced by Player::ApplyEquipCooldown(), and StartCooldown().

◆ CancelGlobalCooldown()

void SpellHistory::CancelGlobalCooldown ( SpellInfo const *  spellInfo)
728{
729 _globalCooldowns[spellInfo->StartRecoveryCategory] = Clock::time_point(Clock::duration(0));
730}

References _globalCooldowns, and SpellInfo::StartRecoveryCategory.

Referenced by Spell::CancelGlobalCooldown().

◆ CategoryKey()

uint64 SpellHistory::CategoryKey ( uint32  categoryId,
uint32  spellId,
uint32  itemId 
)
staticprivate
551{
552 // Only spells of the same source (item or spell) and spell family block each other
553 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
554 uint32 familyName = spellInfo ? spellInfo->SpellFamilyName : 0;
555 return (uint64(categoryId) << 32) | (uint64(itemId != 0) << 31) | familyName;
556}
std::uint32_t uint32
Definition Define.h:107
std::uint64_t uint64
Definition Define.h:106
#define sSpellMgr
Definition SpellMgr.h:851
Definition SpellInfo.h:340
uint32 SpellFamilyName
Definition SpellInfo.h:411

References SpellInfo::SpellFamilyName, and sSpellMgr.

Referenced by GetBlockingCategoryCooldown(), LinkCategoryCooldown(), and UnlinkCategoryCooldown().

◆ EraseCooldown()

CooldownStorageType::iterator SpellHistory::EraseCooldown ( CooldownStorageType::iterator  itr)
inlineprivate
148 {
149 UnlinkCategoryCooldown(itr->second);
150 return _spellCooldowns.erase(itr);
151 }

Referenced by ModifyCooldown(), ResetCooldown(), and Update().

◆ GetBlockingCategoryCooldown()

SpellHistory::CooldownEntry const * SpellHistory::GetBlockingCategoryCooldown ( SpellInfo const *  spellInfo,
uint32  itemId 
) const
private
540{
541 uint32 category = 0;
542 GetCooldownDurations(spellInfo, itemId, nullptr, &category, nullptr);
543 if (!category)
544 return nullptr;
545
546 auto categoryItr = _categoryCooldowns.find(CategoryKey(category, spellInfo->Id, itemId));
547 return categoryItr != _categoryCooldowns.end() ? categoryItr->second : nullptr;
548}
static uint64 CategoryKey(uint32 categoryId, uint32 spellId, uint32 itemId)
Definition SpellHistory.cpp:550
static void GetCooldownDurations(SpellInfo const *spellInfo, uint32 itemId, int32 *cooldown, uint32 *categoryId, int32 *categoryCooldown)
Definition SpellHistory.cpp:780
CategoryCooldownStorageType _categoryCooldowns
Definition SpellHistory.h:156

References _categoryCooldowns, CategoryKey(), GetCooldownDurations(), and SpellInfo::Id.

Referenced by GetRemainingCooldown(), HasCooldown(), and SendCooldownEvent().

◆ GetCooldownDurations()

void SpellHistory::GetCooldownDurations ( SpellInfo const *  spellInfo,
uint32  itemId,
int32 *  cooldown,
uint32 *  categoryId,
int32 *  categoryCooldown 
)
static
781{
782 ASSERT(cooldown || categoryId || categoryCooldown);
783 int32 tmpCooldown = -1;
784 uint32 tmpCategoryId = 0;
785 int32 tmpCategoryCooldown = -1;
786
787 // some special item spells without correct cooldown in SpellInfo
788 // cooldown information stored in item prototype
789 if (itemId)
790 {
791 if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemId))
792 {
793 for (uint8 idx = 0; idx < MAX_ITEM_SPELLS; ++idx)
794 {
795 if (uint32(proto->Spells[idx].SpellId) == spellInfo->Id)
796 {
797 tmpCooldown = proto->Spells[idx].SpellCooldown;
798 tmpCategoryId = proto->Spells[idx].SpellCategory;
799 tmpCategoryCooldown = proto->Spells[idx].SpellCategoryCooldown;
800 break;
801 }
802 }
803 }
804 }
805
806 // if no cooldown found above then base at DBC data
807 if (tmpCooldown < 0 && tmpCategoryCooldown < 0)
808 {
809 tmpCooldown = spellInfo->RecoveryTime;
810 tmpCategoryId = spellInfo->GetCategory();
811 tmpCategoryCooldown = spellInfo->CategoryRecoveryTime;
812 }
813
814 if (cooldown)
815 *cooldown = tmpCooldown;
816
817 if (categoryId)
818 *categoryId = tmpCategoryId;
819
820 if (categoryCooldown)
821 *categoryCooldown = tmpCategoryCooldown;
822}
std::int32_t int32
Definition Define.h:103
std::uint8_t uint8
Definition Define.h:109
#define ASSERT
Definition Errors.h:68
#define MAX_ITEM_SPELLS
Definition Item.h:215
#define sObjectMgr
Definition ObjectMgr.h:1734
Definition ItemTemplate.h:619

References ASSERT, SpellInfo::CategoryRecoveryTime, SpellInfo::GetCategory(), SpellInfo::Id, MAX_ITEM_SPELLS, SpellInfo::RecoveryTime, and sObjectMgr.

Referenced by GetBlockingCategoryCooldown(), misc_commandscript::HandleCooldownCommand(), Player::RemoveArenaSpellCooldowns(), and StartCooldown().

◆ GetCooldownsSizeForPacket()

CooldownStorageType::size_type SpellHistory::GetCooldownsSizeForPacket ( ) const
inline
135{ return _spellCooldowns.size(); }

Referenced by Player::VehicleSpellInitialize().

◆ GetPlayerOwner()

Player * SpellHistory::GetPlayerOwner ( ) const
private

◆ GetRemainingCooldown() [1/2]

uint32 SpellHistory::GetRemainingCooldown ( SpellInfo const *  spellInfo,
uint32  itemId = 0 
) const
592{
593 Clock::time_point end;
594 auto itr = _spellCooldowns.find(spellInfo->Id);
595 if (itr != _spellCooldowns.end())
596 end = itr->second.CooldownEnd;
597 else if (CooldownEntry const* categoryEntry = GetBlockingCategoryCooldown(spellInfo, itemId))
598 end = categoryEntry->CategoryEnd;
599 else
600 return 0;
601
602 Clock::time_point now = GameTime::GetSystemTime();
603 if (end < now)
604 return 0;
605
606 Clock::duration remaining = end - now;
607 return uint32(std::chrono::duration_cast<std::chrono::milliseconds>(remaining).count());
608}
CooldownEntry const * GetBlockingCategoryCooldown(SpellInfo const *spellInfo, uint32 itemId) const
Definition SpellHistory.cpp:539

References _spellCooldowns, GetBlockingCategoryCooldown(), GameTime::GetSystemTime(), and SpellInfo::Id.

Referenced by GetRemainingCooldown(), Aura::HandleAuraSpecificMods(), LockSpellSchool(), npc_brewfest_keg_reciver::MoveInLineOfSight(), SendCreatureCooldowns(), and boss_twin_valkyrAI::UpdateAI().

◆ GetRemainingCooldown() [2/2]

uint32 SpellHistory::GetRemainingCooldown ( uint32  spellId) const
611{
612 if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId))
613 return GetRemainingCooldown(spellInfo);
614
615 // Scripts also track cooldowns on ids missing from Spell.dbc
616 auto itr = _spellCooldowns.find(spellId);
617 if (itr == _spellCooldowns.end())
618 return 0;
619
620 Clock::time_point now = GameTime::GetSystemTime();
621 if (itr->second.CooldownEnd < now)
622 return 0;
623
624 return uint32(std::chrono::duration_cast<std::chrono::milliseconds>(itr->second.CooldownEnd - now).count());
625}
uint32 GetRemainingCooldown(SpellInfo const *spellInfo, uint32 itemId=0) const
Definition SpellHistory.cpp:591

References _spellCooldowns, GetRemainingCooldown(), GameTime::GetSystemTime(), and sSpellMgr.

◆ GetRemainingGlobalCooldown()

uint32 SpellHistory::GetRemainingGlobalCooldown ( SpellInfo const *  spellInfo) const
710{
711 auto itr = _globalCooldowns.find(spellInfo->StartRecoveryCategory);
712 if (itr == _globalCooldowns.end())
713 return 0;
714
715 Clock::time_point now = GameTime::GetSystemTime();
716 if (itr->second <= now)
717 return 0;
718
719 return uint32(std::chrono::duration_cast<std::chrono::milliseconds>(itr->second - now).count());
720}

References _globalCooldowns, GameTime::GetSystemTime(), and SpellInfo::StartRecoveryCategory.

◆ GetSpellCooldowns()

CooldownStorageType const & SpellHistory::GetSpellCooldowns ( ) const
inline

◆ HandleCooldowns() [1/2]

void SpellHistory::HandleCooldowns ( SpellInfo const *  spellInfo,
Item const *  item,
Spell *  spell = nullptr 
)
161{
162 HandleCooldowns(spellInfo, item ? item->GetEntry() : 0, spell);
163}
void HandleCooldowns(SpellInfo const *spellInfo, Item const *item, Spell *spell=nullptr)
Definition SpellHistory.cpp:160

References Object::GetEntry(), and HandleCooldowns().

Referenced by HandleCooldowns(), and Spell::SendSpellCooldown().

◆ HandleCooldowns() [2/2]

void SpellHistory::HandleCooldowns ( SpellInfo const *  spellInfo,
uint32  itemID,
Spell *  spell = nullptr 
)
166{
167 if (Player* player = _owner->ToPlayer())
168 {
169 // potions start cooldown until exiting combat
170 if (ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemID))
171 {
172 if (itemTemplate->IsPotion() || spellInfo->IsCooldownStartedOnEvent())
173 {
174 player->SetLastPotionId(itemID);
175 return;
176 }
177 }
178 }
179
180 if (spellInfo->IsCooldownStartedOnEvent() || spellInfo->IsPassive())
181 return;
182
183 // Triggered casts start no cooldown, unless an item was used (Reincarnation relies on this)
184 if (spell && ((spell->IsIgnoringCooldowns() && !itemID) || spell->HasTriggeredCastFlag(TRIGGERED_IGNORE_EFFECTS)))
185 return;
186
187 StartCooldown(spellInfo, itemID, spell);
188}
@ TRIGGERED_IGNORE_EFFECTS
Periodic aura tick wont be reset on override.
Definition SpellDefines.h:164
void StartCooldown(SpellInfo const *spellInfo, uint32 itemId, Spell *spell=nullptr, bool onHold=false)
Definition SpellHistory.cpp:288
bool HasTriggeredCastFlag(TriggerCastFlags flag) const
Definition Spell.h:569
bool IsIgnoringCooldowns() const
Definition Spell.cpp:8532

References _owner, Spell::HasTriggeredCastFlag(), SpellInfo::IsCooldownStartedOnEvent(), Spell::IsIgnoringCooldowns(), SpellInfo::IsPassive(), sObjectMgr, StartCooldown(), Object::ToPlayer(), and TRIGGERED_IGNORE_EFFECTS.

◆ HasCooldown() [1/2]

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

◆ HasCooldown() [2/2]

bool SpellHistory::HasCooldown ( uint32  spellId,
uint32  itemId = 0,
bool  ignoreCategoryCooldown = false 
) const
576{
577 if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId))
578 return HasCooldown(spellInfo, itemId, ignoreCategoryCooldown);
579
580 // Scripts also track cooldowns on ids missing from Spell.dbc
581 auto itr = _spellCooldowns.find(spellId);
582 return itr != _spellCooldowns.end() && itr->second.CooldownEnd > GameTime::GetSystemTime();
583}
bool HasCooldown(SpellInfo const *spellInfo, uint32 itemId=0, bool ignoreCategoryCooldown=false) const
Definition SpellHistory.cpp:524

References _spellCooldowns, GameTime::GetSystemTime(), HasCooldown(), and sSpellMgr.

◆ HasGlobalCooldown()

bool SpellHistory::HasGlobalCooldown ( SpellInfo const *  spellInfo) const
704{
705 auto itr = _globalCooldowns.find(spellInfo->StartRecoveryCategory);
706 return itr != _globalCooldowns.end() && itr->second > GameTime::GetSystemTime();
707}

References _globalCooldowns, GameTime::GetSystemTime(), and SpellInfo::StartRecoveryCategory.

Referenced by Spell::CheckPetCast(), Spell::HasGlobalCooldown(), and PetAI::UpdateAI().

◆ HasItemCooldown()

bool SpellHistory::HasItemCooldown ( uint32  spellId,
uint32  itemId 
) const
586{
587 auto itr = _spellCooldowns.find(spellId);
588 return itr != _spellCooldowns.end() && itr->second.ItemId == itemId && itr->second.CooldownEnd > GameTime::GetSystemTime();
589}

References _spellCooldowns, and GameTime::GetSystemTime().

Referenced by Spell::CheckCast().

◆ IsReady()

bool SpellHistory::IsReady ( SpellInfo const *  spellInfo,
uint32  itemId = 0,
bool  ignoreCategoryCooldown = false 
) const
191{
192 if (spellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE)
193 if (IsSchoolLocked(spellInfo->GetSchoolMask()))
194 return false;
195
196 if (HasCooldown(spellInfo->Id, itemId, ignoreCategoryCooldown))
197 return false;
198
199 return true;
200}
@ SPELL_PREVENTION_TYPE_SILENCE
Definition SharedDefines.h:1558
bool IsSchoolLocked(SpellSchoolMask schoolMask) const
Definition SpellHistory.cpp:686

References SpellInfo::GetSchoolMask(), HasCooldown(), SpellInfo::Id, IsSchoolLocked(), SpellInfo::PreventionType, and SPELL_PREVENTION_TYPE_SILENCE.

Referenced by Spell::CheckCast().

◆ IsSchoolLocked()

bool SpellHistory::IsSchoolLocked ( SpellSchoolMask  schoolMask) const
687{
688 Clock::time_point now = GameTime::GetSystemTime();
689 for (uint32 i = 0; i < MAX_SPELL_SCHOOL; ++i)
690 if (SpellSchoolMask(1 << i) & schoolMask)
691 if (_schoolLockouts[i] > now)
692 return true;
693
694 return false;
695}
constexpr auto MAX_SPELL_SCHOOL
Definition SharedDefines.h:280
SpellSchoolMask
Definition SharedDefines.h:283

References _schoolLockouts, GameTime::GetSystemTime(), and MAX_SPELL_SCHOOL.

Referenced by Spell::CheckCast(), SmartAI::IsMainSpellPrevented(), IsReady(), and npc_pet_dk_ebon_gargoyle::UpdateAI().

◆ LinkCategoryCooldown()

void SpellHistory::LinkCategoryCooldown ( CooldownEntry &  entry)
private

◆ LoadFromDB()

template<class OwnerType >
template void SpellHistory::LoadFromDB< Pet > ( PreparedQueryResult  cooldownsResult)
98{
99 typedef PersistenceHelper<OwnerType> StatementInfo;
100
101 if (cooldownsResult)
102 {
103 do
104 {
105 uint32 spellId;
106 CooldownEntry cooldown;
107 if (StatementInfo::ReadCooldown(cooldownsResult->Fetch(), &spellId, &cooldown))
108 {
109 CooldownEntry& entry = _spellCooldowns[spellId];
110 entry = cooldown;
112 }
113 } while (cooldownsResult->NextRow());
114 }
115}

References _spellCooldowns, and LinkCategoryCooldown().

Referenced by Player::LoadFromDB().

◆ LockSpellSchool()

void SpellHistory::LockSpellSchool ( SpellSchoolMask  schoolMask,
uint32  lockoutTime 
)
628{
629 Clock::time_point now = GameTime::GetSystemTime();
630 Clock::time_point lockoutEnd = now + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(lockoutTime));
631 for (uint32 i = 0; i < MAX_SPELL_SCHOOL; ++i)
632 if (SpellSchoolMask(1 << i) & schoolMask)
633 _schoolLockouts[i] = lockoutEnd;
634
635 std::set<uint32> knownSpells;
636 if (Player* plrOwner = _owner->ToPlayer())
637 {
638 for (auto const& p : plrOwner->GetSpellMap())
639 if (p.second->State != PLAYERSPELL_REMOVED)
640 knownSpells.insert(p.first);
641 }
642 else if (Pet* petOwner = _owner->ToPet())
643 {
644 for (auto const& p : petOwner->m_spells)
645 if (p.second.state != PETSPELL_REMOVED)
646 knownSpells.insert(p.first);
647 }
648 else if (Creature* creatureOwner = _owner->ToCreature())
649 {
650 for (uint8 i = 0; i < MAX_CREATURE_SPELLS; ++i)
651 if (creatureOwner->m_spells[i])
652 knownSpells.insert(creatureOwner->m_spells[i]);
653 }
654
655 PacketCooldowns cooldowns;
656 for (uint32 spellId : knownSpells)
657 {
658 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
659 if (!spellInfo)
660 continue;
661
662 if (spellInfo->IsCooldownStartedOnEvent())
663 continue;
664
666 continue;
667
668 if ((schoolMask & spellInfo->GetSchoolMask()) && GetRemainingCooldown(spellInfo) < lockoutTime)
669 {
670 cooldowns[spellId] = lockoutTime;
671 AddCooldown(spellId, 0, lockoutEnd, 0, now);
672 }
673 }
674
675 if (Player* player = GetPlayerOwner())
676 {
677 if (!cooldowns.empty())
678 {
679 WorldPacket data;
681 player->SendDirectMessage(&data);
682 }
683 }
684}
@ PETSPELL_REMOVED
Definition PetDefines.h:63
@ PLAYERSPELL_REMOVED
Definition Player.h:123
@ SPELL_COOLDOWN_FLAG_NONE
Definition Unit.h:637
static constexpr uint32 MAX_CREATURE_SPELLS
Definition Unit.h:47
std::unordered_map< uint32, uint32 > PacketCooldowns
Definition Unit.h:642
Definition Creature.h:47
Creature * ToCreature()
Definition Object.h:212
Definition Pet.h:52
Player * GetPlayerOwner() const
Definition SpellHistory.cpp:732
uint32 PreventionType
Definition SpellInfo.h:414
bool IsCooldownStartedOnEvent() const
Definition SpellInfo.cpp:1257
SpellSchoolMask GetSchoolMask() const
Definition SpellInfo.cpp:1935
Pet * ToPet()
Definition Unit.h:734
void BuildCooldownPacket(WorldPacket &data, uint8 flags, uint32 spellId, uint32 cooldown)
Definition Unit.cpp:16806
Definition WorldPacket.h:26

References _owner, _schoolLockouts, AddCooldown(), Unit::BuildCooldownPacket(), GetPlayerOwner(), GetRemainingCooldown(), SpellInfo::GetSchoolMask(), GameTime::GetSystemTime(), SpellInfo::IsCooldownStartedOnEvent(), MAX_CREATURE_SPELLS, MAX_SPELL_SCHOOL, PETSPELL_REMOVED, PLAYERSPELL_REMOVED, SpellInfo::PreventionType, SPELL_COOLDOWN_FLAG_NONE, SPELL_PREVENTION_TYPE_SILENCE, sSpellMgr, Object::ToCreature(), Unit::ToPet(), and Object::ToPlayer().

Referenced by Spell::EffectInterruptCast().

◆ ModifyCooldown()

void SpellHistory::ModifyCooldown ( uint32  spellId,
int32  cooldownModMs 
)
468{
469 auto itr = _spellCooldowns.find(spellId);
470 if (!cooldownModMs || itr == _spellCooldowns.end())
471 return;
472
473 Clock::time_point now = GameTime::GetSystemTime();
474 Clock::duration offset = std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(cooldownModMs));
475 if (itr->second.CooldownEnd + offset > now)
476 itr->second.CooldownEnd += offset;
477 else
478 EraseCooldown(itr);
479
480 if (Player* playerOwner = GetPlayerOwner())
481 {
482 WorldPacket data(SMSG_MODIFY_COOLDOWN, 4 + 8 + 4);
483 data << uint32(spellId);
484 data << _owner->GetGUID();
485 data << int32(cooldownModMs);
486 playerOwner->SendDirectMessage(&data);
487 }
488}
CooldownStorageType::iterator EraseCooldown(CooldownStorageType::iterator itr)
Definition SpellHistory.h:147
@ SMSG_MODIFY_COOLDOWN
Definition Opcodes.h:1199

References _owner, _spellCooldowns, EraseCooldown(), Object::GetGUID(), GetPlayerOwner(), GameTime::GetSystemTime(), and SMSG_MODIFY_COOLDOWN.

◆ ResetAllCooldowns()

void SpellHistory::ResetAllCooldowns ( )
509{
510 if (GetPlayerOwner())
511 {
512 std::vector<int32> cooldowns;
513 cooldowns.reserve(_spellCooldowns.size());
514 for (auto const& p : _spellCooldowns)
515 cooldowns.push_back(p.first);
516
517 SendClearCooldowns(cooldowns);
518 }
519
520 _categoryCooldowns.clear();
521 _spellCooldowns.clear();
522}
void SendClearCooldowns(std::vector< int32 > const &cooldowns) const
Definition SpellHistory.cpp:737

References _categoryCooldowns, _spellCooldowns, GetPlayerOwner(), and SendClearCooldowns().

Referenced by Spell::EffectSummonPet(), and misc_commandscript::HandleCooldownCommand().

◆ ResetCooldown() [1/2]

void SpellHistory::ResetCooldown ( CooldownStorageType::iterator &  itr,
bool  update = false 
)
500{
501 if (update)
502 if (Player* playerOwner = GetPlayerOwner())
503 playerOwner->SendClearCooldown(itr->first, _owner);
504
505 itr = EraseCooldown(itr);
506}

References _owner, EraseCooldown(), and GetPlayerOwner().

◆ ResetCooldown() [2/2]

◆ ResetCooldowns()

template<typename Predicate >
void SpellHistory::ResetCooldowns ( Predicate  predicate,
bool  update = false 
)
inline
95 {
96 std::vector<int32> resetCooldowns;
97 resetCooldowns.reserve(_spellCooldowns.size());
98 for (auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();)
99 {
100 if (predicate(itr))
101 {
102 resetCooldowns.push_back(itr->first);
103 ResetCooldown(itr, false);
104 }
105 else
106 ++itr;
107 }
108
109 if (update && !resetCooldowns.empty())
110 SendClearCooldowns(resetCooldowns);
111 }

Referenced by misc_commandscript::HandleCooldownCommand(), spell_hun_readiness::HandleDummy(), spell_item_refocus::HandleDummy(), spell_mage_cold_snap::HandleDummy(), spell_rog_preparation::HandleDummy(), spell_warr_sword_and_board::HandleProc(), and Player::RemoveArenaSpellCooldowns().

◆ ResetSchoolLockouts()

void SpellHistory::ResetSchoolLockouts ( )
698{
699 for (Clock::time_point& lockoutEnd : _schoolLockouts)
700 lockoutEnd = Clock::time_point();
701}
std::chrono::system_clock Clock
Definition SpellHistory.h:38

References _schoolLockouts.

Referenced by boss_shade_of_aran::JustEngagedWith().

◆ RestoreCooldownStateAfterDuel()

void SpellHistory::RestoreCooldownStateAfterDuel ( )
830{
831 // category cooldows are not preserved.
832 if (Player* player = _owner->ToPlayer())
833 {
834 // add all profession CDs created while in duel (if any)
835 for (auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end(); ++itr)
836 {
837 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(itr->first);
838 if (!spellInfo)
839 continue;
840
841 if (spellInfo->RecoveryTime > 10 * MINUTE * IN_MILLISECONDS ||
842 spellInfo->CategoryRecoveryTime > 10 * MINUTE * IN_MILLISECONDS)
843 _spellCooldownsBeforeDuel[itr->first] = _spellCooldowns[itr->first];
844 }
845
846 // check for spell with onHold active before and during the duel
847 for (auto itr = _spellCooldownsBeforeDuel.begin(); itr != _spellCooldownsBeforeDuel.end(); ++itr)
848 {
849 if (itr->second.OnHold)
850 continue;
851
852 CooldownEntry& entry = _spellCooldowns[itr->first];
853 if (entry.OnHold)
854 continue;
855
857 entry = itr->second;
859 }
860
861 // update the client: restore old cooldowns
862 PacketCooldowns cooldowns;
863 Clock::time_point now = GameTime::GetSystemTime();
864 for (auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end(); ++itr)
865 {
866 uint32 cooldownDuration = itr->second.CooldownEnd > now ? uint32(std::chrono::duration_cast<std::chrono::milliseconds>(itr->second.CooldownEnd - now).count()) : 0;
867
868 // cooldownDuration must be between 0 and 10 minutes in order to avoid any visual bugs
869 if (!cooldownDuration || cooldownDuration > 10 * MINUTE * IN_MILLISECONDS || itr->second.OnHold)
870 continue;
871
872 cooldowns[itr->first] = cooldownDuration;
873 }
874
875 WorldPacket data;
877 player->SendDirectMessage(&data);
878 }
879}
constexpr auto MINUTE
Definition Common.h:47
@ SPELL_COOLDOWN_FLAG_INCLUDE_EVENT_COOLDOWNS
Starts GCD for spells that should start their cooldown on events, requires SPELL_COOLDOWN_FLAG_INCLUD...
Definition Unit.h:639
CooldownStorageType _spellCooldownsBeforeDuel
Definition SpellHistory.h:155
uint32 RecoveryTime
Definition SpellInfo.h:372
uint32 CategoryRecoveryTime
Definition SpellInfo.h:373

References _owner, _spellCooldowns, _spellCooldownsBeforeDuel, Unit::BuildCooldownPacket(), SpellInfo::CategoryRecoveryTime, GameTime::GetSystemTime(), IN_MILLISECONDS, LinkCategoryCooldown(), MINUTE, SpellHistory::CooldownEntry::OnHold, SpellInfo::RecoveryTime, SPELL_COOLDOWN_FLAG_INCLUDE_EVENT_COOLDOWNS, sSpellMgr, Object::ToPlayer(), and UnlinkCategoryCooldown().

◆ SaveCooldownStateBeforeDuel()

void SpellHistory::SaveCooldownStateBeforeDuel ( )

◆ SaveToDB()

template<class OwnerType >
template void SpellHistory::SaveToDB< Pet > ( CharacterDatabaseTransaction  trans)
119{
120 typedef PersistenceHelper<OwnerType> StatementInfo;
121
122 uint8 index = 0;
123 CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(StatementInfo::CooldownsDeleteStatement);
124 StatementInfo::SetIdentifier(stmt, index++, _owner);
125 trans->Append(stmt);
126
127 for (auto const& p : _spellCooldowns)
128 {
129 if (!p.second.OnHold)
130 {
131 index = 0;
132 stmt = CharacterDatabase.GetPreparedStatement(StatementInfo::CooldownsInsertStatement);
133 StatementInfo::SetIdentifier(stmt, index++, _owner);
134 StatementInfo::WriteCooldown(stmt, index, p);
135 trans->Append(stmt);
136 }
137 }
138}
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition DatabaseEnv.cpp:21
Definition PreparedStatement.h:157

References _owner, _spellCooldowns, and CharacterDatabase.

Referenced by Pet::SavePetToDB(), and Player::SaveToDB().

◆ SendClearCooldowns()

void SpellHistory::SendClearCooldowns ( std::vector< int32 > const &  cooldowns) const
private
738{
739 if (Player* playerOwner = GetPlayerOwner())
740 for (int32 spell : cooldowns)
741 playerOwner->SendClearCooldown(spell, _owner);
742}

References _owner, GetPlayerOwner(), and Player::SendClearCooldown().

Referenced by ResetAllCooldowns().

◆ SendCooldownEvent()

void SpellHistory::SendCooldownEvent ( SpellInfo const *  spellInfo,
uint32  itemId = 0,
Spell *  spell = nullptr,
bool  startCooldown = true 
)
409{
410 // Send activate cooldown timer (possible 0) at client side
411 if (Player* player = GetPlayerOwner())
412 {
413 CooldownEntry const* categoryEntry = GetBlockingCategoryCooldown(spellInfo, itemId);
414 if (categoryEntry && categoryEntry->SpellId != spellInfo->Id)
415 {
416 uint32 const categorySpellId = categoryEntry->SpellId;
417 WorldPacket data(SMSG_COOLDOWN_EVENT, 4 + 8);
418 data << uint32(categorySpellId);
419 data << _owner->GetGUID();
420 player->SendDirectMessage(&data);
421
422 if (startCooldown)
423 StartCooldown(sSpellMgr->AssertSpellInfo(categorySpellId), itemId, spell);
424 }
425
426 WorldPacket data(SMSG_COOLDOWN_EVENT, 4 + 8);
427 data << uint32(spellInfo->Id);
428 data << _owner->GetGUID();
429 player->SendDirectMessage(&data);
430 }
431
432 // start cooldowns at server side, if any
433 if (startCooldown)
434 StartCooldown(spellInfo, itemId, spell);
435}
@ SMSG_COOLDOWN_EVENT
Definition Opcodes.h:339

References _owner, GetBlockingCategoryCooldown(), Object::GetGUID(), GetPlayerOwner(), SpellInfo::Id, SMSG_COOLDOWN_EVENT, SpellHistory::CooldownEntry::SpellId, sSpellMgr, and StartCooldown().

Referenced by Aura::_UnapplyForTarget(), Spell::finish(), Unit::RemoveGameObject(), Unit::SetMinion(), and Player::UpdatePotionCooldown().

◆ SendCreatureCooldowns()

void SpellHistory::SendCreatureCooldowns ( SpellInfo const *  spellInfo,
uint32  categoryId 
) const
private
745{
746 // The controlling player only learns creature cooldowns from us, category spells included
747 Player* player = GetPlayerOwner();
748 if (!player)
749 return;
750
751 PacketCooldowns cooldowns;
752 if (categoryId)
753 {
754 SpellCategoryStore::const_iterator categoryItr = sSpellsByCategoryStore.find(categoryId);
755 if (categoryItr != sSpellsByCategoryStore.end())
756 {
757 for (auto const& [itemBased, categorySpellId] : categoryItr->second)
758 {
759 if (!_owner->HasSpell(categorySpellId))
760 continue;
761
762 if (SpellInfo const* categorySpellInfo = sSpellMgr->GetSpellInfo(categorySpellId))
763 if (uint32 remaining = GetRemainingCooldown(categorySpellInfo))
764 cooldowns[categorySpellId] = remaining;
765 }
766 }
767 }
768
769 if (uint32 remaining = GetRemainingCooldown(spellInfo))
770 cooldowns[spellInfo->Id] = remaining;
771
772 if (cooldowns.empty())
773 return;
774
775 WorldPacket data;
777 player->SendDirectMessage(&data);
778}
SpellCategoryStore sSpellsByCategoryStore
Definition DBCStores.cpp:156
void SendDirectMessage(WorldPacket const *data) const
Definition Player.cpp:5756
virtual bool HasSpell(uint32) const
Definition Unit.h:1592

References _owner, Unit::BuildCooldownPacket(), GetPlayerOwner(), GetRemainingCooldown(), Unit::HasSpell(), SpellInfo::Id, Player::SendDirectMessage(), SPELL_COOLDOWN_FLAG_NONE, sSpellMgr, and sSpellsByCategoryStore.

Referenced by StartCooldown().

◆ StartCooldown()

void SpellHistory::StartCooldown ( SpellInfo const *  spellInfo,
uint32  itemId,
Spell *  spell = nullptr,
bool  onHold = false 
)
289{
290 // init cooldown values
291 uint32 categoryId = 0;
292 int32 cooldown = -1;
293 int32 categoryCooldown = -1;
294
295 GetCooldownDurations(spellInfo, itemId, &cooldown, &categoryId, &categoryCooldown);
296
297 Clock::time_point curTime = GameTime::GetSystemTime();
298 Clock::time_point catrecTime;
299 Clock::time_point recTime;
300 bool needsCooldownPacket = false;
301
302 // overwrite time for selected category
303 if (onHold)
304 {
305 // use +MONTH as infinite cooldown marker
306 catrecTime = categoryCooldown > 0 ? (curTime + InfinityCooldownDelay) : curTime;
307 recTime = cooldown > 0 ? (curTime + InfinityCooldownDelay) : catrecTime;
308 }
309 else
310 {
311 // shoot spells used equipped item cooldown values already assigned in GetAttackTime(RANGED_ATTACK)
312 // prevent 0 cooldowns set by another way
313 if (cooldown <= 0 && categoryCooldown <= 0 && (categoryId == 76 || (spellInfo->IsAutoRepeatRangedSpell() && spellInfo->Id != 75)))
315
316 // Now we have cooldown data (if found any), time to apply mods
317 if (Player* modOwner = _owner->GetSpellModOwner())
318 {
319 if (cooldown > 0)
320 modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_COOLDOWN, cooldown, spell);
321
322 if (categoryCooldown > 0 && !spellInfo->HasAttribute(SPELL_ATTR6_NO_CATEGORY_COOLDOWN_MODS))
323 modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_COOLDOWN, categoryCooldown, spell);
324 }
325
327 {
328 // Apply SPELL_AURA_MOD_COOLDOWN only to own spells
329 Player* playerOwner = GetPlayerOwner();
330 if (!playerOwner || playerOwner->HasSpell(spellInfo->Id))
331 {
332 needsCooldownPacket = true;
333 cooldown += cooldownMod * IN_MILLISECONDS; // SPELL_AURA_MOD_COOLDOWN does not affect category cooldows, verified with shaman shocks
334 }
335 }
336
337 // replace negative cooldowns by 0
338 if (cooldown < 0)
339 cooldown = 0;
340
341 if (categoryCooldown < 0)
342 categoryCooldown = 0;
343
344 // no cooldown after applying spell mods
345 if (cooldown == 0 && categoryCooldown == 0)
346 return;
347
348 catrecTime = categoryCooldown ? curTime + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(categoryCooldown)) : curTime;
349 recTime = cooldown ? curTime + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(cooldown)) : catrecTime;
350 }
351
352 // self spell cooldown
353 if (recTime != curTime)
354 {
355 AddCooldown(spellInfo->Id, itemId, recTime, categoryId, catrecTime, onHold);
356
357 if (needsCooldownPacket)
358 {
359 if (Player* playerOwner = GetPlayerOwner())
360 {
361 WorldPacket data;
362 _owner->BuildCooldownPacket(data, SPELL_COOLDOWN_FLAG_NONE, spellInfo->Id, uint32(cooldown));
363 playerOwner->SendDirectMessage(&data);
364 }
365 }
366
367 if (!onHold)
368 {
369 AnnounceToSpectators(spellInfo->Id, uint32(std::chrono::duration_cast<std::chrono::milliseconds>(recTime - curTime).count()));
370
371 // The client applies DBC category cooldowns itself; spells with modded category cooldowns need them sent
372 if (categoryCooldown && spellInfo->HasAttribute(SPELL_ATTR0_CU_FORCE_SEND_CATEGORY_COOLDOWNS))
373 {
374 if (Player* playerOwner = GetPlayerOwner())
375 {
376 PacketCooldowns categoryCooldowns;
377 SpellCategoryStore::const_iterator categoryItr = sSpellsByCategoryStore.find(categoryId);
378 if (categoryItr != sSpellsByCategoryStore.end())
379 {
380 for (auto const& [itemBased, categorySpellId] : categoryItr->second)
381 {
382 if (categorySpellId == spellInfo->Id || (itemId != 0) != itemBased)
383 continue;
384
385 SpellInfo const* categorySpellInfo = sSpellMgr->GetSpellInfo(categorySpellId);
386 if (!categorySpellInfo || categorySpellInfo->SpellFamilyName != spellInfo->SpellFamilyName)
387 continue;
388
389 categoryCooldowns[categorySpellId] = uint32(categoryCooldown);
390 }
391 }
392
393 if (!categoryCooldowns.empty())
394 {
395 WorldPacket data;
396 _owner->BuildCooldownPacket(data, SPELL_COOLDOWN_FLAG_NONE, categoryCooldowns);
397 playerOwner->SendDirectMessage(&data);
398 }
399 }
400 }
401 }
402
403 if (!onHold && !_owner->IsPlayer())
404 SendCreatureCooldowns(spellInfo, categoryId);
405 }
406}
@ SPELL_ATTR6_NO_CATEGORY_COOLDOWN_MODS
Definition SharedDefines.h:623
@ SPELL_AURA_MOD_COOLDOWN
Definition SpellAuraDefines.h:259
@ SPELLMOD_COOLDOWN
Definition SpellDefines.h:95
@ SPELL_ATTR0_CU_FORCE_SEND_CATEGORY_COOLDOWNS
Definition SpellInfo.h:205
@ RANGED_ATTACK
Definition Unit.h:224
bool IsPlayer() const
Definition Object.h:207
bool HasSpell(uint32 spell) const override
Definition Player.cpp:3919
static Clock::duration const InfinityCooldownDelay
Definition SpellHistory.h:75
void SendCreatureCooldowns(SpellInfo const *spellInfo, uint32 categoryId) const
Definition SpellHistory.cpp:744
void AnnounceToSpectators(uint32 spellId, uint32 durationMs)
Definition SpellHistory.cpp:453
uint32 GetAttackTime(WeaponAttackType att) const
Definition Unit.h:922
Player * GetSpellModOwner() const override
Definition Unit.cpp:12672
int32 GetTotalAuraModifier(AuraType auratype) const
Definition Unit.cpp:6116

References _owner, AddCooldown(), AnnounceToSpectators(), Unit::BuildCooldownPacket(), Unit::GetAttackTime(), GetCooldownDurations(), GetPlayerOwner(), Unit::GetSpellModOwner(), GameTime::GetSystemTime(), Unit::GetTotalAuraModifier(), SpellInfo::HasAttribute(), Player::HasSpell(), SpellInfo::Id, IN_MILLISECONDS, InfinityCooldownDelay, SpellInfo::IsAutoRepeatRangedSpell(), Object::IsPlayer(), RANGED_ATTACK, SendCreatureCooldowns(), SPELL_ATTR0_CU_FORCE_SEND_CATEGORY_COOLDOWNS, SPELL_ATTR6_NO_CATEGORY_COOLDOWN_MODS, SPELL_AURA_MOD_COOLDOWN, SPELL_COOLDOWN_FLAG_NONE, SpellInfo::SpellFamilyName, SPELLMOD_COOLDOWN, sSpellMgr, and sSpellsByCategoryStore.

Referenced by Aura::_ApplyForTarget(), spell_yogg_saron_protective_gaze_aura::Absorb(), Unit::AddGameObject(), HandleCooldowns(), spell_valkyr_special_2_dummy_cooldown::HandleDummy(), spell_pvp_trinket_wotf_shared_cd::HandleScript(), boss_faction_championsAI::IsCCed(), SendCooldownEvent(), and Unit::SetMinion().

◆ UnlinkCategoryCooldown()

void SpellHistory::UnlinkCategoryCooldown ( CooldownEntry const &  entry)
private
565{
566 if (!entry.CategoryId)
567 return;
568
569 // Another spell may hold the category by now
570 auto categoryItr = _categoryCooldowns.find(CategoryKey(entry.CategoryId, entry.SpellId, entry.ItemId));
571 if (categoryItr != _categoryCooldowns.end() && categoryItr->second == &entry)
572 _categoryCooldowns.erase(categoryItr);
573}

References _categoryCooldowns, SpellHistory::CooldownEntry::CategoryId, CategoryKey(), SpellHistory::CooldownEntry::ItemId, and SpellHistory::CooldownEntry::SpellId.

Referenced by AddCooldown(), and RestoreCooldownStateAfterDuel().

◆ Update()

void SpellHistory::Update ( )
141{
142 Clock::time_point now = GameTime::GetSystemTime();
143 for (auto itr = _categoryCooldowns.begin(); itr != _categoryCooldowns.end();)
144 {
145 if (itr->second->CategoryEnd < now)
146 itr = _categoryCooldowns.erase(itr);
147 else
148 ++itr;
149 }
150
151 for (auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();)
152 {
153 if (itr->second.CooldownEnd < now)
154 itr = EraseCooldown(itr);
155 else
156 ++itr;
157 }
158}

References _categoryCooldowns, _spellCooldowns, EraseCooldown(), and GameTime::GetSystemTime().

Referenced by Unit::Update().

◆ WritePacket() [1/5]

template<>
void SpellHistory::WritePacket ( WorldPacket &  packet) const
204{
205 Clock::time_point now = GameTime::GetSystemTime();
206
207 uint8 cooldownsCount = uint8(_spellCooldowns.size());
208 packet << uint8(cooldownsCount);
209
210 for (auto const& spellCooldown : _spellCooldowns)
211 {
212 packet << uint32(spellCooldown.first); // spell ID
213 packet << uint16(spellCooldown.second.CategoryId); // spell category
214
215 // send infinity cooldown in special format
216 if (spellCooldown.second.OnHold)
217 {
218 packet << uint32(1); // cooldown
219 packet << uint32(0x80000000); // category cooldown
220 continue;
221 }
222
223 std::chrono::milliseconds cooldownDuration = std::chrono::duration_cast<std::chrono::milliseconds>(spellCooldown.second.CooldownEnd - now);
224 if (cooldownDuration.count() <= 0)
225 {
226 packet << uint32(0);
227 packet << uint32(0);
228 continue;
229 }
230
231 // The own recovery outlasting the category one is sent too, as in WritePacket<Player>
232 std::chrono::milliseconds categoryDuration = std::chrono::duration_cast<std::chrono::milliseconds>(spellCooldown.second.CategoryEnd - now);
233 packet << uint32(cooldownDuration > categoryDuration ? cooldownDuration.count() : 0);
234 packet << uint32(categoryDuration.count() > 0 ? categoryDuration.count() : 0);
235 }
236}
std::uint16_t uint16
Definition Define.h:108

References _spellCooldowns, and GameTime::GetSystemTime().

◆ WritePacket() [2/5]

template<>
void SpellHistory::WritePacket ( WorldPacket &  packet) const
240{
241 Clock::time_point now = GameTime::GetSystemTime();
242
243 std::size_t countPos = packet.wpos();
244 uint16 cooldownsCount = 0;
245 packet << uint16(cooldownsCount);
246
247 for (auto const& spellCooldown : _spellCooldowns)
248 {
249 uint32 recoveryTime = 0;
250 uint32 categoryRecoveryTime = 0;
251
252 if (!spellCooldown.second.OnHold)
253 {
254 std::chrono::milliseconds cooldownDuration = std::chrono::duration_cast<std::chrono::milliseconds>(spellCooldown.second.CooldownEnd - now);
255 if (cooldownDuration.count() <= 0)
256 continue;
257
258 std::chrono::milliseconds categoryDuration = std::chrono::duration_cast<std::chrono::milliseconds>(spellCooldown.second.CategoryEnd - now);
259 if (categoryDuration.count() >= 0)
260 categoryRecoveryTime = uint32(categoryDuration.count());
261
262 if (cooldownDuration > categoryDuration)
263 recoveryTime = uint32(cooldownDuration.count());
264 }
265
266 packet << uint32(spellCooldown.first);
267 packet << uint16(spellCooldown.second.ItemId); // cast item id
268 packet << uint16(spellCooldown.second.CategoryId); // spell category
269
270 // send infinity cooldown in special format
271 if (spellCooldown.second.OnHold)
272 {
273 packet << uint32(1); // cooldown
274 packet << uint32(0x80000000); // category cooldown
275 }
276 else
277 {
278 packet << uint32(recoveryTime);
279 packet << uint32(categoryRecoveryTime);
280 }
281
282 ++cooldownsCount;
283 }
284
285 packet.put<uint16>(countPos, cooldownsCount);
286}
std::size_t wpos() const
Definition ByteBuffer.h:330
void put(std::size_t pos, T value)
Definition ByteBuffer.h:137

References _spellCooldowns, GameTime::GetSystemTime(), ByteBuffer::put(), and ByteBuffer::wpos().

◆ WritePacket() [3/5]

template<class OwnerType >
void SpellHistory::WritePacket ( WorldPacket &  packet) const

◆ WritePacket() [4/5]

template<>
AC_GAME_API void SpellHistory::WritePacket ( WorldPacket &  packet) const

◆ WritePacket() [5/5]

template<>
AC_GAME_API void SpellHistory::WritePacket ( WorldPacket &  packet) const

Member Data Documentation

◆ _categoryCooldowns

◆ _globalCooldowns

◆ _owner

◆ _schoolLockouts

Clock::time_point SpellHistory::_schoolLockouts[MAX_SPELL_SCHOOL]
private

◆ _spellCooldowns

◆ _spellCooldownsBeforeDuel

CooldownStorageType SpellHistory::_spellCooldownsBeforeDuel
private

◆ InfinityCooldownDelay

SpellHistory::Clock::duration const SpellHistory::InfinityCooldownDelay = std::chrono::duration_cast<SpellHistory::Clock::duration>(std::chrono::seconds(MONTH))
static

Referenced by StartCooldown().


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