Reorganizes Project (#41)
This commit is contained in:
parent
08bf44af9a
commit
3614a66aee
3499 changed files with 79 additions and 55 deletions
146
Projects/Server/Serial.cs
Normal file
146
Projects/Server/Serial.cs
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/***************************************************************************
|
||||
* Serial.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public struct Serial : IComparable<Serial>, IComparable<uint>
|
||||
{
|
||||
public static readonly Serial MinusOne = new Serial(0xFFFFFFFF);
|
||||
public static readonly Serial Zero = new Serial(0);
|
||||
|
||||
public static Serial LastMobile{ get; private set; } = Zero;
|
||||
|
||||
public static Serial LastItem{ get; private set; } = 0x40000000;
|
||||
|
||||
public static Serial NewMobile
|
||||
{
|
||||
get
|
||||
{
|
||||
while (World.FindMobile(LastMobile = LastMobile + 1) != null)
|
||||
{
|
||||
}
|
||||
|
||||
return LastMobile;
|
||||
}
|
||||
}
|
||||
|
||||
public static Serial NewItem
|
||||
{
|
||||
get
|
||||
{
|
||||
while (World.FindItem(LastItem = LastItem + 1) != null)
|
||||
{
|
||||
}
|
||||
|
||||
return LastItem;
|
||||
}
|
||||
}
|
||||
|
||||
private Serial(uint serial)
|
||||
{
|
||||
Value = serial;
|
||||
}
|
||||
|
||||
public uint Value{ get; }
|
||||
|
||||
public bool IsMobile => Value > 0 && Value < 0x40000000;
|
||||
|
||||
public bool IsItem => Value >= 0x40000000 && Value < 0x80000000;
|
||||
|
||||
public bool IsValid => Value > 0;
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public int CompareTo(Serial other)
|
||||
{
|
||||
return Value.CompareTo(other.Value);
|
||||
}
|
||||
|
||||
public int CompareTo(uint other)
|
||||
{
|
||||
return 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)
|
||||
{
|
||||
return l.Value == r.Value;
|
||||
}
|
||||
|
||||
public static bool operator !=(Serial l, Serial r)
|
||||
{
|
||||
return l.Value != r.Value;
|
||||
}
|
||||
|
||||
public static bool operator >(Serial l, Serial r)
|
||||
{
|
||||
return l.Value > r.Value;
|
||||
}
|
||||
|
||||
public static bool operator <(Serial l, Serial r)
|
||||
{
|
||||
return l.Value < r.Value;
|
||||
}
|
||||
|
||||
public static bool operator >=(Serial l, Serial r)
|
||||
{
|
||||
return l.Value >= r.Value;
|
||||
}
|
||||
|
||||
public static bool operator <=(Serial l, Serial r)
|
||||
{
|
||||
return l.Value <= r.Value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"0x{Value:X8}";
|
||||
}
|
||||
|
||||
public static implicit operator uint(Serial a)
|
||||
{
|
||||
return a.Value;
|
||||
}
|
||||
|
||||
public static implicit operator Serial(uint a)
|
||||
{
|
||||
return new Serial(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue