Run.php 9.7 KB

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