Creature page overhaul

Updates the creature pages to show more information.
You will need to reload your creatures.
-modifies database with migration 31
-small customisations are allowed via config file.
-functions added, getMonsterLink, getItemRarity, getCreatureImgPath, left, right,
-added functions to twig.
-view elements, immunities, summons, voices, loot, pushables, canpush, canwalk, runonhealth,hostile,attackable,rewardboss,defense,armor
-filter bosses
-show list as picture preview or names list
This commit is contained in:
Lee
2020-12-28 16:37:03 +00:00
parent 7e0fded595
commit 8e6bc73ca6
11 changed files with 559 additions and 156 deletions

View File

@@ -79,6 +79,8 @@ class Creatures {
//load race
$race = $monster->getRace();
$armor = $monster->getArmor();
$defensev = $monster->getDefense();
//load monster flags
$flags = $monster->getFlags();
@@ -87,6 +89,28 @@ class Creatures {
if(!isset($flags['convinceable']))
$flags['convinceable'] = '0';
if(!isset($flags['pushable']))
$flags['pushable'] = '0';
if(!isset($flags['canpushitems']))
$flags['canpushitems'] = '0';
if(!isset($flags['canpushcreatures']))
$flags['canpushcreatures'] = '0';
if(!isset($flags['runonhealth']))
$flags['runonhealth'] = '0';
if(!isset($flags['canwalkonenergy']))
$flags['canwalkonenergy'] = '0';
if(!isset($flags['canwalkonpoison']))
$flags['canwalkonpoison'] = '0';
if(!isset($flags['canwalkonfire']))
$flags['canwalkonfire'] = '0';
if(!isset($flags['hostile']))
$flags['hostile'] = '0';
if(!isset($flags['attackable']))
$flags['attackable'] = '0';
if(!isset($flags['rewardboss']))
$flags['rewardboss'] = '0';
$summons = $monster->getSummons();
$loot = $monster->getLoot();
foreach($loot as &$item) {
if(!Validator::number($item['id'])) {
@@ -105,11 +129,25 @@ class Creatures {
'speed_lvl' => $speed_lvl,
'use_haste' => $use_haste,
'voices' => json_encode($monster->getVoices()),
'immunities' => json_encode($monster->getImmunities()),
'immunities' => json_encode($monster->getImmunities()),
'elements' => json_encode($monster->getElements()),
'summonable' => $flags['summonable'] > 0 ? 1 : 0,
'convinceable' => $flags['convinceable'] > 0 ? 1 : 0,
'pushable' => $flags['pushable'] > 0 ? 1 : 0,
'canpushitems' => $flags['canpushitems'] > 0 ? 1 : 0,
'canpushcreatures' => $flags['canpushcreatures'] > 0 ? 1 : 0,
'runonhealth' => $flags['runonhealth'] > 0 ? 1 : 0,
'canwalkonenergy' => $flags['canwalkonenergy'] > 0 ? 1 : 0,
'canwalkonpoison' => $flags['canwalkonpoison'] > 0 ? 1 : 0,
'canwalkonfire' => $flags['canwalkonfire'] > 0 ? 1 : 0,
'hostile' => $flags['hostile'] > 0 ? 1 : 0,
'attackable' => $flags['attackable'] > 0 ? 1 : 0,
'rewardboss' => $flags['rewardboss'] > 0 ? 1 : 0,
'defense' => $defensev,
'armor' => $armor,
'race' => $race,
'loot' => json_encode($loot)
'loot' => json_encode($loot),
'summons' => json_encode($summons)
));
if($show) {
@@ -136,4 +174,4 @@ class Creatures {
public static function getLastError() {
return self::$lastError;
}
}
}

View File

@@ -15,11 +15,11 @@
/**
* Wrapper for monsters files DOMDocument.
*
*
* <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.
* </p>
*
*
* @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,7 +125,7 @@ class OTS_Monster extends DOMDocument
/**
* Returns all monster flags (in format flagname => value).
*
*
* @return array Flags.
* @throws DOMException On DOM operation error.
*/
@@ -146,7 +146,7 @@ class OTS_Monster extends DOMDocument
/**
* 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 +169,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 +214,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 +234,11 @@ class OTS_Monster extends DOMDocument
/**
* Returns all possible loot.
*
*
* <p>
* In order to use this method you have to have global items list loaded.
* </p>
*
*
* @version 0.1.0
* @since 0.1.0
* @return array List of item types.
@@ -273,9 +273,95 @@ class OTS_Monster extends DOMDocument
return $loot;
}
/**
* Returns all monster summons.
*
* @return array elements.
* @throws DOMException On DOM operation error.
*/
public function getSummons()
{
$summons = array();
$element = $this->documentElement->getElementsByTagName('summons')->item(0);
// checks if it has any Summons
if( isset($element) )
{
// adds all summons
foreach( $element->getElementsByTagName('summon') as $item)
{
$chance = $item->getAttribute('chance');
$id = $item->getAttribute('name');
$summons[] = array('name' => $id, 'chance' => $chance);
}
}
return $summons;
}
/**
* Returns all monster elements.
*
* @return array elements.
* @throws DOMException On DOM operation error.
*/
public function getElements()
{
$elements = array();
$element = $this->documentElement->getElementsByTagName('elements')->item(0);
// checks if it has any elements
if( isset($element) )
{
// read all elements
foreach( $element->getElementsByTagName('element') as $elementv)
{
$elementv = $elementv->attributes->item(0);
// checks if element is set
if($elementv->nodeValue > 0)
{
$elements[] = array('name' => ucfirst(str_replace('Percent', '', $elementv->nodeName)), 'percent' => $elementv->nodeValue);
}
}
}
return $elements;
}
/**
* Checks if monster has given element.
*
* @param string $name element to check.
* @return bool element state.
* @throws DOMException On DOM operation error.
*/
public function hasElement($name)
{
$element = $this->documentElement->getElementsByTagName('elements')->item(0);
// if doesn't have any elements obviously doesn't have this one too
if( isset($element) )
{
// read all elements
foreach( $element->getElementsByTagName('element') as $element)
{
// checks if this is what we are searching for
if( $element->hasAttribute($name) )
{
return $element->getAttribute($name) > 0;
}
}
}
return false;
}
/**
* Returns all monster immunities.
*
*
* @return array Immunities.
* @throws DOMException On DOM operation error.
*/
@@ -306,7 +392,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 +420,7 @@ class OTS_Monster extends DOMDocument
/**
* Returns monster defense rate.
*
*
* @return int Defense rate.
* @throws DOMException On DOM operation error.
*/
@@ -353,7 +439,7 @@ class OTS_Monster extends DOMDocument
/**
* Returns monster armor.
*
*
* @return int Armor rate.
* @throws DOMException On DOM operation error.
*/
@@ -372,7 +458,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 +482,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 +506,7 @@ class OTS_Monster extends DOMDocument
/**
* Magic PHP5 method.
*
*
* @version 0.1.0
* @since 0.1.0
* @param string $name Property name.
@@ -481,11 +567,11 @@ class OTS_Monster extends DOMDocument
/**
* Returns string representation of XML.
*
*
* <p>
* If any display driver is currently loaded then it uses it's method. Otherwise just returns monster XML content.
* </p>
*
*
* @version 0.1.3
* @since 0.1.0
* @return string String representation of object.