fix: Consolidates and fixes movement/direction checks (#1861)
This commit is contained in:
parent
06e05f2e52
commit
e6bfc45228
11 changed files with 146 additions and 320 deletions
|
|
@ -3836,24 +3836,27 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
|
|||
// return root == null ? m_Location : new Point3D( (IPoint3D) root );
|
||||
}
|
||||
|
||||
public Point3D GetSurfaceTop()
|
||||
public IPoint3D GetSurfaceTop()
|
||||
{
|
||||
var root = RootParent;
|
||||
|
||||
if (root == null)
|
||||
{
|
||||
return new Point3D(
|
||||
m_Location.m_X,
|
||||
m_Location.m_Y,
|
||||
m_Location.m_Z + (ItemData.Surface ? ItemData.CalcHeight : 0)
|
||||
);
|
||||
}
|
||||
|
||||
return root.Location;
|
||||
return (root as Item)?.GetSurfaceTop() ?? (ItemData.Surface ? new Point3D(
|
||||
m_Location.m_X,
|
||||
m_Location.m_Y,
|
||||
m_Location.m_Z + ItemData.CalcHeight
|
||||
) : this);
|
||||
}
|
||||
|
||||
public Point3D GetWorldTop() => RootParent?.Location ??
|
||||
new Point3D(m_Location.m_X, m_Location.m_Y, m_Location.m_Z + ItemData.CalcHeight);
|
||||
public Point3D GetWorldTop()
|
||||
{
|
||||
var root = RootParent;
|
||||
|
||||
return (root as Item)?.GetWorldTop() ?? new Point3D(
|
||||
m_Location.m_X,
|
||||
m_Location.m_Y,
|
||||
m_Location.m_Z + ItemData.CalcHeight
|
||||
);
|
||||
}
|
||||
|
||||
public void SendLocalizedMessageTo(Mobile to, int number, string args = "")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4089,10 +4089,12 @@ public partial class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPro
|
|||
return true;
|
||||
}
|
||||
|
||||
public virtual bool CheckMovement(Direction d, out int newZ) => Movement.Movement.CheckMovement(this, d, out newZ);
|
||||
public virtual bool CheckMovement(Direction d, out int newZ) => CalcMoves.CheckMovement(this, d, out newZ);
|
||||
|
||||
private bool CanMove(Direction d, Point3D oldLocation, ref Point3D newLocation)
|
||||
private bool CanMove(Direction d, Point3D oldLocation, out Point3D newLocation)
|
||||
{
|
||||
newLocation = oldLocation;
|
||||
|
||||
if (m_Spell?.OnCasterMoving(d) == false)
|
||||
{
|
||||
return false;
|
||||
|
|
@ -4110,61 +4112,13 @@ public partial class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPro
|
|||
return false;
|
||||
}
|
||||
|
||||
int x = oldLocation.m_X, y = oldLocation.m_Y;
|
||||
int oldX = x, oldY = y;
|
||||
var oldX = oldLocation.m_X;
|
||||
var oldY = oldLocation.m_Y;
|
||||
var oldZ = oldLocation.m_Z;
|
||||
|
||||
switch (d & Direction.Mask)
|
||||
{
|
||||
case Direction.North:
|
||||
{
|
||||
--y;
|
||||
break;
|
||||
}
|
||||
case Direction.Right:
|
||||
{
|
||||
++x;
|
||||
--y;
|
||||
break;
|
||||
}
|
||||
case Direction.East:
|
||||
{
|
||||
++x;
|
||||
break;
|
||||
}
|
||||
case Direction.Down:
|
||||
{
|
||||
++x;
|
||||
++y;
|
||||
break;
|
||||
}
|
||||
case Direction.South:
|
||||
{
|
||||
++y;
|
||||
break;
|
||||
}
|
||||
case Direction.Left:
|
||||
{
|
||||
--x;
|
||||
++y;
|
||||
break;
|
||||
}
|
||||
case Direction.West:
|
||||
{
|
||||
--x;
|
||||
break;
|
||||
}
|
||||
case Direction.Up:
|
||||
{
|
||||
--x;
|
||||
--y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
newLocation.m_X = x;
|
||||
newLocation.m_Y = y;
|
||||
newLocation.m_Z = newZ;
|
||||
var x = oldX;
|
||||
var y = oldY;
|
||||
CalcMoves.Offset(d, ref x, ref y);
|
||||
newLocation = new Point3D(x, y, newZ);
|
||||
|
||||
Pushing = false;
|
||||
|
||||
|
|
@ -4344,18 +4298,22 @@ public partial class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPro
|
|||
}
|
||||
|
||||
var oldLocation = m_Location;
|
||||
Point3D newLocation = oldLocation;
|
||||
Point3D newLocation;
|
||||
|
||||
if ((m_Direction & Direction.Mask) == (d & Direction.Mask))
|
||||
{
|
||||
// We are actually moving (not just a direction change)
|
||||
if (!CanMove(d, oldLocation, ref newLocation))
|
||||
if (!CanMove(d, oldLocation, out newLocation))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DisruptiveAction();
|
||||
}
|
||||
else
|
||||
{
|
||||
newLocation = oldLocation;
|
||||
}
|
||||
|
||||
if (m_NetState != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue