grilo13
RAWR
I'm using spells.php from @Znote as my base, and trying to do a "items.php", where players will be able to see eq. items in server, but I just import the items' ID, Name and Prefix. (Example from the cache generated)
I'd like to know how to also add all the "attribute" values (as weight, armor, slotType).
My code in this moment:
And I'll also add a Pull Request when I finish it.
Code:
{"id":"2472","name":"magic plate armor","article":"a"},{"id":"2474","name":"winged helmet","article":"a"},{"id":"2475","name":"warrior helmet","article":"a"}
I'd like to know how to also add all the "attribute" values (as weight, armor, slotType).
My code in this moment:
PHP:
<?php require_once 'engine/init.php'; include 'layout/overall/header.php';
// Loading item 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>";
// SPELLS 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 spell object
foreach ($itemsXML as $type => $item) {
// Get item 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 ($item->attributes() as $aName => $aValue)
$attributes["$aName"] = "$aValue";
// Remove unececsary attributes
if (isset($attributes['plural'])) unset($attributes['plural']);
if (isset($attributes['fromid'])) unset($attributes['fromid']);
if (isset($attributes['toid'])) unset($attributes['toid']);
if (isset($attributes['editorsuffix'])) unset($attributes['editorsuffix']);
//if (isset($attributes['itemid'])) unset($attributes['itemid']);
//if (isset($attributes['id'])) unset($attributes['id']);
//if (isset($attributes['conjureId'])) unset($attributes['conjureId']);
//if (isset($attributes['function'])) unset($attributes['function']);
// Populate type attributes
foreach (array_keys($attributes) as $attr) {
if (!in_array($attr, $type_attr[$type]))
$type_attr[$type][] = $attr;
}
// I have no idea what I did below here
// Exclude monster spells (Monster spells looks like this on the ORTS data pack)
$slotType = (isset($attributes['slotType'])) ? $attributes['slotType'] : false;
// Also exclude "house spells" such as aleta sio.
$name = (isset($attributes['name'])) ? $attributes['name'] : false;
if (substr($slotType, 0, 3) == NULL ) {
// Populate spell array with potential relevant attributes for the spell type
foreach ($type_attr[$type] as $att)
$items[$type][$name][$att] = (isset($attributes[$att])) ? $attributes[$att] : false;
}
}
// Will sort the items later
// Sort the spell list properly
foreach (array_keys($items) as $type) {
usort($items[$type], function ($a, $b) {
if (isset($a['lvl']))
return $a['lvl'] - $b['lvl'];
if (isset($a['maglv']))
return $a['maglv'] - $b['maglv'];
return -1;
});
}
$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 SPELLS XML TO PHP ARRAY
} else {
$items = $itemsCache->load();
}
// End loading spell list
if ($items) {
// Preparing data
$configVoc = $config['vocations'];
$types = array_keys($items);
$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 ($items[$type] as $name => $item)
if (!empty($item['vocations']))
if (!in_array($getVoc, $item['vocations']))
unset($items[$type][$name]);
}
// Render HTML
?>
HTML Not done yet
<?php
}
include 'layout/overall/footer.php'; ?>