Monster.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "Monster_Base.php");
  4. require_once($path["entity"] . "Monster_Skill.php");
  5. /**
  6. * Monster.
  7. *
  8. * Represents an object from the table 'monster'.
  9. */
  10. class Monster extends Entity{
  11. /**
  12. * Skill identifier.
  13. */
  14. public $id;
  15. /**
  16. * Monster name.
  17. */
  18. public $name;
  19. /**
  20. * Monster name (awakened).
  21. */
  22. public $name_aw;
  23. /**
  24. * Monster element.
  25. */
  26. public $element;
  27. /**
  28. * Default star level.
  29. */
  30. public $stars;
  31. /**
  32. * Base monster. {@see Monster_Base}
  33. */
  34. public $base;
  35. /**
  36. * Monster image.
  37. */
  38. public $image;
  39. /**
  40. * Monster image (awakened).
  41. */
  42. public $image_aw;
  43. /**
  44. * All {@see Monster_Skill}
  45. */
  46. public $skill = [];
  47. /*
  48. * Indicates if the monster can be awakened.
  49. */
  50. public $awakeable;
  51. /**
  52. * Constructor.
  53. *
  54. * Searches the database and retrieves the information about the
  55. * monster, populating it and it's items.
  56. *
  57. * @param SQLite3 $db Connection to the database.
  58. * @param int $id Monster identifier.
  59. */
  60. public function __construct($db, $id){
  61. global $path;
  62. parent::__construct($db);
  63. $s =
  64. "SELECT " .
  65. " id, " .
  66. " name, " .
  67. " name_aw, " .
  68. " element, " .
  69. " stars, " .
  70. " base, " .
  71. " img, " .
  72. " img_aw, " .
  73. " awakeable " .
  74. "FROM monster " .
  75. "WHERE id = $id; ";
  76. $q = $this->db->query($s);
  77. $r = $q->fetchArray(SQLITE3_ASSOC);
  78. if ($r){
  79. $this->id = $r["id"];
  80. $this->name = $r["name"];
  81. $this->name_aw = $r["name_aw"];
  82. $this->element = $r["element"];
  83. $this->stars = $r["stars"];
  84. $this->awakeable = $r["awakeable"];
  85. $this->base = new Monster_Base($this->db, $r["base"]);
  86. $this->image = $path["img"]["monster"] . $r["img"];
  87. $this->image_aw = $path["img"]["monster"] . $r["img_aw"];
  88. }
  89. $s =
  90. "SELECT " .
  91. " id " .
  92. "FROM monster_skill " .
  93. "WHERE " .
  94. " monster = $id AND" .
  95. " upgrade IS NULL " .
  96. "ORDER BY idx; ";
  97. error_log($s);
  98. $q = $this->db->query($s);
  99. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  100. array_push($this->skill, new Monster_Skill($this->db, $r["id"]));
  101. }
  102. }
  103. }
  104. ?>