1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
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. |
---|
8 | * |
---|
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. |
---|
13 | * |
---|
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 |
---|
17 | */ |
---|
18 | |
---|
19 | #include "ByteBuffer.h" |
---|
20 | #include "ReactorAI.h" |
---|
21 | #include "Errors.h" |
---|
22 | #include "Creature.h" |
---|
23 | #include "Log.h" |
---|
24 | #include "ObjectAccessor.h" |
---|
25 | |
---|
26 | #define REACTOR_VISIBLE_RANGE (26.46f) |
---|
27 | |
---|
28 | int |
---|
29 | ReactorAI::Permissible(const Creature *creature) |
---|
30 | { |
---|
31 | if( creature->isCivilian() || creature->IsNeutralToAll() ) |
---|
32 | return PERMIT_BASE_REACTIVE; |
---|
33 | |
---|
34 | return PERMIT_BASE_NO; |
---|
35 | } |
---|
36 | |
---|
37 | void |
---|
38 | ReactorAI::MoveInLineOfSight(Unit *) |
---|
39 | { |
---|
40 | } |
---|
41 | |
---|
42 | void |
---|
43 | ReactorAI::AttackStart(Unit *p) |
---|
44 | { |
---|
45 | if(!p) |
---|
46 | return; |
---|
47 | |
---|
48 | if(i_creature.Attack(p,true)) |
---|
49 | { |
---|
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); |
---|
53 | |
---|
54 | i_creature.AddThreat(p, 0.0f); |
---|
55 | i_victimGuid = p->GetGUID(); |
---|
56 | i_creature.GetMotionMaster()->MoveChase(p); |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | bool |
---|
61 | ReactorAI::IsVisible(Unit *) const |
---|
62 | { |
---|
63 | return false; |
---|
64 | } |
---|
65 | |
---|
66 | void |
---|
67 | ReactorAI::UpdateAI(const uint32 /*time_diff*/) |
---|
68 | { |
---|
69 | // update i_victimGuid if i_creature.getVictim() !=0 and changed |
---|
70 | if(!i_creature.SelectHostilTarget() || !i_creature.getVictim()) |
---|
71 | return; |
---|
72 | |
---|
73 | i_victimGuid = i_creature.getVictim()->GetGUID(); |
---|
74 | |
---|
75 | if( i_creature.isAttackReady() ) |
---|
76 | { |
---|
77 | if( i_creature.IsWithinDistInMap(i_creature.getVictim(), ATTACK_DISTANCE)) |
---|
78 | { |
---|
79 | i_creature.AttackerStateUpdate(i_creature.getVictim()); |
---|
80 | i_creature.resetAttackTimer(); |
---|
81 | } |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | void |
---|
86 | ReactorAI::EnterEvadeMode() |
---|
87 | { |
---|
88 | if( !i_creature.isAlive() ) |
---|
89 | { |
---|
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; |
---|
97 | } |
---|
98 | |
---|
99 | Unit* victim = ObjectAccessor::GetUnit(i_creature, i_victimGuid ); |
---|
100 | |
---|
101 | if( !victim ) |
---|
102 | { |
---|
103 | DEBUG_LOG("Creature stopped attacking because victim is non exist [guid=%u]", i_creature.GetGUIDLow()); |
---|
104 | } |
---|
105 | else if( victim->HasStealthAura() ) |
---|
106 | { |
---|
107 | DEBUG_LOG("Creature stopped attacking cuz his victim is stealth [guid=%u]", i_creature.GetGUIDLow()); |
---|
108 | } |
---|
109 | else if( victim->isInFlight() ) |
---|
110 | { |
---|
111 | DEBUG_LOG("Creature stopped attacking cuz his victim is fly away [guid=%u]", i_creature.GetGUIDLow()); |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | DEBUG_LOG("Creature stopped attacking due to target %s [guid=%u]", victim->isAlive() ? "out run him" : "is dead", i_creature.GetGUIDLow()); |
---|
116 | } |
---|
117 | |
---|
118 | i_creature.RemoveAllAuras(); |
---|
119 | i_creature.DeleteThreatList(); |
---|
120 | i_victimGuid = 0; |
---|
121 | i_creature.CombatStop(); |
---|
122 | i_creature.SetLootRecipient(NULL); |
---|
123 | |
---|
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(); |
---|
127 | } |
---|