Rune_Craft.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * Rune craft 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 . "K_Rune_Set.php");
  14. /**
  15. * Owned rune craft item.
  16. *
  17. * Represents an object from the table 'rune_craft'.
  18. *
  19. * @category Entity
  20. */
  21. class Rune_Craft extends Entity{
  22. /**
  23. * @var int Owner identifier.
  24. */
  25. public $uid;
  26. /**
  27. * @var int Item identifier.
  28. */
  29. public $id;
  30. /**
  31. * @var int Item quality.
  32. *
  33. * @see QUALITY
  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
  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 Rune id.
  93. * @global resource Database connection.
  94. */
  95. public function __construct($id){
  96. global $db;
  97. $s = "
  98. SELECT
  99. rune_craft.id AS id,
  100. rune_craft.quality As quality,
  101. rune_craft.rune AS rune,
  102. rune_craft.stat AS stat,
  103. rune_craft.value AS value,
  104. rune_craft.amount AS amount,
  105. k_rune_craft_type.name AS name,
  106. k_rune_craft_type.gem AS gem,
  107. k_rune_craft_type.inmemorial AS inmemorial,
  108. k_rune_craft_type.ancient AS ancient,
  109. k_rune_craft_range.min AS min,
  110. k_rune_craft_range.max AS max
  111. FROM
  112. rune_craft,
  113. k_rune_craft_type,
  114. k_rune_craft_range
  115. WHERE
  116. rune_craft.id = $id AND
  117. rune_craft.type = k_rune_craft_type.id AND
  118. k_rune_craft_type.gem = k_rune_craft_range.gem AND
  119. k_rune_craft_type.gem = k_rune_craft_range.gem AND
  120. k_rune_craft_type.ancient = k_rune_craft_range.ancient AND
  121. rune_craft.quality = k_rune_craft_range.quality AND
  122. rune_craft.stat = k_rune_craft_range.stat;
  123. ";
  124. $q = $db->query($s);
  125. $r = $q->fetchArray(SQLITE3_ASSOC);
  126. if ($r){
  127. $this->id = $r["id"];
  128. $this->gem = $r["gem"];
  129. $this->quality = $r["quality"];
  130. $this->quality_name = $this->quality_name($r["quality"]);
  131. $this->stat = $r["stat"];
  132. $this->stat_name = $this->stat_name($r["stat"]);
  133. $this->ancient = $r["ancient"];
  134. $this->inmemorial = $r["inmemorial"];
  135. if ($this->inmemorial == 0){
  136. $this->rune = new K_Rune_Set($r["rune"]);
  137. $this->name = $this->rune->name . " " . $r["stat"];
  138. }
  139. else{
  140. $this->name = "Inmemorial " . $r["stat"];
  141. }
  142. $this->min = $r["min"];
  143. $this->max = $r["max"];
  144. $this->value = $r["value"];
  145. $this->amount = $r["amount"];
  146. }
  147. }
  148. /**
  149. * Gets a stat name from the maps.
  150. *
  151. * @param int $stat Stat id.
  152. * @return string Stat name (Uppercase)
  153. */
  154. private function stat_name($stat){
  155. switch ($stat){
  156. case RUNE_STAT_ID::HP:
  157. return "HP";
  158. case RUNE_STAT_ID::HP_P:
  159. return "HP%";
  160. case RUNE_STAT_ID::ATK:
  161. return "ATK";
  162. case RUNE_STAT_ID::ATK_P:
  163. return "ATK%";
  164. case RUNE_STAT_ID::DEF:
  165. return "DEF";
  166. case RUNE_STAT_ID::DEF_P:
  167. return "DEF%";
  168. case RUNE_STAT_ID::SPD:
  169. return "SPD";
  170. case RUNE_STAT_ID::CRR:
  171. return "CRR";
  172. case RUNE_STAT_ID::CRD:
  173. return "CRD";
  174. case RUNE_STAT_ID::RES:
  175. return "RES";
  176. case RUNE_STAT_ID::ACC:
  177. return "ACC";
  178. default:
  179. return "";
  180. }
  181. }
  182. /**
  183. * Gets a stat name from the maps.
  184. *
  185. * @param int $q Quality id.
  186. * @return string Quality (Uppercase)
  187. */
  188. private function quality_name($q){
  189. switch ($q){
  190. case QUALITY_ID::NORMAL:
  191. return "NORMAL";
  192. case QUALITY_ID::MAGIC:
  193. return "MAGIC";
  194. case QUALITY_ID::RARE:
  195. return "RARE";
  196. case QUALITY_ID::HERO:
  197. return "HERO";
  198. case QUALITY_ID::LEGEND:
  199. return "LEGEND";
  200. default:
  201. return "";
  202. }
  203. }
  204. }
  205. ?>