| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789 |
- <?php
- /**
- * Base monster entity file.
- *
- * Creates the entity and makes it available.
- *
- * @author Iñigo Valentin <i@inigovalentin.com>
- * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
- * @package SWDB
- */
- require_once(PATH::ENTITY . "Entity.php");
- require_once(PATH::ENTITY . "Skill.php");
- require_once(PATH::ENTITY . "Leader_Skill.php");
- require_once(PATH::ENTITY . "Source.php");
- require_once(PATH::ENTITY . "Inventory.php");
- require_once(PATH::ENTITY . "Monster_Transformation.php");
- /**
- * A monster.
- *
- * Represents an object from the table 'monster'.
- *
- * @category Entity
- */
- class Monster extends Entity{
- /**
- * @var int Monster ID
- */
- private $id;
- /**
- * @var int Monster family ID.
- */
- private $family;
- /**
- * @var string Monster name.
- */
- private $name;
- /**
- * @var int Monster element ID ({@see ELEMENT_ID}).
- */
- private $element;
- /**
- * @var string Monster element name.
- */
- private $element_name;
- /**
- * @var int Monster archetype ID ({@see ARCHETYPE_ID}).
- */
- private $archetype;
- /**
- * @var string Monster archetype name.
- */
- private $archetype_name;
- /**
- * @var int Stars of the monster in it's current form (1-6)
- */
- private $base_stars;
- /**
- * @var int Stars of the monster in it's base form (1-5).
- */
- private $natural_stars;
- /**
- * @var bool Indicates if the monster is obtainable.
- */
- private $obtainable;
- /**
- * @var bool Indicates if the monster can awaken.
- */
- private $can_awaken;
- /**
- * @var string The bonus the monster obtains when awakening.
- */
- private $awaken_bonus;
- /**
- * @var int Total skill ups to ma all skills.
- */
- private $skill_ups_to_max;
- /**
- * @var int[] Stats of the monster in it's base grade at max level.
- */
- private $stats = array(
- "hp" => 0,
- "atk" => 0,
- "def" => 0,
- "spd" => 0,
- "crr" => 0,
- "crd" => 0,
- "acc" => 0,
- "res" => 0,
- );
- /**
- * @var int[] Stats of the monster in it's base grade at level 1.
- */
- private $min_stats = array(
- "hp" => 0,
- "atk" => 0,
- "def" => 0,
- "spd" => 0,
- "crr" => 0,
- "crd" => 0,
- "acc" => 0,
- "res" => 0,
- );
- /**
- * @var int[] Stats of the monster at 6 stars and max level.
- */
- private $max_stats = array(
- "hp" => 0,
- "atk" => 0,
- "def" => 0,
- "spd" => 0,
- "crr" => 0,
- "crd" => 0,
- "acc" => 0,
- "res" => 0,
- );
- /**
- * @var int ID of the monster this awakens from.
- */
- private $awakens_from;
- /**
- * @var int ID of the monster this awakens to.
- */
- private $awakens_to;
- /**
- * @var bool Indicates if the monster can be skilled up with fusion monsters.
- */
- private $fusion_food;
- /**
- * @var bool Indicates if the monster is an Homunculus.
- */
- private $homunculus;
- /**
- * @var mixed[] Crafting cost
- * @todo Unimplemented, do not use.
- */
- private $craft_cost;
- /**
- * @var bool internal flag to check if the monster skills, including the leader skill, have
- * been loaded into the entity.
- */
- private $flag_skills = false;
- /**
- * @var Leader_Skill Monster's leader skill.
- */
- private $leader_skill;
- /**
- * @var int Leader skill ID.
- */
- private $leader_skill_id;
- /**
- * @var Skill[] Monster skills.
- */
- private $skill = [];
- /**
- * @var bool Internal flag to check if the essences have been loaded into the entity.
- */
- private $flag_essences = false;
- /**
- * @var mixed[] Essences required to awaken the monster.
- */
- private $essences = [];
- /**
- * @var bool Internal flag to check if the monster sources have been loaded.
- */
- private $flag_sources = false;
- /**
- * @var Source[] List of sources the monster can be obtained from.
- */
- private $sources = [];
- /**
- * @var string Monster title.
- */
- private $title;
- /**
- * @var bool Internal flag to check if the monsters transformation have been checked.
- */
- private $flag_transformation = false;
- /**
- * @var Monster_Transformation The monster this one can transform into in battle.
- */
- 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;
- }
- }
- /**
- * Loads the monster skills into the entity.
- *
- * Must be called only once before trying to get the skills (including the leader one). Sets
- * the flag {@link Monster:$flag_skills} to true.
- */
- 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;
- }
- /**
- * Loads the monster sources into the entity.
- *
- * Must be called only once before trying to get the sources. Sets the flag
- * {@link Monster:$flag_sources} to 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;
- }
- /**
- * Loads the essences to awaken the monster into the entity.
- *
- * Must be called only once before trying to get the essences. Sets the flag
- * {@link Monster:$flag_essences} to 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;
- }
- /**
- * Loads the monster transformation into the entity.
- *
- * Must be called only once before trying to get the transformation. Sets the flag
- * {@link Monster:$flag_transformation} to 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 bool 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 bool 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->min_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->max_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 bool 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 bool True if Homunculus, false otherwise.
- */
- public function is_homunculus(){
- return $this->homunculus;
- }
- /**
- * // TODO: Unimplemented.
- * Retrieves $craft_cost
- *
- * @return int
- */
- 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 <element> <name>.
- *
- * @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.
- *
- * @return string Image URL, or a fixed unknown image.
- */
- public function get_image(){
- return APPLICATION::img("UNIT", $this->id);
- }
- }
|