Fusion.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "K_Unit.php");
  4. require_once($path["entity"] . "Unit.php");
  5. /**
  6. * Extension of {@see K_Unit} that also stores information about owned
  7. * monsters.
  8. */
  9. class Monster_Fusion extends K_Unit{
  10. /**
  11. * All owned {@see Monster}s of this type.
  12. */
  13. public $owned = [];
  14. /**
  15. * Constructor.
  16. *
  17. * Searches the database and retrieves the information about the
  18. * fusion, populating it and it's items.
  19. *
  20. * @param SQLite3 $db Connection to the database.
  21. * @param int $id Monster id.
  22. */
  23. public function __construct($db, $id, $uid){
  24. global $path;
  25. parent::__construct($db, $id, false);
  26. $s = "
  27. SELECT unit.id AS id
  28. FROM
  29. unit,
  30. k_unit
  31. WHERE
  32. k_unit.id = unit.unit AND
  33. unit.uid = '$uid' AND
  34. (
  35. k_unit.id = $id OR
  36. k_unit.awakens_from = $id OR
  37. k_unit.awakens_to = $id
  38. );
  39. ";
  40. $q = $this->db->query($s);
  41. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  42. array_push($this->owned, new Unit($this->db, $r["id"], false));
  43. }
  44. }
  45. }
  46. /**
  47. * Fusion.
  48. *
  49. * Represents an object from the table 'fusion'.
  50. */
  51. class Fusion extends Entity{
  52. /**
  53. * {@see K_Unit} to fuse.
  54. */
  55. public $product;
  56. /**
  57. * {@see K_Unit} to fuse (awakened).
  58. */
  59. public $product_awaken;
  60. /**
  61. * {@see K_Unit} to fuse (awakened).
  62. */
  63. public $product_unawaken;
  64. /**
  65. * Fusions required to create ingredients.
  66. */
  67. public $fusion = [];
  68. /**
  69. * List of unfuseable {@see K_Unit} material.
  70. */
  71. public $ingredient = [];
  72. /**
  73. * List of unfuseable {@see K_Unit} material (awakened).
  74. */
  75. public $ingredient_unawaken = [];
  76. /**
  77. * Stars of the monster to fuse.
  78. */
  79. public $stars;
  80. /**
  81. * Fusion cost.
  82. */
  83. public $cost;
  84. /**
  85. * Constructor.
  86. *
  87. * Searches the database and retrieves the information about the
  88. * fusion, populating it and it's items.
  89. *
  90. * @param SQLite3 $db Connection to the database.
  91. * @param int $id Product monster id.
  92. * @param int $uid User id (optional)
  93. */
  94. public function __construct($db, $id, $uid = null){
  95. global $path;
  96. parent::__construct($db);
  97. $s = "
  98. SELECT DISTINCT
  99. product,
  100. stars,
  101. cost
  102. FROM k_fusion
  103. WHERE
  104. product = $id OR
  105. product = (SELECT awakens_to FROM k_unit WHERE id = $id) OR
  106. product = (SELECT awakens_from FROM k_unit WHERE id = $id);
  107. ";
  108. $q = $this->db->query($s);
  109. $r = $q->fetchArray(SQLITE3_ASSOC);
  110. $this->product = new Monster_Fusion($this->db, $r["product"], $uid);
  111. $this->product_awaken = new Monster_Fusion($this->db, $this->product->awakens_to, $uid);
  112. $this->stars = $r["stars"];
  113. $this->cost = $r["cost"];
  114. $s_f = "
  115. SELECT DISTINCT ingredient
  116. FROM k_fusion
  117. WHERE
  118. product = " . $this->product->id . " AND
  119. ingredient IN (
  120. SELECT DISTINCT k_unit.id
  121. FROM
  122. k_fusion,
  123. k_unit
  124. WHERE
  125. k_fusion.product = k_unit.awakens_from OR
  126. k_fusion.product = k_unit.awakens_to OR
  127. k_fusion.product = k_unit.id
  128. );
  129. ";
  130. $q_f = $this->db->query($s_f);
  131. while ($r_f = $q_f->fetchArray(SQLITE3_ASSOC)){
  132. array_push($this->fusion, new Fusion($this->db, $r_f["ingredient"], $uid));
  133. }
  134. $s_m =
  135. "SELECT " .
  136. " id, " .
  137. " awakens_from " .
  138. "FROM k_unit " .
  139. "WHERE id IN ( " .
  140. " SELECT DISTINCT " .
  141. " ingredient " .
  142. " FROM k_fusion " .
  143. " WHERE " .
  144. " product = " . $this->product->id . " AND " .
  145. " ingredient NOT IN ( " .
  146. " SELECT DISTINCT k_unit.id " .
  147. " FROM " .
  148. " k_fusion, " .
  149. " k_unit " .
  150. " WHERE " .
  151. " k_fusion.product = k_unit.awakens_from OR " .
  152. " k_fusion.product = k_unit.awakens_to OR " .
  153. " k_fusion.product = k_unit.id " .
  154. " ) " .
  155. " ); ";
  156. $q_m = $this->db->query($s_m);
  157. while ($r_m = $q_m->fetchArray(SQLITE3_ASSOC)){
  158. $m = new Monster_Fusion($this->db, $r_m["id"], $uid);
  159. array_push($this->ingredient, $m);
  160. $m = new Monster_Fusion($this->db, $r_m["awakens_from"], $uid);
  161. $m->load_essences();
  162. array_push($this->ingredient_unawaken, $m);
  163. }
  164. }
  165. }
  166. ?>