Ranking system rework.

Contributed by iDesy.
This commit is contained in:
MobiusDevelopment
2021-05-22 22:33:14 +00:00
parent 6ebd7458e3
commit c88dcd8ea8
104 changed files with 4616 additions and 2916 deletions

View File

@@ -55,6 +55,8 @@ CREATE TABLE IF NOT EXISTS `characters` (
`language` VARCHAR(2) DEFAULT NULL,
`faction` TINYINT UNSIGNED NOT NULL DEFAULT '0',
`pccafe_points` int(6) NOT NULL DEFAULT '0',
`deaths` SMALLINT NOT NULL DEFAULT '0',
`kills` SMALLINT NOT NULL DEFAULT '0',
PRIMARY KEY (`charId`),
KEY `account_name` (`account_name`),
KEY `char_name` (`char_name`),

View File

@@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS `clan_data` (
`char_penalty_expiry_time` bigint(13) unsigned NOT NULL DEFAULT '0',
`dissolving_expiry_time` bigint(13) unsigned NOT NULL DEFAULT '0',
`new_leader_id` INT(10) unsigned NOT NULL DEFAULT '0',
`exp` INT,
PRIMARY KEY (`clan_id`),
KEY `ally_id` (`ally_id`),
KEY `leader_id` (`leader_id`),

View File

@@ -0,0 +1,57 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.enums;
import static org.l2jmobius.gameserver.enums.RankingScope.ALL;
import static org.l2jmobius.gameserver.enums.RankingScope.SELF;
import static org.l2jmobius.gameserver.enums.RankingScope.TOP_100;
import static org.l2jmobius.gameserver.enums.RankingScope.TOP_150;
/**
* Written by Berezkin Nikolay, on 10.05.2021
*/
public enum RankingCategory
{
SERVER,
RACE,
CLAN,
FRIEND;
public RankingScope getScopeByGroup(int id)
{
switch (this)
{
case SERVER:
{
return id == 0 ? TOP_150 : SELF;
}
case RACE:
{
return id == 0 ? TOP_100 : SELF;
}
case CLAN:
case FRIEND:
{
return ALL;
}
default:
{
return null;
}
}
}
}

View File

@@ -0,0 +1,49 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.enums;
import static org.l2jmobius.gameserver.enums.RankingOlympiadScope.SELF;
import static org.l2jmobius.gameserver.enums.RankingOlympiadScope.TOP_100;
import static org.l2jmobius.gameserver.enums.RankingOlympiadScope.TOP_50;
/**
* Written by Berezkin Nikolay, on 10.05.2021
*/
public enum RankingOlympiadCategory
{
SERVER,
CLASS;
public RankingOlympiadScope getScopeByGroup(int id)
{
switch (this)
{
case SERVER:
{
return id == 0 ? TOP_100 : SELF;
}
case CLASS:
{
return id == 0 ? TOP_50 : SELF;
}
default:
{
return null;
}
}
}
}

View File

@@ -0,0 +1,40 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.enums;
/**
* Written by Berezkin Nikolay, on 10.05.2021
*/
public enum RankingOlympiadScope
{
TOP_100(0),
TOP_50(0),
ALL(0),
SELF(1);
final private int _id;
private RankingOlympiadScope(int id)
{
_id = id;
}
public int getId()
{
return _id;
}
}

View File

@@ -0,0 +1,40 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.enums;
/**
* Written by Berezkin Nikolay, on 10.05.2021
*/
public enum RankingScope
{
TOP_100(0),
TOP_150(0),
ALL(0),
SELF(1);
final private int _id;
private RankingScope(int id)
{
_id = id;
}
public int getId()
{
return _id;
}
}

View File

@@ -29,6 +29,7 @@ import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.util.Chronos;
import org.l2jmobius.gameserver.data.sql.ClanTable;
import org.l2jmobius.gameserver.data.xml.PetDataTable;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.olympiad.Hero;
@@ -42,10 +43,13 @@ public class RankManager
public static final Long TIME_LIMIT = 2592000000L; // 30 days in milliseconds
public static final long CURRENT_TIME = Chronos.currentTimeMillis();
public static final int PLAYER_LIMIT = 100;
public static final int PLAYER_LIMIT = 500;
private static final String SELECT_CHARACTERS = "SELECT charId,char_name,level,race,base_class, clanid FROM characters WHERE (" + CURRENT_TIME + " - cast(lastAccess as signed) < " + TIME_LIMIT + ") AND accesslevel = 0 AND level > 39 ORDER BY exp DESC, onlinetime DESC LIMIT " + PLAYER_LIMIT;
private static final String SELECT_CHARACTERS_PVP = "SELECT charId,char_name,level,race,base_class, clanid, deaths, kills, pvpkills FROM characters WHERE (" + CURRENT_TIME + " - cast(lastAccess as signed) < " + TIME_LIMIT + ") AND accesslevel = 0 AND level > 39 ORDER BY kills DESC, onlinetime DESC LIMIT " + PLAYER_LIMIT;
private static final String SELECT_CHARACTERS_BY_RACE = "SELECT charId FROM characters WHERE (" + CURRENT_TIME + " - cast(lastAccess as signed) < " + TIME_LIMIT + ") AND accesslevel = 0 AND level > 39 AND race = ? ORDER BY exp DESC, onlinetime DESC LIMIT " + PLAYER_LIMIT;
private static final String SELECT_PETS = "SELECT characters.charId, pets.exp, characters.char_name, pets.level as petLevel, characters.level as charLevel, characters.clanId, petsEvolved.index, pets.item_obj_id FROM characters, pets, petsEvolved WHERE pets.ownerId = characters.charId AND petsEvolved.itemObjId = pets.item_obj_id AND (" + CURRENT_TIME + " - cast(characters.lastAccess as signed) < " + TIME_LIMIT + ") AND characters.accesslevel = 0 AND pets.level > 39 ORDER BY pets.exp DESC, characters.onlinetime DESC LIMIT " + PLAYER_LIMIT;
private static final String SELECT_CLANS = "SELECT characters.level, characters.char_name, clan_data.clan_id, clan_data.clan_level, clan_data.clan_name, clan_data.reputation_score, clan_data.exp FROM characters, clan_data WHERE characters.charId = clan_data.leader_id AND characters.clanid = clan_data.clan_id AND dissolving_expiry_time = 0 ORDER BY exp DESC LIMIT " + PLAYER_LIMIT;
private static final String GET_CURRENT_CYCLE_DATA = "SELECT characters.char_name, characters.level, characters.base_class, characters.clanid, olympiad_nobles.charId, olympiad_nobles.olympiad_points, olympiad_nobles.competitions_won, olympiad_nobles.competitions_lost FROM characters, olympiad_nobles WHERE characters.charId = olympiad_nobles.charId ORDER BY olympiad_nobles.olympiad_points DESC LIMIT " + PLAYER_LIMIT;
private static final String GET_CHARACTERS_BY_CLASS = "SELECT characters.charId, olympiad_nobles.olympiad_points FROM characters, olympiad_nobles WHERE olympiad_nobles.charId = characters.charId AND characters.base_class = ? ORDER BY olympiad_nobles.olympiad_points DESC LIMIT " + PLAYER_LIMIT;
@@ -54,6 +58,12 @@ public class RankManager
private Map<Integer, StatSet> _snapshotList = new ConcurrentHashMap<>();
private final Map<Integer, StatSet> _mainOlyList = new ConcurrentHashMap<>();
private Map<Integer, StatSet> _snapshotOlyList = new ConcurrentHashMap<>();
private final Map<Integer, StatSet> _mainPvpList = new ConcurrentHashMap<>();
private Map<Integer, StatSet> _snapshotPvpList = new ConcurrentHashMap<>();
private final Map<Integer, StatSet> _mainPetList = new ConcurrentHashMap<>();
private Map<Integer, StatSet> _snapshotPetList = new ConcurrentHashMap<>();
private final Map<Integer, StatSet> _mainClanList = new ConcurrentHashMap<>();
private Map<Integer, StatSet> _snapshotClanList = new ConcurrentHashMap<>();
protected RankManager()
{
@@ -67,6 +77,12 @@ public class RankManager
_mainList.clear();
_snapshotOlyList = _mainOlyList;
_mainOlyList.clear();
_snapshotPvpList = _mainPvpList;
_mainPvpList.clear();
_snapshotPetList = _mainPetList;
_mainPetList.clear();
_snapshotClanList = _mainClanList;
_mainClanList.clear();
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(SELECT_CHARACTERS))
@@ -166,6 +182,100 @@ public class RankManager
{
LOGGER.log(Level.WARNING, "Could not load olympiad total rank data: " + this + " - " + e.getMessage(), e);
}
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(SELECT_CHARACTERS_PVP))
{
try (ResultSet rset = statement.executeQuery())
{
int i = 1;
while (rset.next())
{
final StatSet player = new StatSet();
final int charId = rset.getInt("charId");
player.set("charId", charId);
player.set("name", rset.getString("char_name"));
player.set("level", rset.getInt("level"));
player.set("classId", rset.getInt("base_class"));
final int race = rset.getInt("race");
player.set("race", race);
player.set("kills", rset.getInt("kills"));
player.set("deaths", rset.getInt("deaths"));
player.set("points", rset.getInt("pvpkills"));
loadRaceRank(charId, race, player);
final int clanId = rset.getInt("clanid");
if (clanId > 0)
{
player.set("clanName", ClanTable.getInstance().getClan(clanId).getName());
}
else
{
player.set("clanName", "");
}
_mainPvpList.put(i, player);
i++;
}
}
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Could not load pvp total rank data: " + this + " - " + e.getMessage(), e);
}
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(SELECT_PETS))
{
try (ResultSet rset = statement.executeQuery())
{
int i = 1;
while (rset.next())
{
final StatSet player = new StatSet();
final int charId = rset.getInt("charId");
player.set("charId", charId);
player.set("name", rset.getString("char_name"));
player.set("level", rset.getInt("charLevel"));
player.set("petLevel", rset.getInt("petLevel"));
player.set("clanName", rset.getInt("clanid") > 0 ? ClanTable.getInstance().getClan(rset.getInt("clanid")).getName() : "");
player.set("petType", PetDataTable.getInstance().getTypeByIndex(rset.getInt("index")));
player.set("exp", rset.getInt("exp"));
player.set("controlledItemObjId", rset.getInt("item_obj_id"));
_mainPetList.put(i, player);
i++;
}
}
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Could not load pet total rank data: " + this + " - " + e.getMessage(), e);
}
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(SELECT_CLANS))
{
try (ResultSet rset = statement.executeQuery())
{
int i = 1;
while (rset.next())
{
final StatSet player = new StatSet();
player.set("char_name", rset.getString("char_name"));
player.set("level", rset.getInt("level"));
player.set("clan_level", rset.getInt("clan_level"));
player.set("clan_name", rset.getString("clan_name"));
player.set("reputation_score", rset.getInt("reputation_score"));
player.set("exp", rset.getInt("exp"));
player.set("clan_id", rset.getInt("clan_id"));
_mainClanList.put(i, player);
i++;
}
}
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Could not load clan total rank data: " + this + " - " + e.getMessage(), e);
}
}
private void loadClassRank(int charId, int classId, StatSet player)
@@ -246,6 +356,36 @@ public class RankManager
return _snapshotOlyList;
}
public Map<Integer, StatSet> getPvpRankList()
{
return _mainPvpList;
}
public Map<Integer, StatSet> getSnapshotPvpRankList()
{
return _snapshotPvpList;
}
public Map<Integer, StatSet> getPetRankList()
{
return _mainPetList;
}
public Map<Integer, StatSet> getSnapshotPetRankList()
{
return _snapshotPetList;
}
public Map<Integer, StatSet> getClanRankList()
{
return _mainClanList;
}
public Map<Integer, StatSet> getSnapshotClanRankList()
{
return _snapshotClanList;
}
public int getPlayerGlobalRank(PlayerInstance player)
{
final int playerOid = player.getObjectId();

View File

@@ -45,14 +45,13 @@ public class PetData
private final int _petType;
private final int _index;
private final int _type;
private final EvolveLevel _evolveLevel;
public EvolveLevel getEvolveLevel()
{
return evolveLevel == null ? EvolveLevel.None : evolveLevel;
return _evolveLevel == null ? EvolveLevel.None : _evolveLevel;
}
private final EvolveLevel evolveLevel;
public int getIndex()
{
return _index;
@@ -68,9 +67,9 @@ public class PetData
_npcId = npcId;
_itemId = itemId;
_petType = petType;
this.evolveLevel = evolveLevel;
this._index = index;
this._type = type;
_evolveLevel = evolveLevel;
_index = index;
_type = type;
}
/**

View File

@@ -972,6 +972,7 @@ public class Npc extends Creature
else if (Config.FAKE_PLAYER_KILL_PVP)
{
player.setPvpKills(player.getPvpKills() + 1);
player.setTotalKills(player.getTotalKills() + 1);
player.broadcastUserInfo(UserInfoType.SOCIAL);
// pvp item rewards
if (Config.REWARD_PVP_ITEM)

View File

@@ -1566,7 +1566,7 @@ public class PetInstance extends Summon
public void setPetType(int petType)
{
this._petType = petType;
_petType = petType;
}
public int getEvolveLevel()
@@ -1576,7 +1576,7 @@ public class PetInstance extends Summon
public void setEvolveLevel(EvolveLevel evolveLevel)
{
this._evolveLevel = evolveLevel;
_evolveLevel = evolveLevel;
}
public void useEquippableItem(ItemInstance item, boolean abortAttack)

View File

@@ -411,8 +411,8 @@ public class PlayerInstance extends Playable
private static final String DELETE_ITEM_REUSE_SAVE = "DELETE FROM character_item_reuse_save WHERE charId=?";
// Character Character SQL String Definitions:
private static final String INSERT_CHARACTER = "INSERT INTO characters (account_name,charId,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,face,hairStyle,hairColor,sex,exp,sp,reputation,fame,raidbossPoints,pvpkills,pkkills,clanid,race,classid,deletetime,cancraft,title,title_color,online,clan_privs,wantspeace,base_class,nobless,power_grade,vitality_points,createDate) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,face=?,hairStyle=?,hairColor=?,sex=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,reputation=?,fame=?,raidbossPoints=?,pvpkills=?,pkkills=?,clanid=?,race=?,classid=?,deletetime=?,title=?,title_color=?,online=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,nobless=?,power_grade=?,subpledge=?,lvl_joined_academy=?,apprentice=?,sponsor=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,bookmarkslot=?,vitality_points=?,language=?,faction=?,pccafe_points=? WHERE charId=?";
private static final String INSERT_CHARACTER = "INSERT INTO characters (account_name,charId,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,face,hairStyle,hairColor,sex,exp,sp,reputation,fame,raidbossPoints,pvpkills,pkkills,clanid,race,classid,deletetime,cancraft,title,title_color,online,clan_privs,wantspeace,base_class,nobless,power_grade,vitality_points,createDate,kills,deaths) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,face=?,hairStyle=?,hairColor=?,sex=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,reputation=?,fame=?,raidbossPoints=?,pvpkills=?,pkkills=?,clanid=?,race=?,classid=?,deletetime=?,title=?,title_color=?,online=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,nobless=?,power_grade=?,subpledge=?,lvl_joined_academy=?,apprentice=?,sponsor=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,bookmarkslot=?,vitality_points=?,language=?,faction=?,pccafe_points=?,kills=?,deaths=? WHERE charId=?";
private static final String UPDATE_CHARACTER_ACCESS = "UPDATE characters SET accesslevel = ? WHERE charId = ?";
private static final String RESTORE_CHARACTER = "SELECT * FROM characters WHERE charId=?";
@@ -513,6 +513,12 @@ public class PlayerInstance extends Playable
/** The PK counter of the PlayerInstance (= Number of non PvP Flagged player killed) */
private int _pkKills;
/** The total kill counter of the PlayerInstance */
private int _totalKills = 0;
/** The total death counter of the PlayerInstance */
private int _totalDeaths = 0;
/** The PvP Flag state of the PlayerInstance (0=White, 1=Purple) */
private byte _pvpFlag;
@@ -1973,6 +1979,26 @@ public class PlayerInstance extends Playable
_pkKills = pkKills;
}
public int getTotalKills()
{
return _totalKills;
}
public int getTotalDeaths()
{
return _totalDeaths;
}
public void setTotalKills(int value)
{
_totalKills = value;
}
public void setTotalDeaths(int value)
{
_totalDeaths = value;
}
/**
* @return the _deleteTimer of the PlayerInstance.
*/
@@ -4817,6 +4843,7 @@ public class PlayerInstance extends Playable
if (pk != null)
{
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerPvPKill(pk, this), this);
setTotalDeaths(getTotalDeaths() + 1);
if (GameEvent.isParticipant(pk))
{
pk.getEventStatus().addKill(this);
@@ -5158,11 +5185,13 @@ public class PlayerInstance extends Playable
}
setPvpKills(_pvpKills + 1);
setTotalKills(getTotalKills() + 1);
updatePvpTitleAndColor(true);
}
else if ((getReputation() > 0) && (_pkKills == 0))
{
setReputation(0);
setTotalKills(getTotalKills() + 1);
setPkKills(getPkKills() + 1);
}
else // Calculate new karma and increase pk count
@@ -5173,12 +5202,14 @@ public class PlayerInstance extends Playable
{
setReputation(getReputation() - Formulas.calculateKarmaGain(getPkKills(), killedPlayable.isSummon()));
setPkKills(getPkKills() + 1);
setTotalKills(getTotalKills() + 1);
}
}
else
{
setReputation(getReputation() - Formulas.calculateKarmaGain(getPkKills(), killedPlayable.isSummon()));
setPkKills(getPkKills() + 1);
setTotalKills(getTotalKills() + 1);
}
}
@@ -6494,6 +6525,8 @@ public class PlayerInstance extends Playable
statement.setLong(34, 0);
statement.setInt(35, PlayerStat.MIN_VITALITY_POINTS);
statement.setDate(36, new Date(_createDate.getTimeInMillis()));
statement.setInt(37, getTotalKills());
statement.setInt(38, getTotalDeaths());
statement.executeUpdate();
}
catch (Exception e)
@@ -6618,7 +6651,8 @@ public class PlayerInstance extends Playable
player.getClanPrivileges().clear();
}
player.setTotalDeaths(rset.getInt("deaths"));
player.setTotalKills(rset.getInt("kills"));
player.setDeleteTimer(rset.getLong("deletetime"));
player.setTitle(rset.getString("title"));
player.setAccessLevel(rset.getInt("accesslevel"), false, false);
@@ -7215,7 +7249,9 @@ public class PlayerInstance extends Playable
}
statement.setInt(47, factionId);
statement.setInt(48, _pcCafePoints);
statement.setInt(49, getObjectId());
statement.setInt(49, getTotalKills());
statement.setInt(50, getTotalDeaths());
statement.setInt(51, getObjectId());
statement.execute();
}
catch (Exception e)

