Leader_Skill.php 4.9 KB

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