| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
- /**
- * Decorative entity file.
- *
- * Creates the entity and makes it available.
- *
- * @author Iñigo Valentin <i@inigovalentin.com>
- * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
- * @package SWDB
- */
- require_once(PATH::ENTITY . "Entity.php");
- /**
- * Decorative.
- *
- * Represents any of the available decorations in the game.
- * Decorations are buildings that can be built and leveled up. If it can't be leveled up, it's not
- * a decorative, but a {@link Buildable}.
- *
- * @category Entity
- */
- class Decorative extends Entity{
- /**
- * @var int Decorative identifier.
- */
- private $id;
- /**
- * @var string Decorative name.
- */
- private $name;
- /**
- * @var string Decorative description.
- */
- private $description;
- /**
- * @var int Area of effect identifier (if any).
- */
- private $area;
- /**
- * @var int Affected stat id (if any).
- */
- private $stat;
- /**
- * @var int Affected element id(if any).
- */
- private $element;
- /**
- * @var int Max. level.
- */
- private $max_level;
- /**
- * @var int[] Effect bonus per level.
- */
- private $level_bonus = [];
- /**
- * Cost per level.
- */
- private $level_cost = [];
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * decoration, populating it and it's items.
- *
- * @param int $id Decorative identifier.
- */
- public function __construct($id){
- $statement = get_context()->get_db()->prepare("
- SELECT
- id,
- name,
- description,
- area,
- affected_stat,
- element,
- max_level
- FROM decorative
- WHERE id = :id;
- ");
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->id = $r["id"];
- $this->name = HTML::e($r["name"]);
- $this->description = HTML::e($r["description"]);
- $this->area = $r["area"];
- $this->stat = $r["affected_stat"];
- $this->element = $r["element"];
- $this->max_level = $r["max_level"];
- $statement = get_context()->get_db()->prepare("
- SELECT
- level,
- bonus,
- cost
- FROM decorative_level
- WHERE decorative = :id
- ");
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- $this->level_bonus[$r["level"]] = $r["bonus"];
- $this->level_cost[$r["level"]] = $r["cost"];
- }
- }
- }
- /**
- * Retrieves the decorative identifier.
- *
- * @return int Decorative ID.
- */
- public function get_id(){
- return $this->id;
- }
- /**
- * Retrieves the name of the decorative.
- *
- * @return string Decorative name.
- */
- public function get_name(){
- return $this->name;
- }
- /**
- * Retrieves $the decorative description.
- *
- * @return string Decorative description.
- */
- public function get_description(){
- return $this->description;
- }
- /**
- * Retrieves the identifier of the area where the decorative has an effect
- *
- * @see AREA_TYPE_ID
- *
- * @return int Area type ID, null if the decorative has a global effect.
- */
- public function get_area_type(){
- return $this->area;
- }
- /**
- * Retrieves the stat raised by the decorative, if any.
- *
- * @see STAT_ID
- *
- * @return int Stat ID, null if non applicable.
- */
- public function get_stat(){
- return $this->stat;
- }
- /**
- * Retrieves the element the effect applies to, if any.
- *
- * @see ELEMENT_ID
- *
- * @return int Element ID, null if not an elemental decorative.
- */
- public function get_element(){
- return $this->element;
- }
- /**
- * Retrieves the maximum level of the decorative.
- *
- * @return int Maximum level.
- */
- public function get_max_level(){
- return $this->max_level;
- }
- /**
- * Retrieves a list of bonuses indexed by the decorative level.
- *
- * @return int[] Array of bonuses by level.
- */
- public function get_level_bonus(){
- return $this->level_bonus;
- }
- /**
- * Retrieves a list of prices indexed by the decorative level.
- *
- * @return int[] Array of prices by level.
- */
- public function get_level_cost(){
- return $this->level_cost;
- }
- /**
- * Gets the path to the decorative image.
- *
- * @return string Image URL, or a fixed unknown image.
- */
- public function get_image(){
- return APPLICATION::img("DECORATION", $this->id);
- }
- }
|