K_Skill.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. $s =
  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. $q = $db->query($s);
  101. $r = $q->fetchArray(SQLITE3_ASSOC);
  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. $s =
  113. "SELECT " .
  114. " skill, " .
  115. " level " .
  116. "FROM k_skill_level " .
  117. "WHERE skill = " . $this->id . " " .
  118. "ORDER BY level; ";
  119. $q = $db->query($s);
  120. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  121. array_push($this->level, new K_Skill_Level($r["skill"], $r["level"]));
  122. }
  123. $s =
  124. "SELECT DISTINCT effect " .
  125. "FROM k_skill_effect " .
  126. "WHERE skill = " . $this->id . "; ";
  127. $q = $db->query($s);
  128. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  129. array_push($this->effect, new K_Effect($r["effect"]));
  130. }
  131. }
  132. /**
  133. * Gets the path to the skill image. The image must be in the
  134. * img/skill/ directory, and its name must be the set id,
  135. * padded with '0' to 8 digits, and the extension must be '.png'.
  136. *
  137. * @return string Image URL, or a fixed unknown image.
  138. */
  139. public function get_image(){
  140. return APPLICATION::img("SKILL", $this->id);
  141. }
  142. }
  143. ?>