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
+29 -18
View File
@@ -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
+5 -2
View File
@@ -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; }
+5 -5
View File
@@ -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
+18 -3
View File
@@ -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->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
@@ -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);
}
+5 -2
View File
@@ -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;