Skip to content

Commit

Permalink
Pet/Misc: Improve Egbert's AI
Browse files Browse the repository at this point in the history
(cherry picked from commit 2322ef3)
  • Loading branch information
Kittnz authored and Shauren committed Apr 5, 2016
1 parent 0654b3b commit a6a8b5b
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/server/scripts/World/npcs_special.cpp
Expand Up @@ -39,6 +39,7 @@ npc_shadowfiend 100% restore 5% of owner's mana when shadowfiend die f
npc_locksmith 75% list of keys needs to be confirmed
npc_firework 100% NPC's summoned by rockets and rocket clusters, for making them cast visual
npc_train_wrecker 100% Wind-Up Train Wrecker that kills train set
npc_egbert 100% Egbert run's around
EndContentData */

#include "ScriptMgr.h"
Expand Down Expand Up @@ -2515,18 +2516,19 @@ class npc_train_wrecker : public CreatureScript

enum EgbertMisc
{
EVENT_MOVE_POS = 1,
EVENT_RETURN = 2
SPELL_EGBERT = 40670,
SPELL_EGBERT2 = 40669,
EVENT_RETURN = 3,
};

class npc_egbert : public CreatureScript
{
public:
npc_egbert() : CreatureScript("npc_egbert") {}

struct npc_egbertAI : public PetAI
struct npc_egbertAI : public NullCreatureAI
{
npc_egbertAI(Creature* creature) : PetAI(creature)
npc_egbertAI(Creature* creature) : NullCreatureAI(creature)
{
if (Unit* owner = me->GetCharmerOrOwner())
if (owner->GetMap()->GetEntry()->ExpansionID > 1)
Expand All @@ -2536,29 +2538,41 @@ class npc_egbert : public CreatureScript
void Reset() override
{
_events.Reset();
_events.ScheduleEvent(EVENT_MOVE_POS, urandms(1, 20));
if (Unit* owner = me->GetCharmerOrOwner())
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, me->GetFollowAngle());
me->CastSpell(me, SPELL_EGBERT);
}

void EnterEvadeMode(EvadeReason why) override
{
if (!_EnterEvadeMode(why))
return;

Reset();
}

void UpdateAI(uint32 diff) override
{
_events.Update(diff);

if (Unit* owner = me->GetCharmerOrOwner())
{
if (!me->IsWithinDist(owner, 40.f))
{
me->RemoveAura(SPELL_EGBERT2);
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, me->GetFollowAngle());
}
}

if (me->HasAura(SPELL_EGBERT2))
_events.ScheduleEvent(EVENT_RETURN, urandms(5, 20));

while (uint32 eventId = _events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_MOVE_POS:
if (Unit* owner = me->GetCharmerOrOwner())
{
me->GetMotionMaster()->Clear();
me->GetMotionMaster()->MovePoint(0, owner->GetPositionX() + frand(-30.0f, 30.0f), owner->GetPositionY() + frand(-30.0f, 30.0f), owner->GetPositionZ());
}
_events.ScheduleEvent(EVENT_RETURN, urandms(3, 4));
break;
case EVENT_RETURN:
if (Unit* owner = me->GetCharmerOrOwner())
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, me->GetFollowAngle());
_events.ScheduleEvent(EVENT_MOVE_POS, urandms(1, 20));
me->RemoveAura(SPELL_EGBERT2);
break;
default:
break;
Expand Down

0 comments on commit a6a8b5b

Please sign in to comment.