Rune.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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
  58. */
  59. public $quality;
  60. /**
  61. * @var int Rune original quality.
  62. *
  63. * @see QUALITY
  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
  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
  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
  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
  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
  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
  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. $s =
  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. $q = $db->query($s);
  238. $r = $q->fetchArray(SQLITE3_ASSOC);
  239. if ($r){
  240. $this->id = $r["id"];
  241. $this->assigned_to = $r["assigned_to"];
  242. $this->type = new K_Rune_Set($r["type"]);
  243. $this->slot = $r["slot"];
  244. $this->stars = $r["stars"];
  245. $this->level = $r["level"];
  246. $this->ancient = $r["ancient"];
  247. $this->quality = $r["quality"];
  248. $this->original_quality = $r["original_quality"];
  249. $this->value = $r["value"];
  250. $this->efficiency = $r["efficiency"];
  251. $this->max_efficiency = $r["max_efficiency"];
  252. $this->main_stat = $r["main_stat"];
  253. $this->main_stat_value = $r["main_stat_value"];
  254. $this->innate_stat = $r["innate_stat"];
  255. $this->innate_stat_value = $r["innate_stat_value"];
  256. $this->substat_1 = $r["substat_1"];
  257. $this->substat_1_value = $r["substat_1_value"];
  258. $this->substat_1_enchant = $r["substat_1_enchant"];
  259. $this->substat_1_grind = $r["substat_1_grind"];
  260. $this->substat_2 = $r["substat_2"];
  261. $this->substat_2_value = $r["substat_2_value"];
  262. $this->substat_2_enchant = $r["substat_2_enchant"];
  263. $this->substat_2_grind = $r["substat_2_grind"];
  264. $this->substat_3 = $r["substat_3"];
  265. $this->substat_3_value = $r["substat_3_value"];
  266. $this->substat_3_enchant = $r["substat_3_enchant"];
  267. $this->substat_3_grind = $r["substat_3_grind"];
  268. $this->substat_4 = $r["substat_4"];
  269. $this->substat_4_value = $r["substat_4_value"];
  270. $this->substat_4_enchant = $r["substat_4_enchant"];
  271. $this->substat_4_grind = $r["substat_4_grind"];
  272. $this->refresh_names();
  273. }
  274. }
  275. /**
  276. * Gets the value of the main stat at an arbitrary level.
  277. *
  278. * @param int $level Desired level.
  279. * @return int Value of the main stat at the selected level.
  280. */
  281. public function get_main_stat_at_level($level){
  282. $level = intval($level);
  283. if ($level < 0 || $level > 15){
  284. return 0;
  285. }
  286. switch ($this->main_stat){
  287. case RUNE_STAT_ID::HP:
  288. return RUNE_STAT_VALUES::HP[$this->stars][$level];
  289. case RUNE_STAT_ID::HP_P:
  290. return RUNE_STAT_VALUES::HP_P[$this->stars][$level];
  291. case RUNE_STAT_ID::ATK:
  292. return RUNE_STAT_VALUES::ATK[$this->stars][$level];
  293. case RUNE_STAT_ID::ATK_P:
  294. return RUNE_STAT_VALUES::ATK_P[$this->stars][$level];
  295. case RUNE_STAT_ID::DEF:
  296. return RUNE_STAT_VALUES::DEF[$this->stars][$level];
  297. case RUNE_STAT_ID::DEF_P:
  298. return RUNE_STAT_VALUES::DEF_P[$this->stars][$level];
  299. case RUNE_STAT_ID::SPD:
  300. return RUNE_STAT_VALUES::SPD[$this->stars][$level];
  301. case RUNE_STAT_ID::CRR:
  302. return RUNE_STAT_VALUES::CRR[$this->stars][$level];
  303. case RUNE_STAT_ID::CRD:
  304. return RUNE_STAT_VALUES::CRD[$this->stars][$level];
  305. case RUNE_STAT_ID::RES:
  306. return RUNE_STAT_VALUES::RES[$this->stars][$level];
  307. case RUNE_STAT_ID::ACC:
  308. return RUNE_STAT_VALUES::ACC[$this->stars][$level];
  309. default:
  310. return 0;
  311. }
  312. }
  313. /**
  314. * Calculates name variables.
  315. */
  316. public function refresh_names(){
  317. $this->main_stat_name = $this->stat_name($this->main_stat);
  318. $this->innate_stat_name = $this->stat_name($this->innate_stat);
  319. $this->substat_1_name = $this->stat_name($this->substat_1);
  320. $this->substat_2_name = $this->stat_name($this->substat_2);
  321. $this->substat_3_name = $this->stat_name($this->substat_3);
  322. $this->substat_4_name = $this->stat_name($this->substat_4);
  323. $this->quality_name = $this->get_quality_name($this->quality);
  324. $this->original_quality_name = $this->get_quality_name($this->original_quality);
  325. }
  326. /**
  327. * Gets a stat name from the mappings.
  328. *
  329. * @param int $stat Stat id.
  330. * @return string Stat name (Uppercase)
  331. */
  332. private function stat_name($stat){
  333. switch ($stat){
  334. case RUNE_STAT_ID::HP:
  335. return "HP";
  336. case RUNE_STAT_ID::HP_P:
  337. return "HP%";
  338. case RUNE_STAT_ID::ATK:
  339. return "ATK";
  340. case RUNE_STAT_ID::ATK_P:
  341. return "ATK%";
  342. case RUNE_STAT_ID::DEF:
  343. return "DEF";
  344. case RUNE_STAT_ID::DEF_P:
  345. return "DEF%";
  346. case RUNE_STAT_ID::SPD:
  347. return "SPD";
  348. case RUNE_STAT_ID::CRR:
  349. return "CRR";
  350. case RUNE_STAT_ID::CRD:
  351. return "CRD";
  352. case RUNE_STAT_ID::RES:
  353. return "RES";
  354. case RUNE_STAT_ID::ACC:
  355. return "ACC";
  356. default:
  357. return "";
  358. }
  359. }
  360. /**
  361. * Gets a stat name frm the mappings.
  362. *
  363. * @param int $q Quality id.
  364. * @return string Quality (Uppercase)
  365. */
  366. private function get_quality_name($q){
  367. switch ($q){
  368. case QUALITY_ID::NORMAL:
  369. return "NORMAL";
  370. case QUALITY_ID::MAGIC:
  371. return "MAGIC";
  372. case QUALITY_ID::RARE:
  373. return "RARE";
  374. case QUALITY_ID::HERO:
  375. return "HERO";
  376. case QUALITY_ID::LEGEND:
  377. return "LEGEND";
  378. default:
  379. return "";
  380. }
  381. }
  382. }
  383. ?>