Leader_Skill.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /**
  3. * Leader 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. /**
  14. * Monster leader skill.
  15. *
  16. * Represents an object from the table 'leader_skill'.
  17. *
  18. * @category Entity
  19. */
  20. class Leader_Skill extends Entity{
  21. /**
  22. * @var int Leader skill identifier.
  23. */
  24. private $id;
  25. /**
  26. * @var int ID of the stat augmented by the leader skill.
  27. */
  28. private $stat;
  29. /**
  30. * @var int Amount the stat is increased by.
  31. */
  32. private $amount;
  33. /**
  34. * @var int Effect area id (if any).
  35. */
  36. private $area;
  37. /**
  38. * @var int Affected element id (if any).
  39. */
  40. private $element;
  41. private $description;
  42. /**
  43. * Constructor.
  44. *
  45. * Searches the database and retrieves the information about the
  46. * skill, populating it and it's items.
  47. *
  48. * @param int $id Skill identifier.
  49. */
  50. public function __construct($id){
  51. $statement = get_context()->get_db()->prepare("
  52. SELECT
  53. id,
  54. stat,
  55. amount,
  56. area,
  57. element
  58. FROM leader_skill
  59. WHERE id = :id;
  60. ");
  61. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  62. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  63. if ($r){
  64. $this->id = $r["id"];
  65. $this->stat = $r["stat"];
  66. $this->amount = $r["amount"];
  67. $this->area = $r["area"];
  68. $this->element = $r["element"];
  69. $this->description = $this->create_description();
  70. }
  71. }
  72. /**
  73. * Retrieves the leader skill identifier.
  74. *
  75. * @return string Leader skill ID.
  76. */
  77. public function get_id(){
  78. return $this->id;
  79. }
  80. /**
  81. * Retrieves $stat
  82. *
  83. * @return number
  84. */
  85. public function get_stat(){
  86. return $this->stat;
  87. }
  88. /**
  89. * Retrieves $amount
  90. *
  91. * @return number
  92. */
  93. public function get_amount(){
  94. return $this->amount;
  95. }
  96. /**
  97. * Retrieves $area
  98. *
  99. * @return number
  100. */
  101. public function get_area(){
  102. return $this->area;
  103. }
  104. /**
  105. * Retrieves $element
  106. *
  107. * @return number
  108. */
  109. public function get_element(){
  110. return $this->element;
  111. }
  112. /**
  113. * Retrieves the skill description.
  114. *
  115. * @return string Skill description.
  116. */
  117. public function get_description(){
  118. return $this->description;
  119. }
  120. /**
  121. * Gets the path to the skill image. The image must be in the
  122. * img/skill_leader/ directory, and its name must be the skill id,
  123. * padded with '0' to 4 digites, and the extension must be '.png'.
  124. *
  125. * @return string Image URL, or a fixed unknown image.
  126. */
  127. public function get_image(){
  128. return APPLICATION::img("SKILL_LEADER", $this->id);
  129. }
  130. /**
  131. * Composes a human readable description of the skill.
  132. *
  133. * @return string The description.
  134. */
  135. private function create_description(){
  136. $s = "Increases the ";
  137. switch ($this->stat){
  138. case STAT_ID::ATK:
  139. $s .= "attack power";
  140. break;
  141. case STAT_ID::DEF:
  142. $s .= "defense";
  143. break;
  144. case STAT_ID::HP:
  145. $s .= "HP";
  146. break;
  147. case STAT_ID::SPD:
  148. $s .= "attack speed";
  149. break;
  150. case STAT_ID::CRIT_RATE:
  151. $s .= "critical rate";
  152. break;
  153. case STAT_ID::CRIT_DMG:
  154. $s .= "critical damage";
  155. break;
  156. case STAT_ID::ACCURACY:
  157. $s .= "accuracy";
  158. break;
  159. case STAT_ID::RESIST:
  160. $s .= "resistance";
  161. break;
  162. }
  163. $s .= " of ally monsters ";
  164. switch ($this->element){
  165. case ELEMENT_ID::WATER:
  166. $s .= " with Water attribute ";
  167. break;
  168. case ELEMENT_ID::FIRE:
  169. $s .= " with Fire attribute ";
  170. break;
  171. case ELEMENT_ID::WIND:
  172. $s .= " with Wind attribute ";
  173. break;
  174. case ELEMENT_ID::LIGHT:
  175. $s .= " with Light attribute ";
  176. break;
  177. case ELEMENT_ID::DARK:
  178. $s .= " with Dark attribute ";
  179. break;
  180. }
  181. $s = $s . "by " . $this->amount . "%";
  182. switch ($this->area){
  183. case EFFECT_AREA_ID::DUNGEON:
  184. $s = $s . " in the Dungeons";
  185. break;
  186. case EFFECT_AREA_ID::ARENA:
  187. $s = $s . " in the Arena";
  188. break;
  189. case EFFECT_AREA_ID::GUILD:
  190. $s = $s . " in Guild content";
  191. break;
  192. }
  193. $s = str_replace(" ", " ", $s) . ".";
  194. return $s;
  195. }
  196. }
  197. ?>