Artifact_Stat.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Artifact 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. * Artifact stat.
  14. *
  15. * Represents the artifact main stat.
  16. *
  17. * @category Entity
  18. */
  19. class Artifact_Stat extends Entity{
  20. /**
  21. * @var int Artifact stat ID ({@see ARTIFACT_STAT_ID}).
  22. */
  23. private $stat;
  24. /**
  25. * @var string Artifact stat name.
  26. */
  27. private $name;
  28. /**
  29. * @var int The value of the artifact stat.
  30. */
  31. private $value;
  32. /**
  33. * Constructor.
  34. *
  35. * Retrieves the artifact stat information from the database.
  36. *
  37. * @param int $artifact_id Artifact id.
  38. */
  39. public function __construct($artifact_id){
  40. $statement = get_context()->get_db()->prepare("
  41. SELECT
  42. stat,
  43. value
  44. FROM artifact_stat
  45. WHERE artifact = :artifact
  46. ");
  47. $statement->bindValue(':artifact', $artifact_id, SQLITE3_TEXT);
  48. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  49. if ($r){
  50. $this->stat = $r["stat"];
  51. $this->value = $r["value"];
  52. switch ($this->stat){
  53. case ARTIFACT_STAT_ID::HP:
  54. $this->name = "HP";
  55. break;
  56. case ARTIFACT_STAT_ID::ATK:
  57. $this->name = "ATK";
  58. break;
  59. case ARTIFACT_STAT_ID::DEF:
  60. $this->name = "DEF";
  61. break;
  62. }
  63. }
  64. else{
  65. // Not found, maybe as a run drop?
  66. $statement = get_context()->get_db()->prepare("
  67. SELECT
  68. stat,
  69. stat_value
  70. FROM run_drop_artifact
  71. WHERE id = :artifact
  72. ");
  73. $statement->bindValue(':artifact', $artifact_id, SQLITE3_TEXT);
  74. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  75. if ($r){
  76. $this->stat = $r["stat"];
  77. $this->value = $r["stat_value"];
  78. switch ($this->stat){
  79. case ARTIFACT_STAT_ID::HP:
  80. $this->name = "HP";
  81. break;
  82. case ARTIFACT_STAT_ID::ATK:
  83. $this->name = "ATK";
  84. break;
  85. case ARTIFACT_STAT_ID::DEF:
  86. $this->name = "DEF";
  87. break;
  88. }
  89. }
  90. }
  91. }
  92. /**
  93. * Retrieves the artifact stat identifier.
  94. *
  95. * @see ARTIFACT_STAT_ID
  96. *
  97. * @return int Artifact stat ID.
  98. */
  99. public function get_stat(){
  100. return $this->stat;
  101. }
  102. /**
  103. * Retrieves the artifact stat name.
  104. *
  105. * @return string Artifact stat name.
  106. */
  107. public function get_name(){
  108. return $this->name;
  109. }
  110. /**
  111. * Retrieves the value of the artifact stat value.
  112. *
  113. * @return int Stat value.
  114. */
  115. public function get_value(){
  116. return $this->value;
  117. }
  118. }