Modernization Fixes & Updates to Default Values (#3)

This commit is contained in:
Kamron Batman 2018-10-28 00:33:16 -07:00 • committed by GitHub
parent 445eddff68
commit dcf64091b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
768 changed files with 10507 additions and 14196 deletions

View file

@ -54,10 +54,7 @@ namespace Server
string[] split = line.Split('\t');
BodyType type;
int bodyID;
if (int.TryParse(split[0], out bodyID) && Enum.TryParse(split[1], true, out type) && bodyID >= 0 &&
if (int.TryParse(split[0], out int bodyID) && Enum.TryParse(split[1], true, out BodyType type) && bodyID >= 0 &&
bodyID < m_Types.Length)
{
m_Types[bodyID] = type;

View file

@ -61,6 +61,14 @@ namespace Server.Commands
return Utility.ToInt32(Arguments[index]);
}
public uint GetUInt32(int index)
{
if (index < 0 || index >= Arguments.Length)
return 0;
return Utility.ToUInt32(Arguments[index]);
}
public bool GetBoolean(int index)
{

View file

@ -38,9 +38,7 @@ namespace Server.Diagnostics
{
if (!Core.Profiling) return null;
GumpProfile prof;
if (!_profiles.TryGetValue(type, out prof)) _profiles.Add(type, prof = new GumpProfile(type));
if (!_profiles.TryGetValue(type, out GumpProfile prof)) _profiles.Add(type, prof = new GumpProfile(type));
return prof;
}

View file

@ -68,9 +68,7 @@ namespace Server.Diagnostics
[MethodImpl(MethodImplOptions.Synchronized)]
public static PacketSendProfile Acquire(Type type)
{
PacketSendProfile prof;
if (!_profiles.TryGetValue(type, out prof)) _profiles.Add(type, prof = new PacketSendProfile(type));
if (!_profiles.TryGetValue(type, out PacketSendProfile prof)) _profiles.Add(type, prof = new PacketSendProfile(type));
return prof;
}
@ -102,9 +100,7 @@ namespace Server.Diagnostics
[MethodImpl(MethodImplOptions.Synchronized)]
public static PacketReceiveProfile Acquire(int packetId)
{
PacketReceiveProfile prof;
if (!_profiles.TryGetValue(packetId, out prof))
if (!_profiles.TryGetValue(packetId, out PacketReceiveProfile prof))
_profiles.Add(packetId, prof = new PacketReceiveProfile(packetId));
return prof;

View file

@ -38,9 +38,7 @@ namespace Server.Diagnostics
{
if (!Core.Profiling) return null;
TargetProfile prof;
if (!_profiles.TryGetValue(type, out prof)) _profiles.Add(type, prof = new TargetProfile(type));
if (!_profiles.TryGetValue(type, out TargetProfile prof)) _profiles.Add(type, prof = new TargetProfile(type));
return prof;
}

View file

@ -44,9 +44,7 @@ namespace Server.Diagnostics
{
if (!Core.Profiling) return null;
TimerProfile prof;
if (!_profiles.TryGetValue(name, out prof)) _profiles.Add(name, prof = new TimerProfile(name));
if (!_profiles.TryGetValue(name, out TimerProfile prof)) _profiles.Add(name, prof = new TimerProfile(name));
return prof;
}

View file

@ -284,13 +284,7 @@ namespace Server
}
public static void SendMovingEffect(IEntity from, IEntity to, int itemID, int speed, int duration,
bool fixedDirection, bool explodes)
{
SendMovingEffect(from, to, itemID, speed, duration, fixedDirection, explodes, 0, 0);
}
public static void SendMovingEffect(IEntity from, IEntity to, int itemID, int speed, int duration,
bool fixedDirection, bool explodes, int hue, int renderMode)
bool fixedDirection, bool explodes, int hue = 0, int renderMode = 0)
{
if (from is Mobile mobile)
mobile.ProcessDelta();
@ -328,11 +322,11 @@ namespace Server
bool fixedDirection, bool explodes, int hue, int renderMode, int effect, int explodeEffect, int explodeSound,
EffectLayer layer, int unknown)
{
if (from is Mobile mobile)
mobile.ProcessDelta();
if (from is Mobile fromMob)
fromMob.ProcessDelta();
if (to is Mobile mobile1)
mobile1.ProcessDelta();
if (to is Mobile toMob)
toMob.ProcessDelta();
Map map = from.Map;
@ -376,42 +370,42 @@ namespace Server
public static void SendPacket(Point3D origin, Map map, Packet p)
{
if (map != null)
if (map == null)
return;
IPooledEnumerable<NetState> eable = map.GetClientsInRange(origin);
p.Acquire();
foreach (NetState state in eable)
{
IPooledEnumerable<NetState> eable = map.GetClientsInRange(origin);
p.Acquire();
foreach (NetState state in eable)
{
state.Mobile.ProcessDelta();
state.Send(p);
}
p.Release();
eable.Free();
state.Mobile.ProcessDelta();
state.Send(p);
}
p.Release();
eable.Free();
}
public static void SendPacket(IPoint3D origin, Map map, Packet p)
{
if (map != null)
if (map == null)
return;
IPooledEnumerable<NetState> eable = map.GetClientsInRange(new Point3D(origin));
p.Acquire();
foreach (NetState state in eable)
{
IPooledEnumerable<NetState> eable = map.GetClientsInRange(new Point3D(origin));
p.Acquire();
foreach (NetState state in eable)
{
state.Mobile.ProcessDelta();
state.Send(p);
}
p.Release();
eable.Free();
state.Mobile.ProcessDelta();
state.Send(p);
}
p.Release();
eable.Free();
}
}
}

View file

@ -128,12 +128,12 @@ namespace Server
public class CreateGuildEventArgs : EventArgs
{
public CreateGuildEventArgs(int id)
public CreateGuildEventArgs(uint id)
{
Id = id;
}
public int Id{ get; set; }
public uint Id{ get; set; }
public BaseGuild Guild{ get; set; }
}

View file

@ -31,9 +31,9 @@ namespace Server.Guilds
public abstract class BaseGuild : ISerializable
{
private static int m_NextID = 1;
private static uint m_NextID = 1;
protected BaseGuild(int Id) //serialization ctor
protected BaseGuild(uint Id) //serialization ctor
{
this.Id = Id;
List.Add(this.Id, this);
@ -48,28 +48,26 @@ namespace Server.Guilds
}
[CommandProperty(AccessLevel.Counselor)]
public int Id{ get; }
public uint Id{ get; }
public abstract string Abbreviation{ get; set; }
public abstract string Name{ get; set; }
public abstract GuildType Type{ get; set; }
public abstract bool Disbanded{ get; }
public static Dictionary<int, BaseGuild> List{ get; } = new Dictionary<int, BaseGuild>();
public static Dictionary<uint, BaseGuild> List{ get; } = new Dictionary<uint, BaseGuild>();
int ISerializable.TypeReference => 0;
int ISerializable.SerialIdentity => Id;
uint ISerializable.SerialIdentity => Id;
public abstract void Serialize(GenericWriter writer);
public abstract void Deserialize(GenericReader reader);
public abstract void OnDelete(Mobile mob);
public static BaseGuild Find(int id)
public static BaseGuild Find(uint id)
{
BaseGuild g;
List.TryGetValue(id, out g);
List.TryGetValue(id, out BaseGuild g);
return g;
}

View file

@ -27,7 +27,7 @@ namespace Server.Gumps
{
public class Gump
{
private static int m_NextSerial = 1;
private static uint m_NextSerial = 1;
private static byte[] m_BeginLayout = StringToBuffer("{ ");
private static byte[] m_EndLayout = StringToBuffer(" }");
@ -39,10 +39,10 @@ namespace Server.Gumps
private bool m_Closable = true;
private bool m_Disposable = true;
private bool m_Dragable = true;
private bool m_Draggable = true;
private bool m_Resizable = true;
private int m_Serial;
private uint m_Serial;
private List<string> m_Strings;
internal int m_TextEntries, m_Switches;
@ -68,7 +68,7 @@ namespace Server.Gumps
public List<GumpEntry> Entries{ get; }
public int Serial
public uint Serial
{
get => m_Serial;
set
@ -133,14 +133,14 @@ namespace Server.Gumps
}
}
public bool Dragable
public bool Draggable
{
get => m_Dragable;
get => m_Draggable;
set
{
if (m_Dragable != value)
if (m_Draggable != value)
{
m_Dragable = value;
m_Draggable = value;
Invalidate();
}
}
@ -161,7 +161,7 @@ namespace Server.Gumps
public static int GetTypeID(Type type)
{
return type.FullName.GetHashCode();
return type?.FullName?.GetHashCode() ?? -1;
}
public void Invalidate()
@ -290,7 +290,7 @@ namespace Server.Gumps
Add(new GumpTextEntryLimited(x, y, width, height, hue, entryID, initialText, size));
}
public void AddItemProperty(int serial)
public void AddItemProperty(uint serial)
{
Add(new GumpItemProperty(serial));
}
@ -349,7 +349,7 @@ namespace Server.Gumps
else
disp = new DisplayGumpFast(this);
if (!m_Dragable)
if (!m_Draggable)
disp.AppendLayout(m_NoMove);
if (!m_Closable)
@ -379,7 +379,7 @@ namespace Server.Gumps
m_TextEntries = disp.TextEntries;
m_Switches = disp.Switches;
return disp as Packet;
return (Packet)disp;
}
public virtual void OnResponse(NetState sender, RelayInfo info)

View file

@ -41,6 +41,11 @@ namespace Server.Gumps
}
}
}
protected void Delta(ref uint var, uint val)
{
if (var != val) var = val;
}
protected void Delta(ref int var, int val)
{

View file

@ -25,14 +25,14 @@ namespace Server.Gumps
public class GumpItemProperty : GumpEntry
{
private static byte[] m_LayoutName = Gump.StringToBuffer("itemproperty");
private int m_Serial;
private uint m_Serial;
public GumpItemProperty(int serial)
public GumpItemProperty(uint serial)
{
m_Serial = serial;
}
public int Serial
public uint Serial
{
get => m_Serial;
set => Delta(ref m_Serial, value);

View file

@ -596,7 +596,7 @@ namespace Server
IEntity parent;
Serial serial = reader.ReadInt();
Serial serial = reader.ReadUInt();
if (serial.IsItem)
parent = World.FindItem(serial);
@ -658,7 +658,7 @@ namespace Server
Spawner = 0x100
}
public class Item : IEntity, IHued, IComparable<Item>, ISerializable, ISpawnable
public class Item : IHued, IComparable<Item>, ISerializable, ISpawnable
{
public const int QuestItemHue = 0x4EA; // Hmmmm... "for EA"?
public static readonly List<Item> EmptyItems = new List<Item>();
@ -730,15 +730,7 @@ namespace Server
public int TempFlags
{
get
{
CompactInfo info = LookupCompactInfo();
if (info != null)
return info.m_TempFlags;
return 0;
}
get => LookupCompactInfo()?.m_TempFlags ?? 0;
set
{
CompactInfo info = AcquireCompactInfo();
@ -752,15 +744,7 @@ namespace Server
public int SavedFlags
{
get
{
CompactInfo info = LookupCompactInfo();
if (info != null)
return info.m_SavedFlags;
return 0;
}
get => LookupCompactInfo()?.m_SavedFlags ?? 0;
set
{
CompactInfo info = AcquireCompactInfo();
@ -777,12 +761,7 @@ namespace Server
/// </summary>
public Mobile HeldBy
{
get
{
CompactInfo info = LookupCompactInfo();
return info?.m_HeldBy;
}
get => LookupCompactInfo()?.m_HeldBy;
set
{
CompactInfo info = AcquireCompactInfo();
@ -797,19 +776,7 @@ namespace Server
/// <summary>
/// Overridable. Determines whether the item will show <see cref="AddWeightProperty" />.
/// </summary>
public virtual bool DisplayWeight
{
get
{
if (!Core.ML)
return false;
if (!Movable && !(IsLockedDown || IsSecure) && ItemData.Weight == 255)
return false;
return true;
}
}
public virtual bool DisplayWeight => Core.ML && (Movable || IsLockedDown || IsSecure || ItemData.Weight != 255);
[CommandProperty(AccessLevel.GameMaster)]
public LootType LootType
@ -1097,10 +1064,7 @@ namespace Server
{
CompactInfo info = LookupCompactInfo();
if (info != null && info.m_Weight != -1)
return info.m_Weight;
return DefaultWeight;
return info != null && info.m_Weight != -1 ? info.m_Weight : DefaultWeight;
}
set
{
@ -1161,18 +1125,7 @@ namespace Server
}
}
public List<Item> Items
{
get
{
List<Item> items = LookupItems();
if (items == null)
items = EmptyItems;
return items;
}
}
public List<Item> Items => LookupItems() ?? EmptyItems;
[CommandProperty(AccessLevel.GameMaster)]
public IEntity RootParent
@ -1230,15 +1183,7 @@ namespace Server
[CommandProperty(AccessLevel.GameMaster)]
public string Name
{
get
{
CompactInfo info = LookupCompactInfo();
if (info?.m_Name != null)
return info.m_Name;
return DefaultName;
}
get => LookupCompactInfo()?.m_Name ?? DefaultName;
set
{
if (value == null || value != DefaultName)
@ -1390,12 +1335,7 @@ namespace Server
public Mobile BlessedFor
{
get
{
CompactInfo info = LookupCompactInfo();
return info?.m_BlessedFor;
}
get => LookupCompactInfo()?.m_BlessedFor;
set
{
CompactInfo info = AcquireCompactInfo();
@ -1464,7 +1404,8 @@ namespace Server
{
Mobile m = state.Mobile;
if (m.InRange(oldLocation, GetUpdateRange(m))) state.Send(RemovePacket);
if (m.InRange(oldLocation, GetUpdateRange(m)))
state.Send(RemovePacket);
}
eable.Free();
@ -1863,7 +1804,7 @@ namespace Server
int ISerializable.TypeReference => m_TypeRef;
int ISerializable.SerialIdentity => Serial;
uint ISerializable.SerialIdentity => Serial;
public virtual void Serialize(GenericWriter writer)
{
@ -2070,12 +2011,7 @@ namespace Server
public ISpawner Spawner
{
get
{
CompactInfo info = LookupCompactInfo();
return info?.m_Spawner;
}
get => LookupCompactInfo()?.m_Spawner;
set
{
CompactInfo info = AcquireCompactInfo();
@ -2141,10 +2077,7 @@ namespace Server
private CompactInfo AcquireCompactInfo()
{
if (m_CompactInfo == null)
m_CompactInfo = new CompactInfo();
return m_CompactInfo;
return m_CompactInfo ?? (m_CompactInfo = new CompactInfo());
}
private void ReleaseCompactInfo()
@ -2178,27 +2111,16 @@ namespace Server
if (this is Container container)
return container.m_Items;
CompactInfo info = LookupCompactInfo();
return info?.m_Items;
return LookupCompactInfo()?.m_Items;
}
public List<Item> AcquireItems()
{
if (this is Container cont)
{
if (cont.m_Items == null)
cont.m_Items = new List<Item>();
return cont.m_Items;
}
return cont.m_Items ?? (cont.m_Items = new List<Item>());
CompactInfo info = AcquireCompactInfo();
if (info.m_Items == null)
info.m_Items = new List<Item>();
return info.m_Items;
return info.m_Items ?? (info.m_Items = new List<Item>());
}
private void SetFlag(ImplFlag flag, bool value)
@ -2216,16 +2138,12 @@ namespace Server
public BounceInfo GetBounce()
{
CompactInfo info = LookupCompactInfo();
return info?.m_Bounce;
return LookupCompactInfo()?.m_Bounce;
}
public void RecordBounce()
{
CompactInfo info = AcquireCompactInfo();
info.m_Bounce = new BounceInfo(this);
AcquireCompactInfo().m_Bounce = new BounceInfo(this);
}
public void ClearBounce()
@ -2234,23 +2152,23 @@ namespace Server
BounceInfo bounce = info?.m_Bounce;
if (bounce != null)
if (bounce == null)
return;
info.m_Bounce = null;
if (bounce.m_Parent is Item parentItem)
{
info.m_Bounce = null;
if (bounce.m_Parent is Item parentItem)
{
if (!parentItem.Deleted)
parentItem.OnItemBounceCleared(this);
}
else if (bounce.m_Parent is Mobile parentMobile)
{
if (!parentMobile.Deleted)
parentMobile.OnItemBounceCleared(this);
}
VerifyCompactInfo();
if (!parentItem.Deleted)
parentItem.OnItemBounceCleared(this);
}
else if (bounce.m_Parent is Mobile parentMobile)
{
if (!parentMobile.Deleted)
parentMobile.OnItemBounceCleared(this);
}
VerifyCompactInfo();
}
/// <summary>
@ -2560,7 +2478,7 @@ namespace Server
/// {
/// if ( from.Int &gt;= 100 )
/// return true;
///
///
/// return base.AllowEquippedCast( from );
/// }</code>
/// When placed in an Item script, the item may be cast when equipped if the <paramref name="from" /> has 100 or more
@ -2940,12 +2858,7 @@ namespace Server
public bool GetTempFlag(int flag)
{
CompactInfo info = LookupCompactInfo();
if (info == null)
return false;
return (info.m_TempFlags & flag) != 0;
return ((LookupCompactInfo()?.m_TempFlags ?? 0) & flag) != 0;
}
public void SetTempFlag(int flag, bool value)
@ -2963,12 +2876,7 @@ namespace Server
public bool GetSavedFlag(int flag)
{
CompactInfo info = LookupCompactInfo();
if (info == null)
return false;
return (info.m_SavedFlags & flag) != 0;
return ((LookupCompactInfo()?.m_SavedFlags ?? 0) & flag) != 0;
}
public void SetSavedFlag(int flag, bool value)
@ -3077,7 +2985,7 @@ namespace Server
if (GetSaveFlag(flags, SaveFlag.Parent))
{
Serial parent = reader.ReadInt();
Serial parent = reader.ReadUInt();
if (parent.IsMobile)
m_Parent = World.FindMobile(parent);
@ -3197,7 +3105,7 @@ namespace Server
if (GetSaveFlag(flags, SaveFlag.Parent))
{
Serial parent = reader.ReadInt();
Serial parent = reader.ReadUInt();
if (parent.IsMobile)
m_Parent = World.FindMobile(parent);
@ -3290,7 +3198,7 @@ namespace Server
if (name != DefaultName)
AcquireCompactInfo().m_Name = name;
Serial parent = reader.ReadInt();
Serial parent = reader.ReadUInt();
if (parent.IsMobile)
m_Parent = World.FindMobile(parent);
@ -3554,6 +3462,7 @@ namespace Server
}
catch
{
// ignored
}
else
m_DeltaQueue.Remove(this);
@ -3599,37 +3508,37 @@ namespace Server
public void PublicOverheadMessage(MessageType type, int hue, bool ascii, string text)
{
if (m_Map != null)
if (m_Map == null)
return;
Packet p = null;
Point3D worldLoc = GetWorldLocation();
IPooledEnumerable<NetState> eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
foreach (NetState state in eable)
{
Packet p = null;
Point3D worldLoc = GetWorldLocation();
Mobile m = state.Mobile;
IPooledEnumerable<NetState> eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
foreach (NetState state in eable)
if (m.CanSee(this) && m.InRange(worldLoc, GetUpdateRange(m)))
{
Mobile m = state.Mobile;
if (m.CanSee(this) && m.InRange(worldLoc, GetUpdateRange(m)))
if (p == null)
{
if (p == null)
{
if (ascii)
p = new AsciiMessage(Serial, m_ItemID, type, hue, 3, Name, text);
else
p = new UnicodeMessage(Serial, m_ItemID, type, hue, 3, "ENU", Name, text);
if (ascii)
p = new AsciiMessage(Serial, m_ItemID, type, hue, 3, Name, text);
else
p = new UnicodeMessage(Serial, m_ItemID, type, hue, 3, "ENU", Name, text);
p.Acquire();
}
state.Send(p);
p.Acquire();
}
state.Send(p);
}
Packet.Release(p);
eable.Free();
}
Packet.Release(p);
eable.Free();
}
public void PublicOverheadMessage(MessageType type, int hue, int number)
@ -3639,30 +3548,30 @@ namespace Server
public void PublicOverheadMessage(MessageType type, int hue, int number, string args)
{
if (m_Map != null)
if (m_Map == null)
return;
Packet p = null;
Point3D worldLoc = GetWorldLocation();
IPooledEnumerable<NetState> eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
foreach (NetState state in eable)
{
Packet p = null;
Point3D worldLoc = GetWorldLocation();
Mobile m = state.Mobile;
IPooledEnumerable<NetState> eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
foreach (NetState state in eable)
if (m.CanSee(this) && m.InRange(worldLoc, GetUpdateRange(m)))
{
Mobile m = state.Mobile;
if (p == null)
p = Packet.Acquire(new MessageLocalized(Serial, m_ItemID, type, hue, 3, number, Name, args));
if (m.CanSee(this) && m.InRange(worldLoc, GetUpdateRange(m)))
{
if (p == null)
p = Packet.Acquire(new MessageLocalized(Serial, m_ItemID, type, hue, 3, number, Name, args));
state.Send(p);
}
state.Send(p);
}
Packet.Release(p);
eable.Free();
}
Packet.Release(p);
eable.Free();
}
public virtual void OnAfterDelete()
@ -3673,7 +3582,7 @@ namespace Server
{
List<Item> items = LookupItems();
if (items != null && items.Contains(item))
if (items?.Contains(item) == true)
{
item.SendRemovePacket();
@ -3728,26 +3637,16 @@ namespace Server
public virtual bool DropToMobile(Mobile from, Mobile target, Point3D p)
{
if (Deleted || from.Deleted || target.Deleted || from.Map != target.Map || from.Map == null ||
target.Map == null)
return false;
if (from.AccessLevel < AccessLevel.GameMaster && !from.InRange(target.Location, 2))
return false;
if (!from.CanSee(target) || !from.InLOS(target))
return false;
if (!from.OnDroppedItemToMobile(this, target))
return false;
if (!OnDroppedToMobile(from, target))
return false;
if (!target.OnDragDrop(from, this))
return false;
return true;
return !(Deleted || from.Deleted || target.Deleted) && from.Map == target.Map && from.Map != null &&
target.Map != null && (from.AccessLevel >= AccessLevel.GameMaster || from.InRange(target.Location, 2)) &&
from.CanSee(target) && from.InLOS(target) && from.OnDroppedItemToMobile(this, target) &&
OnDroppedToMobile(from, target) && target.OnDragDrop(from, this);
}
public virtual bool OnDroppedInto(Mobile from, Container target, Point3D p)
{
if (!from.OnDroppedItemInto(this, target, p)) return false;
if (!from.OnDroppedItemInto(this, target, p))
return false;
if (Nontransferable && from.Player && target != from.Backpack)
{
@ -4044,21 +3943,20 @@ namespace Server
public void SendRemovePacket()
{
if (!Deleted && m_Map != null)
if (Deleted || m_Map == null)
return;
Point3D worldLoc = GetWorldLocation();
IPooledEnumerable<NetState> eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
foreach (NetState state in eable)
{
Point3D worldLoc = GetWorldLocation();
Mobile m = state.Mobile;
IPooledEnumerable<NetState> eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
foreach (NetState state in eable)
{
Mobile m = state.Mobile;
if (m.InRange(worldLoc, GetUpdateRange(m))) state.Send(RemovePacket);
}
eable.Free();
if (m.InRange(worldLoc, GetUpdateRange(m))) state.Send(RemovePacket);
}
eable.Free();
}
public virtual int GetDropSound()
@ -4090,12 +3988,7 @@ namespace Server
public Point3D GetWorldTop()
{
IEntity root = RootParent;
if (root == null)
return new Point3D(m_Location.m_X, m_Location.m_Y, m_Location.m_Z + ItemData.CalcHeight);
return root.Location;
return RootParent?.Location ?? new Point3D(m_Location.m_X, m_Location.m_Y, m_Location.m_Z + ItemData.CalcHeight);
}
public void SendLocalizedMessageTo(Mobile to, int number)
@ -4550,65 +4443,56 @@ namespace Server
{
Point3D oldLocation = m_Location;
if (oldLocation != value)
if (oldLocation == value)
return;
if (m_Map != null)
{
if (m_Map != null)
if (m_Parent == null)
{
if (m_Parent == null)
IPooledEnumerable<NetState> eable;
if (m_Location.m_X != 0)
{
IPooledEnumerable<NetState> eable;
if (m_Location.m_X != 0)
{
eable = m_Map.GetClientsInRange(oldLocation, GetMaxUpdateRange());
foreach (NetState state in eable)
{
Mobile m = state.Mobile;
if (!m.InRange(value, GetUpdateRange(m))) state.Send(RemovePacket);
}
eable.Free();
}
Point3D oldLoc = m_Location;
m_Location = value;
ReleaseWorldPackets();
SetLastMoved();
eable = m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange());
eable = m_Map.GetClientsInRange(oldLocation, GetMaxUpdateRange());
foreach (NetState state in eable)
{
Mobile m = state.Mobile;
if (m.CanSee(this) && m.InRange(m_Location, GetUpdateRange(m)) &&
(!state.HighSeas || !NoMoveHS || (m_DeltaFlags & ItemDelta.Update) != 0 ||
!m.InRange(oldLoc, GetUpdateRange(m))))
SendInfoTo(state);
if (!m.InRange(value, GetUpdateRange(m))) state.Send(RemovePacket);
}
eable.Free();
RemDelta(ItemDelta.Update);
}
else if (m_Parent is Item)
Point3D oldLoc = m_Location;
m_Location = value;
ReleaseWorldPackets();
SetLastMoved();
eable = m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange());
foreach (NetState state in eable)
{
m_Location = value;
ReleaseWorldPackets();
Mobile m = state.Mobile;
Delta(ItemDelta.Update);
}
else
{
m_Location = value;
ReleaseWorldPackets();
if (m.CanSee(this) && m.InRange(m_Location, GetUpdateRange(m)) &&
(!state.HighSeas || !NoMoveHS || (m_DeltaFlags & ItemDelta.Update) != 0 ||
!m.InRange(oldLoc, GetUpdateRange(m))))
SendInfoTo(state);
}
if (m_Parent == null)
m_Map.OnMove(oldLocation, this);
eable.Free();
RemDelta(ItemDelta.Update);
}
else if (m_Parent is Item)
{
m_Location = value;
ReleaseWorldPackets();
Delta(ItemDelta.Update);
}
else
{
@ -4616,8 +4500,16 @@ namespace Server
ReleaseWorldPackets();
}
OnLocationChange(oldLocation);
if (m_Parent == null)
m_Map.OnMove(oldLocation, this);
}
else
{
m_Location = value;
ReleaseWorldPackets();
}
OnLocationChange(oldLocation);
}
}
@ -4675,4 +4567,4 @@ namespace Server
#endregion
}
}
}

View file

@ -845,7 +845,6 @@ namespace Server.Items
for (int i = 0; i < groups.Count; ++i)
{
items[i] = groups[i].ToArray();
//items[i] = (Item[])(((ArrayList)groups[i]).ToArray( typeof( Item ) ));
for (int j = 0; j < items[i].Length; ++j)
totals[i] += items[i][j].Amount;
@ -939,7 +938,6 @@ namespace Server.Items
for (int j = 0; j < groups.Count; ++j)
{
items[i][j] = groups[j].ToArray();
//items[i][j] = (Item[])(((ArrayList)groups[j]).ToArray( typeof( Item ) ));
for (int k = 0; k < items[i][j].Length; ++k)
totals[i][j] += items[i][j][k].Amount;
@ -1341,7 +1339,6 @@ namespace Server.Items
{
Item[] items = groups[i].ToArray();
//Item[] items = (Item[])(((ArrayList)groups[i]).ToArray( typeof( Item ) ));
int total = 0;
for (int j = 0; j < items.Length; ++j)
@ -1392,7 +1389,6 @@ namespace Server.Items
for (int j = 0; j < groups.Count; ++j)
{
Item[] items = groups[j].ToArray();
//Item[] items = (Item[])(((ArrayList)groups[j]).ToArray( typeof( Item ) ));
int total = 0;
for (int k = 0; k < items.Length; ++k)
@ -1445,7 +1441,6 @@ namespace Server.Items
for (int j = 0; j < groups.Count; ++j)
{
Item[] items = groups[j].ToArray();
//Item[] items = (Item[])(((ArrayList)groups[j]).ToArray( typeof( Item ) ));
int total = 0;
for (int k = 0; k < items.Length; ++k)
@ -1501,7 +1496,7 @@ namespace Server.Items
{
if (current == null || current.Items.Count == 0)
return;
List<Item> items = current.Items;
for (int i = 0; i < items.Count; ++i)
@ -1530,7 +1525,7 @@ namespace Server.Items
{
if (current == null || current.Items.Count == 0)
return;
List<Item> items = current.Items;
for (int i = 0; i < items.Count; ++i)
@ -1554,7 +1549,7 @@ namespace Server.Items
{
if (current == null || current.Items.Count == 0)
return null;
List<Item> list = current.Items;
for (int i = 0; i < list.Count; ++i)
@ -1585,7 +1580,7 @@ namespace Server.Items
{
if (current == null || current.Items.Count <= 0)
return null;
List<Item> list = current.Items;
for (int i = 0; i < list.Count; ++i)
@ -1619,7 +1614,7 @@ namespace Server.Items
{
List<T> list = new List<T>();
RecurseFindItemsByType(this, recurse, list, predicate);
return list;
}
@ -1628,7 +1623,7 @@ namespace Server.Items
{
if (current == null || current.Items.Count == 0)
return;
List<Item> items = current.Items;
for (int i = 0; i < items.Count; ++i)
@ -1655,7 +1650,7 @@ namespace Server.Items
{
if (current == null || current.Items.Count == 0)
return null;
List<Item> list = current.Items;
for (int i = 0; i < list.Count; ++i)
@ -1777,12 +1772,8 @@ namespace Server.Items
public static ContainerData GetData(int itemID)
{
ContainerData data = null;
m_Table.TryGetValue(itemID, out data);
if (data != null)
return data;
return Default;
m_Table.TryGetValue(itemID, out ContainerData data);
return data ?? Default;
}
}
}
}

View file

@ -181,10 +181,10 @@ namespace Server
Closable = true;
Disposable = true;
Dragable = true;
Draggable = true;
Resizable = false;
User.CloseGump(GetType());
User.CloseGump<EditGump>();
CompileLayout();
}
@ -201,7 +201,7 @@ namespace Server
public void Close()
{
User.CloseGump(GetType());
User.CloseGump<EditGump>();
if (Check != null && !Check.Deleted)
Check.UpdateTrade(User);

View file

@ -24,12 +24,7 @@ namespace Server
{
public abstract class BaseHairInfo
{
protected BaseHairInfo(int itemid)
: this(itemid, 0)
{
}
protected BaseHairInfo(int itemid, int hue)
protected BaseHairInfo(int itemid, int hue = 0)
{
ItemID = itemid;
Hue = hue;
@ -67,7 +62,7 @@ namespace Server
public class HairInfo : BaseHairInfo
{
public HairInfo(int itemid)
: base(itemid, 0)
: base(itemid)
{
}
@ -81,7 +76,8 @@ namespace Server
{
}
public static int FakeSerial(Mobile parent)
// TOOD: Can we make this higher for newer clients?
public static uint FakeSerial(Mobile parent)
{
return 0x7FFFFFFF - 0x400 - parent.Serial * 4;
}
@ -90,7 +86,7 @@ namespace Server
public class FacialHairInfo : BaseHairInfo
{
public FacialHairInfo(int itemid)
: base(itemid, 0)
: base(itemid)
{
}
@ -104,7 +100,8 @@ namespace Server
{
}
public static int FakeSerial(Mobile parent)
// TOOD: Can we make this higher for newer clients?
public static uint FakeSerial(Mobile parent)
{
return 0x7FFFFFFF - 0x400 - 1 - parent.Serial * 4;
}
@ -120,9 +117,7 @@ namespace Server
if (parent.SolidHueOverride >= 0)
hue = parent.SolidHueOverride;
int hairSerial = HairInfo.FakeSerial(parent);
m_Stream.Write(hairSerial);
m_Stream.Write(HairInfo.FakeSerial(parent));
m_Stream.Write((short)parent.HairItemID);
m_Stream.Write((byte)0);
m_Stream.Write((byte)Layer.Hair);
@ -141,9 +136,7 @@ namespace Server
if (parent.SolidHueOverride >= 0)
hue = parent.SolidHueOverride;
int hairSerial = FacialHairInfo.FakeSerial(parent);
m_Stream.Write(hairSerial);
m_Stream.Write(FacialHairInfo.FakeSerial(parent));
m_Stream.Write((short)parent.FacialHairItemID);
m_Stream.Write((byte)0);
m_Stream.Write((byte)Layer.FacialHair);

View file

@ -95,7 +95,7 @@ namespace Server
{
return s.Mobiles.OfType<T>().Where(o => !o.Deleted && bounds.Contains(o));
}
public static IEnumerable<T> SelectItems<T>(Sector s, Rectangle2D bounds) where T : Item
{
return s.Items.OfType<T>()
@ -1572,5 +1572,47 @@ namespace Server
}
#endregion
public Point3D GetRandomNearbyLocation(Point3D loc, int maxRange = 2, int minRange = 0, int retryCount = 10, int height = 16, bool checkBlocksFit = false,
bool checkMobiles = false)
{
int j = 0;
int range = maxRange - minRange;
bool[,] locs = range <= 10 ? new bool[range + 1, range + 1] : null;
do
{
int xRand = Utility.Random(range);
int yRand = Utility.Random(range);
if (locs?[xRand, yRand] != true)
{
int x = loc.X + xRand + minRange;
int y = loc.Y + yRand + minRange;
if (CanFit(x, y, loc.Z, height, checkBlocksFit, checkMobiles))
{
loc = new Point3D(x, y, loc.Z);
break;
}
int z = GetAverageZ(x, y);
if (CanFit(x, y, z, height, checkBlocksFit, checkMobiles))
{
loc = new Point3D(x, y, z);
break;
}
if (locs != null)
locs[xRand, yRand] = true;
}
j++;
}
while (j < retryCount);
return loc;
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -449,8 +449,7 @@ namespace Server.Network
return;
}
int length;
byte[] buffer = p.Compile(CompressionEnabled, out length);
byte[] buffer = p.Compile(CompressionEnabled, out int length);
if (buffer != null)
{

View file

@ -329,7 +329,7 @@ namespace Server.Network
public static void EncodedCommand(NetState state, PacketReader pvSrc)
{
IEntity e = World.FindEntity(pvSrc.ReadInt32());
IEntity e = World.FindEntity(pvSrc.ReadUInt32());
int packetID = pvSrc.ReadUInt16();
EncodedPacketHandler ph = GetEncodedHandler(packetID);
@ -361,7 +361,7 @@ namespace Server.Network
public static void RenameRequest(NetState state, PacketReader pvSrc)
{
Mobile from = state.Mobile;
Mobile targ = World.FindMobile(pvSrc.ReadInt32());
Mobile targ = World.FindMobile(pvSrc.ReadUInt32());
if (targ != null)
EventSink.InvokeRenameRequest(new RenameRequestEventArgs(from, targ, pvSrc.ReadStringSafe()));
@ -378,7 +378,7 @@ namespace Server.Network
{
case 1: // Cancel
{
Serial serial = pvSrc.ReadInt32();
Serial serial = pvSrc.ReadUInt32();
if (World.FindItem(serial) is SecureTradeContainer cont && cont.Trade != null &&
(cont.Trade.From.Mobile == state.Mobile || cont.Trade.To.Mobile == state.Mobile))
@ -388,7 +388,7 @@ namespace Server.Network
}
case 2: // Check
{
Serial serial = pvSrc.ReadInt32();
Serial serial = pvSrc.ReadUInt32();
if (World.FindItem(serial) is SecureTradeContainer cont)
{
@ -412,7 +412,7 @@ namespace Server.Network
}
case 3: // Update Gold
{
Serial serial = pvSrc.ReadInt32();
Serial serial = pvSrc.ReadUInt32();
if (World.FindItem(serial) is SecureTradeContainer cont)
{
@ -447,7 +447,7 @@ namespace Server.Network
pvSrc.Seek(1, SeekOrigin.Begin);
int msgSize = pvSrc.ReadUInt16();
Mobile vendor = World.FindMobile(pvSrc.ReadInt32());
Mobile vendor = World.FindMobile(pvSrc.ReadUInt32());
byte flag = pvSrc.ReadByte();
if (vendor == null) return;
@ -469,7 +469,7 @@ namespace Server.Network
while (msgSize > 0)
{
byte layer = pvSrc.ReadByte();
Serial serial = pvSrc.ReadInt32();
Serial serial = pvSrc.ReadUInt32();
int amount = pvSrc.ReadInt16();
buyList.Add(new BuyItemResponse(serial, amount));
@ -487,7 +487,7 @@ namespace Server.Network
public static void VendorSellReply(NetState state, PacketReader pvSrc)
{
Serial serial = pvSrc.ReadInt32();
Serial serial = pvSrc.ReadUInt32();
Mobile vendor = World.FindMobile(serial);
if (vendor == null) return;
@ -505,7 +505,7 @@ namespace Server.Network
for (int i = 0; i < count; i++)
{
Item item = World.FindItem(pvSrc.ReadInt32());
Item item = World.FindItem(pvSrc.ReadUInt32());
int Amount = pvSrc.ReadInt16();
if (item != null && Amount > 0)
@ -567,7 +567,7 @@ namespace Server.Network
{
Mobile from = state.Mobile;
Serial serial = pvSrc.ReadInt32();
Serial serial = pvSrc.ReadUInt32();
int unk = pvSrc.ReadByte();
string lang = pvSrc.ReadString(3);
@ -590,7 +590,7 @@ namespace Server.Network
public static void MobileNameRequest(NetState state, PacketReader pvSrc)
{
Mobile m = World.FindMobile(pvSrc.ReadInt32());
Mobile m = World.FindMobile(pvSrc.ReadUInt32());
if (m != null && Utility.InUpdateRange(state.Mobile, m) && state.Mobile.CanSee(m))
state.Send(new MobileName(m));
@ -605,7 +605,7 @@ namespace Server.Network
public static void AttackReq(NetState state, PacketReader pvSrc)
{
Mobile from = state.Mobile;
Mobile m = World.FindMobile(pvSrc.ReadInt32());
Mobile m = World.FindMobile(pvSrc.ReadUInt32());
if (m != null)
from.Attack(m);
@ -613,7 +613,7 @@ namespace Server.Network
public static void HuePickerResponse(NetState state, PacketReader pvSrc)
{
int serial = pvSrc.ReadInt32();
uint serial = pvSrc.ReadUInt32();
int value = pvSrc.ReadInt16();
int hue = pvSrc.ReadInt16() & 0x3FFF;
@ -836,7 +836,7 @@ namespace Server.Network
if (split.Length > 0)
{
int spellID = Utility.ToInt32(split[0]) - 1;
int serial = split.Length > 1 ? Utility.ToInt32(split[1]) : -1;
uint serial = split.Length > 1 ? Utility.ToUInt32(split[1]) : (uint)Serial.MinusOne;
EventSink.InvokeCastSpellRequest(new CastSpellRequestEventArgs(m, spellID, World.FindItem(serial)));
}
@ -892,7 +892,7 @@ namespace Server.Network
public static void AsciiPromptResponse(NetState state, PacketReader pvSrc)
{
int serial = pvSrc.ReadInt32();
uint serial = pvSrc.ReadUInt32();
int prompt = pvSrc.ReadInt32();
int type = pvSrc.ReadInt32();
string text = pvSrc.ReadStringSafe();
@ -916,7 +916,7 @@ namespace Server.Network
public static void UnicodePromptResponse(NetState state, PacketReader pvSrc)
{
int serial = pvSrc.ReadInt32();
uint serial = pvSrc.ReadUInt32();
int prompt = pvSrc.ReadInt32();
int type = pvSrc.ReadInt32();
string lang = pvSrc.ReadString(4);
@ -941,7 +941,7 @@ namespace Server.Network
public static void MenuResponse(NetState state, PacketReader pvSrc)
{
int serial = pvSrc.ReadInt32();
uint serial = pvSrc.ReadUInt32();
int menuID = pvSrc.ReadInt16(); // unused in our implementation
int index = pvSrc.ReadInt16();
int itemID = pvSrc.ReadInt16();
@ -966,7 +966,7 @@ namespace Server.Network
public static void ProfileReq(NetState state, PacketReader pvSrc)
{
int type = pvSrc.ReadByte();
Serial serial = pvSrc.ReadInt32();
Serial serial = pvSrc.ReadUInt32();
Mobile beholder = state.Mobile;
Mobile beheld = World.FindMobile(serial);
@ -1006,14 +1006,11 @@ namespace Server.Network
public static void LiftReq(NetState state, PacketReader pvSrc)
{
Serial serial = pvSrc.ReadInt32();
Serial serial = pvSrc.ReadUInt32();
int amount = pvSrc.ReadUInt16();
Item item = World.FindItem(serial);
bool rejected;
LRReason reject;
state.Mobile.Lift(item, amount, out rejected, out reject);
state.Mobile.Lift(item, amount, out bool rejected, out LRReason reject);
}
public static void EquipReq(NetState state, PacketReader pvSrc)
@ -1028,7 +1025,7 @@ namespace Server.Network
if (!valid) return;
pvSrc.Seek(5, SeekOrigin.Current);
Mobile to = World.FindMobile(pvSrc.ReadInt32());
Mobile to = World.FindMobile(pvSrc.ReadUInt32());
if (to == null)
to = from;
@ -1045,7 +1042,7 @@ namespace Server.Network
int x = pvSrc.ReadInt16();
int y = pvSrc.ReadInt16();
int z = pvSrc.ReadSByte();
Serial dest = pvSrc.ReadInt32();
Serial dest = pvSrc.ReadUInt32();
Point3D loc = new Point3D(x, y, z);
@ -1083,7 +1080,7 @@ namespace Server.Network
int y = pvSrc.ReadInt16();
int z = pvSrc.ReadSByte();
pvSrc.ReadByte(); // Grid Location?
Serial dest = pvSrc.ReadInt32();
Serial dest = pvSrc.ReadUInt32();
Point3D loc = new Point3D(x, y, z);
@ -1140,7 +1137,7 @@ namespace Server.Network
int type = pvSrc.ReadByte();
int targetID = pvSrc.ReadInt32();
int flags = pvSrc.ReadByte();
Serial serial = pvSrc.ReadInt32();
Serial serial = pvSrc.ReadUInt32();
int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16();
int graphic = pvSrc.ReadUInt16();
@ -1164,7 +1161,7 @@ namespace Server.Network
// User pressed escape
t.Cancel(from, TargetCancelType.Canceled);
}
else if (Target.TargetIDValidation && t.TargetID != targetID)
else if (t.TargetID != targetID)
{
// Sanity, prevent fake target
}
@ -1240,92 +1237,93 @@ namespace Server.Network
public static void DisplayGumpResponse(NetState state, PacketReader pvSrc)
{
int serial = pvSrc.ReadInt32();
uint serial = pvSrc.ReadUInt32();
int typeID = pvSrc.ReadInt32();
int buttonID = pvSrc.ReadInt32();
foreach (Gump gump in state.Gumps)
if (gump.Serial == serial && gump.TypeID == typeID)
{
if (gump.Serial != serial || gump.TypeID != typeID)
continue;
bool buttonExists = buttonID == 0; // 0 is always 'close'
if (!buttonExists)
foreach (GumpEntry e in gump.Entries)
{
if (e is GumpButton button && button.ButtonID == buttonID)
{
buttonExists = true;
break;
}
if (e is GumpImageTileButton tileButton && tileButton.ButtonID == buttonID)
{
buttonExists = true;
break;
}
}
if (!buttonExists)
{
bool buttonExists = buttonID == 0; // 0 is always 'close'
if (!buttonExists)
foreach (GumpEntry e in gump.Entries)
{
if (e is GumpButton button && button.ButtonID == buttonID)
{
buttonExists = true;
break;
}
if (e is GumpImageTileButton tileButton && tileButton.ButtonID == buttonID)
{
buttonExists = true;
break;
}
}
if (!buttonExists)
{
state.WriteConsole("Invalid gump response, disconnecting...");
state.Dispose();
return;
}
int switchCount = pvSrc.ReadInt32();
if (switchCount < 0 || switchCount > gump.m_Switches)
{
state.WriteConsole("Invalid gump response, disconnecting...");
state.Dispose();
return;
}
int[] switches = new int[switchCount];
for (int j = 0; j < switches.Length; ++j)
switches[j] = pvSrc.ReadInt32();
int textCount = pvSrc.ReadInt32();
if (textCount < 0 || textCount > gump.m_TextEntries)
{
state.WriteConsole("Invalid gump response, disconnecting...");
state.Dispose();
return;
}
TextRelay[] textEntries = new TextRelay[textCount];
for (int j = 0; j < textEntries.Length; ++j)
{
int entryID = pvSrc.ReadUInt16();
int textLength = pvSrc.ReadUInt16();
if (textLength > 239)
{
state.WriteConsole("Invalid gump response, disconnecting...");
state.Dispose();
return;
}
string text = pvSrc.ReadUnicodeStringSafe(textLength);
textEntries[j] = new TextRelay(entryID, text);
}
state.RemoveGump(gump);
GumpProfile prof = GumpProfile.Acquire(gump.GetType());
prof?.Start();
gump.OnResponse(state, new RelayInfo(buttonID, switches, textEntries));
prof?.Finish();
state.WriteConsole("Invalid gump response, disconnecting...");
state.Dispose();
return;
}
int switchCount = pvSrc.ReadInt32();
if (switchCount < 0 || switchCount > gump.m_Switches)
{
state.WriteConsole("Invalid gump response, disconnecting...");
state.Dispose();
return;
}
int[] switches = new int[switchCount];
for (int j = 0; j < switches.Length; ++j)
switches[j] = pvSrc.ReadInt32();
int textCount = pvSrc.ReadInt32();
if (textCount < 0 || textCount > gump.m_TextEntries)
{
state.WriteConsole("Invalid gump response, disconnecting...");
state.Dispose();
return;
}
TextRelay[] textEntries = new TextRelay[textCount];
for (int j = 0; j < textEntries.Length; ++j)
{
int entryID = pvSrc.ReadUInt16();
int textLength = pvSrc.ReadUInt16();
if (textLength > 239)
{
state.WriteConsole("Invalid gump response, disconnecting...");
state.Dispose();
return;
}
string text = pvSrc.ReadUnicodeStringSafe(textLength);
textEntries[j] = new TextRelay(entryID, text);
}
state.RemoveGump(gump);
GumpProfile prof = GumpProfile.Acquire(gump.GetType());
prof?.Start();
gump.OnResponse(state, new RelayInfo(buttonID, switches, textEntries));
prof?.Finish();
return;
}
if (typeID == 461)
{
// Virtue gump
@ -1333,7 +1331,7 @@ namespace Server.Network
if (buttonID == 1 && switchCount > 0)
{
Mobile beheld = World.FindMobile(pvSrc.ReadInt32());
Mobile beheld = World.FindMobile(pvSrc.ReadUInt32());
if (beheld != null)
EventSink.InvokeVirtueGumpRequest(new VirtueGumpRequestEventArgs(state.Mobile, beheld));
@ -1466,7 +1464,7 @@ namespace Server.Network
if (from.AccessLevel >= AccessLevel.Counselor || Core.TickCount - from.NextActionTime >= 0)
{
int value = pvSrc.ReadInt32();
uint value = pvSrc.ReadUInt32();
if ((value & ~0x7FFFFFFF) != 0)
{
@ -1504,7 +1502,7 @@ namespace Server.Network
{
Mobile from = state.Mobile;
Serial s = pvSrc.ReadInt32();
Serial s = pvSrc.ReadUInt32();
if (s.IsMobile)
{
@ -1609,28 +1607,22 @@ namespace Server.Network
PacketHandler ph = GetExtendedHandler(packetID);
if (ph != null)
if (ph == null)
{
if (ph.Ingame && state.Mobile == null)
{
pvSrc.Trace(state);
return;
}
if (ph.Ingame && state.Mobile?.Deleted != false)
{
if (state.Mobile == null)
Console.WriteLine(
"Client: {0}: Sent ingame packet (0xBFx{1:X2}) before having been attached to a mobile", state,
packetID);
state.Dispose();
}
else if (ph.Ingame && state.Mobile.Deleted)
{
state.Dispose();
}
else
{
ph.OnReceive(state, pvSrc);
}
state.Dispose();
}
else
{
pvSrc.Trace(state);
}
ph.OnReceive(state, pvSrc);
}
public static void CastSpell(NetState state, PacketReader pvSrc)
@ -1643,7 +1635,7 @@ namespace Server.Network
Item spellbook = null;
if (pvSrc.ReadInt16() == 1)
spellbook = World.FindItem(pvSrc.ReadInt32());
spellbook = World.FindItem(pvSrc.ReadUInt32());
int spellID = pvSrc.ReadInt16() - 1;
@ -1659,12 +1651,12 @@ namespace Server.Network
if (from.AccessLevel >= AccessLevel.Counselor || Core.TickCount - from.NextActionTime >= 0)
{
Item bandage = World.FindItem(pvSrc.ReadInt32());
Item bandage = World.FindItem(pvSrc.ReadUInt32());
if (bandage == null)
return;
Mobile target = World.FindMobile(pvSrc.ReadInt32());
Mobile target = World.FindMobile(pvSrc.ReadUInt32());
if (target == null)
return;
@ -1700,7 +1692,7 @@ namespace Server.Network
for (int i = 0; i < count; ++i)
{
Serial s = pvSrc.ReadInt32();
Serial s = pvSrc.ReadUInt32();
if (s.IsMobile)
{
@ -1727,7 +1719,7 @@ namespace Server.Network
Mobile from = state.Mobile;
Serial s = pvSrc.ReadInt32();
Serial s = pvSrc.ReadUInt32();
if (s.IsMobile)
{
@ -1789,13 +1781,13 @@ namespace Server.Network
public static void PartyMessage_RemoveMember(NetState state, PacketReader pvSrc)
{
if (PartyCommands.Handler != null)
PartyCommands.Handler.OnRemove(state.Mobile, World.FindMobile(pvSrc.ReadInt32()));
PartyCommands.Handler.OnRemove(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
}
public static void PartyMessage_PrivateMessage(NetState state, PacketReader pvSrc)
{
if (PartyCommands.Handler != null)
PartyCommands.Handler.OnPrivateMessage(state.Mobile, World.FindMobile(pvSrc.ReadInt32()),
PartyCommands.Handler.OnPrivateMessage(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()),
pvSrc.ReadUnicodeStringSafe());
}
@ -1814,13 +1806,13 @@ namespace Server.Network
public static void PartyMessage_Accept(NetState state, PacketReader pvSrc)
{
if (PartyCommands.Handler != null)
PartyCommands.Handler.OnAccept(state.Mobile, World.FindMobile(pvSrc.ReadInt32()));
PartyCommands.Handler.OnAccept(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
}
public static void PartyMessage_Decline(NetState state, PacketReader pvSrc)
{
if (PartyCommands.Handler != null)
PartyCommands.Handler.OnDecline(state.Mobile, World.FindMobile(pvSrc.ReadInt32()));
PartyCommands.Handler.OnDecline(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
}
public static void StunRequest(NetState state, PacketReader pvSrc)
@ -1875,7 +1867,7 @@ namespace Server.Network
if (menu != null && from == menu.From)
{
IEntity entity = World.FindEntity(pvSrc.ReadInt32());
IEntity entity = World.FindEntity(pvSrc.ReadUInt32());
if (entity != null && entity == menu.Target && from.CanSee(entity))
{
@ -1910,7 +1902,7 @@ namespace Server.Network
public static void ContextMenuRequest(NetState state, PacketReader pvSrc)
{
Mobile from = state.Mobile;
IEntity target = World.FindEntity(pvSrc.ReadInt32());
IEntity target = World.FindEntity(pvSrc.ReadUInt32());
if (from != null && target != null && from.Map == target.Map && from.CanSee(target))
{
@ -1941,7 +1933,7 @@ namespace Server.Network
public static void CloseStatus(NetState state, PacketReader pvSrc)
{
Serial serial = pvSrc.ReadInt32();
Serial serial = pvSrc.ReadUInt32();
}
public static void Language(NetState state, PacketReader pvSrc)
@ -1981,7 +1973,7 @@ namespace Server.Network
pvSrc.ReadInt32(); // 0xEDEDEDED
int type = pvSrc.ReadByte();
Mobile m = World.FindMobile(pvSrc.ReadInt32());
Mobile m = World.FindMobile(pvSrc.ReadUInt32());
if (m != null)
switch (type)

View file

@ -60,6 +60,7 @@ namespace Server.Network
}
catch
{
// ignored
}
}

View file

@ -298,7 +298,7 @@ namespace Server.Network
m_Stream.Write((short)list.Count);
//The client sorts these by their X/Y value.
//OSI sends these in wierd order. X/Y highest to lowest and serial loest to highest
//OSI sends these in weird order. X/Y highest to lowest and serial lowest to highest
//These are already sorted by serial (done by the vendor class) but we have to send them by x/y
//(the x74 packet is sent in 'correct' order.)
for (int i = list.Count - 1; i >= 0; --i)
@ -326,7 +326,7 @@ namespace Server.Network
m_Stream.Write((short)list.Count);
//The client sorts these by their X/Y value.
//OSI sends these in wierd order. X/Y highest to lowest and serial loest to highest
//OSI sends these in weird order. X/Y highest to lowest and serial loewst to highest
//These are already sorted by serial (done by the vendor class) but we have to send them by x/y
//(the x74 packet is sent in 'correct' order.)
for (int i = list.Count - 1; i >= 0; --i)
@ -1142,11 +1142,11 @@ namespace Server.Network
m_Stream.Write((byte)0);
/*} else if ( ) {
m_Stream.Write( (byte) 0x01 );
m_Stream.Write( (int) item.Serial );
m_Stream.Write( (short) itemID );
m_Stream.Write( (byte) item.Direction );*/
}
else
@ -1200,11 +1200,11 @@ namespace Server.Network
m_Stream.Write((byte)0);
/*} else if ( ) {
m_Stream.Write( (byte) 0x01 );
m_Stream.Write( (int) item.Serial );
m_Stream.Write( (ushort) itemID );
m_Stream.Write( (byte) item.Direction );*/
}
else
@ -2346,6 +2346,7 @@ namespace Server.Network
void AppendLayout(bool val);
void AppendLayout(int val);
void AppendLayout(uint val);
void AppendLayoutNS(int val);
void AppendLayout(string text);
void AppendLayout(byte[] buffer);
@ -2404,6 +2405,14 @@ namespace Server.Network
m_Layout.Write(m_Buffer, 0, bytes);
}
public void AppendLayout(uint val)
{
string toString = val.ToString();
int bytes = Encoding.ASCII.GetBytes(toString, 0, toString.Length, m_Buffer, 1) + 1;
m_Layout.Write(m_Buffer, 0, bytes);
}
public void AppendLayoutNS(int val)
{
string toString = val.ToString();
@ -2548,6 +2557,15 @@ namespace Server.Network
m_LayoutLength += bytes;
}
public void AppendLayout(uint val)
{
string toString = val.ToString();
int bytes = Encoding.ASCII.GetBytes(toString, 0, toString.Length, m_Buffer, 1) + 1;
m_Stream.Write(m_Buffer, 0, bytes);
m_LayoutLength += bytes;
}
public void AppendLayoutNS(int val)
{
string toString = val.ToString();
@ -3094,12 +3112,17 @@ namespace Server.Network
IWeapon weapon = m.Weapon;
int min = 0, max = 0;
weapon?.GetStatusDamage(m, out min, out max);
m_Stream.Write((short)min); // Damage min
m_Stream.Write((short)max); // Damage max
if (weapon != null)
{
weapon.GetStatusDamage(m, out int min, out int max);
m_Stream.Write((short)min); // Damage min
m_Stream.Write((short)max); // Damage max
}
else
{
m_Stream.Write((short)0); // Damage min
m_Stream.Write((short)0); // Damage max
}
m_Stream.Write(m.TithingPoints);
}
@ -3193,12 +3216,17 @@ namespace Server.Network
IWeapon weapon = beheld.Weapon;
int min = 0, max = 0;
weapon?.GetStatusDamage(beheld, out min, out max);
m_Stream.Write((short)min); // Damage min
m_Stream.Write((short)max); // Damage max
if (weapon != null)
{
weapon.GetStatusDamage(beheld, out int min, out int max);
m_Stream.Write((short)min); // Damage min
m_Stream.Write((short)max); // Damage max
}
else
{
m_Stream.Write((short)0); // Damage min
m_Stream.Write((short)0); // Damage max
}
m_Stream.Write(beheld.TithingPoints);
}
@ -3748,17 +3776,7 @@ namespace Server.Network
public sealed class MovementAck : Packet
{
private static MovementAck[][] m_Cache = new MovementAck[8][]
{
new MovementAck[256],
new MovementAck[256],
new MovementAck[256],
new MovementAck[256],
new MovementAck[256],
new MovementAck[256],
new MovementAck[256],
new MovementAck[256]
};
private static MovementAck[] m_Cache = new MovementAck[8 * 256];
private MovementAck(int seq, int noto) : base(0x22, 3)
{
@ -3770,11 +3788,11 @@ namespace Server.Network
{
int noto = Notoriety.Compute(m, m);
MovementAck p = m_Cache[noto][seq];
MovementAck p = m_Cache[noto * seq];
if (p == null)
{
m_Cache[noto][seq] = p = new MovementAck(seq, noto);
m_Cache[noto * seq] = p = new MovementAck(seq, noto);
p.SetStatic();
}
@ -4183,6 +4201,7 @@ namespace Server.Network
}
}
[Flags]
public enum AffixType : byte
{
Append = 0x00,
@ -4606,4 +4625,4 @@ namespace Server.Network
Warned = 0x10
}
}
}
}

View file

@ -35,7 +35,7 @@ namespace Server
protected override int BufferSize => 512;
public int CommitTo(SequentialFileWriter dataFile, SequentialFileWriter indexFile, int typeCode, int serial)
public int CommitTo(SequentialFileWriter dataFile, SequentialFileWriter indexFile, int typeCode, uint serial)
{
Flush();

View file

@ -81,7 +81,7 @@ namespace Server
WaitHandle.WaitAll(
Array.ConvertAll<Consumer, WaitHandle>(
consumers,
delegate(Consumer input) { return input.completionEvent; }
input => input.completionEvent
)
);

View file

@ -73,11 +73,6 @@ namespace Server
{
IndexInfo info = _orderedIndexInfo[i];
int typeCode = info.typeCode;
int serial = info.serial;
int length = info.size;
indexBuffer[0] = (byte)info.typeCode;
indexBuffer[1] = (byte)(info.typeCode >> 8);
indexBuffer[2] = (byte)(info.typeCode >> 16);
@ -115,7 +110,7 @@ namespace Server
{
public int size;
public int typeCode;
public int serial;
public uint serial;
}
}
}

View file

@ -65,17 +65,7 @@ namespace Server
public static Poison Parse(string value)
{
Poison p = null;
int plevel;
if (int.TryParse(value, out plevel))
p = GetPoison(plevel);
if (p == null)
p = GetPoison(value);
return p;
return (int.TryParse(value, out int plevel) ? GetPoison(plevel) : null) ?? GetPoison(value);
}
public static Poison GetPoison(int level)

View file

@ -398,6 +398,7 @@ namespace Server
return false;
}
// TODO: Memoize this
public bool IsChildOf(Region region)
{
if (region == null)
@ -415,6 +416,22 @@ namespace Server
return false;
}
// TODO: Memoize this
public T GetRegion<T>() where T : Region
{
Region r = this;
do
{
if (r is T tr)
return tr;
r = r.Parent;
} while (r != null);
return null;
}
public Region GetRegion(Type regionType)
{
@ -451,18 +468,15 @@ namespace Server
return null;
}
public bool IsPartOf<T>() where T : Region
{
return GetRegion<T>() != null;
}
public bool IsPartOf(Region region)
{
if (this == region)
return true;
return IsChildOf(region);
}
public bool IsPartOf(Type regionType)
{
return GetRegion(regionType) != null;
return this == region || IsChildOf(region);
}
public bool IsPartOf(string regionName)
@ -472,16 +486,7 @@ namespace Server
public virtual bool AcceptsSpawnsFrom(Region region)
{
if (!AllowSpawn())
return false;
if (region == this)
return true;
if (Parent != null)
return Parent.AcceptsSpawnsFrom(region);
return false;
return AllowSpawn() && (region == this || Parent?.AcceptsSpawnsFrom(region) == true);
}
public List<Mobile> GetPlayers()
@ -554,9 +559,7 @@ namespace Server
public override string ToString()
{
if (m_Name != null)
return m_Name;
return GetType().Name;
return m_Name ?? GetType().Name;
}
@ -596,18 +599,12 @@ namespace Server
public virtual Type GetResource(Type type)
{
if (Parent != null)
return Parent.GetResource(type);
return type;
return Parent != null ? Parent.GetResource(type) : type;
}
public virtual bool CanUseStuckMenu(Mobile m)
{
if (Parent != null)
return Parent.CanUseStuckMenu(m);
return true;
return Parent == null || Parent.CanUseStuckMenu(m);
}
public virtual void OnAggressed(Mobile aggressor, Mobile aggressed, bool criminal)
@ -632,61 +629,39 @@ namespace Server
public virtual bool OnTarget(Mobile m, Target t, object o)
{
if (Parent != null)
return Parent.OnTarget(m, t, o);
return true;
return Parent == null || Parent.OnTarget(m, t, o);
}
public virtual bool OnCombatantChange(Mobile m, Mobile Old, Mobile New)
{
if (Parent != null)
return Parent.OnCombatantChange(m, Old, New);
return true;
return Parent == null || Parent.OnCombatantChange(m, Old, New);
}
public virtual bool AllowHousing(Mobile from, Point3D p)
{
if (Parent != null)
return Parent.AllowHousing(from, p);
return true;
return Parent == null || Parent.AllowHousing(from, p);
}
public virtual bool SendInaccessibleMessage(Item item, Mobile from)
{
if (Parent != null)
return Parent.SendInaccessibleMessage(item, from);
return false;
return Parent != null && Parent.SendInaccessibleMessage(item, from);
}
public virtual bool CheckAccessibility(Item item, Mobile from)
{
if (Parent != null)
return Parent.CheckAccessibility(item, from);
return true;
return Parent == null || Parent.CheckAccessibility(item, from);
}
public virtual bool OnDecay(Item item)
{
if (Parent != null)
return Parent.OnDecay(item);
return true;
return Parent == null || Parent.OnDecay(item);
}
public virtual bool AllowHarmful(Mobile from, Mobile target)
{
if (Parent != null)
return Parent.AllowHarmful(from, target);
if (Mobile.AllowHarmfulHandler != null)
return Mobile.AllowHarmfulHandler(from, target);
return true;
return Parent?.AllowHarmful(from, target) == true ||
Mobile.AllowHarmfulHandler == null ||
Mobile.AllowHarmfulHandler(from, target);
}
public virtual void OnCriminalAction(Mobile m, bool message)
@ -699,13 +674,9 @@ namespace Server
public virtual bool AllowBeneficial(Mobile from, Mobile target)
{
if (Parent != null)
return Parent.AllowBeneficial(from, target);
if (Mobile.AllowBeneficialHandler != null)
return Mobile.AllowBeneficialHandler(from, target);
return true;
return Parent?.AllowBeneficial(from, target) == true ||
Mobile.AllowBeneficialHandler == null ||
Mobile.AllowBeneficialHandler(from, target);
}
public virtual void OnBeneficialAction(Mobile helper, Mobile target)
@ -730,18 +701,12 @@ namespace Server
public virtual bool OnSkillUse(Mobile m, int Skill)
{
if (Parent != null)
return Parent.OnSkillUse(m, Skill);
return true;
return Parent == null || Parent.OnSkillUse(m, Skill);
}
public virtual bool OnBeginSpellCast(Mobile m, ISpell s)
{
if (Parent != null)
return Parent.OnBeginSpellCast(m, s);
return true;
return Parent == null || Parent.OnBeginSpellCast(m, s);
}
public virtual void OnSpellCast(Mobile m, ISpell s)
@ -751,18 +716,12 @@ namespace Server
public virtual bool OnResurrect(Mobile m)
{
if (Parent != null)
return Parent.OnResurrect(m);
return true;
return Parent == null || Parent.OnResurrect(m);
}
public virtual bool OnBeforeDeath(Mobile m)
{
if (Parent != null)
return Parent.OnBeforeDeath(m);
return true;
return Parent == null || Parent.OnBeforeDeath(m);
}
public virtual void OnDeath(Mobile m)
@ -772,42 +731,27 @@ namespace Server
public virtual bool OnDamage(Mobile m, ref int Damage)
{
if (Parent != null)
return Parent.OnDamage(m, ref Damage);
return true;
return Parent == null || Parent.OnDamage(m, ref Damage);
}
public virtual bool OnHeal(Mobile m, ref int Heal)
{
if (Parent != null)
return Parent.OnHeal(m, ref Heal);
return true;
return Parent == null || Parent.OnHeal(m, ref Heal);
}
public virtual bool OnDoubleClick(Mobile m, object o)
{
if (Parent != null)
return Parent.OnDoubleClick(m, o);
return true;
return Parent == null || Parent.OnDoubleClick(m, o);
}
public virtual bool OnSingleClick(Mobile m, object o)
{
if (Parent != null)
return Parent.OnSingleClick(m, o);
return true;
return Parent == null || Parent.OnSingleClick(m, o);
}
public virtual bool AllowSpawn()
{
if (Parent != null)
return Parent.AllowSpawn();
return true;
return Parent == null || Parent.AllowSpawn();
}
public virtual void AlterLightLevel(Mobile m, ref int global, ref int personal)
@ -863,14 +807,14 @@ namespace Server
if (oldRChild >= newRChild)
{
oldR.OnExit(m);
oldR = oldR.Parent;
oldR?.OnExit(m);
oldR = oldR?.Parent;
}
if (newRChild >= oldRChild)
{
newR.OnEnter(m);
newR = newR.Parent;
newR?.OnEnter(m);
newR = newR?.Parent;
}
}
}
@ -892,19 +836,22 @@ namespace Server
XmlElement root = doc["ServerRegions"];
if (root == null)
{
Console.WriteLine("Could not find root element 'ServerRegions' in Regions.xml");
else
foreach (XmlElement facet in root.SelectNodes("Facet"))
return;
}
foreach (XmlElement facet in root.SelectNodes("Facet"))
{
Map map = null;
if (ReadMap(facet, "name", ref map))
{
Map map = null;
if (ReadMap(facet, "name", ref map))
{
if (map == Map.Internal)
Console.WriteLine("Invalid internal map in a facet element");
else
LoadRegions(facet, map, null);
}
if (map == Map.Internal)
Console.WriteLine("Invalid internal map in a facet element");
else
LoadRegions(facet, map, null);
}
}
Console.WriteLine("done");
}
@ -1088,9 +1035,7 @@ namespace Server
Type type = typeof(T);
T tempVal;
if (type.IsEnum && Enum.TryParse(s, true, out tempVal))
if (type.IsEnum && Enum.TryParse(s, true, out T tempVal))
{
value = tempVal;
return true;

View file

@ -127,17 +127,7 @@ namespace Server
}
}
public static bool CompileCSScripts(out Assembly assembly)
{
return CompileCSScripts(false, true, out assembly);
}
public static bool CompileCSScripts(bool debug, out Assembly assembly)
{
return CompileCSScripts(debug, true, out assembly);
}
public static bool CompileCSScripts(bool debug, bool cache, out Assembly assembly)
public static bool CompileCSScripts(out Assembly assembly, bool cache = true, bool debug = false)
{
Console.Write("Scripts: Compiling C# scripts...");
string[] files = GetScripts("*.cs");
@ -190,6 +180,7 @@ namespace Server
}
catch
{
// ignored
}
DeleteFiles("Scripts.CS*.dll");
@ -252,6 +243,7 @@ namespace Server
}
catch
{
// ignored
}
assembly = results.CompiledAssembly;
@ -259,17 +251,7 @@ namespace Server
}
}
public static bool CompileVBScripts(out Assembly assembly)
{
return CompileVBScripts(false, out assembly);
}
public static bool CompileVBScripts(bool debug, out Assembly assembly)
{
return CompileVBScripts(debug, true, out assembly);
}
public static bool CompileVBScripts(bool debug, bool cache, out Assembly assembly)
public static bool CompileVBScripts(out Assembly assembly, bool cache = true, bool debug = false)
{
Console.Write("Scripts: Compiling VB.NET scripts...");
string[] files = GetScripts("*.vb");
@ -323,6 +305,7 @@ namespace Server
}
catch
{
// ignored
}
}
@ -540,11 +523,10 @@ namespace Server
List<Assembly> assemblies = new List<Assembly>();
Assembly assembly;
if (CompileCSScripts(debug, cache, out assembly))
if (CompileCSScripts(out Assembly assembly, cache, debug))
{
if (assembly != null) assemblies.Add(assembly);
if (assembly != null)
assemblies.Add(assembly);
}
else
{
@ -553,9 +535,10 @@ namespace Server
if (Core.VBdotNet)
{
if (CompileVBScripts(debug, cache, out assembly))
if (CompileVBScripts(out Assembly vbAssembly, cache, debug))
{
if (assembly != null) assemblies.Add(assembly);
if (vbAssembly != null)
assemblies.Add(vbAssembly);
}
else
{
@ -567,7 +550,8 @@ namespace Server
Console.WriteLine("Scripts: Skipping VB.NET Scripts...done (use -vb to enable)");
}
if (assemblies.Count == 0) return false;
if (assemblies.Count == 0)
return false;
Assemblies = assemblies.ToArray();
@ -618,8 +602,7 @@ namespace Server
return m_NullCache;
}
TypeCache c = null;
m_TypeCaches.TryGetValue(asm, out c);
m_TypeCaches.TryGetValue(asm, out TypeCache c);
if (c == null)
m_TypeCaches[asm] = c = new TypeCache(asm);
@ -758,7 +741,7 @@ namespace Server
public Type Get(string key, bool ignoreCase)
{
Type t = null;
Type t;
if (ignoreCase)
m_Insensitive.TryGetValue(key, out t);

View file

@ -22,9 +22,9 @@ using System;
namespace Server
{
public struct Serial : IComparable, IComparable<Serial>
public struct Serial : IComparable, IComparable<Serial>, IComparable<uint>
{
public static readonly Serial MinusOne = new Serial(-1);
public static readonly Serial MinusOne = new Serial(0xFFFFFFFF);
public static readonly Serial Zero = new Serial(0);
public static Serial LastMobile{ get; private set; } = Zero;
@ -55,46 +55,52 @@ namespace Server
}
}
private Serial(int serial)
private Serial(uint serial)
{
Value = serial;
}
public int Value{ get; }
public uint Value{ get; }
public bool IsMobile => Value > 0 && Value < 0x40000000;
public bool IsItem => Value >= 0x40000000 && Value <= 0x7FFFFFFF;
public bool IsItem => Value >= 0x40000000 && Value < 0x80000000;
public bool IsValid => Value > 0;
public override int GetHashCode()
{
return Value;
return Value.GetHashCode();
}
public int CompareTo(Serial other)
{
return Value.CompareTo(other.Value);
}
public int CompareTo(object other)
public int CompareTo(object obj)
{
if (other is Serial serial)
return CompareTo(serial);
if (other == null)
return -1;
throw new ArgumentException();
return Value.CompareTo(obj);
}
public override bool Equals(object o)
public int CompareTo(uint other)
{
if (!(o is Serial serial))
return false;
return Value.CompareTo(other);
}
return serial.Value == Value;
public override bool Equals(object obj)
{
if (obj is Serial serial)
{
return this == serial;
}
if (obj is uint u)
{
return Value == u;
}
return false;
}
public static bool operator ==(Serial l, Serial r)
@ -127,22 +133,17 @@ namespace Server
return l.Value <= r.Value;
}
/*public static Serial operator ++ ( Serial l )
{
return new Serial( l + 1 );
}*/
public override string ToString()
{
return $"0x{Value:X8}";
}
public static implicit operator int(Serial a)
public static implicit operator uint(Serial a)
{
return a.Value;
}
public static implicit operator Serial(int a)
public static implicit operator Serial(uint a)
{
return new Serial(a);
}

View file

@ -67,10 +67,6 @@ namespace Server
public abstract T ReadMobile<T>() where T : Mobile;
public abstract T ReadGuild<T>() where T : BaseGuild;
public abstract ArrayList ReadItemList();
public abstract ArrayList ReadMobileList();
public abstract ArrayList ReadGuildList();
public abstract List<Item> ReadStrongItemList();
public abstract List<T> ReadStrongItemList<T>() where T : Item;
@ -139,15 +135,6 @@ namespace Server
public abstract void Write(Race value);
public abstract void WriteItemList(ArrayList list);
public abstract void WriteItemList(ArrayList list, bool tidy);
public abstract void WriteMobileList(ArrayList list);
public abstract void WriteMobileList(ArrayList list, bool tidy);
public abstract void WriteGuildList(ArrayList list);
public abstract void WriteGuildList(ArrayList list, bool tidy);
public abstract void Write(List<Item> list);
public abstract void Write(List<Item> list, bool tidy);
@ -370,8 +357,7 @@ namespace Server
}
catch
{
if (ticks < now) d = TimeSpan.MaxValue;
else d = TimeSpan.MaxValue;
d = TimeSpan.MaxValue;
}
Write(d);
@ -476,18 +462,12 @@ namespace Server
if (m_Index + 8 > m_Buffer.Length)
Flush();
#if MONO
byte[] bytes = BitConverter.GetBytes(value);
for(int i = 0; i < bytes.Length; i++)
m_Buffer[m_Index++] = bytes[i];
#else
fixed (byte* pBuffer = m_Buffer)
{
*(double*)(pBuffer + m_Index) = value;
}
m_Index += 8;
#endif
}
public override unsafe void Write(float value)
@ -495,18 +475,12 @@ namespace Server
if (m_Index + 4 > m_Buffer.Length)
Flush();
#if MONO
byte[] bytes = BitConverter.GetBytes(value);
for(int i = 0; i < bytes.Length; i++)
m_Buffer[m_Index++] = bytes[i];
#else
fixed (byte* pBuffer = m_Buffer)
{
*(float*)(pBuffer + m_Index) = value;
}
m_Index += 4;
#endif
}
public override void Write(char value)
@ -632,66 +606,6 @@ namespace Server
Write(value);
}
public override void WriteMobileList(ArrayList list)
{
WriteMobileList(list, false);
}
public override void WriteMobileList(ArrayList list, bool tidy)
{
if (tidy)
for (int i = 0; i < list.Count;)
if (((Mobile)list[i]).Deleted)
list.RemoveAt(i);
else
++i;
Write(list.Count);
for (int i = 0; i < list.Count; ++i)
Write((Mobile)list[i]);
}
public override void WriteItemList(ArrayList list)
{
WriteItemList(list, false);
}
public override void WriteItemList(ArrayList list, bool tidy)
{
if (tidy)
for (int i = 0; i < list.Count;)
if (((Item)list[i]).Deleted)
list.RemoveAt(i);
else
++i;
Write(list.Count);
for (int i = 0; i < list.Count; ++i)
Write((Item)list[i]);
}
public override void WriteGuildList(ArrayList list)
{
WriteGuildList(list, false);
}
public override void WriteGuildList(ArrayList list, bool tidy)
{
if (tidy)
for (int i = 0; i < list.Count;)
if (((BaseGuild)list[i]).Disbanded)
list.RemoveAt(i);
else
++i;
Write(list.Count);
for (int i = 0; i < list.Count; ++i)
Write((BaseGuild)list[i]);
}
public override void Write(List<Item> list)
{
Write(list, false);
@ -757,7 +671,7 @@ namespace Server
Write(set.Count);
foreach (Item item in set) Write(item);
foreach (T item in set) Write(item);
}
public override void Write(List<Mobile> list)
@ -825,7 +739,7 @@ namespace Server
Write(set.Count);
foreach (Mobile mob in set) Write(mob);
foreach (T mob in set) Write(mob);
}
public override void Write(List<BaseGuild> list)
@ -893,7 +807,7 @@ namespace Server
Write(set.Count);
foreach (BaseGuild guild in set) Write(guild);
foreach (T guild in set) Write(guild);
}
}
@ -920,9 +834,7 @@ namespace Server
public override string ReadString()
{
if (ReadByte() != 0)
return m_File.ReadString();
return null;
return ReadByte() != 0 ? m_File.ReadString() : null;
}
public override DateTime ReadDeltaTime()
@ -1076,7 +988,7 @@ namespace Server
public override IEntity ReadEntity()
{
Serial serial = ReadInt();
Serial serial = ReadUInt();
IEntity entity = World.FindEntity(serial);
if (entity == null)
return new Entity(serial, new Point3D(0, 0, 0), Map.Internal);
@ -1085,17 +997,17 @@ namespace Server
public override Item ReadItem()
{
return World.FindItem(ReadInt());
return World.FindItem(ReadUInt());
}
public override Mobile ReadMobile()
{
return World.FindMobile(ReadInt());
return World.FindMobile(ReadUInt());
}
public override BaseGuild ReadGuild()
{
return BaseGuild.Find(ReadInt());
return BaseGuild.Find(ReadUInt());
}
public override T ReadItem<T>()
@ -1113,69 +1025,6 @@ namespace Server
return ReadGuild() as T;
}
public override ArrayList ReadItemList()
{
int count = ReadInt();
if (count > 0)
{
ArrayList list = new ArrayList(count);
for (int i = 0; i < count; ++i)
{
Item item = ReadItem();
if (item != null) list.Add(item);
}
return list;
}
return new ArrayList();
}
public override ArrayList ReadMobileList()
{
int count = ReadInt();
if (count > 0)
{
ArrayList list = new ArrayList(count);
for (int i = 0; i < count; ++i)
{
Mobile m = ReadMobile();
if (m != null) list.Add(m);
}
return list;
}
return new ArrayList();
}
public override ArrayList ReadGuildList()
{
int count = ReadInt();
if (count > 0)
{
ArrayList list = new ArrayList(count);
for (int i = 0; i < count; ++i)
{
BaseGuild g = ReadGuild();
if (g != null) list.Add(g);
}
return list;
}
return new ArrayList();
}
public override List<Item> ReadStrongItemList()
{
return ReadStrongItemList<Item>();
@ -1384,10 +1233,9 @@ namespace Server
m_WriteQueue.Enqueue(mem);
}
if (m_WorkerThread == null || !m_WorkerThread.IsAlive)
if (m_WorkerThread.IsAlive != true)
{
m_WorkerThread = new Thread(new WorkerThread(this).Worker);
m_WorkerThread.Priority = ThreadPriority.BelowNormal;
m_WorkerThread = new Thread(new WorkerThread(this).Worker) { Priority = ThreadPriority.BelowNormal };
m_WorkerThread.Start();
}
}
@ -1453,8 +1301,7 @@ namespace Server
}
catch
{
if (ticks < now) d = TimeSpan.MaxValue;
else d = TimeSpan.MaxValue;
d = TimeSpan.MaxValue;
}
Write(d);
@ -1659,66 +1506,6 @@ namespace Server
Write(value);
}
public override void WriteMobileList(ArrayList list)
{
WriteMobileList(list, false);
}
public override void WriteMobileList(ArrayList list, bool tidy)
{
if (tidy)
for (int i = 0; i < list.Count;)
if (((Mobile)list[i]).Deleted)
list.RemoveAt(i);
else
++i;
Write(list.Count);
for (int i = 0; i < list.Count; ++i)
Write((Mobile)list[i]);
}
public override void WriteItemList(ArrayList list)
{
WriteItemList(list, false);
}
public override void WriteItemList(ArrayList list, bool tidy)
{
if (tidy)
for (int i = 0; i < list.Count;)
if (((Item)list[i]).Deleted)
list.RemoveAt(i);
else
++i;
Write(list.Count);
for (int i = 0; i < list.Count; ++i)
Write((Item)list[i]);
}
public override void WriteGuildList(ArrayList list)
{
WriteGuildList(list, false);
}
public override void WriteGuildList(ArrayList list, bool tidy)
{
if (tidy)
for (int i = 0; i < list.Count;)
if (((BaseGuild)list[i]).Disbanded)
list.RemoveAt(i);
else
++i;
Write(list.Count);
for (int i = 0; i < list.Count; ++i)
Write((BaseGuild)list[i]);
}
public override void Write(List<Item> list)
{
Write(list, false);
@ -1784,7 +1571,7 @@ namespace Server
Write(set.Count);
foreach (Item item in set) Write(item);
foreach (T item in set) Write(item);
}
public override void Write(List<Mobile> list)
@ -1852,7 +1639,7 @@ namespace Server
Write(set.Count);
foreach (Mobile mob in set) Write(mob);
foreach (T mob in set) Write(mob);
}
public override void Write(List<BaseGuild> list)
@ -1920,7 +1707,7 @@ namespace Server
Write(set.Count);
foreach (BaseGuild guild in set) Write(guild);
foreach (T guild in set) Write(guild);
}
private class WorkerThread
@ -1936,7 +1723,7 @@ namespace Server
{
ThreadCount++;
int lastCount = 0;
int lastCount;
do
{
@ -1966,7 +1753,7 @@ namespace Server
public interface ISerializable
{
int TypeReference{ get; }
int SerialIdentity{ get; }
uint SerialIdentity{ get; }
void Serialize(GenericWriter writer);
}
}
}

View file

@ -424,8 +424,7 @@ namespace Server
public double GainFactor{ get; set; }
public static SkillInfo[] Table{ get; set; } = new SkillInfo[58]
{
public static SkillInfo[] Table{ get; set; } = {
new SkillInfo(0, "Alchemy", 0.0, 5.0, 5.0, "Alchemist", null, 0.0, 0.5, 0.5, 1.0),
new SkillInfo(1, "Anatomy", 0.0, 0.0, 0.0, "Biologist", null, 0.15, 0.15, 0.7, 1.0),
new SkillInfo(2, "Animal Lore", 0.0, 0.0, 0.0, "Naturalist", null, 0.0, 0.0, 1.0, 1.0),
@ -548,6 +547,7 @@ namespace Server
}
else
{
// Will be discarded
new Skill(this, null, reader);
}
@ -710,419 +710,184 @@ namespace Server
m_Highest = skill;
Owner.OnSkillInvalidated(skill);
NetState ns = Owner.NetState;
ns?.Send(new SkillChange(skill));
Owner.NetState?.Send(new SkillChange(skill));
}
#region Skill Getters & Setters
[CommandProperty(AccessLevel.Counselor)]
public Skill Alchemy
{
get => this[SkillName.Alchemy];
set { }
}
public Skill Alchemy => this[SkillName.Alchemy];
[CommandProperty(AccessLevel.Counselor)]
public Skill Anatomy
{
get => this[SkillName.Anatomy];
set { }
}
public Skill Anatomy => this[SkillName.Anatomy];
[CommandProperty(AccessLevel.Counselor)]
public Skill AnimalLore
{
get => this[SkillName.AnimalLore];
set { }
}
public Skill AnimalLore => this[SkillName.AnimalLore];
[CommandProperty(AccessLevel.Counselor)]
public Skill ItemID
{
get => this[SkillName.ItemID];
set { }
}
public Skill ItemID => this[SkillName.ItemID];
[CommandProperty(AccessLevel.Counselor)]
public Skill ArmsLore
{
get => this[SkillName.ArmsLore];
set { }
}
public Skill ArmsLore => this[SkillName.ArmsLore];
[CommandProperty(AccessLevel.Counselor)]
public Skill Parry
{
get => this[SkillName.Parry];
set { }
}
public Skill Parry => this[SkillName.Parry];
[CommandProperty(AccessLevel.Counselor)]
public Skill Begging
{
get => this[SkillName.Begging];
set { }
}
public Skill Begging => this[SkillName.Begging];
[CommandProperty(AccessLevel.Counselor)]
public Skill Blacksmith
{
get => this[SkillName.Blacksmith];
set { }
}
public Skill Blacksmith => this[SkillName.Blacksmith];
[CommandProperty(AccessLevel.Counselor)]
public Skill Fletching
{
get => this[SkillName.Fletching];
set { }
}
public Skill Fletching => this[SkillName.Fletching];
[CommandProperty(AccessLevel.Counselor)]
public Skill Peacemaking
{
get => this[SkillName.Peacemaking];
set { }
}
public Skill Peacemaking => this[SkillName.Peacemaking];
[CommandProperty(AccessLevel.Counselor)]
public Skill Camping
{
get => this[SkillName.Camping];
set { }
}
public Skill Camping => this[SkillName.Camping];
[CommandProperty(AccessLevel.Counselor)]
public Skill Carpentry
{
get => this[SkillName.Carpentry];
set { }
}
public Skill Carpentry => this[SkillName.Carpentry];
[CommandProperty(AccessLevel.Counselor)]
public Skill Cartography
{
get => this[SkillName.Cartography];
set { }
}
public Skill Cartography => this[SkillName.Cartography];
[CommandProperty(AccessLevel.Counselor)]
public Skill Cooking
{
get => this[SkillName.Cooking];
set { }
}
public Skill Cooking => this[SkillName.Cooking];
[CommandProperty(AccessLevel.Counselor)]
public Skill DetectHidden
{
get => this[SkillName.DetectHidden];
set { }
}
public Skill DetectHidden => this[SkillName.DetectHidden];
[CommandProperty(AccessLevel.Counselor)]
public Skill Discordance
{
get => this[SkillName.Discordance];
set { }
}
public Skill Discordance => this[SkillName.Discordance];
[CommandProperty(AccessLevel.Counselor)]
public Skill EvalInt
{
get => this[SkillName.EvalInt];
set { }
}
public Skill EvalInt => this[SkillName.EvalInt];
[CommandProperty(AccessLevel.Counselor)]
public Skill Healing
{
get => this[SkillName.Healing];
set { }
}
public Skill Healing => this[SkillName.Healing];
[CommandProperty(AccessLevel.Counselor)]
public Skill Fishing
{
get => this[SkillName.Fishing];
set { }
}
public Skill Fishing => this[SkillName.Fishing];
[CommandProperty(AccessLevel.Counselor)]
public Skill Forensics
{
get => this[SkillName.Forensics];
set { }
}
public Skill Forensics => this[SkillName.Forensics];
[CommandProperty(AccessLevel.Counselor)]
public Skill Herding
{
get => this[SkillName.Herding];
set { }
}
public Skill Herding => this[SkillName.Herding];
[CommandProperty(AccessLevel.Counselor)]
public Skill Hiding
{
get => this[SkillName.Hiding];
set { }
}
public Skill Hiding => this[SkillName.Hiding];
[CommandProperty(AccessLevel.Counselor)]
public Skill Provocation
{
get => this[SkillName.Provocation];
set { }
}
public Skill Provocation => this[SkillName.Provocation];
[CommandProperty(AccessLevel.Counselor)]
public Skill Inscribe
{
get => this[SkillName.Inscribe];
set { }
}
public Skill Inscribe => this[SkillName.Inscribe];
[CommandProperty(AccessLevel.Counselor)]
public Skill Lockpicking
{
get => this[SkillName.Lockpicking];
set { }
}
public Skill Lockpicking => this[SkillName.Lockpicking];
[CommandProperty(AccessLevel.Counselor)]
public Skill Magery
{
get => this[SkillName.Magery];
set { }
}
public Skill Magery => this[SkillName.Magery];
[CommandProperty(AccessLevel.Counselor)]
public Skill MagicResist
{
get => this[SkillName.MagicResist];
set { }
}
public Skill MagicResist => this[SkillName.MagicResist];
[CommandProperty(AccessLevel.Counselor)]
public Skill Tactics
{
get => this[SkillName.Tactics];
set { }
}
public Skill Tactics => this[SkillName.Tactics];
[CommandProperty(AccessLevel.Counselor)]
public Skill Snooping
{
get => this[SkillName.Snooping];
set { }
}
public Skill Snooping => this[SkillName.Snooping];
[CommandProperty(AccessLevel.Counselor)]
public Skill Musicianship
{
get => this[SkillName.Musicianship];
set { }
}
public Skill Musicianship => this[SkillName.Musicianship];
[CommandProperty(AccessLevel.Counselor)]
public Skill Poisoning
{
get => this[SkillName.Poisoning];
set { }
}
public Skill Poisoning => this[SkillName.Poisoning];
[CommandProperty(AccessLevel.Counselor)]
public Skill Archery
{
get => this[SkillName.Archery];
set { }
}
public Skill Archery => this[SkillName.Archery];
[CommandProperty(AccessLevel.Counselor)]
public Skill SpiritSpeak
{
get => this[SkillName.SpiritSpeak];
set { }
}
public Skill SpiritSpeak => this[SkillName.SpiritSpeak];
[CommandProperty(AccessLevel.Counselor)]
public Skill Stealing
{
get => this[SkillName.Stealing];
set { }
}
public Skill Stealing => this[SkillName.Stealing];
[CommandProperty(AccessLevel.Counselor)]
public Skill Tailoring
{
get => this[SkillName.Tailoring];
set { }
}
public Skill Tailoring => this[SkillName.Tailoring];
[CommandProperty(AccessLevel.Counselor)]
public Skill AnimalTaming
{
get => this[SkillName.AnimalTaming];
set { }
}
public Skill AnimalTaming => this[SkillName.AnimalTaming];
[CommandProperty(AccessLevel.Counselor)]
public Skill TasteID
{
get => this[SkillName.TasteID];
set { }
}
public Skill TasteID => this[SkillName.TasteID];
[CommandProperty(AccessLevel.Counselor)]
public Skill Tinkering
{
get => this[SkillName.Tinkering];
set { }
}
public Skill Tinkering => this[SkillName.Tinkering];
[CommandProperty(AccessLevel.Counselor)]
public Skill Tracking
{
get => this[SkillName.Tracking];
set { }
}
public Skill Tracking => this[SkillName.Tracking];
[CommandProperty(AccessLevel.Counselor)]
public Skill Veterinary
{
get => this[SkillName.Veterinary];
set { }
}
public Skill Veterinary => this[SkillName.Veterinary];
[CommandProperty(AccessLevel.Counselor)]
public Skill Swords
{
get => this[SkillName.Swords];
set { }
}
public Skill Swords => this[SkillName.Swords];
[CommandProperty(AccessLevel.Counselor)]
public Skill Macing
{
get => this[SkillName.Macing];
set { }
}
public Skill Macing => this[SkillName.Macing];
[CommandProperty(AccessLevel.Counselor)]
public Skill Fencing
{
get => this[SkillName.Fencing];
set { }
}
public Skill Fencing => this[SkillName.Fencing];
[CommandProperty(AccessLevel.Counselor)]
public Skill Wrestling
{
get => this[SkillName.Wrestling];
set { }
}
public Skill Wrestling => this[SkillName.Wrestling];
[CommandProperty(AccessLevel.Counselor)]
public Skill Lumberjacking
{
get => this[SkillName.Lumberjacking];
set { }
}
public Skill Lumberjacking => this[SkillName.Lumberjacking];
[CommandProperty(AccessLevel.Counselor)]
public Skill Mining
{
get => this[SkillName.Mining];
set { }
}
public Skill Mining => this[SkillName.Mining];
[CommandProperty(AccessLevel.Counselor)]
public Skill Meditation
{
get => this[SkillName.Meditation];
set { }
}
public Skill Meditation => this[SkillName.Meditation];
[CommandProperty(AccessLevel.Counselor)]
public Skill Stealth
{
get => this[SkillName.Stealth];
set { }
}
public Skill Stealth => this[SkillName.Stealth];
[CommandProperty(AccessLevel.Counselor)]
public Skill RemoveTrap
{
get => this[SkillName.RemoveTrap];
set { }
}
public Skill RemoveTrap => this[SkillName.RemoveTrap];
[CommandProperty(AccessLevel.Counselor)]
public Skill Necromancy
{
get => this[SkillName.Necromancy];
set { }
}
public Skill Necromancy => this[SkillName.Necromancy];
[CommandProperty(AccessLevel.Counselor)]
public Skill Focus
{
get => this[SkillName.Focus];
set { }
}
public Skill Focus => this[SkillName.Focus];
[CommandProperty(AccessLevel.Counselor)]
public Skill Chivalry
{
get => this[SkillName.Chivalry];
set { }
}
public Skill Chivalry => this[SkillName.Chivalry];
[CommandProperty(AccessLevel.Counselor)]
public Skill Bushido
{
get => this[SkillName.Bushido];
set { }
}
public Skill Bushido => this[SkillName.Bushido];
[CommandProperty(AccessLevel.Counselor)]
public Skill Ninjitsu
{
get => this[SkillName.Ninjitsu];
set { }
}
public Skill Ninjitsu => this[SkillName.Ninjitsu];
[CommandProperty(AccessLevel.Counselor)]
public Skill Spellweaving
{
get => this[SkillName.Spellweaving];
set { }
}
public Skill Spellweaving => this[SkillName.Spellweaving];
[CommandProperty(AccessLevel.Counselor)]
public Skill Mysticism
{
get => this[SkillName.Mysticism];
set { }
}
public Skill Mysticism => this[SkillName.Mysticism];
[CommandProperty(AccessLevel.Counselor)]
public Skill Imbuing
{
get => this[SkillName.Imbuing];
set { }
}
public Skill Imbuing => this[SkillName.Imbuing];
[CommandProperty(AccessLevel.Counselor)]
public Skill Throwing
{
get => this[SkillName.Throwing];
set { }
}
public Skill Throwing => this[SkillName.Throwing];
#endregion
}

View file

@ -39,8 +39,6 @@ namespace Server.Targeting
CheckLOS = true;
}
public static bool TargetIDValidation{ get; set; } = true;
public DateTime TimeoutTime{ get; private set; }
public bool CheckLOS{ get; set; }
@ -59,13 +57,8 @@ namespace Server.Targeting
public static void Cancel(Mobile m)
{
NetState ns = m.NetState;
ns?.Send(CancelTarget.Instance);
Target targ = m.Target;
targ?.OnTargetCancel(m, TargetCancelType.Canceled);
m.NetState?.Send(CancelTarget.Instance);
m.Target?.OnTargetCancel(m, TargetCancelType.Canceled);
}
public void BeginTimeout(Mobile from, TimeSpan delay)
@ -81,7 +74,6 @@ namespace Server.Targeting
public void CancelTimeout()
{
m_TimeoutTimer?.Stop();
m_TimeoutTimer = null;
}
@ -204,11 +196,11 @@ namespace Server.Targeting
OnTargetOutOfLOS(from, targeted);
else if (item?.InSecureTrade == true)
OnTargetInSecureTrade(from, targeted);
else if (item?.IsAccessibleTo(from) == true)
else if (item?.IsAccessibleTo(from) == false)
OnTargetNotAccessible(from, targeted);
else if (item?.CheckTarget(from, this, targeted) == true)
else if (item?.CheckTarget(from, this, targeted) == false)
OnTargetUntargetable(from, targeted);
else if (mobile?.CheckTarget(from, this, mobile) != true)
else if (mobile?.CheckTarget(from, this, mobile) == false)
OnTargetUntargetable(from, mobile);
else if (from.Region.OnTarget(from, this, targeted))
OnTarget(from, targeted);

View file

@ -18,8 +18,11 @@
*
***************************************************************************/
using System;
namespace Server.Targeting
{
[Flags]
public enum TargetFlags : byte
{
None = 0x00,

View file

@ -713,6 +713,12 @@ namespace Server
public int Compare(UOPEntry x, UOPEntry y)
{
if (x == null)
return y == null ? 0 : 1;
if (y == null)
return -1;
return x.m_Offset.CompareTo(y.m_Offset);
}
}

View file

@ -40,9 +40,7 @@ namespace Server
public delegate void TimerCallback();
public delegate void TimerStateCallback(object state);
public delegate void TimerStateCallback<T>(T state);
public delegate void TimerStateCallback<in T>(T state);
public class Timer
{
@ -293,8 +291,7 @@ namespace Server
string key = t.ToString();
List<Timer> list;
hash.TryGetValue(key, out list);
hash.TryGetValue(key, out List<Timer> list);
if (list == null)
hash[key] = list = new List<Timer>();
@ -517,36 +514,6 @@ namespace Server
return t;
}
public static Timer DelayCall(TimerStateCallback callback, object state)
{
return DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, state);
}
public static Timer DelayCall(TimeSpan delay, TimerStateCallback callback, object state)
{
return DelayCall(delay, TimeSpan.Zero, 1, callback, state);
}
public static Timer DelayCall(TimeSpan delay, TimeSpan interval, TimerStateCallback callback, object state)
{
return DelayCall(delay, interval, 0, callback, state);
}
public static Timer DelayCall(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback,
object state)
{
Timer t = new DelayStateCallTimer(delay, interval, count, callback, state);
if (count == 1)
t.Priority = ComputePriority(delay);
else
t.Priority = ComputePriority(interval);
t.Start();
return t;
}
#endregion
#region DelayCall<T>(..)
@ -571,10 +538,7 @@ namespace Server
{
Timer t = new DelayStateCallTimer<T>(delay, interval, count, callback, state);
if (count == 1)
t.Priority = ComputePriority(delay);
else
t.Priority = ComputePriority(interval);
t.Priority = ComputePriority(count == 1 ? delay : interval);
t.Start();
@ -609,34 +573,6 @@ namespace Server
}
}
private class DelayStateCallTimer : Timer
{
private object m_State;
public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback,
object state) : base(delay, interval, count)
{
Callback = callback;
m_State = state;
RegCreation();
}
public TimerStateCallback Callback{ get; }
public override bool DefRegCreation => false;
protected override void OnTick()
{
Callback?.Invoke(m_State);
}
public override string ToString()
{
return $"DelayStateCall[{FormatDelegate(Callback)}]";
}
}
private class DelayStateCallTimer<T> : Timer
{
private T m_State;

View file

@ -166,11 +166,10 @@ namespace Server
public static IPAddress Intern(IPAddress ipAddress)
{
if (_ipAddressTable == null) _ipAddressTable = new Dictionary<IPAddress, IPAddress>();
if (_ipAddressTable == null)
_ipAddressTable = new Dictionary<IPAddress, IPAddress>();
IPAddress interned;
if (!_ipAddressTable.TryGetValue(ipAddress, out interned))
if (!_ipAddressTable.TryGetValue(ipAddress, out IPAddress interned))
{
interned = ipAddress;
_ipAddressTable[ipAddress] = interned;
@ -186,18 +185,14 @@ namespace Server
public static bool IsValidIP(string text)
{
bool valid = true;
IPMatch(text, IPAddress.None, ref valid);
IPMatch(text, IPAddress.None, out bool valid);
return valid;
}
public static bool IPMatch(string val, IPAddress ip)
{
bool valid = true;
return IPMatch(val, ip, ref valid);
return IPMatch(val, ip, out _);
}
public static string FixHtml(string str)
@ -428,7 +423,7 @@ namespace Server
return false;
}
public static bool IPMatch(string val, IPAddress ip, ref bool valid)
public static bool IPMatch(string val, IPAddress ip, out bool valid)
{
valid = true;
@ -698,17 +693,6 @@ namespace Server
}
}
public static ArrayList BuildArrayList(IEnumerable enumerable)
{
IEnumerator e = enumerable.GetEnumerator();
ArrayList list = new ArrayList();
while (e.MoveNext()) list.Add(e.Current);
return list;
}
public static bool RangeCheck(IPoint2D p1, IPoint2D p2, int range)
{
return p1.X >= p2.X - range
@ -800,6 +784,7 @@ namespace Server
}
catch
{
// ignored
}
}
@ -811,6 +796,7 @@ namespace Server
}
catch
{
// ignored
}
}
@ -864,9 +850,14 @@ namespace Server
m.FacialHairHue = m.Race.RandomHairHue();
}
public static List<TOutput> CastConvertList<TInput, TOutput>(List<TInput> list) where TOutput : TInput
public static List<TOutput> CastListContravariant<TInput, TOutput>(List<TInput> list) where TInput : TOutput
{
return list.ConvertAll(delegate(TInput value) { return (TOutput)value; });
return list.ConvertAll(value => (TOutput)value);
}
public static List<TOutput> CastListCovariant<TInput, TOutput>(List<TInput> list) where TOutput : TInput
{
return list.ConvertAll(value => (TOutput)value);
}
public static List<TOutput> SafeConvertList<TInput, TOutput>(List<TInput> list) where TOutput : class
@ -888,24 +879,21 @@ namespace Server
public static bool ToBoolean(string value)
{
bool b;
bool.TryParse(value, out b);
bool.TryParse(value, out bool b);
return b;
}
public static double ToDouble(string value)
{
double d;
double.TryParse(value, out d);
double.TryParse(value, out double d);
return d;
}
public static TimeSpan ToTimeSpan(string value)
{
TimeSpan t;
TimeSpan.TryParse(value, out t);
TimeSpan.TryParse(value, out TimeSpan t);
return t;
}
@ -922,6 +910,18 @@ namespace Server
return i;
}
public static uint ToUInt32(string value)
{
uint i;
if (value.StartsWith("0x"))
uint.TryParse(value.Substring(2), NumberStyles.HexNumber, null, out i);
else
uint.TryParse(value, out i);
return i;
}
#endregion
#region Get[Something]
@ -934,10 +934,7 @@ namespace Server
}
catch
{
if (double.TryParse(doubleString, out double val))
return val;
return defaultValue;
return double.TryParse(doubleString, out double val) ? val : defaultValue;
}
}
@ -949,10 +946,19 @@ namespace Server
}
catch
{
if (int.TryParse(intString, out int val))
return val;
return int.TryParse(intString, out int val) ? val : defaultValue;
}
}
return defaultValue;
public static uint GetXMLUInt32(string uintString, uint defaultValue)
{
try
{
return XmlConvert.ToUInt32(uintString);
}
catch
{
return uint.TryParse(uintString, out uint val) ? val : defaultValue;
}
}
@ -964,10 +970,7 @@ namespace Server
}
catch
{
if (DateTime.TryParse(dateTimeString, out DateTime d))
return d;
return defaultValue;
return DateTime.TryParse(dateTimeString, out DateTime d) ? d : defaultValue;
}
}
@ -979,10 +982,7 @@ namespace Server
}
catch
{
if (DateTimeOffset.TryParse(dateTimeOffsetString, out DateTimeOffset d))
return d;
return defaultValue;
return DateTimeOffset.TryParse(dateTimeOffsetString, out DateTimeOffset d) ? d : defaultValue;
}
}
@ -998,30 +998,19 @@ namespace Server
}
}
public static string GetAttribute(XmlElement node, string attributeName)
{
return GetAttribute(node, attributeName, null);
}
public static string GetAttribute(XmlElement node, string attributeName, string defaultValue)
public static string GetAttribute(XmlElement node, string attributeName, string defaultValue = null)
{
if (node == null)
return defaultValue;
XmlAttribute attr = node.Attributes[attributeName];
if (attr == null)
return defaultValue;
return attr.Value;
return attr == null ? defaultValue : attr.Value;
}
public static string GetText(XmlElement node, string defaultValue)
{
if (node == null)
return defaultValue;
return node.InnerText;
return node == null ? defaultValue : node.InnerText;
}
public static int GetAddressValue(IPAddress address)
@ -1090,15 +1079,23 @@ namespace Server
return total;
}
public static int RandomList(params int[] list)
public static void Shuffle<T>(IList<T> list)
{
return list[RandomImpl.Next(list.Length)];
int count = list.Count;
for (int i = count - 1; i > 0; i--)
{
int r = RandomImpl.Next(count);
T swap = list[r];
list[r] = list[i];
list[i] = swap;
}
}
public static bool RandomBool()
{
return RandomImpl.NextBool();
}
public static int RandomList(params int[] list) => RandomList<int>(list);
public static T RandomList<T>(IList<T> list) => list[RandomImpl.Next(list.Count)];
public static bool RandomBool() => RandomImpl.NextBool();
public static int RandomMinMax(int min, int max)
{
@ -1285,38 +1282,6 @@ namespace Server
return RandomList(0x03, 0x0D, 0x13, 0x1C, 0x21, 0x30, 0x37, 0x3A, 0x44, 0x59);
}
//[Obsolete( "Depreciated, use the methods for the Mobile's race", false )]
public static int ClipSkinHue(int hue)
{
if (hue < 1002)
return 1002;
if (hue > 1058)
return 1058;
return hue;
}
//[Obsolete( "Depreciated, use the methods for the Mobile's race", false )]
public static int RandomSkinHue()
{
return Random(1002, 57) | 0x8000;
}
//[Obsolete( "Depreciated, use the methods for the Mobile's race", false )]
public static int ClipHairHue(int hue)
{
if (hue < 1102)
return 1102;
if (hue > 1149)
return 1149;
return hue;
}
//[Obsolete( "Depreciated, use the methods for the Mobile's race", false )]
public static int RandomHairHue()
{
return Random(1102, 48);
}
#endregion
}
}
}

View file

@ -46,7 +46,7 @@ namespace Server
public static readonly string GuildIndexPath = Path.Combine("Saves/Guilds/", "Guilds.idx");
public static readonly string GuildDataPath = Path.Combine("Saves/Guilds/", "Guilds.bin");
private static readonly Type[] m_SerialTypeArray = new Type[1] { typeof(Serial) };
private static readonly Type[] m_SerialTypeArray = new Type[] { typeof(Serial) };
internal static int m_Saves;
@ -181,7 +181,7 @@ namespace Server
_addQueue = new Queue<IEntity>();
_deleteQueue = new Queue<IEntity>();
int mobileCount = 0, itemCount = 0, guildCount = 0;
int mobileCount, itemCount, guildCount;
object[] ctorArgs = new object[1];
@ -207,7 +207,7 @@ namespace Server
for (int i = 0; i < mobileCount; ++i)
{
int typeID = idxReader.ReadInt32();
int serial = idxReader.ReadInt32();
uint serial = idxReader.ReadUInt32();
long pos = idxReader.ReadInt64();
int length = idxReader.ReadInt32();
@ -227,6 +227,7 @@ namespace Server
}
catch
{
// ignored
}
if (m != null)
@ -262,7 +263,7 @@ namespace Server
for (int i = 0; i < itemCount; ++i)
{
int typeID = idxReader.ReadInt32();
int serial = idxReader.ReadInt32();
uint serial = idxReader.ReadUInt32();
long pos = idxReader.ReadInt64();
int length = idxReader.ReadInt32();
@ -282,6 +283,7 @@ namespace Server
}
catch
{
// ignored
}
if (item != null)
@ -306,11 +308,11 @@ namespace Server
guildCount = idxReader.ReadInt32();
CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(-1);
CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(0xFFFFFFFF);
for (int i = 0; i < guildCount; ++i)
{
idxReader.ReadInt32(); //no typeid for guilds
int id = idxReader.ReadInt32();
uint id = idxReader.ReadUInt32();
long pos = idxReader.ReadInt64();
int length = idxReader.ReadInt32();
@ -440,7 +442,7 @@ namespace Server
failed = e;
failedGuilds = true;
failedType = typeof(BaseGuild);
failedTypeID = g.Id;
failedTypeID = (int)g.Id;
failedSerial = g.Id;
break;
@ -576,6 +578,7 @@ namespace Server
}
catch
{
// ignored
}
}
@ -694,9 +697,7 @@ namespace Server
public static Mobile FindMobile(Serial serial)
{
Mobile mob;
Mobiles.TryGetValue(serial, out mob);
Mobiles.TryGetValue(serial, out Mobile mob);
return mob;
}
@ -716,9 +717,7 @@ namespace Server
public static Item FindItem(Serial serial)
{
Item item;
Items.TryGetValue(serial, out item);
Items.TryGetValue(serial, out Item item);
return item;
}