Run.php 13 KB

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