diff --git a/src/common/Collision/Management/IVMapManager.h b/src/common/Collision/Management/IVMapManager.h index 2a633d32542..31ea635a091 100644 --- a/src/common/Collision/Management/IVMapManager.h +++ b/src/common/Collision/Management/IVMapManager.h @@ -126,8 +126,6 @@ namespace VMAP virtual bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float &level, float &floor, uint32 &type) const=0; // get both area + liquid data in a single vmap lookup virtual void getAreaAndLiquidData(unsigned int mapId, float x, float y, float z, uint8 reqLiquidType, AreaAndLiquidData& data) const=0; - - virtual int32 GetDistanceToClosestPrimaryTile(uint32 mapId, int32 x, int32 y) const = 0; }; } diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager2.cpp index 91e4547149c..591be582593 100644 --- a/src/common/Collision/Management/VMapManager2.cpp +++ b/src/common/Collision/Management/VMapManager2.cpp @@ -345,15 +345,6 @@ namespace VMAP } } - int32 VMapManager2::GetDistanceToClosestPrimaryTile(uint32 mapId, int32 x, int32 y) const - { - auto instanceTree = GetMapTree(mapId); - if (instanceTree != iInstanceMapTrees.end()) - return instanceTree->second->GetDistanceToClosestPrimaryTile(x, y); - - return std::numeric_limits::max(); - } - WorldModel* VMapManager2::acquireModelInstance(const std::string& basepath, const std::string& filename, uint32 flags/* Only used when creating the model */) { //! Critical section, thread safe access to iLoadedModelFiles diff --git a/src/common/Collision/Management/VMapManager2.h b/src/common/Collision/Management/VMapManager2.h index a58e34cfa78..75e43d420d1 100644 --- a/src/common/Collision/Management/VMapManager2.h +++ b/src/common/Collision/Management/VMapManager2.h @@ -124,8 +124,6 @@ namespace VMAP bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 reqLiquidType, float& level, float& floor, uint32& type) const override; void getAreaAndLiquidData(unsigned int mapId, float x, float y, float z, uint8 reqLiquidType, AreaAndLiquidData& data) const override; - int32 GetDistanceToClosestPrimaryTile(uint32 mapId, int32 x, int32 y) const override; - WorldModel* acquireModelInstance(const std::string& basepath, const std::string& filename, uint32 flags = 0); void releaseModelInstance(const std::string& filename); diff --git a/src/common/Collision/Maps/MapTree.cpp b/src/common/Collision/Maps/MapTree.cpp index 55b5eb8fadf..42489dda581 100644 --- a/src/common/Collision/Maps/MapTree.cpp +++ b/src/common/Collision/Maps/MapTree.cpp @@ -241,7 +241,6 @@ namespace VMAP TileFileOpenResult result; result.Name = basePath + getTileFileName(mapID, tileX, tileY); result.File = fopen(result.Name.c_str(), "rb"); - result.IsPrimary = true; if (!result.File) { int32 parentMapId = vm->getParentMapId(mapID); @@ -249,7 +248,6 @@ namespace VMAP { result.Name = basePath + getTileFileName(parentMapId, tileX, tileY); result.File = fopen(result.Name.c_str(), "rb"); - result.IsPrimary = false; } } @@ -372,7 +370,6 @@ namespace VMAP } iLoadedSpawns.clear(); iLoadedTiles.clear(); - iLoadedPrimaryTiles.clear(); } //========================================================= @@ -449,8 +446,6 @@ namespace VMAP } } iLoadedTiles[packTileID(tileX, tileY)] = true; - if (fileResult.IsPrimary) - iLoadedPrimaryTiles.emplace_back(tileX, tileY); fclose(fileResult.File); } else @@ -512,8 +507,6 @@ namespace VMAP } } iLoadedTiles.erase(tile); - iLoadedPrimaryTiles.erase(std::remove_if(iLoadedPrimaryTiles.begin(), iLoadedPrimaryTiles.end(), - [tileX, tileY](std::pair const& p) { return p.first == tileX && p.second == tileY; }), iLoadedPrimaryTiles.end()); TC_METRIC_EVENT("map_events", "UnloadMapTile", "Map: " + std::to_string(iMapID) + " TileX: " + std::to_string(tileX) + " TileY: " + std::to_string(tileY)); } @@ -523,13 +516,4 @@ namespace VMAP models = iTreeValues; count = iNTreeValues; } - - int32 StaticMapTree::GetDistanceToClosestPrimaryTile(int32 x, int32 y) const - { - int32 minDistance = std::numeric_limits::max(); - for (std::pair const& primaryTile : iLoadedPrimaryTiles) - minDistance = std::min(minDistance, (primaryTile.first - x) * (primaryTile.first - x) + (primaryTile.second - y) * (primaryTile.second - y)); - - return minDistance; - } } diff --git a/src/common/Collision/Maps/MapTree.h b/src/common/Collision/Maps/MapTree.h index 8f9fdf1a6c7..7cc56813d9f 100644 --- a/src/common/Collision/Maps/MapTree.h +++ b/src/common/Collision/Maps/MapTree.h @@ -66,7 +66,6 @@ namespace VMAP { FILE* File; std::string Name; - bool IsPrimary; }; private: @@ -96,8 +95,6 @@ namespace VMAP uint32 numLoadedTiles() const { return uint32(iLoadedTiles.size()); } void getModelInstances(ModelInstance* &models, uint32 &count); - int32 GetDistanceToClosestPrimaryTile(int32 x, int32 y) const; - private: StaticMapTree(StaticMapTree const& right) = delete; StaticMapTree& operator=(StaticMapTree const& right) = delete; diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 4460dac48bc..af4d8d176b8 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2504,7 +2504,8 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float } destz = NormalizeZforCollision(this, destx, desty, pos.GetPositionZ()); - bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetPhaseShift().GetTerrainMapId(GetMapId(), pos.m_positionX, pos.m_positionY), pos.m_positionX, pos.m_positionY, pos.m_positionZ + 0.5f, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f); + bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(PhasingHandler::GetTerrainMapId(GetPhaseShift(), GetMap(), pos.m_positionX, pos.m_positionY), + pos.m_positionX, pos.m_positionY, pos.m_positionZ + 0.5f, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f); // collision occured if (col) diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index efede81689f..c46d6caebdf 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -2323,7 +2323,7 @@ float Map::GetStaticHeight(PhaseShift const& phaseShift, float x, float y, float { // find raw .map surface under Z coordinates float mapHeight = VMAP_INVALID_HEIGHT_VALUE; - uint32 terrainMapId = phaseShift.GetTerrainMapId(GetId(), x, y); + uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y); if (GridMap* gmap = const_cast(this)->GetGrid(terrainMapId, x, y)) { float gridHeight = gmap->getHeight(x, y); @@ -2408,7 +2408,7 @@ bool Map::IsOutdoors(PhaseShift const& phaseShift, float x, float y, float z) co bool Map::GetAreaInfo(PhaseShift const& phaseShift, float x, float y, float z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const { float vmap_z = z; - uint32 terrainMapId = phaseShift.GetTerrainMapId(GetId(), x, y); + uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y); VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); if (vmgr->getAreaInfo(terrainMapId, x, y, vmap_z, flags, adtId, rootId, groupId)) { @@ -2432,22 +2432,24 @@ uint32 Map::GetAreaId(PhaseShift const& phaseShift, float x, float y, float z, b WMOAreaTableEntry const* wmoEntry = nullptr; AreaTableEntry const* atEntry = nullptr; bool haveAreaInfo = false; + uint32 areaId = 0; if (GetAreaInfo(phaseShift, x, y, z, mogpFlags, adtId, rootId, groupId)) { haveAreaInfo = true; wmoEntry = GetWMOAreaTableEntryByTripple(rootId, adtId, groupId); if (wmoEntry) + { + areaId = wmoEntry->areaId; atEntry = sAreaTableStore.LookupEntry(wmoEntry->areaId); + + } } - uint32 areaId = 0; - if (atEntry) - areaId = atEntry->ID; - else + if (!areaId) { - if (GridMap* gmap = const_cast(this)->GetGrid(phaseShift.GetTerrainMapId(GetId(), x, y), x, y)) + if (GridMap* gmap = const_cast(this)->GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y)) areaId = gmap->getArea(x, y); // this used while not all *.map files generated (instances) @@ -2485,7 +2487,7 @@ void Map::GetZoneAndAreaId(PhaseShift const& phaseShift, uint32& zoneid, uint32& uint8 Map::GetTerrainType(PhaseShift const& phaseShift, float x, float y) const { - if (GridMap* gmap = const_cast(this)->GetGrid(phaseShift.GetTerrainMapId(GetId(), x, y), x, y)) + if (GridMap* gmap = const_cast(this)->GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y)) return gmap->getTerrainType(x, y); else return 0; @@ -2498,7 +2500,7 @@ ZLiquidStatus Map::GetLiquidStatus(PhaseShift const& phaseShift, float x, float float liquid_level = INVALID_HEIGHT; float ground_level = INVALID_HEIGHT; uint32 liquid_type = 0; - uint32 terrainMapId = phaseShift.GetTerrainMapId(GetId(), x, y); + uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y); if (vmgr->GetLiquidLevel(terrainMapId, x, y, z, ReqLiquidType, liquid_level, ground_level, liquid_type)) { TC_LOG_DEBUG("maps", "GetLiquidStatus(): vmap liquid level: %f ground: %f type: %u", liquid_level, ground_level, liquid_type); @@ -2680,7 +2682,7 @@ void Map::GetFullTerrainStatusForPosition(float x, float y, float z, PositionFul float Map::GetWaterLevel(PhaseShift const& phaseShift, float x, float y) const { - if (GridMap* gmap = const_cast(this)->GetGrid(phaseShift.GetTerrainMapId(GetId(), x, y), x, y)) + if (GridMap* gmap = const_cast(this)->GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y)) return gmap->getLiquidLevel(x, y); else return 0; @@ -2689,7 +2691,7 @@ float Map::GetWaterLevel(PhaseShift const& phaseShift, float x, float y) const bool Map::isInLineOfSight(PhaseShift const& phaseShift, float x1, float y1, float z1, float x2, float y2, float z2, LineOfSightChecks checks, VMAP::ModelIgnoreFlags ignoreFlags) const { if ((checks & LINEOFSIGHT_CHECK_VMAP) - && !VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(phaseShift.GetTerrainMapId(GetId(), x1, x2), x1, y1, z1, x2, y2, z2, ignoreFlags)) + && !VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(PhasingHandler::GetTerrainMapId(phaseShift, this, x1, y1), x1, y1, z1, x2, y2, z2, ignoreFlags)) return false; if (sWorld->getBoolConfig(CONFIG_CHECK_GOBJECT_LOS) && (checks & LINEOFSIGHT_CHECK_GOBJECT) && !_dynamicTree.isInLineOfSight({x1, y1, z1}, {x2, y2, z2}, phaseShift)) diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 794bc7e0df7..b001f6e8b6c 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -350,6 +350,7 @@ class TC_GAME_API Map : public GridRefManager time_t GetGridExpiry(void) const { return i_gridExpiry; } uint32 GetId(void) const { return i_mapEntry->MapID; } + bool HasGrid(int32 gx, int32 gy) const { return GridMaps[gx][gy] && GridMaps[gx][gy]->fileExists(); } static bool ExistMap(uint32 mapid, int gx, int gy); static bool ExistVMap(uint32 mapid, int gx, int gy); @@ -661,8 +662,6 @@ class TC_GAME_API Map : public GridRefManager void setNGrid(NGridType* grid, uint32 x, uint32 y); void ScriptsProcess(); - void UpdateActiveCells(const float &x, const float &y, const uint32 t_diff); - void SendObjectUpdates(); protected: diff --git a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp index 5d227eef3f9..0de1fd19870 100644 --- a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp @@ -24,6 +24,7 @@ #include "PathGenerator.h" #include "MoveSplineInit.h" #include "MoveSpline.h" +#include "PhasingHandler.h" #include "FleeingMovementGenerator.h" #define MIN_QUIET_DISTANCE 28.0f @@ -115,8 +116,13 @@ void FleeingMovementGenerator::SetTargetLocation(T* owner) GetPoint(owner, destination); // Add LOS check for target point - Position currentPosition = owner->GetPosition(); - if (!VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(owner->GetPhaseShift().GetTerrainMapId(owner->GetMapId(), currentPosition.m_positionX, currentPosition.m_positionY), currentPosition.m_positionX, currentPosition.m_positionY, currentPosition.m_positionZ + 1.0f, destination.GetPositionX(), destination.GetPositionY(), destination.GetPositionZ() + 1.0f, VMAP::ModelIgnoreFlags::Nothing)) + Position mypos = owner->GetPosition(); + bool isInLOS = VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight( + PhasingHandler::GetTerrainMapId(owner->GetPhaseShift(), owner->GetMap(), mypos.m_positionX, mypos.m_positionY), + mypos.m_positionX, mypos.m_positionY, mypos.m_positionZ + 2.0f, destination.m_positionX, destination.m_positionY, + destination.m_positionZ + 2.0f, VMAP::ModelIgnoreFlags::Nothing); + + if (!isInLOS) { _timer.Reset(200); return; diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp index 4755e8dfd54..28f6db39109 100644 --- a/src/server/game/Movement/PathGenerator.cpp +++ b/src/server/game/Movement/PathGenerator.cpp @@ -27,6 +27,7 @@ #include "DetourCommon.h" #include "DetourNavMeshQuery.h" #include "Metric.h" +#include "PhasingHandler.h" ////////////////// PathGenerator ////////////////// PathGenerator::PathGenerator(const Unit* owner) : @@ -39,7 +40,7 @@ PathGenerator::PathGenerator(const Unit* owner) : TC_LOG_DEBUG("maps", "++ PathGenerator::PathGenerator for %u \n", _sourceUnit->GetGUID().GetCounter()); - uint32 mapId = _sourceUnit->GetMapId(); + uint32 mapId = PhasingHandler::GetTerrainMapId(_sourceUnit->GetPhaseShift(), _sourceUnit->GetMap(), _sourceUnit->GetPositionX(), _sourceUnit->GetPositionY()); if (DisableMgr::IsPathfindingEnabled(mapId)) { MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager(); diff --git a/src/server/game/Phasing/PhaseShift.cpp b/src/server/game/Phasing/PhaseShift.cpp index 0762d958530..b2885ae15bb 100644 --- a/src/server/game/Phasing/PhaseShift.cpp +++ b/src/server/game/Phasing/PhaseShift.cpp @@ -17,12 +17,10 @@ #include "PhaseShift.h" #include "Containers.h" -#include "GridDefines.h" -#include "VMapFactory.h" -bool PhaseShift::AddPhase(uint32 phaseId, PhaseFlags flags, PhaseInfoStruct const* phase, std::vector const* areaConditions, int32 references /*= 1*/) +bool PhaseShift::AddPhase(uint32 phaseId, PhaseFlags flags, std::vector const* areaConditions, int32 references /*= 1*/) { - auto insertResult = Phases.emplace(phaseId, flags, phase, nullptr); + auto insertResult = Phases.emplace(phaseId, flags, nullptr); ModifyPhasesReferences(insertResult.first, references); if (areaConditions) insertResult.first->AreaConditions = areaConditions; @@ -32,7 +30,7 @@ bool PhaseShift::AddPhase(uint32 phaseId, PhaseFlags flags, PhaseInfoStruct cons PhaseShift::EraseResult PhaseShift::RemovePhase(uint32 phaseId) { - auto itr = Phases.find(PhaseRef(phaseId, PhaseFlags::None, nullptr, nullptr)); + auto itr = Phases.find(PhaseRef(phaseId, PhaseFlags::None, nullptr)); if (itr != Phases.end()) { ModifyPhasesReferences(itr, -1); @@ -147,33 +145,6 @@ bool PhaseShift::CanSee(PhaseShift const& other) const return checkInversePhaseShift(other, *this); } -uint32 PhaseShift::GetTerrainMapId(uint32 realMapId, float x, float y) const -{ - if (VisibleMapIds.empty()) - return realMapId; - - if (VisibleMapIds.size() == 1) - return VisibleMapIds.begin()->first; - - GridCoord gridCoord = Trinity::ComputeGridCoord(x, y); - int32 gx = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.x_coord; - int32 gy = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.y_coord; - - int32 minDistance = std::numeric_limits::max(); - uint32 terrainMapId; - for (auto itr = VisibleMapIds.begin(); itr != VisibleMapIds.end(); ++itr) - { - int32 dist = VMAP::VMapFactory::createOrGetVMapManager()->GetDistanceToClosestPrimaryTile(itr->first, gx, gy); - if (dist < minDistance) - { - minDistance = dist; - terrainMapId = itr->first; - } - } - - return terrainMapId; -} - void PhaseShift::ModifyPhasesReferences(PhaseContainer::iterator itr, int32 references) { itr->References += references; diff --git a/src/server/game/Phasing/PhaseShift.h b/src/server/game/Phasing/PhaseShift.h index a175410c40a..8755868ae9d 100644 --- a/src/server/game/Phasing/PhaseShift.h +++ b/src/server/game/Phasing/PhaseShift.h @@ -26,7 +26,6 @@ class PhasingHandler; struct Condition; -struct PhaseInfoStruct; struct TerrainSwapInfo; #define DEFAULT_PHASE 169 @@ -54,13 +53,12 @@ class TC_GAME_API PhaseShift public: struct PhaseRef { - PhaseRef(uint32 id, PhaseFlags flags, PhaseInfoStruct const* phaseInfo, std::vector const* conditions) - : Id(id), Flags(flags), References(0), PhaseInfo(phaseInfo), AreaConditions(conditions) { } + PhaseRef(uint32 id, PhaseFlags flags, std::vector const* conditions) + : Id(id), Flags(flags), References(0), AreaConditions(conditions) { } uint16 Id; EnumClassFlag Flags; int32 References; - PhaseInfoStruct const* PhaseInfo; std::vector const* AreaConditions; bool operator<(PhaseRef const& right) const { return Id < right.Id; } bool operator==(PhaseRef const& right) const { return Id == right.Id; } @@ -84,9 +82,9 @@ public: typedef std::map VisibleMapIdContainer; typedef std::map UiWorldMapAreaIdSwapContainer; - bool AddPhase(uint32 phaseId, PhaseFlags flags, PhaseInfoStruct const* phase, std::vector const* areaConditions, int32 references = 1); + bool AddPhase(uint32 phaseId, PhaseFlags flags, std::vector const* areaConditions, int32 references = 1); EraseResult RemovePhase(uint32 phaseId); - bool HasPhase(uint32 phaseId) const { return Phases.find(PhaseRef(phaseId, PhaseFlags::None, nullptr, nullptr)) != Phases.end(); } + bool HasPhase(uint32 phaseId) const { return Phases.find(PhaseRef(phaseId, PhaseFlags::None, nullptr)) != Phases.end(); } PhaseContainer const& GetPhases() const { return Phases; } bool AddVisibleMapId(uint32 visibleMapId, TerrainSwapInfo const* visibleMapInfo, int32 references = 1); @@ -103,7 +101,6 @@ public: void ClearPhases(); bool CanSee(PhaseShift const& other) const; - uint32 GetTerrainMapId(uint32 realMapId, float x, float y) const; protected: friend class PhasingHandler; diff --git a/src/server/game/Phasing/PhasingHandler.cpp b/src/server/game/Phasing/PhasingHandler.cpp index 1a07d1e5ec5..8b9e8843db5 100644 --- a/src/server/game/Phasing/PhasingHandler.cpp +++ b/src/server/game/Phasing/PhasingHandler.cpp @@ -61,7 +61,7 @@ inline void ForAllControlled(Unit* unit, Func&& func) void PhasingHandler::AddPhase(WorldObject* object, uint32 phaseId, bool updateVisibility) { - bool changed = object->GetPhaseShift().AddPhase(phaseId, GetPhaseFlags(phaseId), sObjectMgr->GetPhaseInfo(phaseId), nullptr); + bool changed = object->GetPhaseShift().AddPhase(phaseId, GetPhaseFlags(phaseId), nullptr); if (Unit* unit = object->ToUnit()) { @@ -101,7 +101,7 @@ void PhasingHandler::AddPhaseGroup(WorldObject* object, uint32 phaseGroupId, boo bool changed = false; for (uint32 phaseId : *phasesInGroup) - changed = object->GetPhaseShift().AddPhase(phaseId, GetPhaseFlags(phaseId), sObjectMgr->GetPhaseInfo(phaseId), nullptr) || changed; + changed = object->GetPhaseShift().AddPhase(phaseId, GetPhaseFlags(phaseId), nullptr) || changed; if (Unit* unit = object->ToUnit()) { @@ -242,9 +242,9 @@ void PhasingHandler::OnAreaChange(WorldObject* object) uint32 phaseId = phaseArea.PhaseInfo->Id; if (sConditionMgr->IsObjectMeetToConditions(srcInfo, phaseArea.Conditions)) - phaseShift.AddPhase(phaseArea.PhaseInfo->Id, GetPhaseFlags(phaseId), phaseArea.PhaseInfo, &phaseArea.Conditions); + phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), &phaseArea.Conditions); else - suppressedPhaseShift.AddPhase(phaseArea.PhaseInfo->Id, GetPhaseFlags(phaseId), phaseArea.PhaseInfo, &phaseArea.Conditions); + suppressedPhaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), &phaseArea.Conditions); } } @@ -257,13 +257,13 @@ void PhasingHandler::OnAreaChange(WorldObject* object) for (AuraEffect const* aurEff : unit->GetAuraEffectsByType(SPELL_AURA_PHASE)) { uint32 phaseId = uint32(aurEff->GetMiscValueB()); - changed = phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), sObjectMgr->GetPhaseInfo(phaseId), nullptr) || changed; + changed = phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), nullptr) || changed; } for (AuraEffect const* aurEff : unit->GetAuraEffectsByType(SPELL_AURA_PHASE_GROUP)) if (std::vector const* phasesInGroup = GetPhasesForGroup(uint32(aurEff->GetMiscValueB()))) for (uint32 phaseId : *phasesInGroup) - changed = phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), sObjectMgr->GetPhaseInfo(phaseId), nullptr) || changed; + changed = phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), nullptr) || changed; if (changed) unit->OnPhaseChange(); @@ -292,7 +292,7 @@ void PhasingHandler::OnConditionChange(WorldObject* object) { if (itr->AreaConditions && !sConditionMgr->IsObjectMeetToConditions(srcInfo, *itr->AreaConditions)) { - newSuppressions.AddPhase(itr->Id, itr->Flags, itr->PhaseInfo, itr->AreaConditions, itr->References); + newSuppressions.AddPhase(itr->Id, itr->Flags, itr->AreaConditions, itr->References); itr = phaseShift.Phases.erase(itr); } else @@ -303,7 +303,7 @@ void PhasingHandler::OnConditionChange(WorldObject* object) { if (sConditionMgr->IsObjectMeetToConditions(srcInfo, *ASSERT_NOTNULL(itr->AreaConditions))) { - changed = phaseShift.AddPhase(itr->Id, itr->Flags, itr->PhaseInfo, itr->AreaConditions, itr->References) || changed; + changed = phaseShift.AddPhase(itr->Id, itr->Flags, itr->AreaConditions, itr->References) || changed; itr = suppressedPhaseShift.Phases.erase(itr); } else @@ -344,8 +344,10 @@ void PhasingHandler::OnConditionChange(WorldObject* object) for (AuraEffect const* aurEff : unit->GetAuraEffectsByType(SPELL_AURA_PHASE)) { uint32 phaseId = uint32(aurEff->GetMiscValueB()); - phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), sObjectMgr->GetPhaseInfo(phaseId), nullptr); - newSuppressions.RemovePhase(phaseId); + auto eraseResult = newSuppressions.RemovePhase(phaseId); + // if condition was met previously there is nothing to erase + if (eraseResult.Iterator != newSuppressions.Phases.end() || eraseResult.Erased) + phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), nullptr); } for (AuraEffect const* aurEff : unit->GetAuraEffectsByType(SPELL_AURA_PHASE_GROUP)) @@ -354,8 +356,10 @@ void PhasingHandler::OnConditionChange(WorldObject* object) { for (uint32 phaseId : *phasesInGroup) { - phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), sObjectMgr->GetPhaseInfo(phaseId), nullptr); - newSuppressions.RemovePhase(phaseId); + auto eraseResult = newSuppressions.RemovePhase(phaseId); + // if condition was met previously there is nothing to erase + if (eraseResult.Iterator != newSuppressions.Phases.end() || eraseResult.Erased) + phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), nullptr); } } } @@ -363,7 +367,7 @@ void PhasingHandler::OnConditionChange(WorldObject* object) changed = changed || !newSuppressions.Phases.empty() || !newSuppressions.VisibleMapIds.empty(); for (auto itr = newSuppressions.Phases.begin(); itr != newSuppressions.Phases.end(); ++itr) - suppressedPhaseShift.AddPhase(itr->Id, itr->Flags, itr->PhaseInfo, itr->AreaConditions, itr->References); + suppressedPhaseShift.AddPhase(itr->Id, itr->Flags, itr->AreaConditions, itr->References); for (auto itr = newSuppressions.VisibleMapIds.begin(); itr != newSuppressions.VisibleMapIds.end(); ++itr) suppressedPhaseShift.AddVisibleMapId(itr->first, itr->second.VisibleMapInfo, itr->second.References); @@ -453,7 +457,6 @@ PhaseShift const& PhasingHandler::GetEmptyPhaseShift() void PhasingHandler::InitDbPhaseShift(PhaseShift& phaseShift, uint8 phaseUseFlags, uint16 phaseId, uint32 phaseGroupId) { - phaseShift.ClearPhases(); phaseShift.IsDbPhaseShift = true; EnumClassFlag flags = PhaseShiftFlags::None; @@ -463,10 +466,10 @@ void PhasingHandler::InitDbPhaseShift(PhaseShift& phaseShift, uint8 phaseUseFlag flags |= PhaseShiftFlags::Inverse; if (phaseId) - phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), sObjectMgr->GetPhaseInfo(phaseId), nullptr); + phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), nullptr); else if (std::vector const* phasesInGroup = GetPhasesForGroup(phaseGroupId)) for (uint32 phaseInGroup : *phasesInGroup) - phaseShift.AddPhase(phaseInGroup, GetPhaseFlags(phaseInGroup), sObjectMgr->GetPhaseInfo(phaseInGroup), nullptr); + phaseShift.AddPhase(phaseInGroup, GetPhaseFlags(phaseInGroup), nullptr); if (phaseShift.Phases.empty() || phaseShift.HasPhase(DEFAULT_PHASE)) { @@ -493,6 +496,32 @@ bool PhasingHandler::InDbPhaseShift(WorldObject const* object, uint8 phaseUseFla return object->GetPhaseShift().CanSee(phaseShift); } +uint32 PhasingHandler::GetTerrainMapId(PhaseShift const& phaseShift, Map const* map, float x, float y) +{ + if (phaseShift.VisibleMapIds.empty()) + return map->GetId(); + + if (phaseShift.VisibleMapIds.size() == 1) + return phaseShift.VisibleMapIds.begin()->first; + + GridCoord gridCoord = Trinity::ComputeGridCoord(x, y); + int32 gx = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.x_coord; + int32 gy = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.y_coord; + + int32 gxbegin = std::max(gx - 1, 0); + int32 gxend = std::min(gx + 1, MAX_NUMBER_OF_GRIDS); + int32 gybegin = std::max(gy - 1, 0); + int32 gyend = std::min(gy + 1, MAX_NUMBER_OF_GRIDS); + + for (auto itr = phaseShift.VisibleMapIds.rbegin(); itr != phaseShift.VisibleMapIds.rend(); ++itr) + for (int32 gxi = gxbegin; gxi < gxend; ++gxi) + for (int32 gyi = gybegin; gyi < gyend; ++gyi) + if (map->HasGrid(gxi, gyi)) + return itr->first; + + return map->GetId(); +} + void PhasingHandler::SetAlwaysVisible(PhaseShift& phaseShift, bool apply) { if (apply) diff --git a/src/server/game/Phasing/PhasingHandler.h b/src/server/game/Phasing/PhasingHandler.h index 579d7f9de1f..ba88d2f895d 100644 --- a/src/server/game/Phasing/PhasingHandler.h +++ b/src/server/game/Phasing/PhasingHandler.h @@ -22,6 +22,7 @@ #include class ChatHandler; +class Map; class PhaseShift; class Player; class WorldObject; @@ -53,6 +54,8 @@ public: static void InitDbVisibleMapId(PhaseShift& phaseShift, int32 visibleMapId); static bool InDbPhaseShift(WorldObject const* object, uint8 phaseUseFlags, uint16 phaseId, uint32 phaseGroupId); + static uint32 GetTerrainMapId(PhaseShift const& phaseShift, Map const* map, float x, float y); + static void SetAlwaysVisible(PhaseShift& phaseShift, bool apply); static void SetInversed(PhaseShift& phaseShift, bool apply); diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp index d2e607d79f1..1419271dbcb 100644 --- a/src/server/scripts/Commands/cs_debug.cpp +++ b/src/server/scripts/Commands/cs_debug.cpp @@ -1016,7 +1016,7 @@ public: if (p) if (uint32 up = (uint32)atoi(p)) - phaseShift.AddPhase(up, PhaseFlags::None, nullptr, nullptr); + phaseShift.AddPhase(up, PhaseFlags::None, nullptr); if (m) if (uint32 um = (uint32)atoi(m))