Rune.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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 resource $db Connection to the database.
  197. * @param int $id Rune id.
  198. */
  199. public function __construct($db, $id){
  200. parent::__construct($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 = $this->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($this->db, $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. * Calculates name variables.
  277. */
  278. public function refresh_names(){
  279. $this->main_stat_name = $this->stat_name($this->main_stat);
  280. $this->innate_stat_name = $this->stat_name($this->innate_stat);
  281. $this->substat_1_name = $this->stat_name($this->substat_1);
  282. $this->substat_2_name = $this->stat_name($this->substat_2);
  283. $this->substat_3_name = $this->stat_name($this->substat_3);
  284. $this->substat_4_name = $this->stat_name($this->substat_4);
  285. $this->quality_name = $this->get_quality_name($this->quality);
  286. $this->original_quality_name = $this->get_quality_name($this->original_quality);
  287. }
  288. /**
  289. * Gets a stat name from the mappings.
  290. *
  291. * @param int $stat Stat id.
  292. * @return string Stat name (Uppercase)
  293. */
  294. private function stat_name($stat){
  295. switch ($stat){
  296. case RUNE_STAT_ID::HP:
  297. return "HP";
  298. case RUNE_STAT_ID::HP_P:
  299. return "HP%";
  300. case RUNE_STAT_ID::ATK:
  301. return "ATK";
  302. case RUNE_STAT_ID::ATK_P:
  303. return "ATK%";
  304. case RUNE_STAT_ID::DEF:
  305. return "DEF";
  306. case RUNE_STAT_ID::DEF_P:
  307. return "DEF%";
  308. case RUNE_STAT_ID::SPD:
  309. return "SPD";
  310. case RUNE_STAT_ID::CRR:
  311. return "CRR";
  312. case RUNE_STAT_ID::CRD:
  313. return "CRD";
  314. case RUNE_STAT_ID::RES:
  315. return "RES";
  316. case RUNE_STAT_ID::ACC:
  317. return "ACC";
  318. default:
  319. return "";
  320. }
  321. }
  322. /**
  323. * Gets a stat name frm the mappings.
  324. *
  325. * @param int $q Quality id.
  326. * @return string Quality (Uppercase)
  327. */
  328. private function get_quality_name($q){
  329. switch ($q){
  330. case QUALITY_ID::NORMAL:
  331. return "NORMAL";
  332. case QUALITY_ID::MAGIC:
  333. return "MAGIC";
  334. case QUALITY_ID::RARE:
  335. return "RARE";
  336. case QUALITY_ID::HERO:
  337. return "HERO";
  338. case QUALITY_ID::LEGEND:
  339. return "LEGEND";
  340. default:
  341. return "";
  342. }
  343. }
  344. }
  345. ?>