Player.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. <?php
  2. /**
  3. * Player entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. require_once(PATH::ENTITY . "Entity.php");
  12. require_once(PATH::ENTITY . "Unit.php");
  13. require_once(PATH::ENTITY . "Building.php");
  14. require_once(PATH::ENTITY . "Decoration.php");
  15. require_once(PATH::ENTITY . "Item.php");
  16. require_once(PATH::ENTITY . "Record.php");
  17. require_once(PATH::ENTITY . "Server.php");
  18. /**
  19. * A Player.
  20. *
  21. * Represents a game account.
  22. *
  23. * @category Entity
  24. */
  25. class Player extends Entity{
  26. /**
  27. * @var int User ID.
  28. */
  29. private $user;
  30. /**
  31. * @var int In-game player ID.
  32. */
  33. private $id;
  34. /**
  35. * @var int Account server ID.
  36. */
  37. private $server;
  38. /**
  39. * @var string Account country code.
  40. */
  41. private $country;
  42. /**
  43. * @var string Account language code.
  44. */
  45. private $language;
  46. /**
  47. * @var int Player level.
  48. */
  49. private $level;
  50. /**
  51. * @var string Player name.
  52. */
  53. private $name;
  54. /**
  55. * @var int Total experience.
  56. */
  57. private $experience;
  58. /**
  59. * @var Unit Player's representative unit.
  60. */
  61. private $rep;
  62. /**
  63. * @var int Player's representative unit ID.
  64. */
  65. private $rep_id;
  66. /**
  67. * @var DateTime Time the player joined the game.
  68. */
  69. private $joined = 0;
  70. /**
  71. * @var int Player's top rank in the Arena.
  72. * @see ARENA_RANK_ID
  73. */
  74. private $top_rank_arena = 0;
  75. /**
  76. * @var int Player's top rank in the World Arena.
  77. * @see ARENA_RANK_ID
  78. */
  79. private $top_rank_world_arena = 0;
  80. /**
  81. * @var int Player's top rank in the Special League.
  82. * @see ARENA_RANK_ID
  83. */
  84. private $top_rank_special_league = 0;
  85. /**
  86. * @var int Player's top rank in Guild War.
  87. * @see ARENA_RANK_ID
  88. */
  89. private $top_rank_gw = 0;
  90. /**
  91. * @var int Player's top rank in the Siege Battle.
  92. * @see ARENA_RANK_ID
  93. */
  94. private $top_rank_siege = 0;
  95. /**
  96. * @var int Player's top rank in World Boss
  97. * @see WORLD_BOSS_RANK_ID
  98. */
  99. private $top_rank_wboss = 0;
  100. /**
  101. * @var int Top floor reached in the Trial of Ascension Normal.
  102. */
  103. private $top_rank_toan = 0;
  104. /**
  105. * @var int Top floor reached in the Trial of Ascension Hard.
  106. */
  107. private $top_rank_toah = 0;
  108. /**
  109. * @var int Maximum stars achieved in the Trial of Ascension Hell.
  110. */
  111. private $top_rank_toal = 0;
  112. /**
  113. * @var bool Internal flag to chek if Arena, GW and Siege defenses have been read.
  114. */
  115. private $flag_defense = false;
  116. /**
  117. * @var Unit[] Arena defense.
  118. */
  119. private $arena_defense = [];
  120. /**
  121. * @var Unit[][] Guild War defenses.
  122. */
  123. private $gw_defense = [[], []];
  124. /**
  125. * @var Unit[] Siege defenses.
  126. * @todo Implement
  127. */
  128. private $siege_defense = [];
  129. /**
  130. * @var int[] Various currencies.
  131. */
  132. private $currency = [
  133. "mana" => 0,
  134. "crystal" => 0,
  135. "energy" => 0,
  136. "energy_max" => 0,
  137. "arena_energy" => 0,
  138. "darkportal_energy" => 0,
  139. "dimension_energy" => 0,
  140. "honor_point" => 0,
  141. "guild_point" => 0,
  142. "honor_medal" => 0,
  143. "honor_mark" => 0,
  144. "event_coin" => 0,
  145. "social_point" => 0,
  146. "ancient_stone" => 0,
  147. "costume_point" => 0,
  148. ];
  149. /**
  150. * @var bool Internal flag to check if the buildings and decorations have been loaded into the
  151. * entity.
  152. */
  153. private $flag_building = false;
  154. /**
  155. * @var Building[] Player's buildings.
  156. */
  157. private $building = [];
  158. /**
  159. * @var Decoration[] Player's decorations.
  160. */
  161. private $decoration = [];
  162. /**
  163. * @var bool Internal flags to check if various types of inventory items have been loaded into
  164. * the entity;
  165. */
  166. private $flag_item = false;
  167. /**
  168. * @var Item[] Player's scrolls.
  169. */
  170. private $item_scroll = [];
  171. /**
  172. * @var Item[] Player's rune craft materials..
  173. */
  174. private $item_craft_rune = [];
  175. /**
  176. * @var Item[] Player's craft materials.
  177. */
  178. private $item_craft = [];
  179. /**
  180. * @var Item[] Player's essences.
  181. */
  182. private $item_essence = [];
  183. /**
  184. * @var bool Internal flag to check if the player records have been loaded into the entity.
  185. */
  186. private $flag_record = false;
  187. /**
  188. * @var Record[] Player records.
  189. */
  190. private $record = [];
  191. /**
  192. * @var bool Indicates the profile visibility.
  193. */
  194. private $public = false;
  195. /**
  196. * Constructor.
  197. *
  198. * Searches the database and retrieves the information about the
  199. * player, populating it and it's items.
  200. *
  201. * @param int $id Player identifier.
  202. */
  203. public function __construct($id){
  204. $statement = get_context()->get_db()->prepare("
  205. SELECT
  206. user,
  207. id,
  208. server,
  209. country,
  210. lang,
  211. name,
  212. level,
  213. experience,
  214. rep,
  215. mana,
  216. crystal,
  217. energy,
  218. energy_max,
  219. arena_energy,
  220. darkportal_energy,
  221. dimension_energy,
  222. honor_point,
  223. guild_point,
  224. honor_medal,
  225. honor_mark,
  226. event_coin,
  227. social_point,
  228. costume_point,
  229. joined,
  230. top_rank_arena,
  231. top_rank_world_arena,
  232. top_rank_special_league,
  233. top_rank_gw,
  234. top_rank_siege,
  235. top_rank_wboss,
  236. top_rank_toan,
  237. top_rank_toah,
  238. top_rank_toal,
  239. public
  240. FROM player
  241. WHERE id = :id;
  242. ");
  243. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  244. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  245. if ($r){
  246. $this->user = $r["user"];
  247. $this->id = $r["id"];
  248. $this->server = new Server($r["server"]);
  249. $this->country = $r["country"];
  250. $this->lang = $r["lang"];
  251. $this->name = $r["name"];
  252. $this->level = $r["level"];
  253. $this->experience = $r["experience"];
  254. if (strlen($r["rep"]) > 0){
  255. $this->rep_id = $r["rep"];
  256. }
  257. $this->currency["mana"] = $r["mana"];
  258. $this->currency["crystal"] = $r["crystal"];
  259. $this->currency["energy"] = $r["energy"];
  260. $this->currency["energy_max"] = $r["energy_max"];
  261. $this->currency["arena_energy"] = $r["arena_energy"];
  262. $this->currency["darkportal_energy"] = $r["darkportal_energy"];
  263. $this->currency["dimension_energy"] = $r["dimension_energy"];
  264. $this->currency["honor_point"] = $r["honor_point"];
  265. $this->currency["guild_point"] = $r["guild_point"];
  266. $this->currency["honor_medal"] = $r["honor_medal"];
  267. $this->currency["honor_mark"] = $r["honor_mark"];
  268. $this->currency["event_coin"] = $r["event_coin"];
  269. $this->currency["social_point"] = $r["social_point"];
  270. $this->currency["costume_point"] = $r["costume_point"];
  271. $this->joined = new Datetime();
  272. $this->joined->setTimestamp($r["joined"]);
  273. $this->top_rank_arena = $r["top_rank_arena"];
  274. $this->top_rank_world_arena = $r["top_rank_world_arena"];
  275. $this->top_rank_special_league = $r["top_rank_special_league"];
  276. $this->top_rank_gw = $r["top_rank_gw"];
  277. $this->top_rank_siege = $r["top_rank_siege"];
  278. $this->top_rank_wboss = $r["top_rank_wboss"];
  279. $this->top_rank_toan = $r["top_rank_toan"];
  280. $this->top_rank_toah = $r["top_rank_toah"];
  281. $this->top_rank_toal = $r["top_rank_toal"];
  282. if (strlen($r["public"]) == 1){
  283. $this->public = true;
  284. }
  285. }
  286. }
  287. /**
  288. * Loads the defenses into the entity.
  289. *
  290. * Must be called only once before trying to get the units in Arena, Guild War or Siege
  291. * defenses. Sets the flag {@link Player:$flag_defenses} to true.
  292. */
  293. private function load_defenses(){
  294. $statement = get_context()->get_db()->prepare("
  295. SELECT unit
  296. FROM defense
  297. WHERE
  298. player = :player AND
  299. area_type = :area_type
  300. ORDER BY position;
  301. ");
  302. $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
  303. $statement->bindValue(':area_type', AREA_TYPE_ID::ARENA, SQLITE3_INTEGER);
  304. $q = $statement->execute();
  305. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  306. array_push($this->arena_defense, new Unit($r["unit"], false));
  307. }
  308. $statement = get_context()->get_db()->prepare("
  309. SELECT
  310. unit,
  311. position
  312. FROM defense
  313. WHERE
  314. player = :player AND
  315. area_type = :area_type
  316. ORDER BY position;
  317. ");
  318. $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
  319. $statement->bindValue(':area_type', AREA_TYPE_ID::GUILD_WAR, SQLITE3_INTEGER);
  320. $q = $statement->execute();
  321. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  322. if ($r["position"] <= 3){
  323. array_push($this->gw_defense[0], new Unit($r["unit"], false));
  324. }
  325. else{
  326. array_push($this->gw_defense[1], new Unit($r["unit"], false));
  327. }
  328. }
  329. // TODO: Siege defenses
  330. $this->flag_defense = true;
  331. }
  332. /**
  333. * Loads buildings and decorations into the entity.
  334. *
  335. * Must be called only once before trying to get the buildings or decorations. Sets the flag
  336. * {@link Player:$flag_defenses} to true.
  337. */
  338. private function load_buildings(){
  339. $statement = get_context()->get_db()->prepare("
  340. SELECT
  341. building.id AS id,
  342. min(building.buildable) AS min
  343. FROM
  344. building,
  345. buildable
  346. WHERE
  347. player = :player AND
  348. building.buildable = buildable.id
  349. GROUP BY building.buildable;
  350. ");
  351. $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
  352. $q = $statement->execute();
  353. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  354. array_push($this->building, new Building($r["id"]));
  355. }
  356. $statement = get_context()->get_db()->prepare("
  357. SELECT id
  358. FROM decoration
  359. WHERE player = :player;
  360. ");
  361. $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
  362. $q = $statement->execute();
  363. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  364. array_push($this->decoration, new Decoration($r["id"]));
  365. }
  366. $this->flag_building = true;
  367. }
  368. /**
  369. * Loads items into the entity.
  370. *
  371. * Must be called only once before trying to get any of the items in the inventory. Sets the
  372. * flag {@link Player:$flag_defenses} to true.
  373. */
  374. private function load_items(){
  375. $statement = get_context()->get_db()->prepare("
  376. SELECT
  377. id,
  378. type
  379. FROM item
  380. WHERE
  381. player = :player AND
  382. type = :type AND
  383. amount > 0
  384. ORDER BY item.type;
  385. ");
  386. $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
  387. $statement->bindValue(':type', INVENTORY_TYPE_ID::SCROLL, SQLITE3_TEXT);
  388. $q = $statement->execute();
  389. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  390. array_push($this->item_scroll, new Item($this->id, $r["id"], $r["type"]));
  391. }
  392. // Rune crafting items are marked as generic crafting.
  393. $statement = get_context()->get_db()->prepare("
  394. SELECT
  395. id,
  396. type
  397. FROM item
  398. WHERE
  399. player = :player AND
  400. type = :type AND
  401. amount > 0
  402. ORDER BY id;
  403. ");
  404. $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
  405. $statement->bindValue(':type', INVENTORY_TYPE_ID::ENCHANTMENT, SQLITE3_TEXT);
  406. $q = $statement->execute();
  407. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  408. array_push($this->item_craft_rune, new Item($this->id, $r["id"], $r["type"]));
  409. }
  410. $statement = get_context()->get_db()->prepare("
  411. SELECT
  412. id,
  413. type
  414. FROM item
  415. WHERE
  416. player = :player AND
  417. type = :type AND
  418. amount > 0
  419. ORDER BY id;
  420. ");
  421. $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
  422. $statement->bindValue(':type', INVENTORY_TYPE_ID::CRAFT_STUFF, SQLITE3_TEXT);
  423. $q = $statement->execute();
  424. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  425. array_push($this->item_craft, new Item($this->id, $r["id"], $r["type"]));
  426. }
  427. $statement = get_context()->get_db()->prepare("
  428. SELECT
  429. item.id AS id,
  430. item.type AS type
  431. FROM
  432. item,
  433. inventory
  434. WHERE
  435. item.id = inventory.id AND
  436. item.type = inventory.type AND
  437. item.player = :player AND
  438. item.type = :type AND
  439. amount > 0
  440. ORDER BY
  441. upper(inventory.name) NOT LIKE '%MAGIC%',
  442. upper(inventory.name) NOT LIKE '%FIRE%',
  443. upper(inventory.name) NOT LIKE '%WATER%',
  444. upper(inventory.name) NOT LIKE '%WIND%',
  445. upper(inventory.name) NOT LIKE '%LIGHT%',
  446. upper(inventory.name) NOT LIKE '%DARK%',
  447. upper(inventory.name) NOT LIKE '%LOW%',
  448. upper(inventory.name) NOT LIKE '%MID%',
  449. upper(inventory.name) NOT LIKE '%HIGH%'
  450. ;
  451. ");
  452. $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
  453. $statement->bindValue(':type', INVENTORY_TYPE_ID::ESSENCES, SQLITE3_TEXT);
  454. $q = $statement->execute();
  455. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  456. array_push($this->item_essence, new Item($this->id, $r["id"], $r["type"]));
  457. }
  458. $this->flag_item = true;
  459. }
  460. /**
  461. * Loads the records into the entity.
  462. *
  463. * Must be called only once before trying to get records. Sets the flag
  464. * {@link Player:$flag_defenses} to true.
  465. */
  466. private function load_records(){
  467. $statement = get_context()->get_db()->prepare("
  468. SELECT
  469. player,
  470. area_type,
  471. area
  472. FROM record
  473. WHERE player = :player
  474. ORDER BY
  475. CASE
  476. WHEN (area_type = 2 AND area = 8001) THEN 1 -- Giant's Keep
  477. WHEN (area_type = 2 AND area = 9001) THEN 2 -- Dragon's Lair
  478. WHEN (area_type = 2 AND area = 6001) THEN 3 -- Necropolis
  479. WHEN (area_type = 2 AND area = 9501) THEN 4 -- Steel Fortress
  480. WHEN (area_type = 2 AND area = 9502) THEN 5 -- Punisher's Crypt
  481. WHEN (area_type = 4) THEN 6 -- Rift of Worlds
  482. WHEN (area_type = 3 AND area = 1001) THEN 7 -- Rift Dungeon - Ice Beast
  483. WHEN (area_type = 3 AND area = 2001) THEN 8 -- Rift Dungeon - Fire Beast
  484. WHEN (area_type = 3 AND area = 3001) THEN 9 -- Rift Dungeon - Wind Beast
  485. WHEN (area_type = 3 AND area = 4001) THEN 10 -- Rift Dungeon - Light Beast
  486. WHEN (area_type = 3 AND area = 5001) THEN 11 -- Rift Dungeon - Dark Beast
  487. WHEN (area_type = 2 AND area = 5001) THEN 12 -- Hall of Magic
  488. WHEN (area_type = 2 AND area = 3001) THEN 13 -- Hall of Water
  489. WHEN (area_type = 2 AND area = 2001) THEN 14 -- Hall of Fire
  490. WHEN (area_type = 2 AND area = 4001) THEN 15 -- Hall of Wind
  491. WHEN (area_type = 2 AND area = 7001) THEN 16 -- Hall of Light
  492. WHEN (area_type = 2 AND area = 1001) THEN 17 -- Hall of Dark
  493. ELSE area
  494. END ASC
  495. ");
  496. $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
  497. $q = $statement->execute();
  498. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  499. array_push($this->record, new Record($r["player"], $r["area_type"], $r["area"]));
  500. }
  501. $this->flag_record = true;
  502. }
  503. /**
  504. * Retrieves the user identifier
  505. *
  506. * @return int User ID.
  507. */
  508. public function get_user(){
  509. return $this->user;
  510. }
  511. /**
  512. * Retrieves the player identifier
  513. *
  514. * @return int Player ID.
  515. */
  516. public function get_id(){
  517. return $this->id;
  518. }
  519. /**
  520. * Retrieves the player server.
  521. *
  522. * @return Server The player's account server.
  523. */
  524. public function get_server(){
  525. return $this->server;
  526. }
  527. /**
  528. * Retrieves the player's country.
  529. *
  530. * @return string Two digit country code.
  531. */
  532. public function get_country(){
  533. return $this->country;
  534. }
  535. /**
  536. * Retrieves the player's language.
  537. *
  538. * @return string Two digit language code.
  539. */
  540. public function get_language(){
  541. return $this->language;
  542. }
  543. /**
  544. * Retrieves the player's level,
  545. *
  546. * @return int Player's level
  547. */
  548. public function get_level(){
  549. return $this->level;
  550. }
  551. /**
  552. * Retrieves the player's name
  553. *
  554. * @return string The playe's name.
  555. */
  556. public function get_name(){
  557. return $this->name;
  558. }
  559. /**
  560. * Retrieves the total experience earned by the user.
  561. *
  562. * @return int Total experience.
  563. */
  564. public function get_experience(){
  565. return $this->experience;
  566. }
  567. /**
  568. * Retrieves the player's representative unit.
  569. *
  570. * @return Unit Player's representative
  571. */
  572. public function get_rep(){
  573. if ($this->rep_id != null && $this->rep == null){
  574. $this->rep = new Unit($this->rep_id);
  575. }
  576. return $this->rep;
  577. }
  578. /**
  579. * Gets the date the user joined the game.
  580. *
  581. * If $format is supplied, a string in the desired format will be returned. If not, the raw
  582. * DateTime object will e returned.
  583. *
  584. * @param string $format A date format (optional).
  585. * @return DateTime | string The raw date, or a formatted version.
  586. */
  587. public function get_joined($format = null){
  588. if (null == $format){
  589. return $this->joined;
  590. }
  591. else{
  592. return $this->joined->format($format);
  593. }
  594. }
  595. /**
  596. * Retrieves the user's top rank in the Arena.
  597. *
  598. * @return int Top rank.
  599. */
  600. public function get_top_rank_arena(){
  601. return $this->top_rank_arena;
  602. }
  603. /**
  604. * Retrieves the user's top rank in the WorldArena.
  605. *
  606. * @return int Top rank.
  607. */
  608. public function get_top_rank_world_arena(){
  609. return $this->top_rank_world_arena;
  610. }
  611. /**
  612. * Retrieves the user's top rank in the Arena.
  613. *
  614. * @return int Top rank.
  615. */
  616. public function get_top_rank_special_league(){
  617. return $this->top_rank_special_league;
  618. }
  619. /**
  620. * Retrieves the user's top rank in Guild War.
  621. *
  622. * @return int Top rank.
  623. */
  624. public function get_top_rank_gw(){
  625. return $this->top_rank_gw;
  626. }
  627. /**
  628. * Retrieves the user's top rank in Siege battle.
  629. *
  630. * @return int Top rank.
  631. */
  632. public function get_top_rank_siege(){
  633. return $this->top_rank_siege;
  634. }
  635. /**
  636. * Retrieves the user's top rank in the World Boss.
  637. *
  638. * @return int Top rank.
  639. */
  640. public function get_top_rank_wboss(){
  641. return $this->top_rank_wboss;
  642. }
  643. /**
  644. * Retrieves the user's top rank in the Trial of Ascension (normal difficulty).
  645. *
  646. * @return int Top rank.
  647. */
  648. public function get_top_rank_toan(){
  649. return $this->top_rank_toan;
  650. }
  651. /**
  652. * Retrieves the user's top rank in the Trial of Ascension (hard difficulty).
  653. *
  654. * @return int Top rank.
  655. */
  656. public function get_top_rank_toah(){
  657. return $this->top_rank_toah;
  658. }
  659. /**
  660. * Retrieves the user's top rank in the Trial of Ascension (hell difficulty).
  661. *
  662. * @return int Top rank.
  663. */
  664. public function get_top_rank_toal(){
  665. return $this->top_rank_toal;
  666. }
  667. /**
  668. * Retrieves the Arena defense units.
  669. *
  670. * @return \Unit[] Units in the arena defense.
  671. */
  672. public function get_arena_defense(){
  673. if (!$this->flag_defense){
  674. $this->load_defenses();
  675. }
  676. return $this->arena_defense;
  677. }
  678. /**
  679. * Retrieves the Guild War defenses.
  680. *
  681. * @return Unit[][]: Units in Guild War defense, grouped by team.
  682. */
  683. public function get_gw_defense(){
  684. if (!$this->flag_defense){
  685. $this->load_defenses();
  686. }
  687. return $this->gw_defense;
  688. }
  689. /**
  690. * Retrieves the Guild War defenses.
  691. *
  692. * @return Unit[][]: Units in Siege Battle defense, grouped by team.
  693. */
  694. public function get_siege_defense(){
  695. if (!$this->flag_defense){
  696. $this->load_defenses();
  697. }
  698. return $this->siege_defense;
  699. }
  700. /**
  701. * Retrieves various currencies.
  702. *
  703. * @return int[] Array with the keys: mana, crystal, energy, energy_max, arena_energy,
  704. * darkportal_energy, dimension_energy, honor_point, guild_point, honor_medal, honor_mark,
  705. * event_coin, social_point, ancient_stone, costume_point,
  706. */
  707. public function get_currencies(){
  708. return $this->currency;
  709. }
  710. /**
  711. * Retrieves the list of buildings owned by the user.
  712. *
  713. * @return \Building[] Buildings owned.
  714. */
  715. public function get_buildings(){
  716. if (!$this->flag_building){
  717. $this->load_buildings();
  718. }
  719. return $this->building;
  720. }
  721. /**
  722. * Retrieves the list of decorations owned by the user.
  723. *
  724. * @return \Decoration[] Owned decorations.
  725. */
  726. public function get_decorations(){
  727. if (!$this->flag_building){
  728. $this->load_buildings();
  729. }
  730. return $this->decoration;
  731. }
  732. /**
  733. * Retrieves the list of owned scrolls.
  734. *
  735. * @return \Item[] Scrolls.
  736. */
  737. public function get_scrolls(){
  738. if (!$this->flag_item){
  739. $this->load_items();
  740. }
  741. return $this->item_scroll;
  742. }
  743. /**
  744. * Retrieves the list of rune crafting mateials.
  745. *
  746. * @return \Item[] Rune craft materials.
  747. */
  748. public function get_rune_craft_materials(){
  749. if (!$this->flag_item){
  750. $this->load_items();
  751. }
  752. return $this->item_craft_rune;
  753. }
  754. /**
  755. * Retrieves the list of crafting materials.
  756. *
  757. * @return \Item[] Crafting materials
  758. */
  759. public function get_craft_materials(){
  760. if (!$this->flag_item){
  761. $this->load_items();
  762. }
  763. return $this->item_craft;
  764. }
  765. /**
  766. * Retrieves the list of essences owned by the player.
  767. *
  768. * @return \Item[] Essences.
  769. */
  770. public function get_essences(){
  771. if (!$this->flag_item){
  772. $this->load_items();
  773. }
  774. return $this->item_essence;
  775. }
  776. /**
  777. * Retrieves the list of the player's records in the logbook.
  778. *
  779. * @return \Record[] List of records.
  780. */
  781. public function get_records(){
  782. if (!$this->flag_record){
  783. $this->load_records();
  784. }
  785. return $this->record;
  786. }
  787. /**
  788. * Checks if the player profile is public.
  789. *
  790. * @return bool True for public profile, false otherwise.
  791. */
  792. public function is_public(){
  793. return $this->public;
  794. }
  795. }