Enchantment.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. /**
  23. * @var int Owner's player identifier.
  24. */
  25. public $player;
  26. /**
  27. * @var int Item identifier.
  28. */
  29. public $id;
  30. /**
  31. * @var int Item quality.
  32. *
  33. * @see QUALITY_ID
  34. */
  35. public $quality;
  36. /**
  37. * @var string Item quality name.
  38. */
  39. public $quality_name;
  40. /**
  41. * @var K_Rune_Set Rune set the item can be used on.
  42. */
  43. public $rune;
  44. /**
  45. * @var int Stat the item modifies.
  46. *
  47. * @see RUNE_STAT_ID
  48. */
  49. public $stat;
  50. /**
  51. * @var string Stat name.
  52. */
  53. public $stat_name;
  54. /**
  55. * @var bool Indicates if the Item is a gem.
  56. */
  57. public $gem;
  58. /**
  59. * @var bool Indicates if the Item is ancient.
  60. */
  61. public $ancient;
  62. /**
  63. * @var bool Indicates if the Item is inmemorial.
  64. */
  65. public $inmemorial;
  66. /**
  67. * @var string Item name.
  68. */
  69. public $name;
  70. /**
  71. * @var int Minimum value of the stat.
  72. */
  73. public $min;
  74. /**
  75. * @var int Maximum value of the stat.
  76. */
  77. public $max;
  78. /**
  79. * @var int Sell value.
  80. */
  81. public $value;
  82. /**
  83. * @var int Number of item of this type owned.
  84. */
  85. public $amount;
  86. /**
  87. * Constructor.
  88. *
  89. * Searches the database and retrieves the information about the
  90. * rune, populating it and it's items.
  91. *
  92. * @param int $id Enchantment id.
  93. * @global resource Database connection.
  94. */
  95. public function __construct($id){
  96. global $db;
  97. $statement = $db->prepare("
  98. SELECT
  99. enchantment.player AS player,
  100. enchantment.id AS id,
  101. enchantment.quality As quality,
  102. enchantment.rune AS rune,
  103. enchantment.stat AS stat,
  104. enchantment.value AS value,
  105. enchantment.amount AS amount,
  106. enchantment_type.name AS name,
  107. enchantment_type.gem AS gem,
  108. enchantment_type.inmemorial AS inmemorial,
  109. enchantment_type.ancient AS ancient,
  110. enchantment_range.min AS min,
  111. enchantment_range.max AS max
  112. FROM
  113. enchantment,
  114. enchantment_type,
  115. enchantment_range
  116. WHERE
  117. enchantment.id = :id AND
  118. enchantment.type = enchantment_type.id AND
  119. enchantment_type.gem = enchantment_range.gem AND
  120. enchantment_type.gem = enchantment_range.gem AND
  121. enchantment_type.ancient = enchantment_range.ancient AND
  122. enchantment.quality = enchantment_range.quality AND
  123. enchantment.stat = enchantment_range.stat;
  124. ");
  125. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  126. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  127. if ($r){
  128. $this->player = $r["player"];
  129. $this->id = $r["id"];
  130. $this->gem = $r["gem"];
  131. $this->quality = $r["quality"];
  132. $this->quality_name = $this->quality_name($r["quality"]);
  133. $this->stat = $r["stat"];
  134. $this->stat_name = $this->stat_name($r["stat"]);
  135. $this->ancient = $r["ancient"];
  136. $this->inmemorial = $r["inmemorial"];
  137. if ($this->inmemorial == 0){
  138. $this->rune = new Rune_Set($r["rune"]);
  139. $this->name = $this->rune->name . " " . $r["stat"];
  140. }
  141. else{
  142. $this->name = "Inmemorial " . $r["stat"];
  143. }
  144. $this->min = $r["min"];
  145. $this->max = $r["max"];
  146. $this->value = $r["value"];
  147. $this->amount = $r["amount"];
  148. }
  149. }
  150. /**
  151. * Gets a stat name from the maps.
  152. *
  153. * @param int $stat Stat id.
  154. * @return string Stat name (Uppercase)
  155. */
  156. private function stat_name($stat){
  157. switch ($stat){
  158. case RUNE_STAT_ID::HP:
  159. return "HP";
  160. case RUNE_STAT_ID::HP_P:
  161. return "HP%";
  162. case RUNE_STAT_ID::ATK:
  163. return "ATK";
  164. case RUNE_STAT_ID::ATK_P:
  165. return "ATK%";
  166. case RUNE_STAT_ID::DEF:
  167. return "DEF";
  168. case RUNE_STAT_ID::DEF_P:
  169. return "DEF%";
  170. case RUNE_STAT_ID::SPD:
  171. return "SPD";
  172. case RUNE_STAT_ID::CRR:
  173. return "CRR";
  174. case RUNE_STAT_ID::CRD:
  175. return "CRD";
  176. case RUNE_STAT_ID::RES:
  177. return "RES";
  178. case RUNE_STAT_ID::ACC:
  179. return "ACC";
  180. default:
  181. return "";
  182. }
  183. }
  184. /**
  185. * Gets a stat name from the maps.
  186. *
  187. * @param int $q Quality id.
  188. * @return string Quality (Uppercase)
  189. */
  190. private function quality_name($q){
  191. switch ($q){
  192. case QUALITY_ID::NORMAL:
  193. return "NORMAL";
  194. case QUALITY_ID::MAGIC:
  195. return "MAGIC";
  196. case QUALITY_ID::RARE:
  197. return "RARE";
  198. case QUALITY_ID::HERO:
  199. return "HERO";
  200. case QUALITY_ID::LEGEND:
  201. return "LEGEND";
  202. default:
  203. return "";
  204. }
  205. }
  206. /**
  207. * Calculates name variables.
  208. */
  209. public function refresh_names(){
  210. $this->stat_name = $this->stat_name($this->stat);
  211. $this->quality_name = $this->quality_name($this->quality);
  212. $this->name = $this->rune->name . " " . $this->stat;
  213. if ($this->inmemorial == 0){
  214. $this->name = $this->rune->name . " " . $this->stat;
  215. }
  216. else{
  217. $this->name = "Inmemorial " . $this->stat;
  218. }
  219. }
  220. }
  221. ?>