ModernUO/Projects/UOContent/Targets/MoveTarget.cs
Kamron Batman 0925a2d435
fix: Cleans up Point checks and removes statics (#966)
- [X] Removes static freezing/unfreezing. Use other tools for this.
- [X] Cleans up IPoint3D allocations
- [X] Removes IPoint3D constructors since the compiler may not optimize the constructor path and allow allocations.


Note: Instead of `new Point3D(m)`, do something like `new Point3D(m.Location)`. Sorry for the inconvenience. In the long run this will prevent abuse of hot paths that will cause performance issues.
2022-03-20 23:15:59 -07:00

58 lines
1.5 KiB
C#

using Server.Commands;
using Server.Commands.Generic;
using Server.Targeting;
namespace Server.Targets
{
public class MoveTarget : Target
{
private readonly object m_Object;
public MoveTarget(object o) : base(-1, true, TargetFlags.None) => m_Object = o;
protected override void OnTarget(Mobile from, object o)
{
if (o is not IPoint3D ip)
{
return;
}
if (!BaseCommand.IsAccessible(from, m_Object))
{
from.SendLocalizedMessage(500447); // That is not accessible.
return;
}
Point3D p = ip switch
{
Item i => i.GetWorldTop(),
Mobile m => m.Location,
_ => new Point3D(ip)
};
CommandLogging.WriteLine(
from,
"{0} {1} moving {2} to {3}",
from.AccessLevel,
CommandLogging.Format(from),
CommandLogging.Format(m_Object),
p
);
if (m_Object is Item item)
{
if (!item.Deleted)
{
item.MoveToWorld(p, from.Map);
}
}
else if (m_Object is Mobile m)
{
if (!m.Deleted)
{
m.MoveToWorld(p, from.Map);
}
}
}
}
}