Rune_Craft.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "K_Rune_Set.php");
  4. /**
  5. * Owned rune craft item.
  6. *
  7. * Represents an object from the table 'rune_craft'.
  8. */
  9. class Rune_Craft extends Entity{
  10. /**
  11. * Owner identifier.
  12. */
  13. public $uid;
  14. /**
  15. * Item identifier.
  16. */
  17. public $id;
  18. /**
  19. * Item quality.
  20. */
  21. public $quality;
  22. /**
  23. * Item quality name.
  24. */
  25. public $quality_name;
  26. /**
  27. * {@see K_Rune_Set} the item modifies.
  28. */
  29. public $rune;
  30. /**
  31. * Stat the item modifies.
  32. */
  33. public $stat;
  34. /**
  35. * Stat name.
  36. */
  37. public $stat_name;
  38. /**
  39. * Indicates if the Item is a gem.
  40. */
  41. public $gem;
  42. /**
  43. * Indicates if the Item is ancient.
  44. */
  45. public $ancient;
  46. /**
  47. * Indicates if the Item is inmemorial.
  48. */
  49. public $inmemorial;
  50. /**
  51. * Item name.
  52. */
  53. public $name;
  54. /**
  55. * Minimum value of the stat.
  56. */
  57. public $min;
  58. /**
  59. * Maximum value of the stat.
  60. */
  61. public $max;
  62. /**
  63. * Sell value.
  64. */
  65. public $value;
  66. /**
  67. * Constructor.
  68. *
  69. * Searches the database and retrieves the information about the
  70. * rune, populating it and it's items.
  71. *
  72. * @param SQLite3 $db Connection to the database.
  73. * @param int $id Rune id.
  74. */
  75. public function __construct($db, $id){
  76. global $path;
  77. parent::__construct($db);
  78. $s =
  79. "SELECT " .
  80. " rune_craft.id AS id, " .
  81. " rune_craft.quality As quality, " .
  82. " rune_craft.rune AS rune, " .
  83. " rune_craft.stat AS stat, " .
  84. " rune_craft.value AS value, " .
  85. " k_rune_craft_type.name AS name, " .
  86. " k_rune_craft_type.gem AS gem, " .
  87. " k_rune_craft_type.inmemorial AS inmemorial, " .
  88. " k_rune_craft_type.ancient AS ancient, " .
  89. " k_rune_craft_range.min AS min, " .
  90. " k_rune_craft_range.max AS max " .
  91. "FROM " .
  92. " rune_craft, ".
  93. " k_rune_craft_type, " .
  94. " k_rune_craft_range " .
  95. "WHERE " .
  96. " rune_craft.id = $id AND " .
  97. " rune_craft.type = k_rune_craft_type.id AND " .
  98. " k_rune_craft_type.gem = k_rune_craft_range.gem AND " .
  99. " k_rune_craft_type.gem = k_rune_craft_range.gem AND " .
  100. " k_rune_craft_type.ancient = k_rune_craft_range.ancient AND " .
  101. " rune_craft.quality = k_rune_craft_range.quality AND " .
  102. " rune_craft.stat = k_rune_craft_range.stat;";
  103. $q = $this->db->query($s);
  104. $r = $q->fetchArray(SQLITE3_ASSOC);
  105. if ($r){
  106. $this->id = $r["id"];
  107. $this->gem = $r["gem"];
  108. $this->quality = $r["quality"];
  109. $this->quality_name = $this->quality_name($r["quality"]);
  110. $this->stat = $r["stat"];
  111. $this->stat_name = $this->stat_name($r["stat"]);
  112. $this->ancient = $r["ancient"];
  113. $this->inmemorial = $r["inmemorial"];
  114. if ($this->inmemorial == 0){
  115. $this->rune = new K_Rune_Set($this->db, $r["rune"]);
  116. $this->name = $this->rune->name . " " . $r["stat"];
  117. }
  118. else{
  119. $this->name = "Inmemorial " . $r["stat"];
  120. }
  121. $this->min = $r["min"];
  122. $this->max = $r["max"];
  123. $this->value = $r["value"];
  124. }
  125. }
  126. /**
  127. * Gets a stat name from the maps.
  128. *
  129. * @param int $stat Stat id.
  130. * @return string Stat name (Uppercase)
  131. */
  132. private function stat_name($stat){
  133. global $RUNE_STAT;
  134. switch ($stat){
  135. case $RUNE_STAT["HP"]:
  136. return "HP";
  137. case $RUNE_STAT["HP%"]:
  138. return "HP%";
  139. case $RUNE_STAT["ATK"]:
  140. return "ATK";
  141. case $RUNE_STAT["ATK%"]:
  142. return "ATK%";
  143. case $RUNE_STAT["DEF"]:
  144. return "DEF";
  145. case $RUNE_STAT["DEF%"]:
  146. return "DEF%";
  147. case $RUNE_STAT["SPD"]:
  148. return "SPD";
  149. case $RUNE_STAT["CRR"]:
  150. return "CRR";
  151. case $RUNE_STAT["CRD"]:
  152. return "CRD";
  153. case $RUNE_STAT["RES"]:
  154. return "RES";
  155. case $RUNE_STAT["ACC"]:
  156. return "ACC";
  157. default:
  158. return "";
  159. }
  160. }
  161. /**
  162. * Gets a stat name from the maps.
  163. *
  164. * @param int $q Quality id.
  165. * @return string Quality (Uppercase)
  166. */
  167. private function quality_name($q){
  168. global $QUALITY;
  169. switch ($q){
  170. case $QUALITY["NORMAL"]:
  171. return "NORMAL";
  172. case $QUALITY["MAGIC"]:
  173. return "MAGIC";
  174. case $QUALITY["RARE"]:
  175. return "RARE";
  176. case $QUALITY["HERO"]:
  177. return "HERO";
  178. case $QUALITY["LEGEND"]:
  179. return "LEGEND";
  180. default:
  181. return "";
  182. }
  183. }
  184. }
  185. ?>