* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3 * @package SWDB */ require_once(PATH::ENTITY . "Entity.php"); require_once(PATH::ENTITY . "Buildable.php"); /** * A building. * * Represents an building owned by a player. * Buildings that can be built and leveled up are not considered buildings, but {@link Decoration}s. * * @category Entity */ class Building extends Entity{ /** * @var int Owner's player ID. */ private $player_id; /** * @var Buildable The base buildable. */ private $buildable; /** * @var int The gain per hour, on whatever bonus the building provides. */ private $gain; /** * Constructor. * * Searches the database and retrieves the information about the * building, populating it and it's items. * * @param int $id Building identifier. */ public function __construct($id){ $statement = get_context()->get_db()->prepare(" SELECT player, buildable, gain FROM building WHERE id = :id; "); $statement->bindValue(':id', $id, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->player = $r["player"]; $this->buildable = new Buildable($r["buildable"]); $this->gain = $r["gain"]; } } /** * Retrieves the player identifier of the owner * * @return int Player ID. */ public function get_player(){ return $this->player_id; } /** * Retrieves the base buildable. * * @return Buildable Base buildable. */ public function get_buildable(){ return $this->buildable; } /** * Retrieves the gain per hour, on whatever the building provides. * * @return int Gain per hour. */ public function get_gain(){ return $this->gain; } }