| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- /**
- * Fusion 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 . "K_Unit.php");
- require_once(PATH::ENTITY . "Unit.php");
- /**
- * Extension of K_Unit that also stores information about owned
- * monsters.
- *
- * @category Entity
- */
- class Monster_Fusion extends K_Unit{
- /**
- * @var \Unit[] All owned units of this type.
- */
- public $owned = [];
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * fusion, populating it and it's items.
- *
- * @param int $id Unit id.
- * @param int $uid Player id.
- * @global resource Database connection.
- */
- public function __construct($id, $uid){
- global $db;
- parent::__construct($id, true);
- $statement = $db->prepare("
- SELECT unit.id AS id
- FROM
- unit,
- k_unit
- WHERE
- k_unit.id = unit.unit AND
- unit.uid = :uid AND
- (
- k_unit.id = :id OR
- k_unit.awakens_from = :id OR
- k_unit.awakens_to = :id
- );
- ");
- $statement->bindValue(':uid', $uid, SQLITE3_INTEGER);
- $statement->bindValue(':id', $id, SQLITE3_INTEGER);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->owned, new Unit($r["id"], false));
- }
- }
- }
- /**
- * Fusion.
- *
- * Represents an object from the table 'fusion'.
- *
- * @category Entity
- */
- class Fusion extends Entity{
- /**
- * @var K_Unit K_Unit to fuse.
- */
- public $product;
- /**
- * @var K_Unit K_Unit to fuse (awakened).
- */
- public $product_awaken;
- /**
- * @var K_Unit K_Unit to fuse (unawakened).
- */
- public $product_unawaken;
- /**
- * @var Monster_Fusion Fusions required to create ingredients.
- */
- public $fusion = [];
- /**
- * @var \K_Unit[] List of unfuseable K_Unit material.
- */
- public $ingredient = [];
- /**
- * @var \K_Unit[] List of unfuseable K_Unit material. (unawakened).
- */
- public $ingredient_unawaken = [];
- /**
- * @var int Stars of the monster to fuse.
- */
- public $stars;
- /**
- * @var int Fusion cost.
- */
- public $cost;
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * fusion, populating it and it's items.
- *
- * @param int $id Product monster id.
- * @param int $uid User id.
- * @global resource Database connection.
- */
- public function __construct($id, $uid = null){
- global $db;
- $statement = $db->prepare("
- SELECT DISTINCT
- product,
- stars,
- cost
- FROM k_fusion
- WHERE
- product = $id OR
- product = (SELECT awakens_to FROM k_unit WHERE id = $id) OR
- product = (SELECT awakens_from FROM k_unit WHERE id = $id);
- ");
- $statement->bindValue(':id', $id, SQLITE3_INTEGER);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- $this->product = new Monster_Fusion($r["product"], $uid);
- $this->product_awaken = new Monster_Fusion($this->product->awakens_to, $uid);
- $this->stars = $r["stars"];
- $this->cost = $r["cost"];
- $statement = $db->prepare("
- SELECT DISTINCT ingredient
- FROM k_fusion
- WHERE
- product = :product AND
- ingredient IN (
- SELECT DISTINCT k_unit.id
- FROM
- k_fusion,
- k_unit
- WHERE
- k_fusion.product = k_unit.awakens_from OR
- k_fusion.product = k_unit.awakens_to OR
- k_fusion.product = k_unit.id
- );
- ");
- $statement->bindValue(':product', $this->product->id, SQLITE3_INTEGER);
- $q_f = $statement->execute();
- while ($r_f = $q_f->fetchArray(SQLITE3_ASSOC)){
- array_push($this->fusion, new Fusion($r_f["ingredient"], $uid));
- }
- $statement = $db->prepare("
- SELECT
- id,
- awakens_from
- FROM k_unit
- WHERE id IN (
- SELECT DISTINCT
- ingredient
- FROM k_fusion
- WHERE
- product = :product AND
- ingredient NOT IN (
- SELECT DISTINCT k_unit.id
- FROM
- k_fusion,
- k_unit
- WHERE
- k_fusion.product = k_unit.awakens_from OR
- k_fusion.product = k_unit.awakens_to OR
- k_fusion.product = k_unit.id
- )
- );
- ");
- $statement->bindValue(':product', $this->product->id, SQLITE3_INTEGER);
- $q_m = $statement->execute();
- while ($r_m = $q_m->fetchArray(SQLITE3_ASSOC)){
- $m = new Monster_Fusion($r_m["id"], $uid);
- array_push($this->ingredient, $m);
- $m = new Monster_Fusion($r_m["awakens_from"], $uid);
- $m->load_essences();
- array_push($this->ingredient_unawaken, $m);
- }
- }
- }
- ?>
|