forked from runuo/runuo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoison.cs
144 lines (120 loc) · 4.35 KB
/
Poison.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
/***************************************************************************
* Poison.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;
namespace Server
{
[Parsable]
public abstract class Poison
{
/*public abstract TimeSpan Interval{ get; }
public abstract TimeSpan Duration{ get; }*/
public abstract string Name { get; }
public abstract int Level { get; }
public abstract Timer ConstructTimer( Mobile m );
/*public abstract void OnDamage( Mobile m, ref object state );*/
public override string ToString()
{
return this.Name;
}
private static List<Poison> m_Poisons = new List<Poison>();
public static void Register( Poison reg )
{
string regName = reg.Name.ToLower();
for ( int i = 0; i < m_Poisons.Count; i++ )
{
if ( reg.Level == m_Poisons[i].Level )
throw new Exception( "A poison with that level already exists." );
else if ( regName == m_Poisons[i].Name.ToLower() )
throw new Exception( "A poison with that name already exists." );
}
m_Poisons.Add( reg );
}
public static Poison Lesser { get { return GetPoison( "Lesser" ); } }
public static Poison Regular { get { return GetPoison( "Regular" ); } }
public static Poison Greater { get { return GetPoison( "Greater" ); } }
public static Poison Deadly { get { return GetPoison( "Deadly" ); } }
public static Poison Lethal { get { return GetPoison( "Lethal" ); } }
public static List<Poison> Poisons
{
get
{
return m_Poisons;
}
}
public static Poison Parse( string value )
{
Poison p = null;
int plevel;
if ( int.TryParse( value, out plevel ) )
p = GetPoison( plevel );
if ( p == null )
p = GetPoison( value );
return p;
}
public static Poison GetPoison( int level )
{
for ( int i = 0; i < m_Poisons.Count; ++i )
{
Poison p = m_Poisons[i];
if ( p.Level == level )
return p;
}
return null;
}
public static Poison GetPoison( string name )
{
for ( int i = 0; i < m_Poisons.Count; ++i )
{
Poison p = m_Poisons[i];
if ( Utility.InsensitiveCompare( p.Name, name ) == 0 )
return p;
}
return null;
}
public static void Serialize( Poison p, GenericWriter writer )
{
if ( p == null )
{
writer.Write( (byte)0 );
}
else
{
writer.Write( (byte)1 );
writer.Write( (byte)p.Level );
}
}
public static Poison Deserialize( GenericReader reader )
{
switch ( reader.ReadByte() )
{
case 1: return GetPoison( reader.ReadByte() );
case 2:
//no longer used, safe to remove?
reader.ReadInt();
reader.ReadDouble();
reader.ReadInt();
reader.ReadTimeSpan();
break;
}
return null;
}
}
}