K_Skill.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 . "K_Skill_Level.php");
  14. require_once(PATH::ENTITY . "K_Effect.php");
  15. /**
  16. * Monster skill.
  17. *
  18. * Represents an object from the table 'k_skill'.
  19. *
  20. * @category Entity
  21. */
  22. class K_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 K_SKill The skill upgrading this one.
  65. */
  66. public $upgrade;
  67. /**
  68. * @var \K_Skill_Level[] Available skill levels.
  69. */
  70. public $level = [];
  71. /**
  72. * @var \K_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. * @global resource Database connection.
  83. */
  84. public function __construct($id){
  85. global $db;
  86. $statement = $db->prepare("
  87. SELECT
  88. id,
  89. name,
  90. description,
  91. slot,
  92. cooltime,
  93. hits,
  94. passive,
  95. aoe,
  96. max_level,
  97. multiplier_formula
  98. FROM k_skill
  99. WHERE id = :id;
  100. ");
  101. $statement->bindValue(':id', $id, SQLITE3_INTEGER);
  102. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  103. if ($r){
  104. $this->id = $r["id"];
  105. $this->name = HTML::e($r["name"]);
  106. $this->description = HTML::e($r["description"]);
  107. $this->slot = $r["slot"];
  108. $this->cooltime = $r["cooltime"];
  109. $this->hits = $r["hits"];
  110. $this->passive = $r["passive"];
  111. $this->aoe = $r["aoe"];
  112. $this->max_level = $r["max_level"];
  113. $this->multiplier_formula = HTML::e($r["multiplier_formula"]);
  114. $statement = $db->prepare("
  115. SELECT
  116. skill,
  117. level
  118. FROM k_skill_level
  119. WHERE skill = :skill
  120. ORDER BY level;
  121. ");
  122. $statement->bindValue(':skill', $this->id, SQLITE3_INTEGER);
  123. $q = $statement->execute();
  124. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  125. array_push($this->level, new K_Skill_Level($r["skill"], $r["level"]));
  126. }
  127. $statement = $db->prepare("
  128. SELECT DISTINCT effect
  129. FROM k_skill_effect
  130. WHERE skill = :skill;
  131. ");
  132. $statement->bindValue(':skill', $this->id, SQLITE3_INTEGER);
  133. $q = $statement->execute();
  134. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  135. array_push($this->effect, new K_Effect($r["effect"]));
  136. }
  137. }
  138. }
  139. /**
  140. * Gets the path to the skill image. The image must be in the
  141. * img/skill/ directory, and its name must be the set id,
  142. * padded with '0' to 8 digits, and the extension must be '.png'.
  143. *
  144. * @return string Image URL, or a fixed unknown image.
  145. */
  146. public function get_image(){
  147. return APPLICATION::img("SKILL", $this->id);
  148. }
  149. }
  150. ?>