Adds hue support to StaticTile (#1321)

### Summary
Fixes missing properties while reading static tiles.

### Screenshots
<img width="463" alt="Screenshot 2023-01-21 093050" src="https://user-images.githubusercontent.com/3953314/213879788-05d2ad7c-c197-4690-9f5b-660bded416cc.png">

Closes #1320
This commit is contained in:
Kamron Batman 2023-01-21 11:19:11 -08:00 • committed by GitHub
parent b18dfcbb63
commit 68bd9529f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 8 deletions

View file

@ -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);
}
}
}

View file

@ -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; }
}

View file

@ -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<StaticTile>((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()

View file

@ -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;
}

View file

@ -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;
}