Cleanup/Housekeeping (#242)
This commit is contained in:
parent
90ede0659f
commit
741e8d8300
228 changed files with 6292 additions and 2690 deletions
207
Projects/Server/Mobiles/AggressorInfo.cs
Normal file
207
Projects/Server/Mobiles/AggressorInfo.cs
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public class AggressorInfo
|
||||
{
|
||||
private static readonly Queue<AggressorInfo> m_Pool = new Queue<AggressorInfo>();
|
||||
private Mobile m_Attacker, m_Defender;
|
||||
private bool m_CanReportMurder;
|
||||
private bool m_CriminalAggression;
|
||||
private DateTime m_LastCombatTime;
|
||||
|
||||
private bool m_Queued;
|
||||
private bool m_Reported;
|
||||
|
||||
private AggressorInfo(Mobile attacker, Mobile defender, bool criminal)
|
||||
{
|
||||
m_Attacker = attacker;
|
||||
m_Defender = defender;
|
||||
|
||||
m_CanReportMurder = criminal;
|
||||
m_CriminalAggression = criminal;
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public static TimeSpan ExpireDelay { get; set; } = TimeSpan.FromMinutes(2.0);
|
||||
|
||||
public bool Expired
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Queued)
|
||||
{
|
||||
DumpAccess();
|
||||
}
|
||||
|
||||
return m_Attacker.Deleted || m_Defender.Deleted || DateTime.UtcNow >= m_LastCombatTime + ExpireDelay;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CriminalAggression
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Queued)
|
||||
{
|
||||
DumpAccess();
|
||||
}
|
||||
|
||||
return m_CriminalAggression;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (m_Queued)
|
||||
{
|
||||
DumpAccess();
|
||||
}
|
||||
|
||||
m_CriminalAggression = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Mobile Attacker
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Queued)
|
||||
{
|
||||
DumpAccess();
|
||||
}
|
||||
|
||||
return m_Attacker;
|
||||
}
|
||||
}
|
||||
|
||||
public Mobile Defender
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Queued)
|
||||
{
|
||||
DumpAccess();
|
||||
}
|
||||
|
||||
return m_Defender;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime LastCombatTime
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Queued)
|
||||
{
|
||||
DumpAccess();
|
||||
}
|
||||
|
||||
return m_LastCombatTime;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Reported
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Queued)
|
||||
{
|
||||
DumpAccess();
|
||||
}
|
||||
|
||||
return m_Reported;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (m_Queued)
|
||||
{
|
||||
DumpAccess();
|
||||
}
|
||||
|
||||
m_Reported = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanReportMurder
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Queued)
|
||||
{
|
||||
DumpAccess();
|
||||
}
|
||||
|
||||
return m_CanReportMurder;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (m_Queued)
|
||||
{
|
||||
DumpAccess();
|
||||
}
|
||||
|
||||
m_CanReportMurder = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static AggressorInfo Create(Mobile attacker, Mobile defender, bool criminal)
|
||||
{
|
||||
AggressorInfo info;
|
||||
|
||||
if (m_Pool.Count > 0)
|
||||
{
|
||||
info = m_Pool.Dequeue();
|
||||
|
||||
info.m_Attacker = attacker;
|
||||
info.m_Defender = defender;
|
||||
|
||||
info.m_CanReportMurder = criminal;
|
||||
info.m_CriminalAggression = criminal;
|
||||
|
||||
info.m_Queued = false;
|
||||
|
||||
info.Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
info = new AggressorInfo(attacker, defender, criminal);
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public void Free()
|
||||
{
|
||||
if (m_Queued)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_Queued = true;
|
||||
m_Pool.Enqueue(this);
|
||||
}
|
||||
|
||||
public static void DumpAccess()
|
||||
{
|
||||
using var op = new StreamWriter("warnings.log", true);
|
||||
op.WriteLine("Warning: Access to queued AggressorInfo:");
|
||||
op.WriteLine(new StackTrace());
|
||||
op.WriteLine();
|
||||
op.WriteLine();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (m_Queued)
|
||||
{
|
||||
DumpAccess();
|
||||
}
|
||||
|
||||
m_LastCombatTime = DateTime.UtcNow;
|
||||
m_Reported = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
97
Projects/Server/Mobiles/BaseVendor.cs
Normal file
97
Projects/Server/Mobiles/BaseVendor.cs
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public class BuyItemStateComparer : IComparer<BuyItemState>
|
||||
{
|
||||
public int Compare(BuyItemState l, BuyItemState r)
|
||||
{
|
||||
if (l == null && r == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (l == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (r == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return l.MySerial.CompareTo(r.MySerial);
|
||||
}
|
||||
}
|
||||
|
||||
public class BuyItemResponse
|
||||
{
|
||||
public BuyItemResponse(Serial serial, int amount)
|
||||
{
|
||||
Serial = serial;
|
||||
Amount = amount;
|
||||
}
|
||||
|
||||
public Serial Serial { get; }
|
||||
|
||||
public int Amount { get; }
|
||||
}
|
||||
|
||||
public class SellItemResponse
|
||||
{
|
||||
public SellItemResponse(Item i, int amount)
|
||||
{
|
||||
Item = i;
|
||||
Amount = amount;
|
||||
}
|
||||
|
||||
public Item Item { get; }
|
||||
|
||||
public int Amount { get; }
|
||||
}
|
||||
|
||||
public class SellItemState
|
||||
{
|
||||
public SellItemState(Item item, int price, string name)
|
||||
{
|
||||
Item = item;
|
||||
Price = price;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public Item Item { get; }
|
||||
|
||||
public int Price { get; }
|
||||
|
||||
public string Name { get; }
|
||||
}
|
||||
|
||||
public class BuyItemState
|
||||
{
|
||||
public BuyItemState(string name, Serial cont, Serial serial, int price, int amount, int itemID, int hue)
|
||||
{
|
||||
Description = name;
|
||||
ContainerSerial = cont;
|
||||
MySerial = serial;
|
||||
Price = price;
|
||||
Amount = amount;
|
||||
ItemID = itemID;
|
||||
Hue = hue;
|
||||
}
|
||||
|
||||
public int Price { get; }
|
||||
|
||||
public Serial MySerial { get; }
|
||||
|
||||
public Serial ContainerSerial { get; }
|
||||
|
||||
public int ItemID { get; }
|
||||
|
||||
public int Amount { get; }
|
||||
|
||||
public int Hue { get; }
|
||||
|
||||
public string Description { get; }
|
||||
}
|
||||
}
|
||||
153
Projects/Server/Mobiles/Body.cs
Normal file
153
Projects/Server/Mobiles/Body.cs
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public enum BodyType : byte
|
||||
{
|
||||
Empty,
|
||||
Monster,
|
||||
Sea,
|
||||
Animal,
|
||||
Human,
|
||||
Equipment
|
||||
}
|
||||
|
||||
public readonly struct Body : IEquatable<object>, IEquatable<Body>, IEquatable<int>
|
||||
{
|
||||
private static readonly BodyType[] m_Types = Array.Empty<BodyType>();
|
||||
|
||||
static Body()
|
||||
{
|
||||
if (File.Exists("Data/bodyTable.cfg"))
|
||||
{
|
||||
using var ip = new StreamReader("Data/bodyTable.cfg");
|
||||
m_Types = new BodyType[0x1000];
|
||||
|
||||
string line;
|
||||
|
||||
while ((line = ip.ReadLine()) != null)
|
||||
{
|
||||
if (line.Length == 0 || line.StartsWith("#"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var split = line.Split('\t');
|
||||
|
||||
if (int.TryParse(split[0], out var bodyID) && Enum.TryParse(split[1], true, out BodyType type) &&
|
||||
bodyID >= 0 &&
|
||||
bodyID < m_Types.Length)
|
||||
{
|
||||
m_Types[bodyID] = type;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: Invalid bodyTable entry:");
|
||||
Console.WriteLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: Data/bodyTable.cfg does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
public Body(int bodyID) => BodyID = bodyID;
|
||||
|
||||
public BodyType Type => BodyID >= 0 && BodyID < m_Types.Length ? m_Types[BodyID] : BodyType.Empty;
|
||||
|
||||
public bool IsHuman => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Human
|
||||
&& BodyID != 402
|
||||
&& BodyID != 403
|
||||
&& BodyID != 607
|
||||
&& BodyID != 608
|
||||
&& BodyID != 694
|
||||
&& BodyID != 695
|
||||
&& BodyID != 970;
|
||||
|
||||
public bool IsGargoyle => BodyID == 666
|
||||
|| BodyID == 667
|
||||
|| BodyID == 694
|
||||
|| BodyID == 695;
|
||||
|
||||
public bool IsMale => BodyID == 183
|
||||
|| BodyID == 185
|
||||
|| BodyID == 400
|
||||
|| BodyID == 402
|
||||
|| BodyID == 605
|
||||
|| BodyID == 607
|
||||
|| BodyID == 666
|
||||
|| BodyID == 694
|
||||
|| BodyID == 750;
|
||||
|
||||
public bool IsFemale => BodyID == 184
|
||||
|| BodyID == 186
|
||||
|| BodyID == 401
|
||||
|| BodyID == 403
|
||||
|| BodyID == 606
|
||||
|| BodyID == 608
|
||||
|| BodyID == 667
|
||||
|| BodyID == 695
|
||||
|| BodyID == 751;
|
||||
|
||||
public bool IsGhost => BodyID == 402
|
||||
|| BodyID == 403
|
||||
|| BodyID == 607
|
||||
|| BodyID == 608
|
||||
|| BodyID == 694
|
||||
|| BodyID == 695
|
||||
|| BodyID == 970;
|
||||
|
||||
public bool IsMonster => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Monster;
|
||||
|
||||
public bool IsAnimal => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Animal;
|
||||
|
||||
public bool IsEmpty => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Empty;
|
||||
|
||||
public bool IsSea => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Sea;
|
||||
|
||||
public bool IsEquipment => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Equipment;
|
||||
|
||||
public int BodyID { get; }
|
||||
|
||||
public static implicit operator int(Body a) => a.BodyID;
|
||||
|
||||
public static implicit operator Body(int a) => new Body(a);
|
||||
|
||||
public override string ToString() => $"0x{BodyID:X}";
|
||||
|
||||
public override int GetHashCode() => BodyID.GetHashCode();
|
||||
|
||||
public override bool Equals(object o) => o is Body b && b.BodyID == BodyID;
|
||||
|
||||
public bool Equals(Body b) => b.BodyID == BodyID;
|
||||
|
||||
public bool Equals(int number) => number == BodyID;
|
||||
|
||||
public static bool operator ==(Body l, Body r) => l.BodyID == r.BodyID;
|
||||
|
||||
public static bool operator !=(Body l, Body r) => l.BodyID != r.BodyID;
|
||||
|
||||
public static bool operator >(Body l, Body r) => l.BodyID > r.BodyID;
|
||||
|
||||
public static bool operator >=(Body l, Body r) => l.BodyID >= r.BodyID;
|
||||
|
||||
public static bool operator <(Body l, Body r) => l.BodyID < r.BodyID;
|
||||
|
||||
public static bool operator <=(Body l, Body r) => l.BodyID <= r.BodyID;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: IMount.cs *
|
||||
* *
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: IVendor.cs *
|
||||
* *
|
||||
|
|
|
|||
10638
Projects/Server/Mobiles/Mobile.cs
Normal file
10638
Projects/Server/Mobiles/Mobile.cs
Normal file
File diff suppressed because it is too large
Load diff
70
Projects/Server/Mobiles/Movement.cs
Normal file
70
Projects/Server/Mobiles/Movement.cs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
namespace Server.Movement
|
||||
{
|
||||
public static class Movement
|
||||
{
|
||||
public static IMovementImpl Impl { get; set; }
|
||||
|
||||
public static bool CheckMovement(Mobile m, Direction d, out int newZ)
|
||||
{
|
||||
if (Impl != null)
|
||||
{
|
||||
return Impl.CheckMovement(m, d, out newZ);
|
||||
}
|
||||
|
||||
newZ = m.Z;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool CheckMovement(Mobile m, Map map, Point3D loc, Direction d, out int newZ)
|
||||
{
|
||||
if (Impl != null)
|
||||
{
|
||||
return Impl.CheckMovement(m, map, loc, d, out newZ);
|
||||
}
|
||||
|
||||
newZ = m.Z;
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IMovementImpl
|
||||
{
|
||||
bool CheckMovement(Mobile m, Direction d, out int newZ);
|
||||
bool CheckMovement(Mobile m, Map map, Point3D loc, Direction d, out int newZ);
|
||||
}
|
||||
}
|
||||
33
Projects/Server/Mobiles/Notoriety.cs
Normal file
33
Projects/Server/Mobiles/Notoriety.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
namespace Server
|
||||
{
|
||||
public delegate int NotorietyHandler(Mobile source, Mobile target);
|
||||
|
||||
public static class Notoriety
|
||||
{
|
||||
public const int Innocent = 1;
|
||||
public const int Ally = 2;
|
||||
public const int CanBeAttacked = 3;
|
||||
public const int Criminal = 4;
|
||||
public const int Enemy = 5;
|
||||
public const int Murderer = 6;
|
||||
public const int Invulnerable = 7;
|
||||
|
||||
public static NotorietyHandler Handler { get; set; }
|
||||
|
||||
public static int[] Hues { get; set; } =
|
||||
{
|
||||
0x000,
|
||||
0x059,
|
||||
0x03F,
|
||||
0x3B2,
|
||||
0x3B2,
|
||||
0x090,
|
||||
0x022,
|
||||
0x035
|
||||
};
|
||||
|
||||
public static int GetHue(int noto) => noto < 0 || noto >= Hues.Length ? 0 : Hues[noto];
|
||||
|
||||
public static int Compute(Mobile source, Mobile target) => Handler?.Invoke(source, target) ?? CanBeAttacked;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue