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. /**
  6. * Monster.
  7. *
  8. * Represents an object from the table 'monster'.
  9. */
  10. class K_Monster extends Entity{
  11. /**
  12. * Monster identifier.
  13. */
  14. public $id;
  15. /**
  16. * Monster official identifier.
  17. */
  18. public $com2us_id;
  19. /**
  20. * Monster family id.
  21. */
  22. public $family_id;
  23. /**
  24. * Monster name.
  25. */
  26. public $name;
  27. /**
  28. * Monster element.
  29. */
  30. public $element;
  31. /**
  32. * Monster archetype.
  33. */
  34. public $archetype;
  35. /**
  36. * Default star level.
  37. */
  38. public $base_stars;
  39. /**
  40. * Default star level.
  41. */
  42. public $natural_stars;
  43. /**
  44. * Indicates if the monster is obtainable.
  45. */
  46. public $obtainable;
  47. /**
  48. * Indicates if the monster can be awakened.
  49. */
  50. public $can_awaken;
  51. /**
  52. * Bonus when awakening.
  53. */
  54. public $awaken_bonus;
  55. /**
  56. * Required skill-ups.
  57. */
  58. public $skill_ups_to_max;
  59. /**
  60. * @{see K_Leader_Skill} of the monster.
  61. */
  62. public $leader_skill;
  63. /**
  64. * Base HP.
  65. */
  66. public $base_hp;
  67. /**
  68. * Base ATK.
  69. */
  70. public $base_atk;
  71. /**
  72. * Base DEF.
  73. */
  74. public $base_defense;
  75. /**
  76. * SPD.
  77. */
  78. public $speed;
  79. /**
  80. * CRR.
  81. */
  82. public $crit_rate;
  83. /**
  84. * CRD.
  85. */
  86. public $crit_damage;
  87. /**
  88. * RES
  89. */
  90. public $resistance;
  91. /**
  92. * ACC.
  93. */
  94. public $accuracy;
  95. /**
  96. * Raw HP.
  97. */
  98. public $raw_hp;
  99. /**
  100. * Raw ATK.
  101. */
  102. public $raw_atk;
  103. /**
  104. * Raw DEF.
  105. */
  106. public $raw_defense;
  107. /**
  108. * HP at max_level.
  109. */
  110. public $max_lvl_hp;
  111. /**
  112. * ATK at max_level.
  113. */
  114. public $max_lvl_atk;
  115. /**
  116. * DEF at max_level.
  117. */
  118. public $max_lvl_defense;
  119. /**
  120. * @{see Monster} it awakens from.
  121. */
  122. public $awakens_from;
  123. /**
  124. * @{see Monster} it awakens to.
  125. */
  126. public $awakens_to;
  127. /**
  128. * Indicates if the monster is a fusion ingredient.
  129. */
  130. public $fusion_food;
  131. /**
  132. * Indicates if the monster is homunculus.
  133. */
  134. public $homunculus;
  135. /**
  136. * The crafting cost (homunculus only).
  137. */
  138. public $craft_cost;
  139. /**
  140. * All {@see K_Monster_Skill}s.
  141. */
  142. public $skill = [];
  143. /**
  144. * Required essences to awaken the monster. Formed by arrays of:
  145. * [
  146. * "element" => "",
  147. * "grade" => "",
  148. * "amount" =>
  149. * ]
  150. */
  151. public $essences = [];
  152. /**
  153. * Constructor.
  154. *
  155. * Searches the database and retrieves the information about the
  156. * monster, populating it and it's items.
  157. *
  158. * @param SQLite3 $db Connection to the database.
  159. * @param int $id Monster identifier.
  160. */
  161. public function __construct($db, $id){
  162. global $path;
  163. parent::__construct($db);
  164. $s =
  165. "SELECT " .
  166. " id, " .
  167. " com2us_id, " .
  168. " family_id, " .
  169. " name, " .
  170. " element, " .
  171. " archetype, " .
  172. " base_stars, " .
  173. " natural_stars, " .
  174. " obtainable, " .
  175. " can_awaken, " .
  176. " awaken_bonus, " .
  177. " skill_ups_to_max, " .
  178. " leader_skill, " .
  179. " base_hp, " .
  180. " base_attack, " .
  181. " base_defense, " .
  182. " speed, " .
  183. " crit_rate, " .
  184. " crit_damage, " .
  185. " resistance, " .
  186. " accuracy, " .
  187. " raw_hp, " .
  188. " raw_attack, " .
  189. " raw_defense, " .
  190. " max_lvl_hp, " .
  191. " max_lvl_attack, " .
  192. " max_lvl_defense, " .
  193. " awakens_from, " .
  194. " awakens_to, " .
  195. " fusion_food, " .
  196. " homunculus, " .
  197. " craft_cost " .
  198. "FROM k_monster " .
  199. "WHERE id = $id; ";
  200. $q = $this->db->query($s);
  201. $r = $q->fetchArray(SQLITE3_ASSOC);
  202. if ($r){
  203. $this->id = $r["id"];
  204. $this->com2us_id = $r["com2us_id"];
  205. $this->family_id = $r["family_id"];
  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 ($r["leader_skill"]){
  216. $this->leader_skill = new K_Leader_Skill($this->db, $r["leader_skill"]);
  217. }
  218. $this->base_hp = $r["base_hp"];
  219. $this->base_attack = $r["base_attack"];
  220. $this->base_defense = $r["base_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. $s =
  239. "SELECT " .
  240. " skill " .
  241. "FROM " .
  242. " k_skill, " .
  243. " k_monster_skill " .
  244. "WHERE " .
  245. " id = skill AND " .
  246. " monster = $id " .
  247. "ORDER BY slot; ";
  248. $q = $this->db->query($s);
  249. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  250. array_push($this->skill, new K_Skill($this->db, $r["skill"]));
  251. }
  252. $s =
  253. "SELECT " .
  254. " element, " .
  255. " grade, " .
  256. " amount " .
  257. "FROM k_monster_essence " .
  258. "WHERE " .
  259. " monster = $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. public function get_image(){
  275. global $base_dir;
  276. global $path;
  277. if (file_exists($base_dir . "img/content/monster/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
  278. return $path["img"]["content"] . "monster/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
  279. }
  280. else{
  281. return $path["img"]["layout"] . "unknown.png";
  282. }
  283. }
  284. /**
  285. * TODO: UNUSED
  286. *
  287. * @param $stat Stat name ("ATK", "DEF", "HP", "SPD", "CRR", "CRD", "RES", "ACC").
  288. * @return Value of the base stat (floored integer), -1 if wrong stat.
  289. */
  290. public function get_base_stat($stat){
  291. if ($stat == "ATK" || $stat == "DEF" || $stat == "HP" || $stat == "SPD" || $stat == "CRR" || $stat == "CRD" || $stat == "RES" || $stat == "ACC"){
  292. $s =
  293. "SELECT " .
  294. " min, " .
  295. " max " .
  296. "FROM k_monster_stat " .
  297. "WHERE " .
  298. " monster = " . $this->k_monster->id . " AND " .
  299. " stat = '" . $stat . "' AND " .
  300. " stars = " . $this->stars . " AND " .
  301. " awake = " . $this->awakened . ";";
  302. $q = $this->db->query($s);
  303. if ($q){
  304. $r = $q->fetchArray(SQLITE3_ASSOC);
  305. if ($r){
  306. $min = $r["min"];
  307. $max = $r["max"];
  308. $min_level = 1;
  309. $max_level = 40;
  310. switch ($this->stars){
  311. case 1:
  312. $max_level = 15;
  313. break;
  314. case 2:
  315. $max_level = 20;
  316. break;
  317. case 3:
  318. $max_level = 25;
  319. break;
  320. case 4:
  321. $max_level = 30;
  322. break;
  323. case 5:
  324. $max_level = 35;
  325. break;
  326. }
  327. $base = $min + (($max - $min) * $this->level / $max_level);
  328. return floor($base);
  329. }
  330. else{
  331. return -1;
  332. }
  333. }
  334. else{
  335. return -1;
  336. }
  337. }
  338. else{
  339. return -1;
  340. }
  341. }
  342. }
  343. ?>