K_Fusion.php 5.7 KB

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