forked from sharpot/sharpot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.cs
More file actions
177 lines (155 loc) · 4.64 KB
/
Tile.cs
File metadata and controls
177 lines (155 loc) · 4.64 KB
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
using System;
using System.Linq;
using System.Collections.Generic;
namespace SharpOT
{
public class Tile
{
public Location Location { get; set; }
public Item Ground { get; set; }
public IEnumerable<Item> Items { get { return items.AsEnumerable(); } }
public int ItemCount { get { return items.Count; } }
public List<Creature> Creatures { get; set; }
public bool IsProtectionZone = false;
public bool IsNoPvpZone = false;
public bool IsPvpZone = false;
public bool IsNoLogoutZone = false;
public bool IsRefreshZone = false;
private LinkedList<Item> items = new LinkedList<Item>();
public Tile()
{
Creatures = new List<Creature>();
}
public void AddItem(Item item)
{
items.AddFirst(item);
}
public void RemoveItem(Item item)
{
items.Remove(item);
}
public bool IsWalkable { get { return Ground != null && !Ground.Info.IsBlocking; } }
public FloorChangeDirection FloorChange
{
get
{
// TODO: compute this only when items change
if (Ground.Info.FloorChange != FloorChangeDirection.None)
{
return Ground.Info.FloorChange;
}
else
{
foreach (Item item in Items)
{
if (item.Info.FloorChange != FloorChangeDirection.None)
{
return item.Info.FloorChange;
}
}
}
return FloorChangeDirection.None;
}
}
public IEnumerable<Item> GetTopItems()
{
return Items.Where(i => i.GetOrder() < 4).OrderBy(i => i.GetOrder());
}
public IEnumerable<Item> GetDownItems()
{
return Items.Where(i => i.GetOrder() > 4).OrderBy(i => i.GetOrder()); ;
}
public Thing GetThingAtStackPosition(byte stackPosition)
{
int n = -1;
if (Ground != null)
{
++n;
if (stackPosition == n)
{
return Ground;
}
}
if (ItemCount > 0)
{
foreach (Item item in GetTopItems())
{
n++;
if (stackPosition == n)
{
return item;
}
}
}
if (Creatures.Count > 0)
{
foreach (Creature creature in Creatures)
{
++n;
if (stackPosition == n)
{
return creature;
}
}
}
if (ItemCount > 0)
{
foreach (Item item in GetDownItems())
{
n++;
if (stackPosition == n)
{
return item;
}
}
}
return null;
}
public byte GetStackPosition(Thing thing)
{
int n = -1;
if (Ground != null)
{
if (thing == Ground)
{
return 0;
}
++n;
}
if (ItemCount > 0)
{
foreach (Item item in GetTopItems())
{
++n;
if (thing == item)
{
return (byte)n;
}
}
}
if (Creatures.Count > 0)
{
foreach (Creature creature in Creatures)
{
++n;
if (thing == creature)
{
return (byte)n;
}
}
}
if (ItemCount > 0)
{
foreach (Item item in GetDownItems())
{
++n;
if (thing == item)
{
return (byte)n;
}
}
}
throw new Exception("Thing not found in tile.");
}
}
}