forked from runuo/runuo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtility.cs
1364 lines (1136 loc) · 29.2 KB
/
Utility.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
* Utility.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;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Text;
using System.Xml;
using Microsoft.Win32;
using Server.Network;
namespace Server
{
public static class Utility
{
private static Encoding m_UTF8, m_UTF8WithEncoding;
public static Encoding UTF8
{
get
{
if ( m_UTF8 == null )
m_UTF8 = new UTF8Encoding( false, false );
return m_UTF8;
}
}
public static Encoding UTF8WithEncoding
{
get
{
if ( m_UTF8WithEncoding == null )
m_UTF8WithEncoding = new UTF8Encoding( true, false );
return m_UTF8WithEncoding;
}
}
public static void Separate( StringBuilder sb, string value, string separator )
{
if ( sb.Length > 0 )
sb.Append( separator );
sb.Append( value );
}
public static string Intern( string str )
{
if ( str == null )
return null;
else if ( str.Length == 0 )
return String.Empty;
return String.Intern( str );
}
public static void Intern( ref string str )
{
str = Intern( str );
}
private static Dictionary<IPAddress, IPAddress> _ipAddressTable;
public static IPAddress Intern( IPAddress ipAddress ) {
if ( _ipAddressTable == null ) {
_ipAddressTable = new Dictionary<IPAddress, IPAddress>();
}
IPAddress interned;
if ( !_ipAddressTable.TryGetValue( ipAddress, out interned ) ) {
interned = ipAddress;
_ipAddressTable[ipAddress] = interned;
}
return interned;
}
public static void Intern( ref IPAddress ipAddress ) {
ipAddress = Intern( ipAddress );
}
public static bool IsValidIP( string text )
{
bool valid = true;
IPMatch( text, IPAddress.None, ref valid );
return valid;
}
public static bool IPMatch( string val, IPAddress ip )
{
bool valid = true;
return IPMatch( val, ip, ref valid );
}
public static string FixHtml( string str )
{
if( str == null )
return "";
bool hasOpen = ( str.IndexOf( '<' ) >= 0 );
bool hasClose = ( str.IndexOf( '>' ) >= 0 );
bool hasPound = ( str.IndexOf( '#' ) >= 0 );
if ( !hasOpen && !hasClose && !hasPound )
return str;
StringBuilder sb = new StringBuilder( str );
if ( hasOpen )
sb.Replace( '<', '(' );
if ( hasClose )
sb.Replace( '>', ')' );
if ( hasPound )
sb.Replace( '#', '-' );
return sb.ToString();
}
public static bool IPMatchCIDR( string cidr, IPAddress ip )
{
if ( ip == null || ip.AddressFamily == AddressFamily.InterNetworkV6 )
return false; //Just worry about IPv4 for now
/*
string[] str = cidr.Split( '/' );
if ( str.Length != 2 )
return false;
/* **************************************************
IPAddress cidrPrefix;
if ( !IPAddress.TryParse( str[0], out cidrPrefix ) )
return false;
* */
/*
string[] dotSplit = str[0].Split( '.' );
if ( dotSplit.Length != 4 ) //At this point and time, and for speed sake, we'll only worry about IPv4
return false;
byte[] bytes = new byte[4];
for ( int i = 0; i < 4; i++ )
{
byte.TryParse( dotSplit[i], out bytes[i] );
}
uint cidrPrefix = OrderedAddressValue( bytes );
int cidrLength = Utility.ToInt32( str[1] );
//The below solution is the fastest solution of the three
*/
byte[] bytes = new byte[4];
string[] split = cidr.Split( '.' );
bool cidrBits = false;
int cidrLength = 0;
for ( int i = 0; i < 4; i++ )
{
int part = 0;
int partBase = 10;
string pattern = split[i];
for ( int j = 0; j < pattern.Length; j++ )
{
char c = (char)pattern[j];
if ( c == 'x' || c == 'X' )
{
partBase = 16;
}
else if ( c >= '0' && c <= '9' )
{
int offset = c - '0';
if ( cidrBits )
{
cidrLength *= partBase;
cidrLength += offset;
}
else
{
part *= partBase;
part += offset;
}
}
else if ( c >= 'a' && c <= 'f' )
{
int offset = 10 + ( c - 'a' );
if ( cidrBits )
{
cidrLength *= partBase;
cidrLength += offset;
}
else
{
part *= partBase;
part += offset;
}
}
else if ( c >= 'A' && c <= 'F' )
{
int offset = 10 + ( c - 'A' );
if ( cidrBits )
{
cidrLength *= partBase;
cidrLength += offset;
}
else
{
part *= partBase;
part += offset;
}
}
else if ( c == '/' )
{
if ( cidrBits || i != 3 ) //If there's two '/' or the '/' isn't in the last byte
{
return false;
}
partBase = 10;
cidrBits = true;
}
else
{
return false;
}
}
bytes[i] = (byte)part;
}
uint cidrPrefix = OrderedAddressValue( bytes );
return IPMatchCIDR( cidrPrefix, ip, cidrLength );
}
public static bool IPMatchCIDR( IPAddress cidrPrefix, IPAddress ip, int cidrLength )
{
if ( cidrPrefix == null || ip == null || cidrPrefix.AddressFamily == AddressFamily.InterNetworkV6 ) //Ignore IPv6 for now
return false;
uint cidrValue = SwapUnsignedInt( (uint)GetLongAddressValue( cidrPrefix ) );
uint ipValue = SwapUnsignedInt( (uint)GetLongAddressValue( ip ) );
return IPMatchCIDR( cidrValue, ipValue, cidrLength );
}
public static bool IPMatchCIDR( uint cidrPrefixValue, IPAddress ip, int cidrLength )
{
if ( ip == null || ip.AddressFamily == AddressFamily.InterNetworkV6)
return false;
uint ipValue = SwapUnsignedInt( (uint)GetLongAddressValue( ip ) );
return IPMatchCIDR( cidrPrefixValue, ipValue, cidrLength );
}
public static bool IPMatchCIDR( uint cidrPrefixValue, uint ipValue, int cidrLength )
{
if ( cidrLength <= 0 || cidrLength >= 32 ) //if invalid cidr Length, just compare IPs
return cidrPrefixValue == ipValue;
uint mask = uint.MaxValue << 32-cidrLength;
return ( ( cidrPrefixValue & mask ) == ( ipValue & mask ) );
}
private static uint OrderedAddressValue( byte[] bytes )
{
if ( bytes.Length != 4 )
return 0;
return (uint)(((( bytes[0] << 0x18 ) | (bytes[1] << 0x10)) | (bytes[2] << 8)) | bytes[3]) & ((uint)0xffffffff);
}
private static uint SwapUnsignedInt( uint source )
{
return (uint)( ( ( ( source & 0x000000FF ) << 0x18 )
| ( ( source & 0x0000FF00 ) << 8 )
| ( ( source & 0x00FF0000 ) >> 8 )
| ( ( source & 0xFF000000 ) >> 0x18 ) ) );
}
public static bool TryConvertIPv6toIPv4( ref IPAddress address )
{
if ( !Socket.OSSupportsIPv6 || address.AddressFamily == AddressFamily.InterNetwork )
return true;
byte[] addr = address.GetAddressBytes();
if ( addr.Length == 16 ) //sanity 0 - 15 //10 11 //12 13 14 15
{
if ( addr[10] != 0xFF || addr[11] != 0xFF )
return false;
for ( int i = 0; i < 10; i++ )
{
if ( addr[i] != 0 )
return false;
}
byte[] v4Addr = new byte[4];
for ( int i = 0; i < 4; i++ )
{
v4Addr[i] = addr[12 + i];
}
address = new IPAddress( v4Addr );
return true;
}
return false;
}
public static bool IPMatch( string val, IPAddress ip, ref bool valid )
{
valid = true;
string[] split = val.Split( '.' );
for ( int i = 0; i < 4; ++i )
{
int lowPart, highPart;
if ( i >= split.Length )
{
lowPart = 0;
highPart = 255;
}
else
{
string pattern = split[i];
if ( pattern == "*" )
{
lowPart = 0;
highPart = 255;
}
else
{
lowPart = 0;
highPart = 0;
bool highOnly = false;
int lowBase = 10;
int highBase = 10;
for ( int j = 0; j < pattern.Length; ++j )
{
char c = (char)pattern[j];
if ( c == '?' )
{
if ( !highOnly )
{
lowPart *= lowBase;
lowPart += 0;
}
highPart *= highBase;
highPart += highBase - 1;
}
else if ( c == '-' )
{
highOnly = true;
highPart = 0;
}
else if ( c == 'x' || c == 'X' )
{
lowBase = 16;
highBase = 16;
}
else if ( c >= '0' && c <= '9' )
{
int offset = c - '0';
if ( !highOnly )
{
lowPart *= lowBase;
lowPart += offset;
}
highPart *= highBase;
highPart += offset;
}
else if ( c >= 'a' && c <= 'f' )
{
int offset = 10 + (c - 'a');
if ( !highOnly )
{
lowPart *= lowBase;
lowPart += offset;
}
highPart *= highBase;
highPart += offset;
}
else if ( c >= 'A' && c <= 'F' )
{
int offset = 10 + (c - 'A');
if ( !highOnly )
{
lowPart *= lowBase;
lowPart += offset;
}
highPart *= highBase;
highPart += offset;
}
else
{
valid = false; //high & lowpart would be 0 if it got to here.
}
}
}
}
int b = (byte)(Utility.GetAddressValue( ip ) >> (i * 8));
if ( b < lowPart || b > highPart )
return false;
}
return true;
}
public static bool IPMatchClassC( IPAddress ip1, IPAddress ip2 )
{
return ( (Utility.GetAddressValue( ip1 ) & 0xFFFFFF) == (Utility.GetAddressValue( ip2 ) & 0xFFFFFF) );
}
public static int InsensitiveCompare( string first, string second )
{
return Insensitive.Compare( first, second );
}
public static bool InsensitiveStartsWith( string first, string second )
{
return Insensitive.StartsWith( first, second );
}
#region To[Something]
public static bool ToBoolean( string value )
{
bool b;
bool.TryParse( value, out b );
return b;
}
public static double ToDouble( string value )
{
double d;
double.TryParse( value, out d );
return d;
}
public static TimeSpan ToTimeSpan( string value )
{
TimeSpan t;
TimeSpan.TryParse( value, out t );
return t;
}
public static int ToInt32( string value )
{
int i;
if( value.StartsWith( "0x" ) )
int.TryParse( value.Substring( 2 ), NumberStyles.HexNumber, null, out i );
else
int.TryParse( value, out i );
return i;
}
#endregion
#region Get[Something]
public static double GetXMLDouble(string doubleString, double defaultValue)
{
try
{
return XmlConvert.ToDouble(doubleString);
}
catch
{
double val;
if (double.TryParse(doubleString, out val))
return val;
return defaultValue;
}
}
public static int GetXMLInt32( string intString, int defaultValue )
{
try
{
return XmlConvert.ToInt32( intString );
}
catch
{
int val;
if ( int.TryParse( intString, out val ) )
return val;
return defaultValue;
}
}
public static DateTime GetXMLDateTime( string dateTimeString, DateTime defaultValue )
{
try
{
return XmlConvert.ToDateTime( dateTimeString, XmlDateTimeSerializationMode.Utc );
}
catch
{
DateTime d;
if( DateTime.TryParse( dateTimeString, out d ) )
return d;
return defaultValue;
}
}
public static DateTimeOffset GetXMLDateTimeOffset( string dateTimeOffsetString, DateTimeOffset defaultValue )
{
try
{
return XmlConvert.ToDateTimeOffset( dateTimeOffsetString );
}
catch
{
DateTimeOffset d;
if( DateTimeOffset.TryParse( dateTimeOffsetString, out d ) )
return d;
return defaultValue;
}
}
public static TimeSpan GetXMLTimeSpan( string timeSpanString, TimeSpan defaultValue )
{
try
{
return XmlConvert.ToTimeSpan( timeSpanString );
}
catch
{
return defaultValue;
}
}
public static string GetAttribute( XmlElement node, string attributeName )
{
return GetAttribute( node, attributeName, null );
}
public static string GetAttribute( XmlElement node, string attributeName, string defaultValue )
{
if ( node == null )
return defaultValue;
XmlAttribute attr = node.Attributes[attributeName];
if ( attr == null )
return defaultValue;
return attr.Value;
}
public static string GetText( XmlElement node, string defaultValue )
{
if ( node == null )
return defaultValue;
return node.InnerText;
}
public static int GetAddressValue( IPAddress address )
{
#pragma warning disable 618
return (int)address.Address;
#pragma warning restore 618
}
public static long GetLongAddressValue( IPAddress address )
{
#pragma warning disable 618
return address.Address;
#pragma warning restore 618
}
#endregion
#region In[...]Range
public static bool InRange( Point3D p1, Point3D p2, int range )
{
return ( p1.m_X >= (p2.m_X - range) )
&& ( p1.m_X <= (p2.m_X + range) )
&& ( p1.m_Y >= (p2.m_Y - range) )
&& ( p1.m_Y <= (p2.m_Y + range) );
}
public static bool InUpdateRange( Point3D p1, Point3D p2 )
{
return ( p1.m_X >= (p2.m_X - 18) )
&& ( p1.m_X <= (p2.m_X + 18) )
&& ( p1.m_Y >= (p2.m_Y - 18) )
&& ( p1.m_Y <= (p2.m_Y + 18) );
}
public static bool InUpdateRange( Point2D p1, Point2D p2 )
{
return ( p1.m_X >= (p2.m_X - 18) )
&& ( p1.m_X <= (p2.m_X + 18) )
&& ( p1.m_Y >= (p2.m_Y - 18) )
&& ( p1.m_Y <= (p2.m_Y + 18) );
}
public static bool InUpdateRange( IPoint2D p1, IPoint2D p2 )
{
return ( p1.X >= (p2.X - 18) )
&& ( p1.X <= (p2.X + 18) )
&& ( p1.Y >= (p2.Y - 18) )
&& ( p1.Y <= (p2.Y + 18) );
}
#endregion
public static Direction GetDirection( IPoint2D from, IPoint2D to )
{
int dx = to.X - from.X;
int dy = to.Y - from.Y;
int adx = Math.Abs( dx );
int ady = Math.Abs( dy );
if ( adx >= ady * 3 )
{
if ( dx > 0 )
return Direction.East;
else
return Direction.West;
}
else if ( ady >= adx * 3 )
{
if ( dy > 0 )
return Direction.South;
else
return Direction.North;
}
else if ( dx > 0 )
{
if ( dy > 0 )
return Direction.Down;
else
return Direction.Right;
}
else
{
if ( dy > 0 )
return Direction.Left;
else
return Direction.Up;
}
}
/* Should probably be rewritten to use an ITile interface
public static bool CanMobileFit( int z, StaticTile[] tiles )
{
int checkHeight = 15;
int checkZ = z;
for ( int i = 0; i < tiles.Length; ++i )
{
StaticTile tile = tiles[i];
if ( ((checkZ + checkHeight) > tile.Z && checkZ < (tile.Z + tile.Height))*//* || (tile.Z < (checkZ + checkHeight) && (tile.Z + tile.Height) > checkZ)*//* )
{
return false;
}
else if ( checkHeight == 0 && tile.Height == 0 && checkZ == tile.Z )
{
return false;
}
}
return true;
}
public static bool IsInContact( StaticTile check, StaticTile[] tiles )
{
int checkHeight = check.Height;
int checkZ = check.Z;
for ( int i = 0; i < tiles.Length; ++i )
{
StaticTile tile = tiles[i];
if ( ((checkZ + checkHeight) > tile.Z && checkZ < (tile.Z + tile.Height))*//* || (tile.Z < (checkZ + checkHeight) && (tile.Z + tile.Height) > checkZ)*//* )
{
return true;
}
else if ( checkHeight == 0 && tile.Height == 0 && checkZ == tile.Z )
{
return true;
}
}
return false;
}
*/
public static object GetArrayCap( Array array, int index )
{
return GetArrayCap( array, index, null );
}
public static object GetArrayCap( Array array, int index, object emptyValue )
{
if ( array.Length > 0 )
{
if ( index < 0 )
{
index = 0;
}
else if ( index >= array.Length )
{
index = array.Length - 1;
}
return array.GetValue( index );
}
else
{
return emptyValue;
}
}
#region Random
//4d6+8 would be: Utility.Dice( 4, 6, 8 )
public static int Dice( int numDice, int numSides, int bonus )
{
int total = 0;
for (int i = 0; i < numDice; ++i)
total += RandomImpl.Next(numSides) + 1;
total += bonus;
return total;
}
public static int RandomList( params int[] list )
{
return list[RandomImpl.Next(list.Length)];
}
public static bool RandomBool()
{
return RandomImpl.NextBool();
}
public static int RandomMinMax( int min, int max )
{
if ( min > max )
{
int copy = min;
min = max;
max = copy;
}
else if ( min == max )
{
return min;
}
return min + RandomImpl.Next((max - min) + 1);
}
public static int Random( int from, int count )
{
if ( count == 0 ) {
return from;
} else if ( count > 0 ) {
return from + RandomImpl.Next(count);
} else {
return from - RandomImpl.Next(-count);
}
}
public static int Random( int count )
{
return RandomImpl.Next(count);
}
public static void RandomBytes( byte[] buffer )
{
RandomImpl.NextBytes(buffer);
}
public static double RandomDouble()
{
return RandomImpl.NextDouble();
}
#endregion
#region Random Hues
/// <summary>
/// Random pink, blue, green, orange, red or yellow hue
/// </summary>
public static int RandomNondyedHue()
{
switch ( Random( 6 ) )
{
case 0: return RandomPinkHue();
case 1: return RandomBlueHue();
case 2: return RandomGreenHue();
case 3: return RandomOrangeHue();
case 4: return RandomRedHue();
case 5: return RandomYellowHue();
}
return 0;
}
/// <summary>
/// Random hue in the range 1201-1254
/// </summary>
public static int RandomPinkHue()
{
return Random( 1201, 54 );
}
/// <summary>
/// Random hue in the range 1301-1354
/// </summary>
public static int RandomBlueHue()
{
return Random( 1301, 54 );
}
/// <summary>
/// Random hue in the range 1401-1454
/// </summary>
public static int RandomGreenHue()
{
return Random( 1401, 54 );
}
/// <summary>
/// Random hue in the range 1501-1554
/// </summary>
public static int RandomOrangeHue()
{
return Random( 1501, 54 );
}
/// <summary>
/// Random hue in the range 1601-1654
/// </summary>
public static int RandomRedHue()
{
return Random( 1601, 54 );
}
/// <summary>
/// Random hue in the range 1701-1754
/// </summary>
public static int RandomYellowHue()
{
return Random( 1701, 54 );
}
/// <summary>
/// Random hue in the range 1801-1908
/// </summary>
public static int RandomNeutralHue()
{
return Random( 1801, 108 );
}
/// <summary>
/// Random hue in the range 2001-2018
/// </summary>
public static int RandomSnakeHue()
{
return Random( 2001, 18 );
}
/// <summary>
/// Random hue in the range 2101-2130
/// </summary>
public static int RandomBirdHue()
{
return Random( 2101, 30 );
}
/// <summary>
/// Random hue in the range 2201-2224
/// </summary>
public static int RandomSlimeHue()
{
return Random( 2201, 24 );
}
/// <summary>
/// Random hue in the range 2301-2318
/// </summary>
public static int RandomAnimalHue()
{
return Random( 2301, 18 );
}
/// <summary>
/// Random hue in the range 2401-2430
/// </summary>
public static int RandomMetalHue()
{
return Random( 2401, 30 );
}
public static int ClipDyedHue( int hue )
{
if ( hue < 2 )
return 2;
else if ( hue > 1001 )
return 1001;
else
return hue;
}
/// <summary>
/// Random hue in the range 2-1001
/// </summary>
public static int RandomDyedHue()
{
return Random( 2, 1000 );
}
/// <summary>
/// Random hue from 0x62, 0x71, 0x03, 0x0D, 0x13, 0x1C, 0x21, 0x30, 0x37, 0x3A, 0x44, 0x59
/// </summary>
public static int RandomBrightHue()
{
if ( Utility.RandomDouble() < 0.1 )
return Utility.RandomList( 0x62, 0x71 );
return Utility.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 )