K_Leader_Skill.php 4.6 KB

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