Decorative.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. * Retrieves the decorative identifier.
  106. *
  107. * @return int Decorative ID.
  108. */
  109. public function get_id(){
  110. return $this->id;
  111. }
  112. /**
  113. * Retrieves the name of the decorative.
  114. *
  115. * @return string Decorative name.
  116. */
  117. public function get_name(){
  118. return $this->name;
  119. }
  120. /**
  121. * Retrieves $the decorative description.
  122. *
  123. * @return string Decorative description.
  124. */
  125. public function get_description(){
  126. return $this->description;
  127. }
  128. /**
  129. * Retrieves the identifier of the area where the decorative has an effect
  130. *
  131. * @see AREA_TYPE_ID
  132. *
  133. * @return int Area type ID, null if the decorative has a global effect.
  134. */
  135. public function get_area_type(){
  136. return $this->area;
  137. }
  138. /**
  139. * Retrieves the stat raised by the decorative, if any.
  140. *
  141. * @see STAT_ID
  142. *
  143. * @return int Stat ID, null if non applicable.
  144. */
  145. public function get_stat(){
  146. return $this->stat;
  147. }
  148. /**
  149. * Retrieves the element the effect applies to, if any.
  150. *
  151. * @see ELEMENT_ID
  152. *
  153. * @return int Element ID, null if not an elemental decorative.
  154. */
  155. public function get_element(){
  156. return $this->element;
  157. }
  158. /**
  159. * Retrieves the maximum level of the decorative.
  160. *
  161. * @return int Maximum level.
  162. */
  163. public function get_max_level(){
  164. return $this->max_level;
  165. }
  166. /**
  167. * Retrieves a list of bonuses indexed by the decorative level.
  168. *
  169. * @return number[] Array of bonuses by level.
  170. */
  171. public function get_level_bonus(){
  172. return $this->level_bonus;
  173. }
  174. /**
  175. * Retrieves a list of prices indexed by the decorative level.
  176. *
  177. * @return number[] Array of prices by level.
  178. */
  179. public function get_level_cost(){
  180. return $this->level_cost;
  181. }
  182. /**
  183. * Gets the path to the decorative image.
  184. *
  185. * @return string Image URL, or a fixed unknown image.
  186. */
  187. public function get_image(){
  188. return APPLICATION::img("DECORATION", $this->id);
  189. }
  190. }
  191. ?>