#include "StdAfx.h" #include "Setup.h" /************************************************************************/ /* GuardAI.cpp Script */ /************************************************************************/ // Undercity GuardianAI #define CN_UNDERCITY_GUARDIAN 5624 #define DISEASE_CLOUD 12187 //12188 class UNDERCITYGUARDIANAI : public CreatureAIScript { public: ADD_CREATURE_FACTORY_FUNCTION(UNDERCITYGUARDIANAI); SP_AI_Spell spells[1]; bool m_spellcheck[1]; UNDERCITYGUARDIANAI(Creature* pCreature) : CreatureAIScript(pCreature) { nrspells = 1; for(int i=0;iCastSpell(_unit, spells[0].info, spells[0].instant); } void OnCombatStart(Unit* mTarget) { CastTime(); RegisterAIUpdateEvent(_unit->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME)); } void CastTime() { for(int i=0;iGetAIInterface()->setCurrentAgent(AGENT_NULL); _unit->GetAIInterface()->SetAIState(STATE_IDLE); RemoveAIUpdateEvent(); } void OnDied(Unit * mKiller) { CastTime(); RemoveAIUpdateEvent(); } void AIUpdate() { float val = sRand.rand(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;iGetAIInterface()->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; } if (spells[i].speech != "") { _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, spells[i].speech.c_str()); _unit->PlaySoundToSet(spells[i].soundid); } m_spellcheck[i] = false; return; } if ((val > comulativeperc && val <= (comulativeperc + spells[i].perctrigger)) || !spells[i].casttime) { _unit->setAttackTimer(spells[i].attackstoptimer, false); m_spellcheck[i] = true; } comulativeperc += spells[i].perctrigger; } } } protected: int nrspells; }; void SetupGuardAI(ScriptMgr * mgr) { mgr->register_creature_script(CN_UNDERCITY_GUARDIAN, &UNDERCITYGUARDIANAI::Create); }