OregonCore  revision fb2a440-git
Your Favourite TBC server
DynamicObject.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 "Common.h"
19 #include "GameObject.h"
20 #include "UpdateMask.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "ObjectAccessor.h"
25 #include "Database/DatabaseEnv.h"
26 #include "SpellAuras.h"
27 #include "MapManager.h"
28 #include "GridNotifiers.h"
29 #include "CellImpl.h"
30 #include "GridNotifiersImpl.h"
31 
32 DynamicObject::DynamicObject(bool isWorldObject) : WorldObject(isWorldObject)
33 {
36 
38 
40 }
41 
43 {
44  // Register the dynamicObject for guid lookup
45  if (!IsInWorld())
46  {
49  }
50 }
51 
53 {
54  // Remove the dynamicObject from the accessor
55  if (IsInWorld())
56  {
57  if (m_isWorldObject)
58  {
59  if (Unit* caster = GetCaster())
60  {
61  if (caster->GetTypeId() == TYPEID_PLAYER)
62  caster->ToPlayer()->SetViewpoint(this, false);
63  }
64  else
65  sLog.outError("Crash alert! DynamicObject::RemoveFromWorld cannot find viewpoint owner");
66  }
69  }
70 }
71 
72 bool DynamicObject::CreateDynamicObject(uint32 guidlow, Unit* caster, uint32 spellId, uint32 effIndex, const Position& pos, int32 duration, float radius)
73 {
74  SetMap(caster->GetMap());
75  Relocate(pos);
76  if (!IsPositionValid())
77  {
78  sLog.outError("DynamicObject (spell %u eff %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)", spellId, effIndex, GetPositionX(), GetPositionY());
79  return false;
80  }
81 
83 
84  SetEntry(spellId);
85  SetObjectScale(1);
87 
88  // The lower word of DYNAMICOBJECT_BYTES must be 0x0001. This value means that the visual radius will be overriden
89  // by client for most of the "ground patch" visual effect spells and a few "skyfall" ones like Hurricane.
90  // If any other value is used, the client will _always_ use the radius provided in DYNAMICOBJECT_RADIUS, but
91  // precompensation is necessary (eg radius *= 2) for many spells. Anyway, blizz sends 0x0001 for all the spells
92  // I saw sniffed...
93  SetByteValue(DYNAMICOBJECT_BYTES, 0, 0x00000001);
97 
98  if (IsWorldObject())
99  setActive(true); //must before add to map to be put in world container
100 
101  if (!GetMap()->AddToMap(this))
102  return false;
103 
104  m_aliveDuration = duration;
105  m_radius = radius;
106  m_effIndex = effIndex;
107  m_spellId = spellId;
108  m_casterGuid = caster->GetGUID();
109  m_updateTimer = 0;
110 
111  return true;
112 }
113 
115 {
116  // can be not found in some cases
117  return ObjectAccessor::GetUnit(*this, GetCasterGUID());
118 }
119 
121 {
122  // caster can be not in world at time dynamic object update, but dynamic object not yet deleted in Unit destructor
123  Unit* caster = GetCaster();
124  if (!caster)
125  {
126  Remove();
127  return;
128  }
129 
130  bool expired = false;
131 
132  if (m_aliveDuration > int32(p_time))
133  m_aliveDuration -= p_time;
134  else
135  expired = true;
136 
137  if (m_effIndex < 4)
138  {
139  if (m_updateTimer < p_time)
140  {
141  Oregon::DynamicObjectUpdater notifier(*this, caster);
142  VisitNearbyObject(GetRadius(), notifier);
143  m_updateTimer = 500; // is this official-like?
144  }
145  else m_updateTimer -= p_time;
146  }
147 
148  if (expired)
149  {
150  caster->RemoveDynObjectWithGUID(GetGUID());
151  Remove();
152  }
153 }
154 
156 {
157  if (IsInWorld())
158  {
160  RemoveFromWorld();
162  }
163 }
164 
166 {
167  m_aliveDuration -= delaytime;
168  for (AffectedSet::iterator iunit = m_affected.begin(); iunit != m_affected.end(); ++iunit)
169  if (*iunit)
170  (*iunit)->DelayAura(m_spellId, m_effIndex, delaytime);
171 }
AffectedSet m_affected
void _Create(uint32 guidlow, HighGuid guidhigh, uint32 phaseMask)
Definition: Object.cpp:1162
const bool m_isWorldObject
Definition: Object.h:933
uint32 m_updateTimer
Map * GetMap() const
Definition: Object.h:841
Unit * GetCaster() const
void SetObjectScale(float scale)
Definition: Object.h:205
void setActive(bool isActiveObject)
Definition: Object.cpp:1123
virtual void SetMap(Map *map)
Definition: Object.cpp:1954
uint32 getMSTime()
Definition: Timer.h:32
void AddObject(T *object)
#define sLog
Log class singleton.
Definition: Log.h:187
void SetUInt32Value(uint16 index, uint32 value)
Definition: Object.cpp:779
ACE_INT32 int32
Definition: Define.h:67
bool IsWorldObject() const
Definition: Object.cpp:1112
void SetEntry(uint32 entry)
Definition: Object.h:196
uint16 m_objectType
Definition: Object.h:424
uint64 m_casterGuid
void VisitNearbyObject(float const &radius, NOTIFIER &notifier) const
Definition: Object.h:921
uint8 m_objectTypeId
Definition: Object.h:426
void Relocate(float x, float y)
Definition: Position.h:65
void AddToWorld() override
const bool & IsInWorld() const
Definition: Object.h:135
bool CreateDynamicObject(uint32 guidlow, Unit *caster, uint32 spellId, uint32 effIndex, const Position &pos, int32 duration, float radius)
void AddObjectToRemoveList()
Definition: Object.cpp:1990
uint32 GetPhaseMask() const
Definition: Object.h:694
float GetPositionY() const
Definition: Position.h:98
uint8 m_updateFlag
Definition: Object.h:427
void SetByteValue(uint16 index, uint8 offset, uint8 value)
Definition: Object.cpp:878
virtual void RemoveFromWorld() override
Definition: Object.cpp:1169
DynamicObject(bool isWorldObject)
void Update(uint32 p_time) override
int32 m_aliveDuration
void SetUInt64Value(uint16 index, const uint64 &value)
Definition: Object.cpp:798
void RemoveObject(T *object)
virtual void AddToWorld()
Definition: Object.h:139
void SendObjectDeSpawnAnim(uint64 guid)
Definition: Object.cpp:1939
void Delay(int32 delaytime)
float GetRadius() const
Definition: DynamicObject.h:55
void SetFloatValue(uint16 index, float value)
Definition: Object.cpp:859
uint16 m_valuesCount
Definition: Object.h:438
uint64 GetCasterGUID() const
Definition: DynamicObject.h:50
static Unit * GetUnit(WorldObject const &, uint64 guid)
bool IsPositionValid() const
Definition: Position.cpp:40
void RemoveFromWorld() override
ACE_UINT32 uint32
Definition: Define.h:71
float GetPositionX() const
Definition: Position.h:97
void RemoveDynObjectWithGUID(uint64 guid)
Definition: Unit.h:1805
Definition: Unit.h:908
const uint64 & GetGUID() const
Definition: Object.h:162