OregonCore  revision fb2a440-git
Your Favourite TBC server
GuardAI.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "GuardAI.h"
19 #include "Errors.h"
20 #include "Player.h"
21 #include "ObjectAccessor.h"
22 
23 int GuardAI::Permissible(const Creature* creature)
24 {
25  if (creature->IsGuard())
26  return PERMIT_BASE_SPECIAL;
27 
28  return PERMIT_BASE_NO;
29 }
30 
32 {
33 }
34 
36 {
37  if (!obj->isType(TYPEMASK_UNIT))
38  return false;
39 
41  for (ThreatContainer::StorageType::const_iterator itr = threatList.begin(); itr != threatList.end(); ++itr)
42  if ((*itr)->getUnitGuid() == obj->GetGUID())
43  return true;
44 
45  return false;
46 }
47 
49 {
50  if (!me->IsAlive())
51  {
53  me->CombatStop(true);
55  return;
56  }
57 
59 
60  if (!victim)
61  DEBUG_LOG("Creature stopped attacking because victim is non exist [guid=%u]", me->GetGUIDLow());
62  else if (!victim ->IsAlive())
63  DEBUG_LOG("Creature stopped attacking because victim is dead [guid=%u]", me->GetGUIDLow());
64  else if (victim ->HasStealthAura())
65  DEBUG_LOG("Creature stopped attacking because victim is using stealth [guid=%u]", me->GetGUIDLow());
66  else if (victim ->IsInFlight())
67  DEBUG_LOG("Creature stopped attacking because victim is flying away [guid=%u]", me->GetGUIDLow());
68  else
69  DEBUG_LOG("Creature stopped attacking because victim outran him [guid=%u]", me->GetGUIDLow());
70 
71  me->RemoveAllAuras();
73  me->CombatStop(true);
74 
75  // Remove TargetedMovementGenerator from MotionMaster stack list, and add HomeMovementGenerator instead
78 }
79 
80 void GuardAI::JustDied(Unit* killer)
81 {
82  if (Player* player = killer->GetCharmerOrOwnerPlayerOrPlayerItself())
84 }
85 
void RemoveAllAuras()
Definition: Unit.cpp:4577
void MoveIdle(MovementSlot slot=MOTION_SLOT_ACTIVE)
bool CanSeeAlways(WorldObject const *obj) override
Definition: GuardAI.cpp:35
void SendZoneUnderAttackMessage(Player *attacker)
Definition: Creature.cpp:2191
bool isType(uint16 mask) const
Definition: Object.h:214
void EnterEvadeMode()
Definition: GuardAI.cpp:48
MotionMaster * GetMotionMaster()
Definition: Unit.h:1890
void MoveTargetedHome()
MovementGeneratorType GetCurrentMovementGeneratorType() const
ThreatContainer::StorageType const & getThreatList() const
uint32 GetGUIDLow() const
Definition: Object.h:166
uint64 i_victimGuid
Definition: GuardAI.h:43
#define TIME_INTERVAL_LOOK
Definition: CreatureAI.h:31
TimeTracker i_tracker
Definition: GuardAI.h:45
bool IsAlive() const
Definition: Unit.h:1336
void CombatStop(bool cast=false)
Definition: Unit.cpp:7518
#define DEBUG_LOG(...)
Definition: Log.h:194
GuardState i_state
Definition: GuardAI.h:44
static int Permissible(const Creature *)
Definition: GuardAI.cpp:23
GuardAI(Creature *creature)
Definition: GuardAI.cpp:31
bool IsGuard() const
Definition: Creature.h:490
void DeleteThreatList()
Definition: Unit.cpp:10226
std::list< HostileReference * > StorageType
void JustDied(Unit *)
Definition: GuardAI.cpp:80
ThreatManager & getThreatManager()
Definition: Unit.h:1721
static Unit * GetUnit(WorldObject const &, uint64 guid)
Creature * me
Definition: Unit.h:908
Definition: Player.h:922
Player * GetCharmerOrOwnerPlayerOrPlayerItself() const
Definition: Unit.cpp:7641
const uint64 & GetGUID() const
Definition: Object.h:162