K_Monster.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. */
  166. public function __construct($db, $id){
  167. global $path;
  168. parent::__construct($db);
  169. $s =
  170. "SELECT " .
  171. " id, " .
  172. " com2us_id, " .
  173. " family_id, " .
  174. " name, " .
  175. " element, " .
  176. " archetype, " .
  177. " base_stars, " .
  178. " natural_stars, " .
  179. " obtainable, " .
  180. " can_awaken, " .
  181. " awaken_bonus, " .
  182. " skill_ups_to_max, " .
  183. " leader_skill, " .
  184. " base_hp, " .
  185. " base_attack, " .
  186. " base_defense, " .
  187. " speed, " .
  188. " crit_rate, " .
  189. " crit_damage, " .
  190. " resistance, " .
  191. " accuracy, " .
  192. " raw_hp, " .
  193. " raw_attack, " .
  194. " raw_defense, " .
  195. " max_lvl_hp, " .
  196. " max_lvl_attack, " .
  197. " max_lvl_defense, " .
  198. " awakens_from, " .
  199. " awakens_to, " .
  200. " fusion_food, " .
  201. " homunculus, " .
  202. " craft_cost " .
  203. "FROM k_monster " .
  204. "WHERE id = $id; ";
  205. $q = $this->db->query($s);
  206. $r = $q->fetchArray(SQLITE3_ASSOC);
  207. if ($r){
  208. $this->id = $r["id"];
  209. $this->com2us_id = $r["com2us_id"];
  210. $this->family_id = $r["family_id"];
  211. $this->name = $r["name"];
  212. $this->element = $r["element"];
  213. $this->archetype = $r["archetype"];
  214. $this->base_stars = $r["base_stars"];
  215. $this->natural_stars = $r["natural_stars"];
  216. $this->obtainable = $r["obtainable"];
  217. $this->can_awaken = $r["can_awaken"];
  218. $this->awaken_bonus = $r["awaken_bonus"];
  219. $this->skill_ups_to_max = $r["skill_ups_to_max"];
  220. if ($r["leader_skill"]){
  221. $this->leader_skill = new K_Leader_Skill($this->db, $r["leader_skill"]);
  222. }
  223. $this->base_hp = $r["base_hp"];
  224. $this->base_attack = $r["base_attack"];
  225. $this->base_defense = $r["base_defense"];
  226. $this->speed = $r["speed"];
  227. $this->crit_rate = $r["crit_rate"];
  228. $this->crit_damage = $r["crit_damage"];
  229. $this->resistance = $r["resistance"];
  230. $this->accuracy = $r["accuracy"];
  231. $this->raw_hp = $r["raw_hp"];
  232. $this->raw_attack = $r["raw_attack"];
  233. $this->raw_defense = $r["raw_defense"];
  234. $this->max_lvl_hp = $r["max_lvl_hp"];
  235. $this->max_lvl_attack = $r["max_lvl_attack"];
  236. $this->max_lvl_defense = $r["max_lvl_defense"];
  237. $this->awakens_from = $r["awakens_from"];
  238. $this->awakens_to = $r["awakens_to"];
  239. $this->fusion_food = $r["fusion_food"];
  240. $this->homunculus = $r["homunculus"];
  241. $this->craft_cost = $r["craft_cost"];
  242. }
  243. $s =
  244. "SELECT " .
  245. " skill " .
  246. "FROM " .
  247. " k_skill, " .
  248. " k_monster_skill " .
  249. "WHERE " .
  250. " id = skill AND " .
  251. " monster = $id " .
  252. "ORDER BY slot; ";
  253. $q = $this->db->query($s);
  254. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  255. array_push($this->skill, new K_Skill($this->db, $r["skill"]));
  256. }
  257. $s =
  258. "SELECT " .
  259. " element, " .
  260. " grade, " .
  261. " amount " .
  262. "FROM k_monster_essence " .
  263. "WHERE " .
  264. " monster = $id " .
  265. "ORDER BY " .
  266. " element <> 'Magic', " .
  267. " grade <> 'Low', " .
  268. " grade <> 'Mid'; ";
  269. $q = $this->db->query($s);
  270. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  271. $e = [
  272. "element" => $r["element"],
  273. "grade" => $r["grade"],
  274. "amount" => $r["amount"]
  275. ];
  276. array_push($this->essences, $e);
  277. }
  278. $s =
  279. "SELECT source " .
  280. "FROM k_monster_source " .
  281. "WHERE monster = $id; ";
  282. $q = $this->db->query($s);
  283. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  284. array_push($this->sources, new K_Source($this->db, $r["source"]));
  285. }
  286. }
  287. /**
  288. * Gets the pathto the monster image. The image must be in the
  289. * img/content/monster/ directory, and its name must be the monster id,
  290. * padded with '0' to 4 digites, and the extension must be '.png'.
  291. *
  292. * @return path to the image, or a path to a fixed unknown image if it
  293. * doesn't exist.
  294. */
  295. public function get_image(){
  296. global $base_dir;
  297. global $path;
  298. if (file_exists($base_dir . "img/content/monster/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
  299. return $path["img"]["content"] . "monster/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
  300. }
  301. else{
  302. return $path["img"]["layout"] . "unknown.png";
  303. }
  304. }
  305. }
  306. ?>