View File

@@ -89,7 +89,7 @@ public class Clan implements IIdentifiable, INamable
private static final Logger LOGGER = Logger.getLogger(Clan.class.getName());
// SQL queries
private static final String INSERT_CLAN_DATA = "INSERT INTO clan_data (clan_id,clan_name,clan_level,hasCastle,blood_alliance_count,blood_oath_count,ally_id,ally_name,leader_id,crest_id,crest_large_id,ally_crest_id,new_leader_id) values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
private static final String INSERT_CLAN_DATA = "INSERT INTO clan_data (clan_id,clan_name,clan_level,hasCastle,blood_alliance_count,blood_oath_count,ally_id,ally_name,leader_id,crest_id,crest_large_id,ally_crest_id,new_leader_id,exp) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
private static final String SELECT_CLAN_DATA = "SELECT * FROM clan_data where clan_id=?";
// Ally Penalty Types
@@ -153,6 +153,22 @@ public class Clan implements IIdentifiable, INamable
private int _reputationScore = 0;
private int _rank = 0;
private int _exp;
private static final int[] EXP_TABLE =
{
100,
1000,
5000,
10000,
500000,
1500000,
4500000,
7500000,
11000000,
14500000,
20000000
};
private String _notice;
private boolean _noticeEnabled = false;
private static final int MAX_NOTICE_LENGTH = 8192;
@@ -984,7 +1000,7 @@ public class Clan implements IIdentifiable, INamable
public void updateClanInDB()
{
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET leader_id=?,ally_id=?,ally_name=?,reputation_score=?,ally_penalty_expiry_time=?,ally_penalty_type=?,char_penalty_expiry_time=?,dissolving_expiry_time=?,new_leader_id=? WHERE clan_id=?"))
PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET leader_id=?,ally_id=?,ally_name=?,reputation_score=?,ally_penalty_expiry_time=?,ally_penalty_type=?,char_penalty_expiry_time=?,dissolving_expiry_time=?,new_leader_id=?,exp=? WHERE clan_id=?"))
{
ps.setInt(1, getLeaderId());
ps.setInt(2, _allyId);
@@ -995,7 +1011,8 @@ public class Clan implements IIdentifiable, INamable
ps.setLong(7, _charPenaltyExpiryTime);
ps.setLong(8, _dissolvingExpiryTime);
ps.setInt(9, _newLeaderId);
ps.setInt(10, _clanId);
ps.setInt(10, _exp);
ps.setInt(11, _clanId);
ps.execute();
}
catch (Exception e)
@@ -1037,6 +1054,7 @@ public class Clan implements IIdentifiable, INamable
ps.setInt(11, _crestLargeId);
ps.setInt(12, _allyCrestId);
ps.setInt(13, _newLeaderId);
ps.setInt(14, _exp);
ps.execute();
}
catch (Exception e)
@@ -1108,6 +1126,7 @@ public class Clan implements IIdentifiable, INamable
setCrestLargeId(clanData.getInt("crest_large_id"));
setAllyCrestId(clanData.getInt("ally_crest_id"));
_exp = clanData.getInt("exp");
setReputationScore(clanData.getInt("reputation_score"), false);
setAuctionBiddedAt(clanData.getInt("auction_bid_at"), false);
setNewLeaderId(clanData.getInt("new_leader_id"), false);
@@ -3044,4 +3063,24 @@ public class Clan implements IIdentifiable, INamable
vars.storeMe();
}
}
public int getExp()
{
return _exp;
}
public void addExp(int value, boolean save)
{
_exp += value;
if (EXP_TABLE[getLevel()] <= _exp)
{
changeLevel(_level + 1);
}
if (save)
{
updateClanInDB();
}
}
}

