K_Unit.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "K_Skill.php");
  4. require_once($path["entity"] . "K_Leader_Skill.php");
  5. require_once($path["entity"] . "K_Source.php");
  6. /**
  7. * Monster.
  8. *
  9. * Represents an object from the table 'monster'.
  10. */
  11. class K_Unit extends Entity{
  12. /**
  13. * Monster identifier.
  14. */
  15. public $id;
  16. /**
  17. * Monster family id.
  18. */
  19. public $family;
  20. /**
  21. * Monster name.
  22. */
  23. public $name;
  24. /**
  25. * Monster element.
  26. */
  27. public $element;
  28. /**
  29. * Monster archetype.
  30. */
  31. public $archetype;
  32. /**
  33. * Default star level.
  34. */
  35. public $base_stars;
  36. /**
  37. * Default star level.
  38. */
  39. public $natural_stars;
  40. /**
  41. * Indicates if the monster is obtainable.
  42. */
  43. public $obtainable;
  44. /**
  45. * Indicates if the monster can be awakened.
  46. */
  47. public $can_awaken;
  48. /**
  49. * Bonus when awakening.
  50. */
  51. public $awaken_bonus;
  52. /**
  53. * Required skill-ups.
  54. */
  55. public $skill_ups_to_max;
  56. /**
  57. * @{see K_Leader_Skill} of the monster.
  58. */
  59. public $leader_skill;
  60. /**
  61. * Base HP.
  62. */
  63. public $hp;
  64. /**
  65. * Base ATK.
  66. */
  67. public $atk;
  68. /**
  69. * Base DEF.
  70. */
  71. public $defense;
  72. /**
  73. * SPD.
  74. */
  75. public $speed;
  76. /**
  77. * CRR.
  78. */
  79. public $crit_rate;
  80. /**
  81. * CRD.
  82. */
  83. public $crit_damage;
  84. /**
  85. * RES
  86. */
  87. public $resistance;
  88. /**
  89. * ACC.
  90. */
  91. public $accuracy;
  92. /**
  93. * Raw HP.
  94. */
  95. public $raw_hp;
  96. /**
  97. * Raw ATK.
  98. */
  99. public $raw_atk;
  100. /**
  101. * Raw DEF.
  102. */
  103. public $raw_defense;
  104. /**
  105. * HP at max_level.
  106. */
  107. public $max_lvl_hp;
  108. /**
  109. * ATK at max_level.
  110. */
  111. public $max_lvl_atk;
  112. /**
  113. * DEF at max_level.
  114. */
  115. public $max_lvl_defense;
  116. /**
  117. * @{see Monster} it awakens from.
  118. */
  119. public $awakens_from;
  120. /**
  121. * @{see Monster} it awakens to.
  122. */
  123. public $awakens_to;
  124. /**
  125. * Indicates if the monster is a fusion ingredient.
  126. */
  127. public $fusion_food;
  128. /**
  129. * Indicates if the monster is homunculus.
  130. */
  131. public $homunculus;
  132. /**
  133. * The crafting cost (homunculus only).
  134. */
  135. public $craft_cost;
  136. /**
  137. * All {@see K_Monster_Skill}s.
  138. */
  139. public $skill = [];
  140. /**
  141. * Required essences to awaken the monster. Formed by arrays of:
  142. * [
  143. * "element" => "",
  144. * "grade" => "",
  145. * "amount" =>
  146. * ]
  147. */
  148. public $essences = [];
  149. /**
  150. * {@see K_Source}s the monster can be get from.
  151. */
  152. public $sources = [];
  153. /**
  154. * Constructor.
  155. *
  156. * Searches the database and retrieves the information about the
  157. * monster, populating it and it's items.
  158. *
  159. * @param SQLite3 $db Connection to the database.
  160. * @param int $id Monster identifier.
  161. * @param complete If false, query only k_monster.
  162. */
  163. public function __construct($db, $id, $complete = true){
  164. global $path;
  165. parent::__construct($db);
  166. $s =
  167. "SELECT " .
  168. " id, " .
  169. " family, " .
  170. " name, " .
  171. " element, " .
  172. " archetype, " .
  173. " base_stars, " .
  174. " natural_stars, " .
  175. " obtainable, " .
  176. " can_awaken, " .
  177. " awaken_bonus, " .
  178. " skill_ups_to_max, " .
  179. " leader_skill, " .
  180. " hp, " .
  181. " attack, " .
  182. " defense, " .
  183. " speed, " .
  184. " crit_rate, " .
  185. " crit_damage, " .
  186. " resistance, " .
  187. " accuracy, " .
  188. " raw_hp, " .
  189. " raw_attack, " .
  190. " raw_defense, " .
  191. " max_lvl_hp, " .
  192. " max_lvl_attack, " .
  193. " max_lvl_defense, " .
  194. " awakens_from, " .
  195. " awakens_to, " .
  196. " fusion_food, " .
  197. " homunculus, " .
  198. " craft_cost " .
  199. "FROM k_unit " .
  200. "WHERE id = $id; ";
  201. $q = $this->db->query($s);
  202. $r = $q->fetchArray(SQLITE3_ASSOC);
  203. if ($r){
  204. $this->id = $r["id"];
  205. $this->family = $r["family"];
  206. $this->name = $r["name"];
  207. $this->element = $r["element"];
  208. $this->archetype = $r["archetype"];
  209. $this->base_stars = $r["base_stars"];
  210. $this->natural_stars = $r["natural_stars"];
  211. $this->obtainable = $r["obtainable"];
  212. $this->can_awaken = $r["can_awaken"];
  213. $this->awaken_bonus = $r["awaken_bonus"];
  214. $this->skill_ups_to_max = $r["skill_ups_to_max"];
  215. if (strlen($r["leader_skill"]) > 0){
  216. $this->leader_skill = new K_Leader_Skill($this->db, $r["leader_skill"]);
  217. }
  218. $this->hp = $r["hp"];
  219. $this->attack = $r["attack"];
  220. $this->defense = $r["defense"];
  221. $this->speed = $r["speed"];
  222. $this->crit_rate = $r["crit_rate"];
  223. $this->crit_damage = $r["crit_damage"];
  224. $this->resistance = $r["resistance"];
  225. $this->accuracy = $r["accuracy"];
  226. $this->raw_hp = $r["raw_hp"];
  227. $this->raw_attack = $r["raw_attack"];
  228. $this->raw_defense = $r["raw_defense"];
  229. $this->max_lvl_hp = $r["max_lvl_hp"];
  230. $this->max_lvl_attack = $r["max_lvl_attack"];
  231. $this->max_lvl_defense = $r["max_lvl_defense"];
  232. $this->awakens_from = $r["awakens_from"];
  233. $this->awakens_to = $r["awakens_to"];
  234. $this->fusion_food = $r["fusion_food"];
  235. $this->homunculus = $r["homunculus"];
  236. $this->craft_cost = $r["craft_cost"];
  237. }
  238. if ($complete){
  239. $this->load_essences();
  240. $this->load_skills();
  241. $this->load_sources();
  242. }
  243. }
  244. /**
  245. * Loads the information about the essences to awake the monster.
  246. * It is autoatically called at construction time if the
  247. * $complete parameter is true (by default). No point in calling it
  248. * twice.
  249. */
  250. public function load_essences(){
  251. $this->essences = [];
  252. $s =
  253. "SELECT " .
  254. " element, " .
  255. " grade, " .
  256. " amount " .
  257. "FROM k_unit_essence " .
  258. "WHERE " .
  259. " unit = " . $this->id . " " .
  260. "ORDER BY " .
  261. " element <> 'Magic', " .
  262. " grade <> 'Low', " .
  263. " grade <> 'Mid'; ";
  264. $q = $this->db->query($s);
  265. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  266. $e = [
  267. "element" => $r["element"],
  268. "grade" => $r["grade"],
  269. "amount" => $r["amount"]
  270. ];
  271. array_push($this->essences, $e);
  272. }
  273. }
  274. /**
  275. * Loads the information about the monster skills.
  276. * It is autoatically called at construction time if the
  277. * $complete parameter is true (by default). No point in calling it
  278. * twice.
  279. */
  280. public function load_skills(){
  281. $this->skill = [];
  282. $s =
  283. "SELECT " .
  284. " skill " .
  285. "FROM " .
  286. " k_skill, " .
  287. " k_unit_skill " .
  288. "WHERE " .
  289. " id = skill AND " .
  290. " unit = " . $this->id . " " .
  291. "ORDER BY slot; ";
  292. $q = $this->db->query($s);
  293. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  294. array_push($this->skill, new K_Skill($this->db, $r["skill"]));
  295. }
  296. }
  297. /**
  298. * Loads the information about the monster sources.
  299. * It is autoatically called at construction time if the
  300. * $complete parameter is true (by default). No point in calling it
  301. * twice.
  302. */
  303. public function load_sources(){
  304. $this->sources = [];
  305. $s =
  306. "SELECT source " .
  307. "FROM k_unit_source " .
  308. "WHERE unit = " . $this->id . ";";
  309. $q = $this->db->query($s);
  310. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  311. array_push($this->sources, new K_Source($this->db, $r["source"]));
  312. }
  313. }
  314. /**
  315. * Gets the pathto the monster image. The image must be in the
  316. * img/content/monster/ directory, and its name must be the monster id,
  317. * padded with '0' to 4 digites, and the extension must be '.png'.
  318. *
  319. * @return path to the image, or a path to a fixed unknown image if it
  320. * doesn't exist.
  321. */
  322. public function get_image(){
  323. global $dir;
  324. global $path;
  325. if (file_exists($dir . "img/content/unit/" . str_pad($this->id, 8, '0', STR_PAD_LEFT) . ".png")){
  326. return $path["img"]["content"] . "unit/" . str_pad($this->id, 8, '0', STR_PAD_LEFT) . ".png";
  327. }
  328. else{
  329. return $path["img"]["layout"] . "unknown.png";
  330. }
  331. }
  332. }
  333. ?>