From 5395d59c416ee3b3b62561751fb051e28a6eeee4 Mon Sep 17 00:00:00 2001 From: mobius <8391001+MobiusDevelopment@users.noreply.github.com> Date: Wed, 14 Jan 2015 11:51:44 +0000 Subject: [PATCH] Faction chat system. --- trunk/dist/game/config/Custom.properties | 3 ++ .../handlers/chathandlers/ChatAll.java | 24 ++++++++- .../handlers/chathandlers/ChatHeroVoice.java | 19 ++++++- .../chathandlers/ChatPartyMatchRoom.java | 19 ++++++- .../handlers/chathandlers/ChatRandomizer.java | 52 +++++++++++++++++++ .../handlers/chathandlers/ChatShout.java | 41 ++++++++++++++- .../handlers/chathandlers/ChatTell.java | 5 ++ .../handlers/chathandlers/ChatTrade.java | 38 +++++++++++++- .../handlers/chathandlers/ChatWorld.java | 38 +++++++++++++- trunk/java/com/l2jserver/Config.java | 2 + .../l2jserver/gameserver/model/L2World.java | 4 +- 11 files changed, 234 insertions(+), 11 deletions(-) create mode 100644 trunk/dist/game/data/scripts/handlers/chathandlers/ChatRandomizer.java diff --git a/trunk/dist/game/config/Custom.properties b/trunk/dist/game/config/Custom.properties index b756260436..dbaa6a7317 100644 --- a/trunk/dist/game/config/Custom.properties +++ b/trunk/dist/game/config/Custom.properties @@ -657,6 +657,9 @@ GoodNameColor = 00FF00 # Default: 0000FF EvilNameColor = 0000FF +# Disable chat between factions. +# Default: True +EnableFactionChat = True # --------------------------------------------------------------------------- # Premium System (VIP) diff --git a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatAll.java b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatAll.java index fffdb92fb3..d58d3cdf9f 100644 --- a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatAll.java +++ b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatAll.java @@ -105,12 +105,34 @@ public class ChatAll implements IChatHandler else { CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getAppearance().getVisibleName(), text); + CreatureSay csRandom = new CreatureSay(activeChar.getObjectId(), type, activeChar.getAppearance().getVisibleName(), ChatRandomizer.randomize(text)); Collection plrs = activeChar.getKnownList().getKnownPlayers().values(); for (L2PcInstance player : plrs) { if ((player != null) && activeChar.isInsideRadius(player, 1250, false, true) && !BlockList.isBlocked(player, activeChar)) { - player.sendPacket(cs); + if (Config.FACTION_SYSTEM_ENABLED) + { + if (Config.FACTION_SPECIFIC_CHAT) + { + if ((activeChar.isGood() && player.isEvil()) || (activeChar.isEvil() && player.isGood())) + { + player.sendPacket(csRandom); + } + else + { + player.sendPacket(cs); + } + } + else + { + player.sendPacket(cs); + } + } + else + { + player.sendPacket(cs); + } } } diff --git a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatHeroVoice.java b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatHeroVoice.java index c0dab64ec4..aa9193651b 100644 --- a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatHeroVoice.java +++ b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatHeroVoice.java @@ -64,7 +64,24 @@ public class ChatHeroVoice implements IChatHandler { if ((player != null) && !BlockList.isBlocked(player, activeChar)) { - player.sendPacket(cs); + if (Config.FACTION_SYSTEM_ENABLED) + { + if (Config.FACTION_SPECIFIC_CHAT) + { + if ((activeChar.isGood() && player.isGood()) || (activeChar.isEvil() && player.isEvil())) + { + player.sendPacket(cs); + } + } + else + { + player.sendPacket(cs); + } + } + else + { + player.sendPacket(cs); + } } } } diff --git a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatPartyMatchRoom.java b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatPartyMatchRoom.java index c0d2555954..c6ff8f78f1 100644 --- a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatPartyMatchRoom.java +++ b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatPartyMatchRoom.java @@ -58,7 +58,24 @@ public class ChatPartyMatchRoom implements IChatHandler CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text); for (L2PcInstance _member : _room.getPartyMembers()) { - _member.sendPacket(cs); + if (Config.FACTION_SYSTEM_ENABLED) + { + if (Config.FACTION_SPECIFIC_CHAT) + { + if ((activeChar.isGood() && _member.isGood()) || (activeChar.isEvil() && _member.isEvil())) + { + _member.sendPacket(cs); + } + } + else + { + _member.sendPacket(cs); + } + } + else + { + _member.sendPacket(cs); + } } } } diff --git a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatRandomizer.java b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatRandomizer.java new file mode 100644 index 0000000000..8ec5012f2d --- /dev/null +++ b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatRandomizer.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2004-2015 L2J Server + * + * This file is part of L2J Server. + * + * L2J Server 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. + * + * L2J Server 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 . + */ +package handlers.chathandlers; + +import com.l2jserver.util.Rnd; + +/** + * @author Mobius + */ +public class ChatRandomizer +{ + public static String randomize(String text) + { + final StringBuilder textOut = new StringBuilder(); + for (char c : text.toCharArray()) + { + if ((c > 96) && (c < 123)) + { + textOut.append(Character.toString((char) Rnd.get(96, 123))); + } + else if ((c > 64) && (c < 91)) + { + textOut.append(Character.toString((char) Rnd.get(64, 91))); + } + else if ((c == 32) || (c == 44) || (c == 46)) + { + textOut.append(c); + } + else + { + textOut.append(Character.toString((char) Rnd.get(47, 64))); + } + } + return textOut.toString(); + } +} diff --git a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatShout.java b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatShout.java index 5c686e7a58..069df71ff2 100644 --- a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatShout.java +++ b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatShout.java @@ -60,7 +60,27 @@ public class ChatShout implements IChatHandler { if ((region == MapRegionManager.getInstance().getMapRegionLocId(player)) && !BlockList.isBlocked(player, activeChar) && (player.getInstanceId() == activeChar.getInstanceId())) { - player.sendPacket(cs); + if (!BlockList.isBlocked(player, activeChar)) + { + if (Config.FACTION_SYSTEM_ENABLED) + { + if (Config.FACTION_SPECIFIC_CHAT) + { + if ((activeChar.isGood() && player.isGood()) || (activeChar.isEvil() && player.isEvil())) + { + player.sendPacket(cs); + } + } + else + { + player.sendPacket(cs); + } + } + else + { + player.sendPacket(cs); + } + } } } } @@ -76,7 +96,24 @@ public class ChatShout implements IChatHandler { if (!BlockList.isBlocked(player, activeChar)) { - player.sendPacket(cs); + if (Config.FACTION_SYSTEM_ENABLED) + { + if (Config.FACTION_SPECIFIC_CHAT) + { + if ((activeChar.isGood() && player.isGood()) || (activeChar.isEvil() && player.isEvil())) + { + player.sendPacket(cs); + } + } + else + { + player.sendPacket(cs); + } + } + else + { + player.sendPacket(cs); + } } } } diff --git a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatTell.java b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatTell.java index dbd06ffb88..47bf2a7f5c 100644 --- a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatTell.java +++ b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatTell.java @@ -84,6 +84,11 @@ public class ChatTell implements IChatHandler activeChar.sendMessage("Player is in offline mode."); return; } + if (Config.FACTION_SYSTEM_ENABLED && Config.FACTION_SPECIFIC_CHAT && ((activeChar.isGood() && receiver.isEvil()) || (activeChar.isEvil() && receiver.isGood()))) + { + activeChar.sendMessage("Player belongs to the opposing faction."); + return; + } if (!BlockList.isBlocked(receiver, activeChar)) { // Allow reciever to send PMs to this char, which is in silence mode. diff --git a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatTrade.java b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatTrade.java index f1ed92429e..1c7ab159f0 100644 --- a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatTrade.java +++ b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatTrade.java @@ -60,7 +60,24 @@ public class ChatTrade implements IChatHandler { if ((region == MapRegionManager.getInstance().getMapRegionLocId(player)) && !BlockList.isBlocked(player, activeChar) && (player.getInstanceId() == activeChar.getInstanceId())) { - player.sendPacket(cs); + if (Config.FACTION_SYSTEM_ENABLED) + { + if (Config.FACTION_SPECIFIC_CHAT) + { + if ((activeChar.isGood() && player.isGood()) || (activeChar.isEvil() && player.isEvil())) + { + player.sendPacket(cs); + } + } + else + { + player.sendPacket(cs); + } + } + else + { + player.sendPacket(cs); + } } } } @@ -76,7 +93,24 @@ public class ChatTrade implements IChatHandler { if (!BlockList.isBlocked(player, activeChar)) { - player.sendPacket(cs); + if (Config.FACTION_SYSTEM_ENABLED) + { + if (Config.FACTION_SPECIFIC_CHAT) + { + if ((activeChar.isGood() && player.isGood()) || (activeChar.isEvil() && player.isEvil())) + { + player.sendPacket(cs); + } + } + else + { + player.sendPacket(cs); + } + } + else + { + player.sendPacket(cs); + } } } } diff --git a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatWorld.java b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatWorld.java index 49b835f910..f41e105be1 100644 --- a/trunk/dist/game/data/scripts/handlers/chathandlers/ChatWorld.java +++ b/trunk/dist/game/data/scripts/handlers/chathandlers/ChatWorld.java @@ -79,7 +79,24 @@ public class ChatWorld implements IChatHandler final Duration timeDiff = Duration.between(instant, now); final SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_S1_SEC_UNTIL_YOU_ARE_ABLE_TO_USE_WORLD_CHAT); msg.addInt((int) timeDiff.getSeconds()); - activeChar.sendPacket(msg); + if (Config.FACTION_SYSTEM_ENABLED) + { + if (Config.FACTION_SPECIFIC_CHAT) + { + if ((activeChar.isGood() && activeChar.isGood()) || (activeChar.isEvil() && activeChar.isEvil())) + { + activeChar.sendPacket(msg); + } + } + else + { + activeChar.sendPacket(msg); + } + } + else + { + activeChar.sendPacket(msg); + } return; } } @@ -88,7 +105,24 @@ public class ChatWorld implements IChatHandler L2World.getInstance().getPlayers().stream().filter(activeChar::isNotBlocked).forEach(cs::sendTo); activeChar.setWorldChatPoints(activeChar.getWorldChatPoints() - 1); - activeChar.sendPacket(new ExWorldChatCnt(activeChar)); + if (Config.FACTION_SYSTEM_ENABLED) + { + if (Config.FACTION_SPECIFIC_CHAT) + { + if ((activeChar.isGood() && activeChar.isGood()) || (activeChar.isEvil() && activeChar.isEvil())) + { + activeChar.sendPacket(new ExWorldChatCnt(activeChar)); + } + } + else + { + activeChar.sendPacket(new ExWorldChatCnt(activeChar)); + } + } + else + { + activeChar.sendPacket(new ExWorldChatCnt(activeChar)); + } if (Config.WORLD_CHAT_INTERVAL.getSeconds() > 0) { REUSE.put(activeChar.getObjectId(), now.plus(Config.WORLD_CHAT_INTERVAL)); diff --git a/trunk/java/com/l2jserver/Config.java b/trunk/java/com/l2jserver/Config.java index 9dcea6a579..a8005c5fcd 100644 --- a/trunk/java/com/l2jserver/Config.java +++ b/trunk/java/com/l2jserver/Config.java @@ -831,6 +831,7 @@ public final class Config public static String FACTION_EVIL_TEAM_NAME; public static int FACTION_GOOD_NAME_COLOR; public static int FACTION_EVIL_NAME_COLOR; + public static boolean FACTION_SPECIFIC_CHAT; public static boolean PREMIUM_SYSTEM_ENABLED; public static float PREMIUM_RATE_XP; public static float PREMIUM_RATE_SP; @@ -2650,6 +2651,7 @@ public final class Config FACTION_EVIL_TEAM_NAME = CustomSettings.getString("EvilTeamName", "Evil"); FACTION_GOOD_NAME_COLOR = Integer.decode("0x" + CustomSettings.getString("GoodNameColor", "00FF00")); FACTION_EVIL_NAME_COLOR = Integer.decode("0x" + CustomSettings.getString("EvilNameColor", "0000FF")); + FACTION_SPECIFIC_CHAT = Boolean.valueOf(CustomSettings.getBoolean("EnableFactionChat", true)); PREMIUM_SYSTEM_ENABLED = CustomSettings.getBoolean("EnablePremiumSystem", false); PREMIUM_RATE_XP = CustomSettings.getFloat("PremiumRateXp", 2); diff --git a/trunk/java/com/l2jserver/gameserver/model/L2World.java b/trunk/java/com/l2jserver/gameserver/model/L2World.java index ea0877fb4b..1729074750 100644 --- a/trunk/java/com/l2jserver/gameserver/model/L2World.java +++ b/trunk/java/com/l2jserver/gameserver/model/L2World.java @@ -200,12 +200,12 @@ public final class L2World return _allPlayers.size(); } - public int getAllgoodPlayersCount() + public int getAllGoodPlayersCount() { return _allGoodPlayers.size(); } - public int getAllevilPlayersCount() + public int getAllEvilPlayersCount() { return _allEvilPlayers.size(); }