Skill.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. private $id;
  27. /**
  28. * @var string Skill name.
  29. */
  30. private $name;
  31. /**
  32. * @var string Skill description.
  33. */
  34. private $description;
  35. /**
  36. * @var int Skill order.
  37. */
  38. private $slot;
  39. /**
  40. * @var int Skill cooldown turns.
  41. */
  42. private $cooltime;
  43. /**
  44. * @var int Number of hits.
  45. */
  46. private $hits;
  47. /**
  48. * @var bool Wether the skill is passive or not.
  49. */
  50. private $passive;
  51. /**
  52. * @var bool Wether the skill is AOE.
  53. */
  54. private $aoe;
  55. /**
  56. * @var int Skill max level.
  57. */
  58. private $max_level;
  59. /**
  60. * @var string Skill formula.
  61. */
  62. private $multiplier_formula;
  63. /**
  64. * @var Skill The skill upgrading this one.
  65. */
  66. private $upgrade;
  67. private $flag_levels = false;
  68. /**
  69. * @var \Skill_Level[] Available skill levels.
  70. */
  71. private $level = [];
  72. private $flag_effects = false;
  73. /**
  74. * @var \Effect[] Associated eeffects.
  75. */
  76. private $effect = [];
  77. /**
  78. * Constructor.
  79. *
  80. * Searches the database and retrieves the information about the
  81. * skill, populating it and it's items.
  82. *
  83. * @param int $id Skill identifier.
  84. */
  85. public function __construct($id){
  86. $statement = get_context()->get_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 skill
  99. WHERE id = :id;
  100. ");
  101. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  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. }
  115. }
  116. private function load_levels(){
  117. $statement = get_context()->get_db()->prepare("
  118. SELECT
  119. skill,
  120. level
  121. FROM skill_level
  122. WHERE skill = :skill
  123. ORDER BY level;
  124. ");
  125. $statement->bindValue(':skill', $this->id, SQLITE3_TEXT);
  126. $q = $statement->execute();
  127. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  128. array_push($this->level, new Skill_Level($r["skill"], $r["level"]));
  129. }
  130. $this->flag_levels = true;
  131. }
  132. private function load_effects(){
  133. $statement = get_context()->get_db()->prepare("
  134. SELECT DISTINCT effect
  135. FROM skill_effect
  136. WHERE skill = :skill;
  137. ");
  138. $statement->bindValue(':skill', $this->id, SQLITE3_TEXT);
  139. $q = $statement->execute();
  140. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  141. array_push($this->effect, new Effect($r["effect"]));
  142. }
  143. $this->flag_effects = true;
  144. }
  145. /**
  146. * Retrieves the skill identifier.
  147. *
  148. * @return number Skill id.
  149. */
  150. public function get_id(){
  151. return $this->id;
  152. }
  153. /**
  154. * Retrieves the skill name.
  155. *
  156. * @return string Sill name.
  157. */
  158. public function get_name(){
  159. return $this->name;
  160. }
  161. /**
  162. * Retrieves the skill description.
  163. *
  164. * @return string Skill description.
  165. */
  166. public function get_description(){
  167. return $this->description;
  168. }
  169. /**
  170. * Retrieves the skill slot.
  171. *
  172. * @return number The skill slot (1-4);
  173. */
  174. public function get_slot(){
  175. return $this->slot;
  176. }
  177. /**
  178. * Retrieves the skill cooldown time
  179. *
  180. * @return number Skill cooltime.
  181. */
  182. public function get_cooltime(){
  183. return $this->cooltime;
  184. }
  185. /**
  186. * Retrieves the number of times the skill hist.
  187. *
  188. * @return number Number of hits.
  189. */
  190. public function get_hits(){
  191. return $this->hits;
  192. }
  193. /**
  194. * Checks if the skill is passive.
  195. *
  196. * @return boolean True for passive skills, false for active.
  197. */
  198. public function is_passive(){
  199. return $this->passive;
  200. }
  201. /**
  202. * Checks if the skills affects a group instead of a unit.
  203. *
  204. * @return boolean True for AOE skills, false for single-target skills.
  205. */
  206. public function is_aoe(){
  207. return $this->aoe;
  208. }
  209. /**
  210. * Retrieves the maximum level of the skill.
  211. *
  212. * @return number Skill max level.
  213. */
  214. public function get_max_level(){
  215. return $this->max_level;
  216. }
  217. /**
  218. * Retrieves the skills mathematical formula.
  219. *
  220. * @return string Skill formula.
  221. */
  222. public function get_multiplier_formula(){
  223. return $this->multiplier_formula;
  224. }
  225. /**
  226. * Retrieves the skill this one upgrades to (ie, on awakening).
  227. *
  228. * @return Skill Upgraded skill, null if not upgradeable.
  229. */
  230. public function get_upgrade(){
  231. return $this->upgrade;
  232. }
  233. /**
  234. * Retrieves information about the skill levels.
  235. *
  236. * @return Skill_Level[] Levels of the skill.
  237. */
  238. public function get_levels(){
  239. if (! $this->flag_levels){
  240. $this->load_levels();
  241. }
  242. return $this->level;
  243. }
  244. /**
  245. * Retrieves the effects caused by the skill.
  246. *
  247. * @return Effect[] Effects caused by the skill.
  248. */
  249. public function get_effects(){
  250. if (! $this->flag_effects){
  251. $this->load_effects();
  252. }
  253. return $this->effect;
  254. }
  255. /**
  256. * Gets the path to the skill image.
  257. *
  258. * @return string Image URL, or a fixed unknown image.
  259. */
  260. public function get_image(){
  261. return APPLICATION::img("SKILL", $this->id);
  262. }
  263. }
  264. ?>