View File

@@ -123,6 +123,12 @@ import org.l2jmobius.gameserver.network.clientpackets.randomcraft.ExRequestRando
import org.l2jmobius.gameserver.network.clientpackets.ranking.RequestOlympiadHeroAndLegendInfo;
import org.l2jmobius.gameserver.network.clientpackets.ranking.RequestOlympiadMyRankingInfo;
import org.l2jmobius.gameserver.network.clientpackets.ranking.RequestOlympiadRankingInfo;
import org.l2jmobius.gameserver.network.clientpackets.ranking.RequestPetRankingList;
import org.l2jmobius.gameserver.network.clientpackets.ranking.RequestPetRankingMyInfo;
import org.l2jmobius.gameserver.network.clientpackets.ranking.RequestPledgeRankingList;
import org.l2jmobius.gameserver.network.clientpackets.ranking.RequestPledgeRankingMyInfo;
import org.l2jmobius.gameserver.network.clientpackets.ranking.RequestPvpRankingList;
import org.l2jmobius.gameserver.network.clientpackets.ranking.RequestPvpRankingMyInfo;
import org.l2jmobius.gameserver.network.clientpackets.ranking.RequestRankingCharInfo;
import org.l2jmobius.gameserver.network.clientpackets.ranking.RequestRankingCharRankers;
import org.l2jmobius.gameserver.network.clientpackets.sayune.RequestFlyMove;
@@ -606,8 +612,8 @@ public enum ExIncomingPackets implements IIncomingPackets<GameClient>
EX_BLESS_OPTION_PUT_ITEM(0x1BF, RequestBlessOptionPutItem::new, ConnectionState.IN_GAME),
EX_BLESS_OPTION_ENCHANT(0x1C0, RequestBlessOptionEnchant::new, ConnectionState.IN_GAME),
EX_BLESS_OPTION_CANCEL(0x1C1, RequestBlessOptionCancel::new, ConnectionState.IN_GAME),
EX_PVP_RANKING_MY_INFO(0x1C2, null, ConnectionState.IN_GAME),
EX_PVP_RANKING_LIST(0x1C3, null, ConnectionState.IN_GAME),
EX_PVP_RANKING_MY_INFO(0x1C2, RequestPvpRankingMyInfo::new, ConnectionState.IN_GAME),
EX_PVP_RANKING_LIST(0x1C3, RequestPvpRankingList::new, ConnectionState.IN_GAME),
EX_ACQUIRE_PET_SKILL(0x1C4, RequestExAcquirePetSkill::new, ConnectionState.IN_GAME),
EX_PLEDGE_V3_INFO(0x1C5, null, ConnectionState.IN_GAME),
EX_PLEDGE_ENEMY_INFO_LIST(0x1C6, null, ConnectionState.IN_GAME),
@@ -629,8 +635,8 @@ public enum ExIncomingPackets implements IIncomingPackets<GameClient>
EX_STEADY_OPEN_SLOT(0x1D5, null, ConnectionState.IN_GAME),
EX_STEADY_OPEN_BOX(0x1D6, null, ConnectionState.IN_GAME),
EX_STEADY_GET_REWARD(0x1D7, null, ConnectionState.IN_GAME),
EX_PET_RANKING_MY_INFO(0x1D8, null, ConnectionState.IN_GAME),
EX_PET_RANKING_LIST(0x1D9, null, ConnectionState.IN_GAME),
EX_PET_RANKING_MY_INFO(0x1D8, RequestPetRankingMyInfo::new, ConnectionState.IN_GAME),
EX_PET_RANKING_LIST(0x1D9, RequestPetRankingList::new, ConnectionState.IN_GAME),
EX_COLLECTION_OPEN_UI(0x1DA, RequestExCollectionOpenUI::new, ConnectionState.IN_GAME),
EX_COLLECTION_CLOSE_UI(0x1DB, RequestCollectionCloseUI::new, ConnectionState.IN_GAME),
EX_COLLECTION_LIST(0x1DC, RequestExCollectionList::new, ConnectionState.IN_GAME),
@@ -658,8 +664,8 @@ public enum ExIncomingPackets implements IIncomingPackets<GameClient>
EX_PLEDGE_DONATION_INFO(0x1F2, null, ConnectionState.IN_GAME),
EX_PLEDGE_DONATION_REQUEST(0x1F3, null, ConnectionState.IN_GAME),
EX_PLEDGE_CONTRIBUTION_LIST(0x1F4, null, ConnectionState.IN_GAME),
EX_PLEDGE_RANKING_MY_INFO(0x1F5, null, ConnectionState.IN_GAME),
EX_PLEDGE_RANKING_LIST(0x1F6, null, ConnectionState.IN_GAME),
EX_PLEDGE_RANKING_MY_INFO(0x1F5, RequestPledgeRankingMyInfo::new, ConnectionState.IN_GAME),
EX_PLEDGE_RANKING_LIST(0x1F6, RequestPledgeRankingList::new, ConnectionState.IN_GAME),
EX_ITEM_RESTORE_LIST(0x1F7, null, ConnectionState.IN_GAME),
EX_ITEM_RESTORE(0x1F8, null, ConnectionState.IN_GAME),
EX_MAX(0x1F9, null, ConnectionState.IN_GAME);

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network.clientpackets.ranking;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.ranking.ExOlympiadHeroAndLegendInfo;
@@ -35,6 +36,12 @@ public class RequestOlympiadHeroAndLegendInfo implements IClientIncomingPacket
@Override
public void run(GameClient client)
{
client.sendPacket(new ExOlympiadHeroAndLegendInfo());
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new ExOlympiadHeroAndLegendInfo());
}
}

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network.clientpackets.ranking;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.ranking.ExOlympiadMyRankingInfo;
@@ -35,6 +36,12 @@ public class RequestOlympiadMyRankingInfo implements IClientIncomingPacket
@Override
public void run(GameClient client)
{
client.sendPacket(new ExOlympiadMyRankingInfo(client.getPlayer()));
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new ExOlympiadMyRankingInfo(player));
}
}

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network.clientpackets.ranking;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.ranking.ExOlympiadRankingInfo;
@@ -46,6 +47,12 @@ public class RequestOlympiadRankingInfo implements IClientIncomingPacket
@Override
public void run(GameClient client)
{
client.sendPacket(new ExOlympiadRankingInfo(client.getPlayer(), _tabId, _rankingType, _unk, _classId, _serverId));
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new ExOlympiadRankingInfo(player, _tabId, _rankingType, _unk, _classId, _serverId));
}
}

View File

@@ -0,0 +1,56 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.network.clientpackets.ranking;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.ranking.ExPetRankingList;
/**
* Written by Berezkin Nikolay, on 10.05.2021
*/
public class RequestPetRankingList implements IClientIncomingPacket
{
private int _season;
private int _tabId;
private int _type;
private int _race;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_season = packet.readC();
_tabId = packet.readC();
_type = packet.readC();
_race = packet.readD();
return true;
}
@Override
public void run(GameClient client)
{
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new ExPetRankingList(player, _season, _tabId, _type, _race));
}
}

View File

@@ -0,0 +1,50 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.network.clientpackets.ranking;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.ranking.ExPetRankingMyInfo;
/**
* Written by Berezkin Nikolay, on 10.05.2021
*/
public class RequestPetRankingMyInfo implements IClientIncomingPacket
{
private int _petId;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_petId = packet.readD();
return true;
}
@Override
public void run(GameClient client)
{
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new ExPetRankingMyInfo(player, _petId));
}
}

View File

@@ -0,0 +1,50 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.network.clientpackets.ranking;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.ranking.ExPledgeRankingList;
/**
* Written by Berezkin Nikolay, on 16.05.2021
*/
public class RequestPledgeRankingList implements IClientIncomingPacket
{
private int _category;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_category = packet.readC();
return true;
}
@Override
public void run(GameClient client)
{
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new ExPledgeRankingList(player, _category));
}
}

View File

@@ -0,0 +1,47 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.network.clientpackets.ranking;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.ranking.ExPledgeRankingMyInfo;
/**
* Written by Berezkin Nikolay, on 16.05.2021
*/
public class RequestPledgeRankingMyInfo implements IClientIncomingPacket
{
@Override
public boolean read(GameClient client, PacketReader packet)
{
return true;
}
@Override
public void run(GameClient client)
{
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new ExPledgeRankingMyInfo(player));
}
}

View File

@@ -0,0 +1,56 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.network.clientpackets.ranking;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.ranking.ExPvpRankingList;
/**
* Written by Berezkin Nikolay, on 10.05.2021
*/
public class RequestPvpRankingList implements IClientIncomingPacket
{
private int _season;
private int _tabId;
private int _type;
private int _race;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_season = packet.readC();
_tabId = packet.readC();
_type = packet.readC();
_race = packet.readD();
return true;
}
@Override
public void run(GameClient client)
{
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new ExPvpRankingList(player, _season, _tabId, _type, _race));
}
}

