Player.php 16 KB

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