Rune.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <?php
  2. /**
  3. * Rune entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @category Entity
  8. */
  9. /**
  10. * Require dependent entities if not present.
  11. */
  12. require_once(PATH::ENTITY . "Entity.php");
  13. require_once(PATH::ENTITY . "K_Rune_Set.php");
  14. /**
  15. * Owned rune.
  16. *
  17. * Represents an object from the table 'rune'.
  18. *
  19. * @category Entity
  20. */
  21. class Rune extends Entity{
  22. /**
  23. * @var int Owner identifier.
  24. */
  25. public $uid;
  26. /**
  27. * @var int Rune identifier.
  28. */
  29. public $id;
  30. /**
  31. * @var int ID of the monster the rune is assigned to.
  32. */
  33. public $assigned_to;
  34. /**
  35. * @var K_Rune_Set Rune set.
  36. */
  37. public $type;
  38. /**
  39. * @var int Position of the rune type (1-6).
  40. */
  41. public $slot;
  42. /**
  43. * @var int Rune stars.
  44. */
  45. public $stars;
  46. /**
  47. * @var bool Indicates if the rune is ancient.
  48. */
  49. public $ancient;
  50. /**
  51. * @var int Level of the rune.
  52. */
  53. public $level;
  54. /**
  55. * @var int Rune quality.
  56. *
  57. * @see QUALITY_ID
  58. */
  59. public $quality;
  60. /**
  61. * @var int Rune original quality.
  62. *
  63. * @see QUALITY_ID
  64. */
  65. public $original_quality;
  66. /**
  67. * @var string Rune quality name (uppercase).
  68. */
  69. public $quality_name;
  70. /**
  71. * @var string Rune original quality name (uppercase).
  72. */
  73. public $original_quality_name;
  74. /**
  75. * @var int Price of the rune.
  76. */
  77. public $value;
  78. /**
  79. * @var float Current efficiency of the rune.
  80. */
  81. public $efficiency;
  82. /**
  83. * @var float Maximum potential efficiency of the rune.
  84. */
  85. public $max_efficiency;
  86. /**
  87. * @var int Main stat of the rune.
  88. *
  89. * @see RUNE_STAT_ID
  90. */
  91. public $main_stat;
  92. /**
  93. * @var string Main stat name (uppercase).
  94. */
  95. public $main_stat_name;
  96. /**
  97. * @var int Main stat value of the rune.
  98. */
  99. public $main_stat_value;
  100. /**
  101. * @var int Extra stat of the rune.
  102. *
  103. * @see RUNE_STAT_ID
  104. */
  105. public $innate_stat;
  106. /**
  107. * @var string Extra stat name (uppercase).
  108. */
  109. public $innate_stat_name;
  110. /**
  111. * @var string Extra stat value of the rune.
  112. */
  113. public $innate_stat_value;
  114. /**
  115. * @var int Number of substats.
  116. */
  117. public $substats;
  118. /**
  119. * @var int Substat 1 of the rune.
  120. *
  121. * @see RUNE_STAT_ID
  122. */
  123. public $substat_1;
  124. /**
  125. * @var string Substat 1 name (uppercase).
  126. */
  127. public $substat_1_name;
  128. /**
  129. * @var int Substat 1 value of the rune.
  130. */
  131. public $substat_1_value;
  132. /**
  133. * @var int Ammount gained by the substat 1 enchant.
  134. */
  135. public $substat_1_craft;
  136. /**
  137. * @var int Substat 2 of the rune.
  138. *
  139. * @see RUNE_STAT_ID
  140. */
  141. public $substat_2;
  142. /**
  143. * @var string Substat 2 name (uppercase).
  144. */
  145. public $substat_2_name;
  146. /**
  147. * @var int Substat 2 value of the rune.
  148. */
  149. public $substat_2_value;
  150. /**
  151. * @var int Ammount gained by the substat 2 enchant.
  152. */
  153. public $substat_2_craft;
  154. /**
  155. * @var int Substat 3 of the rune.
  156. *
  157. * @see RUNE_STAT_ID
  158. */
  159. public $substat_3;
  160. /**
  161. * @var string Substat 3 name (uppercase).
  162. */
  163. public $substat_3_name;
  164. /**
  165. * @var int Substat 3 value of the rune.
  166. */
  167. public $substat_3_value;
  168. /**
  169. * @var int Ammount gained by the substat 3 enchant.
  170. */
  171. public $substat_3_craft;
  172. /**
  173. * @var int Substat 4 of the rune.
  174. *
  175. * @see RUNE_STAT_ID
  176. */
  177. public $substat_4;
  178. /**
  179. * @var string Substat 4 name (uppercase).
  180. */
  181. public $substat_4_name;
  182. /**
  183. * @var int Substat 4 value of the rune.
  184. */
  185. public $substat_4_value;
  186. /**
  187. * @var int Ammount gained by the substat 4 enchant.
  188. */
  189. public $substat_4_craft;
  190. /**
  191. * Constructor.
  192. *
  193. * Searches the database and retrieves the information about the
  194. * rune, populating it and it's items.
  195. *
  196. * @param int $id Rune id.
  197. * @global resource Database connection.
  198. */
  199. public function __construct($id){
  200. global $db;
  201. $statement = $db->prepare("
  202. SELECT
  203. id,
  204. assigned_to,
  205. type,
  206. slot,
  207. stars,
  208. level,
  209. ancient,
  210. quality,
  211. original_quality,
  212. value,
  213. efficiency,
  214. max_efficiency,
  215. main_stat,
  216. main_stat_value,
  217. innate_stat,
  218. innate_stat_value,
  219. substat_1,
  220. substat_1_value,
  221. substat_1_enchant,
  222. substat_1_grind,
  223. substat_2,
  224. substat_2_value,
  225. substat_2_enchant,
  226. substat_2_grind,
  227. substat_3,
  228. substat_3_value,
  229. substat_3_enchant,
  230. substat_3_grind,
  231. substat_4,
  232. substat_4_value,
  233. substat_4_enchant,
  234. substat_4_grind
  235. FROM rune
  236. WHERE id = :id;
  237. ");
  238. $statement->bindValue(':id', $id, SQLITE3_INTEGER);
  239. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  240. if ($r){
  241. $this->id = $r["id"];
  242. $this->assigned_to = $r["assigned_to"];
  243. $this->type = new K_Rune_Set($r["type"]);
  244. $this->slot = $r["slot"];
  245. $this->stars = $r["stars"];
  246. $this->level = $r["level"];
  247. $this->ancient = $r["ancient"];
  248. $this->quality = $r["quality"];
  249. $this->original_quality = $r["original_quality"];
  250. $this->value = $r["value"];
  251. $this->efficiency = $r["efficiency"];
  252. $this->max_efficiency = $r["max_efficiency"];
  253. $this->main_stat = $r["main_stat"];
  254. $this->main_stat_value = $r["main_stat_value"];
  255. $this->innate_stat = $r["innate_stat"];
  256. $this->innate_stat_value = $r["innate_stat_value"];
  257. $this->substat_1 = $r["substat_1"];
  258. $this->substat_1_value = $r["substat_1_value"];
  259. $this->substat_1_enchant = $r["substat_1_enchant"];
  260. $this->substat_1_grind = $r["substat_1_grind"];
  261. $this->substat_2 = $r["substat_2"];
  262. $this->substat_2_value = $r["substat_2_value"];
  263. $this->substat_2_enchant = $r["substat_2_enchant"];
  264. $this->substat_2_grind = $r["substat_2_grind"];
  265. $this->substat_3 = $r["substat_3"];
  266. $this->substat_3_value = $r["substat_3_value"];
  267. $this->substat_3_enchant = $r["substat_3_enchant"];
  268. $this->substat_3_grind = $r["substat_3_grind"];
  269. $this->substat_4 = $r["substat_4"];
  270. $this->substat_4_value = $r["substat_4_value"];
  271. $this->substat_4_enchant = $r["substat_4_enchant"];
  272. $this->substat_4_grind = $r["substat_4_grind"];
  273. $this->refresh_names();
  274. }
  275. }
  276. /**
  277. * Gets the value of the main stat at an arbitrary level.
  278. *
  279. * @param int $level Desired level.
  280. * @return int Value of the main stat at the selected level.
  281. */
  282. public function get_main_stat_at_level($level){
  283. $level = intval($level);
  284. if ($level < 0 || $level > 15){
  285. return 0;
  286. }
  287. switch ($this->main_stat){
  288. case RUNE_STAT_ID::HP:
  289. return RUNE_STAT_VALUES::HP[$this->stars][$level];
  290. case RUNE_STAT_ID::HP_P:
  291. return RUNE_STAT_VALUES::HP_P[$this->stars][$level];
  292. case RUNE_STAT_ID::ATK:
  293. return RUNE_STAT_VALUES::ATK[$this->stars][$level];
  294. case RUNE_STAT_ID::ATK_P:
  295. return RUNE_STAT_VALUES::ATK_P[$this->stars][$level];
  296. case RUNE_STAT_ID::DEF:
  297. return RUNE_STAT_VALUES::DEF[$this->stars][$level];
  298. case RUNE_STAT_ID::DEF_P:
  299. return RUNE_STAT_VALUES::DEF_P[$this->stars][$level];
  300. case RUNE_STAT_ID::SPD:
  301. return RUNE_STAT_VALUES::SPD[$this->stars][$level];
  302. case RUNE_STAT_ID::CRR:
  303. return RUNE_STAT_VALUES::CRR[$this->stars][$level];
  304. case RUNE_STAT_ID::CRD:
  305. return RUNE_STAT_VALUES::CRD[$this->stars][$level];
  306. case RUNE_STAT_ID::RES:
  307. return RUNE_STAT_VALUES::RES[$this->stars][$level];
  308. case RUNE_STAT_ID::ACC:
  309. return RUNE_STAT_VALUES::ACC[$this->stars][$level];
  310. default:
  311. return 0;
  312. }
  313. }
  314. /**
  315. * Calculates name variables.
  316. */
  317. public function refresh_names(){
  318. $this->main_stat_name = $this->stat_name($this->main_stat);
  319. $this->innate_stat_name = $this->stat_name($this->innate_stat);
  320. $this->substat_1_name = $this->stat_name($this->substat_1);
  321. $this->substat_2_name = $this->stat_name($this->substat_2);
  322. $this->substat_3_name = $this->stat_name($this->substat_3);
  323. $this->substat_4_name = $this->stat_name($this->substat_4);
  324. $this->quality_name = $this->get_quality_name($this->quality);
  325. $this->original_quality_name = $this->get_quality_name($this->original_quality);
  326. }
  327. /**
  328. * Gets a stat name from the mappings.
  329. *
  330. * @param int $stat Stat id.
  331. * @return string Stat name (Uppercase)
  332. */
  333. private function stat_name($stat){
  334. switch ($stat){
  335. case RUNE_STAT_ID::HP:
  336. return "HP";
  337. case RUNE_STAT_ID::HP_P:
  338. return "HP%";
  339. case RUNE_STAT_ID::ATK:
  340. return "ATK";
  341. case RUNE_STAT_ID::ATK_P:
  342. return "ATK%";
  343. case RUNE_STAT_ID::DEF:
  344. return "DEF";
  345. case RUNE_STAT_ID::DEF_P:
  346. return "DEF%";
  347. case RUNE_STAT_ID::SPD:
  348. return "SPD";
  349. case RUNE_STAT_ID::CRR:
  350. return "CRR";
  351. case RUNE_STAT_ID::CRD:
  352. return "CRD";
  353. case RUNE_STAT_ID::RES:
  354. return "RES";
  355. case RUNE_STAT_ID::ACC:
  356. return "ACC";
  357. default:
  358. return "";
  359. }
  360. }
  361. /**
  362. * Gets a stat name frm the mappings.
  363. *
  364. * @param int $q Quality id.
  365. * @return string Quality (Uppercase)
  366. */
  367. private function get_quality_name($q){
  368. switch ($q){
  369. case QUALITY_ID::NORMAL:
  370. return "NORMAL";
  371. case QUALITY_ID::MAGIC:
  372. return "MAGIC";
  373. case QUALITY_ID::RARE:
  374. return "RARE";
  375. case QUALITY_ID::HERO:
  376. return "HERO";
  377. case QUALITY_ID::LEGEND:
  378. return "LEGEND";
  379. default:
  380. return "";
  381. }
  382. }
  383. }
  384. ?>