K_Decoration.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. /**
  4. * Decoration.
  5. *
  6. * Represents an object from the table 'k_decoration'.
  7. */
  8. class K_Decoration extends Entity{
  9. /**
  10. * Decoration identifier.
  11. */
  12. public $id;
  13. /**
  14. * Decoration name.
  15. */
  16. public $name;
  17. /**
  18. * Decoration description.
  19. */
  20. public $description;
  21. /**
  22. * Area of effect (if any).
  23. */
  24. public $area;
  25. /**
  26. * Affected stat (if any).
  27. */
  28. public $stat;
  29. /**
  30. * Affected element (if any).
  31. */
  32. public $element;
  33. /**
  34. * Max. level ().
  35. */
  36. public $max_level;
  37. /**
  38. * Effect bonus per level.
  39. */
  40. public $level_bonus = [];
  41. /**
  42. * Cost per level.
  43. */
  44. public $level_cost = [];
  45. /**
  46. * Constructor.
  47. *
  48. * Searches the database and retrieves the information about the
  49. * decoration, populating it and it's items.
  50. *
  51. * @param SQLite3 $db Connection to the database.
  52. * @param int $id Decoration identifier.
  53. */
  54. public function __construct($db, $id){
  55. global $path;
  56. parent::__construct($db);
  57. $s = "
  58. SELECT
  59. id,
  60. name,
  61. description,
  62. area,
  63. affected_stat,
  64. element,
  65. max_level
  66. FROM k_decoration
  67. WHERE id = $id;
  68. ";
  69. $q = $this->db->query($s);
  70. $r = $q->fetchArray(SQLITE3_ASSOC);
  71. if ($r){
  72. $this->id = $r["id"];
  73. $this->name = $r["name"];
  74. $this->description = $r["description"];
  75. $this->area = $r["area"];
  76. $this->stat = $r["affected_stat"];
  77. $this->element = $r["element"];
  78. $this->max_level = $r["max_level"];
  79. $s = "
  80. SELECT
  81. level,
  82. bonus,
  83. cost
  84. FROM k_decoration_level
  85. WHERE decoration = $id
  86. ";
  87. $q = $this->db->query($s);
  88. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  89. $this->level_bonus[$r["level"]] = $r["bonus"];
  90. $this->level_cost[$r["level"]] = $r["cost"];
  91. }
  92. }
  93. }
  94. /**
  95. * Gets the path to the building image. The image must be in the
  96. * img/content/decoration/ directory, and its name must be the monster id,
  97. * padded with '0' to 4 digites, and the extension must be '.png'.
  98. *
  99. * @return path to the image, or a path to a fixed unknown image if it
  100. * doesn't exist.
  101. */
  102. public function get_image(){
  103. global $base_dir;
  104. global $path;
  105. if (file_exists($base_dir . "img/decoration/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
  106. return $path["img"]["decoration"] . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
  107. }
  108. else{
  109. return $path["img"]["root"] . "unknown.png";
  110. }
  111. }
  112. }
  113. ?>