Decorative.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /**
  3. * Decorative entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. require_once(PATH::ENTITY . "Entity.php");
  12. /**
  13. * Decorative.
  14. *
  15. * Represents any of the available decorations in the game.
  16. * Decorations are buildings that can be built and leveled up. If it can't be leveled up, it's not
  17. * a decorative, but a {@link Buildable}.
  18. *
  19. * @category Entity
  20. */
  21. class Decorative extends Entity{
  22. /**
  23. * @var int Decorative identifier.
  24. */
  25. private $id;
  26. /**
  27. * @var string Decorative name.
  28. */
  29. private $name;
  30. /**
  31. * @var string Decorative description.
  32. */
  33. private $description;
  34. /**
  35. * @var int Area of effect identifier (if any).
  36. */
  37. private $area;
  38. /**
  39. * @var int Affected stat id (if any).
  40. */
  41. private $stat;
  42. /**
  43. * @var int Affected element id(if any).
  44. */
  45. private $element;
  46. /**
  47. * @var int Max. level.
  48. */
  49. private $max_level;
  50. /**
  51. * @var int[] Effect bonus per level.
  52. */
  53. private $level_bonus = [];
  54. /**
  55. * Cost per level.
  56. */
  57. private $level_cost = [];
  58. /**
  59. * Constructor.
  60. *
  61. * Searches the database and retrieves the information about the
  62. * decoration, populating it and it's items.
  63. *
  64. * @param int $id Decorative identifier.
  65. */
  66. public function __construct($id){
  67. $statement = get_context()->get_db()->prepare("
  68. SELECT
  69. id,
  70. name,
  71. description,
  72. area,
  73. affected_stat,
  74. element,
  75. max_level
  76. FROM decorative
  77. WHERE id = :id;
  78. ");
  79. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  80. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  81. if ($r){
  82. $this->id = $r["id"];
  83. $this->name = HTML::e($r["name"]);
  84. $this->description = HTML::e($r["description"]);
  85. $this->area = $r["area"];
  86. $this->stat = $r["affected_stat"];
  87. $this->element = $r["element"];
  88. $this->max_level = $r["max_level"];
  89. $statement = get_context()->get_db()->prepare("
  90. SELECT
  91. level,
  92. bonus,
  93. cost
  94. FROM decorative_level
  95. WHERE decorative = :id
  96. ");
  97. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  98. $q = $statement->execute();
  99. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  100. $this->level_bonus[$r["level"]] = $r["bonus"];
  101. $this->level_cost[$r["level"]] = $r["cost"];
  102. }
  103. }
  104. }
  105. /**
  106. * Retrieves the decorative identifier.
  107. *
  108. * @return int Decorative ID.
  109. */
  110. public function get_id(){
  111. return $this->id;
  112. }
  113. /**
  114. * Retrieves the name of the decorative.
  115. *
  116. * @return string Decorative name.
  117. */
  118. public function get_name(){
  119. return $this->name;
  120. }
  121. /**
  122. * Retrieves $the decorative description.
  123. *
  124. * @return string Decorative description.
  125. */
  126. public function get_description(){
  127. return $this->description;
  128. }
  129. /**
  130. * Retrieves the identifier of the area where the decorative has an effect
  131. *
  132. * @see AREA_TYPE_ID
  133. *
  134. * @return int Area type ID, null if the decorative has a global effect.
  135. */
  136. public function get_area_type(){
  137. return $this->area;
  138. }
  139. /**
  140. * Retrieves the stat raised by the decorative, if any.
  141. *
  142. * @see STAT_ID
  143. *
  144. * @return int Stat ID, null if non applicable.
  145. */
  146. public function get_stat(){
  147. return $this->stat;
  148. }
  149. /**
  150. * Retrieves the element the effect applies to, if any.
  151. *
  152. * @see ELEMENT_ID
  153. *
  154. * @return int Element ID, null if not an elemental decorative.
  155. */
  156. public function get_element(){
  157. return $this->element;
  158. }
  159. /**
  160. * Retrieves the maximum level of the decorative.
  161. *
  162. * @return int Maximum level.
  163. */
  164. public function get_max_level(){
  165. return $this->max_level;
  166. }
  167. /**
  168. * Retrieves a list of bonuses indexed by the decorative level.
  169. *
  170. * @return int[] Array of bonuses by level.
  171. */
  172. public function get_level_bonus(){
  173. return $this->level_bonus;
  174. }
  175. /**
  176. * Retrieves a list of prices indexed by the decorative level.
  177. *
  178. * @return int[] Array of prices by level.
  179. */
  180. public function get_level_cost(){
  181. return $this->level_cost;
  182. }
  183. /**
  184. * Gets the path to the decorative image.
  185. *
  186. * @return string Image URL, or a fixed unknown image.
  187. */
  188. public function get_image(){
  189. return APPLICATION::img("DECORATION", $this->id);
  190. }
  191. }