From 6a17b7e2caa8e1a67c5c761d4c426291940c3dff Mon Sep 17 00:00:00 2001 From: Znote Date: Sun, 5 Feb 2017 05:52:40 +0100 Subject: [PATCH] Spells page with vocation filters. Login as an admin to parse engine/XML/spells.xml file and create a cached copy of it, which will be served to the visitors. --- engine/XML/spells.xml | 745 ++++++++++++++++++++++++++++++++++++++++++ layout/menu.php | 1 + spells.php | 247 ++++++++++++++ 3 files changed, 993 insertions(+) create mode 100644 engine/XML/spells.xml create mode 100644 spells.php diff --git a/engine/XML/spells.xml b/engine/XML/spells.xml new file mode 100644 index 0000000..57d1fad --- /dev/null +++ b/engine/XML/spells.xml @@ -0,0 +1,745 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/layout/menu.php b/layout/menu.php index 8097da1..9f8be20 100644 --- a/layout/menu.php +++ b/layout/menu.php @@ -12,6 +12,7 @@
  • Houses
  • Deaths
  • Killers
  • +
  • Spells
  • Forum
  • diff --git a/spells.php b/spells.php new file mode 100644 index 0000000..fe21cb9 --- /dev/null +++ b/spells.php @@ -0,0 +1,247 @@ +Logged in as admin, loading engine/XML/spells.xml file and updating cache.

    "; + // 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']); + // 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"; + } + } + } + // 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 "

    Failed to load engine/XML/spells.xml file.

    "; + } + } else { + $spells = $spellsCache->load(); + ?> +
    + +
    + load(); +} +// End loading spell list + +// 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 +?> + +

    Spells

    + +
    + + + +
    + +

    Spell types:

    + + +

    Instant Spells

    +Jump to top + + + + + + + + + + + + + + + + + + + +
    NameWordsLevelManaVocations
    ', $names); + } + ?>
    + +

    Magical Runes

    +Jump to top + + + + + + + + + + + + + + + + + + + +
    NameLevelMagic LevelImageVocations
    Rune image', $names); + } + ?>
    + +

    Conjure Spells

    +Jump to top + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameWordsLevelManaSoulChargesImageVocations
    Rune image', $names); + } + ?>
    +Jump to top + $spells) { + data_dump($spells, false, "Type: $type"); +} + +// All spell attributes? +'group', 'words', 'lvl', 'maglv', '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'; ?> \ No newline at end of file