K_Inventory, * "amount" => int * ] */ public $essences = []; /** * @var int \K_Source[] Sources the unit can be get from. */ public $sources = []; /** * @var string Unit title. * If awakened, it will be the awakened from name. * If unawakened, it will be . */ public $title; /** * @var K_Unit_Transformation The transformation the unit can undergo. */ public $transformation; /** * Constructor. * * Searches the database and retrieves the information about the * unit, populating it and it's items. * * @param int $id Unit identifier. * @param bool $complete If false, query only k_unit. * @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 k_unit WHERE id = :id; "); $statement->bindValue(':id', $id, SQLITE3_INTEGER); $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 K_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 unit. if ($this->base_stars >= 4){ // SFV Collab event units, 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 unit. * * 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 k_unit_essence WHERE unit = :unit ORDER BY item; "); $statement->bindValue(':unit', $this->id, SQLITE3_INTEGER); $q = $statement->execute(); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ $e = [ "item" => new K_Inventory($r["item"], INVENTORY_TYPE_ID::ESSENCES), "amount" => $r["amount"] ]; array_push($this->essences, $e); } } /** * Loads the unit 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 k_unit_transformation WHERE unit = :unit; "); $statement->bindValue(':unit', $this->id, SQLITE3_INTEGER); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->transformation = new K_Unit_Transformation($r["id"]); } } /** * Loads the information about the unit 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 FROM k_skill, k_unit_skill WHERE id = skill AND unit = :unit ORDER BY slot; "); $statement->bindValue(':unit', $this->id, SQLITE3_INTEGER); $q = $statement->execute(); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->skill, new K_Skill($r["skill"])); } } /** * Loads the information about the unit 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 k_unit_source WHERE unit = :unit; "); $statement->bindValue(':unit', $this->id, SQLITE3_INTEGER); $q = $statement->execute(); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->sources, new K_Source($r["source"])); } } /** * Gets the path to the unit image. The image must be in the * img/unit/ directory, and it's name must be the unit 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); } } ?>