diff --git a/Projects/Server/Network/Packets/IncomingTargetingPackets.cs b/Projects/Server/Network/Packets/IncomingTargetingPackets.cs index c1b2ee844..19e4c5475 100644 --- a/Projects/Server/Network/Packets/IncomingTargetingPackets.cs +++ b/Projects/Server/Network/Packets/IncomingTargetingPackets.cs @@ -95,11 +95,15 @@ public static class IncomingTargetingPackets } } + int hue = 0; + for (var i = 0; !valid && i < tiles.Length; ++i) { - if (tiles[i].Z == z && tiles[i].ID == graphic) + var tile = tiles[i]; + if (tile.Z == z && tile.ID == graphic) { valid = true; + hue = tile.Hue; } } @@ -110,7 +114,7 @@ public static class IncomingTargetingPackets } else { - toTarget = new StaticTarget(new Point3D(x, y, z), graphic); + toTarget = new StaticTarget(new Point3D(x, y, z), graphic, hue); } } } diff --git a/Projects/Server/Targeting/StaticTarget.cs b/Projects/Server/Targeting/StaticTarget.cs index 289155048..bfcec5e76 100644 --- a/Projects/Server/Targeting/StaticTarget.cs +++ b/Projects/Server/Targeting/StaticTarget.cs @@ -11,6 +11,14 @@ public class StaticTarget : IPoint3D m_Location.Z += TileData.ItemTable[ItemID].CalcHeight; } + public StaticTarget(Point3D location, int itemID, int hue) + { + m_Location = location; + ItemID = itemID & TileData.MaxItemValue; + m_Location.Z += TileData.ItemTable[ItemID].CalcHeight; + Hue = hue; + } + [CommandProperty(AccessLevel.Counselor)] public Point3D Location => m_Location; @@ -31,4 +39,7 @@ public class StaticTarget : IPoint3D [CommandProperty(AccessLevel.Counselor)] public int Z => m_Location.Z; + + [CommandProperty(AccessLevel.Counselor)] + public int Hue { get; } } diff --git a/Projects/Server/TileList.cs b/Projects/Server/TileList.cs index 3622b537e..14ab7d7b9 100644 --- a/Projects/Server/TileList.cs +++ b/Projects/Server/TileList.cs @@ -1,4 +1,6 @@ using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace Server; @@ -34,7 +36,37 @@ public class TileList } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public unsafe void Add(StaticTile* ptr) => Add(Marshal.PtrToStructure((nint)ptr)); + + public void Add(StaticTile tile) + { + TryResize(); + m_Tiles[Count] = tile; + ++Count; + } + + public void Add(ushort id, byte x, byte y, sbyte z, short hue = 0) + { + TryResize(); + ref var tile = ref m_Tiles[Count]; + tile.m_ID = id; + tile.m_X = x; + tile.m_Y = y; + tile.m_Z = z; + tile.m_Hue = hue; + ++Count; + } + public void Add(ushort id, sbyte z) + { + TryResize(); + m_Tiles[Count].m_ID = id; + m_Tiles[Count].m_Z = z; + ++Count; + } + + private void TryResize() { if (Count + 1 > m_Tiles.Length) { @@ -46,10 +78,6 @@ public class TileList m_Tiles[i] = old[i]; } } - - m_Tiles[Count].m_ID = id; - m_Tiles[Count].m_Z = z; - ++Count; } public StaticTile[] ToArray() diff --git a/Projects/Server/TileMatrix/TileMatrix.cs b/Projects/Server/TileMatrix/TileMatrix.cs index ff316a438..6a4c1bb5e 100644 --- a/Projects/Server/TileMatrix/TileMatrix.cs +++ b/Projects/Server/TileMatrix/TileMatrix.cs @@ -408,7 +408,7 @@ public class TileMatrix while (pCur < pEnd) { - lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add(pCur->m_ID, pCur->m_Z); + lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add(pCur); pCur = pCur + 1; } diff --git a/Projects/Server/TileMatrix/TileMatrixPatch.cs b/Projects/Server/TileMatrix/TileMatrixPatch.cs index 04548f980..814807abf 100644 --- a/Projects/Server/TileMatrix/TileMatrixPatch.cs +++ b/Projects/Server/TileMatrix/TileMatrixPatch.cs @@ -158,7 +158,7 @@ public class TileMatrixPatch while (pCur < pEnd) { - lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add(pCur->m_ID, pCur->m_Z); + lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add(pCur); pCur += 1; }