Monster_Transformation.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. private $id;
  28. /**
  29. * @var int Transformed monster family id.
  30. */
  31. private $family;
  32. /**
  33. * @var int ID of the monster that transformes into this.
  34. */
  35. private $monster;
  36. private $flag_skills = false;
  37. /**
  38. * @var \Skill[] Skills in the transformed form.
  39. */
  40. private $skill = [];
  41. /**
  42. * Constructor.
  43. *
  44. * Searches the database and retrieves the information about the
  45. * trnsformed monster, populating it and it's items.
  46. *
  47. * @param int $id Transformed monster identifier.
  48. */
  49. public function __construct($id){
  50. $statement = get_context()->get_db()->prepare("
  51. SELECT
  52. id,
  53. family,
  54. monster
  55. FROM monster_transformation
  56. WHERE id = :id;
  57. ");
  58. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  59. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  60. if ($r){
  61. $this->id = $r["id"];
  62. $this->family = $r["family"];
  63. $this->monster = $r["monster"];
  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. $this->flag_skills = true;
  87. }
  88. /**
  89. * Retrieves the identifier of the transformed monster.
  90. *
  91. * @return string Trasnformed monster ID.
  92. */
  93. public function get_id(){
  94. return $this->id;
  95. }
  96. /**
  97. * Retrieves the transofmred monster family identifier.
  98. *
  99. * @return number Family ID.
  100. */
  101. public function get_family(){
  102. return $this->family;
  103. }
  104. /**
  105. * Retrieves the identifier of the monster that transforms into this one.
  106. *
  107. * @return number Base monster ID.
  108. */
  109. public function get_base_id(){
  110. return $this->monster;
  111. }
  112. /**
  113. * Retrieves the skills of the transformed monster.
  114. *
  115. * @return Skill[] Array of skills.
  116. */
  117. public function get_skills(){
  118. if (! $this->flag_skills){
  119. $this->load_skills();
  120. }
  121. return $this->skill;
  122. }
  123. /**
  124. * Gets the path to the monster image.
  125. *
  126. * @return string Image URL, or a fixed unknown image.
  127. */
  128. public function get_image(){
  129. return APPLICATION::img("UNIT", $this->id);
  130. }
  131. }
  132. ?>