Core/AreaTriggers: Code cleanup

This commit is contained in:
Shauren
2021-01-30 16:26:31 +01:00
parent 0417c5ff5f
commit 7851cd3a96
13 changed files with 215 additions and 256 deletions

View File

@@ -1,45 +0,0 @@
ALTER TABLE `areatrigger_template`
DROP PRIMARY KEY,
ADD COLUMN `IsServer` tinyint(1) NOT NULL AFTER `Id`,
ADD PRIMARY KEY (`Id`, `IsServer`);
ALTER TABLE `areatrigger_template_actions`
DROP PRIMARY KEY,
ADD COLUMN `IsServer` tinyint(1) NOT NULL AFTER `AreaTriggerId`,
ADD PRIMARY KEY (`AreaTriggerId`, `IsServer`);
CREATE TABLE `areatrigger_positions` (
`SpawnId` int(12) unsigned NOT NULL,
`Id` int(10) unsigned NOT NULL,
`IsServer` tinyint(1) NOT NULL,
`MapId` int(10) NOT NULL,
`PosX` float NOT NULL,
`PosY` float NOT NULL,
`PosZ` float NOT NULL,
`PhaseId` int(10) DEFAULT 0,
`PhaseGroup` int(10) DEFAULT 0,
`PhaseUseFlags` tinyint(3) DEFAULT 0,
`Comment` varchar(255) DEFAULT NULL,
PRIMARY KEY (`SpawnId`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
DELETE FROM `areatrigger_positions` WHERE `SpawnId` IN (1, 2);
INSERT INTO `areatrigger_positions` (`SpawnId`, `Id`, `IsServer`, `MapId`, `PosX`, `PosY`, `PosZ`, `PhaseId`, `PhaseGroup`, `PhaseUseFlags`, `Comment`) VALUES
(1, 1, 1, 0, -9015.774, 877.223, 148.61871, 0, 0, 0, 'Stormwind Mage Portal Entrance'),
(2, 2, 1, 0, -8999.866, 864.13995, 65.88978, 0, 0, 0, 'Stormwind Mage Portal Exit');
DELETE FROM `areatrigger_template` WHERE `Id` in (1, 2) AND `IsServer` = 1;
INSERT INTO `areatrigger_template` (`Id`, `IsServer`, `Type`, `Flags`, `Data0`, `Data1`, `Data2`, `Data3`, `Data4`, `Data5`, `ScriptName`, `VerifiedBuild`) VALUES
(1, 1, 1, 0, 1.2597655, 1.2792665, 3.7021635, 0, 0, 0, '', 0),
(2, 1, 1, 0, 1.2597655, 1.2792665, 3.7021635, 0, 0, 0, '', 0);
DELETE FROM `areatrigger_template_actions` WHERE `AreaTriggerId` IN (1, 2) AND `IsServer` = 1;
INSERT INTO `areatrigger_template_actions` (`AreaTriggerId`, `IsServer`, `ActionType`, `ActionParam`, `TargetType`) VALUES
(1, 1, 2, 3631, 5),
(2, 1, 2, 3630, 5);
UPDATE `world_safe_locs` SET LocX=-9014.864258, LocY=874.324890, LocZ=148.618713 WHERE `id` = 3630;

View File

@@ -0,0 +1,42 @@
ALTER TABLE `areatrigger_template`
DROP PRIMARY KEY,
ADD COLUMN `IsServerSide` tinyint(1) unsigned NOT NULL AFTER `Id`,
ADD PRIMARY KEY (`Id`, `IsServerSide`);
ALTER TABLE `areatrigger_template_actions`
DROP PRIMARY KEY,
ADD COLUMN `IsServerSide` tinyint(1) unsigned NOT NULL AFTER `AreaTriggerId`,
ADD PRIMARY KEY (`AreaTriggerId`, `IsServerSide`);
CREATE TABLE `areatrigger` (
`SpawnId` bigint(20) unsigned NOT NULL,
`AreaTriggerId` int(10) unsigned NOT NULL,
`IsServerSide` tinyint(1) unsigned NOT NULL,
`MapId` int(10) unsigned NOT NULL,
`PosX` float NOT NULL,
`PosY` float NOT NULL,
`PosZ` float NOT NULL,
`Orientation` float NOT NULL,
`PhaseUseFlags` tinyint(3) unsigned DEFAULT '0',
`PhaseId` int(10) unsigned DEFAULT '0',
`PhaseGroup` int(10) unsigned DEFAULT '0',
`Comment` varchar(255) DEFAULT NULL,
PRIMARY KEY (`SpawnId`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
DELETE FROM `areatrigger` WHERE `SpawnId` IN (1, 2);
INSERT INTO `areatrigger` (`SpawnId`, `AreaTriggerId`, `IsServerSide`, `MapId`, `PosX`, `PosY`, `PosZ`, `Orientation`, `PhaseUseFlags`, `PhaseId`, `PhaseGroup`, `Comment`) VALUES
(1, 1, 1, 0, -9016.11, 876.142, 148.617, 0.7259, 1, 0, 0, 'Stormwind Mage Portal Entrance'),
(2, 2, 1, 0, -8999.866, 864.13995, 65.88978, 0, 1, 0, 0, 'Stormwind Mage Portal Exit');
DELETE FROM `areatrigger_template` WHERE `Id` in (1, 2) AND `IsServerSide` = 1;
INSERT INTO `areatrigger_template` (`Id`, `IsServerSide`, `Type`, `Flags`, `Data0`, `Data1`, `Data2`, `Data3`, `Data4`, `Data5`, `ScriptName`, `VerifiedBuild`) VALUES
(1, 1, 1, 0, 3, 1, 3, 0, 0, 0, '', 0),
(2, 1, 1, 0, 1.2597655, 1.2792665, 3.7021635, 0, 0, 0, '', 0);
DELETE FROM `areatrigger_template_actions` WHERE `AreaTriggerId` IN (1, 2) AND `IsServerSide` = 1;
INSERT INTO `areatrigger_template_actions` (`AreaTriggerId`, `IsServerSide`, `ActionType`, `ActionParam`, `TargetType`) VALUES
(1, 1, 2, 3631, 5),
(2, 1, 2, 3630, 5);
UPDATE `world_safe_locs` SET LocX=-9014.864258, LocY=874.324890, LocZ=148.618713 WHERE `id`=3630;

View File

@@ -39,13 +39,10 @@
#include "UpdateData.h"
#include <G3D/AABox.h>
AreaTrigger::AreaTrigger() : WorldObject(false), MapObject(),
_targetGuid(), _aurEff(nullptr),
AreaTrigger::AreaTrigger() : WorldObject(false), MapObject(), _aurEff(nullptr),
_duration(0), _totalDuration(0), _timeSinceCreated(0), _previousCheckOrientation(std::numeric_limits<float>::infinity()),
_isRemoved(false), _rollPitchYaw(), _targetRollPitchYaw(), _polygonVertices(), _spline(),
_reachedDestination(true), _lastSplineIndex(0), _movementTime(0),
_orbitInfo(), _areaTriggerMiscTemplate(nullptr), _insideUnits(), _ai(),
_areaTriggerTemplate(nullptr)
_isRemoved(false), _reachedDestination(true), _lastSplineIndex(0), _movementTime(0),
_areaTriggerMiscTemplate(nullptr), _areaTriggerTemplate(nullptr)
{
m_objectType |= TYPEMASK_AREATRIGGER;
m_objectTypeId = TYPEID_AREATRIGGER;
@@ -110,9 +107,9 @@ bool AreaTrigger::Create(uint32 spellMiscId, Unit* caster, Unit* target, SpellIn
_areaTriggerTemplate = _areaTriggerMiscTemplate->Template;
Object::_Create(ObjectGuid::Create<HighGuid::AreaTrigger>(GetMapId(), GetTemplate()->Id, caster->GetMap()->GenerateLowGuid<HighGuid::AreaTrigger>()));
Object::_Create(ObjectGuid::Create<HighGuid::AreaTrigger>(GetMapId(), GetTemplate()->Id.Id, caster->GetMap()->GenerateLowGuid<HighGuid::AreaTrigger>()));
SetEntry(GetTemplate()->Id);
SetEntry(GetTemplate()->Id.Id);
SetDuration(duration);
SetObjectScale(1.0f);
@@ -218,45 +215,47 @@ AreaTrigger* AreaTrigger::CreateAreaTrigger(uint32 spellMiscId, Unit* caster, Un
return at;
}
bool AreaTrigger::LoadFromDB(uint32 spawnId, Map* map, bool /*addToMap*/, bool /*allowDuplicate*/)
bool AreaTrigger::LoadFromDB(ObjectGuid::LowType spawnId, Map* map, bool /*addToMap*/, bool /*allowDuplicate*/)
{
AreaTriggerServerPosition const* position = sAreaTriggerDataStore->GetAreaTriggerServerPosition(spawnId);
AreaTriggerSpawn const* position = sAreaTriggerDataStore->GetAreaTriggerSpawn(spawnId);
if (!position)
return false;
AreaTriggerTemplate const* areaTriggerTemplate = sAreaTriggerDataStore->GetAreaTriggerServerTemplate(position->Id);
AreaTriggerTemplate const* areaTriggerTemplate = sAreaTriggerDataStore->GetAreaTriggerTemplate(position->Id);
if (!areaTriggerTemplate)
return false;
return CreateServer(map, areaTriggerTemplate, *position);
}
bool AreaTrigger::CreateServer(Map* map, AreaTriggerTemplate const* areaTriggerTemplate, AreaTriggerServerPosition const& position)
bool AreaTrigger::CreateServer(Map* map, AreaTriggerTemplate const* areaTriggerTemplate, AreaTriggerSpawn const& position)
{
SetMap(map);
Relocate(position.Location);
if (!IsPositionValid())
{
TC_LOG_ERROR("entities.areatrigger", "AreaTriggerServer (id %u) not created. Invalid coordinates (X: %f Y: %f)", areaTriggerTemplate->Id, GetPositionX(), GetPositionY());
TC_LOG_ERROR("entities.areatrigger", "AreaTriggerServer (id %u) not created. Invalid coordinates (X: %f Y: %f)",
areaTriggerTemplate->Id.Id, GetPositionX(), GetPositionY());
return false;
}
_areaTriggerTemplate = areaTriggerTemplate;
Object::_Create(ObjectGuid::Create<HighGuid::AreaTrigger>(GetMapId(),
areaTriggerTemplate->Id, GetMap()->GenerateLowGuid<HighGuid::AreaTrigger>()));
Object::_Create(ObjectGuid::Create<HighGuid::AreaTrigger>(GetMapId(), areaTriggerTemplate->Id.Id, GetMap()->GenerateLowGuid<HighGuid::AreaTrigger>()));
SetEntry(areaTriggerTemplate->Id);
SetEntry(areaTriggerTemplate->Id.Id);
SetObjectScale(1.0f);
if (position.PhaseId || position.PhaseGroup || position.PhaseUseFlags)
if (position.PhaseUseFlags || position.PhaseId || position.PhaseGroup)
PhasingHandler::InitDbPhaseShift(GetPhaseShift(), position.PhaseUseFlags, position.PhaseId, position.PhaseGroup);
UpdateShape();
AI_Initialize();
_ai->OnCreate();
return true;
}
@@ -265,33 +264,30 @@ void AreaTrigger::Update(uint32 diff)
WorldObject::Update(diff);
_timeSinceCreated += diff;
if (IsServerSide())
if (!IsServerSide())
{
UpdateTargetList();
return;
}
// "If" order matter here, Orbit > Attached > Splines
if (HasOrbit())
{
UpdateOrbitPosition(diff);
}
else if (GetTemplate()->HasFlag(AREATRIGGER_FLAG_HAS_ATTACHED))
{
if (Unit* target = GetTarget())
GetMap()->AreaTriggerRelocation(this, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), target->GetOrientation());
}
else
UpdateSplinePosition(diff);
if (GetDuration() != -1)
{
if (GetDuration() > int32(diff))
_UpdateDuration(_duration - diff);
else
// "If" order matter here, Orbit > Attached > Splines
if (HasOrbit())
{
Remove(); // expired
return;
UpdateOrbitPosition(diff);
}
else if (GetTemplate()->HasFlag(AREATRIGGER_FLAG_HAS_ATTACHED))
{
if (Unit* target = GetTarget())
GetMap()->AreaTriggerRelocation(this, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), target->GetOrientation());
}
else
UpdateSplinePosition(diff);
if (GetDuration() != -1)
{
if (GetDuration() > int32(diff))
_UpdateDuration(_duration - diff);
else
{
Remove(); // expired
return;
}
}
}
@@ -460,7 +456,7 @@ void AreaTrigger::HandleUnitEnterExit(std::list<Unit*> const& newTargetList)
{
if (Player* player = unit->ToPlayer())
if (player->isDebugAreaTriggers)
ChatHandler(player->GetSession()).PSendSysMessage(LANG_DEBUG_AREATRIGGER_ENTERED, GetTemplate()->Id);
ChatHandler(player->GetSession()).PSendSysMessage(LANG_DEBUG_AREATRIGGER_ENTERED, GetTemplate()->Id.Id);
DoActions(unit);
@@ -473,7 +469,7 @@ void AreaTrigger::HandleUnitEnterExit(std::list<Unit*> const& newTargetList)
{
if (Player* player = leavingUnit->ToPlayer())
if (player->isDebugAreaTriggers)
ChatHandler(player->GetSession()).PSendSysMessage(LANG_DEBUG_AREATRIGGER_LEFT, GetTemplate()->Id);
ChatHandler(player->GetSession()).PSendSysMessage(LANG_DEBUG_AREATRIGGER_LEFT, GetTemplate()->Id.Id);
UndoActions(leavingUnit);
@@ -872,7 +868,7 @@ void AreaTrigger::UpdateSplinePosition(uint32 diff)
if (progress < 0.f || progress > 1.f)
{
TC_LOG_ERROR("entities.areatrigger", "AreaTrigger (Id: %u, SpellMiscId: %u) has wrong progress (%f) caused by curve calculation (MoveCurveId: %u)",
GetTemplate()->Id, GetMiscTemplate()->MiscId, progress, GetMiscTemplate()->MorphCurveId);
GetTemplate()->Id.Id, GetMiscTemplate()->MiscId, progress, GetMiscTemplate()->MorphCurveId);
}
else
currentTimePercent = progress;

View File

@@ -61,16 +61,17 @@ class TC_GAME_API AreaTrigger : public WorldObject, public GridObject<AreaTrigge
AreaTriggerAI* AI() { return _ai.get(); }
bool IsServerSide() const { return _areaTriggerTemplate->IsServerSide; }
bool IsServerSide() const { return _areaTriggerTemplate->Id.IsServerSide; }
bool IsNeverVisibleFor(WorldObject const* /*seer*/) const override { return IsServerSide(); }
private:
bool Create(uint32 spellMiscId, Unit* caster, Unit* target, SpellInfo const* spell, Position const& pos, int32 duration, SpellCastVisual spellVisual, ObjectGuid const& castId, AuraEffect const* aurEff);
bool CreateServer(Map* map, AreaTriggerTemplate const* areaTriggerTemplate, AreaTriggerServerPosition const& position);
bool CreateServer(Map* map, AreaTriggerTemplate const* areaTriggerTemplate, AreaTriggerSpawn const& position);
public:
static AreaTrigger* CreateAreaTrigger(uint32 spellMiscId, Unit* caster, Unit* target, SpellInfo const* spell, Position const& pos, int32 duration, SpellCastVisual spellVisual, ObjectGuid const& castId = ObjectGuid::Empty, AuraEffect const* aurEff = nullptr);
bool LoadFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap, bool allowDuplicate);
void Update(uint32 diff) override;
void Remove();
@@ -111,7 +112,6 @@ class TC_GAME_API AreaTrigger : public WorldObject, public GridObject<AreaTrigge
UF::UpdateField<UF::AreaTriggerData, 0, TYPEID_AREATRIGGER> m_areaTriggerData;
bool LoadFromDB(uint32 spawnId, Map* map, bool addToMap, bool allowDuplicate);
protected:
void _UpdateDuration(int32 newDuration);
@@ -159,11 +159,10 @@ class TC_GAME_API AreaTrigger : public WorldObject, public GridObject<AreaTrigge
Optional<AreaTriggerOrbitInfo> _orbitInfo;
AreaTriggerMiscTemplate const* _areaTriggerMiscTemplate;
AreaTriggerTemplate const* _areaTriggerTemplate;
GuidUnorderedSet _insideUnits;
std::unique_ptr<AreaTriggerAI> _ai;
AreaTriggerTemplate const* _areaTriggerTemplate;
};
#endif

View File

@@ -28,12 +28,11 @@ AreaTriggerScaleInfo::AreaTriggerScaleInfo()
AreaTriggerTemplate::AreaTriggerTemplate()
{
Id = 0;
Id = { 0, false };
Type = AREATRIGGER_TYPE_MAX;
Flags = 0;
ScriptId = 0;
MaxSearchRadius = 0.0f;
IsServerSide = false;
memset(DefaultDatas.Data, 0, sizeof(DefaultDatas.Data));
}

View File

@@ -72,17 +72,10 @@ enum AreaTriggerActionUserTypes
AREATRIGGER_ACTION_USER_MAX = 6
};
struct AreaTriggerServerPosition
struct AreaTriggerId
{
uint64 SpawnId;
uint32 Id;
bool IsServer;
WorldLocation Location;
uint32 PhaseId;
uint32 PhaseGroup;
uint8 PhaseUseFlags;
AreaTriggerServerPosition() : SpawnId(0), Id(0), IsServer(false), Location(), PhaseId(0), PhaseGroup(0), PhaseUseFlags(0) { }
uint32 Id = 0;
bool IsServerSide = false;
};
struct AreaTriggerAction
@@ -152,7 +145,7 @@ public:
void InitMaxSearchRadius();
uint32 Id;
AreaTriggerId Id;
AreaTriggerTypes Type;
uint32 Flags;
uint32 ScriptId;
@@ -160,7 +153,6 @@ public:
std::vector<TaggedPosition<Position::XY>> PolygonVertices;
std::vector<TaggedPosition<Position::XY>> PolygonVerticesTarget;
std::vector<AreaTriggerAction> Actions;
bool IsServerSide;
union
{
@@ -235,4 +227,14 @@ public:
std::vector<Position> SplinePoints;
};
struct AreaTriggerSpawn
{
ObjectGuid::LowType SpawnId = 0;
AreaTriggerId Id;
WorldLocation Location;
uint32 PhaseId = 0;
uint32 PhaseGroup = 0;
uint8 PhaseUseFlags = 0;
};
#endif

View File

@@ -18,6 +18,7 @@
#include "AreaTriggerDataStore.h"
#include "AreaTrigger.h"
#include "AreaTriggerTemplate.h"
#include "Containers.h"
#include "DatabaseEnv.h"
#include "DB2Stores.h"
#include "Log.h"
@@ -26,29 +27,21 @@
#include "Timer.h"
#include <cmath>
struct AreaTriggerTemplateKey
bool operator==(AreaTriggerId const& left, AreaTriggerId const& right)
{
uint32 Id;
bool IsServer;
AreaTriggerTemplateKey(uint32 id, bool isServer) : Id(id), IsServer(isServer) { }
};
bool operator ==(AreaTriggerTemplateKey const& A, AreaTriggerTemplateKey const& B)
{
return A.Id == B.Id && A.IsServer == B.IsServer;
return left.Id == right.Id && left.IsServerSide == right.IsServerSide;
}
namespace std
{
template <>
struct hash<AreaTriggerTemplateKey>
struct hash<AreaTriggerId>
{
std::size_t operator()(AreaTriggerTemplateKey const& value) const
std::size_t operator()(AreaTriggerId const& value) const
{
size_t hashVal = 0;
Trinity::hash_combine(hashVal, value.Id);
Trinity::hash_combine(hashVal, value.IsServer);
Trinity::hash_combine(hashVal, value.IsServerSide);
return hashVal;
}
};
@@ -56,87 +49,53 @@ namespace std
namespace
{
typedef std::unordered_map<uint32/*cell_id*/, std::set<ObjectGuid::LowType>> CellAreaTriggersMap;
typedef std::unordered_map<uint32/*mapId*/, CellAreaTriggersMap> MapAreaTriggersMap;
typedef std::unordered_map<uint32, AreaTriggerServerPosition> AreaTriggerSpawnMap;
typedef std::unordered_map<AreaTriggerTemplateKey, AreaTriggerTemplate> AreaTriggerTemplateMap;
MapAreaTriggersMap _areaTriggersGrid;
AreaTriggerSpawnMap _areaTriggerSpawnMap;
AreaTriggerTemplateMap _areaTriggerTemplateMap;
std::unordered_map<std::pair<uint32/*mapId*/, uint32/*cell_id*/>, std::set<ObjectGuid::LowType>> _areaTriggerSpawnsByLocation;
std::unordered_map<uint32, AreaTriggerSpawn> _areaTriggerSpawnsBySpawnId;
std::unordered_map<AreaTriggerId, AreaTriggerTemplate> _areaTriggerTemplateStore;
std::unordered_map<uint32, AreaTriggerMiscTemplate> _areaTriggerTemplateSpellMisc;
}
AreaTriggerTemplate const* AreaTriggerDataStore::GetAreaTriggerServerTemplate(uint32 areaTriggerId) const
{
auto itr = _areaTriggerTemplateMap.find(AreaTriggerTemplateKey(areaTriggerId, true));
if (itr != _areaTriggerTemplateMap.end())
return &itr->second;
return nullptr;
}
std::set<ObjectGuid::LowType> const* AreaTriggerDataStore::GetAreaTriggersForMapAndCell(uint32 mapId, uint32 cellId) const
{
MapAreaTriggersMap::iterator iterMap = _areaTriggersGrid.find(mapId);
if (iterMap == _areaTriggersGrid.end())
return nullptr;
CellAreaTriggersMap::iterator iterCell = iterMap->second.find(cellId);
if (iterCell == iterMap->second.end())
return nullptr;
return &(iterCell->second);
}
AreaTriggerServerPosition const* AreaTriggerDataStore::GetAreaTriggerServerPosition(uint32 spawnId) const
{
AreaTriggerSpawnMap::iterator iter = _areaTriggerSpawnMap.find(spawnId);
if (iter == _areaTriggerSpawnMap.end())
return nullptr;
return &(iter->second);
}
void AreaTriggerDataStore::LoadAreaTriggerTemplates()
{
uint32 oldMSTime = getMSTime();
std::unordered_map<uint32, std::vector<TaggedPosition<Position::XY>>> verticesByAreaTrigger;
std::unordered_map<uint32, std::vector<TaggedPosition<Position::XY>>> verticesTargetByAreaTrigger;
std::unordered_map<uint32, std::vector<Position>> splinesBySpellMisc;
std::unordered_map<uint32, std::vector<AreaTriggerAction>> actionsByAreaTrigger;
std::unordered_map<AreaTriggerId, std::vector<AreaTriggerAction>> actionsByAreaTrigger;
// 0 1 2 3
if (QueryResult templateActions = WorldDatabase.Query("SELECT AreaTriggerId, ActionType, ActionParam, TargetType FROM `areatrigger_template_actions`"))
// 0 1 2 3 4
if (QueryResult templateActions = WorldDatabase.Query("SELECT AreaTriggerId, IsServerSide, ActionType, ActionParam, TargetType FROM `areatrigger_template_actions`"))
{
do
{
Field* templateActionFields = templateActions->Fetch();
uint32 areaTriggerId = templateActionFields[0].GetUInt32();
AreaTriggerId areaTriggerId = { templateActionFields[0].GetUInt32(), templateActionFields[1].GetUInt8() == 1 };
AreaTriggerAction action;
action.Param = templateActionFields[2].GetUInt32();
uint32 actionType = templateActionFields[1].GetUInt32();
uint32 targetType = templateActionFields[3].GetUInt32();
action.Param = templateActionFields[3].GetUInt32();
uint32 actionType = templateActionFields[2].GetUInt32();
uint32 targetType = templateActionFields[4].GetUInt32();
if (actionType >= AREATRIGGER_ACTION_MAX)
{
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template_actions` has invalid ActionType (%u) for AreaTriggerId %u and Param %u", actionType, areaTriggerId, action.Param);
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template_actions` has invalid ActionType (%u,%u) for AreaTriggerId %u and Param %u",
actionType, areaTriggerId.Id, uint32(areaTriggerId.IsServerSide), action.Param);
continue;
}
if (targetType >= AREATRIGGER_ACTION_USER_MAX)
{
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template_actions` has invalid TargetType (%u) for AreaTriggerId %u and Param %u", targetType, areaTriggerId, action.Param);
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template_actions` has invalid TargetType (%u,%u) for AreaTriggerId %u and Param %u",
targetType, areaTriggerId.Id, uint32(areaTriggerId.IsServerSide), action.Param);
continue;
}
if (actionType == AREATRIGGER_ACTION_TELEPORT)
{
WorldSafeLocsEntry const* safeLoc = sObjectMgr->GetWorldSafeLoc(action.Param);
if (!safeLoc)
if (!sObjectMgr->GetWorldSafeLoc(action.Param))
{
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template_actions` has invalid entry (%u) with TargetType=Teleport and Param (%u) not a valid world safe loc entry", areaTriggerId, action.Param);
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template_actions` has invalid entry (%u,%u) with TargetType=Teleport and Param (%u) not a valid world safe loc entry",
areaTriggerId.Id, uint32(areaTriggerId.IsServerSide), action.Param);
continue;
}
}
@@ -191,30 +150,32 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
TC_LOG_INFO("server.loading", ">> Loaded 0 AreaTrigger templates splines. DB table `spell_areatrigger_splines` is empty.");
}
// 0 1 2 3 4 5 6 7 8 9 10
if (QueryResult templates = WorldDatabase.Query("SELECT Id, IsServer, Type, Flags, Data0, Data1, Data2, Data3, Data4, Data5, ScriptName FROM `areatrigger_template`"))
// 0 1 2 3 4 5 6 7 8 9 10
if (QueryResult templates = WorldDatabase.Query("SELECT Id, IsServerSide, Type, Flags, Data0, Data1, Data2, Data3, Data4, Data5, ScriptName FROM `areatrigger_template`"))
{
do
{
Field* fields = templates->Fetch();
AreaTriggerTemplate areaTriggerTemplate;
areaTriggerTemplate.Id = fields[0].GetUInt32();
bool isServer = fields[1].GetUInt8() == 1;
areaTriggerTemplate.Id.Id = fields[0].GetUInt32();
areaTriggerTemplate.Id.IsServerSide = fields[1].GetUInt8() == 1;
uint8 type = fields[2].GetUInt8();
if (type >= AREATRIGGER_TYPE_MAX)
{
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template` has listed areatrigger (Id: %u) with invalid type %u.", areaTriggerTemplate.Id, type);
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template` has listed areatrigger (Id: %u, IsServerSide: %u) with invalid type %u.",
areaTriggerTemplate.Id.Id, uint32(areaTriggerTemplate.Id.IsServerSide), type);
continue;
}
areaTriggerTemplate.Type = static_cast<AreaTriggerTypes>(type);
areaTriggerTemplate.Flags = fields[3].GetUInt32();
if (isServer && areaTriggerTemplate.Flags != 0)
if (areaTriggerTemplate.Id.IsServerSide && areaTriggerTemplate.Flags != 0)
{
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template` has listed server-side areatrigger (Id: %u) with none-zero flags", areaTriggerTemplate.Id);
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template` has listed server-side areatrigger (Id: %u, IsServerSide: %u) with non-zero flags",
areaTriggerTemplate.Id.Id, uint32(areaTriggerTemplate.Id.IsServerSide));
continue;
}
@@ -222,66 +183,19 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
areaTriggerTemplate.DefaultDatas.Data[i] = fields[4 + i].GetFloat();
areaTriggerTemplate.ScriptId = sObjectMgr->GetScriptId(fields[10].GetString());
areaTriggerTemplate.PolygonVertices = std::move(verticesByAreaTrigger[areaTriggerTemplate.Id]);
areaTriggerTemplate.PolygonVerticesTarget = std::move(verticesTargetByAreaTrigger[areaTriggerTemplate.Id]);
if (!areaTriggerTemplate.Id.IsServerSide)
{
areaTriggerTemplate.PolygonVertices = std::move(verticesByAreaTrigger[areaTriggerTemplate.Id.Id]);
areaTriggerTemplate.PolygonVerticesTarget = std::move(verticesTargetByAreaTrigger[areaTriggerTemplate.Id.Id]);
}
areaTriggerTemplate.Actions = std::move(actionsByAreaTrigger[areaTriggerTemplate.Id]);
areaTriggerTemplate.IsServerSide = isServer;
areaTriggerTemplate.InitMaxSearchRadius();
_areaTriggerTemplateMap[AreaTriggerTemplateKey(areaTriggerTemplate.Id, isServer)] = areaTriggerTemplate;
_areaTriggerTemplateStore[areaTriggerTemplate.Id] = areaTriggerTemplate;
}
while (templates->NextRow());
}
// 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, Id, IsServer, MapId, PosX, PosY, PosZ, PhaseId, PhaseGroup, PhaseUseFlags, Comment FROM `areatrigger_positions`"))
{
do
{
Field* fields = templates->Fetch();
AreaTriggerServerPosition position;
position.SpawnId = fields[0].GetUInt64();
position.Id = fields[1].GetUInt32();
position.IsServer = fields[2].GetUInt8() == 1;
uint32 mapId = fields[3].GetUInt32();
float posX = fields[4].GetFloat();
float posY = fields[5].GetFloat();
float posZ = fields[6].GetFloat();
position.Location = WorldLocation(mapId, posX, posY, posZ);
if (!MapManager::IsValidMapCoord(position.Location))
{
TC_LOG_ERROR("sql.sql", "Table `areatrigger_srv_position` has listed an invalid position: Id: %u, IsServer: %d. MapId {%d}, Position {%f, %f, %f}",
position.Id, position.IsServer, mapId, posX, posY, posZ);
continue;
}
position.PhaseId = fields[7].GetUInt32();
position.PhaseGroup = fields[8].GetUInt32();
position.PhaseUseFlags = fields[9].GetUInt8();
auto iter = _areaTriggerTemplateMap.find(AreaTriggerTemplateKey(position.Id, position.IsServer));
if (iter == _areaTriggerTemplateMap.end())
{
TC_LOG_ERROR("sql.sql", "Table `areatrigger_srv_position` has listed areatrigger that doesn't exist: Id: %u, IsServer: %d",
position.Id, position.IsServer);
continue;
}
// Add the trigger to a map::cell map, which is later used by GridLoader to query
CellCoord cellCoord = Trinity::ComputeCellCoord(position.Location.GetPositionX(), position.Location.GetPositionY());
auto iterMap = _areaTriggersGrid.insert(MapAreaTriggersMap::value_type(mapId, CellAreaTriggersMap()));
auto iterCell = iterMap.first->second.insert(CellAreaTriggersMap::value_type(cellCoord.GetId(), CellGuidSet()));
iterCell.first->second.insert(position.SpawnId);
// add the position to the map
_areaTriggerSpawnMap[position.SpawnId] = position;
} while (templates->NextRow());
}
// 0 1 2 3 4 5 6 7 8 9 10
if (QueryResult areatriggerSpellMiscs = WorldDatabase.Query("SELECT SpellMiscId, AreaTriggerId, MoveCurveId, ScaleCurveId, MorphCurveId, FacingCurveId, AnimId, AnimKitId, DecalPropertiesId, TimeToTarget, TimeToTargetScale FROM `spell_areatrigger`"))
{
@@ -293,7 +207,7 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
miscTemplate.MiscId = areatriggerSpellMiscFields[0].GetUInt32();
uint32 areatriggerId = areatriggerSpellMiscFields[1].GetUInt32();
miscTemplate.Template = GetAreaTriggerTemplate(areatriggerId);
miscTemplate.Template = GetAreaTriggerTemplate({ areatriggerId, false });
if (!miscTemplate.Template)
{
@@ -381,25 +295,77 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
TC_LOG_INFO("server.loading", ">> Loaded 0 AreaTrigger templates circular movement infos. DB table `spell_areatrigger_circular` is empty.");
}
TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " spell areatrigger templates in %u ms.", _areaTriggerTemplateMap.size(), GetMSTimeDiffToNow(oldMSTime));
TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " spell areatrigger templates in %u ms.", _areaTriggerTemplateStore.size(), GetMSTimeDiffToNow(oldMSTime));
}
AreaTriggerTemplate const* AreaTriggerDataStore::GetAreaTriggerTemplate(uint32 areaTriggerId) const
void AreaTriggerDataStore::LoadAreaTriggerSpawns()
{
auto itr = _areaTriggerTemplateMap.find(AreaTriggerTemplateKey(areaTriggerId, false));
if (itr != _areaTriggerTemplateMap.end())
return &itr->second;
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 FROM `areatrigger`"))
{
do
{
Field* fields = templates->Fetch();
return nullptr;
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());
if (!GetAreaTriggerTemplate(areaTriggerid))
{
TC_LOG_ERROR("sql.sql", "Table `areatrigger` has listed areatrigger that doesn't exist: Id: %u, IsServerSide: %u for SpawnId " UI64FMTD,
areaTriggerid.Id, uint32(areaTriggerid.IsServerSide), spawnId);
continue;
}
if (!MapManager::IsValidMapCoord(location))
{
TC_LOG_ERROR("sql.sql", "Table `areatrigger` has listed an invalid position: SpawnId: " UI64FMTD ", MapId %u, Position {%s}",
spawnId, location.GetMapId(), location.ToString().c_str());
continue;
}
AreaTriggerSpawn spawn;
spawn.SpawnId = spawnId;
spawn.Id = areaTriggerid;
spawn.Location.WorldRelocate(location);
spawn.PhaseUseFlags = fields[8].GetUInt8();
spawn.PhaseId = fields[9].GetUInt32();
spawn.PhaseGroup = fields[10].GetUInt32();
// Add the trigger to a map::cell map, which is later used by GridLoader to query
CellCoord cellCoord = Trinity::ComputeCellCoord(spawn.Location.GetPositionX(), spawn.Location.GetPositionY());
_areaTriggerSpawnsByLocation[{ spawn.Location.GetMapId(), cellCoord.GetId() }].insert(spawnId);
// add the position to the map
_areaTriggerSpawnsBySpawnId[spawnId] = spawn;
} while (templates->NextRow());
}
TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " areatrigger spawns in %u ms.", _areaTriggerSpawnsBySpawnId.size(), GetMSTimeDiffToNow(oldMSTime));
}
AreaTriggerTemplate const* AreaTriggerDataStore::GetAreaTriggerTemplate(AreaTriggerId const& areaTriggerId) const
{
return Trinity::Containers::MapGetValuePtr(_areaTriggerTemplateStore, areaTriggerId);
}
AreaTriggerMiscTemplate const* AreaTriggerDataStore::GetAreaTriggerMiscTemplate(uint32 spellMiscValue) const
{
auto itr = _areaTriggerTemplateSpellMisc.find(spellMiscValue);
if (itr != _areaTriggerTemplateSpellMisc.end())
return &itr->second;
return Trinity::Containers::MapGetValuePtr(_areaTriggerTemplateSpellMisc, spellMiscValue);
}
return nullptr;
std::set<ObjectGuid::LowType> const* AreaTriggerDataStore::GetAreaTriggersForMapAndCell(uint32 mapId, uint32 cellId) const
{
return Trinity::Containers::MapGetValuePtr(_areaTriggerSpawnsByLocation, { mapId, cellId });
}
AreaTriggerSpawn const* AreaTriggerDataStore::GetAreaTriggerSpawn(ObjectGuid::LowType spawnId) const
{
return Trinity::Containers::MapGetValuePtr(_areaTriggerSpawnsBySpawnId, spawnId);
}
AreaTriggerDataStore* AreaTriggerDataStore::Instance()

