K_Leader_Skill.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 skill.
  15. *
  16. * Represents an object from the table 'k_skill'.
  17. *
  18. * @category Entity
  19. */
  20. class K_Leader_Skill extends Entity{
  21. /**
  22. * @var int Skill identifier.
  23. */
  24. public $id;
  25. /**
  26. * @var int Skill attribute ID.
  27. */
  28. public $attribute;
  29. /**
  30. * @var int Attribute increase amount.
  31. */
  32. public $amount;
  33. /**
  34. * @var int Effect area id.
  35. */
  36. public $area;
  37. /**
  38. * @var int Affected element id.
  39. */
  40. public $element;
  41. /**
  42. * Constructor.
  43. *
  44. * Searches the database and retrieves the information about the
  45. * skill, populating it and it's items.
  46. *
  47. * @param resource $db Connection to the database.
  48. * @param int $id Skill identifier.
  49. */
  50. public function __construct($db, $id){
  51. parent::__construct($db);
  52. $s =
  53. "SELECT " .
  54. " id, " .
  55. " stat, " .
  56. " amount, " .
  57. " area, " .
  58. " element " .
  59. "FROM k_leader_skill " .
  60. "WHERE id = $id; ";
  61. $q = $this->db->query($s);
  62. $r = $q->fetchArray(SQLITE3_ASSOC);
  63. $this->id = $r["id"];
  64. $this->attribute = $r["stat"];
  65. $this->amount = $r["amount"];
  66. $this->area = $r["area"];
  67. $this->element = $r["element"];
  68. }
  69. /**
  70. * Gets the path to the skill image. The image must be in the
  71. * img/skill_leader/ directory, and its name must be the skill id,
  72. * padded with '0' to 4 digites, and the extension must be '.png'.
  73. *
  74. * @return string Image URL, or a fixed unknown image.
  75. */
  76. public function get_image(){
  77. if (file_exists(PATH::BASE . "img/content/skill_leader/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
  78. return URL::IMG["SKILL_LEADER"] . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
  79. }
  80. else{
  81. return URL::IMG["UNKNOWN"];
  82. }
  83. }
  84. /**
  85. * Composes a human readable description of the skill.
  86. *
  87. * @return string The description.
  88. */
  89. public function create_description(){
  90. global $STAT;
  91. global $ELEMENT;
  92. global $EFFECT_AREA;
  93. $s = "Increases the ";
  94. switch ($this->attribute){
  95. case STAT::ATK:
  96. $s .= "attack power";
  97. break;
  98. case STAT::DEF:
  99. $s .= "defense";
  100. break;
  101. case STAT::HP:
  102. $s .= "HP";
  103. break;
  104. case STAT::SPD:
  105. $s .= "attack speed";
  106. break;
  107. case STAT::CRIT_RATE:
  108. $s .= "critical rate";
  109. break;
  110. case STAT::CRIT_DMG:
  111. $s .= "critical damage";
  112. break;
  113. case STAT::ACC:
  114. $s .= "accuracy";
  115. break;
  116. case STAT::RES:
  117. $s .= "resistance";
  118. break;
  119. }
  120. $s .= " of ally monsters ";
  121. switch ($this->element){
  122. case ELEMENT_ID::WATER:
  123. $s .= " with Water attribute ";
  124. break;
  125. case ELEMENT_ID::FIRE:
  126. $s .= " with Fire attribute ";
  127. break;
  128. case ELEMENT_ID::WIND:
  129. $s .= " with Wind attribute ";
  130. break;
  131. case ELEMENT_ID::LIGHT:
  132. $s .= " with Light attribute ";
  133. break;
  134. case ELEMENT_ID::DARK:
  135. $s .= " with Dark attribute ";
  136. break;
  137. }
  138. $s = $s . "by " . $this->amount . "%";
  139. switch ($this->area){
  140. case EFFECT_AREA::DUNGEON:
  141. $s = $s . " in the Dungeons";
  142. break;
  143. case EFFECT_AREA::ARENA:
  144. $s = $s . " in the Arena";
  145. break;
  146. case EFFECT_AREA::GUILD:
  147. $s = $s . " in Guild content";
  148. break;
  149. }
  150. $s = $s . ".";
  151. return $s;
  152. }
  153. }
  154. ?>