K_Effect.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. /**
  4. * Skill effect.
  5. *
  6. * Represents an object from the table 'k_effect'.
  7. */
  8. class K_Effect extends Entity{
  9. /**
  10. * Effect identifier.
  11. */
  12. public $id;
  13. /**
  14. * Effect name.
  15. */
  16. public $name;
  17. /**
  18. * Indicates if the effect is a buff.
  19. */
  20. public $is_buff;
  21. /**
  22. * Effect description.
  23. */
  24. public $description;
  25. /**
  26. * Constructor.
  27. *
  28. * Searches the database and retrieves the information about the
  29. * skill level, populating it and it's items.
  30. *
  31. * @param SQLite3 $db Connection to the database.
  32. * @param int $skill Effect identifier.
  33. */
  34. public function __construct($db, $id){
  35. global $path;
  36. parent::__construct($db);
  37. $s =
  38. "SELECT " .
  39. " id, " .
  40. " name, " .
  41. " is_buff, " .
  42. " description " .
  43. "FROM k_effect " .
  44. "WHERE id = $id;";
  45. $q = $this->db->query($s);
  46. $r = $q->fetchArray(SQLITE3_ASSOC);
  47. if ($r){
  48. $this->id = $r["id"];
  49. $this->name = $r["name"];
  50. $this->is_buff = $r["is_buff"];
  51. $this->description = $r["description"];
  52. }
  53. }
  54. /**
  55. * Gets the pathto the monster image. The image must be in the
  56. * img/effect/ directory, and its name must be the effect id,
  57. * padded with '0' to 4 digits, and the extension must be '.png'.
  58. *
  59. * @return path to the image, or a path to a fixed unknown image if it
  60. * doesn't exist.
  61. */
  62. public function get_image(){
  63. global $base_dir;
  64. global $path;
  65. if (file_exists($base_dir . "img/effect/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
  66. return $path["img"]["effect"] . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
  67. }
  68. else{
  69. return $path["img"]["root"] . "unknown.png";
  70. }
  71. }
  72. }
  73. ?>