Artifact_Effect.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Artifact effect 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. * Artifact effect.
  15. *
  16. * Represents an object from the table 'artifact_effect'.
  17. *
  18. * @category Entity
  19. */
  20. class Artifact_Effect extends Entity{
  21. private $slot;
  22. private $effect;
  23. private $name = "";
  24. private $value;
  25. private $grind;
  26. private $enchant;
  27. /**
  28. * Constructor.
  29. *
  30. * Retrieves the artifact effect information from the database.
  31. *
  32. * @param int $artifact Artifact id.
  33. * @param int $slot Artifact slot id.
  34. */
  35. public function __construct($artifact, $slot){
  36. $statement = get_context()->get_db()->prepare("
  37. SELECT
  38. slot,
  39. effect,
  40. value,
  41. enchant,
  42. grind
  43. FROM artifact_effect
  44. WHERE
  45. artifact = :artifact AND
  46. slot = :slot;
  47. ");
  48. $statement->bindValue(':artifact', $artifact, SQLITE3_TEXT);
  49. $statement->bindValue(':slot', $slot, SQLITE3_TEXT);
  50. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  51. if ($r){
  52. $this->effect = $r["effect"];
  53. $this->value = $r["value"];
  54. $this->enchant = $r["enchant"];
  55. $this->grind = $r["grind"];
  56. $statement = get_context()->get_db()->prepare("
  57. SELECT name
  58. FROM effect_artifact
  59. WHERE id = :id;
  60. ");
  61. $statement->bindValue(':id', $this->effect, SQLITE3_TEXT);
  62. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  63. if ($r){
  64. $this->name = str_replace("{}", $this->value, $r["name"]);
  65. }
  66. }
  67. }
  68. /**
  69. * Retrieves the artifact effect's slot identifier.
  70. *
  71. * @see ARTIFACT_EFFECT_SLOT_ID
  72. *
  73. * @return int Effect slot ID.
  74. */
  75. public function get_slot(){
  76. return $this->slot;
  77. }
  78. /**
  79. * Artifact effect identifier.
  80. *
  81. * @return int Effect ID.
  82. */
  83. public function get_effect(){
  84. return $this->effect;
  85. }
  86. /**
  87. * Retrieves the artifact effect name.
  88. *
  89. * @return string The effect name.
  90. */
  91. public function get_name(){
  92. return $this->name;
  93. }
  94. /**
  95. * Retrieves the value of the artifact effect, excluding grinds.
  96. *
  97. * @return number Effect value.
  98. */
  99. public function get_value(){
  100. return $this->value;
  101. }
  102. /**
  103. * Retrieves the grinded value on the effect.
  104. *
  105. * @return number Effect grinded value.
  106. */
  107. public function get_grind(){
  108. return $this->grind;
  109. }
  110. /**
  111. * Checks if the effect has been enchanted.
  112. *
  113. * @return boolean True if the effect was enchanted, false otherwise
  114. */
  115. public function is_enchanted(){
  116. return filter_var($this->enchant, FILTER_VALIDATE_BOOLEAN);
  117. }
  118. }
  119. ?>