Run.php 9.6 KB

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