Run.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "Unit.php");
  4. require_once($path["entity"] . "K_Unit.php");
  5. require_once($path["entity"] . "Rune.php");
  6. require_once($path["entity"] . "Inventory.php");
  7. require_once($path["entity"] . "K_Area.php");
  8. /**
  9. * A run.
  10. *
  11. * Represents an object from the table 'run'.
  12. */
  13. class Run extends Entity{
  14. /**
  15. * Player identifier.
  16. */
  17. public $uid;
  18. /**
  19. * Run identifier.
  20. */
  21. public $id;
  22. /**
  23. * Run start datestame.
  24. */
  25. public $dtime;
  26. /**
  27. * Area.
  28. */
  29. public $area;
  30. /**
  31. * Stage.
  32. */
  33. public $stage;
  34. /**
  35. * Difficulty (only scenario and dimension hole)
  36. */
  37. public $difficulty;
  38. /**
  39. * Win or lost run.
  40. */
  41. public $win;
  42. /**
  43. * Clear time.
  44. */
  45. public $time;
  46. /**
  47. * Reward mana.
  48. */
  49. public $mana;
  50. /**
  51. * Reward energy.
  52. */
  53. public $energy;
  54. /**
  55. * Reward crystal.
  56. */
  57. public $crystal;
  58. /**
  59. * Indicates if a frind/mentor helped.
  60. */
  61. public $helper;
  62. /**
  63. * Array of {@see Unit}s or {@see K_Unit}.
  64. * If the unit is still owned, it will be a instance of Unit.
  65. * If not, it will be a instance of K_Unit.
  66. */
  67. public $party = [];
  68. /**
  69. * List of {@see Inventory}, of dropped items.
  70. */
  71. public $item = [];
  72. /**
  73. * List of {@see K_Unit}s dropped.
  74. */
  75. public $unit = [];
  76. /**
  77. * List of {@see K_Unit}s whose secret dungeons were found on the run.
  78. */
  79. public $sd= [];
  80. /**
  81. * List of [{@see K_Unit}, quantity] of dropped summon pieces.
  82. */
  83. public $unit_piece = [];
  84. /**
  85. * Number of shapeshifting stones dropped;
  86. */
  87. public $shapeshifting = 0;
  88. /**
  89. * List of {@see Rune}s dropped.
  90. */
  91. public $rune= [];
  92. /**
  93. * Constructor.
  94. *
  95. * Searches the database and retrieves the information about the
  96. * run, populating it and it's items.
  97. *
  98. * @param SQLite3 $db Connection to the database.
  99. * @param int $id Run identifier.
  100. */
  101. public function __construct($db, $id){
  102. global $path;
  103. global $AREA_TYPE;
  104. global $SCENARIO;
  105. global $DUNGEON;
  106. global $RAID_RIFT_DUNGEON;
  107. global $ELEMENTAL_RIFT_DUNGEON;
  108. parent::__construct($db);
  109. $s = "
  110. SELECT
  111. id,
  112. uid,
  113. dtime,
  114. area,
  115. stage,
  116. difficulty,
  117. win,
  118. time,
  119. mana,
  120. energy,
  121. crystal,
  122. helper
  123. FROM run
  124. WHERE id = $id;
  125. ";
  126. $q = $this->db->query($s);
  127. $r = $q->fetchArray(SQLITE3_ASSOC);
  128. $this->id = $r["id"];
  129. $this->uid = $r["uid"];
  130. $this->dtime = $r["dtime"];
  131. $type = 0;
  132. if (in_array($r["area"], $RAID_RIFT_DUNGEON) && $r["stage"] < 1){
  133. $type = $AREA_TYPE["RIFT_RAID_DUNGEON"];
  134. }
  135. elseif (in_array($r["area"], $SCENARIO)){
  136. $type = $AREA_TYPE["SCENARIO"];
  137. }
  138. elseif (in_array($r["area"], $ELEMENTAL_RIFT_DUNGEON) && $r["stage"] < 1){
  139. $type = $AREA_TYPE["ELEMENTAL_RIFT_DUNGEON"];
  140. }
  141. elseif (in_array($r["area"], $DUNGEON)){
  142. $type = $AREA_TYPE["CAIROS_DUNGEON"];
  143. }
  144. $this->area = new K_Area($this->db, $r["area"], $type);
  145. $this->stage = $r["stage"];
  146. $this->difficulty = $r["difficulty"];
  147. $this->win = $r["win"];
  148. $this->time = $r["time"];
  149. $this->mana = $r["mana"];
  150. $this->energy = $r["energy"];
  151. $this->crystal = $r["crystal"];
  152. $this->helper = $r["helper"];
  153. $s = "
  154. SELECT
  155. unit,
  156. k_unit,
  157. (SELECT count(id) FROM unit WHERE unit.unit = k_unit) AS owned
  158. FROM run_party
  159. WHERE run = $id;
  160. ";
  161. $q = $this->db->query($s);
  162. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  163. if ($r["owned"] > 0){
  164. array_push($this->party, new Unit($this->db, $r["unit"], false));
  165. }
  166. else{
  167. array_push($this->party, new K_Unit($this->db, $r["k_unit"], false));
  168. }
  169. }
  170. $s = "
  171. SELECT
  172. item,
  173. quantity
  174. FROM run_drop_item
  175. WHERE run = $this->id;
  176. ";
  177. $q = $this->db->query($s);
  178. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  179. $i = new K_Inventory($this->db, $r["item"]);
  180. $i->amount = $r["quantity"];
  181. array_push($this->item, $i);
  182. }
  183. $s = "
  184. SELECT unit
  185. FROM run_drop_unit
  186. WHERE run = $this->id;
  187. ";
  188. $q = $this->db->query($s);
  189. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  190. array_push($this->unit, new K_Unit($this->db, $r["unit"]));
  191. }
  192. $s = "
  193. SELECT unit
  194. FROM run_drop_sd
  195. WHERE run = $this->id;
  196. ";
  197. $q = $this->db->query($s);
  198. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  199. array_push($this->sd, new K_Unit($this->db, $r["unit"]));
  200. }
  201. $s = "
  202. SELECT
  203. unit,
  204. quantity
  205. FROM run_drop_unit_pieces
  206. WHERE run = $this->id;
  207. ";
  208. $q = $this->db->query($s);
  209. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  210. $i = [
  211. "unit" => new K_Unit($this->db, $r["unit"]),
  212. "quantity" => $r["quantity"]
  213. ];
  214. array_push($this->unit_piece, $i);
  215. }
  216. $s = "
  217. SELECT quantity
  218. FROM run_drop_shapeshifting
  219. WHERE run = $this->id;
  220. ";
  221. $q = $this->db->query($s);
  222. $r = $q->fetchArray(SQLITE3_ASSOC);
  223. if ($r){
  224. $this->shapeshifting = $r["quantity"];
  225. }
  226. $s = "
  227. SELECT
  228. id,
  229. type,
  230. slot,
  231. stars,
  232. ancient,
  233. quality,
  234. value,
  235. efficiency,
  236. main_stat,
  237. main_stat_value,
  238. innate_stat,
  239. innate_stat_value,
  240. substat_1,
  241. substat_1_value,
  242. substat_2,
  243. substat_2_value,
  244. substat_3,
  245. substat_3_value,
  246. substat_4,
  247. substat_4_value
  248. FROM run_drop_rune
  249. WHERE run = $this->id;
  250. ";
  251. $q = $this->db->query($s);
  252. $r = $q->fetchArray(SQLITE3_ASSOC);
  253. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  254. $rune = new Rune($this->id, $r["id"]);
  255. if (!isset($rune->id)){
  256. $rune->id = $r["id"];
  257. $rune->assigned_to = null;
  258. $rune->type = $r["type"];
  259. $rune->slot = $r["slot"];
  260. $rune->stars = $r["stars"];
  261. $rune->ancient = $r["ancient"];
  262. $rune->quality = $r["quality"];
  263. $rune->original_quality = $r["quality"];
  264. $rune->value = $r["value"];
  265. $rune->efficiency = $r["efficiency"];
  266. // TODO: Calculate?
  267. $rune->max_efficiency = $r["efficiency"];
  268. $rune->main_stat = $r["main_stat"];
  269. $rune->main_stat_value = $r["main_stat_value"];
  270. $rune->innate_stat = $r["innate_stat"];
  271. $rune->innate_stat_value = $r["innate_stat_value"];
  272. $rune->substat_1 = $r["substat_1"];
  273. $rune->substat_1_value = $r["substat_1_value"];
  274. $rune->substat_2 = $r["substat_2"];
  275. $rune->substat_2_value = $r["substat_2_value"];
  276. $rune->substat_3 = $r["substat_3"];
  277. $rune->substat_3_value = $r["substat_3_value"];
  278. $rune->substat_4 = $r["substat_4"];
  279. $rune->substat_4_value = $r["substat_4_value"];
  280. }
  281. array_push($this->rune, $rune);
  282. }
  283. }
  284. }
  285. ?>