From 81b6652738a7b04be3980cbf55443a6fbe437b34 Mon Sep 17 00:00:00 2001 From: slawkens Date: Wed, 5 Jun 2024 21:58:44 +0200 Subject: [PATCH] Fix if is not present in monster.xml --- system/libs/pot/OTS_Monster.php | 75 +++++++++++++++++---------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/system/libs/pot/OTS_Monster.php b/system/libs/pot/OTS_Monster.php index d498714f..d5a24223 100644 --- a/system/libs/pot/OTS_Monster.php +++ b/system/libs/pot/OTS_Monster.php @@ -15,11 +15,11 @@ /** * Wrapper for monsters files DOMDocument. - * + * *

* Note: as this class extends {@link http://www.php.net/manual/en/ref.dom.php DOMDocument class} and contains exacly file XML tree you can work on it as on normal DOM tree. *

- * + * * @package POT * @version 0.1.3 * @property-read string $name Monster name. @@ -44,14 +44,14 @@ class OTS_Monster extends DOMDocument { $this->loaded = parent::loadXML($source, $options); } - + public function loaded() { return $this->loaded; } /** * Returns monster name. - * + * * @return string Name. * @throws DOMException On DOM operation error. */ @@ -62,7 +62,7 @@ class OTS_Monster extends DOMDocument /** * Returns monster race. - * + * * @return string Race. * @throws DOMException On DOM operation error. */ @@ -73,7 +73,7 @@ class OTS_Monster extends DOMDocument /** * Returns amount of experience for killing this monster. - * + * * @return int Experience points. * @throws DOMException On DOM operation error. */ @@ -84,7 +84,7 @@ class OTS_Monster extends DOMDocument /** * Returns monster speed. - * + * * @return int Speed. * @throws DOMException On DOM operation error. */ @@ -95,7 +95,7 @@ class OTS_Monster extends DOMDocument /** * Returns amount of mana required to summon this monster. - * + * * @return int|bool Mana required (false if not possible). * @throws DOMException On DOM operation error. */ @@ -114,7 +114,7 @@ class OTS_Monster extends DOMDocument /** * Returns monster HP. - * + * * @return int Hit points. * @throws DOMException On DOM operation error. */ @@ -125,28 +125,29 @@ class OTS_Monster extends DOMDocument /** * Returns all monster flags (in format flagname => value). - * + * * @return array Flags. * @throws DOMException On DOM operation error. */ - public function getFlags() - { - $flags = array(); + public function getFlags() + { + $flags = array(); - // read all flags - foreach( $this->documentElement->getElementsByTagName('flags')->item(0)->getElementsByTagName('flag') as $flag) - { - $flag = $flag->attributes->item(0); + if ($this->documentElement->getElementsByTagName('flags')->item(0)) { + foreach( $this->documentElement->getElementsByTagName('flags')->item(0)->getElementsByTagName('flag') as $flag) + { + $flag = $flag->attributes->item(0); - $flags[$flag->nodeName] = (int) $flag->nodeValue; - } + $flags[$flag->nodeName] = (int) $flag->nodeValue; + } + } - return $flags; - } + return $flags; + } /** * Returns specified flag value. - * + * * @param string $flag Flag. * @return int|bool Flag value (false if not set). * @throws DOMException On DOM operation error. @@ -169,7 +170,7 @@ class OTS_Monster extends DOMDocument /** * Returns voices that monster can sound. - * + * * @return array List of voices. * @throws DOMException On DOM operation error. */ @@ -214,17 +215,17 @@ class OTS_Monster extends DOMDocument $chance = 100000; } } - + $count = $item->getAttribute('countmax'); if(empty($count)) { $count = 1; } - + $id = $item->getAttribute('id'); if(empty($id)) { $id = $item->getAttribute('name'); } - + $loot[] = array('id' => $id, 'count' => $count, 'chance' => $chance); } } @@ -234,11 +235,11 @@ class OTS_Monster extends DOMDocument /** * Returns all possible loot. - * + * *

* In order to use this method you have to have global items list loaded. *

- * + * * @version 0.1.0 * @since 0.1.0 * @return array List of item types. @@ -275,7 +276,7 @@ class OTS_Monster extends DOMDocument /** * Returns all monster immunities. - * + * * @return array Immunities. * @throws DOMException On DOM operation error. */ @@ -306,7 +307,7 @@ class OTS_Monster extends DOMDocument /** * Checks if monster has given immunity. - * + * * @param string $name Immunity to check. * @return bool Immunity state. * @throws DOMException On DOM operation error. @@ -334,7 +335,7 @@ class OTS_Monster extends DOMDocument /** * Returns monster defense rate. - * + * * @return int Defense rate. * @throws DOMException On DOM operation error. */ @@ -353,7 +354,7 @@ class OTS_Monster extends DOMDocument /** * Returns monster armor. - * + * * @return int Armor rate. * @throws DOMException On DOM operation error. */ @@ -372,7 +373,7 @@ class OTS_Monster extends DOMDocument /** * Returns list of special defenses. - * + * * @return array List of defense effects. * @throws DOMException On DOM operation error. */ @@ -396,7 +397,7 @@ class OTS_Monster extends DOMDocument /** * Returns list of monster attacks. - * + * * @return array List of attafck effects. * @throws DOMException On DOM operation error. */ @@ -420,7 +421,7 @@ class OTS_Monster extends DOMDocument /** * Magic PHP5 method. - * + * * @version 0.1.0 * @since 0.1.0 * @param string $name Property name. @@ -481,11 +482,11 @@ class OTS_Monster extends DOMDocument /** * Returns string representation of XML. - * + * *

* If any display driver is currently loaded then it uses it's method. Otherwise just returns monster XML content. *

- * + * * @version 0.1.3 * @since 0.1.0 * @return string String representation of object.