-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
spells.php
277 lines (260 loc) · 8.72 KB
/
spells.php
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
<?php require_once 'engine/init.php'; include 'layout/overall/header.php';
// Loading spell list
$spellsCache = new Cache('engine/cache/spells');
if (user_logged_in() && is_admin($user_data)) {
if (isset($_GET['update'])) {
echo "<p><strong>Logged in as admin, loading engine/XML/spells.xml file and updating cache.</strong></p>";
// SPELLS XML TO PHP ARRAY
$spellsXML = simplexml_load_file("engine/XML/spells.xml");
if ($spellsXML !== false) {
$types = array();
$type_attr = array();
$groups = array();
// This empty array will eventually contain all spells grouped by type and indexed by spell name
$spells = array();
// Loop through each XML spell object
foreach ($spellsXML as $type => $spell) {
// Get spell types
if (!in_array($type, $types)) {
$types[] = $type;
$type_attr[$type] = array();
}
// Get spell attributes
$attributes = array();
// Extract attribute values from the XML object and store it in a more manage friendly way $attributes
foreach ($spell->attributes() as $aName => $aValue)
$attributes["$aName"] = "$aValue";
// Remove unececsary attributes
if (isset($attributes['script'])) unset($attributes['script']);
if (isset($attributes['spellid'])) unset($attributes['spellid']);
//if (isset($attributes['id'])) unset($attributes['id']);
//if (isset($attributes['conjureId'])) unset($attributes['conjureId']);
if (isset($attributes['function'])) unset($attributes['function']);
// Alias attributes
if (isset($attributes['level'])) $attributes['lvl'] = $attributes['level'];
if (isset($attributes['magiclevel'])) $attributes['maglv'] = $attributes['magiclevel'];
// Populate type attributes
foreach (array_keys($attributes) as $attr) {
if (!in_array($attr, $type_attr[$type]))
$type_attr[$type][] = $attr;
}
// Get spell groups
if (isset($attributes['group'])) {
if (!in_array($attributes['group'], $groups))
$groups[] = $attributes['group'];
}
// Get spell vocations
$vocations = array();
foreach ($spell->vocation as $vocation) {
foreach ($vocation->attributes() as $attributeName => $attributeValue) {
if ("$attributeName" == "name") {
$vocId = vocation_name_to_id("$attributeValue");
$vocations[] = ($vocId !== false) ? $vocId : "$attributeValue";
} elseif ("$attributeName" == "id") {
$vocations[] = (int)"$attributeValue";
}
}
}
// Exclude monster spells (Monster spells looks like this on the ORTS data pack)
$words = (isset($attributes['words'])) ? $attributes['words'] : false;
// Also exclude "house spells" such as aleta sio.
$name = (isset($attributes['name'])) ? $attributes['name'] : false;
if (substr($words, 0, 3) !== '###' && substr($name, 0, 5) !== 'House') {
// Build full spell list where the spell name is the key to the spell array.
$spells[$type][$name] = array('vocations' => $vocations);
// Populate spell array with potential relevant attributes for the spell type
foreach ($type_attr[$type] as $att)
$spells[$type][$name][$att] = (isset($attributes[$att])) ? $attributes[$att] : false;
}
}
// Sort the spell list properly
foreach (array_keys($spells) as $type) {
usort($spells[$type], function ($a, $b) {
if (isset($a['lvl']))
return $a['lvl'] - $b['lvl'];
if (isset($a['maglv']))
return $a['maglv'] - $b['maglv'];
return -1;
});
}
$spellsCache->setContent($spells);
$spellsCache->save();
} else {
echo "<p><strong>Failed to load engine/XML/spells.xml file.</strong></p>";
}
} else {
$spells = $spellsCache->load();
?>
<form action="">
<input type="submit" name="update" value="Generate new cache">
</form>
<?php
}
// END SPELLS XML TO PHP ARRAY
} else {
$spells = $spellsCache->load();
}
// End loading spell list
if ($spells) {
// Preparing data
$configVoc = $config['vocations'];
$types = array_keys($spells);
$itemServer = 'http://'.$config['shop']['imageServer'].'/';
// Filter spells by vocation
$getVoc = (isset($_GET['vocation'])) ? getValue($_GET['vocation']) : 'all';
if ($getVoc !== 'all') {
$getVoc = (int)$getVoc;
foreach ($types as $type)
foreach ($spells[$type] as $name => $spell)
if (!empty($spell['vocations']))
if (!in_array($getVoc, $spell['vocations']))
unset($spells[$type][$name]);
}
// Render HTML
?>
<h1 id="spells">Spells<?php if ($getVoc !== 'all') echo ' ('.$configVoc[$getVoc]['name'].')';?></h1>
<form action="#spells" class="filter_spells">
<label for="vocation">Filter vocation:</label>
<select id="vocation" name="vocation">
<option value="all">All</option>
<?php foreach ($config['vocations'] as $id => $vocation): ?>
<option value="<?php echo $id; ?>" <?php if ($getVoc === $id) echo "selected"; ?>><?php echo $vocation['name']; ?></option>
<?php endforeach; ?>
</select>
<input type="submit" value="Search">
</form>
<h2>Spell types:</h2>
<ul>
<?php foreach ($types as $type): ?>
<li><a href="#spell_<?php echo $type; ?>"><?php echo ucfirst($type); ?></a></li>
<?php endforeach; ?>
</ul>
<h2 id="spell_instant">Instant Spells</h2>
<a href="#spells">Jump to top</a>
<table class="table tbl-hover">
<tbody>
<tr class="yellow">
<td>Name</td>
<td>Words</td>
<td>Level</td>
<td>Mana</td>
<td>Vocations</td>
</tr>
<?php foreach ($spells['instant'] as $spell): ?>
<tr>
<td><?php echo $spell['name']; ?></td>
<td><?php echo $spell['words']; ?></td>
<td><?php echo $spell['lvl']; ?></td>
<td><?php echo $spell['mana']; ?></td>
<td><?php
if (!empty($spell['vocations'])) {
if ($getVoc !== 'all') {
echo $configVoc[$getVoc]['name'];
} else {
$names = array();
foreach ($spell['vocations'] as $id) {
if (isset($configVoc[$id]))
$names[] = $configVoc[$id]['name'];
}
echo implode(',<br>', $names);
}
}
?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<h2 id="spell_rune">Magical Runes</h2>
<a href="#spells">Jump to top</a>
<table class="table tbl-hover">
<tbody>
<tr class="yellow">
<td>Name</td>
<td>Level</td>
<td>Magic Level</td>
<td>Image</td>
<td>Vocations</td>
</tr>
<?php foreach ($spells['rune'] as $spell): ?>
<tr>
<td><?php echo $spell['name']; ?></td>
<td><?php echo $spell['lvl']; ?></td>
<td><?php echo $spell['maglv']; ?></td>
<td><img src="<?php echo $itemServer.$spell['id'].'.gif'; ?>" alt="Rune image"></td>
<td><?php
if (!empty($spell['vocations'])) {
if ($getVoc !== 'all') {
echo $configVoc[$getVoc]['name'];
} else {
$names = array();
foreach ($spell['vocations'] as $id) {
if (isset($configVoc[$id]))
$names[] = $configVoc[$id]['name'];
}
echo implode(',<br>', $names);
}
}
?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php if (isset($spells['conjure'])): ?>
<h2 id="spell_conjure">Conjure Spells</h2>
<a href="#spells">Jump to top</a>
<table class="table tbl-hover">
<tbody>
<tr class="yellow">
<td>Name</td>
<td>Words</td>
<td>Level</td>
<td>Mana</td>
<td>Soul</td>
<td>Charges</td>
<td>Image</td>
<td>Vocations</td>
</tr>
<?php foreach ($spells['conjure'] as $spell): ?>
<tr>
<td><?php echo $spell['name']; ?></td>
<td><?php echo $spell['words']; ?></td>
<td><?php echo $spell['lvl']; ?></td>
<td><?php echo $spell['mana']; ?></td>
<td><?php echo $spell['soul']; ?></td>
<td><?php echo $spell['conjureCount']; ?></td>
<td><img src="<?php echo $itemServer.$spell['conjureId'].'.gif'; ?>" alt="Rune image"></td>
<td><?php
if (!empty($spell['vocations'])) {
if ($getVoc !== 'all') {
echo $configVoc[$getVoc]['name'];
} else {
$names = array();
foreach ($spell['vocations'] as $id) {
if (isset($configVoc[$id]))
$names[] = $configVoc[$id]['name'];
}
echo implode(',<br>', $names);
}
}
?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<a href="#spells">Jump to top</a>
<?php endif; ?>
<?php
} else {
?>
<h1>Spells</h1>
<p>Spells have currently not been loaded into the website by the server admin.</p>
<?php
}
/* Debug tests
foreach ($spells as $type => $spells) {
data_dump($spells, false, "Type: $type");
}
// All spell attributes?
'group', 'words', 'lvl', 'level', 'maglv', 'magiclevel', 'charges', 'allowfaruse', 'blocktype', 'mana', 'soul', 'prem', 'aggressive', 'range', 'selftarget', 'needtarget', 'blockwalls', 'needweapon', 'exhaustion', 'groupcooldown', 'needlearn', 'casterTargetOrDirection', 'direction', 'params', 'playernameparam', 'conjureId', 'reagentId', 'conjureCount', 'vocations'
*/
include 'layout/overall/footer.php'; ?>