fix: Cleans up core code (#1187)

**Only one functional change**
* Fixes a bug in LogFactory where `Warning` is being logged as `Information`

Non-functional changes:
* Updates/Fixes copyright headers
* Removes namespace scopes for core files.

View with [whitespace off](https://github.com/modernuo/ModernUO/pull/1187/files?w=1).
This commit is contained in:
Kamron Batman 2022-10-10 21:47:08 -07:00 committed by GitHub
parent 0138d40bda
commit f268d5d4e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
262 changed files with 28527 additions and 28646 deletions

View file

@ -1,39 +1,38 @@
namespace Server.Targeting
namespace Server.Targeting;
public class LandTarget : IPoint3D
{
public class LandTarget : IPoint3D
private Point3D m_Location;
public LandTarget(Point3D location, Map map)
{
private Point3D m_Location;
m_Location = location;
public LandTarget(Point3D location, Map map)
if (map != null)
{
m_Location = location;
if (map != null)
{
m_Location.Z = map.GetAverageZ(m_Location.X, m_Location.Y);
TileID = map.Tiles.GetLandTile(m_Location.X, m_Location.Y).ID & TileData.MaxLandValue;
}
m_Location.Z = map.GetAverageZ(m_Location.X, m_Location.Y);
TileID = map.Tiles.GetLandTile(m_Location.X, m_Location.Y).ID & TileData.MaxLandValue;
}
[CommandProperty(AccessLevel.Counselor)]
public string Name => TileData.LandTable[TileID].Name;
[CommandProperty(AccessLevel.Counselor)]
public TileFlag Flags => TileData.LandTable[TileID].Flags;
[CommandProperty(AccessLevel.Counselor)]
public int TileID { get; }
[CommandProperty(AccessLevel.Counselor)]
public Point3D Location => m_Location;
[CommandProperty(AccessLevel.Counselor)]
public int X => m_Location.X;
[CommandProperty(AccessLevel.Counselor)]
public int Y => m_Location.Y;
[CommandProperty(AccessLevel.Counselor)]
public int Z => m_Location.Z;
}
[CommandProperty(AccessLevel.Counselor)]
public string Name => TileData.LandTable[TileID].Name;
[CommandProperty(AccessLevel.Counselor)]
public TileFlag Flags => TileData.LandTable[TileID].Flags;
[CommandProperty(AccessLevel.Counselor)]
public int TileID { get; }
[CommandProperty(AccessLevel.Counselor)]
public Point3D Location => m_Location;
[CommandProperty(AccessLevel.Counselor)]
public int X => m_Location.X;
[CommandProperty(AccessLevel.Counselor)]
public int Y => m_Location.Y;
[CommandProperty(AccessLevel.Counselor)]
public int Z => m_Location.Z;
}

View file

@ -1,23 +1,22 @@
using Server.Network;
namespace Server.Targeting
namespace Server.Targeting;
public abstract class MultiTarget : Target
{
public abstract class MultiTarget : Target
protected MultiTarget(
int multiID, Point3D offset, int range = 10, bool allowGround = true,
TargetFlags flags = TargetFlags.None
)
: base(range, allowGround, flags)
{
protected MultiTarget(
int multiID, Point3D offset, int range = 10, bool allowGround = true,
TargetFlags flags = TargetFlags.None
)
: base(range, allowGround, flags)
{
MultiID = multiID;
Offset = offset;
}
public int MultiID { get; set; }
public Point3D Offset { get; set; }
public override void SendTargetTo(NetState ns) => ns.SendMultiTargetReq(this);
MultiID = multiID;
Offset = offset;
}
public int MultiID { get; set; }
public Point3D Offset { get; set; }
public override void SendTargetTo(NetState ns) => ns.SendMultiTargetReq(this);
}

View file

@ -1,35 +1,34 @@
namespace Server.Targeting
namespace Server.Targeting;
public class StaticTarget : IPoint3D
{
public class StaticTarget : IPoint3D
private Point3D m_Location;
public StaticTarget(Point3D location, int itemID)
{
private Point3D m_Location;
public StaticTarget(Point3D location, int itemID)
{
m_Location = location;
ItemID = itemID & TileData.MaxItemValue;
m_Location.Z += TileData.ItemTable[ItemID].CalcHeight;
}
[CommandProperty(AccessLevel.Counselor)]
public Point3D Location => m_Location;
[CommandProperty(AccessLevel.Counselor)]
public string Name => TileData.ItemTable[ItemID].Name;
[CommandProperty(AccessLevel.Counselor)]
public TileFlag Flags => TileData.ItemTable[ItemID].Flags;
[CommandProperty(AccessLevel.Counselor)]
public int ItemID { get; }
[CommandProperty(AccessLevel.Counselor)]
public int X => m_Location.X;
[CommandProperty(AccessLevel.Counselor)]
public int Y => m_Location.Y;
[CommandProperty(AccessLevel.Counselor)]
public int Z => m_Location.Z;
m_Location = location;
ItemID = itemID & TileData.MaxItemValue;
m_Location.Z += TileData.ItemTable[ItemID].CalcHeight;
}
[CommandProperty(AccessLevel.Counselor)]
public Point3D Location => m_Location;
[CommandProperty(AccessLevel.Counselor)]
public string Name => TileData.ItemTable[ItemID].Name;
[CommandProperty(AccessLevel.Counselor)]
public TileFlag Flags => TileData.ItemTable[ItemID].Flags;
[CommandProperty(AccessLevel.Counselor)]
public int ItemID { get; }
[CommandProperty(AccessLevel.Counselor)]
public int X => m_Location.X;
[CommandProperty(AccessLevel.Counselor)]
public int Y => m_Location.Y;
[CommandProperty(AccessLevel.Counselor)]
public int Z => m_Location.Z;
}

View file

@ -1,291 +1,290 @@
using System;
using Server.Network;
namespace Server.Targeting
namespace Server.Targeting;
public abstract class Target
{
public abstract class Target
private static int m_NextTargetID;
private Timer m_TimeoutTimer;
protected Target(int range, bool allowGround, TargetFlags flags)
{
private static int m_NextTargetID;
TargetID = ++m_NextTargetID;
Range = range;
AllowGround = allowGround;
Flags = flags;
private Timer m_TimeoutTimer;
CheckLOS = true;
}
protected Target(int range, bool allowGround, TargetFlags flags)
public long TimeoutTime { get; private set; }
public bool CheckLOS { get; set; }
public bool DisallowMultis { get; set; }
public bool AllowNonlocal { get; set; }
public int TargetID { get; }
public int Range { get; set; }
public bool AllowGround { get; set; }
public TargetFlags Flags { get; set; }
public static void Cancel(Mobile m)
{
m.NetState.SendCancelTarget();
m.Target?.OnTargetCancel(m, TargetCancelType.Canceled);
}
public void BeginTimeout(Mobile from, long delay)
{
TimeoutTime = Core.TickCount + delay;
m_TimeoutTimer?.Stop();
m_TimeoutTimer = new TimeoutTimer(this, from, TimeSpan.FromMilliseconds(delay));
m_TimeoutTimer.Start();
}
public void CancelTimeout()
{
m_TimeoutTimer?.Stop();
m_TimeoutTimer = null;
}
public void Timeout(Mobile from)
{
CancelTimeout();
from.ClearTarget();
Cancel(from);
OnTargetCancel(from, TargetCancelType.Timeout);
OnTargetFinish(from);
}
public virtual void SendTargetTo(NetState ns) => ns.SendTargetReq(this);
public void Cancel(Mobile from, TargetCancelType type)
{
CancelTimeout();
from.ClearTarget();
OnTargetCancel(from, type);
OnTargetFinish(from);
}
protected virtual bool CanTarget(Mobile from, LandTarget landTarget, ref Point3D loc, ref Map map)
{
if (!AllowGround)
{
TargetID = ++m_NextTargetID;
Range = range;
AllowGround = allowGround;
Flags = flags;
CheckLOS = true;
// We should actually never get here. If we do, it's probably a misbehaving client/macro.
OnTargetCancel(from, TargetCancelType.Canceled);
return false;
}
public long TimeoutTime { get; private set; }
loc = landTarget.Location;
map = from.Map;
return true;
}
public bool CheckLOS { get; set; }
protected virtual bool CanTarget(Mobile from, StaticTarget staticTarget, ref Point3D loc, ref Map map)
{
loc = staticTarget.Location;
map = from.Map;
return true;
}
public bool DisallowMultis { get; set; }
public bool AllowNonlocal { get; set; }
public int TargetID { get; }
public int Range { get; set; }
public bool AllowGround { get; set; }
public TargetFlags Flags { get; set; }
public static void Cancel(Mobile m)
protected virtual bool CanTarget(Mobile from, Item item, ref Point3D loc, ref Map map)
{
if (item.Deleted)
{
m.NetState.SendCancelTarget();
m.Target?.OnTargetCancel(m, TargetCancelType.Canceled);
OnTargetDeleted(from, item);
return false;
}
public void BeginTimeout(Mobile from, long delay)
if (!item.CanTarget)
{
TimeoutTime = Core.TickCount + delay;
m_TimeoutTimer?.Stop();
m_TimeoutTimer = new TimeoutTimer(this, from, TimeSpan.FromMilliseconds(delay));
m_TimeoutTimer.Start();
OnTargetUntargetable(from, item);
return false;
}
public void CancelTimeout()
if (!AllowNonlocal && item.RootParent is Mobile && item.RootParent != from &&
from.AccessLevel == AccessLevel.Player)
{
m_TimeoutTimer?.Stop();
m_TimeoutTimer = null;
OnNonlocalTarget(from, item);
return false;
}
public void Timeout(Mobile from)
loc = item.GetWorldLocation();
map = item.Map;
return true;
}
protected virtual bool CanTarget(Mobile from, Mobile mobile, ref Point3D loc, ref Map map)
{
if (mobile.Deleted)
{
CancelTimeout();
from.ClearTarget();
OnTargetDeleted(from, mobile);
return false;
}
Cancel(from);
if (!mobile.CanTarget)
{
OnTargetUntargetable(from, mobile);
return false;
}
OnTargetCancel(from, TargetCancelType.Timeout);
loc = mobile.Location;
map = mobile.Map;
return true;
}
public void Invoke(Mobile from, object targeted)
{
CancelTimeout();
from.ClearTarget();
if (from.Deleted)
{
OnTargetCancel(from, TargetCancelType.Canceled);
OnTargetFinish(from);
return;
}
public virtual void SendTargetTo(NetState ns) => ns.SendTargetReq(this);
Point3D loc = default;
Map map = null;
Item item = null;
Mobile mobile = null;
bool isValidTargetType = true;
public void Cancel(Mobile from, TargetCancelType type)
bool valid = targeted switch
{
CancelTimeout();
from.ClearTarget();
LandTarget landTarget => CanTarget(from, landTarget, ref loc, ref map),
StaticTarget staticTarget => CanTarget(from, staticTarget, ref loc, ref map),
Item i => CanTarget(from, item = i, ref loc, ref map),
Mobile m => CanTarget(from, mobile = m, ref loc, ref map),
_ => isValidTargetType = false
};
OnTargetCancel(from, type);
OnTargetFinish(from);
}
protected virtual bool CanTarget(Mobile from, LandTarget landTarget, ref Point3D loc, ref Map map)
if (!valid)
{
if (!AllowGround)
{
// We should actually never get here. If we do, it's probably a misbehaving client/macro.
OnTargetCancel(from, TargetCancelType.Canceled);
return false;
}
loc = landTarget.Location;
map = from.Map;
return true;
}
protected virtual bool CanTarget(Mobile from, StaticTarget staticTarget, ref Point3D loc, ref Map map)
{
loc = staticTarget.Location;
map = from.Map;
return true;
}
protected virtual bool CanTarget(Mobile from, Item item, ref Point3D loc, ref Map map)
{
if (item.Deleted)
{
OnTargetDeleted(from, item);
return false;
}
if (!item.CanTarget)
{
OnTargetUntargetable(from, item);
return false;
}
if (!AllowNonlocal && item.RootParent is Mobile && item.RootParent != from &&
from.AccessLevel == AccessLevel.Player)
{
OnNonlocalTarget(from, item);
return false;
}
loc = item.GetWorldLocation();
map = item.Map;
return true;
}
protected virtual bool CanTarget(Mobile from, Mobile mobile, ref Point3D loc, ref Map map)
{
if (mobile.Deleted)
{
OnTargetDeleted(from, mobile);
return false;
}
if (!mobile.CanTarget)
{
OnTargetUntargetable(from, mobile);
return false;
}
loc = mobile.Location;
map = mobile.Map;
return true;
}
public void Invoke(Mobile from, object targeted)
{
CancelTimeout();
from.ClearTarget();
if (from.Deleted)
if (!isValidTargetType)
{
OnTargetCancel(from, TargetCancelType.Canceled);
OnTargetFinish(from);
return;
}
Point3D loc = default;
Map map = null;
Item item = null;
Mobile mobile = null;
bool isValidTargetType = true;
bool valid = targeted switch
{
LandTarget landTarget => CanTarget(from, landTarget, ref loc, ref map),
StaticTarget staticTarget => CanTarget(from, staticTarget, ref loc, ref map),
Item i => CanTarget(from, item = i, ref loc, ref map),
Mobile m => CanTarget(from, mobile = m, ref loc, ref map),
_ => isValidTargetType = false
};
if (!valid)
{
if (!isValidTargetType)
{
OnTargetCancel(from, TargetCancelType.Canceled);
}
OnTargetFinish(from);
}
if (map == null || map != from.Map || Range >= 0 && !from.InRange(loc, Range))
{
OnTargetOutOfRange(from, targeted);
}
else if (!from.CanSee(targeted))
{
OnCantSeeTarget(from, targeted);
}
else if (CheckLOS && !from.InLOS(targeted))
{
OnTargetOutOfLOS(from, targeted);
}
else if (item?.InSecureTrade == true)
{
OnTargetInSecureTrade(from, targeted);
}
else if (item?.IsAccessibleTo(from) == false)
{
OnTargetNotAccessible(from, targeted);
}
else if (item?.CheckTarget(from, this, targeted) == false)
{
OnTargetUntargetable(from, targeted);
}
else if (mobile?.CheckTarget(from, this, mobile) == false)
{
OnTargetUntargetable(from, mobile);
}
else if (from.Region.OnTarget(from, this, targeted))
{
OnTarget(from, targeted);
}
OnTargetFinish(from);
}
protected virtual void OnTarget(Mobile from, object targeted)
if (map == null || map != from.Map || Range >= 0 && !from.InRange(loc, Range))
{
OnTargetOutOfRange(from, targeted);
}
else if (!from.CanSee(targeted))
{
OnCantSeeTarget(from, targeted);
}
else if (CheckLOS && !from.InLOS(targeted))
{
OnTargetOutOfLOS(from, targeted);
}
else if (item?.InSecureTrade == true)
{
OnTargetInSecureTrade(from, targeted);
}
else if (item?.IsAccessibleTo(from) == false)
{
OnTargetNotAccessible(from, targeted);
}
else if (item?.CheckTarget(from, this, targeted) == false)
{
OnTargetUntargetable(from, targeted);
}
else if (mobile?.CheckTarget(from, this, mobile) == false)
{
OnTargetUntargetable(from, mobile);
}
else if (from.Region.OnTarget(from, this, targeted))
{
OnTarget(from, targeted);
}
protected virtual void OnTargetNotAccessible(Mobile from, object targeted)
OnTargetFinish(from);
}
protected virtual void OnTarget(Mobile from, object targeted)
{
}
protected virtual void OnTargetNotAccessible(Mobile from, object targeted)
{
from.SendLocalizedMessage(500447); // That is not accessible.
}
protected virtual void OnTargetInSecureTrade(Mobile from, object targeted)
{
from.SendLocalizedMessage(500447); // That is not accessible.
}
protected virtual void OnNonlocalTarget(Mobile from, object targeted)
{
from.SendLocalizedMessage(500447); // That is not accessible.
}
protected virtual void OnCantSeeTarget(Mobile from, object targeted)
{
from.SendLocalizedMessage(500237); // Target can not be seen.
}
protected virtual void OnTargetOutOfLOS(Mobile from, object targeted)
{
from.SendLocalizedMessage(500237); // Target can not be seen.
}
protected virtual void OnTargetOutOfRange(Mobile from, object targeted)
{
from.SendLocalizedMessage(500446); // That is too far away.
}
protected virtual void OnTargetDeleted(Mobile from, object targeted)
{
}
protected virtual void OnTargetUntargetable(Mobile from, object targeted)
{
from.SendLocalizedMessage(500447); // That is not accessible.
}
protected virtual void OnTargetCancel(Mobile from, TargetCancelType cancelType)
{
}
protected virtual void OnTargetFinish(Mobile from)
{
}
private class TimeoutTimer : Timer
{
private readonly Mobile m_Mobile;
private readonly Target m_Target;
public TimeoutTimer(Target target, Mobile m, TimeSpan delay) : base(delay)
{
from.SendLocalizedMessage(500447); // That is not accessible.
m_Target = target;
m_Mobile = m;
}
protected virtual void OnTargetInSecureTrade(Mobile from, object targeted)
protected override void OnTick()
{
from.SendLocalizedMessage(500447); // That is not accessible.
}
protected virtual void OnNonlocalTarget(Mobile from, object targeted)
{
from.SendLocalizedMessage(500447); // That is not accessible.
}
protected virtual void OnCantSeeTarget(Mobile from, object targeted)
{
from.SendLocalizedMessage(500237); // Target can not be seen.
}
protected virtual void OnTargetOutOfLOS(Mobile from, object targeted)
{
from.SendLocalizedMessage(500237); // Target can not be seen.
}
protected virtual void OnTargetOutOfRange(Mobile from, object targeted)
{
from.SendLocalizedMessage(500446); // That is too far away.
}
protected virtual void OnTargetDeleted(Mobile from, object targeted)
{
}
protected virtual void OnTargetUntargetable(Mobile from, object targeted)
{
from.SendLocalizedMessage(500447); // That is not accessible.
}
protected virtual void OnTargetCancel(Mobile from, TargetCancelType cancelType)
{
}
protected virtual void OnTargetFinish(Mobile from)
{
}
private class TimeoutTimer : Timer
{
private readonly Mobile m_Mobile;
private readonly Target m_Target;
public TimeoutTimer(Target target, Mobile m, TimeSpan delay) : base(delay)
if (m_Mobile.Target == m_Target)
{
m_Target = target;
m_Mobile = m;
}
protected override void OnTick()
{
if (m_Mobile.Target == m_Target)
{
m_Target.Timeout(m_Mobile);
}
m_Target.Timeout(m_Mobile);
}
}
}

View file

@ -1,10 +1,9 @@
namespace Server.Targeting
namespace Server.Targeting;
public enum TargetCancelType
{
public enum TargetCancelType
{
Overridden,
Canceled,
Disconnected,
Timeout
}
Overridden,
Canceled,
Disconnected,
Timeout
}

View file

@ -1,12 +1,11 @@
using System;
namespace Server.Targeting
namespace Server.Targeting;
[Flags]
public enum TargetFlags : byte
{
[Flags]
public enum TargetFlags : byte
{
None = 0x00,
Harmful = 0x01,
Beneficial = 0x02
}
None = 0x00,
Harmful = 0x01,
Beneficial = 0x02
}