0, "atk" => 0, "def" => 0, "spd" => 0, "crr" => 0, "crd" => 0, "acc" => 0, "res" => 0, ); private $raw_stats = array( "hp" => 0, "atk" => 0, "def" => 0, "spd" => 0, "crr" => 0, "crd" => 0, "acc" => 0, "res" => 0, ); private $max_level_statss = array( "hp" => 0, "atk" => 0, "def" => 0, "spd" => 0, "crr" => 0, "crd" => 0, "acc" => 0, "res" => 0, ); private $awakens_from; private $awakens_to; private $fusion_food; private $homunculus; private $craft_cost; private $flag_skills = false; private $leader_skill; private $leader_skill_id; private $skill = []; private $flag_essences = false; private $essences = []; private $flag_sources = false; private $sources = []; private $title; private $flag_transformation = false; private $transformation; /** * Constructor. * * Searches the database and retrieves the information about the * monster, populating it and it's items. * * @param int $id Monster identifier. */ public function __construct($id){ $this->id = $id; $statement = get_context()->get_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"]; if ($r["can_awaken"] == 1){ $this->can_awaken = true; } else{ $this->can_awaken = false; } $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_id = $r["leader_skill"]; } $this->stats["hp"] = $r["hp"]; $this->stats["atk"] = $r["attack"]; $this->stats["def"] = $r["defense"]; $this->stats["spd"] = $r["speed"]; $this->stats["crr"] = $r["crit_rate"]; $this->stats["crd"] = $r["crit_damage"]; $this->stats["res"] = $r["resistance"]; $this->stats["acc"] = $r["accuracy"]; $this->min_stats["hp"] = $r["raw_hp"]; $this->min_stats["atk"] = $r["raw_attack"]; $this->min_stats["def"] = $r["raw_defense"]; $this->min_stats["spd"] = $r["speed"]; $this->min_stats["crr"] = $r["crit_rate"]; $this->min_stats["crd"] = $r["crit_damage"]; $this->min_stats["res"] = $r["resistance"]; $this->min_stats["acc"] = $r["accuracy"]; $this->max_stats["hp"] = $r["max_lvl_hp"]; $this->max_stats["atk"] = $r["max_lvl_attack"]; $this->max_stats["def"] = $r["max_lvl_defense"]; $this->max_stats["spd"] = $r["speed"]; $this->max_stats["crr"] = $r["crit_rate"]; $this->max_stats["crd"] = $r["crit_damage"]; $this->max_stats["res"] = $r["resistance"]; $this->max_stats["acc"] = $r["accuracy"]; $this->awakens_from = $r["awakens_from"]; $this->awakens_to = $r["awakens_to"]; if ($r["fusion_food"] == 1){ $this->fusion_food = true; } else{ $this->fusion_food = false; } if ($r["homunculus"] == 1){ $this->homunculus = true; } else{ $this->homunculus = false; } $this->craft_cost = $r["craft_cost"]; } // 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; } } private function load_skills(){ $statement = get_context()->get_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"])); } if ($this->leader_skill_id != null){ $this->leader_skill = new Leader_Skill($this->leader_skill_id); } $this->flag_skills = true; } private function load_sources(){ $statement = get_context()->get_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"])); } $this->flag_sources = true; } private function load_essences(){ $statement = get_context()->get_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); } $this->flag_essences = true; } private function load_transformation(){ $statement = get_context()->get_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"]); } $this->flag_transformation = true; } /** * Retrieves the monster identifier. * * @return string Monster ID */ public function get_id(){ return $this->id; } /** * Retrieves the monsters family identifier. * * @return string Family ID. */ public function get_family(){ return $this->family; } /** * Retrieves the monster name. * * @return string Monster name. */ public function get_name(){ return $this->name; } /** * Retrieves the monster's element. * * @see ELEMENT_ID * * @return int Element ID. */ public function get_element(){ return $this->element; } /** * Retrieves the monster's element name. * * @return string Element name. */ public function get_element_name(){ return $this->element_name; } /** * Retrieves the monster's archetype. * * @see ARCHETYPE_ID * * @return int Monster's archetype ID. */ public function get_archetype(){ return $this->archetype; } /** * Retrieves the monster's archetype name. * * @return string Archetype name. */ public function get_archetype_name(){ return $this->archetype_name; } /** * Retrieves the monster's base stars. * Base stars are the default stars of the monsters in it's current form. I.E awakened * monsters have always one more base stars than their unawakened forms, and second awaken * monster always have 6 stars. * * @return int Monster base stars (1-6). */ public function get_base_stars(){ return $this->base_stars; } /** * Retrieves the monster's natural stars. * Natural stars are the default stars of the monsters in it's unawakened form. * * @return int Monster natural stars (1-5). */ public function get_natural_stars(){ return $this->natural_stars; } /** * Checks if the monster is obtainable. * Non obtainable monster are usually enemies (boses, towers, pure units...) * * @return boolean True for obtainable monsters, false for unobtainable. */ public function is_obtainable(){ return $this->obtainable; } /** * Checks if the monster can be awakened. * It also includes monsters that can second awaken. * * @return boolean True if the monster can awaken, false otherwise. */ public function can_awaken(){ return $this->can_awaken; } /** * Retrieves the awakening bonus description. * Note that for second awakenings, the bonus always is described as "Secondary Awakening". * For units that can't awaken, it will return an empty string. * * @return string Awaken bonus. */ public function get_awaken_bonus(){ return $this->awaken_bonus; } /** * Retrieves the number of skill-ups needed to fully skill-up the monster. * * @return int Required skill-ups */ public function get_skill_ups_to_max(){ return $this->skill_ups_to_max; } /** * Retrieves the monster's leader skill. * * @return Leader_Skill The leader skill. */ public function get_leader_skill(){ if (! $this->flag_skills){ $this->load_skills(); } return $this->leader_skill; } /** * Retrieves the monster stats. * These stats are the ones for the monster in it's base grade, at max level. * * It's an associative array with the following keys: * atk, def, hp, spd, crr, crd, acc, res * * @see get_min_stats() * @see get_max_stats() * * @return int[] Monster stats. */ public function get_stats(){ return $this->stats; } /** * Retrieves the monster stats. * These stats are the ones for the monster in it's base grade, at level 1. * * It's an associative array with the following keys: * atk, def, hp, spd, crr, crd, acc, res * * @see get_stats() * @see get_max_stats() * * @return int[] Monster stats. */ public function get_min_stats(){ return $this->stats(); } /** * Retrieves the monster stats. * These stats are the ones for the monster with 6 stars at level 40. * * It's an associative array with the following keys: * atk, def, hp, spd, crr, crd, acc, res * * @return int[] Monster stats. * * @see get_stats() * @see get_min_stats() */ public function get_max_stats(){ return $this->stats(); } /** * Retrieves the identifier of the monster who awakens to this one. * * @return string Unawakened monster identifier, null for unawakened monsters. */ public function get_awakens_from(){ return $this->awakens_from; } /** * Retrieves the identifier of the monster this one awakens to. * * @return string Next awaken monster identifier, null for fully awakened monsters. */ public function get_awakens_to(){ return $this->awakens_to; } /** * Checks if skill-ups can be created by fussion. * * @return boolean True if skill-us can be fused, false otherwise. */ public function has_fusion_food(){ return $this->fusion_food; } /** * Checks if the monster is an Homunculus. * * @return boolean True if Homunculus, false otherwise. */ public function is_homunculus(){ return $this->homunculus; } /** * // TODO: Unimplemented. * Retrieves $craft_cost * * @return number */ public function get_craft_cost(){ return $this->craft_cost; } /** * Retrieves the monster skills * * @return Skill[] Monster skills. */ public function get_skills(){ if (! $this->flag_skills){ $this->load_skills(); } return $this->skill; } /** * Retrieves the essences required to awaken the monster. * * @return [[Inventory][int]] Essences required to awaken the monster.s */ public function get_essences(){ if (! $this->flag_essences){ $this->load_essences(); } return $this->essences; } /** * Retrieves the sources the monster can be obtained from. * * @return Source[] Array of sources.s */ public function get_sources(){ if (! $this->flag_sources){ $this->load_sources(); } return $this->sources; } /** * Retrieves the unit's $title * If awakened, it will be the awakened from name. * If unawakened, it will be . * * @return string Units title. */ public function get_title(){ return $this->title; } /** * Retrieves the unit this ne can transform to. * * @return Monster_Transformation The transformation, null if none. */ public function get_transformation(){ if (! $this->flag_transformation){ $this->load_transformation(); } return $this->transformation; } /** * 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); } } ?>