Player.php 23 KB

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