Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
TemporarySummon.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "CreatureAI.h"
7#include "Log.h"
8#include "ObjectAccessor.h"
9#include "ObjectMgr.h"
10#include "Pet.h"
11#include "Player.h"
12#include "TemporarySummon.h"
13
14TempSummon::TempSummon(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) :
16 m_timer(0), m_lifetime(0), m_summonerGUID(owner ? owner->GetGUID() : 0)
17{
19}
20
25
30
32{
33 Creature::Update(diff);
34
36 {
37 UnSummon();
38 return;
39 }
40 switch (m_type)
41 {
43 break;
45 {
46 if (m_timer <= diff)
47 {
48 UnSummon();
49 return;
50 }
51
52 m_timer -= diff;
53 break;
54 }
56 {
57 if (!IsInCombat())
58 {
59 if (m_timer <= diff)
60 {
61 UnSummon();
62 return;
63 }
64
65 m_timer -= diff;
66 }
67 else if (m_timer != m_lifetime)
69
70 break;
71 }
72
74 {
76 {
77 if (m_timer <= diff)
78 {
79 UnSummon();
80 return;
81 }
82
83 m_timer -= diff;
84 }
85 break;
86 }
88 {
89 // if m_deathState is DEAD, CORPSE was skipped
91 {
92 UnSummon();
93 return;
94 }
95
96 break;
97 }
99 {
101 {
102 UnSummon();
103 return;
104 }
105 break;
106 }
108 {
109 // if m_deathState is DEAD, CORPSE was skipped
111 {
112 UnSummon();
113 return;
114 }
115
116 if (!IsInCombat())
117 {
118 if (m_timer <= diff)
119 {
120 UnSummon();
121 return;
122 }
123 else
124 m_timer -= diff;
125 }
126 else if (m_timer != m_lifetime)
128 break;
129 }
131 {
132 // if m_deathState is DEAD, CORPSE was skipped
134 {
135 UnSummon();
136 return;
137 }
138
139 if (!IsInCombat() && IsAlive())
140 {
141 if (m_timer <= diff)
142 {
143 UnSummon();
144 return;
145 }
146 else
147 m_timer -= diff;
148 }
149 else if (m_timer != m_lifetime)
151 break;
152 }
153 default:
154 UnSummon();
155 SF_LOG_ERROR("entities.unit", "Temporary summoned creature (entry: %u) have unknown type %u of ", GetEntry(), uint32(m_type));
156 break;
157 }
158}
159
161{
162 ASSERT(!IsPet());
163
164 m_timer = duration;
165 m_lifetime = duration;
166
169
170 Unit* owner = GetSummoner();
171
172 if (owner && IsTrigger() && m_spells[0])
173 {
174 setFaction(owner->getFaction());
175 SetLevel(owner->getLevel());
176 if (owner->GetTypeId() == TypeID::TYPEID_PLAYER)
178 }
179
180 if (!m_Properties)
181 return;
182
183 if (owner)
184 {
185 int32 slot = m_Properties->Slot;
186 if (slot > 0)
187 {
188 if (owner->m_SummonSlot[slot] && owner->m_SummonSlot[slot] != GetGUID())
189 {
190 Creature* oldSummon = GetMap()->GetCreature(owner->m_SummonSlot[slot]);
191 if (oldSummon && oldSummon->IsSummon())
192 oldSummon->ToTempSummon()->UnSummon();
193 }
194 owner->m_SummonSlot[slot] = GetGUID();
195 }
196 }
197
198 if (m_Properties->Faction)
199 setFaction(m_Properties->Faction);
200 else if (IsVehicle() && owner) // properties should be vehicle
201 setFaction(owner->getFaction());
202}
203
205{
206 Unit* owner = GetSummoner();
207 if (owner)
208 {
209 if (owner->GetTypeId() == TypeID::TYPEID_UNIT && owner->ToCreature()->IsAIEnabled)
210 owner->ToCreature()->AI()->JustSummoned(this);
211 if (IsAIEnabled)
212 AI()->IsSummonedBy(owner);
213 }
214}
215
217{
218 m_type = type;
219}
220
222{
223 if (msTime)
224 {
226
227 m_Events.AddEvent(pEvent, m_Events.CalculateTime(msTime));
228 return;
229 }
230
231 //ASSERT(!IsPet());
232 if (IsPet())
233 {
234 ((Pet*)this)->Remove(PET_SAVE_NOT_IN_SLOT);
235 ASSERT(!IsInWorld());
236 return;
237 }
238
239 Unit* owner = GetSummoner();
240 if (owner && owner->GetTypeId() == TypeID::TYPEID_UNIT && owner->ToCreature()->IsAIEnabled)
241 owner->ToCreature()->AI()->SummonedCreatureDespawn(this);
242
244}
245
247{
248 m_owner.UnSummon();
249 return true;
250}
251
253{
254 if (!IsInWorld())
255 return;
256
257 if (m_Properties)
258 {
259 int32 slot = m_Properties->Slot;
260 if (slot > 0)
261 if (Unit* owner = GetSummoner())
262 if (owner->m_SummonSlot[slot] == GetGUID())
263 owner->m_SummonSlot[slot] = 0;
264 }
265
266 //if (GetOwnerGUID())
267 // SF_LOG_ERROR("entities.unit", "Unit %u has owner guid when removed from world", GetEntry());
268
270}
271
272Minion::Minion(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject)
273 : TempSummon(properties, owner, isWorldObject), m_owner(owner)
274{
280}
281
283{
284 TempSummon::InitStats(duration);
285
287
290
291 GetOwner()->SetMinion(this, true);
292}
293
295{
296 if (!IsInWorld())
297 return;
298
299 GetOwner()->SetMinion(this, false);
301}
302
304{
305 return IsPet() || (m_Properties && m_Properties->Category == SUMMON_CATEGORY_PET);
306}
307
308Guardian::Guardian(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) : Minion(properties, owner, isWorldObject), m_bonusSpellDamage(0)
309{
310 memset(m_statFromOwner, 0, sizeof(float) * MAX_STATS);
312 if (properties && properties->Type == SUMMON_TYPE_PET)
313 {
316 }
317}
318
330
332{
334
336 && GetOwner()->GetMinionGUID() == GetGUID()
337 && !GetOwner()->GetCharmGUID())
338 {
340 }
341}
342
343Puppet::Puppet(SummonPropertiesEntry const* properties, Unit* owner)
344 : Minion(properties, owner, false) //maybe true?
345{
346 ASSERT(m_owner->GetTypeId() == TypeID::TYPEID_PLAYER);
348}
349
351{
352 Minion::InitStats(duration);
355}
356
358{
361 ASSERT(false);
362}
363
365{
366 Minion::Update(time);
367 //check if caster is channelling?
368 if (IsInWorld())
369 {
370 if (!IsAlive())
371 {
372 UnSummon();
374 }
375 }
376}
377
379{
380 if (!IsInWorld())
381 return;
382
383 RemoveCharmedBy(NULL);
385}
std::int32_t int32
Definition Define.h:73
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
static constexpr TempSummonType TEMPSUMMON_MANUAL_DESPAWN
#define ASSERT
Definition Errors.h:29
#define SF_LOG_ERROR(filterType__,...)
Definition Log.h:143
@ TYPEID_PLAYER
Definition Object.h:55
@ TYPEID_UNIT
Definition Object.h:54
TempSummonType
Definition Object.h:67
@ TEMPSUMMON_MANUAL_DESPAWN
Definition Object.h:75
@ TEMPSUMMON_CORPSE_DESPAWN
Definition Object.h:72
@ TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN
Definition Object.h:69
@ TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT
Definition Object.h:71
@ TEMPSUMMON_TIMED_DESPAWN
Definition Object.h:70
@ TEMPSUMMON_DEAD_DESPAWN
Definition Object.h:74
@ TEMPSUMMON_TIMED_OR_DEAD_DESPAWN
Definition Object.h:68
@ TEMPSUMMON_CORPSE_TIMED_DESPAWN
Definition Object.h:73
@ PET_SAVE_NOT_IN_SLOT
Definition PetDefines.h:25
#define PET_FOLLOW_ANGLE
Definition PetDefines.h:58
#define MAX_STATS
@ SUMMON_TYPE_PET
@ SUMMON_CATEGORY_PET
@ UNIT_MASK_PUPPET
Definition Unit.h:811
@ UNIT_MASK_CONTROLABLE_GUARDIAN
Definition Unit.h:813
@ UNIT_MASK_SUMMON
Definition Unit.h:805
@ UNIT_MASK_GUARDIAN
Definition Unit.h:807
@ UNIT_MASK_MINION
Definition Unit.h:806
@ CORPSE
Definition Unit.h:505
@ CHARM_TYPE_POSSESS
Definition Unit.h:1218
@ REACT_PASSIVE
Definition Unit.h:1156
@ REACT_AGGRESSIVE
Definition Unit.h:1158
virtual void JustSummoned(Creature *)
Definition CreatureAI.h:98
virtual void IsSummonedBy(Unit *)
Definition CreatureAI.h:99
virtual void SummonedCreatureDespawn(Creature *)
Definition CreatureAI.h:101
bool IsTrigger() const
Definition Creature.h:454
void SetReactState(ReactStates st)
Definition Creature.h:460
void Update(uint32 time) OVERRIDE
Definition Creature.cpp:446
Creature(bool isWorldObject=false)
Definition Creature.cpp:141
uint32 m_spells[CREATURE_MAX_SPELLS]
Definition Creature.h:565
CreatureAI * AI() const
Definition Creature.h:483
void RemoveFromWorld() OVERRIDE
Definition Creature.cpp:193
bool Execute(uint64 e_time, uint32 p_time) OVERRIDE
Guardian(SummonPropertiesEntry const *properties, Unit *owner, bool isWorldObject)
void InitSummon() OVERRIDE
int32 m_bonusSpellDamage
bool InitStatsForLevel(uint8 level)
Definition Pet.cpp:828
void InitStats(uint32 duration) OVERRIDE
float m_statFromOwner[MAX_STATS]
Creature * GetCreature(uint64 guid)
Definition Map.cpp:3179
float m_followAngle
Unit * GetOwner() const
Unit *const m_owner
bool IsGuardianPet() const
void InitStats(uint32 duration) OVERRIDE
Minion(SummonPropertiesEntry const *properties, Unit *owner, bool isWorldObject)
void RemoveFromWorld() OVERRIDE
static Creature * GetCreature(WorldObject const &u, uint64 guid)
static Unit * GetUnit(WorldObject const &, uint64 guid)
uint64 GetGUID() const
Definition Object.h:119
Player * ToPlayer()
Definition Object.h:204
bool IsInWorld() const
Definition Object.h:114
TypeID GetTypeId() const
Definition Object.h:131
uint32 GetEntry() const
Definition Object.h:125
Creature * ToCreature()
Definition Object.h:207
Definition Pet.h:28
void CharmSpellInitialize()
Definition Player.cpp:16142
void InitStats(uint32 duration) OVERRIDE
void Update(uint32 time) OVERRIDE
Puppet(SummonPropertiesEntry const *properties, Unit *owner)
void InitSummon() OVERRIDE
void RemoveFromWorld() OVERRIDE
TempSummon(SummonPropertiesEntry const *properties, Unit *owner, bool isWorldObject)
virtual void UnSummon(uint32 msTime=0)
const SummonPropertiesEntry *const m_Properties
void Update(uint32 time) OVERRIDE
virtual void InitSummon()
void SetTempSummonType(TempSummonType type)
virtual void InitStats(uint32 lifetime)
uint64 m_summonerGUID
TempSummonType m_type
Unit * GetSummoner() const
Creature * GetSummonerCreatureBase() const
uint32 m_lifetime
void RemoveFromWorld() OVERRIDE
Definition Unit.h:1367
bool IsVehicle() const
Definition Unit.h:1523
void SetMinion(Minion *minion, bool apply)
Definition Unit.cpp:2432
void setFaction(uint32 faction)
Definition Unit.h:1699
uint64 GetCharmGUID() const
Definition Unit.h:2079
uint32 getFaction() const
Definition Unit.h:1695
void SetCreatorGUID(uint64 creator)
Definition Unit.h:2059
CharmInfo * m_charmInfo
Definition Unit.h:2918
bool IsPet() const
Definition Unit.h:1511
bool SetCharmedBy(Unit *charmer, CharmType type, AuraApplication const *aurApp=NULL)
Definition Unit.cpp:6878
uint64 m_SummonSlot[MAX_SUMMON_SLOT]
Definition Unit.h:2374
bool IsAlive() const
Definition Unit.h:2032
DeathState m_deathState
Definition Unit.h:2883
uint32 m_unitTypeMask
Definition Unit.h:2935
uint64 GetMinionGUID() const
Definition Unit.h:2063
TempSummon * ToTempSummon()
Definition Unit.h:2821
bool m_ControlledByPlayer
Definition Unit.h:2758
EventProcessor m_Events
Definition Unit.h:2396
bool IsSummon() const
Definition Unit.h:1503
void RemoveCharmedBy(Unit *charmer)
Definition Unit.cpp:7029
bool IsAIEnabled
Definition Unit.h:2735
Unit(bool isWorldObject)
Definition Unit.cpp:142
CharmInfo * InitCharmInfo()
Definition Unit.cpp:5518
uint32 HasUnitTypeMask(uint32 mask) const
Definition Unit.h:1495
uint8 getLevel() const
Definition Unit.h:1528
void SetLevel(uint8 lvl)
Definition Unit.cpp:5150
bool IsInCombat() const
Definition Unit.h:1896
Map * GetMap() const
Definition Object.h:740
void AddObjectToRemoveList()
Definition Object.cpp:2550
uint32 Type