K_Monster.php 10 KB

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