Run.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. $type = AREA_TYPE_ID::DIMENSIONAL_HOLE;
  174. }
  175. $this->area = new K_Area($r["area"], $type);
  176. $this->stage = $r["stage"];
  177. $this->difficulty = $r["difficulty"];
  178. $this->win = $r["win"];
  179. $this->time = $r["time"];
  180. $this->mana = $r["mana"];
  181. $this->energy = $r["energy"];
  182. $this->crystal = $r["crystal"];
  183. $this->helper = $r["helper"];
  184. $this->score = $r["score"];
  185. $this->rank = $r["rank"];
  186. $s = "
  187. SELECT
  188. unit,
  189. k_unit,
  190. (SELECT count(id) FROM unit WHERE unit.id = run_party.unit) AS owned,
  191. leader,
  192. front
  193. FROM run_party
  194. WHERE run = $id
  195. ORDER BY
  196. front DESC,
  197. leader DESC;
  198. ";
  199. $q = $db->query($s);
  200. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  201. if ($r["owned"] > 0){
  202. array_push($this->party, new Unit($r["unit"], false));
  203. }
  204. else{
  205. array_push($this->party, new K_Unit($r["k_unit"], false));
  206. }
  207. if ($r["leader"] == 1){
  208. $this->leader = $r["unit"];
  209. }
  210. if ($r["front"] == 1){
  211. array_push($this->frontline, $r["unit"]);
  212. }
  213. }
  214. $s = "
  215. SELECT
  216. item,
  217. amount
  218. FROM run_drop_item
  219. WHERE run = $this->id;
  220. ";
  221. $q = $db->query($s);
  222. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  223. $i = new Inventory($r["item"]);
  224. $i->amount = $r["amount"];
  225. array_push($this->item, $i);
  226. }
  227. $s = "
  228. SELECT unit
  229. FROM run_drop_unit
  230. WHERE run = $this->id;
  231. ";
  232. $q = $db->query($s);
  233. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  234. array_push($this->unit, new K_Unit($r["unit"]));
  235. }
  236. $s = "
  237. SELECT unit
  238. FROM run_drop_sd
  239. WHERE run = $this->id;
  240. ";
  241. $q = $db->query($s);
  242. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  243. array_push($this->sd, new K_Unit($r["unit"]));
  244. }
  245. $s = "
  246. SELECT
  247. unit,
  248. amount
  249. FROM run_drop_unit_pieces
  250. WHERE run = $this->id;
  251. ";
  252. $q = $db->query($s);
  253. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  254. $i = [
  255. "unit" => new K_Unit($r["unit"]),
  256. "amount" => $r["amount"]
  257. ];
  258. array_push($this->unit_piece, $i);
  259. }
  260. $s = "
  261. SELECT amount
  262. FROM run_drop_shapeshifting
  263. WHERE run = $this->id;
  264. ";
  265. $q = $db->query($s);
  266. $r = $q->fetchArray(SQLITE3_ASSOC);
  267. if ($r){
  268. $this->shapeshifting = $r["amount"];
  269. }
  270. $s = "
  271. SELECT
  272. id,
  273. type,
  274. slot,
  275. stars,
  276. ancient,
  277. quality,
  278. value,
  279. efficiency,
  280. main_stat,
  281. main_stat_value,
  282. innate_stat,
  283. innate_stat_value,
  284. substat_1,
  285. substat_1_value,
  286. substat_2,
  287. substat_2_value,
  288. substat_3,
  289. substat_3_value,
  290. substat_4,
  291. substat_4_value
  292. FROM run_drop_rune
  293. WHERE run = $this->id;
  294. ";
  295. $q = $db->query($s);
  296. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  297. $rune = new Rune($r["id"]);
  298. if (!isset($rune->id)){
  299. $rune->id = $r["id"];
  300. $rune->level = 0;
  301. $rune->assigned_to = null;
  302. $rune->type = new K_Rune_Set($r["type"]);
  303. $rune->slot = $r["slot"];
  304. $rune->stars = $r["stars"];
  305. $rune->ancient = $r["ancient"];
  306. $rune->quality = $r["quality"];
  307. $rune->original_quality = $r["quality"];
  308. $rune->value = $r["value"];
  309. $rune->value = 0;
  310. $rune->efficiency = $r["efficiency"];
  311. // TODO: Calculate?
  312. $rune->max_efficiency = $r["efficiency"];
  313. $rune->main_stat = $r["main_stat"];
  314. $rune->main_stat_value = $r["main_stat_value"];
  315. $rune->innate_stat = $r["innate_stat"];
  316. $rune->innate_stat_value = $r["innate_stat_value"];
  317. $rune->substat_1 = $r["substat_1"];
  318. $rune->substat_1_value = $r["substat_1_value"];
  319. $rune->substat_1_enchant = 0;
  320. $rune->substat_1_grind = 0;
  321. $rune->substat_2 = $r["substat_2"];
  322. $rune->substat_2_value = $r["substat_2_value"];
  323. $rune->substat_2_enchant = 0;
  324. $rune->substat_2_grind = 0;
  325. $rune->substat_3 = $r["substat_3"];
  326. $rune->substat_3_value = $r["substat_3_value"];
  327. $rune->substat_3_enchant = 0;
  328. $rune->substat_3_grind = 0;
  329. $rune->substat_4 = $r["substat_4"];
  330. $rune->substat_4_value = $r["substat_4_value"];
  331. $rune->substat_4_enchant = 0;
  332. $rune->substat_4_grind = 0;
  333. $rune->refresh_names();
  334. }
  335. array_push($this->rune, $rune);
  336. }
  337. }
  338. }
  339. ?>