From a858e674a3a063bea307d9be4b259737b29247e1 Mon Sep 17 00:00:00 2001 From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com> Date: Thu, 14 May 2020 09:32:56 +0000 Subject: [PATCH] Addition of .xpon/.xpoff voiced commands. Contributed by ihearcolors. --- .../dist/game/config/main/Character.ini | 8 +++ .../java/org/l2jmobius/Config.java | 2 + .../handler/VoicedCommandHandler.java | 6 ++ .../voicedcommandhandlers/ExperienceGain.java | 55 +++++++++++++++++++ .../model/actor/instance/PlayerInstance.java | 11 ++++ .../model/actor/stat/PlayerStat.java | 10 ++-- 6 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/voicedcommandhandlers/ExperienceGain.java diff --git a/L2J_Mobius_C6_Interlude/dist/game/config/main/Character.ini b/L2J_Mobius_C6_Interlude/dist/game/config/main/Character.ini index 7b20d19f4d..249e65cfdc 100644 --- a/L2J_Mobius_C6_Interlude/dist/game/config/main/Character.ini +++ b/L2J_Mobius_C6_Interlude/dist/game/config/main/Character.ini @@ -299,3 +299,11 @@ ConfigClassMaster = 1;[];[];2;[];[];3;[];[] # Class Manager Handled Remotely at Level 20/40/76 AllowRemoteClassMasters = True + + +# --------------------------------------------------------------------------- +# Voice-command for turning off XP-gain +# --------------------------------------------------------------------------- +# Player can use .xpoff to disable XP-gain, and .xpon to enable again. +# Default: False +EnableExpGainCommands = False diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java index 76de0db52c..39cd69efb8 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java @@ -1097,6 +1097,7 @@ public class Config public static boolean ALLOW_CLASS_MASTERS_THIRD_CLASS; public static ClassMasterSettings CLASS_MASTER_SETTINGS; public static boolean ALLOW_REMOTE_CLASS_MASTERS; + public static boolean ENABLE_EXP_GAIN_COMMANDS; public static long DEADLOCKCHECK_INTIAL_TIME; public static long DEADLOCKCHECK_DELAY_TIME; @@ -2788,6 +2789,7 @@ public class Config ALLOW_CLASS_MASTERS_THIRD_CLASS = characterConfig.getBoolean("AllowClassMastersThirdClass", true); CLASS_MASTER_SETTINGS = new ClassMasterSettings(characterConfig.getString("ConfigClassMaster", "")); ALLOW_REMOTE_CLASS_MASTERS = characterConfig.getBoolean("AllowRemoteClassMasters", false); + ENABLE_EXP_GAIN_COMMANDS = characterConfig.getBoolean("EnableExpGainCommands", false); } public static void loadDaemonsConf() diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/VoicedCommandHandler.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/VoicedCommandHandler.java index 002b6f0213..6b8d78ba0c 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/VoicedCommandHandler.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/VoicedCommandHandler.java @@ -25,6 +25,7 @@ import org.l2jmobius.gameserver.handler.voicedcommandhandlers.BankingCmd; import org.l2jmobius.gameserver.handler.voicedcommandhandlers.CTFCmd; import org.l2jmobius.gameserver.handler.voicedcommandhandlers.DMCmd; import org.l2jmobius.gameserver.handler.voicedcommandhandlers.FarmPvpCmd; +import org.l2jmobius.gameserver.handler.voicedcommandhandlers.ExperienceGain; import org.l2jmobius.gameserver.handler.voicedcommandhandlers.OfflineShop; import org.l2jmobius.gameserver.handler.voicedcommandhandlers.Online; import org.l2jmobius.gameserver.handler.voicedcommandhandlers.StatsCmd; @@ -85,6 +86,11 @@ public class VoicedCommandHandler registerVoicedCommandHandler(new OfflineShop()); } + if (Config.ENABLE_EXP_GAIN_COMMANDS) + { + registerVoicedCommandHandler(new ExperienceGain()); + } + LOGGER.info("VoicedCommandHandler: Loaded " + _datatable.size() + " handlers."); } diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/voicedcommandhandlers/ExperienceGain.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/voicedcommandhandlers/ExperienceGain.java new file mode 100644 index 0000000000..7bd037cc16 --- /dev/null +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/voicedcommandhandlers/ExperienceGain.java @@ -0,0 +1,55 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.handler.voicedcommandhandlers; + +import org.l2jmobius.gameserver.handler.IVoicedCommandHandler; +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance; + +/** + * This class allows user to turn XP-gain off and on. + * @author Notorious + */ +public class ExperienceGain implements IVoicedCommandHandler +{ + private static final String[] _voicedCommands = + { + "xpoff", + "xpon" + }; + + @Override + public boolean useVoicedCommand(String command, PlayerInstance activeChar, String params) + { + if (command.equalsIgnoreCase("xpoff")) + { + activeChar.setExpGain(false); + activeChar.sendMessage("Experience gain is disabled."); + } + else if (command.equalsIgnoreCase("xpon")) + { + activeChar.setExpGain(true); + activeChar.sendMessage("Experience gain is enabled."); + } + return true; + } + + @Override + public String[] getVoicedCommandList() + { + return _voicedCommands; + } +} \ No newline at end of file diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java index 4a0e9be1f1..acf61de7ce 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java @@ -316,6 +316,7 @@ public class PlayerInstance extends Playable public String _originalTitleAway; private boolean _isAio = false; private long _aioEndTime = 0; + private boolean _expGain = true; public int eventX; public int eventY; @@ -15904,6 +15905,16 @@ public class PlayerInstance extends Playable return _aioEndTime; } + public void setExpGain(boolean value) + { + _expGain = value; + } + + public boolean isExpGainEnabled() + { + return _expGain; + } + /** * Gets the offline start time. * @return the offline start time diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/stat/PlayerStat.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/stat/PlayerStat.java index 11bfb7ed49..3afb94772a 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/stat/PlayerStat.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/stat/PlayerStat.java @@ -52,8 +52,8 @@ public class PlayerStat extends PlayableStat { final PlayerInstance player = getActiveChar(); - // Player is GM and access level is below or equal to canGainExp and is in party, don't give XP - if (!getActiveChar().getAccessLevel().canGainExp() && getActiveChar().isInParty()) + // Disable exp gain. + if (!player.getAccessLevel().canGainExp() || (Config.ENABLE_EXP_GAIN_COMMANDS && !getActiveChar().isExpGainEnabled())) { return false; } @@ -63,7 +63,7 @@ public class PlayerStat extends PlayableStat return false; } - // Set new karma + // Set new karma. if (!player.isCursedWeaponEquiped() && (player.getKarma() > 0) && (player.isGM() || !player.isInsideZone(ZoneId.PVP))) { final int karmaLost = player.calculateKarmaLost(value); @@ -95,9 +95,9 @@ public class PlayerStat extends PlayableStat { float ratioTakenByPet = 0; - // Player is GM and access level is below or equal to GM_DONT_TAKE_EXPSP and is in party, don't give Xp/Sp + // Disable exp gain. final PlayerInstance player = getActiveChar(); - if (!player.getAccessLevel().canGainExp() && player.isInParty()) + if (!player.getAccessLevel().canGainExp() || (Config.ENABLE_EXP_GAIN_COMMANDS && !getActiveChar().isExpGainEnabled())) { return false; }