Decorative.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Decorative key entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @category Entity
  8. */
  9. /**
  10. * Require dependent entities if not present.
  11. */
  12. require_once(PATH::ENTITY . "Entity.php");
  13. /**
  14. * Decorative.
  15. *
  16. * Represents an object from the table 'k_decorative'.
  17. *
  18. * @category Entity
  19. */
  20. class Decorative extends Entity{
  21. /**
  22. * @var int Decorative identifier.
  23. */
  24. public $id;
  25. /**
  26. * @var string Decorative name.
  27. */
  28. public $name;
  29. /**
  30. * @var string Decorative description.
  31. */
  32. public $description;
  33. /**
  34. * @var int Area of effect identifier (if any).
  35. */
  36. public $area;
  37. /**
  38. * @var int Affected stat id (if any).
  39. */
  40. public $stat;
  41. /**
  42. * @var int Affected element id(if any).
  43. */
  44. public $element;
  45. /**
  46. * @var int Max. level.
  47. */
  48. public $max_level;
  49. /**
  50. * @var int[] Effect bonus per level.
  51. */
  52. public $level_bonus = [];
  53. /**
  54. * Cost per level.
  55. */
  56. public $level_cost = [];
  57. /**
  58. * Constructor.
  59. *
  60. * Searches the database and retrieves the information about the
  61. * decoration, populating it and it's items.
  62. *
  63. * @param int $id Decorative identifier.
  64. */
  65. public function __construct($id){
  66. $statement = get_context()->get_db()->prepare("
  67. SELECT
  68. id,
  69. name,
  70. description,
  71. area,
  72. affected_stat,
  73. element,
  74. max_level
  75. FROM decorative
  76. WHERE id = :id;
  77. ");
  78. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  79. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  80. if ($r){
  81. $this->id = $r["id"];
  82. $this->name = HTML::e($r["name"]);
  83. $this->description = HTML::e($r["description"]);
  84. $this->area = $r["area"];
  85. $this->stat = $r["affected_stat"];
  86. $this->element = $r["element"];
  87. $this->max_level = $r["max_level"];
  88. $statement = get_context()->get_db()->prepare("
  89. SELECT
  90. level,
  91. bonus,
  92. cost
  93. FROM decorative_level
  94. WHERE decorative = :id
  95. ");
  96. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  97. $q = $statement->execute();
  98. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  99. $this->level_bonus[$r["level"]] = $r["bonus"];
  100. $this->level_cost[$r["level"]] = $r["cost"];
  101. }
  102. }
  103. }
  104. /**
  105. * Gets the path to the building image. The image must be in the
  106. * img/decoration/ directory, and its name must be the decoration
  107. * id, padded with '0' to 4 digites, and the extension must be '.png'.
  108. *
  109. * @return string Image URL, or a fixed unknown image.
  110. */
  111. public function get_image(){
  112. return APPLICATION::img("DECORATION", $this->id);
  113. }
  114. }
  115. ?>