Monster.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "K_Monster.php");
  4. require_once($path["entity"] . "Rune.php");
  5. /**
  6. * Monster.
  7. *
  8. * Represents an object from the table 'monster'.
  9. */
  10. class Monster extends Entity{
  11. /**
  12. * Monster identifier.
  13. */
  14. public $id;
  15. /**
  16. * Monster official identifier.
  17. */
  18. public $com2us_id;
  19. /**
  20. * {@see K_Monster}.
  21. */
  22. public $monster;
  23. /**
  24. * Monster stars.
  25. */
  26. public $stars;
  27. /**
  28. * Monster level.
  29. */
  30. public $level;
  31. /**
  32. * Level of skill 1
  33. */
  34. public $skill_1_level;
  35. /**
  36. * Level of skill 2
  37. */
  38. public $skill_2_level;
  39. /**
  40. * Level of skill 3
  41. */
  42. public $skill_3_level;
  43. /**
  44. * Level of skill 4
  45. */
  46. public $skill_4_level;
  47. /**
  48. * Monster base HP stat.
  49. */
  50. public $base_hp;
  51. /**
  52. * Monster base ATK stat.
  53. */
  54. public $base_attack;
  55. /**
  56. * Monster base DEF stat.
  57. */
  58. public $base_defense;
  59. /**
  60. * Monster base SPD stat.
  61. */
  62. public $base_speed;
  63. /**
  64. * Monster base CRR stat.
  65. */
  66. public $base_crit_rate;
  67. /**
  68. * Monster base CRD stat.
  69. */
  70. public $base_crit_damage;
  71. /**
  72. * Monster base RES stat.
  73. */
  74. public $base_resistance;
  75. /**
  76. * Monster base ACC stat.
  77. */
  78. public $base_accuracy;
  79. /**
  80. * Monster rune HP stat.
  81. */
  82. public $rune_hp;
  83. /**
  84. * Monster rune ATK stat.
  85. */
  86. public $rune_attack;
  87. /**
  88. * Monster rune DEF stat.
  89. */
  90. public $rune_defense;
  91. /**
  92. * Monster rune SPD stat.
  93. */
  94. public $rune_speed;
  95. /**
  96. * Monster rune CRR stat.
  97. */
  98. public $rune_crit_rate;
  99. /**
  100. * Monster rune CRD stat.
  101. */
  102. public $rune_crit_damage;
  103. /**
  104. * Monster rune RES stat.
  105. */
  106. public $rune_resistance;
  107. /**
  108. * Monster rune ACC stat.
  109. */
  110. public $rune_accuracy;
  111. /**
  112. * Average rune efficiency.
  113. */
  114. public $avg_rune_efficiency;
  115. /**
  116. * Indicates if the monster is fodder.
  117. */
  118. public $fodder;
  119. /**
  120. * Indicates if the monster is in storage.
  121. */
  122. public $in_storage;
  123. /**
  124. * Indicates if the monster is ignored in fusion calc.
  125. */
  126. public $ignore_for_fusion;
  127. /**
  128. * Monster priority.
  129. */
  130. public $priority;
  131. /**
  132. * Notes on the monster.
  133. */
  134. public $notes;
  135. /**
  136. * Equiped {@see Rune}s
  137. */
  138. public $rune = [];
  139. /**
  140. * Constructor.
  141. *
  142. * Searches the database and retrieves the information about the
  143. * monster, populating it and it's items.
  144. *
  145. * @param SQLite3 $db Connection to the database.
  146. * @param int $id Monster identifier.
  147. */
  148. public function __construct($db, $id){
  149. global $path;
  150. parent::__construct($db);
  151. $s =
  152. "SELECT " .
  153. " id, " .
  154. " com2us_id, " .
  155. " monster, " .
  156. " stars, " .
  157. " level, " .
  158. " skill_1_level, " .
  159. " skill_2_level, " .
  160. " skill_3_level, " .
  161. " skill_4_level, " .
  162. " base_hp, " .
  163. " base_attack, " .
  164. " base_defense, " .
  165. " base_speed, " .
  166. " base_crit_rate, " .
  167. " base_crit_damage, " .
  168. " base_resistance, " .
  169. " base_accuracy, " .
  170. " rune_hp, " .
  171. " rune_attack, " .
  172. " rune_defense, " .
  173. " rune_speed, " .
  174. " rune_crit_rate, " .
  175. " rune_crit_damage, " .
  176. " rune_resistance, " .
  177. " rune_accuracy, " .
  178. " avg_rune_efficiency, " .
  179. " fodder, " .
  180. " in_storage, " .
  181. " ignore_for_fusion, " .
  182. " priority, " .
  183. " notes " .
  184. "FROM monster " .
  185. "WHERE id = '$id'; ";
  186. $q = $this->db->query($s);
  187. $r = $q->fetchArray(SQLITE3_ASSOC);
  188. $this->id = $r["id"];
  189. $this->com2us_id = $r["com2us_id"];
  190. if (strlen($r["monster"]) > 0){
  191. $this->monster = new K_Monster($this->db, $r["monster"]);
  192. }
  193. $this->stars = $r["stars"];
  194. $this->level = $r["level"];
  195. $this->skill_1_level = $r["skill_1_level"];
  196. $this->skill_2_level = $r["skill_2_level"];
  197. $this->skill_3_level = $r["skill_3_level"];
  198. $this->skill_4_level = $r["skill_4_level"];
  199. $this->base_hp = $r["base_hp"];
  200. $this->base_attack = $r["base_attack"];
  201. $this->base_defense = $r["base_defense"];
  202. $this->base_speed = $r["base_speed"];
  203. $this->base_crit_rate = $r["base_crit_rate"];
  204. $this->base_crit_damage = $r["base_crit_damage"];
  205. $this->base_resistance = $r["base_resistance"];
  206. $this->base_accuracy = $r["base_accuracy"];
  207. $this->rune_hp = $r["rune_hp"];
  208. $this->rune_attack = $r["rune_attack"];
  209. $this->rune_defense = $r["rune_defense"];
  210. $this->rune_speed = $r["rune_speed"];
  211. $this->rune_crit_rate = $r["rune_crit_rate"];
  212. $this->rune_crit_damage = $r["rune_crit_damage"];
  213. $this->rune_resistance = $r["rune_resistance"];
  214. $this->rune_accuracy = $r["rune_accuracy"];
  215. $this->avg_rune_efficiency = $r["avg_rune_efficiency"];
  216. $this->fodder = $r["fodder"];
  217. $this->in_storage = $r["in_storage"];
  218. $this->ignore_for_fusion = $r["ignore_for_fusion"];
  219. $this->priority = $r["priority"];
  220. $this->notes = $r["notes"];
  221. $s =
  222. "SELECT rune " .
  223. "FROM monster_rune " .
  224. "WHERE monster = '$this->id'; ";
  225. $q = $this->db->query($s);
  226. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  227. array_push($this->rune, new Rune($this->db, $r["rune"]));
  228. }
  229. }
  230. /**
  231. * TODO: UNUSED
  232. * Gets a stat increase from rune monsters.
  233. *
  234. * @param $stat Stat name ("ATK", "DEF", "HP", "SPD", "CRR", "CRD", "RES", "ACC").
  235. * @return Value of the base stat (floored integer), -1 if wrong stat.
  236. */
  237. public function get_rune_stat($stat){
  238. switch ($stat){
  239. case "ATK":
  240. $base = $this->atk;
  241. $name_flat = 'ATK flat';
  242. $name_perc = 'ATK%';
  243. break;
  244. case "DEF":
  245. $base = $this->def;
  246. $name_flat = 'DEF flat';
  247. $name_perc = 'DEF%';
  248. break;
  249. case "HP":
  250. $base = $this->hp;
  251. $name_flat = 'HP flat';
  252. $name_perc = 'HP%';
  253. break;
  254. case "SPD":
  255. $base = $this->hp;
  256. $name_flat = 'SPD';
  257. $name_perc = '-';
  258. break;
  259. case "CRR":
  260. $base = $this->crr;
  261. $name_flat = 'CRate';
  262. $name_perc = '-';
  263. break;
  264. case "CRD":
  265. $base = $this->crd;
  266. $name_flat = 'CDmg';
  267. $name_perc = '-';
  268. break;
  269. case "RES":
  270. $base = $this->res;
  271. $name_flat = 'RES';
  272. $name_perc = '-';
  273. break;
  274. case "ACC":
  275. $base = $this->acc;
  276. $name_flat = 'ACC';
  277. $name_perc = '-';
  278. break;
  279. default:
  280. return -1;
  281. }
  282. $s =
  283. "SELECT sum(value) AS v FROM ( " .
  284. " SELECT m_v AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND m_t = '" . $name_flat . "' " .
  285. " UNION " .
  286. " SELECT cast(m_v * " . $base . " / 100 AS int) AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND m_t = '" . $name_perc . "' " .
  287. " UNION " .
  288. " SELECT i_v AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND i_t = '" . $name_flat . "' " .
  289. " UNION " .
  290. " SELECT cast(i_v * " . $base . " / 100 AS int) AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND i_t = '" . $name_perc . "' " .
  291. " UNION " .
  292. " SELECT s1_v AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s1_t = '" . $name_flat . "' " .
  293. " UNION " .
  294. " SELECT cast(s1_v * " . $base . " / 100 AS int) AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s1_t = '" . $name_perc . "' " .
  295. " UNION " .
  296. " SELECT s2_v AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s2_t = '" . $name_flat . "' " .
  297. " UNION " .
  298. " SELECT cast(s2_v * " . $base . " / 100 AS int) AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s2_t = '" . $name_perc . "' " .
  299. " UNION " .
  300. " SELECT s3_v AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s3_t = '" . $name_flat . "' " .
  301. " UNION " .
  302. " SELECT cast(s3_v * " . $base . " / 100 AS int) AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s3_t = '" . $name_perc . "' " .
  303. " UNION " .
  304. " SELECT s4_v AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s4_t = '" . $name_flat . "' " .
  305. " UNION " .
  306. " SELECT cast(s4_v * " . $base . " / 100 AS int) AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s4_t = '" . $name_perc . "' " .
  307. ");";
  308. $q = $this->db->query($s);
  309. $r = $q->fetchArray(SQLITE3_ASSOC);
  310. return $r["v"];
  311. }
  312. }
  313. ?>