Rune_Stat.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. /**
  3. * Rune stat entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. require_once(PATH::ENTITY . "Entity.php");
  12. /**
  13. * Rune_stat.
  14. *
  15. * Represents any of the stats of a rune.
  16. *
  17. * @category Entity
  18. */
  19. class Rune_Stat extends Entity{
  20. /**
  21. * @var int Stat slot.
  22. * @see RUNE_STAT_SLOT_ID
  23. */
  24. private $slot;
  25. /**
  26. * @var int Substat type.
  27. * @see RUNE_STAT_ID
  28. */
  29. private $stat;
  30. /**
  31. * @var string Substat name (uppercase).
  32. */
  33. private $stat_name = "";
  34. /**
  35. * @var int Substat value.
  36. */
  37. private $value;
  38. /**
  39. * @var int Grinded value of the stat.
  40. */
  41. private $grind;
  42. /**
  43. * @var bool Indicates if a gem has been used.
  44. */
  45. private $enchant;
  46. /**
  47. * Constructor.
  48. *
  49. * Searches the database and retrieves the information about the
  50. * rune stat, populating it and it's items.
  51. *
  52. * @param int $id Rune id.
  53. */
  54. public function __construct($rune, $slot){
  55. $statement = get_context()->get_db()->prepare("
  56. SELECT
  57. slot,
  58. stat,
  59. value,
  60. enchant,
  61. grind
  62. FROM rune_stat
  63. WHERE
  64. rune = :rune AND
  65. slot = :slot;
  66. ");
  67. $statement->bindValue(':rune', $rune, SQLITE3_TEXT);
  68. $statement->bindValue(':slot', $slot, SQLITE3_TEXT);
  69. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  70. if ($r){
  71. $this->slot = $r["slot"];
  72. $this->stat = $r["stat"];
  73. $this->value = $r["value"];
  74. if ($r["enchant"] == 1){
  75. $this->enchant = true;
  76. }
  77. else{
  78. $this->enchant = false;
  79. }
  80. $this->grind = $r["grind"];
  81. switch ($this->stat){
  82. case RUNE_STAT_ID::HP:
  83. $this->stat_name = "HP";
  84. break;
  85. case RUNE_STAT_ID::HP_P:
  86. $this->stat_name = "HP%";
  87. break;
  88. case RUNE_STAT_ID::ATK:
  89. $this->stat_name = "ATK";
  90. break;
  91. case RUNE_STAT_ID::ATK_P:
  92. $this->stat_name = "ATK%";
  93. break;
  94. case RUNE_STAT_ID::DEF:
  95. $this->stat_name = "DEF";
  96. break;
  97. case RUNE_STAT_ID::DEF_P:
  98. $this->stat_name = "DEF%";
  99. break;
  100. case RUNE_STAT_ID::SPD:
  101. $this->stat_name = "SPD";
  102. break;
  103. case RUNE_STAT_ID::CRR:
  104. $this->stat_name = "CRR";
  105. break;
  106. case RUNE_STAT_ID::CRD:
  107. $this->stat_name = "CRD";
  108. break;
  109. case RUNE_STAT_ID::RES:
  110. $this->stat_name = "RES";
  111. break;
  112. case RUNE_STAT_ID::ACC:
  113. $this->stat_name = "ACC";
  114. break;
  115. }
  116. }
  117. else{
  118. // Not found, maybe in run_drop_rune?
  119. $select = "main_stat AS stat, main_stat_value AS value";
  120. switch ($slot){
  121. case RUNE_STAT_SLOT_ID::MAIN:
  122. $select = "main_stat AS stat, main_stat_value AS value";
  123. break;
  124. case RUNE_STAT_SLOT_ID::INNATE:
  125. $select = "innate_stat AS stat, innate_stat_value AS value";
  126. break;
  127. case RUNE_STAT_SLOT_ID::SUBSTAT_1:
  128. $select = "substat_1 AS stat, substat_1_value AS value";
  129. break;
  130. case RUNE_STAT_SLOT_ID::SUBSTAT_2:
  131. $select = "substat_2 AS stat, substat_2_value AS value";
  132. break;
  133. case RUNE_STAT_SLOT_ID::SUBSTAT_3:
  134. $select = "substat_3 AS stat, substat_3_value AS value";
  135. break;
  136. case RUNE_STAT_SLOT_ID::SUBSTAT_4:
  137. $select = "substat_4 AS stat, substat_4_value AS value";
  138. break;
  139. }
  140. $statement = get_context()->get_db()->prepare("
  141. SELECT $select
  142. FROM run_drop_rune
  143. WHERE id = :rune;
  144. ");
  145. $statement->bindValue(':rune', $rune, SQLITE3_TEXT);
  146. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  147. if ($r){
  148. $this->slot = $slot;
  149. $this->stat = $r["stat"];
  150. $this->value = $r["value"];
  151. $this->enchant = false;
  152. $this->grind = 0;
  153. switch ($this->stat){
  154. case RUNE_STAT_ID::HP:
  155. $this->stat_name = "HP";
  156. break;
  157. case RUNE_STAT_ID::HP_P:
  158. $this->stat_name = "HP%";
  159. break;
  160. case RUNE_STAT_ID::ATK:
  161. $this->stat_name = "ATK";
  162. break;
  163. case RUNE_STAT_ID::ATK_P:
  164. $this->stat_name = "ATK%";
  165. break;
  166. case RUNE_STAT_ID::DEF:
  167. $this->stat_name = "DEF";
  168. break;
  169. case RUNE_STAT_ID::DEF_P:
  170. $this->stat_name = "DEF%";
  171. break;
  172. case RUNE_STAT_ID::SPD:
  173. $this->stat_name = "SPD";
  174. break;
  175. case RUNE_STAT_ID::CRR:
  176. $this->stat_name = "CRR";
  177. break;
  178. case RUNE_STAT_ID::CRD:
  179. $this->stat_name = "CRD";
  180. break;
  181. case RUNE_STAT_ID::RES:
  182. $this->stat_name = "RES";
  183. break;
  184. case RUNE_STAT_ID::ACC:
  185. $this->stat_name = "ACC";
  186. break;
  187. }
  188. }
  189. }
  190. }
  191. /**
  192. * Retrieves the slot of the stat.
  193. *
  194. * @see RUNE_STAT_SLOT_ID
  195. * @return int Slot number.
  196. */
  197. public function get_slot(){
  198. return $this->slot;
  199. }
  200. /**
  201. * Retrieves the stat identifier.
  202. *
  203. * @see RUNE_STAT_ID
  204. * @return int Stat ID.
  205. */
  206. public function get_stat(){
  207. return $this->stat;
  208. }
  209. /**
  210. * Retrieves the stat name.
  211. *
  212. * @return string Stat name.
  213. */
  214. public function get_stat_name(){
  215. return $this->stat_name;
  216. }
  217. /**
  218. * Retrieves the stat value, without grinds.
  219. *
  220. * @return int Stat value.
  221. */
  222. public function get_value(){
  223. return $this->value;
  224. }
  225. /**
  226. * Retrieves the grinded value of the stat.
  227. *
  228. * @return int Grinded value.
  229. */
  230. public function get_grind(){
  231. return $this->grind;
  232. }
  233. /**
  234. * Checks if the stat has been changed by gems.
  235. *
  236. * @return bool True if the stat was enchanted, false otherwise.
  237. */
  238. public function is_enchanted(){
  239. return $this->enchant;
  240. }
  241. }
  242. ?>