* Example on AI script conversion (and minor correction in CreatureScript).

--HG--
branch : trunk
This commit is contained in:
XTZGZoReX
2010-08-06 20:42:42 +02:00
parent 23c434cfd8
commit 731eaf72cb
3 changed files with 127 additions and 121 deletions

View File

@@ -719,7 +719,7 @@ CreatureAI* ScriptMgr::GetCreatureAI(Creature* creature)
ASSERT(creature);
GET_SCRIPT_RET(CreatureScript, creature->GetScriptId(), tmpscript, NULL);
return tmpscript->OnGetAI();
return tmpscript->OnGetAI(creature);
}
void ScriptMgr::OnCreatureUpdate(Creature* creature, uint32 diff)

View File

@@ -487,7 +487,7 @@ class CreatureScript : public ScriptObject, public UpdatableScript<Creature>
virtual uint32 OnDialogStatus(Player* player, Creature* creature) { return 0; }
// Called when a CreatureAI object is needed for the creature.
virtual CreatureAI* OnGetAI() { return NULL; }
virtual CreatureAI* OnGetAI(Creature* creature) const { return NULL; }
};
class GameObjectScript : public ScriptObject, public UpdatableScript<GameObject>

View File

@@ -47,135 +47,141 @@ enum Creatures
NPC_WEST_FROSTWOLF_WARMASTER = 14777
};
struct mob_av_marshal_or_warmasterAI : public ScriptedAI
class mob_av_marshal_or_warmaster : public CreatureScript
{
mob_av_marshal_or_warmasterAI(Creature *c) : ScriptedAI(c) {}
public:
uint32 uiChargeTimer;
uint32 uiCleaveTimer;
uint32 uiDemoralizingShoutTimer;
uint32 uiWhirlwind1Timer;
uint32 uiWhirlwind2Timer;
uint32 uiEnrageTimer;
uint32 uiResetTimer;
bool bHasAura;
void Reset()
{
uiChargeTimer = urand(2*IN_MILLISECONDS,12*IN_MILLISECONDS);
uiCleaveTimer = urand(1*IN_MILLISECONDS,11*IN_MILLISECONDS);
uiDemoralizingShoutTimer = urand(2*IN_MILLISECONDS,2*IN_MILLISECONDS);
uiWhirlwind1Timer = urand(1*IN_MILLISECONDS,12*IN_MILLISECONDS);
uiWhirlwind2Timer = urand(5*IN_MILLISECONDS,20*IN_MILLISECONDS);
uiEnrageTimer = urand(5*IN_MILLISECONDS,20*IN_MILLISECONDS);
uiResetTimer = 5*IN_MILLISECONDS;
bHasAura = false;
}
void JustRespawned()
{
Reset();
}
void UpdateAI(const uint32 diff)
{
if (!bHasAura)
mob_av_marshal_or_warmaster()
: CreatureScript("mob_av_marshal_or_warmaster")
{
switch(me->GetEntry())
{
case NPC_NORTH_MARSHAL:
DoCast(me,SPELL_NORTH_MARSHAL);
break;
case NPC_SOUTH_MARSHAL:
DoCast(me,SPELL_SOUTH_MARSHAL);
break;
case NPC_STONEHEARTH_MARSHAL:
DoCast(me,SPELL_STONEHEARTH_MARSHAL);
break;
case NPC_ICEWING_MARSHAL:
DoCast(me,SPELL_ICEWING_MARSHAL);
break;
case NPC_EAST_FROSTWOLF_WARMASTER:
DoCast(me,SPELL_EAST_FROSTWOLF_WARMASTER);
break;
case NPC_WEST_FROSTWOLF_WARMASTER:
DoCast(me,SPELL_WEST_FROSTWOLF_WARMASTER);
break;
case NPC_ICEBLOOD_WARMASTER:
DoCast(me,SPELL_ICEBLOOD_WARMASTER);
break;
case NPC_TOWER_POINT_WARMASTER:
DoCast(me,SPELL_TOWER_POINT_WARMASTER);
break;
}
bHasAura = true;
}
if (!UpdateVictim())
return;
if (uiChargeTimer <= diff)
struct mob_av_marshal_or_warmasterAI : public ScriptedAI
{
DoCast(me->getVictim(), SPELL_CHARGE);
uiChargeTimer = urand(10*IN_MILLISECONDS,25*IN_MILLISECONDS);
} else uiChargeTimer -= diff;
mob_av_marshal_or_warmasterAI(Creature *c) : ScriptedAI(c) {}
if (uiCleaveTimer <= diff)
uint32 uiChargeTimer;
uint32 uiCleaveTimer;
uint32 uiDemoralizingShoutTimer;
uint32 uiWhirlwind1Timer;
uint32 uiWhirlwind2Timer;
uint32 uiEnrageTimer;
uint32 uiResetTimer;
bool bHasAura;
void Reset()
{
uiChargeTimer = urand(2*IN_MILLISECONDS,12*IN_MILLISECONDS);
uiCleaveTimer = urand(1*IN_MILLISECONDS,11*IN_MILLISECONDS);
uiDemoralizingShoutTimer = urand(2*IN_MILLISECONDS,2*IN_MILLISECONDS);
uiWhirlwind1Timer = urand(1*IN_MILLISECONDS,12*IN_MILLISECONDS);
uiWhirlwind2Timer = urand(5*IN_MILLISECONDS,20*IN_MILLISECONDS);
uiEnrageTimer = urand(5*IN_MILLISECONDS,20*IN_MILLISECONDS);
uiResetTimer = 5*IN_MILLISECONDS;
bHasAura = false;
}
void JustRespawned()
{
Reset();
}
void UpdateAI(const uint32 diff)
{
if (!bHasAura)
{
switch(me->GetEntry())
{
case NPC_NORTH_MARSHAL:
DoCast(me,SPELL_NORTH_MARSHAL);
break;
case NPC_SOUTH_MARSHAL:
DoCast(me,SPELL_SOUTH_MARSHAL);
break;
case NPC_STONEHEARTH_MARSHAL:
DoCast(me,SPELL_STONEHEARTH_MARSHAL);
break;
case NPC_ICEWING_MARSHAL:
DoCast(me,SPELL_ICEWING_MARSHAL);
break;
case NPC_EAST_FROSTWOLF_WARMASTER:
DoCast(me,SPELL_EAST_FROSTWOLF_WARMASTER);
break;
case NPC_WEST_FROSTWOLF_WARMASTER:
DoCast(me,SPELL_WEST_FROSTWOLF_WARMASTER);
break;
case NPC_ICEBLOOD_WARMASTER:
DoCast(me,SPELL_ICEBLOOD_WARMASTER);
break;
case NPC_TOWER_POINT_WARMASTER:
DoCast(me,SPELL_TOWER_POINT_WARMASTER);
break;
}
bHasAura = true;
}
if (!UpdateVictim())
return;
if (uiChargeTimer <= diff)
{
DoCast(me->getVictim(), SPELL_CHARGE);
uiChargeTimer = urand(10*IN_MILLISECONDS,25*IN_MILLISECONDS);
} else uiChargeTimer -= diff;
if (uiCleaveTimer <= diff)
{
DoCast(me->getVictim(), SPELL_CLEAVE);
uiCleaveTimer = urand(10*IN_MILLISECONDS,16*IN_MILLISECONDS);
} else uiCleaveTimer -= diff;
if (uiDemoralizingShoutTimer <= diff)
{
DoCast(me->getVictim(), SPELL_DEMORALIZING_SHOUT);
uiDemoralizingShoutTimer = urand(10*IN_MILLISECONDS,15*IN_MILLISECONDS);
} else uiDemoralizingShoutTimer -= diff;
if (uiWhirlwind1Timer <= diff)
{
DoCast(me->getVictim(), SPELL_WHIRLWIND1);
uiWhirlwind1Timer = urand(6*IN_MILLISECONDS,20*IN_MILLISECONDS);
} else uiWhirlwind1Timer -= diff;
if (uiWhirlwind2Timer <= diff)
{
DoCast(me->getVictim(), SPELL_WHIRLWIND2);
uiWhirlwind2Timer = urand(10*IN_MILLISECONDS,25*IN_MILLISECONDS);
} else uiWhirlwind2Timer -= diff;
if (uiEnrageTimer <= diff)
{
DoCast(me->getVictim(), SPELL_ENRAGE);
uiEnrageTimer = urand(10*IN_MILLISECONDS,30*IN_MILLISECONDS);
}else uiEnrageTimer -= diff;
// check if creature is not outside of building
if (uiResetTimer <= diff)
{
if (me->GetDistance2d(me->GetHomePosition().GetPositionX(), me->GetHomePosition().GetPositionY()) > 50)
EnterEvadeMode();
uiResetTimer = 5*IN_MILLISECONDS;
} else uiResetTimer -= diff;
DoMeleeAttackIfReady();
}
};
CreatureAI* OnGetAI(Creature* creature) const
{
DoCast(me->getVictim(), SPELL_CLEAVE);
uiCleaveTimer = urand(10*IN_MILLISECONDS,16*IN_MILLISECONDS);
} else uiCleaveTimer -= diff;
if (uiDemoralizingShoutTimer <= diff)
{
DoCast(me->getVictim(), SPELL_DEMORALIZING_SHOUT);
uiDemoralizingShoutTimer = urand(10*IN_MILLISECONDS,15*IN_MILLISECONDS);
} else uiDemoralizingShoutTimer -= diff;
if (uiWhirlwind1Timer <= diff)
{
DoCast(me->getVictim(), SPELL_WHIRLWIND1);
uiWhirlwind1Timer = urand(6*IN_MILLISECONDS,20*IN_MILLISECONDS);
} else uiWhirlwind1Timer -= diff;
if (uiWhirlwind2Timer <= diff)
{
DoCast(me->getVictim(), SPELL_WHIRLWIND2);
uiWhirlwind2Timer = urand(10*IN_MILLISECONDS,25*IN_MILLISECONDS);
} else uiWhirlwind2Timer -= diff;
if (uiEnrageTimer <= diff)
{
DoCast(me->getVictim(), SPELL_ENRAGE);
uiEnrageTimer = urand(10*IN_MILLISECONDS,30*IN_MILLISECONDS);
}else uiEnrageTimer -= diff;
// check if creature is not outside of building
if (uiResetTimer <= diff)
{
if (me->GetDistance2d(me->GetHomePosition().GetPositionX(), me->GetHomePosition().GetPositionY()) > 50)
EnterEvadeMode();
uiResetTimer = 5*IN_MILLISECONDS;
} else uiResetTimer -= diff;
DoMeleeAttackIfReady();
}
return new mob_av_marshal_or_warmasterAI(creature);
}
};
CreatureAI* GetAI_mob_av_marshal_or_warmaster(Creature *_Creature)
{
return new mob_av_marshal_or_warmasterAI (_Creature);
}
void AddSC_alterac_valley()
{
Script *newscript;
newscript = new Script;
newscript->Name = "mob_av_marshal_or_warmaster";
newscript->GetAI = &GetAI_mob_av_marshal_or_warmaster;
newscript->RegisterSelf();
new mob_av_marshal_or_warmaster();
}