-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
items.php
394 lines (370 loc) · 12.2 KB
/
items.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php require_once 'engine/init.php'; include 'layout/overall/header.php';
if($config['items'] == true) {
// Loading equipable items list
$itemsCache = new Cache('engine/cache/items');
if (user_logged_in() && is_admin($user_data)) {
if (isset($_GET['update'])) {
echo "<p><strong>Logged in as admin, loading engine/XML/items.xml file and updating cache.</strong></p>";
// ITEMS XML TO PHP ARRAY
$itemsXML = simplexml_load_file("engine/XML/items.xml");
if ($itemsXML !== false) {
$types = array();
$type_attr = array();
$groups = array();
// This empty array will eventually contain all items grouped by type and indexed by item type
$items = array();
// Loop through each XML item object
foreach ($itemsXML as $type => $item) {
// Get item types
if (!in_array($type, $types)) {
$types[] = $type;
$type_attr[$type] = array();
}
// Get item attributes
$attributes = array();
// Extract attribute values from the XML object and store it in a more manage friendly way $attributes
foreach ($item->attributes() as $aName => $aValue)
$attributes["$aName"] = "$aValue";
// Remove unececsary attributes
if (isset($attributes['plural'])) unset($attributes['plural']);
//if (isset($attributes['id'])) unset($attributes['id']);
//if (isset($attributes['fromid'])) unset($attributes['fromid']);
//if (isset($attributes['toid'])) unset($attributes['toid']);
if (isset($attributes['editorsuffix'])) unset($attributes['editorsuffix']);
if (isset($attributes['article'])) unset($attributes['article']);
// Populate type attributes
foreach (array_keys($attributes) as $attr) {
if (!in_array($attr, $type_attr[$type]))
$type_attr[$type][] = $attr;
}
// Loop through every <attribute> object inside the <item> object
$item_attributes = array();
$iai = array();
foreach ($item as $attribute) {
foreach ($attribute->attributes() as $aName => $aValue) {
if($aName == 'key') {
$attribute_attributes["$aName"] = "$aValue";
$iai[] = $attribute_attributes[$aName];
}
}
}
foreach ($item as $attribute) {
foreach ($attribute->attributes() as $aName => $aValue) {
$attribute_attributes["$aName"] = "$aValue";
if(in_array($attribute_attributes[$aName], $iai)) {
$whatis = $attribute_attributes[$aName];
} else {
$item_attributes[$whatis] = (isset($attribute_attributes[$aName])) ? $attribute_attributes[$aName] : false;
}
}
}
foreach (array_keys($attributes) as $attr) {
if (!in_array($attr, $type_attr[$type]))
$type_attr[$type][] = $attr;
}
// Add items with slotType or weaponType (TFS 1.x default)
if(isset($attributes['id'])) $id = (isset($attributes['id'])) ? $attributes['id'] : false;
if(isset($attributes['fromid'])) $id = (isset($attributes['name'])) ? $attributes['name'] : false;
if (isset($item_attributes['slotType']) || isset($item_attributes['weaponType'])) {
$items[$type][$id] = array('attributes' => $item_attributes);
// Populate item array with potential relevant attributes for the item type
foreach ($type_attr[$type] as $att)
$items[$type][$id][$att] = (isset($attributes[$att])) ? $attributes[$att] : false;
}
$save = array($items);
}
$itemsCache->setContent($items);
$itemsCache->save();
} else {
echo "<p><strong>Failed to load engine/XML/items.xml file.</strong></p>";
}
} else {
$items = $itemsCache->load();
?>
<form action="">
<input type="submit" name="update" value="Generate new cache">
</form>
<?php
}
// END ITEMS XML TO PHP ARRAY
} else {
$items = $itemsCache->load();
}
// End loading items list
if ($items) {
// Preparing data
$types = array_keys($items);
$itemServer = 'http://'.$config['shop']['imageServer'].'/';
//slotType values and names
if(isset($_GET['slot'])) {
switch($_GET['slot']) {
case 'helmet':
$slottype = 'head';
$slottype_name = 'Helmets';
break;
case 'sword':
$slottype = 'sword';
$slottype_name = 'Swords';
break;
case 'distance':
$slottype = 'distance';
$slottype_name = 'Distance Weapons';
break;
case 'wand':
$slottype = 'wand';
$slottype_name = 'Wands & Rods';
break;
case 'armor':
$slottype = 'body';
$slottype_name = 'Armors';
break;
case 'club':
$slottype = 'club';
$slottype_name = 'Clubs';
break;
case 'ammunition':
$slottype = 'ammunition';
$slottype_name = 'Ammunition';
break;
case 'book':
$slottype = 'shield';
$slottype_name = 'Spellbooks';
break;
case 'legs':
$slottype = 'legs';
$slottype_name = 'Legs';
break;
case 'axe':
$slottype = 'axe';
$slottype_name = 'Axes';
break;
case 'necklace':
$slottype = 'necklace';
$slottype_name = 'Amulets & Necklaces';
break;
case 'feet':
$slottype = 'feet';
$slottype_name = 'Boots';
break;
case 'shield':
$slottype = 'shield';
$slottype_name = 'Shields & Spellbooks';
break;
case 'backpack':
$slottype = 'backpack';
$slottype_name = 'Backpacks';
break;
case 'ring':
$slottype = 'ring';
$slottype_name = 'Rings';
break;
default:
$slottype_name = 'null';
break;
}
}
// Render HTML
if(isset($_GET['slot']) && ($slottype_name == 'null')) header("Location:items.php");
?>
<h1 id="items">Items<?php if (isset($_GET['slot'])) echo ' ('.$slottype_name.')';?></h1>
<?php if(empty($_GET['slot'])) { ?>
<table>
<tbody>
<tr>
<td style="text-align:center;"><a href="?slot=helmet">Helmets<br><img src="<?php echo $itemServer.'2471.gif'; ?>" /></a></td>
<td style="text-align:center;"><a href="?slot=sword">Swords<br><img src="<?php echo $itemServer.'8931.gif'; ?>" /></a></td>
<td style="text-align:center;"><a href="?slot=shield">Shields & Spellbooks<br><img src="<?php echo $itemServer.'2523.gif'; ?>" /></a></td>
<td style="text-align:center;"><a href="?slot=necklace">Amulets<br><img src="<?php echo $itemServer.'2173.gif'; ?>" /></a></td>
</tr>
<tr>
<td style="text-align:center;"><a href="?slot=armor">Armors<br><img src="<?php echo $itemServer.'2466.gif'; ?>" /></a></td>
<td style="text-align:center;"><a href="?slot=club">Clubs<br><img src="<?php echo $itemServer.'2444.gif'; ?>" /></a></td>
<td style="text-align:center;"><a href="?slot=wand">Wands & Rods<br><img src="<?php echo $itemServer.'2190.gif'; ?>" /></a></td>
<td style="text-align:center;"><a href="?slot=ammunition">Ammunition<br><img src="<?php echo $itemServer.'6529.gif'; ?>" /></a></td>
</tr>
<tr>
<td style="text-align:center;"><a href="?slot=legs">Legs<br><img src="<?php echo $itemServer.'2470.gif'; ?>" /></a></td>
<td style="text-align:center;"><a href="?slot=axe">Axes<br><img src="<?php echo $itemServer.'8925.gif'; ?>" /></a></td>
<td style="text-align:center;"><a href="?slot=ring">Rings<br><img src="<?php echo $itemServer.'6093.gif'; ?>" /></a></td>
</tr>
<tr>
<td style="text-align:center;"><a href="?slot=feet">Boots<br><img src="<?php echo $itemServer.'2646.gif'; ?>" /></a></td>
<td style="text-align:center;"><a href="?slot=distance">Distance<br><img src="<?php echo $itemServer.'5803.gif'; ?>" /></a></td>
<td style="text-align:center;"><a href="?slot=backpack">Backpacks<br><img src="<?php echo $itemServer.'9774.gif'; ?>" /></a></td>
</tr>
</tbody>
</table>
<?php } else { ?>
<table>
<tbody>
<tr>
<td></td>
<td>Name</td>
<td>Attributes</td>
</tr>
<?php foreach ($items['item'] as $select) {
$attributes = array();
$extradef = NULL;
$element = NULL;
if (!empty($select['id'])) $itemid = $select['id'];
else $itemid = $select['fromid'];
if (!empty($select['attributes'])) {
foreach ($select['attributes'] as $att => $value) {
if($att == 'slotType' || $att == 'weaponType') $slotType = $value;
if(!empty($slotType) && $slotType == $slottype) $show = true;
else $show = false;
}
}
if($show == true) { ?>
<tr>
<td><img src="<?php echo $itemServer.$itemid.'.gif'; ?>" /></td>
<td><?php echo ucwords($select['name']); ?></td>
<td><?php
foreach ($select['attributes'] as $array => $value) {
$extra = NULL;
if($value > 0) $extra = '+';
switch ($array) {
case 'weight':
echo ucwords($array).': '.intval($value/100).'.'.substr($value, -2).' oz<br>';
break;
case 'containerSize':
echo 'Slots: '.$value.'<br>';
break;
case 'armor':
echo ucwords($array).': '.$value.'<br>';
break;
case 'attack':
echo ucwords($array).': '.$value;
if($element != NULL) echo ' ('.$element.')';
echo '<br>';
break;
case 'defense':
echo ucwords($array).': '.$value;
if($extradef != NULL) echo ' ('.$extradef.')';
echo '<br>';
break;
case 'skillFist':
echo 'Fist Fighting: '.$extra.$value.'<br>';
break;
case 'skillAxe':
echo 'Axe Fighting: '.$extra.$value.'<br>';
break;
case 'skillSword':
echo 'Sword Fighting: '.$extra.$value.'<br>';
break;
case 'skillClub':
echo 'Club Fighting: '.$extra.$value.'<br>';
break;
case 'skillAxe':
echo 'Axe Fighting: '.$extra.$value.'<br>';
break;
case 'skillDist':
echo 'Distance Fighting: '.$extra.$value.'<br>';
break;
case 'skillShield':
echo 'Shielding: '.$extra.$value.'<br>';
break;
case 'range':
echo ucwords($array).': '.$value.'<br>';
break;
case 'shootType':
echo 'Shoot Type: '.ucwords($value).'<br>';
break;
case 'hitChance':
echo 'Hit: '.$extra.$value.'%<br>';
break;
case 'magiclevelpoints':
echo 'Magic Level: '.$extra.$value.'<br>';
break;
case 'absorbPercentEnergy':
echo 'Energy Protection: '.$extra.$value.'%<br>';
break;
case 'absorbPercentFire':
echo 'Fire Protection: '.$extra.$value.'%<br>';
break;
case 'absorbPercentEarth':
echo 'Earth Protection: '.$extra.$value.'%<br>';
break;
case 'absorbPercentPoison':
echo 'Poison Protection: '.$extra.$value.'%<br>';
break;
case 'absorbPercentIce':
echo 'Ice Protection: '.$extra.$value.'%<br>';
break;
case 'absorbPercentHoly':
echo 'Holy Protection: '.$extra.$value.'%<br>';
break;
case 'absorbPercentDeath':
echo 'Death Protection: '.$extra.$value.'%<br>';
break;
case 'absorbPercentLifeDrain':
echo 'Life Drain Protection: '.$extra.$value.'%<br>';
break;
case 'absorbPercentManaDrain':
echo 'Mana Drain Protection: '.$extra.$value.'%<br>';
break;
case 'absorbPercentDrown':
echo 'Drown Protection: '.$extra.$value.'%<br>';
break;
case 'absorbPercentPhysical':
echo 'Physical Protection: '.$extra.$value.'%<br>';
break;
case 'absorbPercentIce':
echo 'Ice Protection: '.$extra.$value.'%<br>';
break;
/**case 'suppressDrunk':
echo 'Suppress Drunk: Yes<br>';
break;
case 'suppressEnergy':
echo 'Suppress Energy: Yes<br>';
break;
case 'suppressFire':
echo 'Suppress Fire: Yes<br>';
break;
case 'suppressPoison':
echo 'Suppress Poison: Yes<br>';
break;
case 'suppressDrown':
echo 'Suppress Drown: Yes<br>';
break;
case 'suppressPhysical':
echo 'Suppress Bleeding: Yes<br>';
break;
case 'suppressFreeze':
echo 'Suppress Freeze: Yes<br>';
break;
case 'suppressDazzle':
echo 'Suppress Dazzle: Yes<br>';
break;
case 'suppressCurse':
echo 'Suppress Curse: Yes<br>';
break;
Those are not necessary in my opinion, but if you want to show
**/
case 'speed':
echo 'Speed: '.$extra.($value/2).'<br>';
break;
case 'charges':
echo 'Charges: '.$value.'<br>';
break;
}
}
?>
</td>
</tr>
<?php
}
} ?>
</tbody>
</table>
<?php
}
} else { ?>
<h1>Items</h1>
<p>Items have currently not been loaded into the website by the server admin.</p>
<?php }
} else {
echo 'Items\' page not enabled.';
}
include 'layout/overall/footer.php';
?>