View File

@@ -0,0 +1,47 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.network.clientpackets.ranking;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.ranking.ExPvpRankingMyInfo;
/**
* Written by Berezkin Nikolay, on 10.05.2021
*/
public class RequestPvpRankingMyInfo implements IClientIncomingPacket
{
@Override
public boolean read(GameClient client, PacketReader packet)
{
return true;
}
@Override
public void run(GameClient client)
{
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new ExPvpRankingMyInfo(player));
}
}

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network.clientpackets.ranking;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.ranking.ExRankingCharInfo;
@@ -38,6 +39,12 @@ public class RequestRankingCharInfo implements IClientIncomingPacket
@Override
public void run(GameClient client)
{
client.sendPacket(new ExRankingCharInfo(client.getPlayer(), _unk));
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new ExRankingCharInfo(player, _unk));
}
}

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network.clientpackets.ranking;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.ranking.ExRankingCharRankers;
@@ -42,6 +43,12 @@ public class RequestRankingCharRankers implements IClientIncomingPacket
@Override
public void run(GameClient client)
{
client.sendPacket(new ExRankingCharRankers(client.getPlayer(), _group, _scope, _race));
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new ExRankingCharRankers(player, _group, _scope, _race));
}
}

View File

@@ -75,16 +75,7 @@ public class ExOlympiadHeroAndLegendInfo implements IClientOutgoingPacket
}
packet.writeD(Config.SERVER_ID);
packet.writeD(rset.getInt("race"));
// a stupid, client uses 0 for female and 1 for male, while server no.
final int sex = rset.getInt("sex");
if (sex == 1)
{
packet.writeD(0);
}
else
{
packet.writeD(1);
}
packet.writeD(rset.getInt("sex") == 1 ? 0 : 1);
packet.writeD(rset.getInt("base_class"));
packet.writeD(rset.getInt("level"));
packet.writeD(rset.getInt("legend_count"));
@@ -121,16 +112,7 @@ public class ExOlympiadHeroAndLegendInfo implements IClientOutgoingPacket
}
packet.writeD(Config.SERVER_ID);
packet.writeD(rset.getInt("race"));
// a stupid, client uses 0 for female and 1 for male, while server no.
final int sex = rset.getInt("sex");
if (sex == 1)
{
packet.writeD(0);
}
else
{
packet.writeD(1);
}
packet.writeD(rset.getInt("sex") == 1 ? 0 : 1);
packet.writeD(rset.getInt("base_class"));
packet.writeD(rset.getInt("level"));
packet.writeD(rset.getInt("count"));

View File

@@ -61,116 +61,96 @@ public class ExOlympiadMyRankingInfo implements IClientOutgoingPacket
int year = calendar.get(Calendar.YEAR);
// Add one to month {0 - 11}
int month = calendar.get(Calendar.MONTH) + 1;
if (Olympiad.getInstance().getCurrentCycle() > 1)
if (month == 1)
{
if (month == 1)
{
year--;
month = 12;
}
else
{
month--;
}
int currentPlace = 0;
int currentWins = 0;
int currentLoses = 0;
int currentPoints = 0;
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(GET_CURRENT_CYCLE_DATA))
{
statement.setInt(1, _player.getBaseClass());
try (ResultSet rset = statement.executeQuery())
{
int i = 1;
while (rset.next())
{
if (rset.getInt("charId") == _player.getObjectId())
{
currentPlace = i;
currentWins = rset.getInt("competitions_won");
currentLoses = rset.getInt("competitions_lost");
currentPoints = rset.getInt("olympiad_points");
}
i++;
}
}
}
catch (SQLException e)
{
LOGGER.warning("Olympiad my ranking: Couldnt load data: " + e.getMessage());
}
int previousPlace = 0;
int previousWins = 0;
int previousLoses = 0;
int previousPoints = 0;
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(GET_PREVIOUS_CYCLE_DATA))
{
statement.setInt(1, _player.getBaseClass());
try (ResultSet rset = statement.executeQuery())
{
int i = 1;
while (rset.next())
{
if (rset.getInt("charId") == _player.getObjectId())
{
previousPlace = i;
previousWins = rset.getInt("competitions_won");
previousLoses = rset.getInt("competitions_lost");
previousPoints = rset.getInt("olympiad_points");
}
i++;
}
}
}
catch (SQLException e)
{
LOGGER.warning("Olympiad my ranking: Couldnt load data: " + e.getMessage());
}
int heroCount = 0;
int legendCount = 0;
if (Hero.getInstance().getCompleteHeroes().containsKey(_player.getObjectId()))
{
final StatSet hero = Hero.getInstance().getCompleteHeroes().get(_player.getObjectId());
heroCount = hero.getInt("count", 0);
legendCount = hero.getInt("legend_count", 0);
}
packet.writeD(year); // Year
packet.writeD(month); // Month
packet.writeD(Olympiad.getInstance().getCurrentCycle() - 1); // cycle ?
packet.writeD(currentPlace); // Place on current cycle ?
packet.writeD(currentWins); // Wins
packet.writeD(currentLoses); // Loses
packet.writeD(currentPoints); // Points
packet.writeD(previousPlace); // Place on previous cycle
packet.writeD(previousWins); // win count & lose count previous cycle? lol
packet.writeD(previousLoses); // ??
packet.writeD(previousPoints); // Points on previous cycle
packet.writeD(heroCount); // Hero counts
packet.writeD(legendCount); // Legend counts
packet.writeD(0); // change to 1 causes shows nothing
year--;
month = 12;
}
else
{
packet.writeD(year); // Year
packet.writeD(month); // Month
packet.writeD(0); // cycle
packet.writeD(0); // ??
packet.writeD(0); // Wins
packet.writeD(0); // Loses
packet.writeD(0); // Points
packet.writeD(0); // Place on previous cycle
packet.writeD(0); // win count & lose count previous cycle? lol
packet.writeD(0); // ??
packet.writeD(0); // Points on previous cycle
packet.writeD(0); // Hero counts
packet.writeD(0); // Legend counts
packet.writeD(0); // change to 1 causes shows nothing
month--;
}
int currentPlace = 0;
int currentWins = 0;
int currentLoses = 0;
int currentPoints = 0;
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(GET_CURRENT_CYCLE_DATA))
{
statement.setInt(1, _player.getBaseClass());
try (ResultSet rset = statement.executeQuery())
{
int i = 1;
while (rset.next())
{
if (rset.getInt("charId") == _player.getObjectId())
{
currentPlace = i;
currentWins = rset.getInt("competitions_won");
currentLoses = rset.getInt("competitions_lost");
currentPoints = rset.getInt("olympiad_points");
}
i++;
}
}
}
catch (SQLException e)
{
LOGGER.warning("Olympiad my ranking: Couldnt load data: " + e.getMessage());
}
int previousPlace = 0;
int previousWins = 0;
int previousLoses = 0;
int previousPoints = 0;
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(GET_PREVIOUS_CYCLE_DATA))
{
statement.setInt(1, _player.getBaseClass());
try (ResultSet rset = statement.executeQuery())
{
int i = 1;
while (rset.next())
{
if (rset.getInt("charId") == _player.getObjectId())
{
previousPlace = i;
previousWins = rset.getInt("competitions_won");
previousLoses = rset.getInt("competitions_lost");
previousPoints = rset.getInt("olympiad_points");
}
i++;
}
}
}
catch (SQLException e)
{
LOGGER.warning("Olympiad my ranking: Couldnt load data: " + e.getMessage());
}
int heroCount = 0;
int legendCount = 0;
if (Hero.getInstance().getCompleteHeroes().containsKey(_player.getObjectId()))
{
final StatSet hero = Hero.getInstance().getCompleteHeroes().get(_player.getObjectId());
heroCount = hero.getInt("count", 0);
legendCount = hero.getInt("legend_count", 0);
}
packet.writeD(year); // Year
packet.writeD(month); // Month
packet.writeD(Math.min(Olympiad.getInstance().getCurrentCycle() - 1, 0)); // cycle ?
packet.writeD(currentPlace); // Place on current cycle ?
packet.writeD(currentWins); // Wins
packet.writeD(currentLoses); // Loses
packet.writeD(currentPoints); // Points
packet.writeD(previousPlace); // Place on previous cycle
packet.writeD(previousWins); // win count & lose count previous cycle? lol
packet.writeD(previousLoses); // ??
packet.writeD(previousPoints); // Points on previous cycle
packet.writeD(heroCount); // Hero counts
packet.writeD(legendCount); // Legend counts
packet.writeD(0); // change to 1 causes shows nothing
return true;
}
}

View File

