Monster_Transformation.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Transformation 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. require_once(PATH::ENTITY . "Skill.php");
  14. require_once(PATH::ENTITY . "Leader_Skill.php");
  15. require_once(PATH::ENTITY . "Source.php");
  16. /**
  17. * Monster transformation.
  18. *
  19. * Represents an object from the table 'monster_transformation'.
  20. *
  21. * @category Entity
  22. */
  23. class Monster_Transformation extends Entity{
  24. /**
  25. * @var int Transformed monster identifier.
  26. */
  27. public $id;
  28. /**
  29. * @var int Transformed monster family id.
  30. */
  31. public $family;
  32. /**
  33. * @var int ID of the monster that transformes into this.
  34. */
  35. public $monster;
  36. /**
  37. * @var \Skill[] Skills in the transformed form.
  38. */
  39. public $skill = [];
  40. /**
  41. * Constructor.
  42. *
  43. * Searches the database and retrieves the information about the
  44. * trnsformed monster, populating it and it's items.
  45. *
  46. * @param int $id Transformed monster identifier.
  47. */
  48. public function __construct($id){
  49. $statement = get_context()->get_db()->prepare("
  50. SELECT
  51. id,
  52. family,
  53. monster
  54. FROM monster_transformation
  55. WHERE id = :id;
  56. ");
  57. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  58. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  59. if ($r){
  60. $this->id = $r["id"];
  61. $this->family = $r["family"];
  62. $this->monster = $r["monster"];
  63. $this->load_skills();
  64. }
  65. }
  66. /**
  67. * Loads the information about the monster skills in the transformed form.
  68. */
  69. private function load_skills(){
  70. $this->skill = [];
  71. $statement = get_context()->get_db()->prepare("
  72. SELECT skill
  73. FROM
  74. skill,
  75. monster_skill
  76. WHERE
  77. id = skill AND
  78. monster = :id
  79. ORDER BY slot;
  80. ");
  81. $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
  82. $q = $statement->execute();
  83. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  84. array_push($this->skill, new Skill($r["skill"]));
  85. }
  86. }
  87. /**
  88. * Gets the path to the monster image. The image must be in the
  89. * img/monster/ directory, and it's name must be the monster id,
  90. * padded with '0' to 8 digits, and the extension must be '.png'.
  91. *
  92. * @return string Image URL, or a fixed unknown image.
  93. */
  94. public function get_image(){
  95. return APPLICATION::img("UNIT", $this->id);
  96. }
  97. }
  98. ?>