Enchantment.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. /**
  3. * Enchantments items 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 . "Rune_Set.php");
  14. /**
  15. * Owned enchantments.
  16. *
  17. * Represents an object from the table 'enchantment'.
  18. *
  19. * @category Entity
  20. */
  21. class Enchantment extends Entity{
  22. private $player_id;
  23. private $id;
  24. private $quality;
  25. private $quality_name;
  26. private $rune_set;
  27. private $stat;
  28. private $stat_name;
  29. private $gem;
  30. private $ancient;
  31. private $inmemorial;
  32. private $name;
  33. private $min;
  34. private $max;
  35. private $value;
  36. private $amount;
  37. /**
  38. * Constructor.
  39. *
  40. * Searches the database and retrieves the information about the
  41. * rune, populating it and it's items.
  42. *
  43. * @param int $id Enchantment id.
  44. */
  45. public function __construct($id){
  46. $statement = get_context()->get_db()->prepare("
  47. SELECT
  48. enchantment.player AS player,
  49. enchantment.id AS id,
  50. enchantment.quality As quality,
  51. enchantment.rune AS rune,
  52. enchantment.stat AS stat,
  53. enchantment.value AS value,
  54. enchantment.amount AS amount,
  55. enchantment_type.name AS name,
  56. enchantment_type.gem AS gem,
  57. enchantment_type.inmemorial AS inmemorial,
  58. enchantment_type.ancient AS ancient,
  59. enchantment_range.min AS min,
  60. enchantment_range.max AS max
  61. FROM
  62. enchantment,
  63. enchantment_type,
  64. enchantment_range
  65. WHERE
  66. enchantment.id = :id AND
  67. enchantment.type = enchantment_type.id AND
  68. enchantment_type.gem = enchantment_range.gem AND
  69. enchantment_type.gem = enchantment_range.gem AND
  70. enchantment_type.ancient = enchantment_range.ancient AND
  71. enchantment.quality = enchantment_range.quality AND
  72. enchantment.stat = enchantment_range.stat;
  73. ");
  74. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  75. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  76. if ($r){
  77. $this->player_id = $r["player"];
  78. $this->id = $r["id"];
  79. if ($r["gem"] == 0){
  80. $this->gem = false;
  81. }
  82. else{
  83. $this->gem = true;
  84. }
  85. $this->quality = $r["quality"];
  86. $this->quality_name = $this->quality_name($r["quality"]);
  87. $this->stat = $r["stat"];
  88. $this->stat_name = $this->stat_name($r["stat"]);
  89. if ($r["ancient"] == 0){
  90. $this->ancient = false;
  91. }
  92. else{
  93. $this->ancient = true;
  94. }
  95. $this->inmemorial = $r["inmemorial"];
  96. if ($r["inmemorial"] == 0){
  97. $this->rune_set = new Rune_Set($r["rune"]);
  98. $this->name = $this->rune_set->get_name() . " " . $r["stat"];
  99. $this->inmemorial = false;
  100. }
  101. else{
  102. $this->inmemorial = true;
  103. $this->name = "Inmemorial " . $r["stat"];
  104. }
  105. $this->min = $r["min"];
  106. $this->max = $r["max"];
  107. $this->value = $r["value"];
  108. $this->amount = $r["amount"];
  109. }
  110. }
  111. /**
  112. * Gets a stat name from the maps.
  113. *
  114. * @param int $stat Stat id.
  115. * @return string Stat name (Uppercase)
  116. */
  117. private function stat_name($stat){
  118. switch ($stat){
  119. case RUNE_STAT_ID::HP:
  120. return "HP";
  121. case RUNE_STAT_ID::HP_P:
  122. return "HP%";
  123. case RUNE_STAT_ID::ATK:
  124. return "ATK";
  125. case RUNE_STAT_ID::ATK_P:
  126. return "ATK%";
  127. case RUNE_STAT_ID::DEF:
  128. return "DEF";
  129. case RUNE_STAT_ID::DEF_P:
  130. return "DEF%";
  131. case RUNE_STAT_ID::SPD:
  132. return "SPD";
  133. case RUNE_STAT_ID::CRR:
  134. return "CRR";
  135. case RUNE_STAT_ID::CRD:
  136. return "CRD";
  137. case RUNE_STAT_ID::RES:
  138. return "RES";
  139. case RUNE_STAT_ID::ACC:
  140. return "ACC";
  141. default:
  142. return "";
  143. }
  144. }
  145. /**
  146. * Gets a stat name from the maps.
  147. *
  148. * @param int $q Quality id.
  149. * @return string Quality (Uppercase)
  150. */
  151. private function quality_name($q){
  152. switch ($q){
  153. case QUALITY_ID::NORMAL:
  154. return "NORMAL";
  155. case QUALITY_ID::MAGIC:
  156. return "MAGIC";
  157. case QUALITY_ID::RARE:
  158. return "RARE";
  159. case QUALITY_ID::HERO:
  160. return "HERO";
  161. case QUALITY_ID::LEGEND:
  162. return "LEGEND";
  163. default:
  164. return "";
  165. }
  166. }
  167. /**
  168. * Calculates name variables.
  169. */
  170. public function refresh_names(){
  171. $this->stat_name = $this->stat_name($this->stat);
  172. $this->quality_name = $this->quality_name($this->quality);
  173. $this->name = $this->rune->name . " " . $this->stat;
  174. if ($this->inmemorial == 0){
  175. $this->name = $this->rune->name . " " . $this->stat;
  176. }
  177. else{
  178. $this->name = "Inmemorial " . $this->stat;
  179. }
  180. }
  181. /**
  182. * Retrieves the owner's player identifier.
  183. *
  184. * @return int player identifier.
  185. */
  186. public function get_player_id(){
  187. return $this->player_id;
  188. }
  189. /**
  190. * Retrieves the enchantment identifier.
  191. *
  192. * @return string Enchantment ID.
  193. */
  194. public function get_id(){
  195. return $this->id;
  196. }
  197. /**
  198. * Retrieves the quality of the enchantment.
  199. *
  200. * @see QUALITY_ID
  201. *
  202. * @return int Quality.
  203. */
  204. public function get_quality(){
  205. return $this->quality;
  206. }
  207. /**
  208. * Retrieves the quality name of the enchantment.
  209. *
  210. * @return string Quality name.
  211. */
  212. public function get_quality_name(){
  213. return $this->quality_name;
  214. }
  215. /**
  216. * Retrieves the rune set the enchantment can be used on.
  217. *
  218. * @return Rune_Set The set the enchantment can be used on, null for inmemorials.
  219. */
  220. public function get_rune_set(){
  221. return $this->rune_set;
  222. }
  223. /**
  224. * Retrieves the stat affected by the enchantment.
  225. *
  226. * @see RUNE_STAT_ID
  227. *
  228. * @return int Stat ID.
  229. */
  230. public function get_stat(){
  231. return $this->stat;
  232. }
  233. /**
  234. * Retrieves the name of the affected stat.
  235. *
  236. * @return string Stat name
  237. */
  238. public function get_stat_name(){
  239. return $this->stat_name;
  240. }
  241. /**
  242. * Checks if the enchantment is a enchanted gem.
  243. *
  244. * @return boolean true for enchanted gems, false for grindstones.
  245. */
  246. public function is_gem(){
  247. return $this->gem;
  248. }
  249. /**
  250. * Checks if the enchantment is a grindstone.
  251. *
  252. * @return boolean true for grindstones, false enchanted gems.
  253. */
  254. public function is_grind(){
  255. return ! $this->gem;
  256. }
  257. /**
  258. * Checks if it's an ancient enchantment.
  259. *
  260. * @return boolean Tur if anciend, false if normal.
  261. */
  262. public function is_ancient(){
  263. return $this->ancient;
  264. }
  265. /**
  266. * Checks if the enchantment is inmemorial.
  267. *
  268. * @return boolean True for inmemorial, false otherwise.
  269. */
  270. public function is_inmemorial(){
  271. return $this->inmemorial;
  272. }
  273. /**
  274. * Retrieves the enchantment name.
  275. *
  276. * @return string Enchantment name.
  277. */
  278. public function get_name(){
  279. return $this->name;
  280. }
  281. /**
  282. * Retrieves the minumum value for the enchantment.
  283. *
  284. * @return int Minimum enchant outcome.
  285. */
  286. public function get_min(){
  287. return $this->min;
  288. }
  289. /**
  290. * Retrieves the maximum value for the enchantment.
  291. *
  292. * @return int maximum enchant outcome.
  293. */
  294. public function get_max(){
  295. return $this->max;
  296. }
  297. /**
  298. * Retrieves the value of the enchantment in mana stones.
  299. *
  300. * @return int Value of the enchantment.
  301. */
  302. public function get_value(){
  303. return $this->value;
  304. }
  305. /**
  306. * Retrieves the amount of the same enchantment owned by the user.
  307. *
  308. * @return int Number of the enchantments owned.
  309. */
  310. public function get_amount(){
  311. return $this->amount;
  312. }
  313. }
  314. ?>