Inventory, * "amount" => int * ] */ public $essences = []; /** * @var int \Source[] Sources the monster can be get from. */ public $sources = []; /** * @var string Monster title. * If awakened, it will be the awakened from name. * If unawakened, it will be . */ public $title; /** * @var Monster_Transformation The transformation the monster can undergo. */ public $transformation; /** * Constructor. * * Searches the database and retrieves the information about the * monster, populating it and it's items. * * @param int $id Monster identifier. * @param bool $complete If false, query only monster. * @global resource Database connection. */ public function __construct($id, $complete = true){ global $db; $this->id = $id; $statement = $db->prepare(" SELECT id, family, name, element, archetype, base_stars, natural_stars, obtainable, can_awaken, awaken_bonus, skill_ups_to_max, leader_skill, hp, attack, defense, speed, crit_rate, crit_damage, resistance, accuracy, raw_hp, raw_attack, raw_defense, max_lvl_hp, max_lvl_attack, max_lvl_defense, awakens_from, awakens_to, fusion_food, homunculus, craft_cost FROM monster WHERE id = :id; "); $statement->bindValue(':id', $id, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->family = $r["family"]; $this->name = HTML::e($r["name"]); $this->element = $r["element"]; switch($this->element){ case ELEMENT_ID::WATER: $this->element_name = "Water"; break; case ELEMENT_ID::FIRE: $this->element_name = "Fire"; break; case ELEMENT_ID::WIND: $this->element_name = "Wind"; break; case ELEMENT_ID::LIGHT: $this->element_name = "Light"; break; case ELEMENT_ID::DARK: $this->element_name = "Dark"; break; } $this->archetype = $r["archetype"]; switch($this->archetype){ case ARCHETYPE_ID::ATTACK: $this->archetype_name = "Attack"; break; case ARCHETYPE_ID::DEFENSE: $this->archetype_name = "Defense"; break; case ARCHETYPE_ID::HP: $this->archetype_name = "HP"; break; case ARCHETYPE_ID::SUPPORT: $this->archetype_name = "Support"; break; case ARCHETYPE_ID::MATERIAL: $this->archetype_name = "Material"; break; } $this->base_stars = $r["base_stars"]; $this->natural_stars = $r["natural_stars"]; $this->obtainable = $r["obtainable"]; $this->can_awaken = $r["can_awaken"]; $this->awaken_bonus = HTML::e($r["awaken_bonus"]); $this->skill_ups_to_max = $r["skill_ups_to_max"]; if (strlen($r["leader_skill"]) > 0){ $this->leader_skill = new Leader_Skill($r["leader_skill"]); } $this->hp = $r["hp"]; $this->attack = $r["attack"]; $this->defense = $r["defense"]; $this->speed = $r["speed"]; $this->crit_rate = $r["crit_rate"]; $this->crit_damage = $r["crit_damage"]; $this->resistance = $r["resistance"]; $this->accuracy = $r["accuracy"]; $this->raw_hp = $r["raw_hp"]; $this->raw_attack = $r["raw_attack"]; $this->raw_defense = $r["raw_defense"]; $this->max_lvl_hp = $r["max_lvl_hp"]; $this->max_lvl_attack = $r["max_lvl_attack"]; $this->max_lvl_defense = $r["max_lvl_defense"]; $this->awakens_from = $r["awakens_from"]; $this->awakens_to = $r["awakens_to"]; $this->fusion_food = $r["fusion_food"]; $this->homunculus = $r["homunculus"]; $this->craft_cost = $r["craft_cost"]; } if ($complete){ $this->load_essences(); $this->load_skills(); $this->load_sources(); $this->load_transformation(); } // Guess monster name if ($this->awakens_from == "" && $this->awakens_to == ""){ // No to, no from. Silver monster. if ($this->base_stars >= 4){ // SFV Collab event monsters, always awakened. $this->title = $this->name; } elseif($this->archetype == ARCHETYPE_ID::MATERIAL && $this->element == ELEMENT_ID::LIGHT){ // Rainbowmon, always awakened $this->title = $this->name; } elseif($this->archetype == ARCHETYPE_ID::MATERIAL && $this->element == ELEMENT_ID::DARK){ // Devilmon, always unawakened, but dont include element $this->title = $this->name; } else{ // Unawakeable monster $this->title = $this->element_name . " " . $this->name; } } // Awakened elseif ($this->awakens_from != ""){ $this->title = $this->name; } // Gold elseif (strlen($this->awakens_to) > 0){ $this->title = $this->element_name . " " . $this->name; } } /** * Loads the information about the essences to awake the monster. * * It is autoatically called at construction time if the * $complete parameter is true (by default). No point in calling it * twice. * * @global resource Database connection. */ public function load_essences(){ global $db; $this->essences = []; $statement = $db->prepare(" SELECT item, amount FROM monster_essence WHERE monster = :monster ORDER BY item; "); $statement->bindValue(':monster', $this->id, SQLITE3_TEXT); $q = $statement->execute(); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ $e = [ "item" => new Inventory($r["item"], INVENTORY_TYPE_ID::ESSENCES), "amount" => $r["amount"] ]; array_push($this->essences, $e); } } /** * Loads the monster transformation. * * It is automatically called at construction time if the * $complete parameter is true (by default). No point in calling it * twice. * * @global resource Database connection. */ public function load_transformation(){ global $db; $this->transformation = null; $statement = $db->prepare(" SELECT id FROM monster_transformation WHERE monster = :monster; "); $statement->bindValue(':monster', $this->id, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->transformation = new Monster_Transformation($r["id"]); } } /** * Loads the information about the monster skills. * * It is autoatically called at construction time if the * $complete parameter is true (by default). No point in calling it * twice. * * @global resource Database connection. */ public function load_skills(){ global $db; $this->skill = []; $statement = $db->prepare(" SELECT skill.id AS skill FROM skill, monster_skill WHERE skill.id = monster_skill.skill AND monster_skill.monster = :monster ORDER BY slot; "); $statement->bindValue(':monster', $this->id, SQLITE3_TEXT); $q = $statement->execute(); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->skill, new Skill($r["skill"])); } } /** * Loads the information about the monster sources. * * It is autoatically called at construction time if the * $complete parameter is true (by default). No point in calling it * twice. * * @global resource Database connection. */ public function load_sources(){ global $db; $this->sources = []; $statement = $db->prepare(" SELECT source FROM monster_source WHERE monster = :monster; "); $statement->bindValue(':monster', $this->id, SQLITE3_TEXT); $q = $statement->execute(); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->sources, new Source($r["source"])); } } /** * Gets the path to the monster image. The image must be in the * img/monster/ directory, and it's name must be the monster id, * padded with '0' to 8 digits, and the extension must be '.png'. * * @return string Image URL, or a fixed unknown image. */ public function get_image(){ return APPLICATION::img("UNIT", $this->id); } } ?>