fix(Core/Cooldown): Implement spell cooldown overrides to address cha… (#15143)

This commit is contained in:
Skjalf
2023-02-22 23:00:18 -03:00
committed by GitHub
parent 9b858e4653
commit fff0e17133
6 changed files with 126 additions and 2 deletions

View File

@@ -0,0 +1,10 @@
--
DROP TABLE IF EXISTS `spell_cooldown_overrides`;
CREATE TABLE `spell_cooldown_overrides` (
`Id` INT UNSIGNED NOT NULL,
`RecoveryTime` INT UNSIGNED NOT NULL DEFAULT '0',
`CategoryRecoveryTime` INT UNSIGNED NOT NULL DEFAULT '0',
`StartRecoveryTime` INT UNSIGNED NOT NULL DEFAULT '0',
`StartRecoveryCategory` INT UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`Id`)
);

View File

@@ -2804,6 +2804,16 @@ void Creature::AddSpellCooldown(uint32 spell_id, uint32 /*itemid*/, uint32 end_t
{
_AddCreatureSpellCooldown(spellInfo->Id, 0, spellcooldown);
}
if (sSpellMgr->HasSpellCooldownOverride(spellInfo->Id))
{
if (IsCharmed() && GetCharmer()->IsPlayer())
{
WorldPacket data;
BuildCooldownPacket(data, SPELL_COOLDOWN_FLAG_NONE, spellInfo->Id, spellcooldown);
GetCharmer()->ToPlayer()->SendDirectMessage(&data);
}
}
}
uint32 Creature::GetSpellCooldown(uint32 spell_id) const

View File

@@ -15876,6 +15876,24 @@ bool CharmInfo::AddSpellToActionBar(SpellInfo const* spellInfo, ActiveStates new
if (!PetActionBar[i].GetAction() && PetActionBar[i].IsActionBarForSpell())
{
SetActionBar(i, spell_id, newstate == ACT_DECIDE ? spellInfo->IsAutocastable() ? ACT_DISABLED : ACT_PASSIVE : newstate);
if (_unit->GetCharmer() && _unit->GetCharmer()->IsPlayer())
{
if (Creature* creature = _unit->ToCreature())
{
// Processing this packet needs to be delayed
_unit->m_Events.AddEventAtOffset([creature, spell_id]()
{
if (uint32 cooldown = creature->GetSpellCooldown(spell_id))
{
WorldPacket data;
creature->BuildCooldownPacket(data, SPELL_COOLDOWN_FLAG_NONE, spell_id, cooldown);
creature->GetCharmer()->ToPlayer()->SendDirectMessage(&data);
}
}, 500ms);
}
}
return true;
}
}

View File

