aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bindings/scripts/scripts/eastern_kingdoms/scarlet_enclave/the_scarlet_enclave.cpp53
-rw-r--r--src/game/Unit.cpp15
-rw-r--r--src/game/UnitAI.cpp5
-rw-r--r--src/game/UnitAI.h2
4 files changed, 72 insertions, 3 deletions
diff --git a/src/bindings/scripts/scripts/eastern_kingdoms/scarlet_enclave/the_scarlet_enclave.cpp b/src/bindings/scripts/scripts/eastern_kingdoms/scarlet_enclave/the_scarlet_enclave.cpp
index 0bc4966dc33..cfbc9bc0597 100644
--- a/src/bindings/scripts/scripts/eastern_kingdoms/scarlet_enclave/the_scarlet_enclave.cpp
+++ b/src/bindings/scripts/scripts/eastern_kingdoms/scarlet_enclave/the_scarlet_enclave.cpp
@@ -100,6 +100,54 @@ CreatureAI* GetAI_npc_valkyr_battle_maiden(Creature* pCreature)
return new npc_valkyr_battle_maidenAI (pCreature);
}
+struct TRINITY_DLL_DECL mob_anti_airAI : public ScriptedAI
+{
+ mob_anti_airAI(Creature *c) : ScriptedAI(c)
+ {
+ assert(me->m_spells[0]);
+ range = DoGetSpellMaxRange(me->m_spells[0]);
+ }
+
+ float range;
+
+ void MoveInLineOfSight(Unit *who)
+ {
+ if(!me->getVictim() && me->canAttack(who)
+ && me->IsWithinCombatRange(who, range)
+ && me->IsWithinLOSInMap(who))
+ AttackStart(who);
+ }
+
+ void AttackStart(Unit *who)
+ {
+ if(who->IsFlying() || !me->IsWithinMeleeRange(who))
+ {
+ if(me->Attack(who, false))
+ me->GetMotionMaster()->MoveIdle();
+ }
+ else if(me->Attack(who, true))
+ me->GetMotionMaster()->MoveChase(who);
+ }
+
+ void UpdateAI(const uint32 diff)
+ {
+ if(!UpdateVictim())
+ return;
+
+ if(me->getVictim()->IsFlying() || !me->IsWithinMeleeRange(me->getVictim()))
+ {
+ if(!DoSpellAttackIfReady(me->m_spells[0]))
+ EnterEvadeMode();
+ }
+ else
+ DoMeleeAttackIfReady();
+ }
+};
+
+CreatureAI* GetAI_mob_anti_air(Creature* pCreature)
+{
+ return new mob_anti_airAI (pCreature);
+}
void AddSC_the_scarlet_enclave()
{
@@ -109,4 +157,9 @@ void AddSC_the_scarlet_enclave()
newscript->Name="npc_valkyr_battle_maiden";
newscript->GetAI = &GetAI_npc_valkyr_battle_maiden;
newscript->RegisterSelf();
+
+ newscript = new Script;
+ newscript->Name="mob_anti_air";
+ newscript->GetAI = &GetAI_mob_anti_air;
+ newscript->RegisterSelf();
}
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 8053944f9ea..64fdc7d845d 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -8152,10 +8152,19 @@ bool Unit::Attack(Unit *victim, bool meleeAttack)
if (m_attacking == victim)
{
// switch to melee attack from ranged/magic
- if( meleeAttack && !hasUnitState(UNIT_STAT_MELEE_ATTACKING) )
+ if(meleeAttack)
{
- addUnitState(UNIT_STAT_MELEE_ATTACKING);
- SendMeleeAttackStart(victim);
+ if(!hasUnitState(UNIT_STAT_MELEE_ATTACKING))
+ {
+ addUnitState(UNIT_STAT_MELEE_ATTACKING);
+ SendMeleeAttackStart(victim);
+ return true;
+ }
+ }
+ else if(hasUnitState(UNIT_STAT_MELEE_ATTACKING))
+ {
+ clearUnitState(UNIT_STAT_MELEE_ATTACKING);
+ SendMeleeAttackStop(victim);
return true;
}
return false;
diff --git a/src/game/UnitAI.cpp b/src/game/UnitAI.cpp
index a41ad894097..0f00cd356f2 100644
--- a/src/game/UnitAI.cpp
+++ b/src/game/UnitAI.cpp
@@ -223,6 +223,11 @@ void UnitAI::SelectTargetList(std::list<Unit*> &targetList, uint32 num, SelectAg
}
}
+float UnitAI::DoGetSpellMaxRange(uint32 spellId, bool positive)
+{
+ return GetSpellMaxRange(spellId, positive);
+}
+
void UnitAI::DoCast(uint32 spellId)
{
Unit *target = NULL;
diff --git a/src/game/UnitAI.h b/src/game/UnitAI.h
index 784a453e970..a9afbb61b11 100644
--- a/src/game/UnitAI.h
+++ b/src/game/UnitAI.h
@@ -69,6 +69,8 @@ class TRINITY_DLL_SPEC UnitAI
void DoCast(Unit* victim, uint32 spellId, bool triggered = false);
void DoCastAOE(uint32 spellId, bool triggered = false);
+ float DoGetSpellMaxRange(uint32 spellId, bool positive = false);
+
void DoMeleeAttackIfReady();
bool DoSpellAttackIfReady(uint32 spell);