1 /* Copyright (C) 2006 - 2010 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "precompiled.h"
27 // **** This script is for use within every single guard to save coding time ****
29 #define GENERIC_CREATURE_COOLDOWN 5000
31 #define SAY_GUARD_SIL_AGGRO1 -1000198
32 #define SAY_GUARD_SIL_AGGRO2 -1000199
33 #define SAY_GUARD_SIL_AGGRO3 -1000200
35 guardAI::guardAI(Creature
* pCreature
) : ScriptedAI(pCreature
),
43 BuffTimer
= 0; //Rebuff as soon as we can
46 void guardAI::Aggro(Unit
*who
)
48 if (m_creature
->GetEntry() == 15184)
52 case 0: DoScriptText(SAY_GUARD_SIL_AGGRO1
, m_creature
, who
); break;
53 case 1: DoScriptText(SAY_GUARD_SIL_AGGRO2
, m_creature
, who
); break;
54 case 2: DoScriptText(SAY_GUARD_SIL_AGGRO3
, m_creature
, who
); break;
58 if (SpellEntry
const *spell
= m_creature
->reachWithSpellAttack(who
))
59 DoCastSpell(who
, spell
);
62 void guardAI::JustDied(Unit
*Killer
)
64 //Send Zone Under Attack message to the LocalDefense and WorldDefense Channels
65 if (Player
* pKiller
= Killer
->GetCharmerOrOwnerPlayerOrPlayerItself())
66 m_creature
->SendZoneUnderAttackMessage(pKiller
);
69 void guardAI::UpdateAI(const uint32 diff
)
71 //Always decrease our global cooldown first
72 if (GlobalCooldown
> diff
)
73 GlobalCooldown
-= diff
;
74 else GlobalCooldown
= 0;
76 //Buff timer (only buff when we are alive and not in combat
77 if (m_creature
->isAlive() && !m_creature
->isInCombat())
80 //Find a spell that targets friendly and applies an aura (these are generally buffs)
81 SpellEntry
const *info
= SelectSpell(m_creature
, -1, -1, SELECT_TARGET_ANY_FRIEND
, 0, 0, 0, 0, SELECT_EFFECT_AURA
);
83 if (info
&& !GlobalCooldown
)
86 DoCastSpell(m_creature
, info
);
88 //Set our global cooldown
89 GlobalCooldown
= GENERIC_CREATURE_COOLDOWN
;
91 //Set our timer to 10 minutes before rebuff
93 } //Try agian in 30 seconds
94 else BuffTimer
= 30000;
95 }else BuffTimer
-= diff
;
97 //Return since we have no target
98 if (!m_creature
->SelectHostileTarget() || !m_creature
->getVictim())
101 // Make sure our attack is ready and we arn't currently casting
102 if (m_creature
->isAttackReady() && !m_creature
->IsNonMeleeSpellCasted(false))
104 //If we are within range melee the target
105 if (m_creature
->IsWithinDistInMap(m_creature
->getVictim(), ATTACK_DISTANCE
))
107 bool Healing
= false;
108 SpellEntry
const *info
= NULL
;
110 //Select a healing spell if less than 30% hp
111 if (m_creature
->GetHealthPercent() < 30.0f
)
112 info
= SelectSpell(m_creature
, -1, -1, SELECT_TARGET_ANY_FRIEND
, 0, 0, 0, 0, SELECT_EFFECT_HEALING
);
114 //No healing spell available, select a hostile spell
115 if (info
) Healing
= true;
116 else info
= SelectSpell(m_creature
->getVictim(), -1, -1, SELECT_TARGET_ANY_ENEMY
, 0, 0, 0, 0, SELECT_EFFECT_DONTCARE
);
118 //20% chance to replace our white hit with a spell
119 if (info
&& !urand(0, 4) && !GlobalCooldown
)
122 if (Healing
)DoCastSpell(m_creature
, info
);
123 else DoCastSpell(m_creature
->getVictim(), info
);
125 //Set our global cooldown
126 GlobalCooldown
= GENERIC_CREATURE_COOLDOWN
;
128 else m_creature
->AttackerStateUpdate(m_creature
->getVictim());
130 m_creature
->resetAttackTimer();
135 //Only run this code if we arn't already casting
136 if (!m_creature
->IsNonMeleeSpellCasted(false))
138 bool Healing
= false;
139 SpellEntry
const *info
= NULL
;
141 //Select a healing spell if less than 30% hp ONLY 33% of the time
142 if (m_creature
->GetHealthPercent() < 30.0f
&& !urand(0, 2))
143 info
= SelectSpell(m_creature
, -1, -1, SELECT_TARGET_ANY_FRIEND
, 0, 0, 0, 0, SELECT_EFFECT_HEALING
);
145 //No healing spell available, See if we can cast a ranged spell (Range must be greater than ATTACK_DISTANCE)
146 if (info
) Healing
= true;
147 else info
= SelectSpell(m_creature
->getVictim(), -1, -1, SELECT_TARGET_ANY_ENEMY
, 0, 0, ATTACK_DISTANCE
, 0, SELECT_EFFECT_DONTCARE
);
149 //Found a spell, check if we arn't on cooldown
150 if (info
&& !GlobalCooldown
)
152 //If we are currently moving stop us and set the movement generator
153 if ((*m_creature
).GetMotionMaster()->GetCurrentMovementGeneratorType()!=IDLE_MOTION_TYPE
)
155 (*m_creature
).GetMotionMaster()->Clear(false);
156 (*m_creature
).GetMotionMaster()->MoveIdle();
160 if (Healing
) DoCastSpell(m_creature
,info
);
161 else DoCastSpell(m_creature
->getVictim(),info
);
163 //Set our global cooldown
164 GlobalCooldown
= GENERIC_CREATURE_COOLDOWN
;
166 } //If no spells available and we arn't moving run to target
167 else if ((*m_creature
).GetMotionMaster()->GetCurrentMovementGeneratorType()!=CHASE_MOTION_TYPE
)
169 //Cancel our current spell and then mutate new movement generator
170 m_creature
->InterruptNonMeleeSpells(false);
171 (*m_creature
).GetMotionMaster()->Clear(false);
172 (*m_creature
).GetMotionMaster()->MoveChase(m_creature
->getVictim());
178 void guardAI::DoReplyToTextEmote(uint32 em
)
182 case TEXTEMOTE_KISS
: m_creature
->HandleEmoteCommand(EMOTE_ONESHOT_BOW
); break;
183 case TEXTEMOTE_WAVE
: m_creature
->HandleEmoteCommand(EMOTE_ONESHOT_WAVE
); break;
184 case TEXTEMOTE_SALUTE
: m_creature
->HandleEmoteCommand(EMOTE_ONESHOT_SALUTE
); break;
185 case TEXTEMOTE_SHY
: m_creature
->HandleEmoteCommand(EMOTE_ONESHOT_FLEX
); break;
187 case TEXTEMOTE_CHICKEN
: m_creature
->HandleEmoteCommand(EMOTE_ONESHOT_POINT
); break;
191 void guardAI_orgrimmar::ReceiveEmote(Player
* pPlayer
, uint32 text_emote
)
193 if (pPlayer
->GetTeam()==HORDE
)
194 DoReplyToTextEmote(text_emote
);
197 void guardAI_stormwind::ReceiveEmote(Player
* pPlayer
, uint32 text_emote
)
199 if (pPlayer
->GetTeam() == ALLIANCE
)
200 DoReplyToTextEmote(text_emote
);