Rune_Stat.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. }
  118. /**
  119. * Retrieves the slot of the stat.
  120. *
  121. * @see RUNE_STAT_SLOT_ID
  122. * @return int Slot number.
  123. */
  124. public function get_slot(){
  125. return $this->slot;
  126. }
  127. /**
  128. * Retrieves the stat identifier.
  129. *
  130. * @see RUNE_STAT_ID
  131. * @return int Stat ID.
  132. */
  133. public function get_stat(){
  134. return $this->stat;
  135. }
  136. /**
  137. * Retrieves the stat name.
  138. *
  139. * @return string Stat name.
  140. */
  141. public function get_stat_name(){
  142. return $this->stat_name;
  143. }
  144. /**
  145. * Retrieves the stat value, without grinds.
  146. *
  147. * @return int Stat value.
  148. */
  149. public function get_value(){
  150. return $this->value;
  151. }
  152. /**
  153. * Retrieves the grinded value of the stat.
  154. *
  155. * @return int Grinded value.
  156. */
  157. public function get_grind(){
  158. return $this->grind;
  159. }
  160. /**
  161. * Checks if the stat has been changed by gems.
  162. *
  163. * @return bool True if the stat was enchanted, false otherwise.
  164. */
  165. public function is_enchanted(){
  166. return $this->enchant;
  167. }
  168. }
  169. ?>