*Fix a crash bug of phase hunter script.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-01-19 10:50:31 -06:00
parent a07f3af045
commit c81b6bc7b6
@@ -791,8 +791,8 @@ struct TRINITY_DLL_DECL mob_phase_hunterAI : public ScriptedAI
mob_phase_hunterAI(Creature *c) : ScriptedAI(c) {Reset();} mob_phase_hunterAI(Creature *c) : ScriptedAI(c) {Reset();}
bool Weak; bool Weak;
bool Materialize; bool Materialize;
bool Drained; bool Drained;
int WeakPercent; int WeakPercent;
uint64 PlayerGUID; uint64 PlayerGUID;
@@ -804,8 +804,8 @@ struct TRINITY_DLL_DECL mob_phase_hunterAI : public ScriptedAI
void Reset() void Reset()
{ {
Weak = false; Weak = false;
Materialize = false; Materialize = false;
Drained = false; Drained = false;
WeakPercent = 25 + (rand()%16); // 25-40 WeakPercent = 25 + (rand()%16); // 25-40
PlayerGUID = 0; PlayerGUID = 0;
@@ -814,42 +814,44 @@ struct TRINITY_DLL_DECL mob_phase_hunterAI : public ScriptedAI
void Aggro(Unit *who) void Aggro(Unit *who)
{ {
PlayerGUID = who->GetGUID(); if(Player *player = who->GetCharmerOrOwnerPlayerOrPlayerItself())
PlayerGUID = player->GetGUID();
} }
void SpellHit(Unit *caster, const SpellEntry *spell) void SpellHit(Unit *caster, const SpellEntry *spell)
{ {
DoCast(m_creature, SPELL_DE_MATERIALIZE); DoCast(m_creature, SPELL_DE_MATERIALIZE);
} }
void UpdateAI(const uint32 diff) void UpdateAI(const uint32 diff)
{ {
if(!Materialize) if(!Materialize)
{ {
DoCast(m_creature, SPELL_MATERIALIZE); DoCast(m_creature, SPELL_MATERIALIZE);
Materialize = true; Materialize = true;
} }
if(m_creature->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED) || m_creature->hasUnitState(UNIT_STAT_ROOT)) // if the mob is rooted/slowed by spells eg.: Entangling Roots, Frost Nova, Hamstring, Crippling Poison, etc. => remove it if(m_creature->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED) || m_creature->hasUnitState(UNIT_STAT_ROOT)) // if the mob is rooted/slowed by spells eg.: Entangling Roots, Frost Nova, Hamstring, Crippling Poison, etc. => remove it
DoCast(m_creature, SPELL_PHASE_SLIP); DoCast(m_creature, SPELL_PHASE_SLIP);
if (!m_creature->SelectHostilTarget() || !m_creature->getVictim()) if (!m_creature->SelectHostilTarget() || !m_creature->getVictim())
return; return;
if(ManaBurnTimer < diff) // cast Mana Burn if(ManaBurnTimer < diff) // cast Mana Burn
{ {
if(m_creature->getVictim()->GetCreateMana() > 0) if(m_creature->getVictim()->GetCreateMana() > 0)
{ {
DoCast(m_creature->getVictim(), SPELL_MANA_BURN); DoCast(m_creature->getVictim(), SPELL_MANA_BURN);
ManaBurnTimer = 8000 + (rand()%10 * 1000); // 8-18 sec cd ManaBurnTimer = 8000 + (rand()%10 * 1000); // 8-18 sec cd
} }
}else ManaBurnTimer -= diff; }else ManaBurnTimer -= diff;
if(PlayerGUID) // start: support for quest 10190 if(PlayerGUID) // start: support for quest 10190
{ {
Unit* target = Unit::GetUnit((*m_creature), PlayerGUID); Unit* target = Unit::GetUnit((*m_creature), PlayerGUID);
if(target && !Weak && m_creature->GetHealth() < (m_creature->GetMaxHealth() / 100 * WeakPercent) && ((Player*)target)->GetQuestStatus(10190) == QUEST_STATUS_INCOMPLETE) if(target && !Weak && m_creature->GetHealth() < (m_creature->GetMaxHealth() / 100 * WeakPercent)
&& ((Player*)target)->GetQuestStatus(10190) == QUEST_STATUS_INCOMPLETE)
{ {
DoTextEmote(EMOTE_WEAK, 0); DoTextEmote(EMOTE_WEAK, 0);
Weak = true; Weak = true;
@@ -861,26 +863,26 @@ struct TRINITY_DLL_DECL mob_phase_hunterAI : public ScriptedAI
Health = m_creature->GetHealth(); // get the normal mob's data Health = m_creature->GetHealth(); // get the normal mob's data
Level = m_creature->getLevel(); Level = m_creature->getLevel();
m_creature->AttackStop(); // delete the normal mob m_creature->AttackStop(); // delete the normal mob
m_creature->DealDamage(m_creature, m_creature->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); m_creature->DealDamage(m_creature, m_creature->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
m_creature->RemoveCorpse(); m_creature->RemoveCorpse();
Creature* DrainedPhaseHunter = NULL; Creature* DrainedPhaseHunter = NULL;
if(!DrainedPhaseHunter) if(!DrainedPhaseHunter)
DrainedPhaseHunter = m_creature->SummonCreature(SUMMONED_MOB, m_creature->GetPositionX(), m_creature->GetPositionY(), m_creature->GetPositionZ(), m_creature->GetOrientation(), TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 60000); // summon the mob DrainedPhaseHunter = m_creature->SummonCreature(SUMMONED_MOB, m_creature->GetPositionX(), m_creature->GetPositionY(), m_creature->GetPositionZ(), m_creature->GetOrientation(), TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 60000); // summon the mob
if(DrainedPhaseHunter) if(DrainedPhaseHunter)
{ {
DrainedPhaseHunter->SetLevel(Level); // set the summoned mob's data DrainedPhaseHunter->SetLevel(Level); // set the summoned mob's data
DrainedPhaseHunter->SetHealth(Health); DrainedPhaseHunter->SetHealth(Health);
DrainedPhaseHunter->AddThreat(target, 10000.0f); DrainedPhaseHunter->AddThreat(target, 10000.0f);
DrainedPhaseHunter->AI()->AttackStart(target); DrainedPhaseHunter->AI()->AttackStart(target);
} }
} }
}// end: support for quest 10190 }// end: support for quest 10190
DoMeleeAttackIfReady(); DoMeleeAttackIfReady();
} }
}; };