OregonCore  revision fb2a440-git
Your Favourite TBC server
TemporarySummon.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 "Log.h"
19 #include "ObjectAccessor.h"
20 #include "CreatureAI.h"
21 #include "TemporarySummon.h"
22 
23 TempSummon::TempSummon(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) :
24 Creature(isWorldObject), m_Properties(properties), m_type(TEMPSUMMON_MANUAL_DESPAWN), m_timer(0), m_lifetime(0)
25 {
26  m_summonerGUID = owner ? owner->GetGUID() : 0;
28 }
29 
31 {
33 }
34 
36 {
37  Creature::Update(diff);
38 
39  if (m_deathState == DEAD)
40  {
41  UnSummon();
42  return;
43  }
44  switch (m_type)
45  {
47  break;
49  {
50  if (m_timer <= diff)
51  {
52  UnSummon();
53  return;
54  }
55 
56  m_timer -= diff;
57  break;
58  }
60  {
61  if (!IsInCombat())
62  {
63  if (m_timer <= diff)
64  {
65  UnSummon();
66  return;
67  }
68 
69  m_timer -= diff;
70  }
71  else if (m_timer != m_lifetime)
73 
74  break;
75  }
76 
78  {
79  if (m_deathState == CORPSE)
80  {
81  if (m_timer <= diff)
82  {
83  UnSummon();
84  return;
85  }
86 
87  m_timer -= diff;
88  }
89  break;
90  }
92  if (!isCharmed())
93  {
94  if (m_timer <= diff)
95  {
96  UnSummon();
97  return;
98  }
99  else
100  m_timer -= diff;
101  }
102  break;
104  {
105  // if m_deathState is DEAD, CORPSE was skipped
106  if (m_deathState == CORPSE || m_deathState == DEAD)
107  {
108  UnSummon();
109  return;
110  }
111 
112  break;
113  }
115  {
116  if (m_deathState == DEAD)
117  {
118  UnSummon();
119  return;
120  }
121  break;
122  }
124  {
125  // if m_deathState is DEAD, CORPSE was skipped
126  if (m_deathState == CORPSE || m_deathState == DEAD)
127  {
128  UnSummon();
129  return;
130  }
131 
132  if (!IsInCombat())
133  {
134  if (m_timer <= diff)
135  {
136  UnSummon();
137  return;
138  }
139  else
140  m_timer -= diff;
141  }
142  else if (m_timer != m_lifetime)
144  break;
145  }
147  {
148  // if m_deathState is DEAD, CORPSE was skipped
149  if (m_deathState == DEAD)
150  {
151  UnSummon();
152  return;
153  }
154 
155  if (!IsInCombat() && IsAlive())
156  {
157  if (m_timer <= diff)
158  {
159  UnSummon();
160  return;
161  }
162  else
163  m_timer -= diff;
164  }
165  else if (m_timer != m_lifetime)
167  break;
168  }
169  default:
170  UnSummon();
171  sLog.outError("Temporary summoned creature (entry: %u) has unknown type %u. ", GetEntry(), m_type);
172  break;
173  }
174 }
175 
177 {
178  ASSERT(!IsPet());
179 
180  m_timer = duration;
181  m_lifetime = duration;
182 
185 
186  Unit* owner = GetSummoner();
187 
188  if (owner && IsTrigger() && m_spells[0])
189  {
190  SetFaction(owner->GetFaction());
191  SetLevel(owner->getLevel());
192  if (owner->GetTypeId() == TYPEID_PLAYER)
193  m_ControlledByPlayer = true;
194  }
195 
196  if (!m_Properties)
197  return;
198 
199  if (owner)
200  {
201  if (uint32 slot = m_Properties->Slot)
202  {
203  if (owner->m_SummonSlot[slot] && owner->m_SummonSlot[slot] != GetGUID())
204  {
205  Creature* oldSummon = GetMap()->GetCreature(owner->m_SummonSlot[slot]);
206  if (oldSummon && oldSummon->IsSummon())
207  ((TempSummon*)oldSummon)->UnSummon();
208  }
209  owner->m_SummonSlot[slot] = GetGUID();
210  }
211  }
212 
213  if (m_Properties->Faction)
215 }
216 
218 {
219  Unit* owner = GetSummoner();
220  if (owner)
221  {
222  if (owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->IsAIEnabled)
223  owner->ToCreature()->AI()->JustSummoned(this);
224  if (IsAIEnabled)
225  AI()->IsSummonedBy(owner);
226  }
227 }
228 
230 {
231  m_type = type;
232 }
233 
235 {
236  if (msTime)
237  {
238  UnsummonDelayEvent* pEvent = new UnsummonDelayEvent(*this);
239 
240  m_Events.AddEvent(pEvent, m_Events.CalculateTime(msTime));
241  return;
242  }
243 
244  if (IsPet())
245  {
246  ((Pet*)this)->Remove(PET_SAVE_NOT_IN_SLOT);
247  ASSERT(!IsInWorld());
248  return;
249  }
250 
251  Unit* owner = GetSummoner();
252  if (owner && owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->IsAIEnabled)
253  owner->ToCreature()->AI()->SummonedCreatureDespawn(this);
254 
256 }
257 
258 bool UnsummonDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
259 {
260  if (TempSummon* summon = m_owner.ToTempSummon())
261  summon->UnSummon();
262 
263  return true;
264 }
265 
267 {
268  if (!IsInWorld())
269  return;
270 
271  if (m_Properties)
272  if (uint32 slot = m_Properties->Slot)
273  if (Unit* owner = GetSummoner())
274  if (owner->m_SummonSlot[slot] == GetGUID())
275  owner->m_SummonSlot[slot] = 0;
276 
277  //if (GetOwnerGUID())
278  // sLog.outError("Unit %u has owner guid when removed from world", GetEntry());
279 
281 }
282 
284 {
285 }
286 
287 Minion::Minion(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) : TempSummon(properties, owner, isWorldObject)
288  , m_owner(owner)
289 {
290  ASSERT(m_owner);
293 }
294 
295 void Minion::InitStats(uint32 duration)
296 {
297  TempSummon::InitStats(duration);
298 
300 
303 
304  m_owner->SetMinion(this, true);
305 }
306 
308 {
309  if (!IsInWorld())
310  return;
311 
312  m_owner->SetMinion(this, false);
314 }
315 
317 {
319 }
320 
321 Guardian::Guardian(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) : Minion(properties, owner, isWorldObject)
322  , m_bonusdamage(0)
323 {
325  if (properties && (properties->Type == SUMMON_TYPE_PET || properties->Category == SUMMON_CATEGORY_PET))
326  {
328  InitCharmInfo();
329  }
330 }
331 
333 {
334  Minion::InitStats(duration);
335 
337 
340 
342 }
343 
345 {
347 
349  && m_owner->GetMinionGUID() == GetGUID()
350  && !m_owner->GetCharmGUID())
352 }
353 
354 Puppet::Puppet(SummonPropertiesEntry const* properties, Unit* owner) : Minion(properties, owner, false) //maybe true?
355 {
356  ASSERT(owner->GetTypeId() == TYPEID_PLAYER);
357  m_owner = owner->ToPlayer();
359 }
360 
361 void Puppet::InitStats(uint32 duration)
362 {
363  Minion::InitStats(duration);
366 }
367 
369 {
372 }
373 
375 {
376  Minion::Update(time);
377  //check if caster is channelling?
378  if (IsInWorld() && !IsAlive())
379  {
380  UnSummon();
382  }
383 }
384 
386 {
387  if (!IsInWorld())
388  return;
389 
390  RemoveCharmedBy(NULL);
392 }
393 
despawns when UnSummon() is called
void RemoveFromWorld() override
EventProcessor m_Events
Definition: Unit.h:1636
float m_followAngle
uint64 GetCharmGUID() const
Definition: Unit.h:1370
Definition: Unit.h:440
const uint32 & GetUInt32Value(uint16 index) const
Definition: Object.h:234
TempSummon(SummonPropertiesEntry const *properties, Unit *owner, bool isWorldObject)
bool m_ControlledByPlayer
Definition: Unit.h:1992
Guardian(SummonPropertiesEntry const *properties, Unit *owner, bool isWorldObject)
void CharmSpellInitialize()
Definition: Player.cpp:17438
void Update(uint32 time) override
Map * GetMap() const
Definition: Object.h:841
uint32 GetFaction() const
Definition: Unit.h:1116
uint64 m_summonerGUID
void InitCharmCreateSpells()
Definition: Unit.cpp:11316
pet will not attack
Definition: Unit.h:760
void InitStats(uint32 duration) override
uint64 GetMinionGUID() const
Definition: Unit.h:1354
void AddEvent(BasicEvent *Event, uint64 e_time, bool set_addtime=true)
#define PET_FOLLOW_ANGLE
virtual void IsSummonedBy(Unit *)
Definition: CreatureAI.h:120
bool IsInCombat() const
Definition: Unit.h:1243
CharmInfo * m_charmInfo
Definition: Unit.h:2050
#define sLog
Log class singleton.
Definition: Log.h:187
decharms after a specified time after the cresture is out of charm
NULL Dbg ErrDB Arena Chat Char Map MMap false
Definition: Log.cpp:556
bool IsTrigger() const
Definition: Creature.h:489
uint64 CalculateTime(uint64 t_offset)
Definition: Unit.h:439
despawns after a specified time OR when the creature dies
void SetMinion(Minion *minion, bool apply)
Definition: Unit.cpp:7705
bool IsAIEnabled
Definition: Unit.h:1990
uint64 m_SummonSlot[MAX_SUMMON_SLOT]
Definition: Unit.h:1607
void InitSummon() override
Unit * GetSummoner() const
void RemoveFromWorld() override
Player * ToPlayer()
Definition: Object.h:392
uint8 getLevel() const
Definition: Unit.h:1057
TempSummon * ToTempSummon()
Definition: Unit.h:1998
void UnSummon(uint32 msTime=0)
despawns when the creature disappears
despawns after a specified time
uint8 GetTypeId() const
Definition: Object.h:210
bool Execute(uint64 e_time, uint32 p_time) override
bool InitStatsForLevel(uint32 level)
Definition: Pet.cpp:967
uint32 m_spells[CREATURE_MAX_SPELLS]
Definition: Creature.h:604
void SaveToDB() override
Creature * GetCreature(uint64 guid)
Definition: Map.cpp:2630
void SetCharmedBy(Unit *charmer, CharmType type)
Definition: Unit.cpp:13110
const bool & IsInWorld() const
Definition: Object.h:135
void AddObjectToRemoveList()
Definition: Object.cpp:1990
SummonPropertiesEntry const * m_Properties
bool IsAlive() const
Definition: Unit.h:1336
DeathState m_deathState
Definition: Unit.h:2022
Minion(SummonPropertiesEntry const *properties, Unit *owner, bool isWorldObject)
CreatureAI * AI() const
Definition: Creature.h:517
TempSummonType
void InitSummon() override
despawns after a specified time after the creature is out of combat
Puppet(SummonPropertiesEntry const *properties, Unit *owner)
Unit *const m_owner
bool IsGuardianPet() const
void RemoveFromWorld() override
void InitStats(uint32 duration) override
bool IsPet() const
Definition: Unit.h:1048
ACE_UINT64 uint64
Definition: Define.h:70
uint32 m_lifetime
despawns after a specified time OR when the creature disappears
Player * m_owner
despawns after a specified time after death
TempSummonType m_type
virtual void InitSummon()
void RemoveFromWorld() override
Definition: Creature.cpp:196
Creature * ToCreature()
Definition: Object.h:395
void RemoveCharmedBy(Unit *charmer)
Definition: Unit.cpp:13223
void SetFaction(uint32 faction)
Definition: Unit.h:1117
uint32 m_unitTypeMask
Definition: Unit.h:2049
void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid=0, bool withInstant=true)
Definition: Unit.cpp:3576
CharmInfo * InitCharmInfo()
Definition: Unit.cpp:11221
uint32 HasUnitTypeMask(uint32 mask) const
Definition: Unit.h:1044
#define ASSERT
Definition: Errors.h:29
void Update(uint32 time) override
Definition: Creature.cpp:472
static Unit * GetUnit(WorldObject const &, uint64 guid)
void SetTempSummonType(TempSummonType type)
void SetLevel(uint32 lvl)
Definition: Unit.cpp:10896
virtual void InitStats(uint32 lifetime)
uint32 GetEntry() const
Definition: Object.h:192
void Update(uint32 time) override
void SetCreatorGUID(uint64 creator)
Definition: Unit.h:1350
bool isCharmed() const
Definition: Unit.h:1434
void InitStats(uint32 duration) override
ACE_UINT32 uint32
Definition: Define.h:71
virtual void SummonedCreatureDespawn(Creature *)
Definition: CreatureAI.h:122
bool IsSummon() const
Definition: Unit.h:1046
despawns instantly after death
Definition: Unit.h:908
void SetReactState(ReactStates st)
Definition: Creature.h:495
uint32 m_timer
virtual void JustSummoned(Creature *)
Definition: CreatureAI.h:119
Definition: Pet.h:146
const uint64 & GetGUID() const
Definition: Object.h:162