View File

@@ -24,17 +24,18 @@
class AreaTriggerTemplate;
class AreaTriggerMiscTemplate;
struct AreaTriggerServerPosition;
struct AreaTriggerId;
struct AreaTriggerSpawn;
class TC_GAME_API AreaTriggerDataStore
{
public:
void LoadAreaTriggerTemplates();
void LoadAreaTriggerSpawns();
std::set<ObjectGuid::LowType> const* GetAreaTriggersForMapAndCell(uint32 mapId, uint32 cellId) const;
AreaTriggerServerPosition const* GetAreaTriggerServerPosition(uint32 spawnId) const;
AreaTriggerTemplate const* GetAreaTriggerServerTemplate(uint32 id) const;
AreaTriggerTemplate const* GetAreaTriggerTemplate(uint32 areaTriggerId) const;
AreaTriggerSpawn const* GetAreaTriggerSpawn(ObjectGuid::LowType spawnId) const;
AreaTriggerTemplate const* GetAreaTriggerTemplate(AreaTriggerId const& areaTriggerId) const;
AreaTriggerMiscTemplate const* GetAreaTriggerMiscTemplate(uint32 spellMiscValue) const;
static AreaTriggerDataStore* Instance();

View File

@@ -192,13 +192,12 @@ void ObjectGridLoader::Visit(CreatureMapType &m)
LoadHelper(cell_guids.creatures, cellCoord, m, i_creatures, i_map);
}
void ObjectGridLoader::Visit(AreaTriggerMapType &m)
void ObjectGridLoader::Visit(AreaTriggerMapType& m)
{
CellCoord cellCoord = i_cell.GetCellCoord();
CellGuidSet const* areaTriggers = sAreaTriggerDataStore->GetAreaTriggersForMapAndCell(i_map->GetId(), cellCoord.GetId());
if (!areaTriggers)
return;
LoadHelper(*areaTriggers, cellCoord, m, i_areaTriggers, i_map);
if (areaTriggers)
LoadHelper(*areaTriggers, cellCoord, m, i_areaTriggers, i_map);
}
void ObjectWorldLoader::Visit(CorpseMapType& /*m*/)

