Core/Auras: Add functions for common actions on aura charges.

This commit is contained in:
QAston
2011-06-07 17:26:27 +02:00
parent 109a861407
commit b9e8e6d3b4
7 changed files with 72 additions and 57 deletions
+1 -1
View File
@@ -19669,7 +19669,7 @@ void Player::RemoveSpellMods(Spell * spell)
// remove from list // remove from list
spell->m_appliedMods.erase(iterMod); spell->m_appliedMods.erase(iterMod);
if (mod->ownerAura->DropCharge()) if (mod->ownerAura->DropCharge(AURA_REMOVE_BY_EXPIRE))
itr = m_spellMods[i].begin(); itr = m_spellMods[i].begin();
} }
} }
+9 -26
View File
@@ -3157,13 +3157,8 @@ Aura* Unit::_TryStackingOrRefreshingExistingAura(SpellEntry const* newAura, uint
*oldGUID = castItemGUID; *oldGUID = castItemGUID;
} }
uint8 charges = foundAura->GetSpellProto()->procCharges;
if (caster)
if (Player* modOwner = caster->GetSpellModOwner())
modOwner->ApplySpellMod(foundAura->GetId(), SPELLMOD_CHARGES, charges);
// refresh charges // refresh charges
foundAura->SetCharges(charges); foundAura->SetCharges(foundAura->CalcMaxCharges(caster));
// try to increase stack amount // try to increase stack amount
foundAura->ModStackAmount(1); foundAura->ModStackAmount(1);
@@ -3675,10 +3670,7 @@ void Unit::RemoveAurasDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit
if (aura->GetCasterGUID() == casterGUID) if (aura->GetCasterGUID() == casterGUID)
{ {
if (aura->GetSpellProto()->AttributesEx7 & SPELL_ATTR7_DISPEL_CHARGES) if (aura->GetSpellProto()->AttributesEx7 & SPELL_ATTR7_DISPEL_CHARGES)
{ aura->ModCharges(-chargesRemoved, AURA_REMOVE_BY_ENEMY_SPELL);
for (uint8 i = 0; i < chargesRemoved; i++)
aura->DropCharge();
}
else else
aura->ModStackAmount(-chargesRemoved, AURA_REMOVE_BY_ENEMY_SPELL); aura->ModStackAmount(-chargesRemoved, AURA_REMOVE_BY_ENEMY_SPELL);
@@ -3793,21 +3785,12 @@ void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit
} }
bool stealCharge = aura->GetSpellProto()->AttributesEx7 & SPELL_ATTR7_DISPEL_CHARGES; bool stealCharge = aura->GetSpellProto()->AttributesEx7 & SPELL_ATTR7_DISPEL_CHARGES;
bool stealStack = aura->GetSpellProto()->StackAmount > 1; int32 dur = std::min(2*MINUTE*IN_MILLISECONDS, aura->GetDuration());
int32 dur = (2*MINUTE*IN_MILLISECONDS < aura->GetDuration() || aura->GetDuration() < 0) ? 2*MINUTE*IN_MILLISECONDS : aura->GetDuration();
if (Aura * newAura = (stealCharge || stealStack) ? stealer->GetAura(aura->GetId(), aura->GetCasterGUID()) : NULL) if (Aura * newAura = stealer->GetAura(aura->GetId(), aura->GetCasterGUID()))
{ {
if (stealCharge) if (stealCharge)
{ newAura->ModCharges(1);
uint8 newCharges = newAura->GetCharges() + 1;
uint8 maxCharges = newAura->GetSpellProto()->procCharges;
// We must be able to steal as much charges as original caster can have
if (caster)
if (Player* modOwner = caster->GetSpellModOwner())
modOwner->ApplySpellMod(aura->GetId(), SPELLMOD_CHARGES, maxCharges);
newAura->SetCharges(maxCharges < newCharges ? maxCharges : newCharges);
}
else else
newAura->ModStackAmount(1); newAura->ModStackAmount(1);
newAura->SetDuration(dur); newAura->SetDuration(dur);
@@ -3834,7 +3817,7 @@ void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit
} }
if (stealCharge) if (stealCharge)
aura->DropCharge(); aura->ModCharges(-1, AURA_REMOVE_BY_ENEMY_SPELL);
else else
aura->ModStackAmount(-1, AURA_REMOVE_BY_ENEMY_SPELL); aura->ModStackAmount(-1, AURA_REMOVE_BY_ENEMY_SPELL);
@@ -10065,7 +10048,7 @@ Unit* Unit::SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo)
if (Unit* magnet = (*itr)->GetBase()->GetUnitOwner()) if (Unit* magnet = (*itr)->GetBase()->GetUnitOwner())
if (magnet->isAlive()) if (magnet->isAlive())
{ {
(*itr)->GetBase()->DropCharge(); (*itr)->GetBase()->DropCharge(AURA_REMOVE_BY_EXPIRE);
return magnet; return magnet;
} }
} }
@@ -10078,7 +10061,7 @@ Unit* Unit::SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo)
if (magnet->isAlive() && magnet->IsWithinLOSInMap(this)) if (magnet->isAlive() && magnet->IsWithinLOSInMap(this))
if (roll_chance_i((*i)->GetAmount())) if (roll_chance_i((*i)->GetAmount()))
{ {
(*i)->GetBase()->DropCharge(); (*i)->GetBase()->DropCharge(AURA_REMOVE_BY_EXPIRE);
return magnet; return magnet;
} }
} }
@@ -14417,7 +14400,7 @@ void Unit::ProcDamageAndSpellFor(bool isVictim, Unit * pTarget, uint32 procFlag,
} }
// Remove charge (aura can be removed by triggers) // Remove charge (aura can be removed by triggers)
if (useCharges && takeCharges) if (useCharges && takeCharges)
i->aura->DropCharge(); i->aura->DropCharge(AURA_REMOVE_BY_EXPIRE);
if (spellInfo->AttributesEx3 & SPELL_ATTR3_DISABLE_PROC) if (spellInfo->AttributesEx3 & SPELL_ATTR3_DISABLE_PROC)
SetCantProc(false); SetCantProc(false);
+29 -18
View File
@@ -336,14 +336,7 @@ m_isRemoved(false), m_isSingleTarget(false)
m_maxDuration = CalcMaxDuration(caster); m_maxDuration = CalcMaxDuration(caster);
m_duration = m_maxDuration; m_duration = m_maxDuration;
m_procCharges = CalcMaxCharges(caster);
Player* modOwner = NULL;
if (caster)
modOwner = caster->GetSpellModOwner();
m_procCharges = m_spellProto->procCharges;
if (modOwner)
modOwner->ApplySpellMod(GetId(), SPELLMOD_CHARGES, m_procCharges);
} }
void Aura::_InitEffects(uint8 effMask, Unit * caster, int32 *baseAmount) void Aura::_InitEffects(uint8 effMask, Unit * caster, int32 *baseAmount)
@@ -738,17 +731,34 @@ void Aura::SetCharges(uint8 charges)
SetNeedClientUpdateForTargets(); SetNeedClientUpdateForTargets();
} }
bool Aura::DropCharge() uint8 Aura::CalcMaxCharges(Unit * caster) const
{ {
if (m_procCharges) //auras without charges always have charge = 0 uint8 maxProcCharges = m_spellProto->procCharges;
if (caster)
if (Player* modOwner = caster->GetSpellModOwner())
modOwner->ApplySpellMod(GetId(), SPELLMOD_CHARGES, maxProcCharges);
return maxProcCharges;
}
bool Aura::ModCharges(int32 num, AuraRemoveMode removeMode)
{
if (m_procCharges)
{ {
if (--m_procCharges) // Send charge change int32 charges = m_procCharges + num;
SetNeedClientUpdateForTargets(); int32 maxCharges = CalcMaxCharges();
else // Last charge dropped
// limit charges (only on charges increase, charges may be changed manually)
if ((num > 0) && (charges > int32(maxCharges)))
charges = maxCharges;
// we're out of charges, remove
else if (charges <= 0)
{ {
Remove(AURA_REMOVE_BY_EXPIRE); Remove(removeMode);
return true; return true;
} }
SetCharges(charges);
} }
return false; return false;
} }
@@ -763,12 +773,12 @@ void Aura::SetStackAmount(uint8 stackAmount)
SetNeedClientUpdateForTargets(); SetNeedClientUpdateForTargets();
} }
void Aura::ModStackAmount(int32 num, AuraRemoveMode removeMode) bool Aura::ModStackAmount(int32 num, AuraRemoveMode removeMode)
{ {
int32 stackAmount = m_stackAmount + num; int32 stackAmount = m_stackAmount + num;
// limit the stack amount // limit the stack amount (only on stack increase, stack amount may be changed manually)
if (stackAmount > int32(m_spellProto->StackAmount)) if ((num > 0) && (stackAmount > int32(m_spellProto->StackAmount)))
{ {
// not stackable aura - set stack amount to 1 // not stackable aura - set stack amount to 1
if(!m_spellProto->StackAmount) if(!m_spellProto->StackAmount)
@@ -780,7 +790,7 @@ void Aura::ModStackAmount(int32 num, AuraRemoveMode removeMode)
else if (stackAmount <= 0) else if (stackAmount <= 0)
{ {
Remove(removeMode); Remove(removeMode);
return; return true;
} }
bool refresh = stackAmount >= GetStackAmount(); bool refresh = stackAmount >= GetStackAmount();
@@ -791,6 +801,7 @@ void Aura::ModStackAmount(int32 num, AuraRemoveMode removeMode)
if (refresh) if (refresh)
RefreshDuration(); RefreshDuration();
SetNeedClientUpdateForTargets(); SetNeedClientUpdateForTargets();
return false;
} }
bool Aura::IsPassive() const bool Aura::IsPassive() const
+5 -2
View File
@@ -131,11 +131,14 @@ class Aura
uint8 GetCharges() const { return m_procCharges; } uint8 GetCharges() const { return m_procCharges; }
void SetCharges(uint8 charges); void SetCharges(uint8 charges);
bool DropCharge(); uint8 CalcMaxCharges(Unit * caster) const;
uint8 CalcMaxCharges() const { return CalcMaxCharges(GetCaster()); }
bool ModCharges(int32 num, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT);
bool DropCharge(AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT) { return ModCharges(-1, removeMode); }
uint8 GetStackAmount() const { return m_stackAmount; } uint8 GetStackAmount() const { return m_stackAmount; }
void SetStackAmount(uint8 num); void SetStackAmount(uint8 num);
void ModStackAmount(int32 num, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT); bool ModStackAmount(int32 num, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT);
uint8 GetCasterLevel() const { return m_casterLevel; } uint8 GetCasterLevel() const { return m_casterLevel; }
+5 -5
View File
@@ -5110,15 +5110,15 @@ void Spell::EffectScriptEffect(SpellEffIndex effIndex)
sLog->outError("Unknown Lightwell spell caster %u", m_caster->GetEntry()); sLog->outError("Unknown Lightwell spell caster %u", m_caster->GetEntry());
return; return;
} }
Aura * chargesaura = m_caster->GetAura(59907);
if (chargesaura && chargesaura->GetCharges() > 1) // proc a spellcast
if (Aura * chargesAura = m_caster->GetAura(59907))
{ {
chargesaura->SetCharges(chargesaura->GetCharges() - 1);
m_caster->CastSpell(unitTarget, spell_heal, true, NULL, NULL, m_caster->ToTempSummon()->GetSummonerGUID()); m_caster->CastSpell(unitTarget, spell_heal, true, NULL, NULL, m_caster->ToTempSummon()->GetSummonerGUID());
if (chargesAura->ModCharges(-1))
m_caster->ToTempSummon()->UnSummon();
} }
else
m_caster->ToTempSummon()->UnSummon();
return; return;
} }
// Stoneclaw Totem // Stoneclaw Totem
+18 -3
View File
@@ -778,6 +778,11 @@ void AuraScript::SetMaxDuration(int32 duration)
m_aura->SetMaxDuration(duration); m_aura->SetMaxDuration(duration);
} }
int32 AuraScript::CalcMaxDuration() const
{
return m_aura->CalcMaxDuration();
}
bool AuraScript::IsExpired() const bool AuraScript::IsExpired() const
{ {
return m_aura->IsExpired(); return m_aura->IsExpired();
@@ -798,9 +803,19 @@ void AuraScript::SetCharges(uint8 charges)
m_aura->SetCharges(charges); m_aura->SetCharges(charges);
} }
bool AuraScript::DropCharge() uint8 AuraScript::CalcMaxCharges() const
{ {
return m_aura->DropCharge(); return m_aura->CalcMaxCharges();
}
bool AuraScript::ModCharges(int8 num, AuraRemoveMode removeMode /*= AURA_REMOVE_BY_DEFAULT*/)
{
return m_aura->ModCharges(num, removeMode);
}
bool AuraScript::DropCharge(AuraRemoveMode removeMode)
{
return m_aura->DropCharge(removeMode);
} }
uint8 AuraScript::GetStackAmount() const uint8 AuraScript::GetStackAmount() const
@@ -813,7 +828,7 @@ void AuraScript::SetStackAmount(uint8 num)
m_aura->SetStackAmount(num); m_aura->SetStackAmount(num);
} }
void AuraScript::ModStackAmount(int32 num, AuraRemoveMode removeMode) bool AuraScript::ModStackAmount(int32 num, AuraRemoveMode removeMode)
{ {
return m_aura->ModStackAmount(num, removeMode); return m_aura->ModStackAmount(num, removeMode);
} }
+5 -2
View File
@@ -609,6 +609,7 @@ class AuraScript : public _SpellScript
time_t GetApplyTime() const; time_t GetApplyTime() const;
int32 GetMaxDuration() const; int32 GetMaxDuration() const;
void SetMaxDuration(int32 duration); void SetMaxDuration(int32 duration);
int32 CalcMaxDuration() const;
// expired - duration just went to 0 // expired - duration just went to 0
bool IsExpired() const; bool IsExpired() const;
// permament - has infinite duration // permament - has infinite duration
@@ -617,13 +618,15 @@ class AuraScript : public _SpellScript
// charges manipulation - 0 - not charged aura // charges manipulation - 0 - not charged aura
uint8 GetCharges() const; uint8 GetCharges() const;
void SetCharges(uint8 charges); void SetCharges(uint8 charges);
uint8 CalcMaxCharges() const;
bool ModCharges(int8 num, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT);
// returns true if last charge dropped // returns true if last charge dropped
bool DropCharge(); bool DropCharge(AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT);
// stack amount manipulation // stack amount manipulation
uint8 GetStackAmount() const; uint8 GetStackAmount() const;
void SetStackAmount(uint8 num); void SetStackAmount(uint8 num);
void ModStackAmount(int32 num, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT); bool ModStackAmount(int32 num, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT);
// passive - "working in background", not saved, not removed by immonities, not seen by player // passive - "working in background", not saved, not removed by immonities, not seen by player
bool IsPassive() const; bool IsPassive() const;