/* Copyright (C) 2006,2007 ScriptDev2 * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "../sc_defines.h" #define SPELL_DEATHTOUCH 5 #define SAY_AGGRO "This area is closed!" struct MANGOS_DLL_DECL npc_guardianAI : public ScriptedAI { npc_guardianAI(Creature *c) : ScriptedAI(c) {EnterEvadeMode();} bool InCombat; void EnterEvadeMode() { InCombat = false; m_creature->RemoveAllAuras(); m_creature->DeleteThreatList(); m_creature->CombatStop(); DoGoHome(); m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); } void AttackStart(Unit *who) { if (!who) return; if (who->isTargetableForAttack() && who!= m_creature) { //Say our dialog if(!InCombat) { DoYell(SAY_AGGRO,LANG_UNIVERSAL,NULL); InCombat = true; } DoStartMeleeAttack(who); } } void MoveInLineOfSight(Unit *who) { if (!who || m_creature->getVictim()) return; if (who->isTargetableForAttack() && who->isInAccessablePlaceFor(m_creature) && m_creature->IsHostileTo(who)) { float attackRadius = (m_creature->GetAttackDistance(who) /2); if (m_creature->IsWithinDistInMap(who, attackRadius) && m_creature->GetDistanceZ(who) <= 1 && m_creature->IsWithinLOSInMap(who)) { if(who->HasStealthAura()) who->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH); //Begin melee attack if we are within range DoStartMeleeAttack(who); } } } void UpdateAI(const uint32 diff) { //Return since we have no target if (!m_creature->SelectHostilTarget() || !m_creature->getVictim()) return; if (m_creature->isAttackReady()) { m_creature->CastSpell(m_creature->getVictim(),SPELL_DEATHTOUCH, true); m_creature->resetAttackTimer(); } } }; CreatureAI* GetAI_npc_guardian(Creature *_Creature) { return new npc_guardianAI (_Creature); } void AddSC_npc_guardian() { Script *newscript; newscript = new Script; newscript->Name="npc_guardian"; newscript->GetAI = GetAI_npc_guardian; m_scripts[nrscripts++] = newscript; }