|
@@ -1,120 +1,178 @@
|
|
|
<?php
|
|
<?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{
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * Item entity file.
|
|
|
|
|
- *
|
|
|
|
|
- * Creates the entity and makes it available.
|
|
|
|
|
- *
|
|
|
|
|
- * @category Entity
|
|
|
|
|
|
|
+ * @var string Owner's player identifier.
|
|
|
*/
|
|
*/
|
|
|
-
|
|
|
|
|
|
|
+ private $player;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * Require dependent entities if not present.
|
|
|
|
|
|
|
+ * @var int|Monster Item identifier. If its a monster piece, a Monster entity.
|
|
|
*/
|
|
*/
|
|
|
- require_once(PATH::ENTITY . "Entity.php");
|
|
|
|
|
- require_once(PATH::ENTITY . "Monster.php");
|
|
|
|
|
-
|
|
|
|
|
|
|
+ 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;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * An inventory item.
|
|
|
|
|
|
|
+ * Constructor.
|
|
|
*
|
|
*
|
|
|
- * Represents an object from the table 'item'.
|
|
|
|
|
|
|
+ * Searches the database and retrieves the information about the
|
|
|
|
|
+ * building, populating it and it's items.
|
|
|
*
|
|
*
|
|
|
- * @category Entity
|
|
|
|
|
|
|
+ * @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.
|
|
|
*/
|
|
*/
|
|
|
- class Item extends Entity{
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @var int Owner's player identifier.
|
|
|
|
|
- */
|
|
|
|
|
- public $player;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @var int|Monster Item identifier. If its a monster piece, a Monster entity.
|
|
|
|
|
- */
|
|
|
|
|
- public $id;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @var string Item name.
|
|
|
|
|
- */
|
|
|
|
|
- public $name;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @var string Item type name.
|
|
|
|
|
- */
|
|
|
|
|
- public $type;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @var int Item owned amount.
|
|
|
|
|
- */
|
|
|
|
|
- public $amount;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @var bool Indicates if the item are monster pieces.
|
|
|
|
|
- */
|
|
|
|
|
- public $is_monster_pices;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Constructor.
|
|
|
|
|
- *
|
|
|
|
|
- * Searches the database and retrieves the information about the
|
|
|
|
|
- * building, populating it and it's items.
|
|
|
|
|
- *
|
|
|
|
|
- * @param int $id Item identifier.
|
|
|
|
|
- * @param int $type Item type identifier. Optional, will try to guess if null.
|
|
|
|
|
- */
|
|
|
|
|
- public function __construct($id, $type = null){
|
|
|
|
|
-
|
|
|
|
|
- $s = "
|
|
|
|
|
- SELECT
|
|
|
|
|
- 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
|
|
|
|
|
- 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";
|
|
|
|
|
|
|
+ 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
|
|
|
|
|
+ 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";
|
|
|
}
|
|
}
|
|
|
- $statement = get_context()->get_db()->prepare($s);
|
|
|
|
|
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
|
|
|
|
|
- $statement->bindValue(':type', $type, SQLITE3_TEXT);
|
|
|
|
|
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
|
|
|
|
|
- if ($r){
|
|
|
|
|
- $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_pices = true;
|
|
|
|
|
- $this->id = new Monster($r["id"]);
|
|
|
|
|
- $this->name = HTML::e($this->id->title) . " Pieces";
|
|
|
|
|
- $this->description = HTML::e($this->id->title) . " Pieces";
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- $this->is_monster_pices = false;
|
|
|
|
|
- $this->id = $r["id"];
|
|
|
|
|
- $this->name = HTML::e($r["name"]);
|
|
|
|
|
- $this->description = HTML::e($r["description"]);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ else{
|
|
|
|
|
+ $this->is_monster_pices = false;
|
|
|
|
|
+ $this->id = $r["id"];
|
|
|
|
|
+ $this->name = HTML::e($r["name"]);
|
|
|
|
|
+ $this->description = HTML::e($r["description"]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Gets the path to the item image. The image must be in the
|
|
|
|
|
- * img/content/inventory/ directory, and its name must be the item id,
|
|
|
|
|
- * padded with '0' to 9 digites, and the extension must be '.png'.
|
|
|
|
|
- *
|
|
|
|
|
- * @return string Image URL, or a fixed unknown image.
|
|
|
|
|
- */
|
|
|
|
|
- public function get_image(){
|
|
|
|
|
- return APPLICATION::img("INVENTORY", $this->id);
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 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);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
?>
|
|
?>
|