@@ -16,11 +16,18 @@
*/
package org.l2jmobius.gameserver.network.serverpackets.ranking;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.l2jmobius.Config;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.enums.ClassId;
import org.l2jmobius.gameserver.enums.RankingOlympiadCategory;
import org.l2jmobius.gameserver.enums.RankingOlympiadScope;
import org.l2jmobius.gameserver.instancemanager.RankManager;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
@@ -28,12 +35,11 @@ import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
/**
* @author NviX
* @author Berezkin Nikolay
*/
public class ExOlympiadRankingInfo implements IClientOutgoingPacket
{
private final PlayerInstance _player;
private final int _tabId;
private final int _rankingType;
private final int _unk;
@@ -68,233 +74,102 @@ public class ExOlympiadRankingInfo implements IClientOutgoingPacket
if (_playerList.size() > 0)
{
switch (_tabId)
{
case 0:
{
if (_rankingType == 0)
{
packet.writeD(_playerList.size() > 100 ? 100 : _playerList.size());
for (Integer id : _playerList.keySet())
{
final StatSet player = _playerList.get(id);
packet.writeString(player.getString("name")); // name
packet.writeString(player.getString("clanName")); // clan name
packet.writeD(id); // rank
if (_snapshotList.size() > 0)
{
for (Integer id2 : _snapshotList.keySet())
{
final StatSet snapshot = _snapshotList.get(id2);
if (player.getInt("charId") == snapshot.getInt("charId"))
{
packet.writeD(id2); // previous rank
}
}
}
else
{
packet.writeD(id);
}
packet.writeD(Config.SERVER_ID);// server id
packet.writeD(player.getInt("level"));// level
packet.writeD(player.getInt("classId"));// class id
packet.writeD(player.getInt("clanLevel"));// clan level
packet.writeD(player.getInt("competitions_won"));// win count
packet.writeD(player.getInt("competitions_lost"));// lose count
packet.writeD(player.getInt("olympiad_points"));// points
packet.writeD(player.getInt("count"));// hero counts
packet.writeD(player.getInt("legend_count"));// legend counts
}
}
else
{
boolean found = false;
for (Integer id : _playerList.keySet())
{
final StatSet player = _playerList.get(id);
if (player.getInt("charId") == _player.getObjectId())
{
found = true;
final int first = id > 10 ? (id - 9) : 1;
final int last = _playerList.size() >= (id + 10) ? id + 10 : id + (_playerList.size() - id);
if (first == 1)
{
packet.writeD(last - (first - 1));
}
else
{
packet.writeD(last - first);
}
for (int id2 = first; id2 <= last; id2++)
{
final StatSet plr = _playerList.get(id2);
packet.writeString(plr.getString("name"));
packet.writeString(plr.getString("clanName"));
packet.writeD(id2);
if (_snapshotList.size() > 0)
{
for (Integer id3 : _snapshotList.keySet())
{
final StatSet snapshot = _snapshotList.get(id3);
if (player.getInt("charId") == snapshot.getInt("charId"))
{
packet.writeD(id3); // class rank snapshot
}
}
}
else
{
packet.writeD(id2);
}
packet.writeD(Config.SERVER_ID);
packet.writeD(plr.getInt("level"));
packet.writeD(plr.getInt("classId"));
packet.writeD(plr.getInt("clanLevel"));// clan level
packet.writeD(plr.getInt("competitions_won"));// win count
packet.writeD(plr.getInt("competitions_lost"));// lose count
packet.writeD(plr.getInt("olympiad_points"));// points
packet.writeD(plr.getInt("count"));// hero counts
packet.writeD(plr.getInt("legend_count"));// legend counts
}
}
}
if (!found)
{
packet.writeD(0);
}
}
break;
}
case 1:
{
if (_rankingType == 0)
{
int count = 0;
for (int i = 1; i <= _playerList.size(); i++)
{
final StatSet player = _playerList.get(i);
if (_classId == player.getInt("classId"))
{
count++;
}
}
packet.writeD(count > 50 ? 50 : count);
int i = 1;
for (Integer id : _playerList.keySet())
{
final StatSet player = _playerList.get(id);
if (_classId == player.getInt("classId"))
{
packet.writeString(player.getString("name"));
packet.writeString(player.getString("clanName"));
packet.writeD(i); // class rank
if (_snapshotList.size() > 0)
{
final Map<Integer, StatSet> snapshotRaceList = new ConcurrentHashMap<>();
int j = 1;
for (Integer id2 : _snapshotList.keySet())
{
final StatSet snapshot = _snapshotList.get(id2);
if (_classId == snapshot.getInt("classId"))
{
snapshotRaceList.put(j, _snapshotList.get(id2));
j++;
}
}
for (Integer id2 : snapshotRaceList.keySet())
{
final StatSet snapshot = snapshotRaceList.get(id2);
if (player.getInt("charId") == snapshot.getInt("charId"))
{
packet.writeD(id2); // class rank snapshot
}
}
}
else
{
packet.writeD(i);
}
packet.writeD(Config.SERVER_ID);
packet.writeD(player.getInt("level"));
packet.writeD(player.getInt("classId"));
packet.writeD(player.getInt("clanLevel"));// clan level
packet.writeD(player.getInt("competitions_won"));// win count
packet.writeD(player.getInt("competitions_lost"));// lose count
packet.writeD(player.getInt("olympiad_points"));// points
packet.writeD(player.getInt("count"));// hero counts
packet.writeD(player.getInt("legend_count"));// legend counts
i++;
}
}
}
else
{
boolean found = false;
final Map<Integer, StatSet> classList = new ConcurrentHashMap<>();
int i = 1;
for (Integer id : _playerList.keySet())
{
final StatSet set = _playerList.get(id);
if (_player.getBaseClass() == set.getInt("classId"))
{
classList.put(i, _playerList.get(id));
i++;
}
}
for (Integer id : classList.keySet())
{
final StatSet player = classList.get(id);
if (player.getInt("charId") == _player.getObjectId())
{
found = true;
final int first = id > 10 ? (id - 9) : 1;
final int last = classList.size() >= (id + 10) ? id + 10 : id + (classList.size() - id);
if (first == 1)
{
packet.writeD(last - (first - 1));
}
else
{
packet.writeD(last - first);
}
for (int id2 = first; id2 <= last; id2++)
{
final StatSet plr = classList.get(id2);
packet.writeString(plr.getString("name"));
packet.writeString(plr.getString("clanName"));
packet.writeD(id2); // class rank
packet.writeD(id2);
packet.writeD(Config.SERVER_ID);
packet.writeD(player.getInt("level"));
packet.writeD(player.getInt("classId"));
packet.writeD(player.getInt("clanLevel"));// clan level
packet.writeD(player.getInt("competitions_won"));// win count
packet.writeD(player.getInt("competitions_lost"));// lose count
packet.writeD(player.getInt("olympiad_points"));// points
packet.writeD(player.getInt("count"));// hero counts
packet.writeD(player.getInt("legend_count"));// legend counts
}
}
}
if (!found)
{
packet.writeD(0);
}
}
break;
}
}
final RankingOlympiadCategory category = RankingOlympiadCategory.values()[_tabId];
writeFilteredRankingData(packet, category, category.getScopeByGroup(_rankingType), ClassId.getClassId(_classId));
}
return true;
}
private void writeFilteredRankingData(PacketWriter packet, RankingOlympiadCategory category, RankingOlympiadScope scope, ClassId classId)
{
switch (category)
{
case SERVER:
{
writeScopeData(packet, scope, new ArrayList<>(_playerList.entrySet()), new ArrayList<>(_snapshotList.entrySet()));
break;
}
case CLASS:
{
writeScopeData(packet, scope, _playerList.entrySet().stream().filter(it -> it.getValue().getInt("classId") == classId.getId()).collect(Collectors.toList()), _snapshotList.entrySet().stream().filter(it -> it.getValue().getInt("classId") == classId.getId()).collect(Collectors.toList()));
break;
}
}
}
private void writeScopeData(PacketWriter packet, RankingOlympiadScope scope, List<Entry<Integer, StatSet>> list, List<Entry<Integer, StatSet>> snapshot)
{
Entry<Integer, StatSet> playerData = list.stream().filter(it -> it.getValue().getInt("charId", 0) == _player.getObjectId()).findFirst().orElse(null);
final int indexOf = list.indexOf(playerData);
final List<Entry<Integer, StatSet>> limited;
switch (scope)
{
case TOP_100:
{
limited = list.stream().limit(100).collect(Collectors.toList());
break;
}
case ALL:
{
limited = list;
break;
}
case TOP_50:
{
limited = list.stream().limit(50).collect(Collectors.toList());
break;
}
case SELF:
{
limited = playerData == null ? Collections.emptyList() : list.subList(Math.max(0, indexOf - 10), Math.min(list.size(), indexOf + 10));
break;
}
default:
{
limited = Collections.emptyList();
}
}
packet.writeD(limited.size());
int rank = 1;
for (Entry<Integer, StatSet> data : limited.stream().sorted(Entry.comparingByKey()).collect(Collectors.toList()))
{
int curRank = rank++;
final StatSet player = data.getValue();
packet.writeString(player.getString("name")); // name
packet.writeString(player.getString("clanName")); // clan name
packet.writeD(scope == RankingOlympiadScope.SELF ? data.getKey() : curRank); // rank
if (snapshot.size() > 0)
{
int snapshotRank = 1;
for (Entry<Integer, StatSet> ssData : snapshot.stream().sorted(Entry.comparingByKey()).collect(Collectors.toList()))
{
final StatSet snapshotData = ssData.getValue();
if (player.getInt("charId") == snapshotData.getInt("charId"))
{
packet.writeD(scope == RankingOlympiadScope.SELF ? ssData.getKey() : snapshotRank++); // previous rank
}
}
}
else
{
packet.writeD(scope == RankingOlympiadScope.SELF ? data.getKey() : curRank);
}
packet.writeD(Config.SERVER_ID); // server id
packet.writeD(player.getInt("level")); // level
packet.writeD(player.getInt("classId")); // class id
packet.writeD(player.getInt("clanLevel")); // clan level
packet.writeD(player.getInt("competitions_won")); // win count
packet.writeD(player.getInt("competitions_lost")); // lose count
packet.writeD(player.getInt("olympiad_points")); // points
packet.writeD(player.getInt("count")); // hero counts
packet.writeD(player.getInt("legend_count")); // legend counts
}
}
}

View File

