* @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); } }