Artifact_Effect.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * Artifact effect 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. * Artifact effect.
  14. *
  15. * Represents each of the up to 4 artifact effects (not the main stat).
  16. *
  17. * @category Entity
  18. */
  19. class Artifact_Effect extends Entity{
  20. /**
  21. * @var int The effect slot ({@see ARTIFACT_EFFECT_SLOT_ID}).
  22. */
  23. private $slot;
  24. /**
  25. * @var int The effect ID.
  26. */
  27. private $effect;
  28. /**
  29. * @var string The effect name.
  30. */
  31. private $name;
  32. /**
  33. * @var float The value of the effect.
  34. */
  35. private $value;
  36. /**
  37. * @var float The grinded value of the effect.
  38. */
  39. private $grind;
  40. /**
  41. * @var bool Indicates if the effect has been enchanted.
  42. */
  43. private $enchant;
  44. /**
  45. * Constructor.
  46. *
  47. * Retrieves the artifact effect information from the database.
  48. *
  49. * @param int $artifact Artifact id.
  50. * @param int $slot Artifact effect slot id.
  51. */
  52. public function __construct($artifact, $slot){
  53. $statement = get_context()->get_db()->prepare("
  54. SELECT
  55. slot,
  56. effect,
  57. value,
  58. enchant,
  59. grind
  60. FROM artifact_effect
  61. WHERE
  62. artifact = :artifact AND
  63. slot = :slot;
  64. ");
  65. $statement->bindValue(':artifact', $artifact, SQLITE3_TEXT);
  66. $statement->bindValue(':slot', $slot, SQLITE3_TEXT);
  67. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  68. if ($r){
  69. $this->effect = $r["effect"];
  70. $this->value = $r["value"];
  71. $this->enchant = $r["enchant"];
  72. $this->grind = $r["grind"];
  73. $statement = get_context()->get_db()->prepare("
  74. SELECT name
  75. FROM effect_artifact
  76. WHERE id = :id;
  77. ");
  78. $statement->bindValue(':id', $this->effect, SQLITE3_TEXT);
  79. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  80. if ($r){
  81. $this->name = str_replace("{}", $this->value, $r["name"]);
  82. }
  83. }
  84. else{
  85. // Not found. Maybe as a run drop?
  86. $select = "effect_1 AS effect, effect_1_value AS value";
  87. switch ($slot){
  88. case ARTIFACT_EFFECT_SLOT_ID::EFFECT_1:
  89. $select = "effect_1 AS effect, effect_1_value AS value";
  90. break;
  91. case ARTIFACT_EFFECT_SLOT_ID::EFFECT_2:
  92. $select = "effect_2 AS effect, effect_2_value AS value";
  93. break;
  94. case ARTIFACT_EFFECT_SLOT_ID::EFFECT_3:
  95. $select = "effect_3 AS effect, effect_3_value AS value";
  96. break;
  97. case ARTIFACT_EFFECT_SLOT_ID::EFFECT_4:
  98. $select = "effect_4 AS effect, effect_4_value AS value";
  99. break;
  100. }
  101. $statement = get_context()->get_db()->prepare("
  102. SELECT $select
  103. FROM run_drop_artifact
  104. WHERE id = :id
  105. ");
  106. $statement->bindValue(':id', $artifact, SQLITE3_TEXT);
  107. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  108. if ($r){
  109. $this->slot = $slot;
  110. $this->effect = $r["effect"];
  111. $this->value = $r["value"];
  112. $this->enchant = false;
  113. $this->grind = 0;
  114. $statement = get_context()->get_db()->prepare("
  115. SELECT name
  116. FROM effect_artifact
  117. WHERE id = :id;
  118. ");
  119. $statement->bindValue(':id', $this->effect, SQLITE3_TEXT);
  120. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  121. if ($r){
  122. $this->name = str_replace("{}", $this->value, $r["name"]);
  123. }
  124. }
  125. }
  126. }
  127. /**
  128. * Retrieves the artifact effect's slot identifier.
  129. *
  130. * @see ARTIFACT_EFFECT_SLOT_ID
  131. * @return int Effect slot ID.
  132. */
  133. public function get_slot(){
  134. return $this->slot;
  135. }
  136. /**
  137. * Artifact effect identifier.
  138. *
  139. * @return int Effect ID.
  140. */
  141. public function get_effect(){
  142. return $this->effect;
  143. }
  144. /**
  145. * Retrieves the artifact effect name.
  146. *
  147. * @return string The effect name.
  148. */
  149. public function get_name(){
  150. return $this->name;
  151. }
  152. /**
  153. * Retrieves the value of the artifact effect, excluding grinds.
  154. *
  155. * @return float Effect value.
  156. */
  157. public function get_value(){
  158. return $this->value;
  159. }
  160. /**
  161. * Retrieves the grinded value on the effect.
  162. *
  163. * @return float Effect grinded value.
  164. */
  165. public function get_grind(){
  166. return $this->grind;
  167. }
  168. /**
  169. * Checks if the effect has been enchanted.
  170. *
  171. * @return bool True if the effect was enchanted, false otherwise
  172. */
  173. public function is_enchanted(){
  174. return filter_var($this->enchant, FILTER_VALIDATE_BOOLEAN);
  175. }
  176. }