Scripts/Zalazane's Fall: Some cleanup and general code improvement

This commit is contained in:
kaelima
2012-02-24 22:56:41 +01:00
parent f1f469481d
commit c7ddb428b3
+48 -37
View File
@@ -170,7 +170,7 @@ enum Points
class npc_tiger_matriarch_credit : public CreatureScript class npc_tiger_matriarch_credit : public CreatureScript
{ {
public: public:
npc_tiger_matriarch_credit() : CreatureScript("npc_tiger_matriarch_credit"){} npc_tiger_matriarch_credit() : CreatureScript("npc_tiger_matriarch_credit") { }
struct npc_tiger_matriarch_creditAI : public Scripted_NoMovementAI struct npc_tiger_matriarch_creditAI : public Scripted_NoMovementAI
{ {
@@ -179,7 +179,7 @@ class npc_tiger_matriarch_credit : public CreatureScript
events.ScheduleEvent(EVENT_CHECK_SUMMON_AURA, 2000); events.ScheduleEvent(EVENT_CHECK_SUMMON_AURA, 2000);
} }
void UpdateAI(const uint32 diff) void UpdateAI(uint32 const diff)
{ {
events.Update(diff); events.Update(diff);
@@ -223,27 +223,32 @@ class npc_tiger_matriarch_credit : public CreatureScript
class npc_tiger_matriarch : public CreatureScript class npc_tiger_matriarch : public CreatureScript
{ {
public: public:
npc_tiger_matriarch() : CreatureScript("npc_tiger_matriarch"){} npc_tiger_matriarch() : CreatureScript("npc_tiger_matriarch") {}
struct npc_tiger_matriarchAI : public ScriptedAI struct npc_tiger_matriarchAI : public ScriptedAI
{ {
npc_tiger_matriarchAI(Creature* creature) : ScriptedAI(creature), npc_tiger_matriarchAI(Creature* creature) : ScriptedAI(creature),
_tiger(NULL) _tigerGuid(0)
{ {
} }
void EnterCombat(Unit* /*target*/)
{
_events.Reset();
_events.ScheduleEvent(EVENT_POUNCE, 100);
_events.ScheduleEvent(EVENT_NOSUMMON, 50000);
}
void IsSummonedBy(Unit* summoner) void IsSummonedBy(Unit* summoner)
{ {
if (summoner->GetTypeId() != TYPEID_PLAYER) if (summoner->GetTypeId() != TYPEID_PLAYER && summoner->GetVehicle())
return; return;
_tiger = summoner->GetVehicle()->GetBase(); _tigerGuid = summoner->GetVehicle()->GetBase()->GetGUID();
if (_tiger) if (Unit* tiger = ObjectAccessor::GetUnit(*me, _tigerGuid))
{ {
me->AddThreat(_tiger, 500000.0f); me->AddThreat(tiger, 500000.0f);
DoCast(me, SPELL_FURIOUS_BITE); DoCast(me, SPELL_FURIOUS_BITE);
events.ScheduleEvent(EVENT_POUNCE, 100);
events.ScheduleEvent(EVENT_NOSUMMON, 50000);
} }
} }
@@ -291,24 +296,27 @@ class npc_tiger_matriarch : public CreatureScript
if (!UpdateVictim()) if (!UpdateVictim())
return; return;
if (!_tiger) if (!_tigerGuid)
return; return;
events.Update(diff); _events.Update(diff);
while (uint32 eventId = events.ExecuteEvent()) while (uint32 eventId = _events.ExecuteEvent())
{ {
switch (eventId) switch (eventId)
{ {
case EVENT_POUNCE: case EVENT_POUNCE:
DoCastVictim(SPELL_POUNCE); DoCastVictim(SPELL_POUNCE);
events.ScheduleEvent(EVENT_POUNCE, 30000); _events.ScheduleEvent(EVENT_POUNCE, 30000);
break; break;
case EVENT_NOSUMMON: // Reapply SPELL_NO_SUMMON_AURA case EVENT_NOSUMMON: // Reapply SPELL_NO_SUMMON_AURA
if (_tiger && _tiger->isSummon()) if (Unit* tiger = ObjectAccessor::GetUnit(*me, _tigerGuid))
if (Unit* vehSummoner = _tiger->ToTempSummon()->GetSummoner()) {
if (tiger->isSummon())
if (Unit* vehSummoner = tiger->ToTempSummon()->GetSummoner())
me->AddAura(SPELL_NO_SUMMON_AURA, vehSummoner); me->AddAura(SPELL_NO_SUMMON_AURA, vehSummoner);
events.ScheduleEvent(EVENT_NOSUMMON, 50000); }
_events.ScheduleEvent(EVENT_NOSUMMON, 50000);
break; break;
default: default:
break; break;
@@ -319,8 +327,8 @@ class npc_tiger_matriarch : public CreatureScript
} }
private: private:
EventMap events; EventMap _events;
Unit* _tiger; uint64 _tigerGuid;
}; };
CreatureAI* GetAI(Creature* creature) const CreatureAI* GetAI(Creature* creature) const
@@ -345,26 +353,32 @@ class npc_troll_volunteer : public CreatureScript
{ {
npc_troll_volunteerAI(Creature* creature) : ScriptedAI(creature) npc_troll_volunteerAI(Creature* creature) : ScriptedAI(creature)
{ {
Reset(); }
Player* player = me->GetOwner()->ToPlayer();
switch (urand(1, 4)) void InitializeAI()
{ {
case 1: if (me->isDead() || !me->GetOwner())
return;
Reset();
switch (urand(0, 3))
{
case 0:
_mountModel = 6471; _mountModel = 6471;
break; break;
case 2: case 1:
_mountModel = 6473; _mountModel = 6473;
break; break;
case 3: case 2:
_mountModel = 6469; _mountModel = 6469;
break; break;
case 4: default:
_mountModel = 6472; _mountModel = 6472;
break; break;
} }
me->SetDisplayId(trollmodel[urand(0, 39)]); me->SetDisplayId(trollmodel[urand(0, 39)]);
if (player) if (Player* player = me->GetOwner()->ToPlayer())
me->GetMotionMaster()->MoveFollow(player, 5.0f, float(rand_norm() + 1.0f) * M_PI / 3.0f * 4.0f); me->GetMotionMaster()->MoveFollow(player, 5.0f, float(rand_norm() + 1.0f) * M_PI / 3.0f * 4.0f);
} }
@@ -417,6 +431,8 @@ class npc_troll_volunteer : public CreatureScript
} }
}; };
typedef npc_troll_volunteer::npc_troll_volunteerAI VolunteerAI;
class spell_mount_check : public SpellScriptLoader class spell_mount_check : public SpellScriptLoader
{ {
public: public:
@@ -442,9 +458,8 @@ class spell_mount_check : public SpellScriptLoader
if (owner->IsMounted() && !target->IsMounted()) if (owner->IsMounted() && !target->IsMounted())
{ {
if (Creature* volunteer = target->ToCreature()) if (VolunteerAI* volunteerAI = CAST_AI(VolunteerAI, target->GetAI()))
if (uint32 mountid = CAST_AI(npc_troll_volunteer::npc_troll_volunteerAI, volunteer->AI())->GetMountId()) target->Mount(volunteerAI->GetMountId());
target->Mount(mountid);
} }
else if (!owner->IsMounted() && target->IsMounted()) else if (!owner->IsMounted() && target->IsMounted())
target->Dismount(); target->Dismount();
@@ -493,7 +508,7 @@ class spell_voljin_war_drums : public SpellScriptLoader
else if (target->GetEntry() == NPC_CITIZEN_2) else if (target->GetEntry() == NPC_CITIZEN_2)
motivate = SPELL_MOTIVATE_2; motivate = SPELL_MOTIVATE_2;
if (motivate) if (motivate)
caster->CastSpell(target, motivate, true, NULL, NULL, caster->GetGUID()); caster->CastSpell(target, motivate, false);
} }
} }
@@ -542,13 +557,9 @@ class spell_voodoo : public SpellScriptLoader
void HandleDummy(SpellEffIndex /*effIndex*/) void HandleDummy(SpellEffIndex /*effIndex*/)
{ {
Unit* caster = GetCaster(); uint32 spellid = RAND(SPELL_BREW, SPELL_GHOSTLY, RAND(SPELL_HEX1, SPELL_HEX2, SPELL_HEX3), SPELL_GROW, SPELL_LAUNCH);
if (Unit* target = GetHitUnit()) if (Unit* target = GetHitUnit())
{ GetCaster()->CastSpell(target, spellid, false);
caster->CastSpell(target, RAND(SPELL_BREW, SPELL_GHOSTLY,
RAND(SPELL_HEX1, SPELL_HEX2, SPELL_HEX3),
SPELL_GROW, SPELL_LAUNCH), false);
}
} }
void Register() void Register()