| 1 | /* |
|---|
| 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 3 | * |
|---|
| 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #include "ByteBuffer.h" |
|---|
| 22 | #include "ReactorAI.h" |
|---|
| 23 | #include "Errors.h" |
|---|
| 24 | #include "Creature.h" |
|---|
| 25 | #include "Log.h" |
|---|
| 26 | #include "ObjectAccessor.h" |
|---|
| 27 | |
|---|
| 28 | #define REACTOR_VISIBLE_RANGE (26.46f) |
|---|
| 29 | |
|---|
| 30 | int |
|---|
| 31 | ReactorAI::Permissible(const Creature *creature) |
|---|
| 32 | { |
|---|
| 33 | if( creature->isCivilian() || creature->IsNeutralToAll() ) |
|---|
| 34 | return PERMIT_BASE_REACTIVE; |
|---|
| 35 | |
|---|
| 36 | return PERMIT_BASE_NO; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | void |
|---|
| 40 | ReactorAI::MoveInLineOfSight(Unit *) |
|---|
| 41 | { |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | void |
|---|
| 45 | ReactorAI::AttackStart(Unit *p) |
|---|
| 46 | { |
|---|
| 47 | if(!p) |
|---|
| 48 | return; |
|---|
| 49 | |
|---|
| 50 | if(i_creature.Attack(p,true)) |
|---|
| 51 | { |
|---|
| 52 | DEBUG_LOG("Tag unit GUID: %u (TypeId: %u) as a victim", p->GetGUIDLow(), p->GetTypeId()); |
|---|
| 53 | i_creature.SetInCombatWith(p); |
|---|
| 54 | p->SetInCombatWith(&i_creature); |
|---|
| 55 | |
|---|
| 56 | i_creature.AddThreat(p, 0.0f); |
|---|
| 57 | i_victimGuid = p->GetGUID(); |
|---|
| 58 | i_creature.GetMotionMaster()->MoveChase(p); |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | bool |
|---|
| 63 | ReactorAI::IsVisible(Unit *) const |
|---|
| 64 | { |
|---|
| 65 | return false; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | void |
|---|
| 69 | ReactorAI::UpdateAI(const uint32 /*time_diff*/) |
|---|
| 70 | { |
|---|
| 71 | // update i_victimGuid if i_creature.getVictim() !=0 and changed |
|---|
| 72 | if(!i_creature.SelectHostilTarget() || !i_creature.getVictim()) |
|---|
| 73 | return; |
|---|
| 74 | |
|---|
| 75 | i_victimGuid = i_creature.getVictim()->GetGUID(); |
|---|
| 76 | |
|---|
| 77 | if( i_creature.isAttackReady() ) |
|---|
| 78 | { |
|---|
| 79 | if( i_creature.IsWithinDistInMap(i_creature.getVictim(), ATTACK_DISTANCE)) |
|---|
| 80 | { |
|---|
| 81 | i_creature.AttackerStateUpdate(i_creature.getVictim()); |
|---|
| 82 | i_creature.resetAttackTimer(); |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | void |
|---|
| 88 | ReactorAI::EnterEvadeMode() |
|---|
| 89 | { |
|---|
| 90 | if( !i_creature.isAlive() ) |
|---|
| 91 | { |
|---|
| 92 | DEBUG_LOG("Creature stoped attacking cuz his dead [guid=%u]", i_creature.GetGUIDLow()); |
|---|
| 93 | i_creature.GetMotionMaster()->MovementExpired(); |
|---|
| 94 | i_creature.GetMotionMaster()->MoveIdle(); |
|---|
| 95 | i_victimGuid = 0; |
|---|
| 96 | i_creature.CombatStop(); |
|---|
| 97 | i_creature.DeleteThreatList(); |
|---|
| 98 | return; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | Unit* victim = ObjectAccessor::GetUnit(i_creature, i_victimGuid ); |
|---|
| 102 | |
|---|
| 103 | if( !victim ) |
|---|
| 104 | { |
|---|
| 105 | DEBUG_LOG("Creature stopped attacking because victim is non exist [guid=%u]", i_creature.GetGUIDLow()); |
|---|
| 106 | } |
|---|
| 107 | else if( victim->HasStealthAura() ) |
|---|
| 108 | { |
|---|
| 109 | DEBUG_LOG("Creature stopped attacking cuz his victim is stealth [guid=%u]", i_creature.GetGUIDLow()); |
|---|
| 110 | } |
|---|
| 111 | else if( victim->isInFlight() ) |
|---|
| 112 | { |
|---|
| 113 | DEBUG_LOG("Creature stopped attacking cuz his victim is fly away [guid=%u]", i_creature.GetGUIDLow()); |
|---|
| 114 | } |
|---|
| 115 | else |
|---|
| 116 | { |
|---|
| 117 | DEBUG_LOG("Creature stopped attacking due to target %s [guid=%u]", victim->isAlive() ? "out run him" : "is dead", i_creature.GetGUIDLow()); |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | i_creature.RemoveAllAuras(); |
|---|
| 121 | i_creature.DeleteThreatList(); |
|---|
| 122 | i_victimGuid = 0; |
|---|
| 123 | i_creature.CombatStop(); |
|---|
| 124 | i_creature.SetLootRecipient(NULL); |
|---|
| 125 | |
|---|
| 126 | // Remove TargetedMovementGenerator from MotionMaster stack list, and add HomeMovementGenerator instead |
|---|
| 127 | if( i_creature.GetMotionMaster()->GetCurrentMovementGeneratorType() == TARGETED_MOTION_TYPE ) |
|---|
| 128 | i_creature.GetMotionMaster()->MoveTargetedHome(); |
|---|
| 129 | } |
|---|