Run.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <?php
  2. /**
  3. * Saved run entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @category Entity
  8. */
  9. // TODO: Replace in_array for property_exists
  10. /**
  11. * Require dependent entities if not present.
  12. */
  13. require_once(PATH::ENTITY . "Entity.php");
  14. require_once(PATH::ENTITY . "Unit.php");
  15. require_once(PATH::ENTITY . "K_Unit.php");
  16. require_once(PATH::ENTITY . "Rune.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;
  64. /**
  65. * @var int Reward energy.
  66. */
  67. public $energy;
  68. /**
  69. * @var int Reward crystal.
  70. */
  71. public $crystal;
  72. /**
  73. * @var bool Indicates if a frind/mentor helped.
  74. */
  75. public $helper;
  76. /**
  77. * @var \Unit[]|\K_Unit[] Uits used.
  78. * If the unit is still owned, it will be a instance of Unit.
  79. * If not, it will be a instance of K_Unit.
  80. */
  81. public $party = [];
  82. /**
  83. * @var \Inventory[] Dropped items.
  84. */
  85. public $item = [];
  86. /**
  87. * @var \K_Unit[] Units dropped.
  88. */
  89. public $unit = [];
  90. /**
  91. * @var int K_Unit[] Units whose secret dungeons were found on the run.
  92. */
  93. public $sd= [];
  94. /**
  95. * @var mixed[] List of dropped summon pieces.
  96. *
  97. * Formated as:
  98. * [@{see K_Unit}, amount]
  99. */
  100. public $unit_piece = [];
  101. /**
  102. * @var int Number of shapeshifting stones dropped;
  103. */
  104. public $shapeshifting = 0;
  105. /**
  106. * @var \Rune[] List of Runes dropped.
  107. */
  108. public $rune= [];
  109. /**
  110. * Constructor.
  111. *
  112. * Searches the database and retrieves the information about the
  113. * run, populating it and it's items.
  114. *
  115. * @param resource $db Connection to the database.
  116. * @param int $id Run identifier.
  117. */
  118. public function __construct($db, $id){
  119. parent::__construct($db);
  120. $s = "
  121. SELECT
  122. id,
  123. uid,
  124. dtime,
  125. area,
  126. stage,
  127. difficulty,
  128. win,
  129. time,
  130. mana,
  131. energy,
  132. crystal,
  133. helper
  134. FROM run
  135. WHERE id = $id;
  136. ";
  137. $q = $this->db->query($s);
  138. $r = $q->fetchArray(SQLITE3_ASSOC);
  139. $this->id = $r["id"];
  140. $this->uid = $r["uid"];
  141. $this->dtime = $r["dtime"];
  142. $type = 0;
  143. if (in_array($r["area"], $RAID_RIFT_DUNGEON) && $r["stage"] < 1){
  144. $type = AREA_TYPE::RIFT_RAID_DUNGEON;
  145. }
  146. elseif (in_array($r["area"], $SCENARIO)){
  147. $type = AREA_TYPE::SCENARIO;
  148. }
  149. elseif (in_array($r["area"], $ELEMENTAL_RIFT_DUNGEON) && $r["stage"] < 1){
  150. $type = AREA_TYPE::ELEMENTAL_RIFT_DUNGEON;
  151. }
  152. elseif (in_array($r["area"], $DUNGEON)){
  153. $type = AREA_TYPE::CAIROS_DUNGEON;
  154. }
  155. $this->area = new K_Area($this->db, $r["area"], $type);
  156. $this->stage = $r["stage"];
  157. $this->difficulty = $r["difficulty"];
  158. $this->win = $r["win"];
  159. $this->time = $r["time"];
  160. $this->mana = $r["mana"];
  161. $this->energy = $r["energy"];
  162. $this->crystal = $r["crystal"];
  163. $this->helper = $r["helper"];
  164. $s = "
  165. SELECT
  166. unit,
  167. k_unit,
  168. (SELECT count(id) FROM unit WHERE unit.unit = k_unit) AS owned
  169. FROM run_party
  170. WHERE run = $id;
  171. ";
  172. $q = $this->db->query($s);
  173. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  174. if ($r["owned"] > 0){
  175. array_push($this->party, new Unit($this->db, $r["unit"], false));
  176. }
  177. else{
  178. array_push($this->party, new K_Unit($this->db, $r["k_unit"], false));
  179. }
  180. }
  181. $s = "
  182. SELECT
  183. item,
  184. amount
  185. FROM run_drop_item
  186. WHERE run = $this->id;
  187. ";
  188. $q = $this->db->query($s);
  189. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  190. $i = new Inventory($this->db, $r["item"]);
  191. $i->amount = $r["amount"];
  192. array_push($this->item, $i);
  193. }
  194. $s = "
  195. SELECT unit
  196. FROM run_drop_unit
  197. WHERE run = $this->id;
  198. ";
  199. $q = $this->db->query($s);
  200. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  201. array_push($this->unit, new K_Unit($this->db, $r["unit"]));
  202. }
  203. $s = "
  204. SELECT unit
  205. FROM run_drop_sd
  206. WHERE run = $this->id;
  207. ";
  208. $q = $this->db->query($s);
  209. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  210. array_push($this->sd, new K_Unit($this->db, $r["unit"]));
  211. }
  212. $s = "
  213. SELECT
  214. unit,
  215. amount
  216. FROM run_drop_unit_pieces
  217. WHERE run = $this->id;
  218. ";
  219. $q = $this->db->query($s);
  220. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  221. $i = [
  222. "unit" => new K_Unit($this->db, $r["unit"]),
  223. "amount" => $r["amount"]
  224. ];
  225. array_push($this->unit_piece, $i);
  226. }
  227. $s = "
  228. SELECT amount
  229. FROM run_drop_shapeshifting
  230. WHERE run = $this->id;
  231. ";
  232. $q = $this->db->query($s);
  233. $r = $q->fetchArray(SQLITE3_ASSOC);
  234. if ($r){
  235. $this->shapeshifting = $r["amount"];
  236. }
  237. $s = "
  238. SELECT
  239. id,
  240. type,
  241. slot,
  242. stars,
  243. ancient,
  244. quality,
  245. value,
  246. efficiency,
  247. main_stat,
  248. main_stat_value,
  249. innate_stat,
  250. innate_stat_value,
  251. substat_1,
  252. substat_1_value,
  253. substat_2,
  254. substat_2_value,
  255. substat_3,
  256. substat_3_value,
  257. substat_4,
  258. substat_4_value
  259. FROM run_drop_rune
  260. WHERE run = $this->id;
  261. ";
  262. $q = $this->db->query($s);
  263. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  264. $rune = new Rune($this->db, $r["id"]);
  265. if (!isset($rune->id)){
  266. $rune->id = $r["id"];
  267. $rune->assigned_to = null;
  268. $rune->type = new K_Rune_Set($this->db, $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. ?>