K_Fusion.php 5.6 KB

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