Rune_Stat.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /**
  3. * Rune stat 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. /**
  14. * Rune_stat.
  15. *
  16. * Represents an object from the table 'rune_stat'.
  17. *
  18. * @category Entity
  19. */
  20. class Rune_Stat extends Entity{
  21. /**
  22. * @var int Stat slot.
  23. *
  24. * @see RUNE_STAT_SLOT_ID
  25. */
  26. private $slot;
  27. /**
  28. * @var int Substat 1 of the rune.
  29. *
  30. * @see RUNE_STAT_ID
  31. */
  32. private $stat;
  33. /**
  34. * @var string Substat 1 name (uppercase).
  35. */
  36. private $stat_name = "";
  37. /**
  38. * @var int Substat 1 value of the rune.
  39. */
  40. private $value;
  41. /**
  42. * @var int Ammount gained by the substat 1 enchant.
  43. */
  44. private $grind;
  45. /**
  46. * @var bool Indicates if a gem has been used.
  47. */
  48. private $enchant;
  49. /**
  50. * Retrieves the slot of the stat.
  51. *
  52. * @see RUNE_STAT_SLOT_ID
  53. *
  54. * @return number Slot number.
  55. */
  56. public function get_slot(){
  57. return $this->slot;
  58. }
  59. /**
  60. * Retrieves the stat identifier.
  61. *
  62. * @see RUNE_STAT_ID
  63. *
  64. * @return number Stat ID.
  65. */
  66. public function get_stat(){
  67. return $this->stat;
  68. }
  69. /**
  70. * Retrieves the stat name.
  71. *
  72. * @return string Stat name.
  73. */
  74. public function get_stat_name(){
  75. return $this->stat_name;
  76. }
  77. /**
  78. * Retrieves the stat value, without grinds.
  79. *
  80. * @return number Stat value.
  81. */
  82. public function get_value(){
  83. return $this->value;
  84. }
  85. /**
  86. * Retrieves the grinded value of the stat.
  87. *
  88. * @return number Grinded value.
  89. */
  90. public function get_grind(){
  91. return $this->grind;
  92. }
  93. /**
  94. * Checks if the stat has been changed by gems.
  95. *
  96. * @return bool True if the stat was enchanted, false otherwise.
  97. */
  98. public function is_enchanted(){
  99. return $this->enchant;
  100. }
  101. /**
  102. * Constructor.
  103. *
  104. * Searches the database and retrieves the information about the
  105. * rune stat, populating it and it's items.
  106. *
  107. * @param int $id Rune id.
  108. */
  109. public function __construct($rune, $slot){
  110. $statement = get_context()->get_db()->prepare("
  111. SELECT
  112. slot,
  113. stat,
  114. value,
  115. enchant,
  116. grind
  117. FROM rune_stat
  118. WHERE
  119. rune = :rune AND
  120. slot = :slot;
  121. ");
  122. $statement->bindValue(':rune', $rune, SQLITE3_TEXT);
  123. $statement->bindValue(':slot', $slot, SQLITE3_TEXT);
  124. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  125. if ($r){
  126. $this->slot = $r["slot"];
  127. $this->stat = $r["stat"];
  128. $this->value = $r["value"];
  129. if ($r["enchant"] == 1){
  130. $this->enchant = true;
  131. }
  132. else{
  133. $this->enchant = false;
  134. }
  135. $this->grind = $r["grind"];
  136. switch ($this->stat){
  137. case RUNE_STAT_ID::HP:
  138. $this->stat_name = "HP";
  139. break;
  140. case RUNE_STAT_ID::HP_P:
  141. $this->stat_name = "HP%";
  142. break;
  143. case RUNE_STAT_ID::ATK:
  144. $this->stat_name = "ATK";
  145. break;
  146. case RUNE_STAT_ID::ATK_P:
  147. $this->stat_name = "ATK%";
  148. break;
  149. case RUNE_STAT_ID::DEF:
  150. $this->stat_name = "DEF";
  151. break;
  152. case RUNE_STAT_ID::DEF_P:
  153. $this->stat_name = "DEF%";
  154. break;
  155. case RUNE_STAT_ID::SPD:
  156. $this->stat_name = "SPD";
  157. break;
  158. case RUNE_STAT_ID::CRR:
  159. $this->stat_name = "CRR";
  160. break;
  161. case RUNE_STAT_ID::CRD:
  162. $this->stat_name = "CRD";
  163. break;
  164. case RUNE_STAT_ID::RES:
  165. $this->stat_name = "RES";
  166. break;
  167. case RUNE_STAT_ID::ACC:
  168. $this->stat_name = "ACC";
  169. break;
  170. }
  171. }
  172. }
  173. }
  174. ?>