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

@ -13,6 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System.Runtime.CompilerServices;
namespace Server.Movement;
public static class Movement
@ -56,52 +58,63 @@ public static class Movement
return false;
}
public static void Offset(Direction d, ref int x, ref int y)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Offset(Direction d, ref Point3D p, int count = 1)
{
var x = p.m_X;
var y = p.m_Y;
Offset(d, ref x, ref y, count);
p = new Point3D(x, y, p.m_Z);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Offset(Direction d, ref int x, ref int y, int count = 1)
{
switch (d & Direction.Mask)
{
case Direction.North:
{
--y;
y -= count;
break;
}
case Direction.South:
{
++y;
y += count;
break;
}
case Direction.West:
{
--x;
x -= count;
break;
}
case Direction.East:
{
++x;
x += count;
break;
}
case Direction.Right:
{
++x;
--y;
x += count;
y -= count;
break;
}
case Direction.Left:
{
--x;
++y;
x -= count;
y += count;
break;
}
case Direction.Down:
{
++x;
++y;
x += count;
y += count;
break;
}
case Direction.Up:
{
--x;
--y;
x -= count;
y -= count;
break;
}
}