View File

@@ -32,7 +32,7 @@ class TC_GAME_API ObjectGridLoader
public:
ObjectGridLoader(NGridType& grid, Map* map, Cell const& cell)
: i_cell(cell), i_grid(grid), i_map(map), i_gameObjects(0), i_creatures(0), i_corpses (0)
: i_cell(cell), i_grid(grid), i_map(map), i_gameObjects(0), i_creatures(0), i_corpses(0), i_areaTriggers(0)
{ }
void Visit(GameObjectMapType &m);

View File

@@ -16,7 +16,6 @@
*/
#include "Map.h"
#include "AreaTriggerDataStore.h"
#include "Battleground.h"
#include "CellImpl.h"
#include "CharacterPackets.h"

View File

@@ -25,7 +25,6 @@
class AccountMgr;
class AreaTrigger;
class AreaTriggerAI;
class AreaTriggerTemplate;
class AuctionHouseObject;
class Aura;
class AuraScript;
@@ -450,7 +449,6 @@ class TC_GAME_API AreaTriggerScript : public ScriptObject
// Called when the area trigger is activated by a player.
virtual bool OnTrigger(Player* /*player*/, AreaTriggerEntry const* /*trigger*/, bool /*entered*/) { return false; }
virtual bool OnTriggerServer(Player* /*player*/, AreaTriggerTemplate const* /*triggerTemplate*/, bool /*entered*/) { return false; }
};
class TC_GAME_API OnlyOnceAreaTriggerScript : public AreaTriggerScript

View File

@@ -2034,6 +2034,9 @@ void World::SetInitialWorldSettings()
TC_LOG_INFO("server.loading", "Loading AreaTrigger Templates...");
sAreaTriggerDataStore->LoadAreaTriggerTemplates();
TC_LOG_INFO("server.loading", "Loading AreaTrigger Spawns...");
sAreaTriggerDataStore->LoadAreaTriggerSpawns();
TC_LOG_INFO("server.loading", "Loading Conversation Templates...");
sConversationDataStore->LoadConversationTemplates();