-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAutoResPotion.cs
155 lines (127 loc) · 4.29 KB
/
AutoResPotion.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
using System;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Prompts;
using Server.Network;
using System.Collections;
using System.Collections.Generic;
namespace Server.Items
{
public class AutoResPotion : Item
{
private static Dictionary<Mobile, AutoResPotion> m_ResList;
private int m_Charges;
[CommandProperty( AccessLevel.GameMaster )]
public int Charges
{
get { return m_Charges; }
set { m_Charges = value; InvalidateProperties(); }
}
private Timer m_Timer;
private static TimeSpan m_Delay = TimeSpan.FromSeconds( 30.0 ); /*TimeSpan.Zero*/
[CommandProperty(AccessLevel.GameMaster)]
public TimeSpan Delay { get { return m_Delay; } set { m_Delay = value; } }
public static void Initialize()
{
EventSink.PlayerDeath += new PlayerDeathEventHandler(EventSink_Death);
}
[Constructable]
public AutoResPotion() : this( 1 )
{ }
[Constructable]
public AutoResPotion(int charges) : base(0xF04)
{
m_Charges = charges;
Name = "Potion Of Rebirth";
LootType = LootType.Blessed;
/*Stackable = true;*/
Weight = 1.0;
/*Amount = amount;*/
}
public AutoResPotion(Serial serial)
: base(serial)
{ }
public override void OnDoubleClick( Mobile from )
{
if(!from.Alive)
return;
if(m_ResList == null)
m_ResList = new Dictionary<Mobile, AutoResPotion>();
if( !m_ResList.ContainsKey(from))
{
if(!m_ResList.ContainsValue(this))
{
m_ResList.Add(from, this);
from.SendMessage("You feel the spirits watching you, awaiting to send you back to your body.");
}
else
from.SendMessage("The spirits of this potion are watching another");
}
else
from.SendMessage("The spirits watch you already.");
}
private static void EventSink_Death(PlayerDeathEventArgs e)
{
PlayerMobile owner = e.Mobile as PlayerMobile;
if (owner != null && !owner.Deleted)
{
if (owner.Alive)
return;
if(m_ResList != null && m_ResList.ContainsKey(owner))
{
AutoResPotion arp = m_ResList[owner];
if(arp == null || arp.Deleted)
{
m_ResList.Remove(owner);
return;
}
arp.m_Timer = Timer.DelayCall(m_Delay, new TimerStateCallback(Resurrect_OnTick), new object[] { owner, arp });
m_ResList.Remove(owner);
}
}
}
private static void Resurrect_OnTick(object state)
{
object[] states = (object[])state;
PlayerMobile owner = (PlayerMobile)states[0];
AutoResPotion arp = (AutoResPotion)states[1];
if (owner != null && !owner.Deleted && arp != null && !arp.Deleted)
{
if (owner.Alive || arp.m_Charges < 1)
return;
owner.SendMessage("You died under the watch of the spirits, they have offered you another chance at life.");
owner.Resurrect();
arp.m_Charges--;
arp.InvalidateProperties();
if (arp.m_Charges < 1)
arp.Delete();
}
}
public override void GetProperties( ObjectPropertyList list )
{
base.GetProperties( list );
list.Add(String.Format("{0} Charges", m_Charges));
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write( (int) 0 ); // version
writer.Write( (TimeSpan) m_Delay );
writer.Write( (int) m_Charges );
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
switch (version)
{
case 0:
{
m_Delay = reader.ReadTimeSpan();
m_Charges = reader.ReadInt();
} break;
}
}
}
}