| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- /**
- * Item entity file.
- *
- * Creates the entity and makes it available.
- *
- * @category Entity
- */
- /**
- * Require dependent entities if not present.
- */
- require_once(PATH::ENTITY . "Entity.php");
- require_once(PATH::ENTITY . "Monster.php");
- /**
- * An item in the players inventory inventory item.
- *
- * Represents an object from the table 'item'.
- *
- * @category Entity
- */
- class Item extends Entity{
-
- /**
- * @var string Owner's player identifier.
- */
- private $player;
-
- /**
- * @var int|Monster Item identifier. If its a monster piece, a Monster entity.
- */
- private $id;
-
- /**
- * @var string Item name.
- */
- private $name;
-
- /**
- * @var string Item type name.
- */
- private $type;
-
- /**
- * @var int Item owned amount.
- */
- private $amount;
-
- /**
- * @var bool Indicates if the item are monster pieces.
- */
- private $is_monster_pieces;
-
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * building, populating it and it's items.
- *
- * @param string $player Owner's player identifier.
- * @param int $id Item identifier.
- * @param int $type Item type identifier. Optional, will try to guess if null.
- */
- public function __construct($player, $id, $type = null){
-
- $s = "
- SELECT
- item.player AS player,
- item.id AS id,
- inventory.name AS name,
- inventory.description AS description,
- item.type AS type_ref,
- inventory_type.name AS type,
- item.amount AS amount
- FROM
- item,
- inventory,
- inventory_type
- WHERE
- item.player = :player AND
- item.id = inventory.id AND
- item.type = inventory.type AND
- inventory.type = inventory_type.id AND
- inventory.id = inventory.id AND
- inventory.type = inventory.type AND
- inventory.id = :id
- ";
- if ($type != null){
- $s .= "AND inventory.type = :type";
- }
- $statement = get_context()->get_db()->prepare($s);
- $statement->bindValue(':player', $player, SQLITE3_TEXT);
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
- $statement->bindValue(':type', $type, SQLITE3_TEXT);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->player = $r["player"];
- $this->type = $r["type"];
- $this->amount = $r["amount"];
- if ($r["type"] == INVENTORY_TYPE_ID::GUILD_MONSTER_PIECE || $r["type"] == INVENTORY_TYPE_ID::MONSTER_PIECE){
- $this->is_monster_pieces = true;
- $this->id = new Monster($r["id"]);
- $this->name = HTML::e($this->id->get_title()) . " Pieces";
- $this->description = HTML::e($this->id->get_title()) . " Pieces";
- }
- else{
- $this->is_monster_pices = false;
- $this->id = $r["id"];
- $this->name = HTML::e($r["name"]);
- $this->description = HTML::e($r["description"]);
- }
- }
- }
-
- /**
- * Retrieves the owner's player identifier
- *
- * @return string Owner's ID.
- */
- public function get_player(){
- return $this->player;
- }
-
- /**
- * Retrieves the item identifier.
- * If the item is a monster piece, the unit instance will be returned instead
- *
- * @return int|Monster Item ID or monster instance
- */
- public function get_id(){
- return $this->id;
- }
-
- /**
- * Retrieves the item name.
- *
- * @return string Item name.
- */
- public function get_name(){
- return $this->name;
- }
-
- /**
- * Retrieves the item type.
- *
- * @return int Item type.
- */
- public function get_type(){
- return $this->type;
- }
-
- /**
- * Retrieves the owned amount of the item.
- *
- * @return int Owned amount.
- */
- public function get_amount(){
- return $this->amount;
- }
-
- /**
- * Checks if the item is a monste piece.
- *
- * @return boolean True for monster pieces, false otherwise.
- */
- public function is_monster_pieces(){
- return $this->is_monster_pieces;
- }
-
- /**
- * Gets the path to the item image.
- *
- * @return string Image URL, or a fixed unknown image.
- */
- public function get_image(){
- return APPLICATION::img("INVENTORY", $this->id);
- }
- }
- ?>
|