Artifact_Effect.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. }
  85. /**
  86. * Retrieves the artifact effect's slot identifier.
  87. *
  88. * @see ARTIFACT_EFFECT_SLOT_ID
  89. * @return int Effect slot ID.
  90. */
  91. public function get_slot(){
  92. return $this->slot;
  93. }
  94. /**
  95. * Artifact effect identifier.
  96. *
  97. * @return int Effect ID.
  98. */
  99. public function get_effect(){
  100. return $this->effect;
  101. }
  102. /**
  103. * Retrieves the artifact effect name.
  104. *
  105. * @return string The effect name.
  106. */
  107. public function get_name(){
  108. return $this->name;
  109. }
  110. /**
  111. * Retrieves the value of the artifact effect, excluding grinds.
  112. *
  113. * @return float Effect value.
  114. */
  115. public function get_value(){
  116. return $this->value;
  117. }
  118. /**
  119. * Retrieves the grinded value on the effect.
  120. *
  121. * @return float Effect grinded value.
  122. */
  123. public function get_grind(){
  124. return $this->grind;
  125. }
  126. /**
  127. * Checks if the effect has been enchanted.
  128. *
  129. * @return bool True if the effect was enchanted, false otherwise
  130. */
  131. public function is_enchanted(){
  132. return filter_var($this->enchant, FILTER_VALIDATE_BOOLEAN);
  133. }
  134. }