Rune_Craft.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. * Constructor.
  84. *
  85. * Searches the database and retrieves the information about the
  86. * rune, populating it and it's items.
  87. *
  88. * @param int $id Rune id.
  89. * @global resource Database connection.
  90. */
  91. public function __construct($id){
  92. global $db;
  93. $s =
  94. "SELECT " .
  95. " rune_craft.id AS id, " .
  96. " rune_craft.quality As quality, " .
  97. " rune_craft.rune AS rune, " .
  98. " rune_craft.stat AS stat, " .
  99. " rune_craft.value AS value, " .
  100. " k_rune_craft_type.name AS name, " .
  101. " k_rune_craft_type.gem AS gem, " .
  102. " k_rune_craft_type.inmemorial AS inmemorial, " .
  103. " k_rune_craft_type.ancient AS ancient, " .
  104. " k_rune_craft_range.min AS min, " .
  105. " k_rune_craft_range.max AS max " .
  106. "FROM " .
  107. " rune_craft, ".
  108. " k_rune_craft_type, " .
  109. " k_rune_craft_range " .
  110. "WHERE " .
  111. " rune_craft.id = $id AND " .
  112. " rune_craft.type = k_rune_craft_type.id AND " .
  113. " k_rune_craft_type.gem = k_rune_craft_range.gem AND " .
  114. " k_rune_craft_type.gem = k_rune_craft_range.gem AND " .
  115. " k_rune_craft_type.ancient = k_rune_craft_range.ancient AND " .
  116. " rune_craft.quality = k_rune_craft_range.quality AND " .
  117. " rune_craft.stat = k_rune_craft_range.stat;";
  118. $q = $db->query($s);
  119. $r = $q->fetchArray(SQLITE3_ASSOC);
  120. if ($r){
  121. $this->id = $r["id"];
  122. $this->gem = $r["gem"];
  123. $this->quality = $r["quality"];
  124. $this->quality_name = $this->quality_name($r["quality"]);
  125. $this->stat = $r["stat"];
  126. $this->stat_name = $this->stat_name($r["stat"]);
  127. $this->ancient = $r["ancient"];
  128. $this->inmemorial = $r["inmemorial"];
  129. if ($this->inmemorial == 0){
  130. $this->rune = new K_Rune_Set($r["rune"]);
  131. $this->name = $this->rune->name . " " . $r["stat"];
  132. }
  133. else{
  134. $this->name = "Inmemorial " . $r["stat"];
  135. }
  136. $this->min = $r["min"];
  137. $this->max = $r["max"];
  138. $this->value = $r["value"];
  139. }
  140. }
  141. /**
  142. * Gets a stat name from the maps.
  143. *
  144. * @param int $stat Stat id.
  145. * @return string Stat name (Uppercase)
  146. */
  147. private function stat_name($stat){
  148. switch ($stat){
  149. case RUNE_STAT_ID::HP:
  150. return "HP";
  151. case RUNE_STAT_ID::HP_P:
  152. return "HP%";
  153. case RUNE_STAT_ID::ATK:
  154. return "ATK";
  155. case RUNE_STAT_ID::ATK_P:
  156. return "ATK%";
  157. case RUNE_STAT_ID::DEF:
  158. return "DEF";
  159. case RUNE_STAT_ID::DEF_P:
  160. return "DEF%";
  161. case RUNE_STAT_ID::SPD:
  162. return "SPD";
  163. case RUNE_STAT_ID::CRR:
  164. return "CRR";
  165. case RUNE_STAT_ID::CRD:
  166. return "CRD";
  167. case RUNE_STAT_ID::RES:
  168. return "RES";
  169. case RUNE_STAT_ID::ACC:
  170. return "ACC";
  171. default:
  172. return "";
  173. }
  174. }
  175. /**
  176. * Gets a stat name from the maps.
  177. *
  178. * @param int $q Quality id.
  179. * @return string Quality (Uppercase)
  180. */
  181. private function quality_name($q){
  182. switch ($q){
  183. case QUALITY_ID::NORMAL:
  184. return "NORMAL";
  185. case QUALITY_ID::MAGIC:
  186. return "MAGIC";
  187. case QUALITY_ID::RARE:
  188. return "RARE";
  189. case QUALITY_ID::HERO:
  190. return "HERO";
  191. case QUALITY_ID::LEGEND:
  192. return "LEGEND";
  193. default:
  194. return "";
  195. }
  196. }
  197. }
  198. ?>