aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/server/game/Entities/Player/Player.cpp2
-rwxr-xr-xsrc/server/game/Entities/Unit/Unit.cpp35
-rwxr-xr-xsrc/server/game/Spells/Auras/SpellAuras.cpp47
-rwxr-xr-xsrc/server/game/Spells/Auras/SpellAuras.h7
-rwxr-xr-xsrc/server/game/Spells/SpellEffects.cpp10
-rwxr-xr-xsrc/server/game/Spells/SpellScript.cpp21
-rwxr-xr-xsrc/server/game/Spells/SpellScript.h7
7 files changed, 72 insertions, 57 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 6e43d918760..01d2f7776fa 100755
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -19669,7 +19669,7 @@ void Player::RemoveSpellMods(Spell * spell)
// remove from list
spell->m_appliedMods.erase(iterMod);
- if (mod->ownerAura->DropCharge())
+ if (mod->ownerAura->DropCharge(AURA_REMOVE_BY_EXPIRE))
itr = m_spellMods[i].begin();
}
}
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 04b285ef334..a4b0041e609 100755
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -3157,13 +3157,8 @@ Aura* Unit::_TryStackingOrRefreshingExistingAura(SpellEntry const* newAura, uint
*oldGUID = castItemGUID;
}
- uint8 charges = foundAura->GetSpellProto()->procCharges;
- if (caster)
- if (Player* modOwner = caster->GetSpellModOwner())
- modOwner->ApplySpellMod(foundAura->GetId(), SPELLMOD_CHARGES, charges);
-
// refresh charges
- foundAura->SetCharges(charges);
+ foundAura->SetCharges(foundAura->CalcMaxCharges(caster));
// try to increase stack amount
foundAura->ModStackAmount(1);
@@ -3675,10 +3670,7 @@ void Unit::RemoveAurasDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit
if (aura->GetCasterGUID() == casterGUID)
{
if (aura->GetSpellProto()->AttributesEx7 & SPELL_ATTR7_DISPEL_CHARGES)
- {
- for (uint8 i = 0; i < chargesRemoved; i++)
- aura->DropCharge();
- }
+ aura->ModCharges(-chargesRemoved, AURA_REMOVE_BY_ENEMY_SPELL);
else
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 stealStack = aura->GetSpellProto()->StackAmount > 1;
- int32 dur = (2*MINUTE*IN_MILLISECONDS < aura->GetDuration() || aura->GetDuration() < 0) ? 2*MINUTE*IN_MILLISECONDS : aura->GetDuration();
+ int32 dur = std::min(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)
- {
- 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);
- }
+ newAura->ModCharges(1);
else
newAura->ModStackAmount(1);
newAura->SetDuration(dur);
@@ -3834,7 +3817,7 @@ void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit
}
if (stealCharge)
- aura->DropCharge();
+ aura->ModCharges(-1, AURA_REMOVE_BY_ENEMY_SPELL);
else
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 (magnet->isAlive())
{
- (*itr)->GetBase()->DropCharge();
+ (*itr)->GetBase()->DropCharge(AURA_REMOVE_BY_EXPIRE);
return magnet;
}
}
@@ -10078,7 +10061,7 @@ Unit* Unit::SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo)
if (magnet->isAlive() && magnet->IsWithinLOSInMap(this))
if (roll_chance_i((*i)->GetAmount()))
{
- (*i)->GetBase()->DropCharge();
+ (*i)->GetBase()->DropCharge(AURA_REMOVE_BY_EXPIRE);
return magnet;
}
}
@@ -14417,7 +14400,7 @@ void Unit::ProcDamageAndSpellFor(bool isVictim, Unit * pTarget, uint32 procFlag,
}
// Remove charge (aura can be removed by triggers)
if (useCharges && takeCharges)
- i->aura->DropCharge();
+ i->aura->DropCharge(AURA_REMOVE_BY_EXPIRE);
if (spellInfo->AttributesEx3 & SPELL_ATTR3_DISABLE_PROC)
SetCantProc(false);
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;