Fix if <flags> is not present in monster.xml

This commit is contained in:
slawkens 2024-06-05 21:58:44 +02:00
parent e5b4d2c6b3
commit 81b6652738

View File

@ -15,11 +15,11 @@
/** /**
* Wrapper for monsters files DOMDocument. * Wrapper for monsters files DOMDocument.
* *
* <p> * <p>
* 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. * 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.
* </p> * </p>
* *
* @package POT * @package POT
* @version 0.1.3 * @version 0.1.3
* @property-read string $name Monster name. * @property-read string $name Monster name.
@ -44,14 +44,14 @@ class OTS_Monster extends DOMDocument
{ {
$this->loaded = parent::loadXML($source, $options); $this->loaded = parent::loadXML($source, $options);
} }
public function loaded() public function loaded()
{ {
return $this->loaded; return $this->loaded;
} }
/** /**
* Returns monster name. * Returns monster name.
* *
* @return string Name. * @return string Name.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
@ -62,7 +62,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns monster race. * Returns monster race.
* *
* @return string Race. * @return string Race.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
@ -73,7 +73,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns amount of experience for killing this monster. * Returns amount of experience for killing this monster.
* *
* @return int Experience points. * @return int Experience points.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
@ -84,7 +84,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns monster speed. * Returns monster speed.
* *
* @return int Speed. * @return int Speed.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
@ -95,7 +95,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns amount of mana required to summon this monster. * Returns amount of mana required to summon this monster.
* *
* @return int|bool Mana required (false if not possible). * @return int|bool Mana required (false if not possible).
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
@ -114,7 +114,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns monster HP. * Returns monster HP.
* *
* @return int Hit points. * @return int Hit points.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
@ -125,28 +125,29 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns all monster flags (in format flagname => value). * Returns all monster flags (in format flagname => value).
* *
* @return array Flags. * @return array Flags.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
public function getFlags() public function getFlags()
{ {
$flags = array(); $flags = array();
// read all flags if ($this->documentElement->getElementsByTagName('flags')->item(0)) {
foreach( $this->documentElement->getElementsByTagName('flags')->item(0)->getElementsByTagName('flag') as $flag) foreach( $this->documentElement->getElementsByTagName('flags')->item(0)->getElementsByTagName('flag') as $flag)
{ {
$flag = $flag->attributes->item(0); $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. * Returns specified flag value.
* *
* @param string $flag Flag. * @param string $flag Flag.
* @return int|bool Flag value (false if not set). * @return int|bool Flag value (false if not set).
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
@ -169,7 +170,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns voices that monster can sound. * Returns voices that monster can sound.
* *
* @return array List of voices. * @return array List of voices.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
@ -214,17 +215,17 @@ class OTS_Monster extends DOMDocument
$chance = 100000; $chance = 100000;
} }
} }
$count = $item->getAttribute('countmax'); $count = $item->getAttribute('countmax');
if(empty($count)) { if(empty($count)) {
$count = 1; $count = 1;
} }
$id = $item->getAttribute('id'); $id = $item->getAttribute('id');
if(empty($id)) { if(empty($id)) {
$id = $item->getAttribute('name'); $id = $item->getAttribute('name');
} }
$loot[] = array('id' => $id, 'count' => $count, 'chance' => $chance); $loot[] = array('id' => $id, 'count' => $count, 'chance' => $chance);
} }
} }
@ -234,11 +235,11 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns all possible loot. * Returns all possible loot.
* *
* <p> * <p>
* In order to use this method you have to have global items list loaded. * In order to use this method you have to have global items list loaded.
* </p> * </p>
* *
* @version 0.1.0 * @version 0.1.0
* @since 0.1.0 * @since 0.1.0
* @return array List of item types. * @return array List of item types.
@ -275,7 +276,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns all monster immunities. * Returns all monster immunities.
* *
* @return array Immunities. * @return array Immunities.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
@ -306,7 +307,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Checks if monster has given immunity. * Checks if monster has given immunity.
* *
* @param string $name Immunity to check. * @param string $name Immunity to check.
* @return bool Immunity state. * @return bool Immunity state.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
@ -334,7 +335,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns monster defense rate. * Returns monster defense rate.
* *
* @return int Defense rate. * @return int Defense rate.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
@ -353,7 +354,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns monster armor. * Returns monster armor.
* *
* @return int Armor rate. * @return int Armor rate.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
@ -372,7 +373,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns list of special defenses. * Returns list of special defenses.
* *
* @return array List of defense effects. * @return array List of defense effects.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
@ -396,7 +397,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns list of monster attacks. * Returns list of monster attacks.
* *
* @return array List of attafck effects. * @return array List of attafck effects.
* @throws DOMException On DOM operation error. * @throws DOMException On DOM operation error.
*/ */
@ -420,7 +421,7 @@ class OTS_Monster extends DOMDocument
/** /**
* Magic PHP5 method. * Magic PHP5 method.
* *
* @version 0.1.0 * @version 0.1.0
* @since 0.1.0 * @since 0.1.0
* @param string $name Property name. * @param string $name Property name.
@ -481,11 +482,11 @@ class OTS_Monster extends DOMDocument
/** /**
* Returns string representation of XML. * Returns string representation of XML.
* *
* <p> * <p>
* If any display driver is currently loaded then it uses it's method. Otherwise just returns monster XML content. * If any display driver is currently loaded then it uses it's method. Otherwise just returns monster XML content.
* </p> * </p>
* *
* @version 0.1.3 * @version 0.1.3
* @since 0.1.0 * @since 0.1.0
* @return string String representation of object. * @return string String representation of object.