@@ -0,0 +1,177 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.network.serverpackets.ranking;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.enums.RankingCategory;
import org.l2jmobius.gameserver.enums.RankingScope;
import org.l2jmobius.gameserver.instancemanager.RankManager;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
/**
* Written by Berezkin Nikolay, on 10.05.2021
*/
public class ExPetRankingList implements IClientOutgoingPacket
{
private final PlayerInstance _player;
private final int _season;
private final int _tabId;
private final int _type;
private final int _race;
private final Map<Integer, StatSet> _playerList;
private final Map<Integer, StatSet> _snapshotList;
public ExPetRankingList(PlayerInstance player, int season, int tabId, int type, int race)
{
_player = player;
_season = season;
_tabId = tabId;
_type = type;
_race = race;
_playerList = RankManager.getInstance().getPetRankList();
_snapshotList = RankManager.getInstance().getSnapshotPetRankList();
}
@Override
public boolean write(PacketWriter packet)
{
OutgoingPackets.EX_PET_RANKING_LIST.writeId(packet);
packet.writeC(_season);
packet.writeC(_tabId);
packet.writeC(_type);
packet.writeD(_race);
packet.writeC(0);
if ((_playerList.size() > 0) && (_type != 255) && (_race != 255))
{
final RankingCategory category = RankingCategory.values()[_season];
writeFilteredRankingData(packet, category, category.getScopeByGroup(_tabId));
}
else
{
packet.writeD(0);
}
return true;
}
private void writeFilteredRankingData(PacketWriter packet, RankingCategory category, RankingScope scope)
{
switch (category)
{
case SERVER:
{
writeScopeData(packet, scope, new ArrayList<>(_playerList.entrySet()), new ArrayList<>(_snapshotList.entrySet()));
break;
}
case RACE:
{
writeScopeData(packet, scope, _playerList.entrySet().stream().filter(it -> it.getValue().getInt("petType") == _type).collect(Collectors.toList()), _snapshotList.entrySet().stream().filter(it -> it.getValue().getInt("petType") == _type).collect(Collectors.toList()));
break;
}
case CLAN:
{
writeScopeData(packet, scope, _player.getClan() == null ? Collections.emptyList() : _playerList.entrySet().stream().filter(it -> it.getValue().getString("clanName").equals(_player.getClan().getName())).collect(Collectors.toList()), _player.getClan() == null ? Collections.emptyList() : _snapshotList.entrySet().stream().filter(it -> it.getValue().getString("clanName").equals(_player.getClan().getName())).collect(Collectors.toList()));
break;
}
case FRIEND:
{
writeScopeData(packet, scope, _playerList.entrySet().stream().filter(it -> _player.getFriendList().contains(it.getValue().getInt("charId"))).collect(Collectors.toList()), _snapshotList.entrySet().stream().filter(it -> _player.getFriendList().contains(it.getValue().getInt("charId"))).collect(Collectors.toList()));
break;
}
}
}
private void writeScopeData(PacketWriter packet, RankingScope scope, List<Entry<Integer, StatSet>> list, List<Entry<Integer, StatSet>> snapshot)
{
Entry<Integer, StatSet> playerData = list.stream().filter(it -> it.getValue().getInt("charId", 0) == _player.getObjectId()).findFirst().orElse(null);
final int indexOf = list.indexOf(playerData);
final List<Entry<Integer, StatSet>> limited;
switch (scope)
{
case TOP_100:
{
limited = list.stream().limit(100).collect(Collectors.toList());
break;
}
case ALL:
{
limited = list;
break;
}
case TOP_150:
{
limited = list.stream().limit(150).collect(Collectors.toList());
break;
}
case SELF:
{
limited = playerData == null ? Collections.emptyList() : list.subList(Math.max(0, indexOf - 10), Math.min(list.size(), indexOf + 10));
break;
}
default:
{
limited = Collections.emptyList();
}
}
packet.writeD(limited.size());
int rank = 1;
for (Entry<Integer, StatSet> data : limited.stream().sorted(Entry.comparingByKey()).collect(Collectors.toList()))
{
int curRank = rank++;
final StatSet player = data.getValue();
packet.writeH(0);
packet.writeString(player.getString("name"));
packet.writeString(player.getString("clanName"));
packet.writeD(player.getInt("exp"));
packet.writeH(player.getInt("petType"));
packet.writeH(player.getInt("petLevel"));
packet.writeH(3);
packet.writeH(player.getInt("level"));
packet.writeD(scope == RankingScope.SELF ? data.getKey() : curRank); // server rank
if (snapshot.size() > 0)
{
for (Entry<Integer, StatSet> ssData : snapshot.stream().sorted(Entry.comparingByKey()).collect(Collectors.toList()))
{
final StatSet snapshotData = ssData.getValue();
if (player.getInt("controlledItemObjId") == snapshotData.getInt("controlledItemObjId"))
{
packet.writeD(scope == RankingScope.SELF ? ssData.getKey() : curRank); // server rank snapshot
}
}
}
else
{
packet.writeD(scope == RankingScope.SELF ? data.getKey() : curRank); // server rank
}
}
}
}

View File

@@ -0,0 +1,111 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.network.serverpackets.ranking;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.data.xml.PetDataTable;
import org.l2jmobius.gameserver.instancemanager.RankManager;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
/**
* Written by Berezkin Nikolay, on 11.05.2021 00 00 00 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
public class ExPetRankingMyInfo implements IClientOutgoingPacket
{
private final int _petId;
private final PlayerInstance _player;
private final Optional<Entry<Integer, StatSet>> _ranking;
private final Optional<Entry<Integer, StatSet>> _snapshotRanking;
private final Map<Integer, StatSet> _rankingList;
private final Map<Integer, StatSet> _snapshotList;
public ExPetRankingMyInfo(PlayerInstance player, int petId)
{
_player = player;
_petId = petId;
_ranking = RankManager.getInstance().getPetRankList().entrySet().stream().filter(it -> it.getValue().getInt("controlledItemObjId") == petId).findFirst();
_snapshotRanking = RankManager.getInstance().getSnapshotPetRankList().entrySet().stream().filter(it -> it.getValue().getInt("controlledItemObjId") == petId).findFirst();
_rankingList = RankManager.getInstance().getPetRankList();
_snapshotList = RankManager.getInstance().getSnapshotPetRankList();
}
@Override
public boolean write(PacketWriter packet)
{
OutgoingPackets.EX_PET_RANKING_MY_INFO.writeId(packet);
packet.writeD(_petId);
packet.writeH(1);
packet.writeD(-1);
packet.writeD(0);
packet.writeD(_ranking.isPresent() ? _ranking.get().getKey() : 0); // server rank
packet.writeD(_snapshotRanking.isPresent() ? _snapshotRanking.get().getKey() : 0); // snapshot server rank
if (_petId > 0)
{
int typeRank = 1;
boolean found = false;
for (StatSet ss : _rankingList.values())
{
if (ss.getInt("petType", -1) == PetDataTable.getInstance().getTypeByIndex(_player.getPetEvolve(_petId).getIndex()))
{
if (ss.getInt("controlledItemObjId", -1) == _petId)
{
found = true;
packet.writeD(typeRank);
break;
}
typeRank++;
}
}
if (!found)
{
packet.writeD(0);
}
int snapshotTypeRank = 1;
boolean snapshotFound = false;
for (StatSet ss : _snapshotList.values())
{
if (ss.getInt("petType", -1) == PetDataTable.getInstance().getTypeByIndex(_player.getPetEvolve(_petId).getIndex()))
{
if (ss.getInt("controlledItemObjId", -1) == _petId)
{
snapshotFound = true;
packet.writeD(snapshotTypeRank);
break;
}
snapshotTypeRank++;
}
}
if (!snapshotFound)
{
packet.writeD(0);
}
}
else
{
packet.writeD(0);
packet.writeD(0);
}
return true;
}
}

View File

@@ -0,0 +1,99 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.network.serverpackets.ranking;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.data.sql.ClanTable;
import org.l2jmobius.gameserver.instancemanager.RankManager;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
/**
* Written by Berezkin Nikolay, on 16.05.2021
*/
public class ExPledgeRankingList implements IClientOutgoingPacket
{
private final PlayerInstance _player;
private final int _category;
private final Map<Integer, StatSet> _rankingClanList;
private final Map<Integer, StatSet> _snapshotClanList;
public ExPledgeRankingList(PlayerInstance player, int category)
{
_player = player;
_category = category;
_rankingClanList = RankManager.getInstance().getClanRankList();
_snapshotClanList = RankManager.getInstance().getSnapshotClanRankList();
}
@Override
public boolean write(PacketWriter packet)
{
OutgoingPackets.EX_PLEDGE_RANKING_LIST.writeId(packet);
packet.writeC(_category);
if (_rankingClanList.size() > 0)
{
writeScopeData(packet, _category == 0, new ArrayList<>(_rankingClanList.entrySet()), new ArrayList<>(_snapshotClanList.entrySet()));
}
else
{
packet.writeD(0);
}
return true;
}
private void writeScopeData(PacketWriter packet, boolean isTop150, List<Entry<Integer, StatSet>> list, List<Entry<Integer, StatSet>> snapshot)
{
Entry<Integer, StatSet> playerData = list.stream().filter(it -> it.getValue().getInt("clan_id", 0) == _player.getClanId()).findFirst().orElse(null);
final int indexOf = list.indexOf(playerData);
final List<Entry<Integer, StatSet>> limited = isTop150 ? list.stream().limit(150).collect(Collectors.toList()) : playerData == null ? Collections.emptyList() : list.subList(Math.max(0, indexOf - 10), Math.min(list.size(), indexOf + 10));
packet.writeD(limited.size());
int rank = 1;
for (Entry<Integer, StatSet> data : limited.stream().sorted(Entry.comparingByKey()).collect(Collectors.toList()))
{
int curRank = rank++;
final StatSet player = data.getValue();
packet.writeD(!isTop150 ? data.getKey() : curRank);
for (Entry<Integer, StatSet> ssData : snapshot.stream().sorted(Entry.comparingByKey()).collect(Collectors.toList()))
{
final StatSet snapshotData = ssData.getValue();
if (player.getInt("clan_id") == snapshotData.getInt("clan_id"))
{
packet.writeD(!isTop150 ? ssData.getKey() : curRank); // server rank snapshot
}
}
packet.writeString(player.getString("clan_name"));
packet.writeD(player.getInt("clan_level"));
packet.writeString(player.getString("char_name"));
packet.writeD(player.getInt("level"));
packet.writeD(ClanTable.getInstance().getClan(player.getInt("clan_id")) != null ? ClanTable.getInstance().getClan(player.getInt("clan_id")).getMembersCount() : 0);
packet.writeD(player.getInt("exp"));
}
}
}

View File

@@ -0,0 +1,46 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.network.serverpackets.ranking;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.instancemanager.RankManager;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
/**
* Written by Berezkin Nikolay, on 16.05.2021
*/
public class ExPledgeRankingMyInfo implements IClientOutgoingPacket
{
private final PlayerInstance _player;
public ExPledgeRankingMyInfo(PlayerInstance player)
{
_player = player;
}
@Override
public boolean write(PacketWriter packet)
{
OutgoingPackets.EX_PLEDGE_RANKING_MY_INFO.writeId(packet);
packet.writeD(_player.getClan() != null ? RankManager.getInstance().getClanRankList().entrySet().stream().anyMatch(it -> it.getValue().getInt("clan_id") == _player.getClanId()) ? RankManager.getInstance().getClanRankList().entrySet().stream().filter(it -> it.getValue().getInt("clan_id") == _player.getClanId()).findFirst().orElse(null).getKey() : 0 : 0); // rank
packet.writeD(_player.getClan() != null ? RankManager.getInstance().getSnapshotClanRankList().entrySet().stream().anyMatch(it -> it.getValue().getInt("clan_id") == _player.getClanId()) ? RankManager.getInstance().getSnapshotClanRankList().entrySet().stream().filter(it -> it.getValue().getInt("clan_id") == _player.getClanId()).findFirst().orElse(null).getKey() : 0 : 0); // snapshot
packet.writeD(_player.getClan() != null ? _player.getClan().getExp() : 0); // exp
return true;
}
}

View File

