Skip to content

Commit 81b6652

Browse files
committed
Fix if <flags> is not present in monster.xml
1 parent e5b4d2c commit 81b6652

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

system/libs/pot/OTS_Monster.php

+38-37
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
/**
1717
* Wrapper for monsters files DOMDocument.
18-
*
18+
*
1919
* <p>
2020
* 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.
2121
* </p>
22-
*
22+
*
2323
* @package POT
2424
* @version 0.1.3
2525
* @property-read string $name Monster name.
@@ -44,14 +44,14 @@ public function loadXML($source , $options = 0)
4444
{
4545
$this->loaded = parent::loadXML($source, $options);
4646
}
47-
47+
4848
public function loaded()
4949
{
5050
return $this->loaded;
5151
}
5252
/**
5353
* Returns monster name.
54-
*
54+
*
5555
* @return string Name.
5656
* @throws DOMException On DOM operation error.
5757
*/
@@ -62,7 +62,7 @@ public function getName()
6262

6363
/**
6464
* Returns monster race.
65-
*
65+
*
6666
* @return string Race.
6767
* @throws DOMException On DOM operation error.
6868
*/
@@ -73,7 +73,7 @@ public function getRace()
7373

7474
/**
7575
* Returns amount of experience for killing this monster.
76-
*
76+
*
7777
* @return int Experience points.
7878
* @throws DOMException On DOM operation error.
7979
*/
@@ -84,7 +84,7 @@ public function getExperience()
8484

8585
/**
8686
* Returns monster speed.
87-
*
87+
*
8888
* @return int Speed.
8989
* @throws DOMException On DOM operation error.
9090
*/
@@ -95,7 +95,7 @@ public function getSpeed()
9595

9696
/**
9797
* Returns amount of mana required to summon this monster.
98-
*
98+
*
9999
* @return int|bool Mana required (false if not possible).
100100
* @throws DOMException On DOM operation error.
101101
*/
@@ -114,7 +114,7 @@ public function getManaCost()
114114

115115
/**
116116
* Returns monster HP.
117-
*
117+
*
118118
* @return int Hit points.
119119
* @throws DOMException On DOM operation error.
120120
*/
@@ -125,28 +125,29 @@ public function getHealth()
125125

126126
/**
127127
* Returns all monster flags (in format flagname => value).
128-
*
128+
*
129129
* @return array Flags.
130130
* @throws DOMException On DOM operation error.
131131
*/
132-
public function getFlags()
133-
{
134-
$flags = array();
132+
public function getFlags()
133+
{
134+
$flags = array();
135135

136-
// read all flags
137-
foreach( $this->documentElement->getElementsByTagName('flags')->item(0)->getElementsByTagName('flag') as $flag)
138-
{
139-
$flag = $flag->attributes->item(0);
136+
if ($this->documentElement->getElementsByTagName('flags')->item(0)) {
137+
foreach( $this->documentElement->getElementsByTagName('flags')->item(0)->getElementsByTagName('flag') as $flag)
138+
{
139+
$flag = $flag->attributes->item(0);
140140

141-
$flags[$flag->nodeName] = (int) $flag->nodeValue;
142-
}
141+
$flags[$flag->nodeName] = (int) $flag->nodeValue;
142+
}
143+
}
143144

144-
return $flags;
145-
}
145+
return $flags;
146+
}
146147

147148
/**
148149
* Returns specified flag value.
149-
*
150+
*
150151
* @param string $flag Flag.
151152
* @return int|bool Flag value (false if not set).
152153
* @throws DOMException On DOM operation error.
@@ -169,7 +170,7 @@ public function getFlag($flag)
169170

170171
/**
171172
* Returns voices that monster can sound.
172-
*
173+
*
173174
* @return array List of voices.
174175
* @throws DOMException On DOM operation error.
175176
*/
@@ -214,17 +215,17 @@ public function getLoot()
214215
$chance = 100000;
215216
}
216217
}
217-
218+
218219
$count = $item->getAttribute('countmax');
219220
if(empty($count)) {
220221
$count = 1;
221222
}
222-
223+
223224
$id = $item->getAttribute('id');
224225
if(empty($id)) {
225226
$id = $item->getAttribute('name');
226227
}
227-
228+
228229
$loot[] = array('id' => $id, 'count' => $count, 'chance' => $chance);
229230
}
230231
}
@@ -234,11 +235,11 @@ public function getLoot()
234235

235236
/**
236237
* Returns all possible loot.
237-
*
238+
*
238239
* <p>
239240
* In order to use this method you have to have global items list loaded.
240241
* </p>
241-
*
242+
*
242243
* @version 0.1.0
243244
* @since 0.1.0
244245
* @return array List of item types.
@@ -275,7 +276,7 @@ public function getItems()
275276

276277
/**
277278
* Returns all monster immunities.
278-
*
279+
*
279280
* @return array Immunities.
280281
* @throws DOMException On DOM operation error.
281282
*/
@@ -306,7 +307,7 @@ public function getImmunities()
306307

307308
/**
308309
* Checks if monster has given immunity.
309-
*
310+
*
310311
* @param string $name Immunity to check.
311312
* @return bool Immunity state.
312313
* @throws DOMException On DOM operation error.
@@ -334,7 +335,7 @@ public function hasImmunity($name)
334335

335336
/**
336337
* Returns monster defense rate.
337-
*
338+
*
338339
* @return int Defense rate.
339340
* @throws DOMException On DOM operation error.
340341
*/
@@ -353,7 +354,7 @@ public function getDefense()
353354

354355
/**
355356
* Returns monster armor.
356-
*
357+
*
357358
* @return int Armor rate.
358359
* @throws DOMException On DOM operation error.
359360
*/
@@ -372,7 +373,7 @@ public function getArmor()
372373

373374
/**
374375
* Returns list of special defenses.
375-
*
376+
*
376377
* @return array List of defense effects.
377378
* @throws DOMException On DOM operation error.
378379
*/
@@ -396,7 +397,7 @@ public function getDefenses()
396397

397398
/**
398399
* Returns list of monster attacks.
399-
*
400+
*
400401
* @return array List of attafck effects.
401402
* @throws DOMException On DOM operation error.
402403
*/
@@ -420,7 +421,7 @@ public function getAttacks()
420421

421422
/**
422423
* Magic PHP5 method.
423-
*
424+
*
424425
* @version 0.1.0
425426
* @since 0.1.0
426427
* @param string $name Property name.
@@ -481,11 +482,11 @@ public function __get($name)
481482

482483
/**
483484
* Returns string representation of XML.
484-
*
485+
*
485486
* <p>
486487
* If any display driver is currently loaded then it uses it's method. Otherwise just returns monster XML content.
487488
* </p>
488-
*
489+
*
489490
* @version 0.1.3
490491
* @since 0.1.0
491492
* @return string String representation of object.

0 commit comments

Comments
 (0)