Skill.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * Skill 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_Level.php");
  14. require_once(PATH::ENTITY . "Effect.php");
  15. /**
  16. * Monster skill.
  17. *
  18. * Represents an object from the table 'skill'.
  19. *
  20. * @category Entity
  21. */
  22. class Skill extends Entity{
  23. /**
  24. * @var int Skill identifier.
  25. */
  26. public $id;
  27. /**
  28. * @var string Skill name.
  29. */
  30. public $name;
  31. /**
  32. * @var string Skill description.
  33. */
  34. public $description;
  35. /**
  36. * @var int Skill order.
  37. */
  38. public $slot;
  39. /**
  40. * @var int Skill cooldown turns.
  41. */
  42. public $cooltime;
  43. /**
  44. * @var int Number of hits.
  45. */
  46. public $hits;
  47. /**
  48. * @var bool Wether the skill is passive or not.
  49. */
  50. public $passive;
  51. /**
  52. * @var bool Wether the skill is AOE.
  53. */
  54. public $aoe;
  55. /**
  56. * @var int Skill max level.
  57. */
  58. public $max_level;
  59. /**
  60. * @var string Skill formula.
  61. */
  62. public $multiplier_formula;
  63. /**
  64. * @var SKill The skill upgrading this one.
  65. */
  66. public $upgrade;
  67. /**
  68. * @var \Skill_Level[] Available skill levels.
  69. */
  70. public $level = [];
  71. /**
  72. * @var \Effect[] Associated eeffects.
  73. */
  74. public $effect = [];
  75. /**
  76. * Constructor.
  77. *
  78. * Searches the database and retrieves the information about the
  79. * skill, populating it and it's items.
  80. *
  81. * @param int $id Skill identifier.
  82. */
  83. public function __construct($id){
  84. $statement = get_context()->get_db()->prepare("
  85. SELECT
  86. id,
  87. name,
  88. description,
  89. slot,
  90. cooltime,
  91. hits,
  92. passive,
  93. aoe,
  94. max_level,
  95. multiplier_formula
  96. FROM skill
  97. WHERE id = :id;
  98. ");
  99. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  100. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  101. if ($r){
  102. $this->id = $r["id"];
  103. $this->name = HTML::e($r["name"]);
  104. $this->description = HTML::e($r["description"]);
  105. $this->slot = $r["slot"];
  106. $this->cooltime = $r["cooltime"];
  107. $this->hits = $r["hits"];
  108. $this->passive = $r["passive"];
  109. $this->aoe = $r["aoe"];
  110. $this->max_level = $r["max_level"];
  111. $this->multiplier_formula = HTML::e($r["multiplier_formula"]);
  112. $statement = get_context()->get_db()->prepare("
  113. SELECT
  114. skill,
  115. level
  116. FROM skill_level
  117. WHERE skill = :skill
  118. ORDER BY level;
  119. ");
  120. $statement->bindValue(':skill', $this->id, SQLITE3_TEXT);
  121. $q = $statement->execute();
  122. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  123. array_push($this->level, new Skill_Level($r["skill"], $r["level"]));
  124. }
  125. $statement = get_context()->get_db()->prepare("
  126. SELECT DISTINCT effect
  127. FROM skill_effect
  128. WHERE skill = :skill;
  129. ");
  130. $statement->bindValue(':skill', $this->id, SQLITE3_TEXT);
  131. $q = $statement->execute();
  132. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  133. array_push($this->effect, new Effect($r["effect"]));
  134. }
  135. }
  136. }
  137. /**
  138. * Gets the path to the skill image. The image must be in the
  139. * img/skill/ directory, and its name must be the set id,
  140. * padded with '0' to 8 digits, and the extension must be '.png'.
  141. *
  142. * @return string Image URL, or a fixed unknown image.
  143. */
  144. public function get_image(){
  145. return APPLICATION::img("SKILL", $this->id);
  146. }
  147. }
  148. ?>