Core/AreaTriggers: Implement height check for polygon db2 areatriggers

Port From (https://github.com/TrinityCore/TrinityCore/commit/1c3268155d0165e150d239c3a808d5a8dddeae18)
This commit is contained in:
Hondacrx
2024-08-25 20:45:39 -04:00
parent c2409af60b
commit 22ec091beb
9 changed files with 109 additions and 39 deletions
+19
View File
@@ -1860,6 +1860,25 @@ namespace Framework.Constants
HideIfUnknown = 0x40 HideIfUnknown = 0x40
} }
public enum PathPropertyIndex
{
UseNewLiquidGenerateCode = 0,
AnimaCableId = 1,
AnimaPlayerCondition = 2,
AnimaStartTaper = 3,
AnimaEndTaper = 4,
VolumeHeight = 5,
AiPathGraphMaxStartDist = 6,
AiPathGraphMinTotalDist = 7,
AiPathGraphAreaControl = 8,
AiPathGraphAreaId = 9,
AiPathGraphWidth = 10,
AiPathDefaultFollowStyle = 11,
AiPathConstrainSteering = 12,
Phase = 13,
SteepSlopeDegrees = 14
}
public enum PhaseEntryFlags : int public enum PhaseEntryFlags : int
{ {
ReadOnly = 0x1, ReadOnly = 0x1,
@@ -993,6 +993,9 @@ namespace Framework.Database
// PathNode.db2 // PathNode.db2
PrepareStatement(HotfixStatements.SEL_PATH_NODE, "SELECT ID, PathID, Sequence, LocationID FROM path_node WHERE (`VerifiedBuild` > 0) = ?"); PrepareStatement(HotfixStatements.SEL_PATH_NODE, "SELECT ID, PathID, Sequence, LocationID FROM path_node WHERE (`VerifiedBuild` > 0) = ?");
// PathProperty.db2
PrepareStatement(HotfixStatements.SEL_PATH_PROPERTY, "SELECT ID, PathID, PropertyIndex, Value FROM path_property WHERE (`VerifiedBuild` > 0) = ?");
// Phase.db2 // Phase.db2
PrepareStatement(HotfixStatements.SEL_PHASE, "SELECT ID, Flags FROM phase WHERE (`VerifiedBuild` > 0) = ?"); PrepareStatement(HotfixStatements.SEL_PHASE, "SELECT ID, Flags FROM phase WHERE (`VerifiedBuild` > 0) = ?");
@@ -2090,6 +2093,8 @@ namespace Framework.Database
SEL_PATH_NODE, SEL_PATH_NODE,
SEL_PATH_PROPERTY,
SEL_PHASE, SEL_PHASE,
SEL_PHASE_X_PHASE_GROUP, SEL_PHASE_X_PHASE_GROUP,
+2
View File
@@ -254,6 +254,7 @@ namespace Game.DataStorage
ParagonReputationStorage = ReadDB2<ParagonReputationRecord>("ParagonReputation.db2", HotfixStatements.SEL_PARAGON_REPUTATION); ParagonReputationStorage = ReadDB2<ParagonReputationRecord>("ParagonReputation.db2", HotfixStatements.SEL_PARAGON_REPUTATION);
PathStorage = ReadDB2<PathRecord>("Path.db2", HotfixStatements.SEL_PATH); PathStorage = ReadDB2<PathRecord>("Path.db2", HotfixStatements.SEL_PATH);
PathNodeStorage = ReadDB2<PathNodeRecord>("PathNode.db2", HotfixStatements.SEL_PATH_NODE); PathNodeStorage = ReadDB2<PathNodeRecord>("PathNode.db2", HotfixStatements.SEL_PATH_NODE);
PathPropertyStorage = ReadDB2<PathPropertyRecord>("PathProperty.db2", HotfixStatements.SEL_PATH_PROPERTY);
PhaseStorage = ReadDB2<PhaseRecord>("Phase.db2", HotfixStatements.SEL_PHASE); PhaseStorage = ReadDB2<PhaseRecord>("Phase.db2", HotfixStatements.SEL_PHASE);
PhaseXPhaseGroupStorage = ReadDB2<PhaseXPhaseGroupRecord>("PhaseXPhaseGroup.db2", HotfixStatements.SEL_PHASE_X_PHASE_GROUP); PhaseXPhaseGroupStorage = ReadDB2<PhaseXPhaseGroupRecord>("PhaseXPhaseGroup.db2", HotfixStatements.SEL_PHASE_X_PHASE_GROUP);
PlayerConditionStorage = ReadDB2<PlayerConditionRecord>("PlayerCondition.db2", HotfixStatements.SEL_PLAYER_CONDITION, HotfixStatements.SEL_PLAYER_CONDITION_LOCALE); PlayerConditionStorage = ReadDB2<PlayerConditionRecord>("PlayerCondition.db2", HotfixStatements.SEL_PLAYER_CONDITION, HotfixStatements.SEL_PLAYER_CONDITION_LOCALE);
@@ -697,6 +698,7 @@ namespace Game.DataStorage
public static DB6Storage<ParagonReputationRecord> ParagonReputationStorage; public static DB6Storage<ParagonReputationRecord> ParagonReputationStorage;
public static DB6Storage<PathRecord> PathStorage; public static DB6Storage<PathRecord> PathStorage;
public static DB6Storage<PathNodeRecord> PathNodeStorage; public static DB6Storage<PathNodeRecord> PathNodeStorage;
public static DB6Storage<PathPropertyRecord> PathPropertyStorage;
public static DB6Storage<PhaseRecord> PhaseStorage; public static DB6Storage<PhaseRecord> PhaseStorage;
public static DB6Storage<PhaseXPhaseGroupRecord> PhaseXPhaseGroupStorage; public static DB6Storage<PhaseXPhaseGroupRecord> PhaseXPhaseGroupStorage;
public static DB6Storage<PlayerConditionRecord> PlayerConditionStorage; public static DB6Storage<PlayerConditionRecord> PlayerConditionStorage;
+22 -15
View File
@@ -423,28 +423,28 @@ namespace Game.DataStorage
Dictionary<uint, List<PathNodeRecord>> unsortedNodes = new(); Dictionary<uint, List<PathNodeRecord>> unsortedNodes = new();
foreach (var (_, pathNode) in CliDB.PathNodeStorage) foreach (var (_, pathNode) in CliDB.PathNodeStorage)
{ {
if (CliDB.PathStorage.ContainsKey(pathNode.PathID)) if (CliDB.PathStorage.HasRecord(pathNode.PathID) && CliDB.LocationStorage.HasRecord((uint)pathNode.LocationID))
{ {
if (CliDB.LocationStorage.ContainsKey(pathNode.LocationID)) if (!unsortedNodes.ContainsKey(pathNode.PathID))
{ unsortedNodes[pathNode.PathID] = new();
if (!unsortedNodes.ContainsKey(pathNode.PathID))
unsortedNodes[pathNode.PathID] = new();
unsortedNodes[pathNode.PathID].Add(pathNode); unsortedNodes[pathNode.PathID].Add(pathNode);
}
} }
} }
foreach (var (pathId, pathNodes) in unsortedNodes) foreach (var (pathId, pathNodes) in unsortedNodes)
{ {
if (!_paths.ContainsKey(pathId))
_paths[pathId] = new();
pathNodes.OrderBy(node => node.Sequence); pathNodes.OrderBy(node => node.Sequence);
_pathNodes.AddRange(pathId, pathNodes.Select(node => _paths[pathId].Locations.AddRange(pathNodes.Select(node => CliDB.LocationStorage.LookupByKey(node.LocationID).Pos));
{
LocationRecord location = CliDB.LocationStorage.LookupByKey(node.LocationID);
return location.Pos;
}));
} }
foreach (var (_, pathProperty) in CliDB.PathPropertyStorage)
if (CliDB.PathStorage.HasRecord(pathProperty.PathID))
_paths[pathProperty.PathID].Properties.Add(pathProperty);
foreach (var group in PhaseXPhaseGroupStorage.Values) foreach (var group in PhaseXPhaseGroupStorage.Values)
{ {
PhaseRecord phase = PhaseStorage.LookupByKey(group.PhaseId); PhaseRecord phase = PhaseStorage.LookupByKey(group.PhaseId);
@@ -1765,9 +1765,9 @@ namespace Game.DataStorage
return _paragonReputations.LookupByKey(factionId); return _paragonReputations.LookupByKey(factionId);
} }
public List<Vector3> GetNodesForPath(uint pathId) public PathDb2 GetPath(uint pathId)
{ {
return _pathNodes.LookupByKey(pathId); return _paths.LookupByKey(pathId);
} }
public PvpDifficultyRecord GetBattlegroundBracketByLevel(uint mapid, uint level) public PvpDifficultyRecord GetBattlegroundBracketByLevel(uint mapid, uint level)
@@ -2358,7 +2358,7 @@ namespace Game.DataStorage
Dictionary<uint, List<NameGenRecord>[]> _nameGenData = new(); Dictionary<uint, List<NameGenRecord>[]> _nameGenData = new();
List<string>[] _nameValidators = new List<string>[(int)Locale.Total + 1]; List<string>[] _nameValidators = new List<string>[(int)Locale.Total + 1];
Dictionary<uint, ParagonReputationRecord> _paragonReputations = new(); Dictionary<uint, ParagonReputationRecord> _paragonReputations = new();
MultiMap<uint, Vector3> _pathNodes = new(); Dictionary<uint, PathDb2> _paths;
MultiMap<uint, uint> _phasesByGroup = new(); MultiMap<uint, uint> _phasesByGroup = new();
Dictionary<PowerType, PowerTypeRecord> _powerTypes = new(); Dictionary<PowerType, PowerTypeRecord> _powerTypes = new();
Dictionary<uint, byte> _pvpItemBonus = new(); Dictionary<uint, byte> _pvpItemBonus = new();
@@ -2650,6 +2650,13 @@ namespace Game.DataStorage
public short TargetLevelMax; public short TargetLevelMax;
} }
public class PathDb2
{
public uint Id;
public List<Vector3> Locations = new();
public List<PathPropertyRecord> Properties = new();
}
public class ShapeshiftFormModelData public class ShapeshiftFormModelData
{ {
public uint OptionID; public uint OptionID;
+14 -4
View File
@@ -33,6 +33,16 @@ namespace Game.DataStorage
public int LocationID; public int LocationID;
} }
public sealed class PathPropertyRecord
{
public uint Id;
public ushort PathID;
public byte PropertyIndex;
public int Value;
public PathPropertyIndex GetPropertyIndex() { return (PathPropertyIndex)PropertyIndex; }
}
public sealed class PhaseRecord public sealed class PhaseRecord
{ {
public uint Id; public uint Id;
@@ -132,9 +142,9 @@ namespace Game.DataStorage
public uint[] CurrencyCount = new uint[4]; public uint[] CurrencyCount = new uint[4];
public uint[] QuestKillMonster = new uint[6]; public uint[] QuestKillMonster = new uint[6];
public int[] MovementFlags = new int[2]; public int[] MovementFlags = new int[2];
public int[]TraitNodeEntryID = new int[4]; public int[] TraitNodeEntryID = new int[4];
public ushort[]TraitNodeEntryMinRank = new ushort[4]; public ushort[] TraitNodeEntryMinRank = new ushort[4];
public ushort[]TraitNodeEntryMaxRank = new ushort[4]; public ushort[] TraitNodeEntryMaxRank = new ushort[4];
} }
public sealed class PowerDisplayRecord public sealed class PowerDisplayRecord
@@ -176,7 +186,7 @@ namespace Game.DataStorage
public int AwardedAchievementID; public int AwardedAchievementID;
public bool HasFlag(PrestigeLevelInfoFlags prestigeLevelInfoFlags) { return (Flags & (byte)prestigeLevelInfoFlags) != 0; } public bool HasFlag(PrestigeLevelInfoFlags prestigeLevelInfoFlags) { return (Flags & (byte)prestigeLevelInfoFlags) != 0; }
public bool IsDisabled() { return HasFlag(PrestigeLevelInfoFlags.Disabled); } public bool IsDisabled() { return HasFlag(PrestigeLevelInfoFlags.Disabled); }
} }
public sealed class PvpDifficultyRecord public sealed class PvpDifficultyRecord
+2 -1
View File
@@ -2449,7 +2449,8 @@ namespace Game.Entities
return false; return false;
break; break;
case 3: // Polygon case 3: // Polygon
if (!IsInPolygon2D(areaTriggerPos, ObjectMgr.GetVerticesForAreaTrigger(areaTrigger))) var polygon = ObjectMgr.GetAreaTriggerPolygon(areaTrigger.Id);
if (polygon == null || (polygon.Height.HasValue && GetPositionZ() > areaTrigger.Pos.Z + polygon.Height) || !IsInPolygon2D(areaTriggerPos, polygon.Vertices))
return false; return false;
break; break;
case 4: // Cylinder case 4: // Cylinder
+40 -17
View File
@@ -751,23 +751,6 @@ namespace Game
return pointsOfInterestStorage.LookupByKey(id); return pointsOfInterestStorage.LookupByKey(id);
} }
public List<Position> GetVerticesForAreaTrigger(AreaTriggerRecord areaTrigger)
{
List<Position> vertices = new();
if (areaTrigger != null && areaTrigger.ShapeType == 3 /* Polygon */)
{
var pathNodes = Global.DB2Mgr.GetNodesForPath((uint)areaTrigger.ShapeID);
if (pathNodes != null)
vertices.AddRange(pathNodes.Select(dbcPosition => new Position(dbcPosition.X, dbcPosition.Y, dbcPosition.Z)));
// Drop first node (areatrigger position)
vertices.RemoveAt(0);
}
return vertices;
}
public void LoadGraveyardZones() public void LoadGraveyardZones()
{ {
uint oldMSTime = Time.GetMSTime(); uint oldMSTime = Time.GetMSTime();
@@ -5372,6 +5355,7 @@ namespace Game
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} instance templates in {1} ms", count, Time.GetMSTimeDiffToNow(time)); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} instance templates in {1} ms", count, Time.GetMSTimeDiffToNow(time));
} }
public void LoadGameTele() public void LoadGameTele()
{ {
uint oldMSTime = Time.GetMSTime(); uint oldMSTime = Time.GetMSTime();
@@ -5415,6 +5399,7 @@ namespace Game
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} GameTeleports in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} GameTeleports in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
} }
public void LoadAreaTriggerTeleports() public void LoadAreaTriggerTeleports()
{ {
uint oldMSTime = Time.GetMSTime(); uint oldMSTime = Time.GetMSTime();
@@ -5465,6 +5450,29 @@ namespace Game
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} area trigger teleport definitions in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} area trigger teleport definitions in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
} }
public void LoadAreaTriggerPolygons()
{
foreach (var (_, areaTrigger) in CliDB.AreaTriggerStorage)
{
if (areaTrigger.ShapeType != 3)
continue;
PathDb2 path = Global.DB2Mgr.GetPath((uint)areaTrigger.ShapeID);
if (path == null || path.Locations.Count < 4)
continue;
AreaTriggerPolygon polygon = new();
polygon.Vertices.AddRange(path.Locations.Select(pos => new Position(pos.X, pos.Y, pos.Z)));
foreach (var pathProperty in path.Properties)
if (pathProperty.GetPropertyIndex() == PathPropertyIndex.VolumeHeight)
polygon.Height = pathProperty.Value * 0.001f + 0.02f;
_areaTriggerPolygons[areaTrigger.Id] = polygon;
}
}
public void LoadAccessRequirements() public void LoadAccessRequirements()
{ {
uint oldMSTime = Time.GetMSTime(); uint oldMSTime = Time.GetMSTime();
@@ -5561,6 +5569,7 @@ namespace Game
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} access requirement definitions in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} access requirement definitions in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
} }
public void LoadSpawnGroupTemplates() public void LoadSpawnGroupTemplates()
{ {
uint oldMSTime = Time.GetMSTime(); uint oldMSTime = Time.GetMSTime();
@@ -5621,6 +5630,7 @@ namespace Game
else else
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 spawn group templates. DB table `spawn_group_template` is empty."); Log.outInfo(LogFilter.ServerLoading, "Loaded 0 spawn group templates. DB table `spawn_group_template` is empty.");
} }
public void LoadSpawnGroups() public void LoadSpawnGroups()
{ {
uint oldMSTime = Time.GetMSTime(); uint oldMSTime = Time.GetMSTime();
@@ -5683,6 +5693,7 @@ namespace Game
Log.outInfo(LogFilter.ServerLoading, $"Loaded {numMembers} spawn group members in {Time.GetMSTimeDiffToNow(oldMSTime)} ms"); Log.outInfo(LogFilter.ServerLoading, $"Loaded {numMembers} spawn group members in {Time.GetMSTimeDiffToNow(oldMSTime)} ms");
} }
public void LoadInstanceSpawnGroups() public void LoadInstanceSpawnGroups()
{ {
uint oldMSTime = Time.GetMSTime(); uint oldMSTime = Time.GetMSTime();
@@ -5749,6 +5760,7 @@ namespace Game
Log.outInfo(LogFilter.ServerLoading, $"Loaded {count} instance spawn groups in {Time.GetMSTimeDiffToNow(oldMSTime)} ms"); Log.outInfo(LogFilter.ServerLoading, $"Loaded {count} instance spawn groups in {Time.GetMSTimeDiffToNow(oldMSTime)} ms");
} }
void OnDeleteSpawnData(SpawnData data) void OnDeleteSpawnData(SpawnData data)
{ {
var templateIt = _spawnGroupDataStorage.LookupByKey(data.spawnGroupData.groupId); var templateIt = _spawnGroupDataStorage.LookupByKey(data.spawnGroupData.groupId);
@@ -5888,6 +5900,10 @@ namespace Game
} }
} }
public List<InstanceSpawnGroupInfo> GetInstanceSpawnGroupsForMap(uint mapId) { return _instanceSpawnGroupStorage.LookupByKey(mapId); } public List<InstanceSpawnGroupInfo> GetInstanceSpawnGroupsForMap(uint mapId) { return _instanceSpawnGroupStorage.LookupByKey(mapId); }
public AreaTriggerPolygon GetAreaTriggerPolygon(uint areaTriggerId)
{
return _areaTriggerPolygons.LookupByKey(areaTriggerId);
}
//Player //Player
public void LoadPlayerInfo() public void LoadPlayerInfo()
@@ -11020,6 +11036,7 @@ namespace Game
MultiMap<uint, SpawnMetadata> _spawnGroupMapStorage = new(); MultiMap<uint, SpawnMetadata> _spawnGroupMapStorage = new();
MultiMap<uint, uint> _spawnGroupsByMap = new(); MultiMap<uint, uint> _spawnGroupsByMap = new();
MultiMap<ushort, InstanceSpawnGroupInfo> _instanceSpawnGroupStorage = new(); MultiMap<ushort, InstanceSpawnGroupInfo> _instanceSpawnGroupStorage = new();
Dictionary<uint, AreaTriggerPolygon> _areaTriggerPolygons = new();
//Spells /Skills / Phases //Spells /Skills / Phases
Dictionary<uint, PhaseInfoStruct> _phaseInfoById = new(); Dictionary<uint, PhaseInfoStruct> _phaseInfoById = new();
@@ -12234,4 +12251,10 @@ namespace Game
public uint Parent; public uint Parent;
public uint ScriptId; public uint ScriptId;
} }
public class AreaTriggerPolygon
{
public List<Position> Vertices = new();
public float? Height;
}
} }
+1 -1
View File
@@ -171,7 +171,7 @@ namespace Game
return; return;
} }
if (packet.Entered && !player.IsInAreaTrigger(atEntry)) if (packet.Entered != player.IsInAreaTrigger(atEntry))
{ {
Log.outDebug(LogFilter.Network, "HandleAreaTrigger: Player '{0}' ({1}) too far, ignore Area Trigger ID: {2}", Log.outDebug(LogFilter.Network, "HandleAreaTrigger: Player '{0}' ({1}) too far, ignore Area Trigger ID: {2}",
player.GetName(), player.GetGUID().ToString(), packet.AreaTriggerID); player.GetName(), player.GetGUID().ToString(), packet.AreaTriggerID);
+3
View File
@@ -740,6 +740,9 @@ namespace Game
Log.outInfo(LogFilter.ServerLoading, "Loading Area Trigger Teleports definitions..."); Log.outInfo(LogFilter.ServerLoading, "Loading Area Trigger Teleports definitions...");
Global.ObjectMgr.LoadAreaTriggerTeleports(); Global.ObjectMgr.LoadAreaTriggerTeleports();
Log.outInfo(LogFilter.ServerLoading, "Loading Area Trigger Polygon data...");
Global.ObjectMgr.LoadAreaTriggerPolygons();
Log.outInfo(LogFilter.ServerLoading, "Loading Access Requirements..."); Log.outInfo(LogFilter.ServerLoading, "Loading Access Requirements...");
Global.ObjectMgr.LoadAccessRequirements(); // must be after item template load Global.ObjectMgr.LoadAccessRequirements(); // must be after item template load