| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687 |
- <?php
- /**
- * Player entity file.
- *
- * Creates the entity and makes it available.
- *
- * @category Entity
- */
- /**
- * Require dependent entities if not present.
- */
- require_once(PATH::ENTITY . "Entity.php");
- require_once(PATH::ENTITY . "Unit.php");
- require_once(PATH::ENTITY . "Building.php");
- require_once(PATH::ENTITY . "Decoration.php");
- require_once(PATH::ENTITY . "Item.php");
- require_once(PATH::ENTITY . "Record.php");
- require_once(PATH::ENTITY . "Server.php");
- /**
- * A Player.
- *
- * Represents an object from the table 'player'.
- *
- * @category Entity
- */
- class Player extends Entity{
- private $id;
- private $server;
- private $country;
- private $language;
- private $level;
- private $name;
- private $experience;
- private $rep = null;
- private $rep_id = null;
- private $joined = 0;
- private $top_rank_arena = 0;
- private $top_rank_world_arena = 0;
- private $top_rank_special_league = 0;
- private $top_rank_gw = 0;
- private $top_rank_siege = 0;
- private $top_rank_wboss = 0;
- private $top_rank_toan = 0;
- private $top_rank_toah = 0;
- private $top_rank_toal = 0;
- private $flag_defense = false;
- private $arena_defense = [];
- private $gw_defense = [[], []];
- private $siege_defense = [];
- private $currency = [
- "mana" => 0,
- "crystal" => 0,
- "energy" => 0,
- "energy_max" => 0,
- "arena_energy" => 0,
- "darkportal_energy" => 0,
- "dimension_energy" => 0,
- "honor_point" => 0,
- "guild_point" => 0,
- "honor_medal" => 0,
- "honor_mark" => 0,
- "event_coin" => 0,
- "social_point" => 0,
- "ancient_stone" => 0,
- "costume_point" => 0,
- ];
- private $flag_building = false;
- private $building = [];
- private $decoration = [];
- private $flag_item = false;
- private $item_scroll = [];
- private $item_craft_rune = [];
- private $item_craft = [];
- private $item_essence = [];
- private $flag_record = false;
- private $record = [];
- private $public = false;
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * player, populating it and it's items.
- *
- * @param int $id Monster identifier.
- * @param bool $complete If false, query only monster and k_monster.
- */
- public function __construct($id, $complete = true){
- $statement = get_context()->get_db()->prepare("
- SELECT
- id,
- server,
- country,
- lang,
- name,
- level,
- experience,
- rep,
- mana,
- crystal,
- energy,
- energy_max,
- arena_energy,
- darkportal_energy,
- dimension_energy,
- honor_point,
- guild_point,
- honor_medal,
- honor_mark,
- event_coin,
- social_point,
- costume_point,
- joined,
- top_rank_arena,
- top_rank_world_arena,
- top_rank_special_league,
- top_rank_gw,
- top_rank_siege,
- top_rank_wboss,
- top_rank_toan,
- top_rank_toah,
- top_rank_toal,
- public
- FROM player
- WHERE id = :id;
- ");
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->id = $r["id"];
- $this->server = new Server($r["server"]);
- $this->country = $r["country"];
- $this->lang = $r["lang"];
- $this->name = $r["name"];
- $this->level = $r["level"];
- $this->experience = $r["experience"];
- if (strlen($r["rep"]) > 0){
- $this->rep_id = $r["rep"];
- }
- $this->currency["mana"] = $r["mana"];
- $this->currency["crystal"] = $r["crystal"];
- $this->currency["energy"] = $r["energy"];
- $this->currency["energy_max"] = $r["energy_max"];
- $this->currency["arena_energy"] = $r["arena_energy"];
- $this->currency["darkportal_energy"] = $r["darkportal_energy"];
- $this->currency["dimension_energy"] = $r["dimension_energy"];
- $this->currency["honor_point"] = $r["honor_point"];
- $this->currency["guild_point"] = $r["guild_point"];
- $this->currency["honor_medal"] = $r["honor_medal"];
- $this->currency["honor_mark"] = $r["honor_mark"];
- $this->currency["event_coin"] = $r["event_coin"];
- $this->currency["social_point"] = $r["social_point"];
- $this->currency["costume_point"] = $r["costume_point"];
- $this->joined = new Datetime();
- $this->joined->setTimestamp($r["joined"]);
- $this->top_rank_arena = $r["top_rank_arena"];
- $this->top_rank_world_arena = $r["top_rank_world_arena"];
- $this->top_rank_special_league = $r["top_rank_special_league"];
- $this->top_rank_gw = $r["top_rank_gw"];
- $this->top_rank_siege = $r["top_rank_siege"];
- $this->top_rank_wboss = $r["top_rank_wboss"];
- $this->top_rank_toan = $r["top_rank_toan"];
- $this->top_rank_toah = $r["top_rank_toah"];
- $this->top_rank_toal = $r["top_rank_toal"];
- if (strlen($r["public"]) == 1){
- $this->public = true;
- }
- }
- }
- private function load_defenses(){
- $statement = get_context()->get_db()->prepare("
- SELECT unit
- FROM defense
- WHERE
- player = :player AND
- area_type = :area_type
- ORDER BY position;
- ");
- $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
- $statement->bindValue(':area_type', AREA_TYPE_ID::ARENA, SQLITE3_INTEGER);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->arena_defense, new Unit($r["unit"], false));
- }
- $statement = get_context()->get_db()->prepare("
- SELECT
- unit,
- position
- FROM defense
- WHERE
- player = :player AND
- area_type = :area_type
- ORDER BY position;
- ");
- $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
- $statement->bindValue(':area_type', AREA_TYPE_ID::GUILD_WAR, SQLITE3_INTEGER);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- if ($r["position"] <= 3){
- array_push($this->gw_defense[0], new Unit($r["unit"], false));
- }
- else{
- array_push($this->gw_defense[1], new Unit($r["unit"], false));
- }
- }
- // TODO: Siege defenses
- $this->flag_defense = true;
- }
- private function load_buildings(){
- $statement = get_context()->get_db()->prepare("
- SELECT
- building.id AS id,
- min(building.buildable) AS min
- FROM
- building,
- buildable
- WHERE
- player = :player AND
- building.buildable = buildable.id
- GROUP BY building.buildable;
- ");
- $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->building, new Building($r["id"]));
- }
- $statement = get_context()->get_db()->prepare("
- SELECT id
- FROM decoration
- WHERE player = :player;
- ");
- $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->decoration, new Decoration($r["id"]));
- }
- $this->flag_building = true;
- }
- private function load_items(){
- $statement = get_context()->get_db()->prepare("
- SELECT
- id,
- type
- FROM item
- WHERE
- player = :player AND
- type = :type AND
- amount > 0
- ORDER BY item.type;
- ");
- $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
- $statement->bindValue(':type', INVENTORY_TYPE_ID::SCROLL, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->item_scroll, new item($r["id"], $r["type"]));
- }
- // Rune crafting items are marked as generic crafting.
- $statement = get_context()->get_db()->prepare("
- SELECT
- id,
- type
- FROM item
- WHERE
- player = :player AND
- type = :type AND
- amount > 0
- ORDER BY id;
- ");
- $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
- $statement->bindValue(':type', INVENTORY_TYPE_ID::ENCHANTMENT, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->item_craft_rune, new item($r["id"], $r["type"]));
- }
- $statement = get_context()->get_db()->prepare("
- SELECT
- id,
- type
- FROM item
- WHERE
- player = :player AND
- type = :type AND
- amount > 0
- ORDER BY id;
- ");
- $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
- $statement->bindValue(':type', INVENTORY_TYPE_ID::CRAFT_STUFF, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->item_craft, new item($r["id"], $r["type"]));
- }
- $statement = get_context()->get_db()->prepare("
- SELECT
- item.id AS id,
- item.type AS type
- FROM
- item,
- inventory
- WHERE
- item.id = inventory.id AND
- item.type = inventory.type AND
- item.player = :player AND
- item.type = :type AND
- amount > 0
- ORDER BY
- upper(inventory.name) NOT LIKE '%MAGIC%',
- upper(inventory.name) NOT LIKE '%FIRE%',
- upper(inventory.name) NOT LIKE '%WATER%',
- upper(inventory.name) NOT LIKE '%WIND%',
- upper(inventory.name) NOT LIKE '%LIGHT%',
- upper(inventory.name) NOT LIKE '%DARK%',
- upper(inventory.name) NOT LIKE '%LOW%',
- upper(inventory.name) NOT LIKE '%MID%',
- upper(inventory.name) NOT LIKE '%HIGH%'
- ;
- ");
- $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
- $statement->bindValue(':type', INVENTORY_TYPE_ID::ESSENCES, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->item_essence, new item($r["id"], $r["type"]));
- }
- $this->flag_item = true;
- }
- private function load_records(){
- $statement = get_context()->get_db()->prepare("
- SELECT
- player,
- area_type,
- area
- FROM record
- WHERE player = :player
- ORDER BY
- CASE
- WHEN (area_type = 2 AND area = 8001) THEN 1 -- Giant's Keep
- WHEN (area_type = 2 AND area = 9001) THEN 2 -- Dragon's Lair
- WHEN (area_type = 2 AND area = 6001) THEN 3 -- Necropolis
- WHEN (area_type = 2 AND area = 9501) THEN 4 -- Steel Fortress
- WHEN (area_type = 2 AND area = 9502) THEN 5 -- Punisher's Crypt
- WHEN (area_type = 4) THEN 6 -- Rift of Worlds
- WHEN (area_type = 3 AND area = 1001) THEN 7 -- Rift Dungeon - Ice Beast
- WHEN (area_type = 3 AND area = 2001) THEN 8 -- Rift Dungeon - Fire Beast
- WHEN (area_type = 3 AND area = 3001) THEN 9 -- Rift Dungeon - Wind Beast
- WHEN (area_type = 3 AND area = 4001) THEN 10 -- Rift Dungeon - Light Beast
- WHEN (area_type = 3 AND area = 5001) THEN 11 -- Rift Dungeon - Dark Beast
- WHEN (area_type = 2 AND area = 5001) THEN 12 -- Hall of Magic
- WHEN (area_type = 2 AND area = 3001) THEN 13 -- Hall of Water
- WHEN (area_type = 2 AND area = 2001) THEN 14 -- Hall of Fire
- WHEN (area_type = 2 AND area = 4001) THEN 15 -- Hall of Wind
- WHEN (area_type = 2 AND area = 7001) THEN 16 -- Hall of Light
- WHEN (area_type = 2 AND area = 1001) THEN 17 -- Hall of Dark
- ELSE area
- END ASC
- ");
- $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->record, new Record($r["player"], $r["area_type"], $r["area"]));
- }
- $this->flag_record = true;
- }
- /**
- * Retrieves the player identifier
- *
- * @return int Plyaer ID.
- */
- public function get_id(){
- return $this->id;
- }
- /**
- * Retrieves the player server.
- *
- * @return Server The player's account server.
- */
- public function get_server(){
- return $this->server;
- }
- /**
- * Retrieves the player's country.
- *
- * @return string Two digit country code.
- */
- public function get_country(){
- return $this->country;
- }
- /**
- * Retrieves the player's language.
- *
- * @return string Two digit language code.
- */
- public function get_language(){
- return $this->language;
- }
- /**
- * Retrieves the player's level,
- *
- * @return int Player's level
- */
- public function get_level(){
- return $this->level;
- }
- /**
- * Retrieves the player's name
- *
- * @return string The playe's name.
- */
- public function get_name(){
- return $this->name;
- }
- /**
- * Retrieves the total experience earned by the user.
- *
- * @return number Total experience.
- */
- public function get_experience(){
- return $this->experience;
- }
- /**
- * Retrieves the player's representative unit.
- *
- * @return Unit Player's representative
- */
- public function get_rep(){
- if ($this->rep_id != null && $this->rep == null){
- $this->rep = new Unit($this->rep_id);
- }
- return $this->rep;
- }
- /**
- * Gets the date the user joined the game.
- *
- * If $format is supplied, a string in the desired format will be returned. If not, the raw
- * DateTime object will e returned.
- *
- * @param string $format A date format (optional).
- * @return DateTime | string The raw date, or a formatted version.
- */
- public function get_joined($format = null){
- if (null == $format){
- return $this->joined;
- }
- else{
- return $this->joined->format($format);
- }
- }
- /**
- * Retrieves the user's top rank in the Arena.
- *
- * @return int Top rank.
- */
- public function get_top_rank_arena(){
- return $this->top_rank_arena;
- }
- /**
- * Retrieves the user's top rank in the WorldArena.
- *
- * @return int Top rank.
- */
- public function get_top_rank_world_arena(){
- return $this->top_rank_world_arena;
- }
- /**
- * Retrieves the user's top rank in the Arena.
- *
- * @return int Top rank.
- */
- public function get_top_rank_special_league(){
- return $this->top_rank_special_league;
- }
- /**
- * Retrieves the user's top rank in Guild War.
- *
- * @return int Top rank.
- */
- public function get_top_rank_gw(){
- return $this->top_rank_gw;
- }
- /**
- * Retrieves the user's top rank in Siege battle.
- *
- * @return int Top rank.
- */
- public function get_top_rank_siege(){
- return $this->top_rank_siege;
- }
- /**
- * Retrieves the user's top rank in the World Boss.
- *
- * @return int Top rank.
- */
- public function get_top_rank_wboss(){
- return $this->top_rank_wboss;
- }
- /**
- * Retrieves the user's top rank in the Trial of Ascension (normal difficulty).
- *
- * @return int Top rank.
- */
- public function get_top_rank_toan(){
- return $this->top_rank_toan;
- }
- /**
- * Retrieves the user's top rank in the Trial of Ascension (hard difficulty).
- *
- * @return int Top rank.
- */
- public function get_top_rank_toah(){
- return $this->top_rank_toah;
- }
- /**
- * Retrieves the user's top rank in the Trial of Ascension (hell difficulty).
- *
- * @return int Top rank.
- */
- public function get_top_rank_toal(){
- return $this->top_rank_toal;
- }
- /**
- * Retrieves the Arena defense units.
- *
- * @return \Unit[] Units in the arena defense.
- */
- public function get_arena_defense(){
- if (!$this->flag_defense){
- $this->load_defenses();
- }
- return $this->arena_defense;
- }
- /**
- * Retrieves the Guild War defenses.
- *
- * @return Unit[][]: Units in Guild War defense, grouped by team.
- */
- public function get_gw_defense(){
- if (!$this->flag_defense){
- $this->load_defenses();
- }
- return $this->gw_defense;
- }
- /**
- * Retrieves the Guild War defenses.
- *
- * @return Unit[][]: Units in Siege Battle defense, grouped by team.
- */
- public function get_siege_defense(){
- if (!$this->flag_defense){
- $this->load_defenses();
- }
- return $this->siege_defense;
- }
- /**
- * Retrieves various currencies.
- *
- * @return int[] Array with the keys: mana, crystal, energy, energy_max, arena_energy,
- * darkportal_energy, dimension_energy, honor_point, guild_point, honor_medal, honor_mark,
- * event_coin, social_point, ancient_stone, costume_point,
- */
- public function get_currencies(){
- return $this->currency;
- }
- /**
- * Retrieves the list of buildings owned by the user.
- *
- * @return \Building[] Buildings owned.
- */
- public function get_buildings(){
- if (!$this->flag_building){
- $this->load_buildings();
- }
- return $this->building;
- }
- /**
- * Retrieves the list of decorations owned by the user.
- *
- * @return \Decoration[] Owned decorations.
- */
- public function get_decorations(){
- if (!$this->flag_building){
- $this->load_buildings();
- }
- return $this->decoration;
- }
- /**
- * Retrieves the list of owned scrolls.
- *
- * @return \Item[] Scrolls.
- */
- public function get_scrolls(){
- if (!$this->flag_item){
- $this->load_items();
- }
- return $this->item_scroll;
- }
- /**
- * Retrieves the list of rune crafting mateials.
- *
- * @return \Item[] Rune craft materials.
- */
- public function get_rune_craft_materials(){
- if (!$this->flag_item){
- $this->load_items();
- }
- return $this->item_craft_rune;
- }
- /**
- * Retrieves the list of crafting materials.
- *
- * @return \Item[] Crafting materials
- */
- public function get_craft_materials(){
- if (!$this->flag_item){
- $this->load_items();
- }
- return $this->item_craft;
- }
- /**
- * Retrieves the list of essences owned by the player.
- *
- * @return \Item[] Essences.
- */
- public function get_essences(){
- if (!$this->flag_item){
- $this->load_items();
- }
- return $this->item_essence;
- }
- /**
- * Retrieves the list of the player's records in the logbook.
- *
- * @return \Record[] List of records.
- */
- public function get_records(){
- if (!$this->flag_record){
- $this->load_records();
- }
- return $this->record;
- }
- /**
- * Checks if the player profile is public.
- *
- * @return bool True for public profile, false otherwise.
- */
- public function is_public(){
- return $this->public;
- }
- }
- ?>
|