K_Fusion.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "K_Monster.php");
  4. /**
  5. * Fusion.
  6. *
  7. * Represents an object from the table 'fusion'.
  8. */
  9. class Fusion extends Entity{
  10. /**
  11. * Fusion identifier.
  12. */
  13. public $id;
  14. /**
  15. * {@see K_Monster} to fuse.
  16. */
  17. public $product;
  18. /**
  19. * {@see K_Monster} to fuse (awakened).
  20. */
  21. public $product_awaken;
  22. /**
  23. * {@see K_Monster} to fuse (awakened).
  24. */
  25. public $product_unawaken;
  26. /**
  27. * Fusions required to create ingredients.
  28. */
  29. public $fusion = [];
  30. /**
  31. * List of unfuseable {@see K_Monster} material.
  32. */
  33. public $ingredient = [];
  34. /**
  35. * List of unfuseable {@see K_Monster} material (awakened).
  36. */
  37. public $ingredient_unawaken = [];
  38. /**
  39. * Stars of the monster to fuse.
  40. */
  41. public $stars;
  42. /**
  43. * Fusion cost.
  44. */
  45. public $cost;
  46. /**
  47. * Constructor.
  48. *
  49. * Searches the database and retrieves the information about the
  50. * fusion, populating it and it's items.
  51. *
  52. * @param SQLite3 $db Connection to the database.
  53. * @param int $id Product monster id.
  54. */
  55. public function __construct($db, $id){
  56. global $path;
  57. parent::__construct($db);
  58. $s =
  59. "SELECT DISTINCT " .
  60. " id, " .
  61. " product, " .
  62. " stars, " .
  63. " cost " .
  64. "FROM k_fusion " .
  65. "WHERE " .
  66. " product = $id OR " .
  67. " product = (SELECT awakens_to FROM k_monster WHERE id = $id) OR " .
  68. " product = (SELECT awakens_from FROM k_monster WHERE id = $id); ";
  69. $q = $this->db->query($s);
  70. $r = $q->fetchArray(SQLITE3_ASSOC);
  71. $this->id = $r["id"];
  72. $this->product = new K_Monster($this->db, $r["product"]);
  73. $this->product_awaken = new K_Monster($this->db, $this->product->awakens_to);
  74. $this->stars = $r["stars"];
  75. $this->cost = $r["cost"];
  76. $s_f =
  77. "SELECT DISTINCT " .
  78. " ingredient " .
  79. "FROM k_fusion " .
  80. "WHERE " .
  81. " product = " . $this->product->id . " AND " .
  82. " ingredient IN ( " .
  83. " SELECT DISTINCT k_monster.id " .
  84. " FROM " .
  85. " k_fusion, " .
  86. " k_monster " .
  87. " WHERE " .
  88. " k_fusion.product = k_monster.awakens_from OR " .
  89. " k_fusion.product = k_monster.awakens_to OR " .
  90. " k_fusion.product = k_monster.id " .
  91. " ); ";
  92. $q_f = $this->db->query($s_f);
  93. while ($r_f = $q_f->fetchArray(SQLITE3_ASSOC)){
  94. array_push($this->fusion, new Fusion($this->db, $r_f["ingredient"]));
  95. }
  96. $s_m =
  97. "SELECT " .
  98. " id, " .
  99. " awakens_from " .
  100. "FROM k_monster " .
  101. "WHERE id IN ( " .
  102. " SELECT DISTINCT " .
  103. " ingredient " .
  104. " FROM k_fusion " .
  105. " WHERE " .
  106. " product = " . $this->product->id . " AND " .
  107. " ingredient NOT IN ( " .
  108. " SELECT DISTINCT k_monster.id " .
  109. " FROM " .
  110. " k_fusion, " .
  111. " k_monster " .
  112. " WHERE " .
  113. " k_fusion.product = k_monster.awakens_from OR " .
  114. " k_fusion.product = k_monster.awakens_to OR " .
  115. " k_fusion.product = k_monster.id " .
  116. " ) " .
  117. " ); ";
  118. error_log("ING: " . $s_m);
  119. $q_m = $this->db->query($s_m);
  120. while ($r_m = $q_m->fetchArray(SQLITE3_ASSOC)){
  121. array_push($this->ingredient, new K_Monster($this->db, $r_m["id"]));
  122. error_log("NEW awakens_from: " . $r_m["awakens_from"]);
  123. array_push($this->ingredient_unawaken, new K_Monster($this->db, $r_m["awakens_from"]));
  124. }
  125. }
  126. }
  127. ?>