K_Skill.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "K_Skill_Level.php");
  4. require_once($path["entity"] . "K_Effect.php");
  5. /**
  6. * Monster skill.
  7. *
  8. * Represents an object from the table 'k_skill'.
  9. */
  10. class K_Skill extends Entity{
  11. /**
  12. * Skill identifier.
  13. */
  14. public $id;
  15. /**
  16. * Skill official identifier.
  17. */
  18. public $com2us_id;
  19. /**
  20. * Skill name.
  21. */
  22. public $name;
  23. /**
  24. * Skill description.
  25. */
  26. public $description;
  27. /**
  28. * Skill order.
  29. */
  30. public $slot;
  31. /**
  32. * Skill cooldown turns.
  33. */
  34. public $cooltime;
  35. /**
  36. * Number of hits.
  37. */
  38. public $hits;
  39. /**
  40. * Wether the skill is passive or not.
  41. */
  42. public $passive;
  43. /**
  44. * Wether the skill is AOE.
  45. */
  46. public $aoe;
  47. /**
  48. * Skill max level.
  49. */
  50. public $max_level;
  51. /**
  52. * Skill formula.
  53. */
  54. public $multiplier_formula;
  55. /**
  56. * The {@see Monster_Skill} upgrading this one.
  57. */
  58. public $upgrade;
  59. /**
  60. * Available {@see K_Skill_Level}
  61. */
  62. public $level = [];
  63. /**
  64. * Skill {@see K_Effect}s
  65. */
  66. public $effect = [];
  67. /**
  68. * Constructor.
  69. *
  70. * Searches the database and retrieves the information about the
  71. * skill, populating it and it's items.
  72. *
  73. * @param SQLite3 $db Connection to the database.
  74. * @param int $id Skill identifier.
  75. */
  76. public function __construct($db, $id){
  77. global $path;
  78. parent::__construct($db);
  79. $s =
  80. "SELECT " .
  81. " id, " .
  82. " com2us_id, " .
  83. " name, " .
  84. " description, " .
  85. " slot, " .
  86. " cooltime, " .
  87. " hits, " .
  88. " passive, " .
  89. " aoe, " .
  90. " max_level, " .
  91. " multiplier_formula " .
  92. "FROM k_skill " .
  93. "WHERE id = $id; ";
  94. $q = $this->db->query($s);
  95. $r = $q->fetchArray(SQLITE3_ASSOC);
  96. $this->id = $r["id"];
  97. $this->com2us_id = $r["com2us_id"];
  98. $this->name = $r["name"];
  99. $this->description = $r["description"];
  100. $this->slot = $r["slot"];
  101. $this->cooltime = $r["cooltime"];
  102. $this->hits = $r["hits"];
  103. $this->passive = $r["passive"];
  104. $this->aoe = $r["aoe"];
  105. $this->max_level = $r["max_level"];
  106. $this->multiplier_formula = $r["multiplier_formula"];
  107. $s =
  108. "SELECT " .
  109. " skill, " .
  110. " level " .
  111. "FROM k_skill_level " .
  112. "WHERE skill = " . $this->id . " " .
  113. "ORDER BY level; ";
  114. $q = $this->db->query($s);
  115. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  116. array_push($this->level, new K_Skill_Level($this->db, $r["skill"], $r["level"]));
  117. }
  118. $s =
  119. "SELECT effect " .
  120. "FROM k_skill_effect " .
  121. "WHERE skill = " . $this->id . "; ";
  122. $q = $this->db->query($s);
  123. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  124. array_push($this->effect, new K_Effect($this->db, $r["effect"]));
  125. }
  126. }
  127. public function get_image(){
  128. global $base_dir;
  129. global $path;
  130. if (file_exists($base_dir . "img/content/skill/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
  131. return $path["img"]["content"] . "skill/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
  132. }
  133. else{
  134. return $path["img"]["layout"] . "unknown.png";
  135. }
  136. }
  137. }
  138. ?>