made this yesterday:
/***********************************************************************
* Sharrior.ccp writen by: Swanitalia *
***********************************************************************/
/* Sharrior AI - Creature AI Class */
#define CN_Sharrior # //not maded yet
#define CONSECRATION 20924
#define CLEANSING 53659
#define HOLY_SHOCK 27174
#define DIVINE 642
class SharriorAI : public CreatureAIScript
{
public:
ADD_CREATURE_FACTORY_FUNCTION(SharriorAI);
SP_AI_Spell spells[4];
bool m_spellcheck[4];
SharriorAI(Creature* pCreature) : CreatureAIScript(pCreature)
{
nrspells = 3;
for(int i=0;i<nrspells;i++)
{
m_spellcheck[i] = false;
spells[i].casttime = 0;
}
spells[0].info = dbcSpell.LookupEntry(CONSECRATION);
spells[0].targettype = TARGET_ATTACKING;
spells[0].instant = true;
spells[0].cooldown = 30;
spells[0].perctrigger = 7.0f;
spells[0].attackstoptimer = 1000;
spells[1].info = dbcSpell.LookupEntry(CLEANSING);
spells[1].targettype = TARGET_SELF;
spells[1].instant = true;
spells[1].cooldown = 35;
spells[1].prectrigger = 13.0f;
spells[1].attackstoptimer = 1000;
spells[2].info = dbcSpell.LookupEntry(HOLY_SHOCK);
spells[2].targettype = TARGET_ATTACKING;
spells[2].instant = true;
spells[2].cooldown = 15;
spells[2].prectrigger = 20.0f;
spells[2].attackstoptimer = 1000;
spells[3].info = dbcSpell.LookupEntry(DIVINE);
spells[3].targettype = TARGET_SELF;
spells[3].instant = true;
spells[3].cooldown = 60;
_unit->m_noRespawn = true;
}
void OnCombatStart(Unit* mTarget)
{
_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Deadswan, I will not let you down!!");
RegisterAIUpdateEvent(_unit->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME));
}
void OnCombatStop(Unit *mTarget)
{
_unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
_unit->GetAIInterface()->SetAIState(STATE_IDLE);
RemoveAIUpdateEvent();
for (int i = 0; i < nrspells; i++)
spells[i].casttime = 0;
}
void OnDied(Unit * mKiller)
{
_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Deadswan I failed you!!");
RemoveAIUpdateEvent();
FoADeaths[_unit->GetInstanceID()]--;
}
void AIUpdate()
{
if (_unit->GetCurrentSpell() == NULL && _unit->GetAIInterface()->GetNextTarget())
{
Unit *target = NULL;
target = _unit->GetAIInterface()->GetNextTarget();
if (_unit->GetDistance2dSq(target) >= 20.0f && _unit->GetDistance2dSq(target) <= 1225 && rand()%5 == 0) // I must test this value (15-35yards for now)
{
_unit->CastSpell(target, spells[0].info, spells[0].instant);
_unit->CastSpell(target, spells[1].info, spells[1].instant);
_unit->CastSpell(target, spells[2].info, spells[2].instant);
if(_unit->GetHealthPct() == 20)
{
_unit->CastSpell(target, spells[3].info, spells[3].instant);
}
}
}
float val = (float)RandomFloat(100.0f);
SpellCast(val);
}
void SpellCast(float val)
{
if(_unit->GetCurrentSpell() == NULL && _unit->GetAIInterface()->GetNextTarget())
{
float comulativeperc = 0;
Unit *target = NULL;
for(int i=0;i<nrspells;i++)
{
if(!spells[i].perctrigger) continue;
if(m_spellcheck[i])
{
target = _unit->GetAIInterface()->GetNextTarget();
switch(spells[i].targettype)
{
case TARGET_SELF:
case TARGET_VARIOUS:
_unit->CastSpell(_unit, spells[i].info, spells[i].instant); break;
case TARGET_ATTACKING:
_unit->CastSpell(target, spells[i].info, spells[i].instant); break;
case TARGET_DESTINATION:
_unit->CastSpellAoF(target->GetPositionX(),target->GetPositionY(),target->GetPositionZ(), spells[i].info, spells[i].instant); break;
}
m_spellcheck[i] = false;
return;
}
uint32 t = (uint32)time(NULL);
if(val > comulativeperc && val <= (comulativeperc + spells[i].perctrigger) && t > spells[i].casttime)
{
_unit->setAttackTimer(spells[i].attackstoptimer, false);
spells[i].casttime = t + spells[i].cooldown;
m_spellcheck[i] = true;
}
comulativeperc += spells[i].perctrigger;
}
}
}
protected:
int nrspells;
};