K_Skill.php 3.9 KB

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