ModernUO/Projects/Server/Serial.cs
Kamron Batman 1ca8655fc1
Updates Serialization (#292)
- [X] Removes all save strategies
- [X] Removes duplicate file writer that won't be used
- [X] Removes persistence (it will become a duplicate system)
- [X] Add a save position variable to skip serializing a clean item/mobile
- [X] Update Guilds/Accounts to be IEntity types
    - Because guilds are abstract, this may make serialization tricky.
- [X] Update the generalized IEntity writing
- [X] Update the load/save to write to buffers then to files in background


Bumps release version
2020-10-31 17:38:29 -07:00

63 lines
1.8 KiB
C#

using System;
namespace Server
{
public readonly struct Serial : IComparable<Serial>, IComparable<uint>, IEquatable<Serial>
{
public static readonly Serial MinusOne = new Serial(0xFFFFFFFF);
public static readonly Serial Zero = new Serial(0);
private Serial(uint serial) => Value = serial;
public uint Value { get; }
public bool IsMobile => Value > 0 && Value < World.ItemOffset;
public bool IsItem => Value >= World.ItemOffset && Value < World.MaxItemSerial;
public bool IsValid => Value > 0;
public override int GetHashCode() => Value.GetHashCode();
public int CompareTo(Serial other) => Value.CompareTo(other.Value);
public int CompareTo(uint other) => Value.CompareTo(other);
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) => l.Value == r.Value;
public static bool operator !=(Serial l, Serial r) => l.Value != r.Value;
public static bool operator >(Serial l, Serial r) => l.Value > r.Value;
public static bool operator <(Serial l, Serial r) => l.Value < r.Value;
public static bool operator >=(Serial l, Serial r) => l.Value >= r.Value;
public static bool operator <=(Serial l, Serial r) => l.Value <= r.Value;
public override string ToString() => $"0x{Value:X8}";
public static implicit operator uint(Serial a) => a.Value;
public static implicit operator Serial(uint a) => new Serial(a);
public bool Equals(Serial other) => Value == other.Value;
public int ToInt32() => (int)Value;
}
}