diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/AreaTrigger/AreaTrigger.cpp | 19 | ||||
-rw-r--r-- | src/server/game/Globals/AreaTriggerDataStore.cpp | 52 | ||||
-rw-r--r-- | src/server/game/Globals/AreaTriggerDataStore.h | 3 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.h | 2 | ||||
-rw-r--r-- | src/server/game/Grids/ObjectGridLoader.cpp | 2 |
6 files changed, 50 insertions, 30 deletions
diff --git a/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp b/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp index 7fcbff488a3..a17a4f4cc82 100644 --- a/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp +++ b/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp @@ -272,6 +272,7 @@ bool AreaTrigger::CreateServer(Map* map, AreaTriggerTemplate const* areaTriggerT SetEntry(areaTriggerTemplate->Id.Id); SetObjectScale(1.0f); + SetDuration(-1); auto areaTriggerData = m_values.ModifyValue(&AreaTrigger::m_areaTriggerData); SetUpdateFieldValue(areaTriggerData.ModifyValue(&UF::AreaTriggerData::BoundsRadius2D), GetMaxSearchRadius()); @@ -290,8 +291,6 @@ bool AreaTrigger::CreateServer(Map* map, AreaTriggerTemplate const* areaTriggerT SetUpdateFieldValue(areaTriggerData.ModifyValue(&UF::AreaTriggerData::VisualAnim).ModifyValue(&UF::VisualAnim::AnimationDataID), -1); - SetDuration(-1); - _shape = position.Shape; _maxSearchRadius = _shape.GetMaxSearchRadius(); @@ -326,16 +325,16 @@ void AreaTrigger::Update(uint32 diff) } else UpdateSplinePosition(diff); + } - if (GetDuration() != -1) + if (GetDuration() != -1) + { + if (GetDuration() > int32(diff)) + _UpdateDuration(_duration - diff); + else { - if (GetDuration() > int32(diff)) - _UpdateDuration(_duration - diff); - else - { - Remove(); // expired - return; - } + Remove(); // expired + return; } } diff --git a/src/server/game/Globals/AreaTriggerDataStore.cpp b/src/server/game/Globals/AreaTriggerDataStore.cpp index 6b49e5cf332..b1cf3db98cd 100644 --- a/src/server/game/Globals/AreaTriggerDataStore.cpp +++ b/src/server/game/Globals/AreaTriggerDataStore.cpp @@ -42,7 +42,10 @@ struct std::hash<AreaTriggerId> namespace { - std::unordered_map<std::pair<uint32/*mapId*/, uint32/*cell_id*/>, std::set<ObjectGuid::LowType>> _areaTriggerSpawnsByLocation; + typedef std::unordered_map<uint32/*cell_id*/, std::set<ObjectGuid::LowType>> AtCellObjectGuidsMap; + typedef std::unordered_map<std::pair<uint32 /*mapId*/, Difficulty>, AtCellObjectGuidsMap> AtMapObjectGuids; + + AtMapObjectGuids _areaTriggerSpawnsByLocation; std::unordered_map<ObjectGuid::LowType, AreaTriggerSpawn> _areaTriggerSpawnsBySpawnId; std::unordered_map<AreaTriggerId, AreaTriggerTemplate> _areaTriggerTemplateStore; std::unordered_map<uint32, AreaTriggerCreateProperties> _areaTriggerCreateProperties; @@ -296,11 +299,15 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates() void AreaTriggerDataStore::LoadAreaTriggerSpawns() { + // build single time for check spawnmask + std::unordered_map<uint32, std::set<Difficulty>> spawnMasks; + for (MapDifficultyEntry const* mapDifficulty : sMapDifficultyStore) + spawnMasks[mapDifficulty->MapID].insert(Difficulty(mapDifficulty->DifficultyID)); + uint32 oldMSTime = getMSTime(); - // Load area trigger positions (to put them on the server) - // 0 1 2 3 4 5 6 7 8 9 10 - if (QueryResult templates = WorldDatabase.Query("SELECT SpawnId, AreaTriggerId, IsServerSide, MapId, PosX, PosY, PosZ, Orientation, PhaseUseFlags, PhaseId, PhaseGroup, " - // 11 12 13 14 15 16 17 18 19 20 21 + // 0 1 2 3 4 5 6 7 8 9 10 11 + if (QueryResult templates = WorldDatabase.Query("SELECT SpawnId, AreaTriggerId, IsServerSide, MapId, SpawnDifficulties, PosX, PosY, PosZ, Orientation, PhaseUseFlags, PhaseId, PhaseGroup, " + // 12 13 14 15 16 17 18 19 20 21 22 "Shape, ShapeData0, ShapeData1, ShapeData2, ShapeData3, ShapeData4, ShapeData5, ShapeData6, ShapeData7, SpellForVisuals, ScriptName FROM `areatrigger`")) { do @@ -309,8 +316,8 @@ void AreaTriggerDataStore::LoadAreaTriggerSpawns() ObjectGuid::LowType spawnId = fields[0].GetUInt64(); AreaTriggerId areaTriggerid = { fields[1].GetUInt32(), fields[2].GetUInt8() == 1 }; - WorldLocation location(fields[3].GetUInt32(), fields[4].GetFloat(), fields[5].GetFloat(), fields[6].GetFloat(), fields[7].GetFloat()); - uint8 shape = fields[11].GetUInt8(); + WorldLocation location(fields[3].GetUInt32(), fields[5].GetFloat(), fields[6].GetFloat(), fields[7].GetFloat(), fields[8].GetFloat()); + uint8 shape = fields[12].GetUInt8(); if (!GetAreaTriggerTemplate(areaTriggerid)) { @@ -333,23 +340,30 @@ void AreaTriggerDataStore::LoadAreaTriggerSpawns() continue; } + std::vector<Difficulty> difficulties = sObjectMgr->ParseSpawnDifficulties(fields[4].GetStringView(), "areatrigger", spawnId, location.GetMapId(), spawnMasks[location.GetMapId()]); + if (difficulties.empty()) + { + TC_LOG_DEBUG("sql.sql", "Table `areatrigger` has areatrigger (GUID: {}) that is not spawned in any difficulty, skipped.", spawnId); + continue; + } + AreaTriggerSpawn& spawn = _areaTriggerSpawnsBySpawnId[spawnId]; spawn.spawnId = spawnId; spawn.mapId = location.GetMapId(); spawn.Id = areaTriggerid; spawn.spawnPoint.Relocate(location); - spawn.phaseUseFlags = fields[8].GetUInt8(); - spawn.phaseId = fields[9].GetUInt32(); - spawn.phaseGroup = fields[10].GetUInt32(); + spawn.phaseUseFlags = fields[9].GetUInt8(); + spawn.phaseId = fields[10].GetUInt32(); + spawn.phaseGroup = fields[11].GetUInt32(); spawn.Shape.Type = static_cast<AreaTriggerTypes>(shape); for (uint8 i = 0; i < MAX_AREATRIGGER_ENTITY_DATA; ++i) - spawn.Shape.DefaultDatas.Data[i] = fields[12 + i].GetFloat(); + spawn.Shape.DefaultDatas.Data[i] = fields[13 + i].GetFloat(); - if (!fields[20].IsNull()) + if (!fields[21].IsNull()) { - spawn.SpellForVisuals = fields[20].GetInt32(); + spawn.SpellForVisuals = fields[21].GetInt32(); if (!sSpellMgr->GetSpellInfo(*spawn.SpellForVisuals, DIFFICULTY_NONE)) { TC_LOG_ERROR("sql.sql", "Table `areatrigger` has listed areatrigger SpawnId: {} with invalid SpellForVisual {}, set to none.", @@ -358,12 +372,13 @@ void AreaTriggerDataStore::LoadAreaTriggerSpawns() } } - spawn.scriptId = sObjectMgr->GetScriptId(fields[21].GetString()); + spawn.scriptId = sObjectMgr->GetScriptId(fields[22].GetString()); spawn.spawnGroupData = sObjectMgr->GetLegacySpawnGroup(); // Add the trigger to a map::cell map, which is later used by GridLoader to query CellCoord cellCoord = Trinity::ComputeCellCoord(spawn.spawnPoint.GetPositionX(), spawn.spawnPoint.GetPositionY()); - _areaTriggerSpawnsByLocation[{ spawn.mapId, cellCoord.GetId() }].insert(spawnId); + for (Difficulty difficulty : difficulties) + _areaTriggerSpawnsByLocation[{ spawn.mapId, difficulty }][cellCoord.GetId()].insert(spawnId); } while (templates->NextRow()); } @@ -380,9 +395,12 @@ AreaTriggerCreateProperties const* AreaTriggerDataStore::GetAreaTriggerCreatePro return Trinity::Containers::MapGetValuePtr(_areaTriggerCreateProperties, areaTriggerCreatePropertiesId); } -std::set<ObjectGuid::LowType> const* AreaTriggerDataStore::GetAreaTriggersForMapAndCell(uint32 mapId, uint32 cellId) const +std::set<ObjectGuid::LowType> const* AreaTriggerDataStore::GetAreaTriggersForMapAndCell(uint32 mapId, Difficulty difficulty, uint32 cellId) const { - return Trinity::Containers::MapGetValuePtr(_areaTriggerSpawnsByLocation, { mapId, cellId }); + if (auto* atForMapAndDifficulty = Trinity::Containers::MapGetValuePtr(_areaTriggerSpawnsByLocation, { mapId, difficulty })) + return Trinity::Containers::MapGetValuePtr(*atForMapAndDifficulty, cellId); + + return nullptr; } AreaTriggerSpawn const* AreaTriggerDataStore::GetAreaTriggerSpawn(ObjectGuid::LowType spawnId) const diff --git a/src/server/game/Globals/AreaTriggerDataStore.h b/src/server/game/Globals/AreaTriggerDataStore.h index fd40c3d5f5d..07bbf64cc92 100644 --- a/src/server/game/Globals/AreaTriggerDataStore.h +++ b/src/server/game/Globals/AreaTriggerDataStore.h @@ -24,6 +24,7 @@ class AreaTriggerTemplate; class AreaTriggerCreateProperties; +enum Difficulty : uint8; struct AreaTriggerId; struct AreaTriggerSpawn; @@ -33,7 +34,7 @@ public: void LoadAreaTriggerTemplates(); void LoadAreaTriggerSpawns(); - std::set<ObjectGuid::LowType> const* GetAreaTriggersForMapAndCell(uint32 mapId, uint32 cellId) const; + std::set<ObjectGuid::LowType> const* GetAreaTriggersForMapAndCell(uint32 mapId, Difficulty difficulty, uint32 cellId) const; AreaTriggerSpawn const* GetAreaTriggerSpawn(ObjectGuid::LowType spawnId) const; AreaTriggerTemplate const* GetAreaTriggerTemplate(AreaTriggerId const& areaTriggerId) const; AreaTriggerCreateProperties const* GetAreaTriggerCreateProperties(uint32 areaTriggerCreatePropertiesId) const; diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 9e209b438d7..6e932aeeb8f 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -2095,7 +2095,7 @@ void ObjectMgr::LoadTempSummons() TC_LOG_INFO("server.loading", ">> Loaded {} temp summons in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); } -inline std::vector<Difficulty> ParseSpawnDifficulties(std::string_view difficultyString, std::string_view table, ObjectGuid::LowType spawnId, uint32 mapId, +std::vector<Difficulty> ObjectMgr::ParseSpawnDifficulties(std::string_view difficultyString, std::string_view table, ObjectGuid::LowType spawnId, uint32 mapId, std::set<Difficulty> const& mapDifficulties) { std::vector<Difficulty> difficulties; diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 3a9bf626ca9..ec298506588 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -1312,6 +1312,8 @@ class TC_GAME_API ObjectMgr return _exclusiveQuestGroups.equal_range(exclusiveGroupId); } + std::vector<Difficulty> ParseSpawnDifficulties(std::string_view difficultyString, std::string_view table, ObjectGuid::LowType spawnId, uint32 mapId, std::set<Difficulty> const& mapDifficulties); + bool LoadTrinityStrings(); void LoadEventScripts(); diff --git a/src/server/game/Grids/ObjectGridLoader.cpp b/src/server/game/Grids/ObjectGridLoader.cpp index 44af94fa717..3420707fdbe 100644 --- a/src/server/game/Grids/ObjectGridLoader.cpp +++ b/src/server/game/Grids/ObjectGridLoader.cpp @@ -145,7 +145,7 @@ void ObjectGridLoader::Visit(CreatureMapType &m) void ObjectGridLoader::Visit(AreaTriggerMapType& m) { CellCoord cellCoord = i_cell.GetCellCoord(); - CellGuidSet const* areaTriggers = sAreaTriggerDataStore->GetAreaTriggersForMapAndCell(i_map->GetId(), cellCoord.GetId()); + CellGuidSet const* areaTriggers = sAreaTriggerDataStore->GetAreaTriggersForMapAndCell(i_map->GetId(), i_map->GetDifficultyID(), cellCoord.GetId()); if (areaTriggers) LoadHelper(*areaTriggers, cellCoord, m, i_areaTriggers, i_map); } |