mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-27 23:56:25 +00:00
fix(Core/Spells): several improvements to cooldowns (#7559)
- Reworked spell category cooldowns. - Implemented category cooldowns for pets. - Properly shows pet spell cooldowns in player's UI. - Corrected pet spell cooldowns with infinity duration. - Do not add/remove infinity spell cooldown on aura apply/remove if casted by item. - Closes #5263
This commit is contained in:
@@ -2547,9 +2547,12 @@ bool Creature::IsSpellProhibited(SpellSchoolMask idSchoolMask) const
|
||||
return false;
|
||||
}
|
||||
|
||||
void Creature::_AddCreatureSpellCooldown(uint32 spell_id, uint32 end_time)
|
||||
void Creature::_AddCreatureSpellCooldown(uint32 spell_id, uint16 categoryId, uint32 end_time)
|
||||
{
|
||||
m_CreatureSpellCooldowns[spell_id] = World::GetGameTimeMS() + end_time;
|
||||
CreatureSpellCooldown spellCooldown;
|
||||
spellCooldown.category = categoryId;
|
||||
spellCooldown.end = World::GetGameTimeMS() + end_time;
|
||||
m_CreatureSpellCooldowns[spell_id] = std::move(spellCooldown);
|
||||
}
|
||||
|
||||
void Creature::AddSpellCooldown(uint32 spell_id, uint32 /*itemid*/, uint32 end_time, bool /*needSendToClient*/, bool /*forceSendToSpectator*/)
|
||||
@@ -2561,33 +2564,31 @@ void Creature::AddSpellCooldown(uint32 spell_id, uint32 /*itemid*/, uint32 end_t
|
||||
// used in proc system, otherwise normal creature cooldown
|
||||
if (end_time)
|
||||
{
|
||||
_AddCreatureSpellCooldown(spellInfo->Id, end_time);
|
||||
_AddCreatureSpellCooldown(spellInfo->Id, 0, end_time);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 spellcooldown = spellInfo->RecoveryTime;
|
||||
uint32 categorycooldown = spellInfo->CategoryRecoveryTime;
|
||||
if(Player* modOwner = GetSpellModOwner())
|
||||
uint32 categoryId = spellInfo->GetCategory();
|
||||
uint32 categorycooldown = categoryId ? spellInfo->CategoryRecoveryTime : 0;
|
||||
if (Player* modOwner = GetSpellModOwner())
|
||||
{
|
||||
modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_COOLDOWN, spellcooldown);
|
||||
modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_COOLDOWN, categorycooldown);
|
||||
}
|
||||
|
||||
if (spellcooldown)
|
||||
_AddCreatureSpellCooldown(spellInfo->Id, spellcooldown);
|
||||
|
||||
if (categorycooldown)
|
||||
if (spellInfo->GetCategory())
|
||||
SpellCategoryStore::const_iterator i_scstore = sSpellsByCategoryStore.find(categoryId);
|
||||
if (categorycooldown && i_scstore != sSpellsByCategoryStore.end())
|
||||
{
|
||||
for (SpellCategorySet::const_iterator i_scset = i_scstore->second.begin(); i_scset != i_scstore->second.end(); ++i_scset)
|
||||
{
|
||||
SpellCategoryStore::const_iterator i_scstore = sSpellsByCategoryStore.find(spellInfo->GetCategory());
|
||||
if (i_scstore != sSpellsByCategoryStore.end())
|
||||
{
|
||||
uint32 cattime = categorycooldown;
|
||||
for (SpellCategorySet::const_iterator i_scset = i_scstore->second.begin(); i_scset != i_scstore->second.end(); ++i_scset)
|
||||
if (GetSpellCooldown(*i_scset) < cattime)
|
||||
_AddCreatureSpellCooldown(*i_scset, cattime);
|
||||
}
|
||||
_AddCreatureSpellCooldown(i_scset->second, categoryId, categorycooldown);
|
||||
}
|
||||
}
|
||||
else if (spellcooldown)
|
||||
{
|
||||
_AddCreatureSpellCooldown(spellInfo->Id, 0, spellcooldown);
|
||||
}
|
||||
}
|
||||
|
||||
uint32 Creature::GetSpellCooldown(uint32 spell_id) const
|
||||
@@ -2596,13 +2597,13 @@ uint32 Creature::GetSpellCooldown(uint32 spell_id) const
|
||||
if (itr == m_CreatureSpellCooldowns.end())
|
||||
return 0;
|
||||
|
||||
return itr->second > World::GetGameTimeMS() ? itr->second - World::GetGameTimeMS() : 0;
|
||||
return itr->second.end > World::GetGameTimeMS() ? itr->second.end - World::GetGameTimeMS() : 0;
|
||||
}
|
||||
|
||||
bool Creature::HasSpellCooldown(uint32 spell_id) const
|
||||
{
|
||||
CreatureSpellCooldowns::const_iterator itr = m_CreatureSpellCooldowns.find(spell_id);
|
||||
return (itr != m_CreatureSpellCooldowns.end() && itr->second > World::GetGameTimeMS());
|
||||
return (itr != m_CreatureSpellCooldowns.end() && itr->second.end > World::GetGameTimeMS());
|
||||
}
|
||||
|
||||
bool Creature::HasSpell(uint32 spellID) const
|
||||
|
||||
@@ -142,7 +142,7 @@ public:
|
||||
[[nodiscard]] SpellSchoolMask GetMeleeDamageSchoolMask() const override { return m_meleeDamageSchoolMask; }
|
||||
void SetMeleeDamageSchool(SpellSchools school) { m_meleeDamageSchoolMask = SpellSchoolMask(1 << school); }
|
||||
|
||||
void _AddCreatureSpellCooldown(uint32 spell_id, uint32 end_time);
|
||||
void _AddCreatureSpellCooldown(uint32 spell_id, uint16 categoryId, uint32 end_time);
|
||||
void AddSpellCooldown(uint32 spell_id, uint32 /*itemid*/, uint32 end_time, bool needSendToClient = false, bool forceSendToSpectator = false) override;
|
||||
[[nodiscard]] bool HasSpellCooldown(uint32 spell_id) const override;
|
||||
[[nodiscard]] uint32 GetSpellCooldown(uint32 spell_id) const;
|
||||
|
||||
@@ -417,6 +417,15 @@ struct TrainerSpellData
|
||||
[[nodiscard]] TrainerSpell const* Find(uint32 spell_id) const;
|
||||
};
|
||||
|
||||
typedef std::map<uint32, time_t> CreatureSpellCooldowns;
|
||||
struct CreatureSpellCooldown
|
||||
{
|
||||
CreatureSpellCooldown() : category(0), end(0) { }
|
||||
CreatureSpellCooldown(uint16 categoryId, uint32 endTime) : category(categoryId), end(endTime) { }
|
||||
|
||||
uint16 category;
|
||||
uint32 end;
|
||||
};
|
||||
|
||||
typedef std::map<uint32, CreatureSpellCooldown> CreatureSpellCooldowns;
|
||||
|
||||
#endif // AZEROTHCORE_CREATUREDATA_H
|
||||
|
||||
Reference in New Issue
Block a user