Leader_Skill.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. public $id;
  25. /**
  26. * @var int ID of the stat augmented by the leader skill.
  27. */
  28. public $stat;
  29. /**
  30. * @var int Amount the stat is increased by.
  31. */
  32. public $amount;
  33. /**
  34. * @var int Effect area id (if any).
  35. */
  36. public $area;
  37. /**
  38. * @var int Affected element id (if any).
  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 int $id Skill identifier.
  48. */
  49. public function __construct($id){
  50. $statement = get_context()->get_db()->prepare("
  51. SELECT
  52. id,
  53. stat,
  54. amount,
  55. area,
  56. element
  57. FROM leader_skill
  58. WHERE id = :id;
  59. ");
  60. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  61. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  62. if ($r){
  63. $this->id = $r["id"];
  64. $this->stat = $r["stat"];
  65. $this->amount = $r["amount"];
  66. $this->area = $r["area"];
  67. $this->element = $r["element"];
  68. }
  69. }
  70. /**
  71. * Gets the path to the skill image. The image must be in the
  72. * img/skill_leader/ directory, and its name must be the skill id,
  73. * padded with '0' to 4 digites, and the extension must be '.png'.
  74. *
  75. * @return string Image URL, or a fixed unknown image.
  76. */
  77. public function get_image(){
  78. return APPLICATION::img("SKILL_LEADER", $this->id);
  79. }
  80. /**
  81. * Composes a human readable description of the skill.
  82. *
  83. * @return string The description.
  84. */
  85. public function create_description(){
  86. $s = "Increases the ";
  87. switch ($this->attribute){
  88. case STAT_ID::ATK:
  89. $s .= "attack power";
  90. break;
  91. case STAT_ID::DEF:
  92. $s .= "defense";
  93. break;
  94. case STAT_ID::HP:
  95. $s .= "HP";
  96. break;
  97. case STAT_ID::SPD:
  98. $s .= "attack speed";
  99. break;
  100. case STAT_ID::CRIT_RATE:
  101. $s .= "critical rate";
  102. break;
  103. case STAT_ID::CRIT_DMG:
  104. $s .= "critical damage";
  105. break;
  106. case STAT_ID::ACCURACY:
  107. $s .= "accuracy";
  108. break;
  109. case STAT_ID::RESIST:
  110. $s .= "resistance";
  111. break;
  112. }
  113. $s .= " of ally monsters ";
  114. switch ($this->element){
  115. case ELEMENT_ID::WATER:
  116. $s .= " with Water attribute ";
  117. break;
  118. case ELEMENT_ID::FIRE:
  119. $s .= " with Fire attribute ";
  120. break;
  121. case ELEMENT_ID::WIND:
  122. $s .= " with Wind attribute ";
  123. break;
  124. case ELEMENT_ID::LIGHT:
  125. $s .= " with Light attribute ";
  126. break;
  127. case ELEMENT_ID::DARK:
  128. $s .= " with Dark attribute ";
  129. break;
  130. }
  131. $s = $s . "by " . $this->amount . "%";
  132. switch ($this->area){
  133. case EFFECT_AREA_ID::DUNGEON:
  134. $s = $s . " in the Dungeons";
  135. break;
  136. case EFFECT_AREA_ID::ARENA:
  137. $s = $s . " in the Arena";
  138. break;
  139. case EFFECT_AREA_ID::GUILD:
  140. $s = $s . " in Guild content";
  141. break;
  142. }
  143. $s = str_replace(" ", " ", $s) . ".";
  144. return $s;
  145. }
  146. }
  147. ?>