@@ -0,0 +1,178 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.network.serverpackets.ranking;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.enums.Race;
import org.l2jmobius.gameserver.enums.RankingCategory;
import org.l2jmobius.gameserver.enums.RankingScope;
import org.l2jmobius.gameserver.instancemanager.RankManager;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
/**
* Written by Berezkin Nikolay, on 10.05.2021
*/
public class ExPvpRankingList implements IClientOutgoingPacket
{
private final PlayerInstance _player;
private final int _season;
private final int _tabId;
private final int _type;
private final int _race;
private final Map<Integer, StatSet> _playerList;
private final Map<Integer, StatSet> _snapshotList;
public ExPvpRankingList(PlayerInstance player, int season, int tabId, int type, int race)
{
_player = player;
_season = season;
_tabId = tabId;
_type = type;
_race = race;
_playerList = RankManager.getInstance().getPvpRankList();
_snapshotList = RankManager.getInstance().getSnapshotPvpRankList();
}
@Override
public boolean write(PacketWriter packet)
{
OutgoingPackets.EX_PVP_RANKING_LIST.writeId(packet);
packet.writeC(_season);
packet.writeC(_tabId);
packet.writeC(_type);
packet.writeD(_race);
if ((_playerList.size() > 0) && (_type != 255) && (_race != 255))
{
final RankingCategory category = RankingCategory.values()[_tabId];
writeFilteredRankingData(packet, category, category.getScopeByGroup(_type), Race.values()[_race]);
}
else
{
packet.writeD(0);
}
return true;
}
private void writeFilteredRankingData(PacketWriter packet, RankingCategory category, RankingScope scope, Race race)
{
switch (category)
{
case SERVER:
{
writeScopeData(packet, scope, new ArrayList<>(_playerList.entrySet()), new ArrayList<>(_snapshotList.entrySet()));
break;
}
case RACE:
{
writeScopeData(packet, scope, _playerList.entrySet().stream().filter(it -> it.getValue().getInt("race") == race.ordinal()).collect(Collectors.toList()), _snapshotList.entrySet().stream().filter(it -> it.getValue().getInt("race") == race.ordinal()).collect(Collectors.toList()));
break;
}
case CLAN:
{
writeScopeData(packet, scope, _player.getClan() == null ? Collections.emptyList() : _playerList.entrySet().stream().filter(it -> it.getValue().getString("clanName").equals(_player.getClan().getName())).collect(Collectors.toList()), _player.getClan() == null ? Collections.emptyList() : _snapshotList.entrySet().stream().filter(it -> it.getValue().getString("clanName").equals(_player.getClan().getName())).collect(Collectors.toList()));
break;
}
case FRIEND:
{
writeScopeData(packet, scope, _playerList.entrySet().stream().filter(it -> _player.getFriendList().contains(it.getValue().getInt("charId"))).collect(Collectors.toList()), _snapshotList.entrySet().stream().filter(it -> _player.getFriendList().contains(it.getValue().getInt("charId"))).collect(Collectors.toList()));
break;
}
}
}
private void writeScopeData(PacketWriter packet, RankingScope scope, List<Entry<Integer, StatSet>> list, List<Entry<Integer, StatSet>> snapshot)
{
Entry<Integer, StatSet> playerData = list.stream().filter(it -> it.getValue().getInt("charId", 0) == _player.getObjectId()).findFirst().orElse(null);
final int indexOf = list.indexOf(playerData);
final List<Entry<Integer, StatSet>> limited;
switch (scope)
{
case TOP_100:
{
limited = list.stream().limit(100).collect(Collectors.toList());
break;
}
case ALL:
{
limited = list;
break;
}
case TOP_150:
{
limited = list.stream().limit(150).collect(Collectors.toList());
break;
}
case SELF:
{
limited = playerData == null ? Collections.emptyList() : list.subList(Math.max(0, indexOf - 10), Math.min(list.size(), indexOf + 10));
break;
}
default:
{
limited = Collections.emptyList();
}
}
packet.writeD(limited.size());
int rank = 1;
for (Entry<Integer, StatSet> data : limited.stream().sorted(Entry.comparingByKey()).collect(Collectors.toList()))
{
int curRank = rank++;
final StatSet player = data.getValue();
packet.writeString(player.getString("name"));
packet.writeString(player.getString("clanName"));
packet.writeD(player.getInt("level"));
packet.writeD(player.getInt("race"));
packet.writeD(player.getInt("classId"));
packet.writeQ(player.getInt("points")); // server rank
if (snapshot.size() > 0)
{
for (Entry<Integer, StatSet> ssData : snapshot.stream().sorted(Entry.comparingByKey()).collect(Collectors.toList()))
{
final StatSet snapshotData = ssData.getValue();
if (player.getInt("charId") == snapshotData.getInt("charId"))
{
packet.writeD(scope == RankingScope.SELF ? ssData.getKey() : curRank); // server rank snapshot
packet.writeD(snapshotData.getInt("raceRank", 0)); // race rank snapshot
packet.writeD(player.getInt("kills"));
packet.writeD(player.getInt("deaths"));
}
}
}
else
{
packet.writeD(scope == RankingScope.SELF ? data.getKey() : curRank);
packet.writeD(0);
packet.writeD(0);
packet.writeD(0);
}
}
}
}

View File

@@ -0,0 +1,85 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.network.serverpackets.ranking;
import java.util.Map;
import java.util.Optional;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.instancemanager.RankManager;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
/**
* Written by Berezkin Nikolay, on 10.05.2021
*/
public class ExPvpRankingMyInfo implements IClientOutgoingPacket
{
private final PlayerInstance _player;
private final Map<Integer, StatSet> _playerList;
private final Map<Integer, StatSet> _snapshotList;
public ExPvpRankingMyInfo(PlayerInstance player)
{
_player = player;
_playerList = RankManager.getInstance().getPvpRankList();
_snapshotList = RankManager.getInstance().getSnapshotPvpRankList();
}
@Override
public boolean write(PacketWriter packet)
{
OutgoingPackets.EX_PVP_RANKING_MY_INFO.writeId(packet);
if (_playerList.size() > 0)
{
boolean found = false;
for (Integer id : _playerList.keySet())
{
final StatSet ss = _playerList.get(id);
if (ss.getInt("charId") == _player.getObjectId())
{
final Optional<Map.Entry<Integer, StatSet>> snapshotValue = _snapshotList.entrySet().stream().filter(it -> it.getValue().getInt("charId") == _player.getObjectId()).findFirst();
found = true;
packet.writeQ(ss.getInt("points")); // pvp points
packet.writeD(id); // current rank
packet.writeD(snapshotValue.isPresent() ? snapshotValue.get().getKey() : id); // ingame shown change in rank as this value - current rank value.
packet.writeD(ss.getInt("kills")); // kills
packet.writeD(ss.getInt("deaths")); // deaths
}
}
if (!found)
{
packet.writeQ(0); // pvp points
packet.writeD(0); // current rank
packet.writeD(0); // ingame shown change in rank as this value - current rank value.
packet.writeD(0); // kills
packet.writeD(0); // deaths
}
}
else
{
packet.writeQ(0); // pvp points
packet.writeD(0); // current rank
packet.writeD(0); // ingame shown change in rank as this value - current rank value.
packet.writeD(0); // kills
packet.writeD(0); // deaths
}
return true;
}
}

View File

@@ -66,6 +66,8 @@ public class ExRankingCharInfo implements IClientOutgoingPacket
{
packet.writeD(id2); // server rank snapshot
packet.writeD(snapshot.getInt("raceRank")); // race rank snapshot
packet.writeD(0);
packet.writeD(0);
return true;
}
}

View File

