From 01bb57d197d81011522dc333b5cec204eb2eca97 Mon Sep 17 00:00:00 2001 From: mobius <8391001+MobiusDevelopment@users.noreply.github.com> Date: Thu, 15 Jan 2015 02:08:27 +0000 Subject: [PATCH] Faction balance online players. --- trunk/dist/game/config/Custom.properties | 10 +++++++- .../html/mods/Faction/ExceededOnlineLimit.htm | 3 +++ .../custom/FactionManager/FactionManager.java | 22 +++++++++++++++++ .../custom/FactionManager/onlinelimit.html | 5 ++++ trunk/java/com/l2jserver/Config.java | 6 ++++- .../model/CharSelectInfoPackage.java | 24 +++++++++++++++++++ .../clientpackets/CharacterSelect.java | 23 ++++++++++++++++++ .../serverpackets/AbstractHtmlPacket.java | 5 ++++ .../serverpackets/CharSelectionInfo.java | 10 ++++++++ 9 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 trunk/dist/game/data/html/mods/Faction/ExceededOnlineLimit.htm create mode 100644 trunk/dist/game/data/scripts/custom/FactionManager/onlinelimit.html diff --git a/trunk/dist/game/config/Custom.properties b/trunk/dist/game/config/Custom.properties index cea7c226de..3175b77242 100644 --- a/trunk/dist/game/config/Custom.properties +++ b/trunk/dist/game/config/Custom.properties @@ -667,10 +667,18 @@ EnableFactionGuards = True # Default: True RespawnAtFactionBase = True -# Disable chat between factions. +# Disallow chat between factions. # Default: True EnableFactionChat = True +# Prohibit login when faction has more online players. +# Default: True +BalanceOnlinePlayers = True + +# Online player exceed limit (used by setting above). +# Default: 20 +BalancePlayerExceedLimit = 20 + # --------------------------------------------------------------------------- # Premium System (VIP) diff --git a/trunk/dist/game/data/html/mods/Faction/ExceededOnlineLimit.htm b/trunk/dist/game/data/html/mods/Faction/ExceededOnlineLimit.htm new file mode 100644 index 0000000000..858aa73517 --- /dev/null +++ b/trunk/dist/game/data/html/mods/Faction/ExceededOnlineLimit.htm @@ -0,0 +1,3 @@ +RestrictionIt seems that there are currently more %more% than %less% players online.
+Try selecting an opposing faction character or wait for some %more% players to logout. + \ No newline at end of file diff --git a/trunk/dist/game/data/scripts/custom/FactionManager/FactionManager.java b/trunk/dist/game/data/scripts/custom/FactionManager/FactionManager.java index 89626eb5c4..0a508827bb 100644 --- a/trunk/dist/game/data/scripts/custom/FactionManager/FactionManager.java +++ b/trunk/dist/game/data/scripts/custom/FactionManager/FactionManager.java @@ -63,6 +63,17 @@ public class FactionManager extends AbstractNpcAI { case "selectGoodFaction": { + if (Config.FACTION_BALANCE_ONLINE_PLAYERS && (L2World.getInstance().getAllGoodPlayersCount() >= ((L2World.getInstance().getAllEvilPlayersCount() + Config.FACTION_BALANCE_PLAYER_EXCEED_LIMIT)))) + { + String htmltext = null; + final NpcHtmlMessage packet = new NpcHtmlMessage(npc.getObjectId()); + packet.setHtml(getHtm(player.getHtmlPrefix(), "onlinelimit.html")); + packet.replace("%name%", player.getName()); + packet.replace("%more%", Config.FACTION_GOOD_TEAM_NAME); + packet.replace("%less%", Config.FACTION_EVIL_TEAM_NAME); + player.sendPacket(packet); + return htmltext; + } player.setGood(); player.getAppearance().setNameColor(Config.FACTION_GOOD_NAME_COLOR); player.getAppearance().setTitleColor(Config.FACTION_GOOD_NAME_COLOR); @@ -75,6 +86,17 @@ public class FactionManager extends AbstractNpcAI } case "selectEvilFaction": { + if (Config.FACTION_BALANCE_ONLINE_PLAYERS && (L2World.getInstance().getAllEvilPlayersCount() >= ((L2World.getInstance().getAllGoodPlayersCount() + Config.FACTION_BALANCE_PLAYER_EXCEED_LIMIT)))) + { + String htmltext = null; + final NpcHtmlMessage packet = new NpcHtmlMessage(npc.getObjectId()); + packet.setHtml(getHtm(player.getHtmlPrefix(), "onlinelimit.html")); + packet.replace("%name%", player.getName()); + packet.replace("%more%", Config.FACTION_EVIL_TEAM_NAME); + packet.replace("%less%", Config.FACTION_GOOD_TEAM_NAME); + player.sendPacket(packet); + return htmltext; + } player.setEvil(); player.getAppearance().setNameColor(Config.FACTION_EVIL_NAME_COLOR); player.getAppearance().setTitleColor(Config.FACTION_EVIL_NAME_COLOR); diff --git a/trunk/dist/game/data/scripts/custom/FactionManager/onlinelimit.html b/trunk/dist/game/data/scripts/custom/FactionManager/onlinelimit.html new file mode 100644 index 0000000000..0f9fa95cc6 --- /dev/null +++ b/trunk/dist/game/data/scripts/custom/FactionManager/onlinelimit.html @@ -0,0 +1,5 @@ +Faction Manager:
+I am sorry %name%. +It seems that there are currently more %more% than %less% players online.
+Try selecting the opposing faction or wait for some %more% players to logout. + \ No newline at end of file diff --git a/trunk/java/com/l2jserver/Config.java b/trunk/java/com/l2jserver/Config.java index 4e0b063e3d..db7042dcb0 100644 --- a/trunk/java/com/l2jserver/Config.java +++ b/trunk/java/com/l2jserver/Config.java @@ -834,6 +834,8 @@ public final class Config public static boolean FACTION_GUARDS_ENABLED; public static boolean FACTION_RESPAWN_AT_BASE; public static boolean FACTION_SPECIFIC_CHAT; + public static boolean FACTION_BALANCE_ONLINE_PLAYERS; + public static int FACTION_BALANCE_PLAYER_EXCEED_LIMIT; public static boolean PREMIUM_SYSTEM_ENABLED; public static float PREMIUM_RATE_XP; public static float PREMIUM_RATE_SP; @@ -2655,7 +2657,9 @@ public final class Config FACTION_EVIL_NAME_COLOR = Integer.decode("0x" + CustomSettings.getString("EvilNameColor", "0000FF")); FACTION_GUARDS_ENABLED = CustomSettings.getBoolean("EnableFactionGuards", true); FACTION_RESPAWN_AT_BASE = CustomSettings.getBoolean("RespawnAtFactionBase", true); - FACTION_SPECIFIC_CHAT = Boolean.valueOf(CustomSettings.getBoolean("EnableFactionChat", true)); + FACTION_SPECIFIC_CHAT = CustomSettings.getBoolean("EnableFactionChat", true); + FACTION_BALANCE_ONLINE_PLAYERS = CustomSettings.getBoolean("BalanceOnlinePlayers", true); + FACTION_BALANCE_PLAYER_EXCEED_LIMIT = CustomSettings.getInt("BalancePlayerExceedLimit", 20); PREMIUM_SYSTEM_ENABLED = CustomSettings.getBoolean("EnablePremiumSystem", false); PREMIUM_RATE_XP = CustomSettings.getFloat("PremiumRateXp", 2); diff --git a/trunk/java/com/l2jserver/gameserver/model/CharSelectInfoPackage.java b/trunk/java/com/l2jserver/gameserver/model/CharSelectInfoPackage.java index 1fa8670df1..ddc95c9666 100644 --- a/trunk/java/com/l2jserver/gameserver/model/CharSelectInfoPackage.java +++ b/trunk/java/com/l2jserver/gameserver/model/CharSelectInfoPackage.java @@ -59,6 +59,8 @@ public class CharSelectInfoPackage private String _htmlPrefix = null; private int _vitalityPoints = 0; private int _accessLevel = 0; + private boolean _isGood = false; + private boolean _isEvil = false; private final PlayerVariables _vars; /** @@ -103,6 +105,28 @@ public class CharSelectInfoPackage _accessLevel = level; } + public boolean isGood() + { + return _isGood; + } + + public void setGood() + { + _isGood = true; + _isEvil = false; + } + + public boolean isEvil() + { + return _isEvil; + } + + public void setEvil() + { + _isGood = false; + _isEvil = true; + } + public int getClanId() { return _clanId; diff --git a/trunk/java/com/l2jserver/gameserver/network/clientpackets/CharacterSelect.java b/trunk/java/com/l2jserver/gameserver/network/clientpackets/CharacterSelect.java index 5884e02e55..bdb78bda59 100644 --- a/trunk/java/com/l2jserver/gameserver/network/clientpackets/CharacterSelect.java +++ b/trunk/java/com/l2jserver/gameserver/network/clientpackets/CharacterSelect.java @@ -28,6 +28,7 @@ import com.l2jserver.gameserver.datatables.SecondaryAuthData; import com.l2jserver.gameserver.instancemanager.AntiFeedManager; import com.l2jserver.gameserver.instancemanager.PunishmentManager; import com.l2jserver.gameserver.model.CharSelectInfoPackage; +import com.l2jserver.gameserver.model.L2World; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import com.l2jserver.gameserver.model.events.Containers; import com.l2jserver.gameserver.model.events.EventDispatcher; @@ -126,6 +127,28 @@ public class CharacterSelect extends L2GameClientPacket return; } + if (Config.FACTION_SYSTEM_ENABLED && Config.FACTION_BALANCE_ONLINE_PLAYERS) + { + if (info.isGood() && (L2World.getInstance().getAllGoodPlayersCount() >= ((L2World.getInstance().getAllEvilPlayersCount() + Config.FACTION_BALANCE_PLAYER_EXCEED_LIMIT)))) + { + final NpcHtmlMessage msg = new NpcHtmlMessage(); + msg.setFile(info.getHtmlPrefix(), "data/html/mods/Faction/ExceededOnlineLimit.htm"); + msg.replace("%more%", Config.FACTION_GOOD_TEAM_NAME); + msg.replace("%less%", Config.FACTION_EVIL_TEAM_NAME); + client.sendPacket(msg); + return; + } + if (info.isEvil() && (L2World.getInstance().getAllEvilPlayersCount() >= ((L2World.getInstance().getAllGoodPlayersCount() + Config.FACTION_BALANCE_PLAYER_EXCEED_LIMIT)))) + { + final NpcHtmlMessage msg = new NpcHtmlMessage(); + msg.setFile(info.getHtmlPrefix(), "data/html/mods/Faction/ExceededOnlineLimit.htm"); + msg.replace("%more%", Config.FACTION_EVIL_TEAM_NAME); + msg.replace("%less%", Config.FACTION_GOOD_TEAM_NAME); + client.sendPacket(msg); + return; + } + } + // The L2PcInstance must be created here, so that it can be attached to the L2GameClient if (Config.DEBUG) { diff --git a/trunk/java/com/l2jserver/gameserver/network/serverpackets/AbstractHtmlPacket.java b/trunk/java/com/l2jserver/gameserver/network/serverpackets/AbstractHtmlPacket.java index 639d625e67..e4435798bc 100644 --- a/trunk/java/com/l2jserver/gameserver/network/serverpackets/AbstractHtmlPacket.java +++ b/trunk/java/com/l2jserver/gameserver/network/serverpackets/AbstractHtmlPacket.java @@ -132,6 +132,11 @@ public abstract class AbstractHtmlPacket extends L2GameServerPacket public final void runImpl() { L2PcInstance player = getClient().getActiveChar(); + if (player == null) + { + return; + } + player.clearHtmlActions(getScope()); if (_disabledValidation) diff --git a/trunk/java/com/l2jserver/gameserver/network/serverpackets/CharSelectionInfo.java b/trunk/java/com/l2jserver/gameserver/network/serverpackets/CharSelectionInfo.java index 102a0306da..0c6678da14 100644 --- a/trunk/java/com/l2jserver/gameserver/network/serverpackets/CharSelectionInfo.java +++ b/trunk/java/com/l2jserver/gameserver/network/serverpackets/CharSelectionInfo.java @@ -307,6 +307,16 @@ public class CharSelectionInfo extends L2GameServerPacket charInfopackage.setY(chardata.getInt("y")); charInfopackage.setZ(chardata.getInt("z")); + final int faction = chardata.getInt("faction"); + if (faction == 1) + { + charInfopackage.setGood(); + } + if (faction == 2) + { + charInfopackage.setEvil(); + } + if (Config.L2JMOD_MULTILANG_ENABLE) { String lang = chardata.getString("language");