Run.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <?php
  2. /**
  3. * Saved run entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @category Entity
  8. */
  9. /**
  10. * Require dependent entities if not present.
  11. */
  12. require_once(PATH::ENTITY . "Entity.php");
  13. require_once(PATH::ENTITY . "Unit.php");
  14. require_once(PATH::ENTITY . "K_Unit.php");
  15. require_once(PATH::ENTITY . "Rune.php");
  16. require_once(PATH::ENTITY . "Inventory.php");
  17. require_once(PATH::ENTITY . "K_Area.php");
  18. require_once(PATH::ENTITY . "K_Rune_Set.php");
  19. /**
  20. * A run.
  21. *
  22. * Represents an object from the table 'run'.
  23. *
  24. * @category Entity
  25. */
  26. class Run extends Entity{
  27. /**
  28. * @var int Player identifier.
  29. */
  30. public $uid;
  31. /**
  32. * @var int Run identifier.
  33. */
  34. public $id;
  35. /**
  36. * @var DateTime Run start datestamp.
  37. */
  38. public $dtime;
  39. /**
  40. * @var K_Area Area.
  41. */
  42. public $area;
  43. /**
  44. * @var int Stage.
  45. */
  46. public $stage;
  47. /**
  48. * @var int Difficulty (only scenario and dimension hole)
  49. */
  50. public $difficulty;
  51. /**
  52. * @var bool Win or lost run.
  53. */
  54. public $win;
  55. /**
  56. * @var int Clear time, milliseconds.
  57. */
  58. public $time;
  59. /**
  60. * @var int Reward mana.
  61. */
  62. public $mana;
  63. /**
  64. * @var int Reward energy.
  65. */
  66. public $energy;
  67. /**
  68. * @var int Reward crystal.
  69. */
  70. public $crystal;
  71. /**
  72. * @var bool Indicates if a frind/mentor helped.
  73. */
  74. public $helper;
  75. /**
  76. * @var int Score in battles that are rated (WB, rift dungeons...).
  77. */
  78. public $score;
  79. /**
  80. * @var String Rank in battles that are rated (WB, rift dungeons...).
  81. */
  82. public $rank;
  83. /**
  84. * @var \Unit[]|\K_Unit[] Uits used.
  85. * If the unit is still owned, it will be a instance of Unit.
  86. * If not, it will be a instance of K_Unit.
  87. */
  88. public $party = [];
  89. /**
  90. * @var int ID of the leader unit.
  91. */
  92. public $leader;
  93. /**
  94. * @var int[] List of IDs of the frontline units.
  95. */
  96. public $frontline = [];
  97. /**
  98. * @var \Inventory[] Dropped items.
  99. */
  100. public $item = [];
  101. /**
  102. * @var \K_Unit[] Units dropped.
  103. */
  104. public $unit = [];
  105. /**
  106. * @var int K_Unit[] Units whose secret dungeons were found on the run.
  107. */
  108. public $sd= [];
  109. /**
  110. * @var mixed[] List of dropped summon pieces.
  111. *
  112. * Formated as:
  113. * [@{see K_Unit}, amount]
  114. */
  115. public $unit_piece = [];
  116. /**
  117. * @var int Number of shapeshifting stones dropped;
  118. */
  119. public $shapeshifting = 0;
  120. /**
  121. * @var \Rune[] List of Runes dropped.
  122. */
  123. public $rune= [];
  124. /**
  125. * Constructor.
  126. *
  127. * Searches the database and retrieves the information about the
  128. * run, populating it and it's items.
  129. *
  130. * @param int $id Run identifier.
  131. * @global resource Database connection.
  132. */
  133. public function __construct($id){
  134. global $db;
  135. $s = "
  136. SELECT
  137. id,
  138. uid,
  139. dtime,
  140. area,
  141. stage,
  142. difficulty,
  143. win,
  144. time,
  145. mana,
  146. energy,
  147. crystal,
  148. helper,
  149. score,
  150. rank
  151. FROM run
  152. WHERE id = $id;
  153. ";
  154. $q = $db->query($s);
  155. $r = $q->fetchArray(SQLITE3_ASSOC);
  156. $this->id = $r["id"];
  157. $this->uid = $r["uid"];
  158. $this->dtime = $r["dtime"];
  159. $type = 0;
  160. if (APPLICATION::valid_id("RAID_RIFT_DUNGEON_ID", $r["area"]) && $r["stage"] < 1){
  161. $type = AREA_TYPE_ID::RIFT_RAID_DUNGEON;
  162. }
  163. elseif (APPLICATION::valid_id("SCENARIO_ID", $r["area"])){
  164. $type = AREA_TYPE_ID::SCENARIO;
  165. }
  166. elseif (APPLICATION::valid_id("ELEMENTAL_RIFT_DUNGEON_ID", $r["area"]) && $r["stage"] < 1){
  167. $type = AREA_TYPE_ID::RIFT_DUNGEON;
  168. }
  169. elseif (APPLICATION::valid_id("CAIROS_DUNGEON_ID", $r["area"])){
  170. $type = AREA_TYPE_ID::CAIROS_DUNGEON;
  171. }
  172. elseif (APPLICATION::valid_id("DIMENSION_DUNGEON_ID", $r["area"])){
  173. if ($this->id == 1486){
  174. error_log("VALID AREA ID: " . $r["area"] . ", " . AREA_TYPE_ID::DIMENSIONAL_HOLE);
  175. }
  176. $type = AREA_TYPE_ID::DIMENSIONAL_HOLE;
  177. }
  178. if ($this->id == 1486){
  179. error_log("INSTANCING DH AREA: " . $r["area"] . ", " . $type);
  180. }
  181. $this->area = new K_Area($r["area"], $type);
  182. $this->stage = $r["stage"];
  183. $this->difficulty = $r["difficulty"];
  184. $this->win = $r["win"];
  185. $this->time = $r["time"];
  186. $this->mana = $r["mana"];
  187. $this->energy = $r["energy"];
  188. $this->crystal = $r["crystal"];
  189. $this->helper = $r["helper"];
  190. $this->score = $r["score"];
  191. $this->rank = $r["rank"];
  192. $s = "
  193. SELECT
  194. unit,
  195. k_unit,
  196. (SELECT count(id) FROM unit WHERE unit.id = run_party.unit) AS owned,
  197. leader,
  198. front
  199. FROM run_party
  200. WHERE run = $id
  201. ORDER BY
  202. front DESC,
  203. leader DESC;
  204. ";
  205. $q = $db->query($s);
  206. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  207. if ($r["owned"] > 0){
  208. array_push($this->party, new Unit($r["unit"], false));
  209. }
  210. else{
  211. array_push($this->party, new K_Unit($r["k_unit"], false));
  212. }
  213. if ($r["leader"] == 1){
  214. $this->leader = $r["unit"];
  215. }
  216. if ($r["front"] == 1){
  217. array_push($this->frontline, $r["unit"]);
  218. }
  219. }
  220. $s = "
  221. SELECT
  222. item,
  223. amount
  224. FROM run_drop_item
  225. WHERE run = $this->id;
  226. ";
  227. $q = $db->query($s);
  228. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  229. $i = new Inventory($r["item"]);
  230. $i->amount = $r["amount"];
  231. array_push($this->item, $i);
  232. }
  233. $s = "
  234. SELECT unit
  235. FROM run_drop_unit
  236. WHERE run = $this->id;
  237. ";
  238. $q = $db->query($s);
  239. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  240. array_push($this->unit, new K_Unit($r["unit"]));
  241. }
  242. $s = "
  243. SELECT unit
  244. FROM run_drop_sd
  245. WHERE run = $this->id;
  246. ";
  247. $q = $db->query($s);
  248. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  249. array_push($this->sd, new K_Unit($r["unit"]));
  250. }
  251. $s = "
  252. SELECT
  253. unit,
  254. amount
  255. FROM run_drop_unit_pieces
  256. WHERE run = $this->id;
  257. ";
  258. $q = $db->query($s);
  259. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  260. $i = [
  261. "unit" => new K_Unit($r["unit"]),
  262. "amount" => $r["amount"]
  263. ];
  264. array_push($this->unit_piece, $i);
  265. }
  266. $s = "
  267. SELECT amount
  268. FROM run_drop_shapeshifting
  269. WHERE run = $this->id;
  270. ";
  271. $q = $db->query($s);
  272. $r = $q->fetchArray(SQLITE3_ASSOC);
  273. if ($r){
  274. $this->shapeshifting = $r["amount"];
  275. }
  276. $s = "
  277. SELECT
  278. id,
  279. type,
  280. slot,
  281. stars,
  282. ancient,
  283. quality,
  284. value,
  285. efficiency,
  286. main_stat,
  287. main_stat_value,
  288. innate_stat,
  289. innate_stat_value,
  290. substat_1,
  291. substat_1_value,
  292. substat_2,
  293. substat_2_value,
  294. substat_3,
  295. substat_3_value,
  296. substat_4,
  297. substat_4_value
  298. FROM run_drop_rune
  299. WHERE run = $this->id;
  300. ";
  301. $q = $db->query($s);
  302. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  303. $rune = new Rune($r["id"]);
  304. if (!isset($rune->id)){
  305. $rune->id = $r["id"];
  306. $rune->level = 0;
  307. $rune->assigned_to = null;
  308. $rune->type = new K_Rune_Set($r["type"]);
  309. $rune->slot = $r["slot"];
  310. $rune->stars = $r["stars"];
  311. $rune->ancient = $r["ancient"];
  312. $rune->quality = $r["quality"];
  313. $rune->original_quality = $r["quality"];
  314. $rune->value = $r["value"];
  315. $rune->value = 0;
  316. $rune->efficiency = $r["efficiency"];
  317. // TODO: Calculate?
  318. $rune->max_efficiency = $r["efficiency"];
  319. $rune->main_stat = $r["main_stat"];
  320. $rune->main_stat_value = $r["main_stat_value"];
  321. $rune->innate_stat = $r["innate_stat"];
  322. $rune->innate_stat_value = $r["innate_stat_value"];
  323. $rune->substat_1 = $r["substat_1"];
  324. $rune->substat_1_value = $r["substat_1_value"];
  325. $rune->substat_1_enchant = 0;
  326. $rune->substat_1_grind = 0;
  327. $rune->substat_2 = $r["substat_2"];
  328. $rune->substat_2_value = $r["substat_2_value"];
  329. $rune->substat_2_enchant = 0;
  330. $rune->substat_2_grind = 0;
  331. $rune->substat_3 = $r["substat_3"];
  332. $rune->substat_3_value = $r["substat_3_value"];
  333. $rune->substat_3_enchant = 0;
  334. $rune->substat_3_grind = 0;
  335. $rune->substat_4 = $r["substat_4"];
  336. $rune->substat_4_value = $r["substat_4_value"];
  337. $rune->substat_4_enchant = 0;
  338. $rune->substat_4_grind = 0;
  339. $rune->refresh_names();
  340. }
  341. array_push($this->rune, $rune);
  342. }
  343. }
  344. }
  345. ?>