| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- <?php
- /**
- * Base unit entity file.
- *
- * Creates the entity and makes it available.
- *
- * @category Entity
- */
- /**
- * Require dependent entities if not present.
- */
- require_once(PATH::ENTITY . "Entity.php");
- require_once(PATH::ENTITY . "K_Skill.php");
- require_once(PATH::ENTITY . "K_Leader_Skill.php");
- require_once(PATH::ENTITY . "K_Source.php");
- require_once(PATH::ENTITY . "K_Inventory.php");
- require_once(PATH::ENTITY . "K_Unit_Transformation.php");
- /**
- * A unit.
- *
- * Represents an object from the table 'k_unit'.
- *
- * @category Entity
- */
- class K_Unit extends Entity{
- /**
- * @var int Unit identifier.
- */
- public $id;
- /**
- * @var int Unit family id.
- */
- public $family;
- /**
- * @var string Unit name.
- */
- public $name;
- /**
- * @var int Unit element id.
- */
- public $element;
- /**
- * @var string Element name (title case)
- */
- public $element_name;
- /**
- * @var int Unit archetype id.
- */
- public $archetype;
- /**
- * @var string Archetype name (title case).
- */
- public $archetype_name;
- /**
- * @var int Default star level.
- */
- public $base_stars;
- /**
- *@var int Default star level.
- */
- public $natural_stars;
- /**
- * @var bool Indicates if the unit is obtainable.
- */
- public $obtainable;
- /**
- * @var bool Indicates if the unit can be awakened.
- */
- public $can_awaken;
- /**
- * @var string Bonus when awakening.
- */
- public $awaken_bonus;
- /**
- * @var int Required skill-ups.
- */
- public $skill_ups_to_max;
- /**
- * @var K_Leader_Skill Unit's leader skill.
- */
- public $leader_skill;
- /**
- * @var int Base HP.
- */
- public $hp;
- /**
- * @var int Base attack.
- */
- public $atk;
- /**
- * @var int Base defense.
- */
- public $defense;
- /**
- * @var int Speed.
- */
- public $speed;
- /**
- * @var int Critical rate.
- */
- public $crit_rate;
- /**
- * @var int Critical damage.
- */
- public $crit_damage;
- /**
- * @var int Resistance
- */
- public $resistance;
- /**
- * @var int Accuracy.
- */
- public $accuracy;
- /**
- * @var int Raw HP.
- */
- public $raw_hp;
- /**
- * @var int Raw attack.
- */
- public $raw_atk;
- /**
- * @var int Raw Defense.
- */
- public $raw_defense;
- /**
- * @var int HP at max_level.
- */
- public $max_lvl_hp;
- /**
- * @var int Attack at max_level.
- */
- public $max_lvl_atk;
- /**
- * @var int Defense at max_level.
- */
- public $max_lvl_defense;
- /**
- * @var K_Unit Unit it awakens from.
- */
- public $awakens_from;
- /**
- * @var K_Unit Unit it awakens to.
- */
- public $awakens_to;
- /**
- * @var bool Indicates if the unit is a fusion ingredient.
- */
- public $fusion_food;
- /**
- * @var bool Indicates if the unit is homunculus.
- */
- public $homunculus;
- /**
- * @var int The crafting cost (homunculus only).
- */
- public $craft_cost;
- /**
- * @var \K_Unit_Skill[] Unit skills.
- */
- public $skill = [];
- /**
- * @var mixed[] Required essences to awaken the unit.
- *
- * Formed by arrays of:
- * [
- * "item" => 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 <element> <name>.
- */
- 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 resouce $db Connection to the database.
- * @param int $id Unit identifier.
- * @param bool $complete If false, query only k_unit.
- */
- public function __construct($db, $id, $complete = true){
- parent::__construct($db);
- $s =
- "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; ";
- $q = $this->db->query($s);
- $r = $q->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->id = $r["id"];
- $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($this->db, $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();
- }
- // No to, no from. Silver unit.
- if ($this->awakens_from == "" && $this->awakens_to == ""){
- $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.
- */
- public function load_essences(){
- $this->essences = [];
- $s =
- "SELECT " .
- " item, " .
- " amount " .
- "FROM k_unit_essence " .
- "WHERE " .
- " unit = " . $this->id . " " .
- "ORDER BY item; ";
- $q = $this->db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- $e = [
- "item" => new K_Inventory($this->db, $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.
- */
- public function load_transformation(){
- $this->transformation = null;
- $s = "
- SELECT id
- FROM k_unit_transformation
- WHERE unit = " . $this->id . ";";
- $q = $this->db->query($s);
- $r = $q->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->transformation = new K_Unit_Transformation($this->db, $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.
- */
- public function load_skills(){
- $this->skill = [];
- $s = "
- SELECT skill
- FROM
- k_skill,
- k_unit_skill
- WHERE
- id = skill AND
- unit = " . $this->id . "
- ORDER BY slot;
- ";
- $q = $this->db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->skill, new K_Skill($this->db, $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.
- */
- public function load_sources(){
- $this->sources = [];
- $s =
- "SELECT source " .
- "FROM k_unit_source " .
- "WHERE unit = " . $this->id . ";";
- $q = $this->db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->sources, new K_Source($this->db, $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);
- }
- }
- ?>
|