/
PreviewHouse.cs
144 lines (110 loc) · 3.58 KB
/
PreviewHouse.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
using System;
using System.Collections.Generic;
using Server.Items;
namespace Server.Multis
{
public class PreviewHouse : BaseMulti
{
private List<Item> m_Components;
private Timer m_Timer;
public PreviewHouse(int multiID)
: base(multiID)
{
this.m_Components = new List<Item>();
MultiComponentList mcl = this.Components;
for (int i = 1; i < mcl.List.Length; ++i)
{
MultiTileEntry entry = mcl.List[i];
if (entry.m_Flags == 0)
{
Item item = new Static((int)entry.m_ItemID);
item.MoveToWorld(new Point3D(this.X + entry.m_OffsetX, this.Y + entry.m_OffsetY, this.Z + entry.m_OffsetZ), this.Map);
this.m_Components.Add(item);
}
}
this.m_Timer = new DecayTimer(this);
this.m_Timer.Start();
}
public PreviewHouse(Serial serial)
: base(serial)
{
}
public override void OnLocationChange(Point3D oldLocation)
{
base.OnLocationChange(oldLocation);
if (this.m_Components == null)
return;
int xOffset = this.X - oldLocation.X;
int yOffset = this.Y - oldLocation.Y;
int zOffset = this.Z - oldLocation.Z;
for (int i = 0; i < this.m_Components.Count; ++i)
{
Item item = this.m_Components[i];
item.MoveToWorld(new Point3D(item.X + xOffset, item.Y + yOffset, item.Z + zOffset), this.Map);
}
}
public override void OnMapChange()
{
base.OnMapChange();
if (this.m_Components == null)
return;
for (int i = 0; i < this.m_Components.Count; ++i)
{
Item item = this.m_Components[i];
item.Map = this.Map;
}
}
public override void OnDelete()
{
base.OnDelete();
if (this.m_Components == null)
return;
for (int i = 0; i < this.m_Components.Count; ++i)
{
Item item = this.m_Components[i];
item.Delete();
}
}
public override void OnAfterDelete()
{
if (this.m_Timer != null)
this.m_Timer.Stop();
this.m_Timer = null;
base.OnAfterDelete();
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write((int)0); // version
writer.Write(this.m_Components);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
switch ( version )
{
case 0:
{
this.m_Components = reader.ReadStrongItemList();
break;
}
}
Timer.DelayCall(TimeSpan.Zero, new TimerCallback(this.Delete));
}
private class DecayTimer : Timer
{
private readonly Item m_Item;
public DecayTimer(Item item)
: base(TimeSpan.FromSeconds(20.0))
{
this.m_Item = item;
this.Priority = TimerPriority.OneSecond;
}
protected override void OnTick()
{
this.m_Item.Delete();
}
}
}
}