Scripts/AuraScript: Make AuraApplication in OnEffectPeriodic never be NULL.

Scripts: remove some unnecessary NULL checks from scripts.

--HG--
branch : trunk
This commit is contained in:
QAston
2010-12-05 21:38:52 +01:00
parent e2c9453442
commit 59c1a238f5
13 changed files with 84 additions and 88 deletions
@@ -400,6 +400,17 @@ void AuraEffect::GetTargetList(std::list<Unit *> & targetList) const
} }
} }
void AuraEffect::GetApplicationList(std::list<AuraApplication *> & applicationList) const
{
Aura::ApplicationMap const & targetMap = GetBase()->GetApplicationMap();
// remove all targets which were not added to new list - they no longer deserve area aura
for (Aura::ApplicationMap::const_iterator appIter = targetMap.begin(); appIter != targetMap.end(); ++appIter)
{
if (appIter->second->HasEffect(GetEffIndex()))
applicationList.push_back(appIter->second);
}
}
int32 AuraEffect::CalculateAmount(Unit * caster) int32 AuraEffect::CalculateAmount(Unit * caster)
{ {
int32 amount; int32 amount;
@@ -1057,13 +1068,13 @@ void AuraEffect::Update(uint32 diff, Unit * caster)
m_periodicTimer += m_amplitude - diff; m_periodicTimer += m_amplitude - diff;
UpdatePeriodic(caster); UpdatePeriodic(caster);
UnitList effectTargets; std::list<AuraApplication*> effectApplications;
GetTargetList(effectTargets); GetApplicationList(effectApplications);
// tick on targets of effects // tick on targets of effects
if (!caster || !caster->hasUnitState(UNIT_STAT_ISOLATED)) if (!caster || !caster->hasUnitState(UNIT_STAT_ISOLATED))
{ {
for (UnitList::iterator targetItr = effectTargets.begin(); targetItr != effectTargets.end(); ++targetItr) for (std::list<AuraApplication*>::iterator apptItr = effectApplications.begin(); apptItr != effectApplications.end(); ++apptItr)
PeriodicTick(*targetItr, caster); PeriodicTick(*apptItr, caster);
} }
} }
} }
@@ -1224,12 +1235,14 @@ void AuraEffect::SendTickImmune(Unit * target, Unit *caster) const
caster->SendSpellDamageImmune(target, m_spellProto->Id); caster->SendSpellDamageImmune(target, m_spellProto->Id);
} }
void AuraEffect::PeriodicTick(Unit * target, Unit * caster) const void AuraEffect::PeriodicTick(AuraApplication * aurApp, Unit * caster) const
{ {
bool prevented = GetBase()->CallScriptEffectPeriodicHandlers(const_cast<AuraEffect const *>(this), GetBase()->GetApplicationOfTarget(target->GetGUID())); bool prevented = GetBase()->CallScriptEffectPeriodicHandlers(const_cast<AuraEffect const *>(this), aurApp);
if (prevented) if (prevented)
return; return;
Unit * target = aurApp->GetTarget();
switch(GetAuraType()) switch(GetAuraType())
{ {
case SPELL_AURA_PERIODIC_DAMAGE: case SPELL_AURA_PERIODIC_DAMAGE:
@@ -23,6 +23,7 @@ class AuraEffect
uint64 GetCasterGUID() const { return GetBase()->GetCasterGUID(); } uint64 GetCasterGUID() const { return GetBase()->GetCasterGUID(); }
Aura * GetBase() const { return m_base; } Aura * GetBase() const { return m_base; }
void GetTargetList(std::list<Unit*> & targetList) const; void GetTargetList(std::list<Unit*> & targetList) const;
void GetApplicationList(std::list<AuraApplication*> & applicationList) const;
SpellEntry const * GetSpellProto() const { return m_spellProto; } SpellEntry const * GetSpellProto() const { return m_spellProto; }
uint32 GetId() const { return m_spellProto->Id; } uint32 GetId() const { return m_spellProto->Id; }
@@ -63,7 +64,7 @@ class AuraEffect
void SendTickImmune(Unit * target, Unit *caster) const; void SendTickImmune(Unit * target, Unit *caster) const;
void PeriodicTick(Unit * target, Unit * caster) const; void PeriodicTick(AuraApplication * aurApp, Unit * caster) const;
void PeriodicDummyTick(Unit * target, Unit * caster) const; void PeriodicDummyTick(Unit * target, Unit * caster) const;
Unit* GetTriggerTarget(Unit * target) const; Unit* GetTriggerTarget(Unit * target) const;
void TriggerSpell(Unit * target, Unit * caster) const; void TriggerSpell(Unit * target, Unit * caster) const;
+1 -1
View File
@@ -444,7 +444,7 @@ class AuraScript : public _SpellScript
Unit* GetCaster() const; Unit* GetCaster() const;
// returns object on which aura was casted, target for non-area auras, area aura source for area auras // returns object on which aura was casted, target for non-area auras, area aura source for area auras
WorldObject * GetOwner() const; WorldObject * GetOwner() const;
// returns owner if it's unit, NULL otherwise // returns owner if it's unit or unit derived object, NULL otherwise (only for persistent area auras NULL is returned)
Unit * GetUnitOwner() const; Unit * GetUnitOwner() const;
// returns owner if it's dynobj, NULL otherwise // returns owner if it's dynobj, NULL otherwise
DynamicObject * GetDynobjOwner() const; DynamicObject * GetDynobjOwner() const;
@@ -1508,9 +1508,8 @@ class spell_blood_council_shadow_prison : public SpellScriptLoader
void HandleDummyTick(AuraEffect const* aurEff, AuraApplication const* aurApp) void HandleDummyTick(AuraEffect const* aurEff, AuraApplication const* aurApp)
{ {
if (aurApp) if (aurApp->GetTarget()->isMoving())
if (aurApp->GetTarget()->isMoving()) aurApp->GetTarget()->CastSpell(aurApp->GetTarget(), SPELL_SHADOW_PRISON_DAMAGE, true, NULL, aurEff);
aurApp->GetTarget()->CastSpell(aurApp->GetTarget(), SPELL_SHADOW_PRISON_DAMAGE, true, NULL, aurEff);
} }
void Register() void Register()
@@ -473,9 +473,6 @@ class spell_blood_queen_frenzied_bloodthirst : public SpellScriptLoader
void OnRemove(AuraEffect const* /*aurEff*/, AuraApplication const* aurApp, AuraEffectHandleModes /*mode*/) void OnRemove(AuraEffect const* /*aurEff*/, AuraApplication const* aurApp, AuraEffectHandleModes /*mode*/)
{ {
if (!aurApp)
return;
Unit* target = aurApp->GetTarget(); Unit* target = aurApp->GetTarget();
if (aurApp->GetRemoveMode() == AURA_REMOVE_BY_EXPIRE) if (aurApp->GetRemoveMode() == AURA_REMOVE_BY_EXPIRE)
if (InstanceScript* instance = target->GetInstanceScript()) if (InstanceScript* instance = target->GetInstanceScript())
@@ -760,8 +760,7 @@ class spell_putricide_gaseous_bloat : public SpellScriptLoader
void HandleExtraEffect(AuraEffect const* /*aurEff*/, AuraApplication const* aurApp) void HandleExtraEffect(AuraEffect const* /*aurEff*/, AuraApplication const* aurApp)
{ {
if (aurApp->GetTarget()) aurApp->GetTarget()->RemoveAuraFromStack(GetSpellProto()->Id, aurApp->GetBase()->GetCasterGUID());
aurApp->GetTarget()->RemoveAuraFromStack(GetSpellProto()->Id, aurApp->GetBase()->GetCasterGUID());
} }
void Register() void Register()
@@ -712,7 +712,7 @@ class spell_rotface_unstable_ooze_explosion_suicide : public SpellScriptLoader
{ {
PreventDefaultAction(); PreventDefaultAction();
Unit* target = aurApp->GetTarget(); Unit* target = aurApp->GetTarget();
if (!target || target->GetTypeId() != TYPEID_UNIT) if (target->GetTypeId() != TYPEID_UNIT)
return; return;
target->ToCreature()->AI()->DoAction(EVENT_UNSTABLE_DESPAWN); target->ToCreature()->AI()->DoAction(EVENT_UNSTABLE_DESPAWN);
+24 -30
View File
@@ -106,13 +106,13 @@ public:
void HandleEffectPeriodic(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp) void HandleEffectPeriodic(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp)
{ {
if (Unit* pTarget = aurApp->GetTarget()) Unit* pTarget = aurApp->GetTarget();
if (Player* pPlayerTarget = pTarget->ToPlayer()) if (Player* pPlayerTarget = pTarget->ToPlayer())
if (pPlayerTarget->IsFalling()) if (pPlayerTarget->IsFalling())
{ {
pPlayerTarget->RemoveAurasDueToSpell(SPELL_PARACHUTE); pPlayerTarget->RemoveAurasDueToSpell(SPELL_PARACHUTE);
pPlayerTarget->CastSpell(pPlayerTarget, SPELL_PARACHUTE_BUFF, true); pPlayerTarget->CastSpell(pPlayerTarget, SPELL_PARACHUTE_BUFF, true);
} }
} }
void Register() void Register()
@@ -246,17 +246,17 @@ public:
void HandleEffectPeriodic(AuraEffect const * aurEff, AuraApplication const * aurApp) void HandleEffectPeriodic(AuraEffect const * aurEff, AuraApplication const * aurApp)
{ {
if (Unit* pTarget = aurApp->GetTarget()) Unit* pTarget = aurApp->GetTarget();
if (Unit* pCaster = GetCaster()) if (Unit* pCaster = GetCaster())
{ {
int32 lifeLeeched = pTarget->CountPctFromMaxHealth(aurEff->GetAmount()); int32 lifeLeeched = pTarget->CountPctFromMaxHealth(aurEff->GetAmount());
if (lifeLeeched < 250) if (lifeLeeched < 250)
lifeLeeched = 250; lifeLeeched = 250;
// Damage // Damage
pCaster->CastCustomSpell(pTarget, SPELL_LEECHING_SWARM_DMG, &lifeLeeched, 0, 0, false); pCaster->CastCustomSpell(pTarget, SPELL_LEECHING_SWARM_DMG, &lifeLeeched, 0, 0, false);
// Heal // Heal
pCaster->CastCustomSpell(pCaster, SPELL_LEECHING_SWARM_HEAL, &lifeLeeched, 0, 0, false); pCaster->CastCustomSpell(pCaster, SPELL_LEECHING_SWARM_HEAL, &lifeLeeched, 0, 0, false);
} }
} }
void Register() void Register()
@@ -408,8 +408,6 @@ class spell_creature_permanent_feign_death : public SpellScriptLoader
void HandleEffectApply(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp, AuraEffectHandleModes /*mode*/) void HandleEffectApply(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp, AuraEffectHandleModes /*mode*/)
{ {
Unit* pTarget = aurApp->GetTarget(); Unit* pTarget = aurApp->GetTarget();
if (!pTarget)
return;
pTarget->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD); pTarget->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
pTarget->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH); pTarget->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
@@ -528,20 +526,16 @@ class spell_gen_shroud_of_death : public SpellScriptLoader
void HandleEffectApply(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp, AuraEffectHandleModes /*mode*/) void HandleEffectApply(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp, AuraEffectHandleModes /*mode*/)
{ {
if (Unit* target = aurApp->GetTarget()) Unit* target = aurApp->GetTarget();
{ target->m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_GHOST);
target->m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_GHOST); target->m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_GHOST);
target->m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_GHOST);
}
} }
void HandleEffectRemove(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp, AuraEffectHandleModes /*mode*/) void HandleEffectRemove(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp, AuraEffectHandleModes /*mode*/)
{ {
if (Unit* target = aurApp->GetTarget()) Unit* target = aurApp->GetTarget();
{ target->m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
target->m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE); target->m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
target->m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
}
} }
void Register() void Register()
+15 -17
View File
@@ -361,29 +361,27 @@ public:
if (aurEff->GetAmount() > 0) if (aurEff->GetAmount() > 0)
return; return;
if (Unit* pTarget = aurApp->GetTarget()) uint32 spellId = SPELL_SNIPER_TRAINING_BUFF_R1 + GetId() - SPELL_SNIPER_TRAINING_R1;
Unit * pTarget = aurApp->GetTarget();
if (!pTarget->HasAura(spellId))
{ {
uint32 spellId = SPELL_SNIPER_TRAINING_BUFF_R1 + GetId() - SPELL_SNIPER_TRAINING_R1; SpellEntry const * triggeredSpellInfo = sSpellStore.LookupEntry(spellId);
if (!pTarget->HasAura(spellId)) Unit* triggerCaster = GetTriggeredSpellCaster(triggeredSpellInfo, GetCaster(), pTarget);
{ triggerCaster->CastSpell(pTarget, triggeredSpellInfo, true, 0, aurEff);
const SpellEntry* triggeredSpellInfo = sSpellStore.LookupEntry(spellId);
Unit* triggerCaster = GetTriggeredSpellCaster(triggeredSpellInfo, GetCaster(), pTarget);
triggerCaster->CastSpell(pTarget, triggeredSpellInfo, true, 0, aurEff);
}
} }
} }
void HandleUpdatePeriodic(AuraEffect * aurEff) void HandleUpdatePeriodic(AuraEffect * aurEff)
{ {
if (Unit* pTarget = GetUnitOwner()) Unit * pTarget = GetUnitOwner();
if (Player* pPlayerTarget = pTarget->ToPlayer()) if (Player* pPlayerTarget = pTarget->ToPlayer())
{ {
int32 baseAmount = aurEff->GetBaseAmount(); int32 baseAmount = aurEff->GetBaseAmount();
int32 amount = pPlayerTarget->isMoving() ? int32 amount = pPlayerTarget->isMoving() ?
pTarget->CalculateSpellDamage(pTarget, GetSpellProto(), aurEff->GetEffIndex(), &baseAmount) : pTarget->CalculateSpellDamage(pTarget, GetSpellProto(), aurEff->GetEffIndex(), &baseAmount) :
aurEff->GetAmount() - 1; aurEff->GetAmount() - 1;
aurEff->SetAmount(amount); aurEff->SetAmount(amount);
} }
} }
void Register() void Register()
+2 -4
View File
@@ -701,8 +701,7 @@ public:
void OnStackChange(AuraEffect const* /*aurEff*/, AuraApplication const* aurApp, AuraEffectHandleModes /*mode*/) void OnStackChange(AuraEffect const* /*aurEff*/, AuraApplication const* aurApp, AuraEffectHandleModes /*mode*/)
{ {
Unit* target = aurApp->GetTarget(); Unit* target = aurApp->GetTarget();
if (!target)
return;
switch (GetStackAmount()) switch (GetStackAmount())
{ {
case 1: case 1:
@@ -722,8 +721,7 @@ public:
void OnRemove(AuraEffect const* /*aurEff*/, AuraApplication const* aurApp, AuraEffectHandleModes /*mode*/) void OnRemove(AuraEffect const* /*aurEff*/, AuraApplication const* aurApp, AuraEffectHandleModes /*mode*/)
{ {
Unit* target = aurApp->GetTarget(); Unit* target = aurApp->GetTarget();
if (!target)
return;
if (aurApp->GetRemoveMode() == AURA_REMOVE_BY_STACK) if (aurApp->GetRemoveMode() == AURA_REMOVE_BY_STACK)
return; return;
target->RemoveAurasDueToSpell(SPELL_SHADOWMOURNE_VISUAL_LOW); target->RemoveAurasDueToSpell(SPELL_SHADOWMOURNE_VISUAL_LOW);
+4 -5
View File
@@ -110,16 +110,15 @@ public:
void HandleEffectApply(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp, AuraEffectHandleModes /*mode*/) void HandleEffectApply(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp, AuraEffectHandleModes /*mode*/)
{ {
Unit* pTarget = aurApp->GetTarget();
if (Unit* pCaster = GetCaster()) if (Unit* pCaster = GetCaster())
if (Unit* pTarget = aurApp->GetTarget()) pCaster->CastSpell(pTarget, PALADIN_SPELL_BLESSING_OF_SANCTUARY_BUFF, true);
pCaster->CastSpell(pTarget, PALADIN_SPELL_BLESSING_OF_SANCTUARY_BUFF, true);
} }
void HandleEffectRemove(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp, AuraEffectHandleModes /*mode*/) void HandleEffectRemove(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp, AuraEffectHandleModes /*mode*/)
{ {
if (GetCaster()) Unit* pTarget = aurApp->GetTarget();
if (Unit* pTarget = aurApp->GetTarget()) pTarget->RemoveAura(PALADIN_SPELL_BLESSING_OF_SANCTUARY_BUFF, GetCasterGUID());
pTarget->RemoveAura(PALADIN_SPELL_BLESSING_OF_SANCTUARY_BUFF, GetCasterGUID());
} }
void Register() void Register()
+8 -10
View File
@@ -111,20 +111,18 @@ public:
void HandleEffectPeriodic(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp) void HandleEffectPeriodic(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp)
{ {
if (Unit* pTarget = aurApp->GetTarget()) Unit* pTarget = aurApp->GetTarget();
Unit* pVictim = pTarget->getVictim();
if (pVictim && (pTarget->GetHealthPct() > pVictim->GetHealthPct()))
{ {
Unit* pVictim = pTarget->getVictim(); if (!pTarget->HasAura(ROGUE_SPELL_PREY_ON_THE_WEAK))
if (pVictim && (pTarget->GetHealthPct() > pVictim->GetHealthPct()))
{ {
if (!pTarget->HasAura(ROGUE_SPELL_PREY_ON_THE_WEAK)) int32 bp = SpellMgr::CalculateSpellEffectAmount(GetSpellProto(), 0);
{ pTarget->CastCustomSpell(pTarget, ROGUE_SPELL_PREY_ON_THE_WEAK, &bp, 0, 0, true);
int32 bp = SpellMgr::CalculateSpellEffectAmount(GetSpellProto(), 0);
pTarget->CastCustomSpell(pTarget, ROGUE_SPELL_PREY_ON_THE_WEAK, &bp, 0, 0, true);
}
} }
else
pTarget->RemoveAurasDueToSpell(ROGUE_SPELL_PREY_ON_THE_WEAK);
} }
else
pTarget->RemoveAurasDueToSpell(ROGUE_SPELL_PREY_ON_THE_WEAK);
} }
void Register() void Register()
+5 -5
View File
@@ -156,11 +156,11 @@ public:
void HandleEffectPeriodic(AuraEffect const * aurEff, AuraApplication const * aurApp) void HandleEffectPeriodic(AuraEffect const * aurEff, AuraApplication const * aurApp)
{ {
if (Unit* target = aurApp->GetTarget()) Unit* target = aurApp->GetTarget();
if (Unit *caster = aurEff->GetBase()->GetCaster()) if (Unit *caster = aurEff->GetBase()->GetCaster())
if (AuraEffect* aur = caster->GetDummyAuraEffect(SPELLFAMILY_SHAMAN, 2289, 0)) if (AuraEffect* aur = caster->GetDummyAuraEffect(SPELLFAMILY_SHAMAN, 2289, 0))
if (roll_chance_i(aur->GetBaseAmount())) if (roll_chance_i(aur->GetBaseAmount()))
target->CastSpell(target, SHAMAN_TOTEM_SPELL_EARTHEN_POWER, true, NULL, aurEff); target->CastSpell(target, SHAMAN_TOTEM_SPELL_EARTHEN_POWER, true, NULL, aurEff);
} }
void Register() void Register()