using System; using System.Globalization; namespace Questionable.Model.Questing; public abstract class ElementId : IComparable, IEquatable { public ushort Value { get; } protected ElementId(ushort value) { Value = value; } public int CompareTo(ElementId? other) { if ((object)this == other) { return 0; } if ((object)other == null) { return 1; } return Value.CompareTo(other.Value); } public bool Equals(ElementId? other) { if ((object)other == null) { return false; } if ((object)this == other) { return true; } if (other.GetType() != GetType()) { return false; } return Value == other.Value; } public override bool Equals(object? obj) { if (obj == null) { return false; } if (this == obj) { return true; } if (obj.GetType() != GetType()) { return false; } return Equals((ElementId)obj); } public override int GetHashCode() { return Value.GetHashCode(); } public static bool operator ==(ElementId? left, ElementId? right) { return object.Equals(left, right); } public static bool operator !=(ElementId? left, ElementId? right) { return !object.Equals(left, right); } public static ElementId FromString(string value) { if (value.StartsWith("S")) { return new SatisfactionSupplyNpcId(ushort.Parse(value.Substring(1), CultureInfo.InvariantCulture)); } if (value.StartsWith("U")) { return new UnlockLinkId(ushort.Parse(value.Substring(1), CultureInfo.InvariantCulture)); } if (value.StartsWith("N")) { return new AethernetId(ushort.Parse(value.Substring(1), CultureInfo.InvariantCulture)); } if (value.StartsWith("C")) { return new AetherCurrentId(ushort.Parse(value.Substring(1), CultureInfo.InvariantCulture)); } if (value.StartsWith("A")) { value = value.Substring(1); string[] array = value.Split(new char[1] { 'x' }); if (array.Length == 2) { return new AlliedSocietyDailyId(byte.Parse(array[0], CultureInfo.InvariantCulture), byte.Parse(array[1], CultureInfo.InvariantCulture)); } return new AlliedSocietyDailyId(byte.Parse(value, CultureInfo.InvariantCulture), 0); } return new QuestId(ushort.Parse(value, CultureInfo.InvariantCulture)); } public static bool TryFromString(string value, out ElementId? elementId) { try { elementId = FromString(value); return true; } catch (Exception) { elementId = null; return false; } } public abstract override string ToString(); }