From fd419076c282a0b585bc90c0ba9aba7bab0ad8d3 Mon Sep 17 00:00:00 2001 From: Matheus Collier <50173479+matheuscollier@users.noreply.github.com> Date: Fri, 31 Mar 2023 04:04:13 -0300 Subject: [PATCH] [UPDATE] Adding monster looks to db (#220) * [UPDATE] Adding monster looks to db * small adjustments add into schema.sql + change position in table * add DEFAULT = '' --------- Co-authored-by: slawkens --- common.php | 2 +- install/includes/schema.sql | 3 ++- system/libs/creatures.php | 4 ++++ system/libs/pot/OTS_Monster.php | 28 ++++++++++++++++++++++++++++ system/migrations/35.php | 3 +++ 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 system/migrations/35.php diff --git a/common.php b/common.php index bcc66be3..fff55002 100644 --- a/common.php +++ b/common.php @@ -27,7 +27,7 @@ if (version_compare(phpversion(), '7.2.5', '<')) die('PHP version 7.2.5 or highe const MYAAC = true; const MYAAC_VERSION = '0.9.0-dev'; -const DATABASE_VERSION = 34; +const DATABASE_VERSION = 35; const TABLE_PREFIX = 'myaac_'; define('START_TIME', microtime(true)); define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX')); diff --git a/install/includes/schema.sql b/install/includes/schema.sql index 8a70d66a..83f4c051 100644 --- a/install/includes/schema.sql +++ b/install/includes/schema.sql @@ -1,4 +1,4 @@ -SET @myaac_database_version = 34; +SET @myaac_database_version = 35; CREATE TABLE `myaac_account_actions` ( @@ -203,6 +203,7 @@ CREATE TABLE `myaac_monsters` ( `mana` int(11) NOT NULL DEFAULT 0, `exp` int(11) NOT NULL, `health` int(11) NOT NULL, + `look` VARCHAR(255) NOT NULL DEFAULT '', `speed_lvl` int(11) NOT NULL default 1, `use_haste` tinyint(1) NOT NULL, `voices` text NOT NULL, diff --git a/system/libs/creatures.php b/system/libs/creatures.php index 95657a58..a9e76066 100644 --- a/system/libs/creatures.php +++ b/system/libs/creatures.php @@ -82,6 +82,9 @@ class Creatures { $armor = $monster->getArmor(); $defensev = $monster->getDefense(); + //load look + $look = $monster->getLook(); + //load monster flags $flags = $monster->getFlags(); if(!isset($flags['summonable'])) @@ -147,6 +150,7 @@ class Creatures { 'armor' => $armor, 'race' => $race, 'loot' => json_encode($loot), + 'look' => json_encode($look), 'summons' => json_encode($summons) )); diff --git a/system/libs/pot/OTS_Monster.php b/system/libs/pot/OTS_Monster.php index db35091f..a7e079ac 100644 --- a/system/libs/pot/OTS_Monster.php +++ b/system/libs/pot/OTS_Monster.php @@ -36,6 +36,7 @@ * @property-read int $armor Armor rate. * @property-read array $defenses List of defenses. * @property-read array $attacks List of attacks. + * @property-read array $look List of looks. */ class OTS_Monster extends DOMDocument { @@ -273,6 +274,30 @@ class OTS_Monster extends DOMDocument return $loot; } +/** + * Returns look of the monster. + * + * @return array Look with all the attributes of the look. + * @throws DOMException On DOM operation error. + */ + public function getLook() + { + $look = array(); + + $element = $this->documentElement->getElementsByTagName('look')->item(0); + + $look['type'] = $element->getAttribute('type'); + $look['typeex'] = $element->getAttribute('typeex'); + $look['head'] = $element->getAttribute('head'); + $look['body'] = $element->getAttribute('body'); + $look['legs'] = $element->getAttribute('legs'); + $look['feet'] = $element->getAttribute('feet'); + $look['addons'] = $element->getAttribute('addons'); + $look['corpse'] = $element->getAttribute('corpse'); + + return $look; + } + /** * Returns all monster summons. * @@ -560,6 +585,9 @@ class OTS_Monster extends DOMDocument case 'attacks': return $this->getAttacks(); + case 'look': + return $this->getLook(); + default: throw new OutOfBoundsException(); } diff --git a/system/migrations/35.php b/system/migrations/35.php new file mode 100644 index 00000000..8016807d --- /dev/null +++ b/system/migrations/35.php @@ -0,0 +1,3 @@ +exec('ALTER TABLE `' . TABLE_PREFIX . "monsters` ADD `look` VARCHAR(255) NOT NULL DEFAULT '' AFTER `health`;"); \ No newline at end of file