aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities/Object
diff options
context:
space:
mode:
authorSubv <subv2112@gmail.com>2014-06-01 22:27:29 -0500
committerSubv <subv2112@gmail.com>2014-06-01 22:27:29 -0500
commit48ec2df81fa8f88cd32d7a79b587603aedbd89e0 (patch)
tree1a6404c63979ee20a39f8b577db21541b37739c5 /src/server/game/Entities/Object
parent6bc62d730ed08e6e12d9b57d4914e98019298781 (diff)
Core/Phases: Preliminary work with correctly implementing the phase system in 4.3.4
Put here for peer review.
Diffstat (limited to 'src/server/game/Entities/Object')
-rw-r--r--src/server/game/Entities/Object/Object.cpp47
-rw-r--r--src/server/game/Entities/Object/Object.h5
2 files changed, 49 insertions, 3 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index a2fd19c443c..24e4a7b82ce 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -1493,7 +1493,7 @@ bool WorldObject::IsWithinDist(WorldObject const* obj, float dist2compare, bool
bool WorldObject::IsWithinDistInMap(WorldObject const* obj, float dist2compare, bool is3D /*= true*/) const
{
- return obj && IsInMap(obj) && InSamePhase(obj) && _IsWithinDist(obj, dist2compare, is3D);
+ return obj && IsInMap(obj) && IsInPhase(obj) && _IsWithinDist(obj, dist2compare, is3D);
}
bool WorldObject::IsWithinLOS(float ox, float oy, float oz) const
@@ -1932,7 +1932,7 @@ bool WorldObject::CanSeeOrDetect(WorldObject const* obj, bool ignoreStealth, boo
bool WorldObject::CanNeverSee(WorldObject const* obj) const
{
- return GetMap() != obj->GetMap() || !InSamePhase(obj);
+ return GetMap() != obj->GetMap() || !IsInPhase(obj);
}
bool WorldObject::CanDetect(WorldObject const* obj, bool ignoreStealth) const
@@ -2330,8 +2330,12 @@ TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropert
}
uint32 phase = PHASEMASK_NORMAL;
+ std::set<uint32> phases;
if (summoner)
+ {
phase = summoner->GetPhaseMask();
+ phases = summoner->GetPhases();
+ }
TempSummon* summon = NULL;
switch (mask)
@@ -2359,6 +2363,10 @@ TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropert
return NULL;
}
+ // Set the summon to the summoner's phase
+ for (auto phaseId : phases)
+ summon->SetInPhase(phaseId, false, true);
+
summon->SetUInt32Value(UNIT_CREATED_BY_SPELL, spellId);
summon->SetHomePosition(pos);
@@ -2453,6 +2461,9 @@ GameObject* WorldObject::SummonGameObject(uint32 entry, float x, float y, float
return NULL;
}
+ for (auto phase : GetPhases())
+ go->SetInPhase(phase, false, true);
+
go->SetRespawnTime(respawnTime);
if (GetTypeId() == TYPEID_PLAYER || GetTypeId() == TYPEID_UNIT) //not sure how to handle this
ToUnit()->AddGameObject(go);
@@ -2835,9 +2846,39 @@ void WorldObject::SetPhaseMask(uint32 newPhaseMask, bool update)
UpdateObjectVisibility();
}
+void WorldObject::SetInPhase(uint32 id, bool update, bool apply)
+{
+ if (apply)
+ _phases.insert(id);
+ else
+ _phases.erase(id);
+
+ if (update && IsInWorld())
+ UpdateObjectVisibility();
+}
+
+bool WorldObject::IsInPhase(WorldObject const* obj) const
+{
+ // PhaseId 169 is the default fallback phase
+ if (_phases.empty() && obj->GetPhases().empty())
+ return true;
+
+ if (_phases.empty() && obj->IsInPhase(169))
+ return true;
+
+ if (obj->GetPhases().empty() && IsInPhase(169))
+ return true;
+
+ for (auto phase : _phases)
+ if (obj->IsInPhase(phase))
+ return true;
+ return false;
+}
+
bool WorldObject::InSamePhase(WorldObject const* obj) const
{
- return InSamePhase(obj->GetPhaseMask());
+ return IsInPhase(obj);
+ // return InSamePhase(obj->GetPhaseMask());
}
void WorldObject::PlayDistanceSound(uint32 sound_id, Player* target /*= NULL*/)
diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h
index 5e525f1e0d5..2d7a6f12016 100644
--- a/src/server/game/Entities/Object/Object.h
+++ b/src/server/game/Entities/Object/Object.h
@@ -676,9 +676,13 @@ class WorldObject : public Object, public WorldLocation
uint32 GetInstanceId() const { return m_InstanceId; }
virtual void SetPhaseMask(uint32 newPhaseMask, bool update);
+ virtual void SetInPhase(uint32 id, bool update, bool apply);
uint32 GetPhaseMask() const { return m_phaseMask; }
bool InSamePhase(WorldObject const* obj) const;
bool InSamePhase(uint32 phasemask) const { return (GetPhaseMask() & phasemask); }
+ bool IsInPhase(uint32 phase) const { return _phases.find(phase) != _phases.end(); }
+ bool IsInPhase(WorldObject const* obj) const;
+ std::set<uint32> const& GetPhases() const { return _phases; }
uint32 GetZoneId() const;
uint32 GetAreaId() const;
@@ -861,6 +865,7 @@ class WorldObject : public Object, public WorldLocation
//uint32 m_mapId; // object at map with map_id
uint32 m_InstanceId; // in map copy with instance id
uint32 m_phaseMask; // in area phase state
+ std::set<uint32> _phases;
uint16 m_notifyflags;
uint16 m_executed_notifies;