Core/AreaTriggers: Code cleanup
Port From (https://github.com/TrinityCore/TrinityCore/commit/7851cd3a9618b245c9b425dcaf71bbadbfecd054)
This commit is contained in:
@@ -28,64 +28,45 @@ namespace Game.DataStorage
|
||||
{
|
||||
AreaTriggerDataStorage() { }
|
||||
|
||||
public AreaTriggerTemplate GetAreaTriggerServerTemplate(uint areaTriggerId)
|
||||
{
|
||||
return _areaTriggerTemplateMap.LookupByKey(new AreaTriggerTemplateKey(areaTriggerId, true));
|
||||
}
|
||||
|
||||
public SortedSet<ulong> GetAreaTriggersForMapAndCell(uint mapId, uint cellId)
|
||||
{
|
||||
if (!_areaTriggersGrid.ContainsKey(mapId))
|
||||
return null;
|
||||
|
||||
return _areaTriggersGrid[mapId].LookupByKey(cellId);
|
||||
}
|
||||
|
||||
public AreaTriggerServerPosition GetAreaTriggerServerPosition(uint spawnId)
|
||||
{
|
||||
return _areaTriggerSpawnMap.LookupByKey(spawnId);
|
||||
}
|
||||
|
||||
public void LoadAreaTriggerTemplates()
|
||||
{
|
||||
uint oldMSTime = Time.GetMSTime();
|
||||
MultiMap<uint, Vector2> verticesByAreaTrigger = new MultiMap<uint, Vector2>();
|
||||
MultiMap<uint, Vector2> verticesTargetByAreaTrigger = new MultiMap<uint, Vector2>();
|
||||
MultiMap<uint, Vector3> splinesBySpellMisc = new MultiMap<uint, Vector3>();
|
||||
MultiMap<uint, AreaTriggerAction> actionsByAreaTrigger = new MultiMap<uint, AreaTriggerAction>();
|
||||
MultiMap<AreaTriggerId, AreaTriggerAction> actionsByAreaTrigger = new MultiMap<AreaTriggerId, AreaTriggerAction>();
|
||||
|
||||
// 0 1 2 3
|
||||
SQLResult templateActions = DB.World.Query("SELECT AreaTriggerId, ActionType, ActionParam, TargetType FROM `areatrigger_template_actions`");
|
||||
// 0 1 2 3 4
|
||||
SQLResult templateActions = DB.World.Query("SELECT AreaTriggerId, IsServerSide, ActionType, ActionParam, TargetType FROM `areatrigger_template_actions`");
|
||||
if (!templateActions.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
uint areaTriggerId = templateActions.Read<uint>(0);
|
||||
AreaTriggerId areaTriggerId = new() { Id = templateActions.Read<uint>(0), IsServerSide = templateActions.Read<byte>(1) == 1 };
|
||||
|
||||
AreaTriggerAction action;
|
||||
action.Param = templateActions.Read<uint>(2);
|
||||
action.ActionType = (AreaTriggerActionTypes)templateActions.Read<uint>(1);
|
||||
action.TargetType = (AreaTriggerActionUserTypes)templateActions.Read<uint>(3);
|
||||
action.Param = templateActions.Read<uint>(3);
|
||||
action.ActionType = (AreaTriggerActionTypes)templateActions.Read<uint>(2);
|
||||
action.TargetType = (AreaTriggerActionUserTypes)templateActions.Read<uint>(4);
|
||||
|
||||
if (action.ActionType >= AreaTriggerActionTypes.Max)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, "Table `areatrigger_template_actions` has invalid ActionType ({0}) for AreaTriggerId {1} and Param {2}", action.ActionType, areaTriggerId, action.Param);
|
||||
Log.outError(LogFilter.Sql, $"Table `areatrigger_template_actions` has invalid ActionType ({action.ActionType}, IsServerSide: {areaTriggerId.IsServerSide}) for AreaTriggerId {areaTriggerId.Id} and Param {action.Param}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (action.TargetType >= AreaTriggerActionUserTypes.Max)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, "Table `areatrigger_template_actions` has invalid TargetType ({0}) for AreaTriggerId {1} and Param {2}", action.TargetType, areaTriggerId, action.Param);
|
||||
Log.outError(LogFilter.Sql, $"Table `areatrigger_template_actions` has invalid TargetType ({action.TargetType}, IsServerSide: {areaTriggerId.IsServerSide}) for AreaTriggerId {areaTriggerId} and Param {action.Param}");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (action.ActionType == AreaTriggerActionTypes.Teleport)
|
||||
{
|
||||
WorldSafeLocsEntry safeLoc = Global.ObjectMgr.GetWorldSafeLoc(action.Param);
|
||||
if (safeLoc == null)
|
||||
if (Global.ObjectMgr.GetWorldSafeLoc(action.Param) == null)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, $"Table `areatrigger_template_actions` has invalid entry ({areaTriggerId}) with TargetType=Teleport and Param ({action.Param}) not a valid world safe loc entry");
|
||||
Log.outError(LogFilter.Sql, $"Table `areatrigger_template_actions` has invalid (Id: {areaTriggerId}, IsServerSide: {areaTriggerId.IsServerSide}) with TargetType=Teleport and Param ({action.Param}) not a valid world safe loc entry");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -140,29 +121,28 @@ namespace Game.DataStorage
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 AreaTrigger templates splines. DB table `spell_areatrigger_splines` is empty.");
|
||||
}
|
||||
|
||||
// 0 1 2 3 4 5 6 7 8 9 10
|
||||
SQLResult templates = DB.World.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
|
||||
SQLResult templates = DB.World.Query("SELECT Id, IsServerSide, Type, Flags, Data0, Data1, Data2, Data3, Data4, Data5, ScriptName FROM `areatrigger_template`");
|
||||
if (!templates.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
AreaTriggerTemplate areaTriggerTemplate = new AreaTriggerTemplate();
|
||||
areaTriggerTemplate.Id = templates.Read<uint>(0);
|
||||
bool isServer = templates.Read<byte>(1) == 1;
|
||||
areaTriggerTemplate.Id = new() { Id = templates.Read<uint>(0), IsServerSide = templates.Read<byte>(1) == 1 };
|
||||
AreaTriggerTypes type = (AreaTriggerTypes)templates.Read<byte>(2);
|
||||
|
||||
if (type >= AreaTriggerTypes.Max)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, "Table `areatrigger_template` has listed areatrigger (Id: {0}) with invalid type {1}.", areaTriggerTemplate.Id, type);
|
||||
Log.outError(LogFilter.Sql, $"Table `areatrigger_template` has listed areatrigger (Id: {areaTriggerTemplate.Id.Id}, IsServerSide: {areaTriggerTemplate.Id.IsServerSide}) with invalid type {type}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
areaTriggerTemplate.TriggerType = type;
|
||||
areaTriggerTemplate.Flags = (AreaTriggerFlags)templates.Read<uint>(3);
|
||||
|
||||
if (isServer && areaTriggerTemplate.Flags != 0)
|
||||
if (areaTriggerTemplate.Id.IsServerSide && areaTriggerTemplate.Flags != 0)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, $"Table `areatrigger_template` has listed server-side areatrigger (Id: {areaTriggerTemplate.Id}) with none-zero flags");
|
||||
Log.outError(LogFilter.Sql, $"Table `areatrigger_template` has listed server-side areatrigger (Id: {areaTriggerTemplate.Id.Id}, IsServerSide: {areaTriggerTemplate.Id.IsServerSide}) with none-zero flags");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -173,67 +153,19 @@ namespace Game.DataStorage
|
||||
}
|
||||
|
||||
areaTriggerTemplate.ScriptId = Global.ObjectMgr.GetScriptId(templates.Read<string>(10));
|
||||
areaTriggerTemplate.PolygonVertices = verticesByAreaTrigger[areaTriggerTemplate.Id];
|
||||
areaTriggerTemplate.PolygonVerticesTarget = verticesTargetByAreaTrigger[areaTriggerTemplate.Id];
|
||||
if (!areaTriggerTemplate.Id.IsServerSide)
|
||||
{
|
||||
areaTriggerTemplate.PolygonVertices = verticesByAreaTrigger[areaTriggerTemplate.Id.Id];
|
||||
areaTriggerTemplate.PolygonVerticesTarget = verticesTargetByAreaTrigger[areaTriggerTemplate.Id.Id];
|
||||
}
|
||||
areaTriggerTemplate.Actions = actionsByAreaTrigger[areaTriggerTemplate.Id];
|
||||
areaTriggerTemplate.IsServerSide = isServer;
|
||||
|
||||
areaTriggerTemplate.InitMaxSearchRadius();
|
||||
_areaTriggerTemplateMap[new 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
|
||||
SQLResult templatePos = DB.World.Query("SELECT SpawnId, Id, IsServer, MapId, PosX, PosY, PosZ, PhaseId, PhaseGroup, PhaseUseFlags, Comment FROM `areatrigger_positions`");
|
||||
if (!templatePos.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
AreaTriggerServerPosition position = new AreaTriggerServerPosition();
|
||||
position.SpawnId = templatePos.Read<ulong>(0);
|
||||
position.Id = templatePos.Read<uint>(1);
|
||||
position.IsServer = templatePos.Read<byte>(2) == 1;
|
||||
uint mapId = templatePos.Read<uint>(3);
|
||||
|
||||
float posX = templatePos.Read<float>(4);
|
||||
float posY = templatePos.Read<float>(5);
|
||||
float posZ = templatePos.Read<float>(6);
|
||||
position.Location = new WorldLocation(mapId, posX, posY, posZ);
|
||||
|
||||
if (!GridDefines.IsValidMapCoord(position.Location))
|
||||
{
|
||||
Log.outError(LogFilter.Sql, $"Table `areatrigger_srv_position` has listed an invalid position: Id: {position.Id}, IsServer: {position.IsServer}. MapId ({mapId}), Position ({posX}, {posY}, {posZ})");
|
||||
continue;
|
||||
}
|
||||
|
||||
position.PhaseId = templatePos.Read<uint>(7);
|
||||
position.PhaseGroup = templatePos.Read<uint>(8);
|
||||
position.PhaseUseFlags = templatePos.Read<byte>(9);
|
||||
|
||||
var template = _areaTriggerTemplateMap.LookupByKey(new AreaTriggerTemplateKey(position.Id, position.IsServer));
|
||||
if (template == null)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, $"Table `areatrigger_srv_position` has listed areatrigger that doesn't exist: Id: {position.Id}, IsServer: {position.IsServer}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add the trigger to a map::cell map, which is later used by GridLoader to query
|
||||
CellCoord cellCoord = GridDefines.ComputeCellCoord(position.Location.GetPositionX(), position.Location.GetPositionY());
|
||||
if (!_areaTriggersGrid.ContainsKey(mapId))
|
||||
_areaTriggersGrid[mapId] = new Dictionary<uint, SortedSet<ulong>>();
|
||||
|
||||
if (!_areaTriggersGrid[mapId].ContainsKey(cellCoord.GetId()))
|
||||
_areaTriggersGrid[mapId][cellCoord.GetId()] = new SortedSet<ulong>();
|
||||
|
||||
_areaTriggersGrid[mapId][cellCoord.GetId()].Add(position.SpawnId);
|
||||
|
||||
// add the position to the map
|
||||
_areaTriggerSpawnMap[(uint)position.SpawnId] = position;
|
||||
} while (templates.NextRow());
|
||||
}
|
||||
|
||||
// 0 1 2 3 4 5 6 7 8 9 10
|
||||
SQLResult areatriggerSpellMiscs = DB.World.Query("SELECT SpellMiscId, AreaTriggerId, MoveCurveId, ScaleCurveId, MorphCurveId, FacingCurveId, AnimId, AnimKitId, DecalPropertiesId, TimeToTarget, TimeToTargetScale FROM `spell_areatrigger`");
|
||||
if (!areatriggerSpellMiscs.IsEmpty())
|
||||
@@ -244,7 +176,7 @@ namespace Game.DataStorage
|
||||
miscTemplate.MiscId = areatriggerSpellMiscs.Read<uint>(0);
|
||||
|
||||
uint areatriggerId = areatriggerSpellMiscs.Read<uint>(1);
|
||||
miscTemplate.Template = GetAreaTriggerTemplate(areatriggerId);
|
||||
miscTemplate.Template = GetAreaTriggerTemplate(new AreaTriggerId() { Id = areatriggerId, IsServerSide = false });
|
||||
|
||||
if (miscTemplate.Template == null)
|
||||
{
|
||||
@@ -344,12 +276,62 @@ namespace Game.DataStorage
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 AreaTrigger templates circular movement infos. DB table `spell_areatrigger_circular` is empty.");
|
||||
}
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} spell areatrigger templates in {1} ms.", _areaTriggerTemplateMap.Count, Time.GetMSTimeDiffToNow(oldMSTime));
|
||||
Log.outInfo(LogFilter.ServerLoading, $"Loaded {_areaTriggerTemplateStore.Count} spell areatrigger templates in {Time.GetMSTimeDiffToNow(oldMSTime)} ms.");
|
||||
}
|
||||
|
||||
public AreaTriggerTemplate GetAreaTriggerTemplate(uint areaTriggerId)
|
||||
public void LoadAreaTriggerSpawns()
|
||||
{
|
||||
return _areaTriggerTemplateMap.LookupByKey(new AreaTriggerTemplateKey(areaTriggerId, false));
|
||||
uint oldMSTime = Time.GetMSTime();
|
||||
// Load area trigger positions (to put them on the server)
|
||||
// 0 1 2 3 4 5 6 7 8 9 10
|
||||
SQLResult templates = DB.World.Query("SELECT SpawnId, AreaTriggerId, IsServerSide, MapId, PosX, PosY, PosZ, Orientation, PhaseUseFlags, PhaseId, PhaseGroup FROM `areatrigger`");
|
||||
if (!templates.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
ulong spawnId = templates.Read<ulong>(0);
|
||||
AreaTriggerId areaTriggerId = new() { Id = templates.Read<uint>(1), IsServerSide = templates.Read<byte>(2) == 1 };
|
||||
WorldLocation location = new(templates.Read<uint>(3), templates.Read<float>(4), templates.Read<float>(5), templates.Read<float>(6), templates.Read<float>(7));
|
||||
|
||||
if (GetAreaTriggerTemplate(areaTriggerId) == null)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed areatrigger that doesn't exist: Id: {areaTriggerId.Id}, IsServerSide: {areaTriggerId.IsServerSide} for SpawnId {spawnId}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!GridDefines.IsValidMapCoord(location))
|
||||
{
|
||||
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed an invalid position: SpawnId: {spawnId}, MapId: {location.GetMapId()}, Position: {location}");
|
||||
continue;
|
||||
}
|
||||
|
||||
AreaTriggerSpawn spawn = new AreaTriggerSpawn();
|
||||
spawn.SpawnId = spawnId;
|
||||
spawn.Id = areaTriggerId;
|
||||
spawn.Location.WorldRelocate(location);
|
||||
|
||||
spawn.PhaseUseFlags = templates.Read<byte>(8);
|
||||
spawn.PhaseId = templates.Read<uint>(9);
|
||||
spawn.PhaseGroup = templates.Read<uint>(10);
|
||||
|
||||
// Add the trigger to a map::cell map, which is later used by GridLoader to query
|
||||
CellCoord cellCoord = GridDefines.ComputeCellCoord(spawn.Location.GetPositionX(), spawn.Location.GetPositionY());
|
||||
if (!_areaTriggerSpawnsByLocation.ContainsKey((spawn.Location.GetMapId(), cellCoord.GetId())))
|
||||
_areaTriggerSpawnsByLocation[(spawn.Location.GetMapId(), cellCoord.GetId())] = new SortedSet<ulong>();
|
||||
|
||||
_areaTriggerSpawnsByLocation[(spawn.Location.GetMapId(), cellCoord.GetId())].Add(spawnId);
|
||||
|
||||
// add the position to the map
|
||||
_areaTriggerSpawnsBySpawnId[spawnId] = spawn;
|
||||
} while (templates.NextRow());
|
||||
}
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, $"Loaded {_areaTriggerSpawnsBySpawnId.Count} areatrigger spawns in {Time.GetMSTimeDiffToNow(oldMSTime)} ms.");
|
||||
}
|
||||
|
||||
public AreaTriggerTemplate GetAreaTriggerTemplate(AreaTriggerId areaTriggerId)
|
||||
{
|
||||
return _areaTriggerTemplateStore.LookupByKey(areaTriggerId);
|
||||
}
|
||||
|
||||
public AreaTriggerMiscTemplate GetAreaTriggerMiscTemplate(uint spellMiscValue)
|
||||
@@ -357,9 +339,19 @@ namespace Game.DataStorage
|
||||
return _areaTriggerTemplateSpellMisc.LookupByKey(spellMiscValue);
|
||||
}
|
||||
|
||||
Dictionary<uint, Dictionary<uint, SortedSet<ulong>>> _areaTriggersGrid = new Dictionary<uint, Dictionary<uint, SortedSet<ulong>>>();
|
||||
Dictionary<uint, AreaTriggerServerPosition> _areaTriggerSpawnMap = new Dictionary<uint, AreaTriggerServerPosition>();
|
||||
Dictionary<AreaTriggerTemplateKey, AreaTriggerTemplate> _areaTriggerTemplateMap = new Dictionary<AreaTriggerTemplateKey, AreaTriggerTemplate>();
|
||||
public SortedSet<ulong> GetAreaTriggersForMapAndCell(uint mapId, uint cellId)
|
||||
{
|
||||
return _areaTriggerSpawnsByLocation.LookupByKey((mapId, cellId));
|
||||
}
|
||||
|
||||
public AreaTriggerSpawn GetAreaTriggerSpawn(ulong spawnId)
|
||||
{
|
||||
return _areaTriggerSpawnsBySpawnId.LookupByKey(spawnId);
|
||||
}
|
||||
|
||||
Dictionary<(uint mapId, uint cellId), SortedSet<ulong>> _areaTriggerSpawnsByLocation = new Dictionary<(uint mapId, uint cellId), SortedSet<ulong>>();
|
||||
Dictionary<ulong, AreaTriggerSpawn> _areaTriggerSpawnsBySpawnId = new Dictionary<ulong, AreaTriggerSpawn>();
|
||||
Dictionary<AreaTriggerId, AreaTriggerTemplate> _areaTriggerTemplateStore = new Dictionary<AreaTriggerId, AreaTriggerTemplate>();
|
||||
Dictionary<uint, AreaTriggerMiscTemplate> _areaTriggerTemplateSpellMisc = new Dictionary<uint, AreaTriggerMiscTemplate>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,9 +100,9 @@ namespace Game.Entities
|
||||
|
||||
_areaTriggerTemplate = _areaTriggerMiscTemplate.Template;
|
||||
|
||||
_Create(ObjectGuid.Create(HighGuid.AreaTrigger, GetMapId(), GetTemplate().Id, caster.GetMap().GenerateLowGuid(HighGuid.AreaTrigger)));
|
||||
_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);
|
||||
@@ -212,20 +212,20 @@ namespace Game.Entities
|
||||
return at;
|
||||
}
|
||||
|
||||
bool LoadFromDB(uint spawnId, Map map, bool addToMap, bool allowDuplicate)
|
||||
public override bool LoadFromDB(ulong spawnId, Map map, bool addToMap, bool allowDuplicate)
|
||||
{
|
||||
AreaTriggerServerPosition position = Global.AreaTriggerDataStorage.GetAreaTriggerServerPosition(spawnId);
|
||||
AreaTriggerSpawn position = Global.AreaTriggerDataStorage.GetAreaTriggerSpawn(spawnId);
|
||||
if (position == null)
|
||||
return false;
|
||||
|
||||
AreaTriggerTemplate areaTriggerTemplate = Global.AreaTriggerDataStorage.GetAreaTriggerServerTemplate(position.Id);
|
||||
AreaTriggerTemplate areaTriggerTemplate = Global.AreaTriggerDataStorage.GetAreaTriggerTemplate(position.Id);
|
||||
if (areaTriggerTemplate == null)
|
||||
return false;
|
||||
|
||||
return CreateServer(map, areaTriggerTemplate, position);
|
||||
}
|
||||
|
||||
bool CreateServer(Map map, AreaTriggerTemplate areaTriggerTemplate, AreaTriggerServerPosition position)
|
||||
bool CreateServer(Map map, AreaTriggerTemplate areaTriggerTemplate, AreaTriggerSpawn position)
|
||||
{
|
||||
SetMap(map);
|
||||
Relocate(position.Location);
|
||||
@@ -237,19 +237,21 @@ namespace Game.Entities
|
||||
|
||||
_areaTriggerTemplate = areaTriggerTemplate;
|
||||
|
||||
_Create(ObjectGuid.Create(HighGuid.AreaTrigger, GetMapId(), areaTriggerTemplate.Id, GetMap().GenerateLowGuid(HighGuid.AreaTrigger)));
|
||||
_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 != 0 || position.PhaseGroup != 0 || position.PhaseUseFlags != 0)
|
||||
if (position.PhaseUseFlags != 0 || position.PhaseId != 0 || position.PhaseGroup != 0)
|
||||
PhasingHandler.InitDbPhaseShift(GetPhaseShift(), (PhaseUseFlagsValues)position.PhaseUseFlags, position.PhaseId, position.PhaseGroup);
|
||||
|
||||
UpdateShape();
|
||||
|
||||
AI_Initialize();
|
||||
|
||||
_ai.OnCreate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -258,34 +260,31 @@ namespace Game.Entities
|
||||
base.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(AreaTriggerFlags.HasAttached))
|
||||
{
|
||||
Unit target = GetTarget();
|
||||
if (target)
|
||||
GetMap().AreaTriggerRelocation(this, target.GetPositionX(), target.GetPositionY(), target.GetPositionZ(), target.GetOrientation());
|
||||
}
|
||||
else
|
||||
UpdateSplinePosition(diff);
|
||||
|
||||
if (GetDuration() != -1)
|
||||
{
|
||||
if (GetDuration() > diff)
|
||||
_UpdateDuration((int)(_duration - diff));
|
||||
else
|
||||
// "If" order matter here, Orbit > Attached > Splines
|
||||
if (HasOrbit())
|
||||
{
|
||||
Remove(); // expired
|
||||
return;
|
||||
UpdateOrbitPosition(diff);
|
||||
}
|
||||
else if (GetTemplate().HasFlag(AreaTriggerFlags.HasAttached))
|
||||
{
|
||||
Unit target = GetTarget();
|
||||
if (target)
|
||||
GetMap().AreaTriggerRelocation(this, target.GetPositionX(), target.GetPositionY(), target.GetPositionZ(), target.GetOrientation());
|
||||
}
|
||||
else
|
||||
UpdateSplinePosition(diff);
|
||||
|
||||
if (GetDuration() != -1)
|
||||
{
|
||||
if (GetDuration() > diff)
|
||||
_UpdateDuration((int)(_duration - diff));
|
||||
else
|
||||
{
|
||||
Remove(); // expired
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -967,7 +966,7 @@ namespace Game.Entities
|
||||
|
||||
AreaTriggerAI GetAI() { return _ai; }
|
||||
|
||||
public bool IsServerSide() { return _areaTriggerTemplate.IsServerSide; }
|
||||
public bool IsServerSide() { return _areaTriggerTemplate.Id.IsServerSide; }
|
||||
|
||||
public override bool IsNeverVisibleFor(WorldObject seer) { return IsServerSide(); }
|
||||
|
||||
@@ -1034,10 +1033,9 @@ namespace Game.Entities
|
||||
Optional<AreaTriggerOrbitInfo> _orbitInfo;
|
||||
|
||||
AreaTriggerMiscTemplate _areaTriggerMiscTemplate;
|
||||
AreaTriggerTemplate _areaTriggerTemplate;
|
||||
List<ObjectGuid> _insideUnits = new List<ObjectGuid>();
|
||||
|
||||
AreaTriggerAI _ai;
|
||||
|
||||
AreaTriggerTemplate _areaTriggerTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,24 +187,28 @@ namespace Game.Entities
|
||||
}
|
||||
}
|
||||
|
||||
struct AreaTriggerTemplateKey
|
||||
public struct AreaTriggerId
|
||||
{
|
||||
public uint Id;
|
||||
public bool IsServer;
|
||||
public bool IsServerSide;
|
||||
|
||||
public AreaTriggerTemplateKey(uint id, bool isServer)
|
||||
public override int GetHashCode()
|
||||
{
|
||||
Id = id;
|
||||
IsServer = isServer;
|
||||
return Id.GetHashCode() ^ IsServerSide.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(AreaTriggerTemplateKey A, AreaTriggerTemplateKey B)
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return A.Id == B.Id && A.IsServer == B.IsServer;
|
||||
return Equals((AreaTriggerId)obj);
|
||||
}
|
||||
public static bool operator !=(AreaTriggerTemplateKey A, AreaTriggerTemplateKey B)
|
||||
|
||||
public static bool operator ==(AreaTriggerId left, AreaTriggerId right)
|
||||
{
|
||||
return A.Id != B.Id && A.IsServer != B.IsServer;
|
||||
return left.Id == right.Id && left.IsServerSide == right.IsServerSide;
|
||||
}
|
||||
public static bool operator !=(AreaTriggerId left, AreaTriggerId right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +260,7 @@ namespace Game.Entities
|
||||
public bool IsPolygon() { return TriggerType == AreaTriggerTypes.Polygon; }
|
||||
public bool IsCylinder() { return TriggerType == AreaTriggerTypes.Cylinder; }
|
||||
|
||||
public uint Id;
|
||||
public AreaTriggerId Id;
|
||||
public AreaTriggerTypes TriggerType;
|
||||
public AreaTriggerFlags Flags;
|
||||
public uint ScriptId;
|
||||
@@ -265,7 +269,6 @@ namespace Game.Entities
|
||||
public List<Vector2> PolygonVertices = new List<Vector2>();
|
||||
public List<Vector2> PolygonVerticesTarget = new List<Vector2>();
|
||||
public List<AreaTriggerAction> Actions = new List<AreaTriggerAction>();
|
||||
public bool IsServerSide;
|
||||
}
|
||||
|
||||
public unsafe class AreaTriggerMiscTemplate
|
||||
@@ -305,11 +308,10 @@ namespace Game.Entities
|
||||
public List<Vector3> SplinePoints = new List<Vector3>();
|
||||
}
|
||||
|
||||
public class AreaTriggerServerPosition
|
||||
public class AreaTriggerSpawn
|
||||
{
|
||||
public ulong SpawnId;
|
||||
public uint Id;
|
||||
public bool IsServer;
|
||||
public AreaTriggerId Id;
|
||||
public WorldLocation Location;
|
||||
public uint PhaseId;
|
||||
public uint PhaseGroup;
|
||||
|
||||
@@ -364,7 +364,6 @@ namespace Game.Scripting
|
||||
|
||||
// Called when the area trigger is activated by a player.
|
||||
public virtual bool OnTrigger(Player player, AreaTriggerRecord trigger, bool entered) { return false; }
|
||||
public virtual bool OnTriggerServer(Player player, AreaTriggerTemplate triggerTemplate, bool entered) { return false; }
|
||||
}
|
||||
|
||||
public class OnlyOnceAreaTriggerScript : AreaTriggerScript
|
||||
|
||||
@@ -718,6 +718,9 @@ namespace Game
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loading AreaTrigger Templates...");
|
||||
Global.AreaTriggerDataStorage.LoadAreaTriggerTemplates();
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loading AreaTrigger Spawns...");
|
||||
Global.AreaTriggerDataStorage.LoadAreaTriggerSpawns();
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loading Conversation Templates...");
|
||||
Global.ConversationDataStorage.LoadConversationTemplates();
|
||||
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user