[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / ReactorAI.cpp
blob91fa808ed2a8c4b77b051e60031751497b4a5d56
1 /*
2 * Copyright (C) 2005-2009 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"
21 #include "Errors.h"
22 #include "Creature.h"
23 #include "Log.h"
24 #include "ObjectAccessor.h"
26 #define REACTOR_VISIBLE_RANGE (26.46f)
28 int
29 ReactorAI::Permissible(const Creature *creature)
31 if( creature->isCivilian() || creature->IsNeutralToAll() )
32 return PERMIT_BASE_REACTIVE;
34 return PERMIT_BASE_NO;
37 void
38 ReactorAI::MoveInLineOfSight(Unit *)
42 void
43 ReactorAI::AttackStart(Unit *p)
45 if(!p)
46 return;
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);
60 bool
61 ReactorAI::IsVisible(Unit *) const
63 return false;
66 void
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())
71 return;
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();
85 void
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();
93 i_victimGuid = 0;
94 i_creature.CombatStop();
95 i_creature.DeleteThreatList();
96 return;
99 Unit* victim = ObjectAccessor::GetUnit(i_creature, i_victimGuid );
101 if( !victim )
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());
113 else
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();
120 i_victimGuid = 0;
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();