diff options
| author | QAston <qaston@gmail.com> | 2011-06-07 17:25:34 +0200 |
|---|---|---|
| committer | QAston <qaston@gmail.com> | 2011-06-07 17:26:27 +0200 |
| commit | b9e8e6d3b4cfedea8e0cbe51e1f6789aeb996de0 (patch) | |
| tree | 7bc4a68a56fd9ea9ca4bf1fe8e8e603615f6e3b0 /src/server/game/Spells | |
| parent | 109a861407bf88a6a1485f3cf4758c45ba8bc743 (diff) | |
Core/Auras: Add functions for common actions on aura charges.
Diffstat (limited to 'src/server/game/Spells')
| -rwxr-xr-x | src/server/game/Spells/Auras/SpellAuras.cpp | 47 | ||||
| -rwxr-xr-x | src/server/game/Spells/Auras/SpellAuras.h | 7 | ||||
| -rwxr-xr-x | src/server/game/Spells/SpellEffects.cpp | 10 | ||||
| -rwxr-xr-x | src/server/game/Spells/SpellScript.cpp | 21 | ||||
| -rwxr-xr-x | src/server/game/Spells/SpellScript.h | 7 |
5 files changed, 62 insertions, 30 deletions
diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp index 592eb08a1c9..0630abe1ca1 100755 --- a/src/server/game/Spells/Auras/SpellAuras.cpp +++ b/src/server/game/Spells/Auras/SpellAuras.cpp @@ -336,14 +336,7 @@ m_isRemoved(false), m_isSingleTarget(false) m_maxDuration = CalcMaxDuration(caster); m_duration = m_maxDuration; - - Player* modOwner = NULL; - if (caster) - modOwner = caster->GetSpellModOwner(); - - m_procCharges = m_spellProto->procCharges; - if (modOwner) - modOwner->ApplySpellMod(GetId(), SPELLMOD_CHARGES, m_procCharges); + m_procCharges = CalcMaxCharges(caster); } void Aura::_InitEffects(uint8 effMask, Unit * caster, int32 *baseAmount) @@ -738,17 +731,34 @@ void Aura::SetCharges(uint8 charges) 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 - SetNeedClientUpdateForTargets(); - else // Last charge dropped + int32 charges = m_procCharges + num; + int32 maxCharges = CalcMaxCharges(); + + // 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; } + + SetCharges(charges); } return false; } @@ -763,12 +773,12 @@ void Aura::SetStackAmount(uint8 stackAmount) SetNeedClientUpdateForTargets(); } -void Aura::ModStackAmount(int32 num, AuraRemoveMode removeMode) +bool Aura::ModStackAmount(int32 num, AuraRemoveMode removeMode) { int32 stackAmount = m_stackAmount + num; - // limit the stack amount - if (stackAmount > int32(m_spellProto->StackAmount)) + // limit the stack amount (only on stack increase, stack amount may be changed manually) + if ((num > 0) && (stackAmount > int32(m_spellProto->StackAmount))) { // not stackable aura - set stack amount to 1 if(!m_spellProto->StackAmount) @@ -780,7 +790,7 @@ void Aura::ModStackAmount(int32 num, AuraRemoveMode removeMode) else if (stackAmount <= 0) { Remove(removeMode); - return; + return true; } bool refresh = stackAmount >= GetStackAmount(); @@ -791,6 +801,7 @@ void Aura::ModStackAmount(int32 num, AuraRemoveMode removeMode) if (refresh) RefreshDuration(); SetNeedClientUpdateForTargets(); + return false; } bool Aura::IsPassive() const diff --git a/src/server/game/Spells/Auras/SpellAuras.h b/src/server/game/Spells/Auras/SpellAuras.h index 67f4eb30b27..3dd9c651692 100755 --- a/src/server/game/Spells/Auras/SpellAuras.h +++ b/src/server/game/Spells/Auras/SpellAuras.h @@ -131,11 +131,14 @@ class Aura uint8 GetCharges() const { return m_procCharges; } 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; } 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; } diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index caed2ca93f4..85dfa7273ea 100755 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -5110,15 +5110,15 @@ void Spell::EffectScriptEffect(SpellEffIndex effIndex) sLog->outError("Unknown Lightwell spell caster %u", m_caster->GetEntry()); 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()); + if (chargesAura->ModCharges(-1)) + m_caster->ToTempSummon()->UnSummon(); } - else - m_caster->ToTempSummon()->UnSummon(); + return; } // Stoneclaw Totem diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp index 4645a2564a7..d6c95ed4187 100755 --- a/src/server/game/Spells/SpellScript.cpp +++ b/src/server/game/Spells/SpellScript.cpp @@ -778,6 +778,11 @@ void AuraScript::SetMaxDuration(int32 duration) m_aura->SetMaxDuration(duration); } +int32 AuraScript::CalcMaxDuration() const +{ + return m_aura->CalcMaxDuration(); +} + bool AuraScript::IsExpired() const { return m_aura->IsExpired(); @@ -798,9 +803,19 @@ void AuraScript::SetCharges(uint8 charges) m_aura->SetCharges(charges); } -bool AuraScript::DropCharge() +uint8 AuraScript::CalcMaxCharges() const +{ + 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(); + return m_aura->DropCharge(removeMode); } uint8 AuraScript::GetStackAmount() const @@ -813,7 +828,7 @@ void AuraScript::SetStackAmount(uint8 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); } diff --git a/src/server/game/Spells/SpellScript.h b/src/server/game/Spells/SpellScript.h index 564d699c69b..5deb035160d 100755 --- a/src/server/game/Spells/SpellScript.h +++ b/src/server/game/Spells/SpellScript.h @@ -609,6 +609,7 @@ class AuraScript : public _SpellScript time_t GetApplyTime() const; int32 GetMaxDuration() const; void SetMaxDuration(int32 duration); + int32 CalcMaxDuration() const; // expired - duration just went to 0 bool IsExpired() const; // permament - has infinite duration @@ -617,13 +618,15 @@ class AuraScript : public _SpellScript // charges manipulation - 0 - not charged aura uint8 GetCharges() const; void SetCharges(uint8 charges); + uint8 CalcMaxCharges() const; + bool ModCharges(int8 num, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT); // returns true if last charge dropped - bool DropCharge(); + bool DropCharge(AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT); // stack amount manipulation uint8 GetStackAmount() const; 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 bool IsPassive() const; |
