Run.php 11 KB

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