aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/AI/SmartScripts
diff options
context:
space:
mode:
authorjackpoz <giacomopoz@gmail.com>2014-04-19 21:48:22 +0200
committerjackpoz <giacomopoz@gmail.com>2014-04-19 21:48:22 +0200
commit8ca63717932ae6db48d74e866e8d379c4f5a5920 (patch)
tree0ebd6fa6ded2af7c4becaae1bb372be427235c6d /src/server/game/AI/SmartScripts
parentfac3f445b12ee9ab484a2c229cdd49ca68120cea (diff)
Core/Misc: Ensure GetVictim() returns a valid reference when expected
Add a new method EnsureVictim() which asserts a valid not NULL reference will be returned to the caller. Use this whenever the GetVictim() would be dereferenced .
Diffstat (limited to 'src/server/game/AI/SmartScripts')
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.cpp2
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.cpp10
2 files changed, 6 insertions, 6 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp
index 23dea877776..3b055cabbfa 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.cpp
+++ b/src/server/game/AI/SmartScripts/SmartAI.cpp
@@ -499,7 +499,7 @@ bool SmartAI::AssistPlayerInCombat(Unit* who)
return false;
//not a player
- if (!who->GetVictim()->GetCharmerOrOwnerPlayerOrPlayerItself())
+ if (!who->EnsureVictim()->GetCharmerOrOwnerPlayerOrPlayerItself())
return false;
//never attack friendly
diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp
index 231f3808aa9..467a35967c2 100644
--- a/src/server/game/AI/SmartScripts/SmartScript.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScript.cpp
@@ -2691,9 +2691,9 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
}
case SMART_EVENT_TARGET_HEALTH_PCT:
{
- if (!me || !me->IsInCombat() || !me->GetVictim() || !me->GetVictim()->GetMaxHealth())
+ if (!me || !me->IsInCombat() || !me->GetVictim() || !me->EnsureVictim()->GetMaxHealth())
return;
- uint32 perc = (uint32)me->GetVictim()->GetHealthPct();
+ uint32 perc = (uint32)me->EnsureVictim()->GetHealthPct();
if (perc > e.event.minMaxRepeat.max || perc < e.event.minMaxRepeat.min)
return;
ProcessTimedAction(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax, me->GetVictim());
@@ -2711,9 +2711,9 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
}
case SMART_EVENT_TARGET_MANA_PCT:
{
- if (!me || !me->IsInCombat() || !me->GetVictim() || !me->GetVictim()->GetMaxPower(POWER_MANA))
+ if (!me || !me->IsInCombat() || !me->GetVictim() || !me->EnsureVictim()->GetMaxPower(POWER_MANA))
return;
- uint32 perc = uint32(100.0f * me->GetVictim()->GetPower(POWER_MANA) / me->GetVictim()->GetMaxPower(POWER_MANA));
+ uint32 perc = uint32(100.0f * me->EnsureVictim()->GetPower(POWER_MANA) / me->EnsureVictim()->GetMaxPower(POWER_MANA));
if (perc > e.event.minMaxRepeat.max || perc < e.event.minMaxRepeat.min)
return;
ProcessTimedAction(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax, me->GetVictim());
@@ -2793,7 +2793,7 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
{
if (!me || !me->GetVictim())
return;
- uint32 count = me->GetVictim()->GetAuraCount(e.event.aura.spell);
+ uint32 count = me->EnsureVictim()->GetAuraCount(e.event.aura.spell);
if (count < e.event.aura.count)
return;
ProcessTimedAction(e, e.event.aura.repeatMin, e.event.aura.repeatMax);