Monster_Transformation.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. * @global resource Database connection.
  48. */
  49. public function __construct($id){
  50. global $db;
  51. $statement = $db->prepare("
  52. SELECT
  53. id,
  54. family,
  55. monster
  56. FROM monster_transformation
  57. WHERE id = :id;
  58. ");
  59. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  60. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  61. if ($r){
  62. $this->id = $r["id"];
  63. $this->family = $r["family"];
  64. $this->monster = $r["monster"];
  65. $this->load_skills();
  66. }
  67. }
  68. /**
  69. * Loads the information about the monster skills in the transformed form.
  70. *
  71. * @global resource Database connection.
  72. */
  73. private function load_skills(){
  74. global $db;
  75. $this->skill = [];
  76. $statement = $db->prepare("
  77. SELECT skill
  78. FROM
  79. skill,
  80. monster_skill
  81. WHERE
  82. id = skill AND
  83. monster = :id
  84. ORDER BY slot;
  85. ");
  86. $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
  87. $q = $statement->execute();
  88. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  89. array_push($this->skill, new Skill($r["skill"]));
  90. }
  91. }
  92. /**
  93. * Gets the path to the monster image. The image must be in the
  94. * img/monster/ directory, and it's name must be the monster id,
  95. * padded with '0' to 8 digits, and the extension must be '.png'.
  96. *
  97. * @return string Image URL, or a fixed unknown image.
  98. */
  99. public function get_image(){
  100. return APPLICATION::img("UNIT", $this->id);
  101. }
  102. }
  103. ?>