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 amount;
@@ -1057,13 +1068,13 @@ void AuraEffect::Update(uint32 diff, Unit * caster)
m_periodicTimer += m_amplitude - diff;
UpdatePeriodic(caster);
UnitList effectTargets;
GetTargetList(effectTargets);
std::list<AuraApplication*> effectApplications;
GetApplicationList(effectApplications);
// tick on targets of effects
if (!caster || !caster->hasUnitState(UNIT_STAT_ISOLATED))
{
for (UnitList::iterator targetItr = effectTargets.begin(); targetItr != effectTargets.end(); ++targetItr)
PeriodicTick(*targetItr, caster);
for (std::list<AuraApplication*>::iterator apptItr = effectApplications.begin(); apptItr != effectApplications.end(); ++apptItr)
PeriodicTick(*apptItr, caster);
}
}
}
@@ -1224,12 +1235,14 @@ void AuraEffect::SendTickImmune(Unit * target, Unit *caster) const
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)
return;
Unit * target = aurApp->GetTarget();
switch(GetAuraType())
{
case SPELL_AURA_PERIODIC_DAMAGE:
@@ -23,6 +23,7 @@ class AuraEffect
uint64 GetCasterGUID() const { return GetBase()->GetCasterGUID(); }
Aura * GetBase() const { return m_base; }
void GetTargetList(std::list<Unit*> & targetList) const;
void GetApplicationList(std::list<AuraApplication*> & applicationList) const;
SpellEntry const * GetSpellProto() const { return m_spellProto; }
uint32 GetId() const { return m_spellProto->Id; }
@@ -63,7 +64,7 @@ class AuraEffect
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;
Unit* GetTriggerTarget(Unit * target) const;
void TriggerSpell(Unit * target, Unit * caster) const;
+1 -1
View File
@@ -444,7 +444,7 @@ class AuraScript : public _SpellScript
Unit* GetCaster() const;
// returns object on which aura was casted, target for non-area auras, area aura source for area auras
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;
// returns owner if it's dynobj, NULL otherwise
DynamicObject * GetDynobjOwner() const;
@@ -1508,9 +1508,8 @@ class spell_blood_council_shadow_prison : public SpellScriptLoader
void HandleDummyTick(AuraEffect const* aurEff, AuraApplication const* aurApp)
{
if (aurApp)
if (aurApp->GetTarget()->isMoving())
aurApp->GetTarget()->CastSpell(aurApp->GetTarget(), SPELL_SHADOW_PRISON_DAMAGE, true, NULL, aurEff);
if (aurApp->GetTarget()->isMoving())
aurApp->GetTarget()->CastSpell(aurApp->GetTarget(), SPELL_SHADOW_PRISON_DAMAGE, true, NULL, aurEff);
}
void Register()
@@ -473,9 +473,6 @@ class spell_blood_queen_frenzied_bloodthirst : public SpellScriptLoader
void OnRemove(AuraEffect const* /*aurEff*/, AuraApplication const* aurApp, AuraEffectHandleModes /*mode*/)
{
if (!aurApp)
return;
Unit* target = aurApp->GetTarget();
if (aurApp->GetRemoveMode() == AURA_REMOVE_BY_EXPIRE)
if (InstanceScript* instance = target->GetInstanceScript())
@@ -760,8 +760,7 @@ class spell_putricide_gaseous_bloat : public SpellScriptLoader
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()
@@ -712,7 +712,7 @@ class spell_rotface_unstable_ooze_explosion_suicide : public SpellScriptLoader
{
PreventDefaultAction();
Unit* target = aurApp->GetTarget();
if (!target || target->GetTypeId() != TYPEID_UNIT)
if (target->GetTypeId() != TYPEID_UNIT)
return;
target->ToCreature()->AI()->DoAction(EVENT_UNSTABLE_DESPAWN);
+24 -30
View File
@@ -106,13 +106,13 @@ public:
void HandleEffectPeriodic(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp)
{
if (Unit* pTarget = aurApp->GetTarget())
if (Player* pPlayerTarget = pTarget->ToPlayer())
if (pPlayerTarget->IsFalling())
{
pPlayerTarget->RemoveAurasDueToSpell(SPELL_PARACHUTE);
pPlayerTarget->CastSpell(pPlayerTarget, SPELL_PARACHUTE_BUFF, true);
}
Unit* pTarget = aurApp->GetTarget();
if (Player* pPlayerTarget = pTarget->ToPlayer())
if (pPlayerTarget->IsFalling())
{
pPlayerTarget->RemoveAurasDueToSpell(SPELL_PARACHUTE);
pPlayerTarget->CastSpell(pPlayerTarget, SPELL_PARACHUTE_BUFF, true);
}
}
void Register()
@@ -246,17 +246,17 @@ public:
void HandleEffectPeriodic(AuraEffect const * aurEff, AuraApplication const * aurApp)
{
if (Unit* pTarget = aurApp->GetTarget())
if (Unit* pCaster = GetCaster())
{
int32 lifeLeeched = pTarget->CountPctFromMaxHealth(aurEff->GetAmount());
if (lifeLeeched < 250)
lifeLeeched = 250;
// Damage
pCaster->CastCustomSpell(pTarget, SPELL_LEECHING_SWARM_DMG, &lifeLeeched, 0, 0, false);
// Heal
pCaster->CastCustomSpell(pCaster, SPELL_LEECHING_SWARM_HEAL, &lifeLeeched, 0, 0, false);
}
Unit* pTarget = aurApp->GetTarget();
if (Unit* pCaster = GetCaster())
{
int32 lifeLeeched = pTarget->CountPctFromMaxHealth(aurEff->GetAmount());
if (lifeLeeched < 250)
lifeLeeched = 250;
// Damage
pCaster->CastCustomSpell(pTarget, SPELL_LEECHING_SWARM_DMG, &lifeLeeched, 0, 0, false);
// Heal
pCaster->CastCustomSpell(pCaster, SPELL_LEECHING_SWARM_HEAL, &lifeLeeched, 0, 0, false);
}
}
void Register()
@@ -408,8 +408,6 @@ class spell_creature_permanent_feign_death : public SpellScriptLoader
void HandleEffectApply(AuraEffect const * /*aurEff*/, AuraApplication const * aurApp, AuraEffectHandleModes /*mode*/)
{
Unit* pTarget = aurApp->GetTarget();
if (!pTarget)
return;
pTarget->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
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*/)
{
if (Unit* target = aurApp->GetTarget())
{
target->m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_GHOST);
target->m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_GHOST);
}
Unit* target = aurApp->GetTarget();
target->m_serverSideVisibility.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*/)
{
if (Unit* target = aurApp->GetTarget())
{
target->m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
target->m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
}
Unit* target = aurApp->GetTarget();
target->m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
target->m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
}
void Register()
+15 -17
View File
@@ -361,29 +361,27 @@ public:
if (aurEff->GetAmount() > 0)
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;
if (!pTarget->HasAura(spellId))
{
const SpellEntry* triggeredSpellInfo = sSpellStore.LookupEntry(spellId);
Unit* triggerCaster = GetTriggeredSpellCaster(triggeredSpellInfo, GetCaster(), pTarget);
triggerCaster->CastSpell(pTarget, triggeredSpellInfo, true, 0, aurEff);
}
SpellEntry const * triggeredSpellInfo = sSpellStore.LookupEntry(spellId);
Unit* triggerCaster = GetTriggeredSpellCaster(triggeredSpellInfo, GetCaster(), pTarget);
triggerCaster->CastSpell(pTarget, triggeredSpellInfo, true, 0, aurEff);
}
}
void HandleUpdatePeriodic(AuraEffect * aurEff)
{
if (Unit* pTarget = GetUnitOwner())
if (Player* pPlayerTarget = pTarget->ToPlayer())
{
int32 baseAmount = aurEff->GetBaseAmount();
int32 amount = pPlayerTarget->isMoving() ?
pTarget->CalculateSpellDamage(pTarget, GetSpellProto(), aurEff->GetEffIndex(), &baseAmount) :
aurEff->GetAmount() - 1;
aurEff->SetAmount(amount);
}
Unit * pTarget = GetUnitOwner();
if (Player* pPlayerTarget = pTarget->ToPlayer())
{
int32 baseAmount = aurEff->GetBaseAmount();
int32 amount = pPlayerTarget->isMoving() ?
pTarget->CalculateSpellDamage(pTarget, GetSpellProto(), aurEff->GetEffIndex(), &baseAmount) :
aurEff->GetAmount() - 1;
aurEff->SetAmount(amount);
}
}
void Register()
+2 -4
View File
@@ -701,8 +701,7 @@ public:
void OnStackChange(AuraEffect const* /*aurEff*/, AuraApplication const* aurApp, AuraEffectHandleModes /*mode*/)
{
Unit* target = aurApp->GetTarget();
if (!target)
return;
switch (GetStackAmount())
{
case 1:
@@ -722,8 +721,7 @@ public:
void OnRemove(AuraEffect const* /*aurEff*/, AuraApplication const* aurApp, AuraEffectHandleModes /*mode*/)
{
Unit* target = aurApp->GetTarget();
if (!target)
return;
if (aurApp->GetRemoveMode() == AURA_REMOVE_BY_STACK)
return;
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*/)
{
Unit* pTarget = aurApp->GetTarget();
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*/)
{
if (GetCaster())
if (Unit* pTarget = aurApp->GetTarget())
pTarget->RemoveAura(PALADIN_SPELL_BLESSING_OF_SANCTUARY_BUFF, GetCasterGUID());
Unit* pTarget = aurApp->GetTarget();
pTarget->RemoveAura(PALADIN_SPELL_BLESSING_OF_SANCTUARY_BUFF, GetCasterGUID());
}
void Register()
+8 -10
View File
@@ -111,20 +111,18 @@ public:
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 (pVictim && (pTarget->GetHealthPct() > pVictim->GetHealthPct()))
if (!pTarget->HasAura(ROGUE_SPELL_PREY_ON_THE_WEAK))
{
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()
+5 -5
View File
@@ -156,11 +156,11 @@ public:
void HandleEffectPeriodic(AuraEffect const * aurEff, AuraApplication const * aurApp)
{
if (Unit* target = aurApp->GetTarget())
if (Unit *caster = aurEff->GetBase()->GetCaster())
if (AuraEffect* aur = caster->GetDummyAuraEffect(SPELLFAMILY_SHAMAN, 2289, 0))
if (roll_chance_i(aur->GetBaseAmount()))
target->CastSpell(target, SHAMAN_TOTEM_SPELL_EARTHEN_POWER, true, NULL, aurEff);
Unit* target = aurApp->GetTarget();
if (Unit *caster = aurEff->GetBase()->GetCaster())
if (AuraEffect* aur = caster->GetDummyAuraEffect(SPELLFAMILY_SHAMAN, 2289, 0))
if (roll_chance_i(aur->GetBaseAmount()))
target->CastSpell(target, SHAMAN_TOTEM_SPELL_EARTHEN_POWER, true, NULL, aurEff);
}
void Register()