Run.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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 int Reward guild points.
  73. */
  74. public $guild_points;
  75. /**
  76. * @var bool Indicates if a frind/mentor helped.
  77. */
  78. public $helper;
  79. /**
  80. * @var int Score in battles that are rated (WB, rift dungeons...).
  81. */
  82. public $score;
  83. /**
  84. * @var String Rank in battles that are rated (WB, rift dungeons...).
  85. */
  86. public $rank;
  87. /**
  88. * @var \Unit[]|\K_Unit[] Uits used.
  89. * If the unit is still owned, it will be a instance of Unit.
  90. * If not, it will be a instance of K_Unit.
  91. */
  92. public $party = [];
  93. /**
  94. * @var int ID of the leader unit.
  95. */
  96. public $leader;
  97. /**
  98. * @var int[] List of IDs of the frontline units.
  99. */
  100. public $frontline = [];
  101. /**
  102. * @var \Inventory[] Dropped items.
  103. */
  104. public $item = [];
  105. /**
  106. * @var \K_Unit[] Units dropped.
  107. */
  108. public $unit = [];
  109. /**
  110. * @var int K_Unit[] Units whose secret dungeons were found on the run.
  111. */
  112. public $sd= [];
  113. /**
  114. * @var mixed[] List of dropped summon pieces.
  115. *
  116. * Formated as:
  117. * [@{see K_Unit}, amount]
  118. */
  119. public $unit_piece = [];
  120. /**
  121. * @var int Number of shapeshifting stones dropped;
  122. */
  123. public $shapeshifting = 0;
  124. /**
  125. * @var \Rune[] List of Runes dropped.
  126. */
  127. public $rune= [];
  128. /**
  129. * Constructor.
  130. *
  131. * Searches the database and retrieves the information about the
  132. * run, populating it and it's items.
  133. *
  134. * @param int $id Run identifier.
  135. * @global resource Database connection.
  136. */
  137. public function __construct($id){
  138. global $db;
  139. $s = "
  140. SELECT
  141. id,
  142. uid,
  143. dtime,
  144. area_type,
  145. area,
  146. stage,
  147. difficulty,
  148. win,
  149. time,
  150. mana,
  151. energy,
  152. crystal,
  153. guild_points,
  154. helper,
  155. score,
  156. rank
  157. FROM run
  158. WHERE id = $id;
  159. ";
  160. $q = $db->query($s);
  161. $r = $q->fetchArray(SQLITE3_ASSOC);
  162. $this->id = $r["id"];
  163. $this->uid = $r["uid"];
  164. $this->dtime = $r["dtime"];
  165. $this->area = new K_Area($r["area"], $r["area_type"]);
  166. $this->stage = $r["stage"];
  167. $this->difficulty = $r["difficulty"];
  168. $this->win = $r["win"];
  169. $this->time = $r["time"];
  170. $this->mana = $r["mana"];
  171. $this->energy = $r["energy"];
  172. $this->crystal = $r["crystal"];
  173. $this->guild_points = $r["guild_points"];
  174. $this->helper = $r["helper"];
  175. $this->score = $r["score"];
  176. $this->rank = $r["rank"];
  177. $s = "
  178. SELECT
  179. unit,
  180. k_unit,
  181. (SELECT count(id) FROM unit WHERE unit.id = run_party.unit) AS owned,
  182. leader,
  183. front
  184. FROM run_party
  185. WHERE run = $id
  186. ORDER BY
  187. front DESC,
  188. leader DESC;
  189. ";
  190. $q = $db->query($s);
  191. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  192. if ($r["owned"] > 0){
  193. array_push($this->party, new Unit($r["unit"], false));
  194. }
  195. else{
  196. array_push($this->party, new K_Unit($r["k_unit"], false));
  197. }
  198. if ($r["leader"] == 1){
  199. $this->leader = $r["unit"];
  200. }
  201. if ($r["front"] == 1){
  202. array_push($this->frontline, $r["unit"]);
  203. }
  204. }
  205. $s = "
  206. SELECT
  207. item,
  208. amount
  209. FROM run_drop_item
  210. WHERE run = $this->id;
  211. ";
  212. $q = $db->query($s);
  213. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  214. $i = new Inventory($r["item"]);
  215. $i->amount = $r["amount"];
  216. array_push($this->item, $i);
  217. }
  218. $s = "
  219. SELECT unit
  220. FROM run_drop_unit
  221. WHERE run = $this->id;
  222. ";
  223. $q = $db->query($s);
  224. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  225. array_push($this->unit, new K_Unit($r["unit"]));
  226. }
  227. $s = "
  228. SELECT unit
  229. FROM run_drop_sd
  230. WHERE run = $this->id;
  231. ";
  232. $q = $db->query($s);
  233. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  234. array_push($this->sd, new K_Unit($r["unit"]));
  235. }
  236. $s = "
  237. SELECT
  238. unit,
  239. amount
  240. FROM run_drop_unit_pieces
  241. WHERE run = $this->id;
  242. ";
  243. $q = $db->query($s);
  244. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  245. $i = [
  246. "unit" => new K_Unit($r["unit"]),
  247. "amount" => $r["amount"]
  248. ];
  249. array_push($this->unit_piece, $i);
  250. }
  251. $s = "
  252. SELECT amount
  253. FROM run_drop_shapeshifting
  254. WHERE run = $this->id;
  255. ";
  256. $q = $db->query($s);
  257. $r = $q->fetchArray(SQLITE3_ASSOC);
  258. if ($r){
  259. $this->shapeshifting = $r["amount"];
  260. }
  261. $s = "
  262. SELECT
  263. id,
  264. type,
  265. slot,
  266. stars,
  267. ancient,
  268. quality,
  269. value,
  270. efficiency,
  271. main_stat,
  272. main_stat_value,
  273. innate_stat,
  274. innate_stat_value,
  275. substat_1,
  276. substat_1_value,
  277. substat_2,
  278. substat_2_value,
  279. substat_3,
  280. substat_3_value,
  281. substat_4,
  282. substat_4_value
  283. FROM run_drop_rune
  284. WHERE run = $this->id;
  285. ";
  286. $q = $db->query($s);
  287. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  288. $rune = new Rune($r["id"]);
  289. if (!isset($rune->id)){
  290. $rune->id = $r["id"];
  291. $rune->level = 0;
  292. $rune->assigned_to = null;
  293. $rune->type = new K_Rune_Set($r["type"]);
  294. $rune->slot = $r["slot"];
  295. $rune->stars = $r["stars"];
  296. $rune->ancient = $r["ancient"];
  297. $rune->quality = $r["quality"];
  298. $rune->original_quality = $r["quality"];
  299. $rune->value = $r["value"];
  300. $rune->value = 0;
  301. $rune->efficiency = $r["efficiency"];
  302. // TODO: Calculate?
  303. $rune->max_efficiency = $r["efficiency"];
  304. $rune->main_stat = $r["main_stat"];
  305. $rune->main_stat_value = $r["main_stat_value"];
  306. $rune->innate_stat = $r["innate_stat"];
  307. $rune->innate_stat_value = $r["innate_stat_value"];
  308. $rune->substat_1 = $r["substat_1"];
  309. $rune->substat_1_value = $r["substat_1_value"];
  310. $rune->substat_1_enchant = 0;
  311. $rune->substat_1_grind = 0;
  312. $rune->substat_2 = $r["substat_2"];
  313. $rune->substat_2_value = $r["substat_2_value"];
  314. $rune->substat_2_enchant = 0;
  315. $rune->substat_2_grind = 0;
  316. $rune->substat_3 = $r["substat_3"];
  317. $rune->substat_3_value = $r["substat_3_value"];
  318. $rune->substat_3_enchant = 0;
  319. $rune->substat_3_grind = 0;
  320. $rune->substat_4 = $r["substat_4"];
  321. $rune->substat_4_value = $r["substat_4_value"];
  322. $rune->substat_4_enchant = 0;
  323. $rune->substat_4_grind = 0;
  324. $rune->refresh_names();
  325. }
  326. array_push($this->rune, $rune);
  327. }
  328. }
  329. }
  330. ?>