@@ -16,11 +16,16 @@
*/
package org.l2jmobius.gameserver.network.serverpackets.ranking;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.enums.Race;
import org.l2jmobius.gameserver.enums.RankingCategory;
import org.l2jmobius.gameserver.enums.RankingScope;
import org.l2jmobius.gameserver.instancemanager.RankManager;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
@@ -28,7 +33,7 @@ import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
/**
* @author NviX
* @author Berezkin Nikolay
*/
public class ExRankingCharRankers implements IClientOutgoingPacket
{
@@ -61,361 +66,8 @@ public class ExRankingCharRankers implements IClientOutgoingPacket
if (_playerList.size() > 0)
{
switch (_group)
{
case 0: // all
{
if (_scope == 0) // all
{
final int count = _playerList.size() > 150 ? 150 : _playerList.size();
packet.writeD(count);
for (Integer id : _playerList.keySet())
{
final StatSet player = _playerList.get(id);
packet.writeString(player.getString("name"));
packet.writeString(player.getString("clanName"));
packet.writeD(player.getInt("level"));
packet.writeD(player.getInt("classId"));
packet.writeD(player.getInt("race"));
packet.writeD(id); // server rank
if (_snapshotList.size() > 0)
{
for (Integer id2 : _snapshotList.keySet())
{
final StatSet snapshot = _snapshotList.get(id2);
if (player.getInt("charId") == snapshot.getInt("charId"))
{
packet.writeD(id2); // server rank snapshot
packet.writeD(snapshot.getInt("raceRank", 0)); // race rank snapshot
packet.writeD(0); // TODO: nClassRank_Snapshot
}
}
}
else
{
packet.writeD(id);
packet.writeD(0);
packet.writeD(0);
}
}
}
else
{
boolean found = false;
for (Integer id : _playerList.keySet())
{
final StatSet player = _playerList.get(id);
if (player.getInt("charId") == _player.getObjectId())
{
found = true;
final int first = id > 10 ? (id - 9) : 1;
final int last = _playerList.size() >= (id + 10) ? id + 10 : id + (_playerList.size() - id);
if (first == 1)
{
packet.writeD(last - (first - 1));
}
else
{
packet.writeD(last - first);
}
for (int id2 = first; id2 <= last; id2++)
{
final StatSet plr = _playerList.get(id2);
packet.writeString(plr.getString("name"));
packet.writeString(plr.getString("clanName"));
packet.writeD(plr.getInt("level"));
packet.writeD(plr.getInt("classId"));
packet.writeD(plr.getInt("race"));
packet.writeD(id2); // server rank
if (_snapshotList.size() > 0)
{
for (Integer id3 : _snapshotList.keySet())
{
final StatSet snapshot = _snapshotList.get(id3);
if (player.getInt("charId") == snapshot.getInt("charId"))
{
packet.writeD(id3); // server rank snapshot
packet.writeD(snapshot.getInt("raceRank", 0));
packet.writeD(0); // TODO: nClassRank_Snapshot
}
}
}
}
}
}
if (!found)
{
packet.writeD(0);
}
}
break;
}
case 1: // race
{
if (_scope == 0) // all
{
int count = 0;
for (int i = 1; i <= _playerList.size(); i++)
{
final StatSet player = _playerList.get(i);
if (_race == player.getInt("race"))
{
count++;
}
}
packet.writeD(count > 100 ? 100 : count);
int i = 1;
for (Integer id : _playerList.keySet())
{
final StatSet player = _playerList.get(id);
if (_race == player.getInt("race"))
{
packet.writeString(player.getString("name"));
packet.writeString(player.getString("clanName"));
packet.writeD(player.getInt("level"));
packet.writeD(player.getInt("classId"));
packet.writeD(player.getInt("race"));
packet.writeD(i); // server rank
if (_snapshotList.size() > 0)
{
final Map<Integer, StatSet> snapshotRaceList = new ConcurrentHashMap<>();
int j = 1;
for (Integer id2 : _snapshotList.keySet())
{
final StatSet snapshot = _snapshotList.get(id2);
if (_race == snapshot.getInt("race"))
{
snapshotRaceList.put(j, _snapshotList.get(id2));
j++;
}
}
for (Integer id2 : snapshotRaceList.keySet())
{
final StatSet snapshot = snapshotRaceList.get(id2);
if (player.getInt("charId") == snapshot.getInt("charId"))
{
packet.writeD(id2); // server rank snapshot
packet.writeD(snapshot.getInt("raceRank", 0)); // race rank snapshot
packet.writeD(0); // TODO: nClassRank_Snapshot
}
}
}
else
{
packet.writeD(i);
packet.writeD(i);
packet.writeD(i); // TODO: Check this. nClassRank_Snapshot?
}
i++;
}
}
}
else
{
boolean found = false;
final Map<Integer, StatSet> raceList = new ConcurrentHashMap<>();
int i = 1;
for (Integer id : _playerList.keySet())
{
final StatSet set = _playerList.get(id);
if (_player.getRace().ordinal() == set.getInt("race"))
{
raceList.put(i, _playerList.get(id));
i++;
}
}
for (Integer id : raceList.keySet())
{
final StatSet player = raceList.get(id);
if (player.getInt("charId") == _player.getObjectId())
{
found = true;
final int first = id > 10 ? (id - 9) : 1;
final int last = raceList.size() >= (id + 10) ? id + 10 : id + (raceList.size() - id);
if (first == 1)
{
packet.writeD(last - (first - 1));
}
else
{
packet.writeD(last - first);
}
for (int id2 = first; id2 <= last; id2++)
{
final StatSet plr = raceList.get(id2);
packet.writeString(plr.getString("name"));
packet.writeString(plr.getString("clanName"));
packet.writeD(plr.getInt("level"));
packet.writeD(plr.getInt("classId"));
packet.writeD(plr.getInt("race"));
packet.writeD(id2); // server rank
packet.writeD(id2);
packet.writeD(id2);
packet.writeD(id2); // TODO: Check this. nClassRank_Snapshot?
}
}
}
if (!found)
{
packet.writeD(0);
}
}
break;
}
case 2: // clan
{
if (_player.getClan() != null)
{
final Map<Integer, StatSet> clanList = new ConcurrentHashMap<>();
int i = 1;
for (Integer id : _playerList.keySet())
{
final StatSet set = _playerList.get(id);
if (_player.getClan().getName() == set.getString("clanName"))
{
clanList.put(i, _playerList.get(id));
i++;
}
}
packet.writeD(clanList.size());
for (Integer id : clanList.keySet())
{
final StatSet player = clanList.get(id);
packet.writeString(player.getString("name"));
packet.writeString(player.getString("clanName"));
packet.writeD(player.getInt("level"));
packet.writeD(player.getInt("classId"));
packet.writeD(player.getInt("race"));
packet.writeD(id); // clan rank
if (_snapshotList.size() > 0)
{
for (Integer id2 : _snapshotList.keySet())
{
final StatSet snapshot = _snapshotList.get(id2);
if (player.getInt("charId") == snapshot.getInt("charId"))
{
packet.writeD(id2); // server rank snapshot
packet.writeD(snapshot.getInt("raceRank", 0)); // race rank snapshot
packet.writeD(0); // TODO: nClassRank_Snapshot
}
}
}
else
{
packet.writeD(id);
packet.writeD(0);
packet.writeD(0);
}
}
}
else
{
packet.writeD(0);
}
break;
}
case 3: // friend
{
if (_player.getFriendList().size() > 0)
{
final Set<Integer> friendList = ConcurrentHashMap.newKeySet();
int count = 1;
for (int id : _player.getFriendList())
{
for (Integer id2 : _playerList.keySet())
{
final StatSet temp = _playerList.get(id2);
if (temp.getInt("charId") == id)
{
friendList.add(temp.getInt("charId"));
count++;
}
}
}
friendList.add(_player.getObjectId());
packet.writeD(count);
for (int id : _playerList.keySet())
{
final StatSet player = _playerList.get(id);
if (friendList.contains(player.getInt("charId")))
{
packet.writeString(player.getString("name"));
packet.writeString(player.getString("clanName"));
packet.writeD(player.getInt("level"));
packet.writeD(player.getInt("classId"));
packet.writeD(player.getInt("race"));
packet.writeD(id); // friend rank
if (_snapshotList.size() > 0)
{
for (Integer id2 : _snapshotList.keySet())
{
final StatSet snapshot = _snapshotList.get(id2);
if (player.getInt("charId") == snapshot.getInt("charId"))
{
packet.writeD(id2); // server rank snapshot
packet.writeD(snapshot.getInt("raceRank", 0)); // race rank snapshot
packet.writeD(0); // TODO: nClassRank_Snapshot
}
}
}
else
{
packet.writeD(id);
packet.writeD(0);
packet.writeD(0);
}
}
}
}
else
{
packet.writeD(1);
packet.writeString(_player.getName());
if (_player.getClan() != null)
{
packet.writeString(_player.getClan().getName());
}
else
{
packet.writeString("");
}
packet.writeD(_player.getStat().getBaseLevel());
packet.writeD(_player.getBaseClass());
packet.writeD(_player.getRace().ordinal());
packet.writeD(1); // clan rank
if (_snapshotList.size() > 0)
{
for (Integer id : _snapshotList.keySet())
{
final StatSet snapshot = _snapshotList.get(id);
if (_player.getObjectId() == snapshot.getInt("charId"))
{
packet.writeD(id); // server rank snapshot
packet.writeD(snapshot.getInt("raceRank", 0)); // race rank snapshot
packet.writeD(0); // TODO: nClassRank_Snapshot
}
}
}
else
{
packet.writeD(0);
packet.writeD(0);
packet.writeD(0);
}
}
break;
}
}
final RankingCategory category = RankingCategory.values()[_group];
writeFilteredRankingData(packet, category, category.getScopeByGroup(_scope), Race.values()[_race]);
}
else
{
@@ -423,4 +75,64 @@ public class ExRankingCharRankers implements IClientOutgoingPacket
}
return true;
}
private void writeFilteredRankingData(PacketWriter packet, RankingCategory category, RankingScope scope, Race race)
{
switch (category)
{
case SERVER -> writeScopeData(packet, scope, new ArrayList<>(_playerList.entrySet()), new ArrayList<>(_snapshotList.entrySet()));
case RACE -> writeScopeData(packet, scope, _playerList.entrySet().stream().filter(it -> it.getValue().getInt("race") == race.ordinal()).collect(Collectors.toList()), _snapshotList.entrySet().stream().filter(it -> it.getValue().getInt("race") == race.ordinal()).collect(Collectors.toList()));
case CLAN -> writeScopeData(packet, scope, _player.getClan() == null ? Collections.emptyList() : _playerList.entrySet().stream().filter(it -> it.getValue().getString("clanName").equals(_player.getClan().getName())).collect(Collectors.toList()), _player.getClan() == null ? Collections.emptyList() : _snapshotList.entrySet().stream().filter(it -> it.getValue().getString("clanName").equals(_player.getClan().getName())).collect(Collectors.toList()));
case FRIEND -> writeScopeData(packet, scope, _playerList.entrySet().stream().filter(it -> _player.getFriendList().contains(it.getValue().getInt("charId"))).collect(Collectors.toList()), _snapshotList.entrySet().stream().filter(it -> _player.getFriendList().contains(it.getValue().getInt("charId"))).collect(Collectors.toList()));
}
}
private void writeScopeData(PacketWriter packet, RankingScope scope, List<Map.Entry<Integer, StatSet>> list, List<Map.Entry<Integer, StatSet>> snapshot)
{
Map.Entry<Integer, StatSet> playerData = list.stream().filter(it -> it.getValue().getInt("charId", 0) == _player.getObjectId()).findFirst().orElse(null);
final int indexOf = list.indexOf(playerData);
final List<Map.Entry<Integer, StatSet>> limited = switch (scope)
{
case TOP_100 -> list.stream().limit(100).collect(Collectors.toList());
case ALL -> list;
case TOP_150 -> list.stream().limit(150).collect(Collectors.toList());
case SELF -> playerData == null ? Collections.emptyList() : list.subList(Math.max(0, indexOf - 10), Math.min(list.size(), indexOf + 10));
};
packet.writeD(limited.size());
int rank = 1;
for (Map.Entry<Integer, StatSet> data : limited.stream().sorted(Map.Entry.comparingByKey()).collect(Collectors.toList()))
{
int curRank = rank++;
final StatSet player = data.getValue();
packet.writeString(player.getString("name"));
packet.writeString(player.getString("clanName"));
packet.writeD(player.getInt("level"));
packet.writeD(player.getInt("classId"));
packet.writeD(player.getInt("race"));
packet.writeD(scope == RankingScope.SELF ? data.getKey() : curRank); // server rank
if (snapshot.size() > 0)
{
int snapshotRank = 1;
for (Map.Entry<Integer, StatSet> ssData : snapshot.stream().sorted(Map.Entry.comparingByKey()).collect(Collectors.toList()))
{
final StatSet snapshotData = ssData.getValue();
if (player.getInt("charId") == snapshotData.getInt("charId"))
{
packet.writeD(scope == RankingScope.SELF ? ssData.getKey() : snapshotRank++); // server rank snapshot
packet.writeD(snapshotData.getInt("raceRank", 0)); // race rank snapshot
packet.writeD(0); // TODO: nClassRank_Snapshot
}
}
}
else
{
packet.writeD(scope == RankingScope.SELF ? data.getKey() : curRank);
packet.writeD(0);
packet.writeD(0);
}
}
}
}