forked from runuo/runuo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerial.cs
172 lines (141 loc) · 3.57 KB
/
Serial.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/***************************************************************************
* Serial.cs
* -------------------
* begin : May 1, 2002
* copyright : (C) The RunUO Software Team
* email : [email protected]
*
* $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, IComparable<Serial>
{
private int m_Serial;
private static Serial m_LastMobile = Zero;
private static Serial m_LastItem = 0x40000000;
public static Serial LastMobile { get { return m_LastMobile; } }
public static Serial LastItem { get { return m_LastItem; } }
public static readonly Serial MinusOne = new Serial( -1 );
public static readonly Serial Zero = new Serial( 0 );
public static Serial NewMobile
{
get
{
while ( World.FindMobile( m_LastMobile = (m_LastMobile + 1) ) != null );
return m_LastMobile;
}
}
public static Serial NewItem
{
get
{
while ( World.FindItem( m_LastItem = (m_LastItem + 1) ) != null );
return m_LastItem;
}
}
private Serial( int serial )
{
m_Serial = serial;
}
public int Value
{
get
{
return m_Serial;
}
}
public bool IsMobile
{
get
{
return ( m_Serial > 0 && m_Serial < 0x40000000 );
}
}
public bool IsItem
{
get
{
return ( m_Serial >= 0x40000000 && m_Serial <= 0x7FFFFFFF );
}
}
public bool IsValid
{
get
{
return ( m_Serial > 0 );
}
}
public override int GetHashCode()
{
return m_Serial;
}
public int CompareTo( Serial other )
{
return m_Serial.CompareTo( other.m_Serial );
}
public int CompareTo( object other )
{
if ( other is Serial )
return this.CompareTo( (Serial) other );
else if ( other == null )
return -1;
throw new ArgumentException();
}
public override bool Equals( object o )
{
if ( o == null || !(o is Serial) ) return false;
return ((Serial)o).m_Serial == m_Serial;
}
public static bool operator == ( Serial l, Serial r )
{
return l.m_Serial == r.m_Serial;
}
public static bool operator != ( Serial l, Serial r )
{
return l.m_Serial != r.m_Serial;
}
public static bool operator > ( Serial l, Serial r )
{
return l.m_Serial > r.m_Serial;
}
public static bool operator < ( Serial l, Serial r )
{
return l.m_Serial < r.m_Serial;
}
public static bool operator >= ( Serial l, Serial r )
{
return l.m_Serial >= r.m_Serial;
}
public static bool operator <= ( Serial l, Serial r )
{
return l.m_Serial <= r.m_Serial;
}
/*public static Serial operator ++ ( Serial l )
{
return new Serial( l + 1 );
}*/
public override string ToString()
{
return String.Format( "0x{0:X8}", m_Serial );
}
public static implicit operator int( Serial a )
{
return a.m_Serial;
}
public static implicit operator Serial( int a )
{
return new Serial( a );
}
}
}