TrinityCore
Loading...
Searching...
No Matches
PassiveAI.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore 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 "PassiveAI.h"
19#include "Creature.h"
20#include "World.h"
21
22PassiveAI::PassiveAI(Creature* c, uint32 scriptId) noexcept : CreatureAI(c, scriptId)
23{
24 me->SetReactState(REACT_PASSIVE);
25 me->SetCanMelee(false);
26}
27
28PossessedAI::PossessedAI(Creature* c, uint32 scriptId) noexcept : CreatureAI(c, scriptId)
29{
30 me->SetReactState(REACT_PASSIVE);
31}
32
33NullCreatureAI::NullCreatureAI(Creature* c, uint32 scriptId) noexcept : CreatureAI(c, scriptId)
34{
35 me->SetReactState(REACT_PASSIVE);
36 me->SetCanMelee(false);
37}
38
40{
42 return PERMIT_BASE_PROACTIVE + 50;
43
44 if (creature->IsTrigger())
46
47 return PERMIT_BASE_IDLE;
48}
49
55
58 me->Attack(target, true);
59}
60
62{
63 if (me->GetVictim())
64 {
66 me->AttackStop();
67 }
68}
69
71{
72 // We died while possessed, disable our loot
74}
75
76CritterAI::CritterAI(Creature* creature, uint32 scriptId) noexcept : PassiveAI(creature, scriptId)
77{
78 me->SetCanMelee(false, true);
79}
80
86
88{
89 if (me->IsEngaged())
90 {
91 if (!me->IsInCombat())
92 {
94 return;
95 }
96
97 _evadeTimer.Update(diff);
98 if (_evadeTimer.Passed())
100 }
101}
102
104{
105 if (creature->IsCritter() && !creature->HasUnitTypeMask(UNIT_MASK_GUARDIAN))
107
108 return PERMIT_BASE_NO;
109}
110
112{
113 if (me->m_spells[0])
114 {
115 CastSpellExtraArgs extra;
116 extra.OriginalCaster = summoner->GetGUID();
117 me->CastSpell(me, me->m_spells[0], extra);
118 }
119}
120
122{
123 if (creature->IsTrigger() && creature->m_spells[0])
124 return PERMIT_BASE_SPECIAL;
125
126 return PERMIT_BASE_NO;
127}
@ PERMIT_BASE_SPECIAL
Definition CreatureAI.h:51
@ PERMIT_BASE_PROACTIVE
Definition CreatureAI.h:49
@ PERMIT_BASE_NO
Definition CreatureAI.h:46
@ PERMIT_BASE_IDLE
Definition CreatureAI.h:47
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition Duration.h:24
@ UNIT_DYNFLAG_LOOTABLE
@ REACT_PASSIVE
@ UNIT_NPC_FLAG_SPELLCLICK
@ UNIT_MASK_GUARDIAN
Definition Unit.h:358
ObjectGuid const & GetGUID() const
Definition BaseEntity.h:163
virtual void EnterEvadeMode(EvadeReason why=EvadeReason::Other)
Creature *const me
Definition CreatureAI.h:63
bool IsTrigger() const
Definition Creature.h:127
void StartDefaultCombatMovement(Unit *victim, Optional< float > range={}, Optional< float > angle={})
uint32 m_spells[MAX_CREATURE_SPELLS]
Definition Creature.h:324
bool IsEngaged() const override
void JustEngagedWith(Unit *) override
Definition PassiveAI.cpp:81
TimeTracker _evadeTimer
Definition PassiveAI.h:83
void UpdateAI(uint32 diff) override
Definition PassiveAI.cpp:87
CritterAI(Creature *creature, uint32 scriptId={}) noexcept
Definition PassiveAI.cpp:76
static int32 Permissible(Creature const *creature)
NullCreatureAI(Creature *creature, uint32 scriptId={}) noexcept
Definition PassiveAI.cpp:33
static int32 Permissible(Creature const *creature)
Definition PassiveAI.cpp:39
void RemoveDynamicFlag(uint32 flag)
Definition Object.h:98
PassiveAI(Creature *creature, uint32 scriptId={}) noexcept
Definition PassiveAI.cpp:22
void UpdateAI(uint32) override
Definition PassiveAI.cpp:50
void AttackStart(Unit *target) override
== Triggered Actions Requested ==================
Definition PassiveAI.cpp:56
void UpdateAI(uint32) override
Definition PassiveAI.cpp:61
PossessedAI(Creature *creature, uint32 scriptId={}) noexcept
Definition PassiveAI.cpp:28
void JustDied(Unit *) override
Definition PassiveAI.cpp:70
void IsSummonedBy(WorldObject *summoner) override
static int32 Permissible(Creature const *creature)
Definition Unit.h:635
bool Attack(Unit *victim, bool meleeAttack)
Definition Unit.cpp:5853
bool HasNpcFlag(NPCFlags flags) const
Definition Unit.h:996
Unit * GetVictim() const
Definition Unit.h:726
bool IsCritter() const
Definition Unit.h:1025
uint32 HasUnitTypeMask(uint32 mask) const
Definition Unit.h:747
bool AttackStop()
Definition Unit.cpp:5965
bool IsInCombat() const
Definition Unit.h:1058
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2217
bool IsValidAttackTarget(WorldObject const *target, SpellInfo const *bySpell=nullptr) const
Definition Object.cpp:2324
#define sWorld
Definition World.h:916
@ CONFIG_CREATURE_FAMILY_FLEE_DELAY
Definition World.h:313
void Update(int32 diff)
Definition Timer.h:121
bool Passed() const
Definition Timer.h:131
void Reset(int32 expiry)
Definition Timer.h:136