2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "ByteBuffer.h"
20 #include "ReactorAI.h"
24 #include "ObjectAccessor.h"
26 #define REACTOR_VISIBLE_RANGE (26.46f)
29 ReactorAI::Permissible(const Creature
*creature
)
31 if( creature
->isCivilian() || creature
->IsNeutralToAll() )
32 return PERMIT_BASE_REACTIVE
;
34 return PERMIT_BASE_NO
;
38 ReactorAI::MoveInLineOfSight(Unit
*)
43 ReactorAI::AttackStart(Unit
*p
)
48 if(i_creature
.Attack(p
,true))
50 DEBUG_LOG("Tag unit GUID: %u (TypeId: %u) as a victim", p
->GetGUIDLow(), p
->GetTypeId());
51 i_creature
.SetInCombatWith(p
);
52 p
->SetInCombatWith(&i_creature
);
54 i_creature
.AddThreat(p
, 0.0f
);
55 i_victimGuid
= p
->GetGUID();
56 i_creature
.GetMotionMaster()->MoveChase(p
);
61 ReactorAI::IsVisible(Unit
*) const
67 ReactorAI::UpdateAI(const uint32
/*time_diff*/)
69 // update i_victimGuid if i_creature.getVictim() !=0 and changed
70 if(!i_creature
.SelectHostilTarget() || !i_creature
.getVictim())
73 i_victimGuid
= i_creature
.getVictim()->GetGUID();
75 if( i_creature
.isAttackReady() )
77 if( i_creature
.IsWithinDistInMap(i_creature
.getVictim(), ATTACK_DISTANCE
))
79 i_creature
.AttackerStateUpdate(i_creature
.getVictim());
80 i_creature
.resetAttackTimer();
86 ReactorAI::EnterEvadeMode()
88 if( !i_creature
.isAlive() )
90 DEBUG_LOG("Creature stoped attacking cuz his dead [guid=%u]", i_creature
.GetGUIDLow());
91 i_creature
.GetMotionMaster()->MovementExpired();
92 i_creature
.GetMotionMaster()->MoveIdle();
94 i_creature
.CombatStop();
95 i_creature
.DeleteThreatList();
99 Unit
* victim
= ObjectAccessor::GetUnit(i_creature
, i_victimGuid
);
103 DEBUG_LOG("Creature stopped attacking because victim is non exist [guid=%u]", i_creature
.GetGUIDLow());
105 else if( victim
->HasStealthAura() )
107 DEBUG_LOG("Creature stopped attacking cuz his victim is stealth [guid=%u]", i_creature
.GetGUIDLow());
109 else if( victim
->isInFlight() )
111 DEBUG_LOG("Creature stopped attacking cuz his victim is fly away [guid=%u]", i_creature
.GetGUIDLow());
115 DEBUG_LOG("Creature stopped attacking due to target %s [guid=%u]", victim
->isAlive() ? "out run him" : "is dead", i_creature
.GetGUIDLow());
118 i_creature
.RemoveAllAuras();
119 i_creature
.DeleteThreatList();
121 i_creature
.CombatStop();
122 i_creature
.SetLootRecipient(NULL
);
124 // Remove TargetedMovementGenerator from MotionMaster stack list, and add HomeMovementGenerator instead
125 if( i_creature
.GetMotionMaster()->GetCurrentMovementGeneratorType() == TARGETED_MOTION_TYPE
)
126 i_creature
.GetMotionMaster()->MoveTargetedHome();