Core/Spell: kill old charge restoring system. Mods are fully handled by proc system now.

- Fixes an edge case of spell failing due to out of range and re-adding charges to an existing aura.

(cherry picked from commit ee6d1d02c0)
This commit is contained in:
ariel-
2016-12-30 15:59:59 -03:00
committed by joschiwald
parent 95408869c0
commit 87ed45d912
5 changed files with 12 additions and 88 deletions

View File

@@ -21901,62 +21901,6 @@ void Player::AddSpellMod(SpellModifier* mod, bool apply)
}
}
// Restore spellmods in case of failed cast
void Player::RestoreSpellMods(Spell* spell, uint32 ownerAuraId /*= 0*/, Aura* aura /*= nullptr*/)
{
if (!spell || spell->m_appliedMods.empty())
return;
std::vector<Aura*> aurasQueue;
for (uint8 i = 0; i < MAX_SPELLMOD; ++i)
{
for (uint8 j = 0; j < SPELLMOD_END; ++j)
{
for (SpellModifier* mod : m_spellMods[i][j])
{
// Spellmods without charged aura set cannot be charged
if (!mod->ownerAura->IsUsingCharges())
continue;
// Restore only specific owner aura mods
if (ownerAuraId && mod->spellId != ownerAuraId)
continue;
if (aura && mod->ownerAura != aura)
continue;
// Check if mod affected this spell
// First, check if the mod aura applied at least one spellmod to this spell
Spell::UsedSpellMods::iterator iterMod = spell->m_appliedMods.find(mod->ownerAura);
if (iterMod == spell->m_appliedMods.end())
continue;
// Second, check if the current mod is one of those applied by the mod aura
if (!(mod->mask & spell->m_spellInfo->SpellFamilyFlags))
continue;
// remove from list - This will be done after all mods have been gone through
// to ensure we iterate over all mods of an aura before removing said aura
// from applied mods (Else, an aura with two mods on the current spell would
// only see the first of its modifier restored)
aurasQueue.push_back(mod->ownerAura);
// add charges back to aura
mod->ownerAura->ModCharges(1);
}
}
}
for (Aura* aura : aurasQueue)
spell->m_appliedMods.erase(aura);
}
void Player::RestoreAllSpellMods(uint32 ownerAuraId /*= 0*/, Aura* aura /*= nullptr*/)
{
for (uint32 i = 0; i < CURRENT_MAX_SPELL; ++i)
if (Spell* spell = m_currentSpells[i])
RestoreSpellMods(spell, ownerAuraId, aura);
}
void Player::ApplyModToSpell(SpellModifier* mod, Spell* spell)
{
if (!spell)

View File

@@ -1681,8 +1681,6 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
static bool IsAffectedBySpellmod(SpellInfo const* spellInfo, SpellModifier* mod, Spell* spell = nullptr);
template <class T>
void ApplySpellMod(uint32 spellId, SpellModOp op, T& basevalue, Spell* spell = nullptr) const;
void RestoreSpellMods(Spell* spell, uint32 ownerAuraId = 0, Aura* aura = nullptr);
void RestoreAllSpellMods(uint32 ownerAuraId = 0, Aura* aura = nullptr);
static void ApplyModToSpell(SpellModifier* mod, Spell* spell);
void SetSpellModTakingSpell(Spell* spell, bool apply);
void SendSpellModifiers() const;

View File

@@ -961,7 +961,6 @@ bool Aura::ModStackAmount(int32 num, AuraRemoveMode removeMode /*= AURA_REMOVE_B
if (refresh)
{
RefreshSpellMods();
RefreshTimers(resetPeriodicTimer);
// reset charges
@@ -972,13 +971,6 @@ bool Aura::ModStackAmount(int32 num, AuraRemoveMode removeMode /*= AURA_REMOVE_B
return false;
}
void Aura::RefreshSpellMods()
{
for (Aura::ApplicationMap::const_iterator appIter = m_applications.begin(); appIter != m_applications.end(); ++appIter)
if (Player* player = appIter->second->GetTarget()->ToPlayer())
player->RestoreAllSpellMods(0, this);
}
bool Aura::HasMoreThanOneEffectForType(AuraType auraType) const
{
uint32 count = 0;

View File

@@ -182,8 +182,6 @@ class TC_GAME_API Aura
void SetStackAmount(uint8 num);
bool ModStackAmount(int32 num, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT, bool resetPeriodicTimer = true);
void RefreshSpellMods();
uint8 GetCasterLevel() const { return m_casterLevel; }
bool HasMoreThanOneEffectForType(AuraType auraType) const;

View File

@@ -3030,13 +3030,10 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect const* triggered
triggeredByAura->GetBase()->SetDuration(0);
}
// cleanup after mod system
// triggered spell pointer can be not removed in some cases
if (m_caster->GetTypeId() == TYPEID_PLAYER)
{
m_caster->ToPlayer()->RestoreSpellMods(this);
// cleanup after mod system
// triggered spell pointer can be not removed in some cases
m_caster->ToPlayer()->SetSpellModTakingSpell(this, false);
}
if (param1 || param2)
SendCastResult(result, &param1, &param2);
@@ -3144,8 +3141,6 @@ void Spell::cancel()
{
case SPELL_STATE_PREPARING:
CancelGlobalCooldown();
if (m_caster->GetTypeId() == TYPEID_PLAYER)
m_caster->ToPlayer()->RestoreSpellMods(this);
// no break
case SPELL_STATE_DELAYED:
SendInterrupted(0);
@@ -3240,14 +3235,12 @@ void Spell::cast(bool skipCheck)
{
SendCastResult(castResult, &param1, &param2);
SendInterrupted(0);
//restore spell mods
// cleanup after mod system
// triggered spell pointer can be not removed in some cases
if (m_caster->GetTypeId() == TYPEID_PLAYER)
{
m_caster->ToPlayer()->RestoreSpellMods(this);
// cleanup after mod system
// triggered spell pointer can be not removed in some cases
m_caster->ToPlayer()->SetSpellModTakingSpell(this, false);
}
finish(false);
SetExecutedCurrently(false);
return;
@@ -3267,10 +3260,11 @@ void Spell::cast(bool skipCheck)
my_trade->SetSpell(m_spellInfo->Id, m_CastItem);
SendCastResult(SPELL_FAILED_DONT_REPORT);
SendInterrupted(0);
m_caster->ToPlayer()->RestoreSpellMods(this);
// cleanup after mod system
// triggered spell pointer can be not removed in some cases
m_caster->ToPlayer()->SetSpellModTakingSpell(this, false);
finish(false);
SetExecutedCurrently(false);
return;
@@ -3293,14 +3287,12 @@ void Spell::cast(bool skipCheck)
if (m_spellState == SPELL_STATE_FINISHED)
{
SendInterrupted(0);
//restore spell mods
// cleanup after mod system
// triggered spell pointer can be not removed in some cases
if (m_caster->GetTypeId() == TYPEID_PLAYER)
{
m_caster->ToPlayer()->RestoreSpellMods(this);
// cleanup after mod system
// triggered spell pointer can be not removed in some cases
m_caster->ToPlayer()->SetSpellModTakingSpell(this, false);
}
finish(false);
SetExecutedCurrently(false);
return;