Player.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <?php
  2. /**
  3. * Player 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 . "Building.php");
  15. require_once(PATH::ENTITY . "Decoration.php");
  16. require_once(PATH::ENTITY . "Inventory.php");
  17. require_once(PATH::ENTITY . "Record.php");
  18. /**
  19. * A Unit.
  20. *
  21. * Represents an object from the table 'unit'.
  22. *
  23. * @category Entity
  24. */
  25. class Player extends Entity{
  26. /**
  27. * @var int Player ID.
  28. */
  29. public $uid;
  30. /**
  31. * @var int Player level.
  32. */
  33. public $level;
  34. /**
  35. * @var string Player name.
  36. */
  37. public $name;
  38. /**
  39. * @var string Player country (XX).
  40. */
  41. public $country;
  42. /**
  43. * @var int Total experience.
  44. */
  45. public $experience;
  46. /**
  47. * @var Unit Representative Unit.
  48. */
  49. public $rep;
  50. /**
  51. * @var int Timestamp of player registration.
  52. */
  53. public $joined = 0;
  54. /**
  55. * @var int Top rank in arena.
  56. */
  57. public $top_rank_arena = 0;
  58. /**
  59. * @var int Top rank in world arena.
  60. */
  61. public $top_rank_world_arena = 0;
  62. /**
  63. * @var int Top rank in special league.
  64. */
  65. public $top_rank_special_league = 0;
  66. /**
  67. * @var int Top rank in guild war.
  68. */
  69. public $top_rank_gw = 0;
  70. /**
  71. * @var int Top rank in guild siege.
  72. */
  73. public $top_rank_siege = 0;
  74. /**
  75. * @var int Top rank in World Boss.
  76. */
  77. public $top_rank_wboss = 0;
  78. /**
  79. * @var int Top rank in TOA normal.
  80. */
  81. public $top_rank_toan = 0;
  82. /**
  83. * @var int Top rank in TOA HARD.
  84. */
  85. public $top_rank_toah = 0;
  86. /**
  87. * @var \Unit[] Units in Arena defense.
  88. */
  89. public $defense = [];
  90. /**
  91. * @var \Unit[] Units in Arena defense.
  92. */
  93. public $gw_defense = [[], []];
  94. /**
  95. * @var int[] Currency.
  96. */
  97. public $currency = [
  98. "mana" => 0,
  99. "crystal" => 0,
  100. "energy" => 0,
  101. "energy_max" => 0,
  102. "arena_energy" => 0,
  103. "arena_energy_max" => 0,
  104. "darkportal_energy" => 0,
  105. "darkportal_energy_max" => 0,
  106. "dimension_energy" => 0,
  107. "dimension_energy_max" => 0,
  108. "honor_point" => 0,
  109. "guild_point" => 0,
  110. "honor_medal" => 0,
  111. "honor_mark" => 0,
  112. "event_coin" => 0,
  113. "social_point" => 0,
  114. "ancient_stone" => 0,
  115. "costume_point" => 0,
  116. ];
  117. /**
  118. * @var \Building[] List of Buildings.
  119. */
  120. public $building = [];
  121. /**
  122. * @var \Decoration[] List of Decorations.
  123. */
  124. public $decoration = [];
  125. /**
  126. * @var \Inventory[] List of Scrolls in Inventory.
  127. */
  128. public $inventory_scroll = [];
  129. /**
  130. * @var \Inventory[] List of rune crafting items in Inventory.
  131. */
  132. public $inventory_craft_rune = [];
  133. /**
  134. * @var \Inventory[] List of rune crafting items in Inventory.
  135. */
  136. public $inventory_craft = [];
  137. /**
  138. * @var \Inventory[] List of rune crafting items in Inventory.
  139. */
  140. public $inventory_essence = [];
  141. /**
  142. * @var \Record[] Player record runs.
  143. */
  144. public $record = [];
  145. /**
  146. * Constructor.
  147. *
  148. * Searches the database and retrieves the information about the
  149. * player, populating it and it's items.
  150. *
  151. * @param int $id Monster identifier.
  152. * @param bool $complete If false, query only monster and k_monster.
  153. * @global int Player ID.
  154. * @global resource Database connection.
  155. */
  156. public function __construct($id, $complete = true){
  157. global $UID;
  158. global $db;
  159. $s = "
  160. SELECT
  161. uid,
  162. name,
  163. level,
  164. country,
  165. experience,
  166. rep,
  167. mana,
  168. crystal,
  169. energy,
  170. energy_max,
  171. arena_energy,
  172. arena_energy_max,
  173. darkportal_energy,
  174. darkportal_energy_max,
  175. dimension_energy,
  176. dimension_energy_max,
  177. honor_point,
  178. guild_point,
  179. honor_medal,
  180. honor_mark,
  181. event_coin,
  182. social_point,
  183. costume_point,
  184. joined,
  185. top_rank_arena,
  186. top_rank_world_arena,
  187. top_rank_special_league,
  188. top_rank_gw,
  189. top_rank_siege,
  190. top_rank_wboss,
  191. top_rank_toan,
  192. top_rank_toah
  193. FROM player
  194. WHERE uid = '$UID';
  195. ";
  196. $q = $db->query($s);
  197. $r = $q->fetchArray(SQLITE3_ASSOC);
  198. if ($r){
  199. $this->uid = $r["uid"];
  200. $this->name = $r["name"];
  201. $this->level = $r["level"];
  202. $this->country = $r["country"];
  203. $this->experience = $r["experience"];
  204. if (strlen($r["rep"]) > 0){
  205. $this->rep = new Unit($r["rep"]);
  206. }
  207. $this->currency["mana"] = $r["mana"];
  208. $this->currency["crystal"] = $r["crystal"];
  209. $this->currency["energy"] = $r["energy"];
  210. $this->currency["energy_max"] = $r["energy_max"];
  211. $this->currency["arena_energy"] = $r["arena_energy"];
  212. $this->currency["arena_energy_max"] = $r["arena_energy_max"];
  213. $this->currency["darkportal_energy"] = $r["darkportal_energy"];
  214. $this->currency["darkportal_energy_max"] = $r["darkportal_energy_max"];
  215. $this->currency["dimension_energy"] = $r["dimension_energy"];
  216. $this->currency["dimension_energy_max"] = $r["dimension_energy_max"];
  217. $this->currency["honor_point"] = $r["honor_point"];
  218. $this->currency["guild_point"] = $r["guild_point"];
  219. $this->currency["honor_medal"] = $r["honor_medal"];
  220. $this->currency["honor_mark"] = $r["honor_mark"];
  221. $this->currency["event_coin"] = $r["event_coin"];
  222. $this->currency["social_point"] = $r["social_point"];
  223. $this->currency["costume_point"] = $r["costume_point"];
  224. $this->joined = $r["joined"];
  225. $this->top_rank_arena = $r["top_rank_arena"];
  226. $this->top_rank_world_arena = $r["top_rank_world_arena"];
  227. $this->top_rank_special_league = $r["top_rank_special_league"];
  228. $this->top_rank_gw = $r["top_rank_gw"];
  229. $this->top_rank_siege = $r["top_rank_siege"];
  230. $this->top_rank_wboss = $r["top_rank_wboss"];
  231. $this->top_rank_toan = $r["top_rank_toan"];
  232. $this->top_rank_toah = $r["top_rank_toah"];
  233. }
  234. $s = "
  235. SELECT unit
  236. FROM defense
  237. WHERE uid = '$UID'
  238. ORDER BY position;
  239. ";
  240. $q = $db->query($s);
  241. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  242. array_push($this->defense, new Unit($r["unit"], false));
  243. }
  244. $s = "
  245. SELECT
  246. unit,
  247. position
  248. FROM gw_defense
  249. WHERE uid = '$UID'
  250. ORDER BY position;
  251. ";
  252. $q = $db->query($s);
  253. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  254. if ($r["position"] <= 3){
  255. array_push($this->gw_defense[0], new Unit($r["unit"], false));
  256. }
  257. else{
  258. array_push($this->gw_defense[1], new Unit($r["unit"], false));
  259. }
  260. }
  261. $s = "
  262. SELECT
  263. building.id,
  264. min(building)
  265. FROM
  266. building,
  267. k_building
  268. WHERE
  269. uid = '$UID' AND
  270. building.building = k_building.id
  271. GROUP BY building.building;
  272. ";
  273. $q = $db->query($s);
  274. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  275. array_push($this->building, new Building($r["id"]));
  276. }
  277. $s = "
  278. SELECT id
  279. FROM decoration
  280. WHERE uid = '$UID';
  281. ";
  282. $q = $db->query($s);
  283. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  284. array_push($this->decoration, new Decoration($r["id"]));
  285. }
  286. $s = "
  287. SELECT
  288. id,
  289. type
  290. FROM inventory
  291. WHERE
  292. uid = '$UID' AND
  293. type = " . INVENTORY_TYPE_ID::SCROLL . " AND
  294. amount > 0
  295. ORDER BY inventory.type;
  296. ";
  297. $q = $db->query($s);
  298. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  299. array_push($this->inventory_scroll, new Inventory($r["id"], $r["type"]));
  300. }
  301. // Rune crafting items are marked as generic crafting.
  302. $s = "
  303. SELECT
  304. inventory.id AS id,
  305. inventory.type AS type
  306. FROM
  307. inventory
  308. WHERE
  309. inventory.uid = '$UID' AND
  310. inventory.type = " . INVENTORY_TYPE_ID::RUNE_CRAFT . " AND
  311. amount > 0
  312. ORDER BY inventory.id;
  313. ";
  314. $q = $db->query($s);
  315. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  316. array_push($this->inventory_craft_rune, new Inventory($r["id"], $r["type"]));
  317. }
  318. $s = "
  319. SELECT
  320. inventory.id AS id,
  321. inventory.type AS type
  322. FROM
  323. inventory
  324. WHERE
  325. inventory.uid = '$UID' AND
  326. inventory.type = " . INVENTORY_TYPE_ID::CRAFT_STUFF . " AND
  327. amount > 0
  328. ORDER BY inventory.id;
  329. ";
  330. $q = $db->query($s);
  331. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  332. array_push($this->inventory_craft, new Inventory($r["id"], $r["type"]));
  333. }
  334. $s = "
  335. SELECT
  336. inventory.id AS id,
  337. inventory.type AS type
  338. FROM
  339. inventory,
  340. k_inventory
  341. WHERE
  342. inventory.id = k_inventory.id AND
  343. inventory.type = k_inventory.type AND
  344. inventory.uid = '$UID' AND
  345. inventory.type = " . INVENTORY_TYPE_ID::ESSENCES . " AND
  346. amount > 0
  347. ORDER BY
  348. upper(name) NOT LIKE '%MAGIC%',
  349. upper(name) NOT LIKE '%FIRE%',
  350. upper(name) NOT LIKE '%WATER%',
  351. upper(name) NOT LIKE '%WIND%',
  352. upper(name) NOT LIKE '%LIGHT%',
  353. upper(name) NOT LIKE '%DARK%',
  354. upper(name) NOT LIKE '%LOW%',
  355. upper(name) NOT LIKE '%MID%',
  356. upper(name) NOT LIKE '%HIGH%'
  357. ;
  358. ";
  359. $q = $db->query($s);
  360. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  361. array_push($this->inventory_essence, new Inventory($r["id"], $r["type"]));
  362. }
  363. $s = "
  364. SELECT
  365. uid,
  366. area_type,
  367. area
  368. FROM record
  369. WHERE uid = '$UID'
  370. ORDER BY
  371. CASE
  372. WHEN (area_type = 2 AND area = 8001) THEN 1 -- Giant's Keep
  373. WHEN (area_type = 2 AND area = 9001) THEN 2 -- Dragon's Lair
  374. WHEN (area_type = 2 AND area = 6001) THEN 3 -- Necropolis
  375. WHEN (area_type = 2 AND area = 9501) THEN 4 -- Steel Fortress
  376. WHEN (area_type = 2 AND area = 9502) THEN 5 -- Punisher's Crypt
  377. WHEN (area_type = 4) THEN 6 -- Rift of Worlds
  378. WHEN (area_type = 3 AND area = 1001) THEN 7 -- Rift Dungeon - Ice Beast
  379. WHEN (area_type = 3 AND area = 2001) THEN 8 -- Rift Dungeon - Fire Beast
  380. WHEN (area_type = 3 AND area = 3001) THEN 9 -- Rift Dungeon - Wind Beast
  381. WHEN (area_type = 3 AND area = 4001) THEN 10 -- Rift Dungeon - Light Beast
  382. WHEN (area_type = 3 AND area = 5001) THEN 11 -- Rift Dungeon - Dark Beast
  383. WHEN (area_type = 2 AND area = 5001) THEN 12 -- Hall of Magic
  384. WHEN (area_type = 2 AND area = 3001) THEN 13 -- Hall of Water
  385. WHEN (area_type = 2 AND area = 2001) THEN 14 -- Hall of Fire
  386. WHEN (area_type = 2 AND area = 4001) THEN 15 -- Hall of Wind
  387. WHEN (area_type = 2 AND area = 7001) THEN 16 -- Hall of Light
  388. WHEN (area_type = 2 AND area = 1001) THEN 17 -- Hall of Dark
  389. ELSE area
  390. END ASC
  391. ";
  392. $q = $db->query($s);
  393. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  394. array_push($this->record, new Record($r["uid"], $r["area_type"], $r["area"]));
  395. }
  396. }
  397. }
  398. ?>