Artifact_Stat.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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
  46. artifact = :artifact
  47. ");
  48. $statement->bindValue(':artifact', $artifact_id, SQLITE3_TEXT);
  49. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  50. if ($r){
  51. $this->stat = $r["stat"];
  52. $this->value = $r["value"];
  53. switch ($this->stat){
  54. case ARTIFACT_STAT_ID::HP:
  55. $this->name = "HP";
  56. break;
  57. case ARTIFACT_STAT_ID::ATK:
  58. $this->name = "ATK";
  59. break;
  60. case ARTIFACT_STAT_ID::DEF:
  61. $this->name = "DEF";
  62. break;
  63. }
  64. }
  65. }
  66. /**
  67. * Retrieves the artifact stat identifier.
  68. *
  69. * @see ARTIFACT_STAT_ID
  70. *
  71. * @return int Artifact stat ID.
  72. */
  73. public function get_stat(){
  74. return $this->stat;
  75. }
  76. /**
  77. * Retrieves the artifact stat name.
  78. *
  79. * @return string Artifact stat name.
  80. */
  81. public function get_name(){
  82. return $this->name;
  83. }
  84. /**
  85. * Retrieves the value of the artifact stat value.
  86. *
  87. * @return int Stat value.
  88. */
  89. public function get_value(){
  90. return $this->value;
  91. }
  92. }