fix: Consolidates and fixes movement/direction checks (#1861)

This commit is contained in:
Kamron Batman 2024-07-06 12:41:45 -07:00 • committed by GitHub
parent 06e05f2e52
commit e6bfc45228
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 146 additions and 320 deletions

View file

@ -54,9 +54,9 @@ namespace Server.Movement
var checkDiagonals = ((int)d & 0x1) == 0x1;
Offset(d, ref xForward, ref yForward);
Offset((Direction)(((int)d - 1) & 0x7), ref xLeft, ref yLeft);
Offset((Direction)(((int)d + 1) & 0x7), ref xRight, ref yRight);
Movement.Offset(d, ref xForward, ref yForward);
Movement.Offset((Direction)(((int)d - 1) & 0x7), ref xLeft, ref yLeft);
Movement.Offset((Direction)(((int)d + 1) & 0x7), ref xRight, ref yRight);
if (xForward < 0 || yForward < 0 || xForward >= map.Width || yForward >= map.Height)
{
@ -578,57 +578,5 @@ namespace Server.Movement
zTop = loc.Z;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Offset(Direction d, ref int x, ref int y)
{
switch (d & Direction.Mask)
{
case Direction.North:
{
--y;
break;
}
case Direction.South:
{
++y;
break;
}
case Direction.West:
{
--x;
break;
}
case Direction.East:
{
++x;
break;
}
case Direction.Right:
{
++x;
--y;
break;
}
case Direction.Left:
{
--x;
++y;
break;
}
case Direction.Down:
{
++x;
++y;
break;
}
case Direction.Up:
{
--x;
--y;
break;
}
}
}
}
}

View file

@ -42,12 +42,7 @@ namespace Server
if (index >= 0 && index < dirs.Length)
{
int x = p.X, y = p.Y;
CalcMoves.Offset(dirs[index], ref x, ref y);
p.X = x;
p.Y = y;
CalcMoves.Offset(dirs[index], ref p);
}
}
}