@@ -2725,6 +2725,48 @@ void SpellMgr::LoadSpellInfoStore()
LOG_INFO("server.loading", " ");
}
void SpellMgr::LoadSpellCooldownOverrides()
{
uint32 oldMSTime = getMSTime();
mSpellCooldownOverrideMap.clear();
QueryResult result = WorldDatabase.Query("SELECT Id, RecoveryTime, CategoryRecoveryTime, StartRecoveryTime, StartRecoveryCategory FROM spell_cooldown_overrides");
uint32 count = 0;
if (result)
{
do
{
Field* fields = result->Fetch();
SpellCooldownOverride spellCooldown;
uint32 spellId = fields[0].Get<uint32>();
spellCooldown.RecoveryTime = fields[1].Get<uint32>();
spellCooldown.CategoryRecoveryTime = fields[2].Get<uint32>();
spellCooldown.StartRecoveryTime = fields[3].Get<uint32>();
spellCooldown.StartRecoveryCategory = fields[4].Get<uint32>();
mSpellCooldownOverrideMap[spellId] = spellCooldown;
++count;
} while (result->NextRow());
}
LOG_INFO("server.loading", ">> Loaded {} Spell Cooldown Overrides entries in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}
bool SpellMgr::HasSpellCooldownOverride(uint32 spellId) const
{
return mSpellCooldownOverrideMap.find(spellId) != mSpellCooldownOverrideMap.end();
}
SpellCooldownOverride SpellMgr::GetSpellCooldownOverride(uint32 spellId) const
{
auto range = mSpellCooldownOverrideMap.find(spellId);
return range->second;
}
void SpellMgr::UnloadSpellInfoStore()
{
for (uint32 i = 0; i < GetSpellInfoStoreSize(); ++i)
@@ -3412,9 +3454,35 @@ void SpellMgr::LoadSpellInfoCustomAttributes()
}
}
}
spellInfo->_InitializeExplicitTargetMask();
sScriptMgr->OnLoadSpellCustomAttr(spellInfo);
spellInfo->_InitializeExplicitTargetMask();
if (sSpellMgr->HasSpellCooldownOverride(spellInfo->Id))
{
SpellCooldownOverride spellOverride = sSpellMgr->GetSpellCooldownOverride(spellInfo->Id);
if (spellInfo->RecoveryTime != spellOverride.RecoveryTime)
{
spellInfo->RecoveryTime = spellOverride.RecoveryTime;
}
if (spellInfo->CategoryRecoveryTime != spellOverride.CategoryRecoveryTime)
{
spellInfo->CategoryRecoveryTime = spellOverride.CategoryRecoveryTime;
}
if (spellInfo->StartRecoveryTime != spellOverride.StartRecoveryTime)
{
spellInfo->RecoveryTime = spellOverride.RecoveryTime;
}
if (spellInfo->StartRecoveryCategory != spellOverride.StartRecoveryCategory)
{
spellInfo->RecoveryTime = spellOverride.RecoveryTime;
}
}
sScriptMgr->OnLoadSpellCustomAttr(spellInfo);
}
// Xinef: addition for binary spells, ommit spells triggering other spells

View File

@@ -596,6 +596,16 @@ typedef std::vector<SpellInfo*> SpellInfoMap;
typedef std::map<int32, std::vector<int32> > SpellLinkedMap;
struct SpellCooldownOverride
{
uint32 RecoveryTime;
uint32 CategoryRecoveryTime;
uint32 StartRecoveryTime;
uint32 StartRecoveryCategory;
};
typedef std::map<uint32, SpellCooldownOverride> SpellCooldownOverrideMap;
bool IsPrimaryProfessionSkill(uint32 skill);
inline bool IsProfessionSkill(uint32 skill)
@@ -736,6 +746,9 @@ public:
// Talent Additional Set
[[nodiscard]] bool IsAdditionalTalentSpell(uint32 spellId) const;
[[nodiscard]] bool HasSpellCooldownOverride(uint32 spellId) const;
[[nodiscard]] SpellCooldownOverride GetSpellCooldownOverride(uint32 spellId) const;
private:
SpellInfo* _GetSpellInfo(uint32 spellId) { return spellId < GetSpellInfoStoreSize() ? mSpellInfoMap[spellId] : nullptr; }
@@ -764,6 +777,7 @@ public:
void LoadPetDefaultSpells();
void LoadSpellAreas();
void LoadSpellInfoStore();
void LoadSpellCooldownOverrides();
void UnloadSpellInfoStore();
void UnloadSpellInfoImplicitTargetConditionLists();
void LoadSpellInfoCustomAttributes();
@@ -797,6 +811,7 @@ private:
PetLevelupSpellMap mPetLevelupSpellMap;
PetDefaultSpellsMap mPetDefaultSpellsMap; // only spells not listed in related mPetLevelupSpellMap entry
SpellInfoMap mSpellInfoMap;
SpellCooldownOverrideMap mSpellCooldownOverrideMap;
TalentAdditionalSet mTalentSpellAdditionalSet;
};

View File

@@ -1582,6 +1582,9 @@ void World::SetInitialWorldSettings()
LOG_INFO("server.loading", "Loading SpellInfo Store...");
sSpellMgr->LoadSpellInfoStore();
LOG_INFO("server.loading", "Loading Spell Cooldown Overrides...");
sSpellMgr->LoadSpellCooldownOverrides();
LOG_INFO("server.loading", "Loading SpellInfo Data Corrections...");
sSpellMgr->LoadSpellInfoCorrections();