From f48a7f1e51dd23388e26ef27c4e252e994aae426 Mon Sep 17 00:00:00 2001
From: MobiusDev <8391001+MobiusDevelopment@users.noreply.github.com>
Date: Thu, 22 Mar 2018 14:06:56 +0000
Subject: [PATCH] Custom auto potion system. Contributed by gigilo1968.
---
.../dist/game/config/Custom/AutoPotions.ini | 34 ++++++
.../data/scripts/handlers/MasterHandler.java | 2 +
.../voicedcommandhandlers/AutoPotion.java | 106 ++++++++++++++++++
.../java/com/l2jmobius/Config.java | 41 +++++++
.../actor/tasks/player/AutoPotionTask.java | 105 +++++++++++++++++
L2J_Mobius_1.0_Ertheia/readme.txt | 1 +
.../dist/game/config/Custom/AutoPotions.ini | 34 ++++++
.../data/scripts/handlers/MasterHandler.java | 2 +
.../voicedcommandhandlers/AutoPotion.java | 106 ++++++++++++++++++
.../java/com/l2jmobius/Config.java | 41 +++++++
.../actor/tasks/player/AutoPotionTask.java | 105 +++++++++++++++++
L2J_Mobius_2.5_Underground/readme.txt | 1 +
.../dist/game/config/Custom/AutoPotions.ini | 34 ++++++
.../data/scripts/handlers/MasterHandler.java | 2 +
.../voicedcommandhandlers/AutoPotion.java | 106 ++++++++++++++++++
.../java/com/l2jmobius/Config.java | 41 +++++++
.../actor/tasks/player/AutoPotionTask.java | 105 +++++++++++++++++
L2J_Mobius_3.0_Helios/readme.txt | 1 +
.../dist/game/config/Custom/AutoPotions.ini | 34 ++++++
.../data/scripts/handlers/MasterHandler.java | 2 +
.../voicedcommandhandlers/AutoPotion.java | 106 ++++++++++++++++++
.../java/com/l2jmobius/Config.java | 41 +++++++
.../actor/tasks/player/AutoPotionTask.java | 105 +++++++++++++++++
L2J_Mobius_4.0_GrandCrusade/readme.txt | 1 +
.../dist/game/config/Custom.ini | 36 ++++++
.../data/scripts/handlers/MasterHandler.java | 2 +
.../voicedcommandhandlers/AutoPotion.java | 106 ++++++++++++++++++
.../java/com/l2jmobius/Config.java | 37 ++++++
.../actor/tasks/player/AutoPotionTask.java | 105 +++++++++++++++++
.../dist/game/config/Custom/AutoPotions.ini | 34 ++++++
.../data/scripts/handlers/MasterHandler.java | 2 +
.../voicedcommandhandlers/AutoPotion.java | 106 ++++++++++++++++++
.../java/com/l2jmobius/Config.java | 41 +++++++
.../actor/tasks/player/AutoPotionTask.java | 105 +++++++++++++++++
.../dist/game/config/Custom/AutoPotions.ini | 34 ++++++
.../data/scripts/handlers/MasterHandler.java | 2 +
.../voicedcommandhandlers/AutoPotion.java | 106 ++++++++++++++++++
.../java/com/l2jmobius/Config.java | 41 +++++++
.../actor/tasks/player/AutoPotionTask.java | 105 +++++++++++++++++
39 files changed, 2018 insertions(+)
create mode 100644 L2J_Mobius_1.0_Ertheia/dist/game/config/Custom/AutoPotions.ini
create mode 100644 L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
create mode 100644 L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
create mode 100644 L2J_Mobius_2.5_Underground/dist/game/config/Custom/AutoPotions.ini
create mode 100644 L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
create mode 100644 L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
create mode 100644 L2J_Mobius_3.0_Helios/dist/game/config/Custom/AutoPotions.ini
create mode 100644 L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
create mode 100644 L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
create mode 100644 L2J_Mobius_4.0_GrandCrusade/dist/game/config/Custom/AutoPotions.ini
create mode 100644 L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
create mode 100644 L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
create mode 100644 L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
create mode 100644 L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
create mode 100644 L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Custom/AutoPotions.ini
create mode 100644 L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
create mode 100644 L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
create mode 100644 L2J_Mobius_Classic_2.0_Zaken/dist/game/config/Custom/AutoPotions.ini
create mode 100644 L2J_Mobius_Classic_2.0_Zaken/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
create mode 100644 L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
diff --git a/L2J_Mobius_1.0_Ertheia/dist/game/config/Custom/AutoPotions.ini b/L2J_Mobius_1.0_Ertheia/dist/game/config/Custom/AutoPotions.ini
new file mode 100644
index 0000000000..2bb76c26d5
--- /dev/null
+++ b/L2J_Mobius_1.0_Ertheia/dist/game/config/Custom/AutoPotions.ini
@@ -0,0 +1,34 @@
+# ---------------------------------------------------------------------------
+# Auto Potion Settings
+# ---------------------------------------------------------------------------
+# Use .apon / .apoff voiced commands to enable / disable.
+
+# Enable auto potion commands.
+AutoPotionsEnabled = false
+
+# Use auto potions in Olympiad.
+AutoPotionsInOlympiad = false
+
+# Mimim player level to use the commands.
+AutoPotionMinimumLevel = 1
+
+# Enable auto CP potions.
+AutoCpEnabled = true
+# Percentage that CP potions will be used.
+AutoCpPercentage = 70
+# Auto CP item ids. Order by use priority.
+AutoCpItemIds = 5592,5591
+
+# Enable auto HP potions.
+AutoHpEnabled = true
+# Percentage that HP potions will be used.
+AutoHpPercentage = 70
+# Auto HP item ids. Order by use priority.
+AutoHpItemIds = 1540,1539,1061,1060
+
+# Enable auto MP potions.
+AutoMpEnabled = true
+# Percentage that MP potions will be used.
+AutoMpPercentage = 70
+# Auto MP item ids. Order by use priority.
+AutoMpItemIds = 728
diff --git a/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/MasterHandler.java b/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/MasterHandler.java
index 6e38ce1d0c..573b9e4b9f 100644
--- a/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/MasterHandler.java
+++ b/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/MasterHandler.java
@@ -325,6 +325,7 @@ import handlers.usercommandhandlers.PartyInfo;
import handlers.usercommandhandlers.SiegeStatus;
import handlers.usercommandhandlers.Time;
import handlers.usercommandhandlers.Unstuck;
+import handlers.voicedcommandhandlers.AutoPotion;
import handlers.voicedcommandhandlers.Banking;
import handlers.voicedcommandhandlers.ChangePassword;
import handlers.voicedcommandhandlers.ChatAdmin;
@@ -584,6 +585,7 @@ public class MasterHandler
Config.MULTILANG_ENABLE && Config.MULTILANG_VOICED_ALLOW ? Lang.class : null,
Config.ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null,
Config.PREMIUM_SYSTEM_ENABLED ? Premium.class : null,
+ Config.AUTO_POTIONS_ENABLED ? AutoPotion.class : null,
},
{
// Target Handlers
diff --git a/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java b/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
new file mode 100644
index 0000000000..7f2ed62f90
--- /dev/null
+++ b/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
@@ -0,0 +1,106 @@
+/*
+ * 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 handlers.voicedcommandhandlers;
+
+import java.util.HashMap;
+import java.util.concurrent.Future;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.ThreadPoolManager;
+import com.l2jmobius.gameserver.handler.IVoicedCommandHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.actor.tasks.player.AutoPotionTask;
+import com.l2jmobius.gameserver.model.events.EventType;
+import com.l2jmobius.gameserver.model.events.ListenerRegisterType;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterEvent;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterType;
+import com.l2jmobius.gameserver.model.events.impl.character.player.OnPlayerLogout;
+
+/**
+ * @author Gigi, Mobius
+ */
+public class AutoPotion implements IVoicedCommandHandler
+{
+ private static final HashMap> AUTO_POTION_TASKS = new HashMap<>();
+ private static final int POTION_TASK_DELAY = 1000; // 1 second
+
+ private static final String[] VOICED_COMMANDS =
+ {
+ "apon",
+ "apoff"
+ };
+
+ public static AutoPotion getInstance()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
+ {
+ if (!Config.AUTO_POTIONS_ENABLED || (activeChar == null))
+ {
+ return false;
+ }
+ if (activeChar.getLevel() < Config.AUTO_POTION_MIN_LVL)
+ {
+ activeChar.sendMessage("You need to be at least " + Config.AUTO_POTION_MIN_LVL + " to use auto potions.");
+ return false;
+ }
+
+ final int playerOID = activeChar.getObjectId();
+ if (command.equals("apon"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ AUTO_POTION_TASKS.put(activeChar.getObjectId(), ThreadPoolManager.scheduleAtFixedRate(new AutoPotionTask(activeChar), POTION_TASK_DELAY, POTION_TASK_DELAY));
+ activeChar.sendMessage("Auto potions is enabled.");
+ return true;
+ }
+ else if (command.equals("apoff"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ activeChar.sendMessage("Auto potions is disabled.");
+ }
+ return false;
+ }
+
+ @RegisterEvent(EventType.ON_PLAYER_LOGOUT)
+ @RegisterType(ListenerRegisterType.GLOBAL)
+ public void OnPlayerLogout(OnPlayerLogout event)
+ {
+ final int playerOID = event.getActiveChar().getObjectId();
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ }
+
+ @Override
+ public String[] getVoicedCommandList()
+ {
+ return VOICED_COMMANDS;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java
index ea13908985..ae8bef9ce1 100644
--- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java
@@ -108,6 +108,7 @@ public final class Config
// Custom Config File Definitions
// --------------------------------------------------
public static final String CUSTOM_ALLOWED_PLAYER_RACES_CONFIG_FILE = "./config/Custom/AllowedPlayerRaces.ini";
+ public static final String CUSTOM_AUTO_POTIONS_CONFIG_FILE = "./config/Custom/AutoPotions.ini";
public static final String CUSTOM_BANKING_CONFIG_FILE = "./config/Custom/Banking.ini";
public static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
public static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
@@ -1100,6 +1101,18 @@ public final class Config
public static boolean ALLOW_DWARF;
public static boolean ALLOW_KAMAEL;
public static boolean ALLOW_ERTHEIA;
+ public static boolean AUTO_POTIONS_ENABLED;
+ public static boolean AUTO_POTIONS_IN_OLYMPIAD;
+ public static int AUTO_POTION_MIN_LVL;
+ public static boolean AUTO_CP_ENABLED;
+ public static boolean AUTO_HP_ENABLED;
+ public static boolean AUTO_MP_ENABLED;
+ public static int AUTO_CP_PERCENTAGE;
+ public static int AUTO_HP_PERCENTAGE;
+ public static int AUTO_MP_PERCENTAGE;
+ public static List AUTO_CP_ITEM_IDS;
+ public static List AUTO_HP_ITEM_IDS;
+ public static List AUTO_MP_ITEM_IDS;
public static boolean CUSTOM_STARTING_LOC;
public static int CUSTOM_STARTING_LOC_X;
public static int CUSTOM_STARTING_LOC_Y;
@@ -2398,6 +2411,34 @@ public final class Config
ALLOW_KAMAEL = AllowedPlayerRaces.getBoolean("AllowKamael", true);
ALLOW_ERTHEIA = AllowedPlayerRaces.getBoolean("AllowErtheia", true);
+ // Load AutoPotions config file (if exists)
+ final PropertiesParser AutoPotions = new PropertiesParser(CUSTOM_AUTO_POTIONS_CONFIG_FILE);
+
+ AUTO_POTIONS_ENABLED = AutoPotions.getBoolean("AutoPotionsEnabled", false);
+ AUTO_POTIONS_IN_OLYMPIAD = AutoPotions.getBoolean("AutoPotionsInOlympiad", false);
+ AUTO_POTION_MIN_LVL = AutoPotions.getInt("AutoPotionMinimumLevel", 1);
+ AUTO_CP_ENABLED = AutoPotions.getBoolean("AutoCpEnabled", true);
+ AUTO_HP_ENABLED = AutoPotions.getBoolean("AutoHpEnabled", true);
+ AUTO_MP_ENABLED = AutoPotions.getBoolean("AutoMpEnabled", true);
+ AUTO_CP_PERCENTAGE = AutoPotions.getInt("AutoCpPercentage", 70);
+ AUTO_HP_PERCENTAGE = AutoPotions.getInt("AutoHpPercentage", 70);
+ AUTO_MP_PERCENTAGE = AutoPotions.getInt("AutoMpPercentage", 70);
+ AUTO_CP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoCpItemIds", "0").split(","))
+ {
+ AUTO_CP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_HP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoHpItemIds", "0").split(","))
+ {
+ AUTO_HP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_MP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoMpItemIds", "0").split(","))
+ {
+ AUTO_MP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+
// Load Banking config file (if exists)
final PropertiesParser Banking = new PropertiesParser(CUSTOM_BANKING_CONFIG_FILE);
diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
new file mode 100644
index 0000000000..0819aebf24
--- /dev/null
+++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
@@ -0,0 +1,105 @@
+/*
+ * 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 com.l2jmobius.gameserver.model.actor.tasks.player;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.handler.ItemHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
+
+/**
+ * @author Mobius
+ */
+public class AutoPotionTask implements Runnable
+{
+ private final L2PcInstance _player;
+
+ public AutoPotionTask(L2PcInstance player)
+ {
+ _player = player;
+ }
+
+ @Override
+ public void run()
+ {
+ if ((_player == null) || (_player.isOnlineInt() != 1) || _player.isAlikeDead() || (!Config.AUTO_POTIONS_IN_OLYMPIAD && _player.isInOlympiadMode()))
+ {
+ return;
+ }
+
+ boolean success = false;
+ if (Config.AUTO_HP_ENABLED)
+ {
+ final boolean restoreHP = ((_player.getStatus().getCurrentHp() / _player.getMaxHp()) * 100) < Config.AUTO_HP_PERCENTAGE;
+ for (int itemId : Config.AUTO_HP_ITEM_IDS)
+ {
+ final L2ItemInstance hpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((hpPotion != null) && (hpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreHP)
+ {
+ ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(_player, hpPotion, false);
+ _player.sendMessage("Auto potion: Restored HP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_CP_ENABLED)
+ {
+ final boolean restoreCP = ((_player.getStatus().getCurrentCp() / _player.getMaxCp()) * 100) < Config.AUTO_CP_PERCENTAGE;
+ for (int itemId : Config.AUTO_CP_ITEM_IDS)
+ {
+ final L2ItemInstance cpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((cpPotion != null) && (cpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreCP)
+ {
+ ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(_player, cpPotion, false);
+ _player.sendMessage("Auto potion: Restored CP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_MP_ENABLED)
+ {
+ final boolean restoreMP = ((_player.getStatus().getCurrentMp() / _player.getMaxMp()) * 100) < Config.AUTO_MP_PERCENTAGE;
+ for (int itemId : Config.AUTO_MP_ITEM_IDS)
+ {
+ final L2ItemInstance mpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((mpPotion != null) && (mpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreMP)
+ {
+ ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(_player, mpPotion, false);
+ _player.sendMessage("Auto potion: Restored MP.");
+ break;
+ }
+ }
+ }
+ }
+
+ if (!success)
+ {
+ _player.sendMessage("Auto potion: You are out of potions!");
+ }
+ }
+}
diff --git a/L2J_Mobius_1.0_Ertheia/readme.txt b/L2J_Mobius_1.0_Ertheia/readme.txt
index 76b22c8dea..3143b960c7 100644
--- a/L2J_Mobius_1.0_Ertheia/readme.txt
+++ b/L2J_Mobius_1.0_Ertheia/readme.txt
@@ -78,6 +78,7 @@ Events:
Customs:
-Allowed player races
+-Auto potions command
-Banking
-Champion monsters
-Classmaster
diff --git a/L2J_Mobius_2.5_Underground/dist/game/config/Custom/AutoPotions.ini b/L2J_Mobius_2.5_Underground/dist/game/config/Custom/AutoPotions.ini
new file mode 100644
index 0000000000..2bb76c26d5
--- /dev/null
+++ b/L2J_Mobius_2.5_Underground/dist/game/config/Custom/AutoPotions.ini
@@ -0,0 +1,34 @@
+# ---------------------------------------------------------------------------
+# Auto Potion Settings
+# ---------------------------------------------------------------------------
+# Use .apon / .apoff voiced commands to enable / disable.
+
+# Enable auto potion commands.
+AutoPotionsEnabled = false
+
+# Use auto potions in Olympiad.
+AutoPotionsInOlympiad = false
+
+# Mimim player level to use the commands.
+AutoPotionMinimumLevel = 1
+
+# Enable auto CP potions.
+AutoCpEnabled = true
+# Percentage that CP potions will be used.
+AutoCpPercentage = 70
+# Auto CP item ids. Order by use priority.
+AutoCpItemIds = 5592,5591
+
+# Enable auto HP potions.
+AutoHpEnabled = true
+# Percentage that HP potions will be used.
+AutoHpPercentage = 70
+# Auto HP item ids. Order by use priority.
+AutoHpItemIds = 1540,1539,1061,1060
+
+# Enable auto MP potions.
+AutoMpEnabled = true
+# Percentage that MP potions will be used.
+AutoMpPercentage = 70
+# Auto MP item ids. Order by use priority.
+AutoMpItemIds = 728
diff --git a/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/MasterHandler.java b/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/MasterHandler.java
index ad8653530d..61c0dbf57b 100644
--- a/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/MasterHandler.java
+++ b/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/MasterHandler.java
@@ -326,6 +326,7 @@ import handlers.usercommandhandlers.PartyInfo;
import handlers.usercommandhandlers.SiegeStatus;
import handlers.usercommandhandlers.Time;
import handlers.usercommandhandlers.Unstuck;
+import handlers.voicedcommandhandlers.AutoPotion;
import handlers.voicedcommandhandlers.Banking;
import handlers.voicedcommandhandlers.ChangePassword;
import handlers.voicedcommandhandlers.ChatAdmin;
@@ -586,6 +587,7 @@ public class MasterHandler
Config.MULTILANG_ENABLE && Config.MULTILANG_VOICED_ALLOW ? Lang.class : null,
Config.ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null,
Config.PREMIUM_SYSTEM_ENABLED ? Premium.class : null,
+ Config.AUTO_POTIONS_ENABLED ? AutoPotion.class : null,
},
{
// Target Handlers
diff --git a/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java b/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
new file mode 100644
index 0000000000..7f2ed62f90
--- /dev/null
+++ b/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
@@ -0,0 +1,106 @@
+/*
+ * 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 handlers.voicedcommandhandlers;
+
+import java.util.HashMap;
+import java.util.concurrent.Future;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.ThreadPoolManager;
+import com.l2jmobius.gameserver.handler.IVoicedCommandHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.actor.tasks.player.AutoPotionTask;
+import com.l2jmobius.gameserver.model.events.EventType;
+import com.l2jmobius.gameserver.model.events.ListenerRegisterType;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterEvent;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterType;
+import com.l2jmobius.gameserver.model.events.impl.character.player.OnPlayerLogout;
+
+/**
+ * @author Gigi, Mobius
+ */
+public class AutoPotion implements IVoicedCommandHandler
+{
+ private static final HashMap> AUTO_POTION_TASKS = new HashMap<>();
+ private static final int POTION_TASK_DELAY = 1000; // 1 second
+
+ private static final String[] VOICED_COMMANDS =
+ {
+ "apon",
+ "apoff"
+ };
+
+ public static AutoPotion getInstance()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
+ {
+ if (!Config.AUTO_POTIONS_ENABLED || (activeChar == null))
+ {
+ return false;
+ }
+ if (activeChar.getLevel() < Config.AUTO_POTION_MIN_LVL)
+ {
+ activeChar.sendMessage("You need to be at least " + Config.AUTO_POTION_MIN_LVL + " to use auto potions.");
+ return false;
+ }
+
+ final int playerOID = activeChar.getObjectId();
+ if (command.equals("apon"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ AUTO_POTION_TASKS.put(activeChar.getObjectId(), ThreadPoolManager.scheduleAtFixedRate(new AutoPotionTask(activeChar), POTION_TASK_DELAY, POTION_TASK_DELAY));
+ activeChar.sendMessage("Auto potions is enabled.");
+ return true;
+ }
+ else if (command.equals("apoff"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ activeChar.sendMessage("Auto potions is disabled.");
+ }
+ return false;
+ }
+
+ @RegisterEvent(EventType.ON_PLAYER_LOGOUT)
+ @RegisterType(ListenerRegisterType.GLOBAL)
+ public void OnPlayerLogout(OnPlayerLogout event)
+ {
+ final int playerOID = event.getActiveChar().getObjectId();
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ }
+
+ @Override
+ public String[] getVoicedCommandList()
+ {
+ return VOICED_COMMANDS;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java
index 9631e85707..113fb01d82 100644
--- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java
@@ -109,6 +109,7 @@ public final class Config
// Custom Config File Definitions
// --------------------------------------------------
public static final String CUSTOM_ALLOWED_PLAYER_RACES_CONFIG_FILE = "./config/Custom/AllowedPlayerRaces.ini";
+ public static final String CUSTOM_AUTO_POTIONS_CONFIG_FILE = "./config/Custom/AutoPotions.ini";
public static final String CUSTOM_BANKING_CONFIG_FILE = "./config/Custom/Banking.ini";
public static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
public static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
@@ -1107,6 +1108,18 @@ public final class Config
public static boolean ALLOW_DWARF;
public static boolean ALLOW_KAMAEL;
public static boolean ALLOW_ERTHEIA;
+ public static boolean AUTO_POTIONS_ENABLED;
+ public static boolean AUTO_POTIONS_IN_OLYMPIAD;
+ public static int AUTO_POTION_MIN_LVL;
+ public static boolean AUTO_CP_ENABLED;
+ public static boolean AUTO_HP_ENABLED;
+ public static boolean AUTO_MP_ENABLED;
+ public static int AUTO_CP_PERCENTAGE;
+ public static int AUTO_HP_PERCENTAGE;
+ public static int AUTO_MP_PERCENTAGE;
+ public static List AUTO_CP_ITEM_IDS;
+ public static List AUTO_HP_ITEM_IDS;
+ public static List AUTO_MP_ITEM_IDS;
public static boolean CUSTOM_STARTING_LOC;
public static int CUSTOM_STARTING_LOC_X;
public static int CUSTOM_STARTING_LOC_Y;
@@ -2414,6 +2427,34 @@ public final class Config
ALLOW_KAMAEL = AllowedPlayerRaces.getBoolean("AllowKamael", true);
ALLOW_ERTHEIA = AllowedPlayerRaces.getBoolean("AllowErtheia", true);
+ // Load AutoPotions config file (if exists)
+ final PropertiesParser AutoPotions = new PropertiesParser(CUSTOM_AUTO_POTIONS_CONFIG_FILE);
+
+ AUTO_POTIONS_ENABLED = AutoPotions.getBoolean("AutoPotionsEnabled", false);
+ AUTO_POTIONS_IN_OLYMPIAD = AutoPotions.getBoolean("AutoPotionsInOlympiad", false);
+ AUTO_POTION_MIN_LVL = AutoPotions.getInt("AutoPotionMinimumLevel", 1);
+ AUTO_CP_ENABLED = AutoPotions.getBoolean("AutoCpEnabled", true);
+ AUTO_HP_ENABLED = AutoPotions.getBoolean("AutoHpEnabled", true);
+ AUTO_MP_ENABLED = AutoPotions.getBoolean("AutoMpEnabled", true);
+ AUTO_CP_PERCENTAGE = AutoPotions.getInt("AutoCpPercentage", 70);
+ AUTO_HP_PERCENTAGE = AutoPotions.getInt("AutoHpPercentage", 70);
+ AUTO_MP_PERCENTAGE = AutoPotions.getInt("AutoMpPercentage", 70);
+ AUTO_CP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoCpItemIds", "0").split(","))
+ {
+ AUTO_CP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_HP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoHpItemIds", "0").split(","))
+ {
+ AUTO_HP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_MP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoMpItemIds", "0").split(","))
+ {
+ AUTO_MP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+
// Load Banking config file (if exists)
final PropertiesParser Banking = new PropertiesParser(CUSTOM_BANKING_CONFIG_FILE);
diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
new file mode 100644
index 0000000000..0819aebf24
--- /dev/null
+++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
@@ -0,0 +1,105 @@
+/*
+ * 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 com.l2jmobius.gameserver.model.actor.tasks.player;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.handler.ItemHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
+
+/**
+ * @author Mobius
+ */
+public class AutoPotionTask implements Runnable
+{
+ private final L2PcInstance _player;
+
+ public AutoPotionTask(L2PcInstance player)
+ {
+ _player = player;
+ }
+
+ @Override
+ public void run()
+ {
+ if ((_player == null) || (_player.isOnlineInt() != 1) || _player.isAlikeDead() || (!Config.AUTO_POTIONS_IN_OLYMPIAD && _player.isInOlympiadMode()))
+ {
+ return;
+ }
+
+ boolean success = false;
+ if (Config.AUTO_HP_ENABLED)
+ {
+ final boolean restoreHP = ((_player.getStatus().getCurrentHp() / _player.getMaxHp()) * 100) < Config.AUTO_HP_PERCENTAGE;
+ for (int itemId : Config.AUTO_HP_ITEM_IDS)
+ {
+ final L2ItemInstance hpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((hpPotion != null) && (hpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreHP)
+ {
+ ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(_player, hpPotion, false);
+ _player.sendMessage("Auto potion: Restored HP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_CP_ENABLED)
+ {
+ final boolean restoreCP = ((_player.getStatus().getCurrentCp() / _player.getMaxCp()) * 100) < Config.AUTO_CP_PERCENTAGE;
+ for (int itemId : Config.AUTO_CP_ITEM_IDS)
+ {
+ final L2ItemInstance cpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((cpPotion != null) && (cpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreCP)
+ {
+ ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(_player, cpPotion, false);
+ _player.sendMessage("Auto potion: Restored CP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_MP_ENABLED)
+ {
+ final boolean restoreMP = ((_player.getStatus().getCurrentMp() / _player.getMaxMp()) * 100) < Config.AUTO_MP_PERCENTAGE;
+ for (int itemId : Config.AUTO_MP_ITEM_IDS)
+ {
+ final L2ItemInstance mpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((mpPotion != null) && (mpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreMP)
+ {
+ ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(_player, mpPotion, false);
+ _player.sendMessage("Auto potion: Restored MP.");
+ break;
+ }
+ }
+ }
+ }
+
+ if (!success)
+ {
+ _player.sendMessage("Auto potion: You are out of potions!");
+ }
+ }
+}
diff --git a/L2J_Mobius_2.5_Underground/readme.txt b/L2J_Mobius_2.5_Underground/readme.txt
index fc332336e9..b3e8bfe997 100644
--- a/L2J_Mobius_2.5_Underground/readme.txt
+++ b/L2J_Mobius_2.5_Underground/readme.txt
@@ -91,6 +91,7 @@ Events:
Customs:
-Allowed player races
+-Auto potions command
-Banking
-Champion monsters
-Classmaster
diff --git a/L2J_Mobius_3.0_Helios/dist/game/config/Custom/AutoPotions.ini b/L2J_Mobius_3.0_Helios/dist/game/config/Custom/AutoPotions.ini
new file mode 100644
index 0000000000..2bb76c26d5
--- /dev/null
+++ b/L2J_Mobius_3.0_Helios/dist/game/config/Custom/AutoPotions.ini
@@ -0,0 +1,34 @@
+# ---------------------------------------------------------------------------
+# Auto Potion Settings
+# ---------------------------------------------------------------------------
+# Use .apon / .apoff voiced commands to enable / disable.
+
+# Enable auto potion commands.
+AutoPotionsEnabled = false
+
+# Use auto potions in Olympiad.
+AutoPotionsInOlympiad = false
+
+# Mimim player level to use the commands.
+AutoPotionMinimumLevel = 1
+
+# Enable auto CP potions.
+AutoCpEnabled = true
+# Percentage that CP potions will be used.
+AutoCpPercentage = 70
+# Auto CP item ids. Order by use priority.
+AutoCpItemIds = 5592,5591
+
+# Enable auto HP potions.
+AutoHpEnabled = true
+# Percentage that HP potions will be used.
+AutoHpPercentage = 70
+# Auto HP item ids. Order by use priority.
+AutoHpItemIds = 1540,1539,1061,1060
+
+# Enable auto MP potions.
+AutoMpEnabled = true
+# Percentage that MP potions will be used.
+AutoMpPercentage = 70
+# Auto MP item ids. Order by use priority.
+AutoMpItemIds = 728
diff --git a/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/MasterHandler.java b/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/MasterHandler.java
index f407232e2e..15619c6ee5 100644
--- a/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/MasterHandler.java
+++ b/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/MasterHandler.java
@@ -327,6 +327,7 @@ import handlers.usercommandhandlers.PartyInfo;
import handlers.usercommandhandlers.SiegeStatus;
import handlers.usercommandhandlers.Time;
import handlers.usercommandhandlers.Unstuck;
+import handlers.voicedcommandhandlers.AutoPotion;
import handlers.voicedcommandhandlers.Banking;
import handlers.voicedcommandhandlers.ChangePassword;
import handlers.voicedcommandhandlers.ChatAdmin;
@@ -588,6 +589,7 @@ public class MasterHandler
Config.MULTILANG_ENABLE && Config.MULTILANG_VOICED_ALLOW ? Lang.class : null,
Config.ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null,
Config.PREMIUM_SYSTEM_ENABLED ? Premium.class : null,
+ Config.AUTO_POTIONS_ENABLED ? AutoPotion.class : null,
},
{
// Target Handlers
diff --git a/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java b/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
new file mode 100644
index 0000000000..7f2ed62f90
--- /dev/null
+++ b/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
@@ -0,0 +1,106 @@
+/*
+ * 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 handlers.voicedcommandhandlers;
+
+import java.util.HashMap;
+import java.util.concurrent.Future;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.ThreadPoolManager;
+import com.l2jmobius.gameserver.handler.IVoicedCommandHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.actor.tasks.player.AutoPotionTask;
+import com.l2jmobius.gameserver.model.events.EventType;
+import com.l2jmobius.gameserver.model.events.ListenerRegisterType;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterEvent;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterType;
+import com.l2jmobius.gameserver.model.events.impl.character.player.OnPlayerLogout;
+
+/**
+ * @author Gigi, Mobius
+ */
+public class AutoPotion implements IVoicedCommandHandler
+{
+ private static final HashMap> AUTO_POTION_TASKS = new HashMap<>();
+ private static final int POTION_TASK_DELAY = 1000; // 1 second
+
+ private static final String[] VOICED_COMMANDS =
+ {
+ "apon",
+ "apoff"
+ };
+
+ public static AutoPotion getInstance()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
+ {
+ if (!Config.AUTO_POTIONS_ENABLED || (activeChar == null))
+ {
+ return false;
+ }
+ if (activeChar.getLevel() < Config.AUTO_POTION_MIN_LVL)
+ {
+ activeChar.sendMessage("You need to be at least " + Config.AUTO_POTION_MIN_LVL + " to use auto potions.");
+ return false;
+ }
+
+ final int playerOID = activeChar.getObjectId();
+ if (command.equals("apon"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ AUTO_POTION_TASKS.put(activeChar.getObjectId(), ThreadPoolManager.scheduleAtFixedRate(new AutoPotionTask(activeChar), POTION_TASK_DELAY, POTION_TASK_DELAY));
+ activeChar.sendMessage("Auto potions is enabled.");
+ return true;
+ }
+ else if (command.equals("apoff"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ activeChar.sendMessage("Auto potions is disabled.");
+ }
+ return false;
+ }
+
+ @RegisterEvent(EventType.ON_PLAYER_LOGOUT)
+ @RegisterType(ListenerRegisterType.GLOBAL)
+ public void OnPlayerLogout(OnPlayerLogout event)
+ {
+ final int playerOID = event.getActiveChar().getObjectId();
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ }
+
+ @Override
+ public String[] getVoicedCommandList()
+ {
+ return VOICED_COMMANDS;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java
index c6505c538c..a228a1b729 100644
--- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java
@@ -109,6 +109,7 @@ public final class Config
// Custom Config File Definitions
// --------------------------------------------------
public static final String CUSTOM_ALLOWED_PLAYER_RACES_CONFIG_FILE = "./config/Custom/AllowedPlayerRaces.ini";
+ public static final String CUSTOM_AUTO_POTIONS_CONFIG_FILE = "./config/Custom/AutoPotions.ini";
public static final String CUSTOM_BANKING_CONFIG_FILE = "./config/Custom/Banking.ini";
public static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
public static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
@@ -1115,6 +1116,18 @@ public final class Config
public static boolean ALLOW_DWARF;
public static boolean ALLOW_KAMAEL;
public static boolean ALLOW_ERTHEIA;
+ public static boolean AUTO_POTIONS_ENABLED;
+ public static boolean AUTO_POTIONS_IN_OLYMPIAD;
+ public static int AUTO_POTION_MIN_LVL;
+ public static boolean AUTO_CP_ENABLED;
+ public static boolean AUTO_HP_ENABLED;
+ public static boolean AUTO_MP_ENABLED;
+ public static int AUTO_CP_PERCENTAGE;
+ public static int AUTO_HP_PERCENTAGE;
+ public static int AUTO_MP_PERCENTAGE;
+ public static List AUTO_CP_ITEM_IDS;
+ public static List AUTO_HP_ITEM_IDS;
+ public static List AUTO_MP_ITEM_IDS;
public static boolean CUSTOM_STARTING_LOC;
public static int CUSTOM_STARTING_LOC_X;
public static int CUSTOM_STARTING_LOC_Y;
@@ -2431,6 +2444,34 @@ public final class Config
ALLOW_KAMAEL = AllowedPlayerRaces.getBoolean("AllowKamael", true);
ALLOW_ERTHEIA = AllowedPlayerRaces.getBoolean("AllowErtheia", true);
+ // Load AutoPotions config file (if exists)
+ final PropertiesParser AutoPotions = new PropertiesParser(CUSTOM_AUTO_POTIONS_CONFIG_FILE);
+
+ AUTO_POTIONS_ENABLED = AutoPotions.getBoolean("AutoPotionsEnabled", false);
+ AUTO_POTIONS_IN_OLYMPIAD = AutoPotions.getBoolean("AutoPotionsInOlympiad", false);
+ AUTO_POTION_MIN_LVL = AutoPotions.getInt("AutoPotionMinimumLevel", 1);
+ AUTO_CP_ENABLED = AutoPotions.getBoolean("AutoCpEnabled", true);
+ AUTO_HP_ENABLED = AutoPotions.getBoolean("AutoHpEnabled", true);
+ AUTO_MP_ENABLED = AutoPotions.getBoolean("AutoMpEnabled", true);
+ AUTO_CP_PERCENTAGE = AutoPotions.getInt("AutoCpPercentage", 70);
+ AUTO_HP_PERCENTAGE = AutoPotions.getInt("AutoHpPercentage", 70);
+ AUTO_MP_PERCENTAGE = AutoPotions.getInt("AutoMpPercentage", 70);
+ AUTO_CP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoCpItemIds", "0").split(","))
+ {
+ AUTO_CP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_HP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoHpItemIds", "0").split(","))
+ {
+ AUTO_HP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_MP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoMpItemIds", "0").split(","))
+ {
+ AUTO_MP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+
// Load Banking config file (if exists)
final PropertiesParser Banking = new PropertiesParser(CUSTOM_BANKING_CONFIG_FILE);
diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
new file mode 100644
index 0000000000..0819aebf24
--- /dev/null
+++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
@@ -0,0 +1,105 @@
+/*
+ * 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 com.l2jmobius.gameserver.model.actor.tasks.player;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.handler.ItemHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
+
+/**
+ * @author Mobius
+ */
+public class AutoPotionTask implements Runnable
+{
+ private final L2PcInstance _player;
+
+ public AutoPotionTask(L2PcInstance player)
+ {
+ _player = player;
+ }
+
+ @Override
+ public void run()
+ {
+ if ((_player == null) || (_player.isOnlineInt() != 1) || _player.isAlikeDead() || (!Config.AUTO_POTIONS_IN_OLYMPIAD && _player.isInOlympiadMode()))
+ {
+ return;
+ }
+
+ boolean success = false;
+ if (Config.AUTO_HP_ENABLED)
+ {
+ final boolean restoreHP = ((_player.getStatus().getCurrentHp() / _player.getMaxHp()) * 100) < Config.AUTO_HP_PERCENTAGE;
+ for (int itemId : Config.AUTO_HP_ITEM_IDS)
+ {
+ final L2ItemInstance hpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((hpPotion != null) && (hpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreHP)
+ {
+ ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(_player, hpPotion, false);
+ _player.sendMessage("Auto potion: Restored HP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_CP_ENABLED)
+ {
+ final boolean restoreCP = ((_player.getStatus().getCurrentCp() / _player.getMaxCp()) * 100) < Config.AUTO_CP_PERCENTAGE;
+ for (int itemId : Config.AUTO_CP_ITEM_IDS)
+ {
+ final L2ItemInstance cpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((cpPotion != null) && (cpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreCP)
+ {
+ ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(_player, cpPotion, false);
+ _player.sendMessage("Auto potion: Restored CP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_MP_ENABLED)
+ {
+ final boolean restoreMP = ((_player.getStatus().getCurrentMp() / _player.getMaxMp()) * 100) < Config.AUTO_MP_PERCENTAGE;
+ for (int itemId : Config.AUTO_MP_ITEM_IDS)
+ {
+ final L2ItemInstance mpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((mpPotion != null) && (mpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreMP)
+ {
+ ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(_player, mpPotion, false);
+ _player.sendMessage("Auto potion: Restored MP.");
+ break;
+ }
+ }
+ }
+ }
+
+ if (!success)
+ {
+ _player.sendMessage("Auto potion: You are out of potions!");
+ }
+ }
+}
diff --git a/L2J_Mobius_3.0_Helios/readme.txt b/L2J_Mobius_3.0_Helios/readme.txt
index f1db3c49cc..e6e50f4195 100644
--- a/L2J_Mobius_3.0_Helios/readme.txt
+++ b/L2J_Mobius_3.0_Helios/readme.txt
@@ -100,6 +100,7 @@ Events:
Customs:
-Allowed player races
+-Auto potions command
-Banking
-Champion monsters
-Classmaster
diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Custom/AutoPotions.ini b/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Custom/AutoPotions.ini
new file mode 100644
index 0000000000..2bb76c26d5
--- /dev/null
+++ b/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Custom/AutoPotions.ini
@@ -0,0 +1,34 @@
+# ---------------------------------------------------------------------------
+# Auto Potion Settings
+# ---------------------------------------------------------------------------
+# Use .apon / .apoff voiced commands to enable / disable.
+
+# Enable auto potion commands.
+AutoPotionsEnabled = false
+
+# Use auto potions in Olympiad.
+AutoPotionsInOlympiad = false
+
+# Mimim player level to use the commands.
+AutoPotionMinimumLevel = 1
+
+# Enable auto CP potions.
+AutoCpEnabled = true
+# Percentage that CP potions will be used.
+AutoCpPercentage = 70
+# Auto CP item ids. Order by use priority.
+AutoCpItemIds = 5592,5591
+
+# Enable auto HP potions.
+AutoHpEnabled = true
+# Percentage that HP potions will be used.
+AutoHpPercentage = 70
+# Auto HP item ids. Order by use priority.
+AutoHpItemIds = 1540,1539,1061,1060
+
+# Enable auto MP potions.
+AutoMpEnabled = true
+# Percentage that MP potions will be used.
+AutoMpPercentage = 70
+# Auto MP item ids. Order by use priority.
+AutoMpItemIds = 728
diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/MasterHandler.java b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/MasterHandler.java
index f407232e2e..15619c6ee5 100644
--- a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/MasterHandler.java
+++ b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/MasterHandler.java
@@ -327,6 +327,7 @@ import handlers.usercommandhandlers.PartyInfo;
import handlers.usercommandhandlers.SiegeStatus;
import handlers.usercommandhandlers.Time;
import handlers.usercommandhandlers.Unstuck;
+import handlers.voicedcommandhandlers.AutoPotion;
import handlers.voicedcommandhandlers.Banking;
import handlers.voicedcommandhandlers.ChangePassword;
import handlers.voicedcommandhandlers.ChatAdmin;
@@ -588,6 +589,7 @@ public class MasterHandler
Config.MULTILANG_ENABLE && Config.MULTILANG_VOICED_ALLOW ? Lang.class : null,
Config.ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null,
Config.PREMIUM_SYSTEM_ENABLED ? Premium.class : null,
+ Config.AUTO_POTIONS_ENABLED ? AutoPotion.class : null,
},
{
// Target Handlers
diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
new file mode 100644
index 0000000000..7f2ed62f90
--- /dev/null
+++ b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
@@ -0,0 +1,106 @@
+/*
+ * 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 handlers.voicedcommandhandlers;
+
+import java.util.HashMap;
+import java.util.concurrent.Future;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.ThreadPoolManager;
+import com.l2jmobius.gameserver.handler.IVoicedCommandHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.actor.tasks.player.AutoPotionTask;
+import com.l2jmobius.gameserver.model.events.EventType;
+import com.l2jmobius.gameserver.model.events.ListenerRegisterType;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterEvent;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterType;
+import com.l2jmobius.gameserver.model.events.impl.character.player.OnPlayerLogout;
+
+/**
+ * @author Gigi, Mobius
+ */
+public class AutoPotion implements IVoicedCommandHandler
+{
+ private static final HashMap> AUTO_POTION_TASKS = new HashMap<>();
+ private static final int POTION_TASK_DELAY = 1000; // 1 second
+
+ private static final String[] VOICED_COMMANDS =
+ {
+ "apon",
+ "apoff"
+ };
+
+ public static AutoPotion getInstance()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
+ {
+ if (!Config.AUTO_POTIONS_ENABLED || (activeChar == null))
+ {
+ return false;
+ }
+ if (activeChar.getLevel() < Config.AUTO_POTION_MIN_LVL)
+ {
+ activeChar.sendMessage("You need to be at least " + Config.AUTO_POTION_MIN_LVL + " to use auto potions.");
+ return false;
+ }
+
+ final int playerOID = activeChar.getObjectId();
+ if (command.equals("apon"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ AUTO_POTION_TASKS.put(activeChar.getObjectId(), ThreadPoolManager.scheduleAtFixedRate(new AutoPotionTask(activeChar), POTION_TASK_DELAY, POTION_TASK_DELAY));
+ activeChar.sendMessage("Auto potions is enabled.");
+ return true;
+ }
+ else if (command.equals("apoff"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ activeChar.sendMessage("Auto potions is disabled.");
+ }
+ return false;
+ }
+
+ @RegisterEvent(EventType.ON_PLAYER_LOGOUT)
+ @RegisterType(ListenerRegisterType.GLOBAL)
+ public void OnPlayerLogout(OnPlayerLogout event)
+ {
+ final int playerOID = event.getActiveChar().getObjectId();
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ }
+
+ @Override
+ public String[] getVoicedCommandList()
+ {
+ return VOICED_COMMANDS;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java
index 1c847d3465..dd407347ec 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java
@@ -109,6 +109,7 @@ public final class Config
// Custom Config File Definitions
// --------------------------------------------------
public static final String CUSTOM_ALLOWED_PLAYER_RACES_CONFIG_FILE = "./config/Custom/AllowedPlayerRaces.ini";
+ public static final String CUSTOM_AUTO_POTIONS_CONFIG_FILE = "./config/Custom/AutoPotions.ini";
public static final String CUSTOM_BANKING_CONFIG_FILE = "./config/Custom/Banking.ini";
public static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
public static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
@@ -1114,6 +1115,18 @@ public final class Config
public static boolean ALLOW_DWARF;
public static boolean ALLOW_KAMAEL;
public static boolean ALLOW_ERTHEIA;
+ public static boolean AUTO_POTIONS_ENABLED;
+ public static boolean AUTO_POTIONS_IN_OLYMPIAD;
+ public static int AUTO_POTION_MIN_LVL;
+ public static boolean AUTO_CP_ENABLED;
+ public static boolean AUTO_HP_ENABLED;
+ public static boolean AUTO_MP_ENABLED;
+ public static int AUTO_CP_PERCENTAGE;
+ public static int AUTO_HP_PERCENTAGE;
+ public static int AUTO_MP_PERCENTAGE;
+ public static List AUTO_CP_ITEM_IDS;
+ public static List AUTO_HP_ITEM_IDS;
+ public static List AUTO_MP_ITEM_IDS;
public static boolean CUSTOM_STARTING_LOC;
public static int CUSTOM_STARTING_LOC_X;
public static int CUSTOM_STARTING_LOC_Y;
@@ -2429,6 +2442,34 @@ public final class Config
ALLOW_KAMAEL = AllowedPlayerRaces.getBoolean("AllowKamael", true);
ALLOW_ERTHEIA = AllowedPlayerRaces.getBoolean("AllowErtheia", true);
+ // Load AutoPotions config file (if exists)
+ final PropertiesParser AutoPotions = new PropertiesParser(CUSTOM_AUTO_POTIONS_CONFIG_FILE);
+
+ AUTO_POTIONS_ENABLED = AutoPotions.getBoolean("AutoPotionsEnabled", false);
+ AUTO_POTIONS_IN_OLYMPIAD = AutoPotions.getBoolean("AutoPotionsInOlympiad", false);
+ AUTO_POTION_MIN_LVL = AutoPotions.getInt("AutoPotionMinimumLevel", 1);
+ AUTO_CP_ENABLED = AutoPotions.getBoolean("AutoCpEnabled", true);
+ AUTO_HP_ENABLED = AutoPotions.getBoolean("AutoHpEnabled", true);
+ AUTO_MP_ENABLED = AutoPotions.getBoolean("AutoMpEnabled", true);
+ AUTO_CP_PERCENTAGE = AutoPotions.getInt("AutoCpPercentage", 70);
+ AUTO_HP_PERCENTAGE = AutoPotions.getInt("AutoHpPercentage", 70);
+ AUTO_MP_PERCENTAGE = AutoPotions.getInt("AutoMpPercentage", 70);
+ AUTO_CP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoCpItemIds", "0").split(","))
+ {
+ AUTO_CP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_HP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoHpItemIds", "0").split(","))
+ {
+ AUTO_HP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_MP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoMpItemIds", "0").split(","))
+ {
+ AUTO_MP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+
// Load Banking config file (if exists)
final PropertiesParser Banking = new PropertiesParser(CUSTOM_BANKING_CONFIG_FILE);
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
new file mode 100644
index 0000000000..0819aebf24
--- /dev/null
+++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
@@ -0,0 +1,105 @@
+/*
+ * 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 com.l2jmobius.gameserver.model.actor.tasks.player;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.handler.ItemHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
+
+/**
+ * @author Mobius
+ */
+public class AutoPotionTask implements Runnable
+{
+ private final L2PcInstance _player;
+
+ public AutoPotionTask(L2PcInstance player)
+ {
+ _player = player;
+ }
+
+ @Override
+ public void run()
+ {
+ if ((_player == null) || (_player.isOnlineInt() != 1) || _player.isAlikeDead() || (!Config.AUTO_POTIONS_IN_OLYMPIAD && _player.isInOlympiadMode()))
+ {
+ return;
+ }
+
+ boolean success = false;
+ if (Config.AUTO_HP_ENABLED)
+ {
+ final boolean restoreHP = ((_player.getStatus().getCurrentHp() / _player.getMaxHp()) * 100) < Config.AUTO_HP_PERCENTAGE;
+ for (int itemId : Config.AUTO_HP_ITEM_IDS)
+ {
+ final L2ItemInstance hpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((hpPotion != null) && (hpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreHP)
+ {
+ ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(_player, hpPotion, false);
+ _player.sendMessage("Auto potion: Restored HP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_CP_ENABLED)
+ {
+ final boolean restoreCP = ((_player.getStatus().getCurrentCp() / _player.getMaxCp()) * 100) < Config.AUTO_CP_PERCENTAGE;
+ for (int itemId : Config.AUTO_CP_ITEM_IDS)
+ {
+ final L2ItemInstance cpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((cpPotion != null) && (cpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreCP)
+ {
+ ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(_player, cpPotion, false);
+ _player.sendMessage("Auto potion: Restored CP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_MP_ENABLED)
+ {
+ final boolean restoreMP = ((_player.getStatus().getCurrentMp() / _player.getMaxMp()) * 100) < Config.AUTO_MP_PERCENTAGE;
+ for (int itemId : Config.AUTO_MP_ITEM_IDS)
+ {
+ final L2ItemInstance mpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((mpPotion != null) && (mpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreMP)
+ {
+ ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(_player, mpPotion, false);
+ _player.sendMessage("Auto potion: Restored MP.");
+ break;
+ }
+ }
+ }
+ }
+
+ if (!success)
+ {
+ _player.sendMessage("Auto potion: You are out of potions!");
+ }
+ }
+}
diff --git a/L2J_Mobius_4.0_GrandCrusade/readme.txt b/L2J_Mobius_4.0_GrandCrusade/readme.txt
index 44ef986610..db50c454de 100644
--- a/L2J_Mobius_4.0_GrandCrusade/readme.txt
+++ b/L2J_Mobius_4.0_GrandCrusade/readme.txt
@@ -104,6 +104,7 @@ Events:
Customs:
-Allowed player races
+-Auto potions command
-Banking
-Champion monsters
-Classmaster
diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Custom.ini b/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Custom.ini
index 0a8704da5c..bd93aebac7 100644
--- a/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Custom.ini
+++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Custom.ini
@@ -681,3 +681,39 @@ PremiumRateDropAmountByItemId = 57,2;6656,1;6657,1;6658,1;6659,1;6660,1;6661,1;6
# Enable FindPvP bypass.
# Default: False
EnableFindPvP = False
+
+
+# ---------------------------------------------------------------------------
+# Auto Potion Settings
+# ---------------------------------------------------------------------------
+# Use .apon / .apoff voiced commands to enable / disable.
+
+# Enable auto potion commands.
+AutoPotionsEnabled = false
+
+# Use auto potions in Olympiad.
+AutoPotionsInOlympiad = false
+
+# Mimim player level to use the commands.
+AutoPotionMinimumLevel = 1
+
+# Enable auto CP potions.
+AutoCpEnabled = true
+# Percentage that CP potions will be used.
+AutoCpPercentage = 70
+# Auto CP item ids. Order by use priority.
+AutoCpItemIds = 5592,5591
+
+# Enable auto HP potions.
+AutoHpEnabled = true
+# Percentage that HP potions will be used.
+AutoHpPercentage = 70
+# Auto HP item ids. Order by use priority.
+AutoHpItemIds = 1540,1539,1061,1060
+
+# Enable auto MP potions.
+AutoMpEnabled = true
+# Percentage that MP potions will be used.
+AutoMpPercentage = 70
+# Auto MP item ids. Order by use priority.
+AutoMpItemIds = 728
diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/MasterHandler.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/MasterHandler.java
index d3c6bae702..4f8ddd172b 100644
--- a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/MasterHandler.java
+++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/MasterHandler.java
@@ -274,6 +274,7 @@ import handlers.usercommandhandlers.PartyInfo;
import handlers.usercommandhandlers.SiegeStatus;
import handlers.usercommandhandlers.Time;
import handlers.usercommandhandlers.Unstuck;
+import handlers.voicedcommandhandlers.AutoPotion;
import handlers.voicedcommandhandlers.Banking;
import handlers.voicedcommandhandlers.ChangePassword;
import handlers.voicedcommandhandlers.ChatAdmin;
@@ -541,6 +542,7 @@ public class MasterHandler
Config.L2JMOD_MULTILANG_ENABLE && Config.L2JMOD_MULTILANG_VOICED_ALLOW ? Lang.class : null,
Config.L2JMOD_ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null,
Config.PREMIUM_SYSTEM_ENABLED ? Premium.class : null,
+ Config.AUTO_POTIONS_ENABLED ? AutoPotion.class : null,
},
{
// Target Handlers
diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
new file mode 100644
index 0000000000..7f2ed62f90
--- /dev/null
+++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
@@ -0,0 +1,106 @@
+/*
+ * 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 handlers.voicedcommandhandlers;
+
+import java.util.HashMap;
+import java.util.concurrent.Future;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.ThreadPoolManager;
+import com.l2jmobius.gameserver.handler.IVoicedCommandHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.actor.tasks.player.AutoPotionTask;
+import com.l2jmobius.gameserver.model.events.EventType;
+import com.l2jmobius.gameserver.model.events.ListenerRegisterType;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterEvent;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterType;
+import com.l2jmobius.gameserver.model.events.impl.character.player.OnPlayerLogout;
+
+/**
+ * @author Gigi, Mobius
+ */
+public class AutoPotion implements IVoicedCommandHandler
+{
+ private static final HashMap> AUTO_POTION_TASKS = new HashMap<>();
+ private static final int POTION_TASK_DELAY = 1000; // 1 second
+
+ private static final String[] VOICED_COMMANDS =
+ {
+ "apon",
+ "apoff"
+ };
+
+ public static AutoPotion getInstance()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
+ {
+ if (!Config.AUTO_POTIONS_ENABLED || (activeChar == null))
+ {
+ return false;
+ }
+ if (activeChar.getLevel() < Config.AUTO_POTION_MIN_LVL)
+ {
+ activeChar.sendMessage("You need to be at least " + Config.AUTO_POTION_MIN_LVL + " to use auto potions.");
+ return false;
+ }
+
+ final int playerOID = activeChar.getObjectId();
+ if (command.equals("apon"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ AUTO_POTION_TASKS.put(activeChar.getObjectId(), ThreadPoolManager.scheduleAtFixedRate(new AutoPotionTask(activeChar), POTION_TASK_DELAY, POTION_TASK_DELAY));
+ activeChar.sendMessage("Auto potions is enabled.");
+ return true;
+ }
+ else if (command.equals("apoff"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ activeChar.sendMessage("Auto potions is disabled.");
+ }
+ return false;
+ }
+
+ @RegisterEvent(EventType.ON_PLAYER_LOGOUT)
+ @RegisterType(ListenerRegisterType.GLOBAL)
+ public void OnPlayerLogout(OnPlayerLogout event)
+ {
+ final int playerOID = event.getActiveChar().getObjectId();
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ }
+
+ @Override
+ public String[] getVoicedCommandList()
+ {
+ return VOICED_COMMANDS;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java
index 3b04380200..e791060996 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java
@@ -822,6 +822,18 @@ public final class Config
public static Map PREMIUM_RATE_DROP_CHANCE_BY_ID;
public static Map PREMIUM_RATE_DROP_AMOUNT_BY_ID;
public static boolean ENABLE_FIND_PVP;
+ public static boolean AUTO_POTIONS_ENABLED;
+ public static boolean AUTO_POTIONS_IN_OLYMPIAD;
+ public static int AUTO_POTION_MIN_LVL;
+ public static boolean AUTO_CP_ENABLED;
+ public static boolean AUTO_HP_ENABLED;
+ public static boolean AUTO_MP_ENABLED;
+ public static int AUTO_CP_PERCENTAGE;
+ public static int AUTO_HP_PERCENTAGE;
+ public static int AUTO_MP_PERCENTAGE;
+ public static List AUTO_CP_ITEM_IDS;
+ public static List AUTO_HP_ITEM_IDS;
+ public static List AUTO_MP_ITEM_IDS;
// --------------------------------------------------
// NPC Settings
// --------------------------------------------------
@@ -2711,6 +2723,31 @@ public final class Config
ENABLE_FIND_PVP = CustomSettings.getBoolean("EnableFindPvP", false);
+ AUTO_POTIONS_ENABLED = CustomSettings.getBoolean("AutoPotionsEnabled", false);
+ AUTO_POTIONS_IN_OLYMPIAD = CustomSettings.getBoolean("AutoPotionsInOlympiad", false);
+ AUTO_POTION_MIN_LVL = CustomSettings.getInt("AutoPotionMinimumLevel", 1);
+ AUTO_CP_ENABLED = CustomSettings.getBoolean("AutoCpEnabled", true);
+ AUTO_HP_ENABLED = CustomSettings.getBoolean("AutoHpEnabled", true);
+ AUTO_MP_ENABLED = CustomSettings.getBoolean("AutoMpEnabled", true);
+ AUTO_CP_PERCENTAGE = CustomSettings.getInt("AutoCpPercentage", 70);
+ AUTO_HP_PERCENTAGE = CustomSettings.getInt("AutoHpPercentage", 70);
+ AUTO_MP_PERCENTAGE = CustomSettings.getInt("AutoMpPercentage", 70);
+ AUTO_CP_ITEM_IDS = new ArrayList<>();
+ for (String s : CustomSettings.getString("AutoCpItemIds", "0").split(","))
+ {
+ AUTO_CP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_HP_ITEM_IDS = new ArrayList<>();
+ for (String s : CustomSettings.getString("AutoHpItemIds", "0").split(","))
+ {
+ AUTO_HP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_MP_ITEM_IDS = new ArrayList<>();
+ for (String s : CustomSettings.getString("AutoMpItemIds", "0").split(","))
+ {
+ AUTO_MP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+
// Load PvP L2Properties file (if exists)
final PropertiesParser PVPSettings = new PropertiesParser(PVP_CONFIG_FILE);
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
new file mode 100644
index 0000000000..0819aebf24
--- /dev/null
+++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
@@ -0,0 +1,105 @@
+/*
+ * 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 com.l2jmobius.gameserver.model.actor.tasks.player;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.handler.ItemHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
+
+/**
+ * @author Mobius
+ */
+public class AutoPotionTask implements Runnable
+{
+ private final L2PcInstance _player;
+
+ public AutoPotionTask(L2PcInstance player)
+ {
+ _player = player;
+ }
+
+ @Override
+ public void run()
+ {
+ if ((_player == null) || (_player.isOnlineInt() != 1) || _player.isAlikeDead() || (!Config.AUTO_POTIONS_IN_OLYMPIAD && _player.isInOlympiadMode()))
+ {
+ return;
+ }
+
+ boolean success = false;
+ if (Config.AUTO_HP_ENABLED)
+ {
+ final boolean restoreHP = ((_player.getStatus().getCurrentHp() / _player.getMaxHp()) * 100) < Config.AUTO_HP_PERCENTAGE;
+ for (int itemId : Config.AUTO_HP_ITEM_IDS)
+ {
+ final L2ItemInstance hpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((hpPotion != null) && (hpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreHP)
+ {
+ ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(_player, hpPotion, false);
+ _player.sendMessage("Auto potion: Restored HP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_CP_ENABLED)
+ {
+ final boolean restoreCP = ((_player.getStatus().getCurrentCp() / _player.getMaxCp()) * 100) < Config.AUTO_CP_PERCENTAGE;
+ for (int itemId : Config.AUTO_CP_ITEM_IDS)
+ {
+ final L2ItemInstance cpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((cpPotion != null) && (cpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreCP)
+ {
+ ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(_player, cpPotion, false);
+ _player.sendMessage("Auto potion: Restored CP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_MP_ENABLED)
+ {
+ final boolean restoreMP = ((_player.getStatus().getCurrentMp() / _player.getMaxMp()) * 100) < Config.AUTO_MP_PERCENTAGE;
+ for (int itemId : Config.AUTO_MP_ITEM_IDS)
+ {
+ final L2ItemInstance mpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((mpPotion != null) && (mpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreMP)
+ {
+ ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(_player, mpPotion, false);
+ _player.sendMessage("Auto potion: Restored MP.");
+ break;
+ }
+ }
+ }
+ }
+
+ if (!success)
+ {
+ _player.sendMessage("Auto potion: You are out of potions!");
+ }
+ }
+}
diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Custom/AutoPotions.ini b/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Custom/AutoPotions.ini
new file mode 100644
index 0000000000..2bb76c26d5
--- /dev/null
+++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Custom/AutoPotions.ini
@@ -0,0 +1,34 @@
+# ---------------------------------------------------------------------------
+# Auto Potion Settings
+# ---------------------------------------------------------------------------
+# Use .apon / .apoff voiced commands to enable / disable.
+
+# Enable auto potion commands.
+AutoPotionsEnabled = false
+
+# Use auto potions in Olympiad.
+AutoPotionsInOlympiad = false
+
+# Mimim player level to use the commands.
+AutoPotionMinimumLevel = 1
+
+# Enable auto CP potions.
+AutoCpEnabled = true
+# Percentage that CP potions will be used.
+AutoCpPercentage = 70
+# Auto CP item ids. Order by use priority.
+AutoCpItemIds = 5592,5591
+
+# Enable auto HP potions.
+AutoHpEnabled = true
+# Percentage that HP potions will be used.
+AutoHpPercentage = 70
+# Auto HP item ids. Order by use priority.
+AutoHpItemIds = 1540,1539,1061,1060
+
+# Enable auto MP potions.
+AutoMpEnabled = true
+# Percentage that MP potions will be used.
+AutoMpPercentage = 70
+# Auto MP item ids. Order by use priority.
+AutoMpItemIds = 728
diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/MasterHandler.java b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/MasterHandler.java
index 567c257ad0..9afcf3bb83 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/MasterHandler.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/MasterHandler.java
@@ -327,6 +327,7 @@ import handlers.usercommandhandlers.PartyInfo;
import handlers.usercommandhandlers.SiegeStatus;
import handlers.usercommandhandlers.Time;
import handlers.usercommandhandlers.Unstuck;
+import handlers.voicedcommandhandlers.AutoPotion;
import handlers.voicedcommandhandlers.Banking;
import handlers.voicedcommandhandlers.ChangePassword;
import handlers.voicedcommandhandlers.ChatAdmin;
@@ -588,6 +589,7 @@ public class MasterHandler
Config.MULTILANG_ENABLE && Config.MULTILANG_VOICED_ALLOW ? Lang.class : null,
Config.ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null,
Config.PREMIUM_SYSTEM_ENABLED ? Premium.class : null,
+ Config.AUTO_POTIONS_ENABLED ? AutoPotion.class : null,
},
{
// Target Handlers
diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
new file mode 100644
index 0000000000..7f2ed62f90
--- /dev/null
+++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
@@ -0,0 +1,106 @@
+/*
+ * 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 handlers.voicedcommandhandlers;
+
+import java.util.HashMap;
+import java.util.concurrent.Future;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.ThreadPoolManager;
+import com.l2jmobius.gameserver.handler.IVoicedCommandHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.actor.tasks.player.AutoPotionTask;
+import com.l2jmobius.gameserver.model.events.EventType;
+import com.l2jmobius.gameserver.model.events.ListenerRegisterType;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterEvent;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterType;
+import com.l2jmobius.gameserver.model.events.impl.character.player.OnPlayerLogout;
+
+/**
+ * @author Gigi, Mobius
+ */
+public class AutoPotion implements IVoicedCommandHandler
+{
+ private static final HashMap> AUTO_POTION_TASKS = new HashMap<>();
+ private static final int POTION_TASK_DELAY = 1000; // 1 second
+
+ private static final String[] VOICED_COMMANDS =
+ {
+ "apon",
+ "apoff"
+ };
+
+ public static AutoPotion getInstance()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
+ {
+ if (!Config.AUTO_POTIONS_ENABLED || (activeChar == null))
+ {
+ return false;
+ }
+ if (activeChar.getLevel() < Config.AUTO_POTION_MIN_LVL)
+ {
+ activeChar.sendMessage("You need to be at least " + Config.AUTO_POTION_MIN_LVL + " to use auto potions.");
+ return false;
+ }
+
+ final int playerOID = activeChar.getObjectId();
+ if (command.equals("apon"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ AUTO_POTION_TASKS.put(activeChar.getObjectId(), ThreadPoolManager.scheduleAtFixedRate(new AutoPotionTask(activeChar), POTION_TASK_DELAY, POTION_TASK_DELAY));
+ activeChar.sendMessage("Auto potions is enabled.");
+ return true;
+ }
+ else if (command.equals("apoff"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ activeChar.sendMessage("Auto potions is disabled.");
+ }
+ return false;
+ }
+
+ @RegisterEvent(EventType.ON_PLAYER_LOGOUT)
+ @RegisterType(ListenerRegisterType.GLOBAL)
+ public void OnPlayerLogout(OnPlayerLogout event)
+ {
+ final int playerOID = event.getActiveChar().getObjectId();
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ }
+
+ @Override
+ public String[] getVoicedCommandList()
+ {
+ return VOICED_COMMANDS;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java
index 47a210d47f..7bc69b8542 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java
@@ -109,6 +109,7 @@ public final class Config
// Custom Config File Definitions
// --------------------------------------------------
public static final String CUSTOM_ALLOWED_PLAYER_RACES_CONFIG_FILE = "./config/Custom/AllowedPlayerRaces.ini";
+ public static final String CUSTOM_AUTO_POTIONS_CONFIG_FILE = "./config/Custom/AutoPotions.ini";
public static final String CUSTOM_BANKING_CONFIG_FILE = "./config/Custom/Banking.ini";
public static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
public static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
@@ -1047,6 +1048,18 @@ public final class Config
public static boolean ALLOW_DWARF;
public static boolean ALLOW_KAMAEL;
public static boolean ALLOW_ERTHEIA;
+ public static boolean AUTO_POTIONS_ENABLED;
+ public static boolean AUTO_POTIONS_IN_OLYMPIAD;
+ public static int AUTO_POTION_MIN_LVL;
+ public static boolean AUTO_CP_ENABLED;
+ public static boolean AUTO_HP_ENABLED;
+ public static boolean AUTO_MP_ENABLED;
+ public static int AUTO_CP_PERCENTAGE;
+ public static int AUTO_HP_PERCENTAGE;
+ public static int AUTO_MP_PERCENTAGE;
+ public static List AUTO_CP_ITEM_IDS;
+ public static List AUTO_HP_ITEM_IDS;
+ public static List AUTO_MP_ITEM_IDS;
public static boolean CUSTOM_STARTING_LOC;
public static int CUSTOM_STARTING_LOC_X;
public static int CUSTOM_STARTING_LOC_Y;
@@ -2305,6 +2318,34 @@ public final class Config
ALLOW_KAMAEL = AllowedPlayerRaces.getBoolean("AllowKamael", true);
ALLOW_ERTHEIA = AllowedPlayerRaces.getBoolean("AllowErtheia", true);
+ // Load AutoPotions config file (if exists)
+ final PropertiesParser AutoPotions = new PropertiesParser(CUSTOM_AUTO_POTIONS_CONFIG_FILE);
+
+ AUTO_POTIONS_ENABLED = AutoPotions.getBoolean("AutoPotionsEnabled", false);
+ AUTO_POTIONS_IN_OLYMPIAD = AutoPotions.getBoolean("AutoPotionsInOlympiad", false);
+ AUTO_POTION_MIN_LVL = AutoPotions.getInt("AutoPotionMinimumLevel", 1);
+ AUTO_CP_ENABLED = AutoPotions.getBoolean("AutoCpEnabled", true);
+ AUTO_HP_ENABLED = AutoPotions.getBoolean("AutoHpEnabled", true);
+ AUTO_MP_ENABLED = AutoPotions.getBoolean("AutoMpEnabled", true);
+ AUTO_CP_PERCENTAGE = AutoPotions.getInt("AutoCpPercentage", 70);
+ AUTO_HP_PERCENTAGE = AutoPotions.getInt("AutoHpPercentage", 70);
+ AUTO_MP_PERCENTAGE = AutoPotions.getInt("AutoMpPercentage", 70);
+ AUTO_CP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoCpItemIds", "0").split(","))
+ {
+ AUTO_CP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_HP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoHpItemIds", "0").split(","))
+ {
+ AUTO_HP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_MP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoMpItemIds", "0").split(","))
+ {
+ AUTO_MP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+
// Load Banking config file (if exists)
final PropertiesParser Banking = new PropertiesParser(CUSTOM_BANKING_CONFIG_FILE);
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
new file mode 100644
index 0000000000..0819aebf24
--- /dev/null
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
@@ -0,0 +1,105 @@
+/*
+ * 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 com.l2jmobius.gameserver.model.actor.tasks.player;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.handler.ItemHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
+
+/**
+ * @author Mobius
+ */
+public class AutoPotionTask implements Runnable
+{
+ private final L2PcInstance _player;
+
+ public AutoPotionTask(L2PcInstance player)
+ {
+ _player = player;
+ }
+
+ @Override
+ public void run()
+ {
+ if ((_player == null) || (_player.isOnlineInt() != 1) || _player.isAlikeDead() || (!Config.AUTO_POTIONS_IN_OLYMPIAD && _player.isInOlympiadMode()))
+ {
+ return;
+ }
+
+ boolean success = false;
+ if (Config.AUTO_HP_ENABLED)
+ {
+ final boolean restoreHP = ((_player.getStatus().getCurrentHp() / _player.getMaxHp()) * 100) < Config.AUTO_HP_PERCENTAGE;
+ for (int itemId : Config.AUTO_HP_ITEM_IDS)
+ {
+ final L2ItemInstance hpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((hpPotion != null) && (hpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreHP)
+ {
+ ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(_player, hpPotion, false);
+ _player.sendMessage("Auto potion: Restored HP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_CP_ENABLED)
+ {
+ final boolean restoreCP = ((_player.getStatus().getCurrentCp() / _player.getMaxCp()) * 100) < Config.AUTO_CP_PERCENTAGE;
+ for (int itemId : Config.AUTO_CP_ITEM_IDS)
+ {
+ final L2ItemInstance cpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((cpPotion != null) && (cpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreCP)
+ {
+ ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(_player, cpPotion, false);
+ _player.sendMessage("Auto potion: Restored CP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_MP_ENABLED)
+ {
+ final boolean restoreMP = ((_player.getStatus().getCurrentMp() / _player.getMaxMp()) * 100) < Config.AUTO_MP_PERCENTAGE;
+ for (int itemId : Config.AUTO_MP_ITEM_IDS)
+ {
+ final L2ItemInstance mpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((mpPotion != null) && (mpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreMP)
+ {
+ ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(_player, mpPotion, false);
+ _player.sendMessage("Auto potion: Restored MP.");
+ break;
+ }
+ }
+ }
+ }
+
+ if (!success)
+ {
+ _player.sendMessage("Auto potion: You are out of potions!");
+ }
+ }
+}
diff --git a/L2J_Mobius_Classic_2.0_Zaken/dist/game/config/Custom/AutoPotions.ini b/L2J_Mobius_Classic_2.0_Zaken/dist/game/config/Custom/AutoPotions.ini
new file mode 100644
index 0000000000..2bb76c26d5
--- /dev/null
+++ b/L2J_Mobius_Classic_2.0_Zaken/dist/game/config/Custom/AutoPotions.ini
@@ -0,0 +1,34 @@
+# ---------------------------------------------------------------------------
+# Auto Potion Settings
+# ---------------------------------------------------------------------------
+# Use .apon / .apoff voiced commands to enable / disable.
+
+# Enable auto potion commands.
+AutoPotionsEnabled = false
+
+# Use auto potions in Olympiad.
+AutoPotionsInOlympiad = false
+
+# Mimim player level to use the commands.
+AutoPotionMinimumLevel = 1
+
+# Enable auto CP potions.
+AutoCpEnabled = true
+# Percentage that CP potions will be used.
+AutoCpPercentage = 70
+# Auto CP item ids. Order by use priority.
+AutoCpItemIds = 5592,5591
+
+# Enable auto HP potions.
+AutoHpEnabled = true
+# Percentage that HP potions will be used.
+AutoHpPercentage = 70
+# Auto HP item ids. Order by use priority.
+AutoHpItemIds = 1540,1539,1061,1060
+
+# Enable auto MP potions.
+AutoMpEnabled = true
+# Percentage that MP potions will be used.
+AutoMpPercentage = 70
+# Auto MP item ids. Order by use priority.
+AutoMpItemIds = 728
diff --git a/L2J_Mobius_Classic_2.0_Zaken/dist/game/data/scripts/handlers/MasterHandler.java b/L2J_Mobius_Classic_2.0_Zaken/dist/game/data/scripts/handlers/MasterHandler.java
index 567c257ad0..9afcf3bb83 100644
--- a/L2J_Mobius_Classic_2.0_Zaken/dist/game/data/scripts/handlers/MasterHandler.java
+++ b/L2J_Mobius_Classic_2.0_Zaken/dist/game/data/scripts/handlers/MasterHandler.java
@@ -327,6 +327,7 @@ import handlers.usercommandhandlers.PartyInfo;
import handlers.usercommandhandlers.SiegeStatus;
import handlers.usercommandhandlers.Time;
import handlers.usercommandhandlers.Unstuck;
+import handlers.voicedcommandhandlers.AutoPotion;
import handlers.voicedcommandhandlers.Banking;
import handlers.voicedcommandhandlers.ChangePassword;
import handlers.voicedcommandhandlers.ChatAdmin;
@@ -588,6 +589,7 @@ public class MasterHandler
Config.MULTILANG_ENABLE && Config.MULTILANG_VOICED_ALLOW ? Lang.class : null,
Config.ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null,
Config.PREMIUM_SYSTEM_ENABLED ? Premium.class : null,
+ Config.AUTO_POTIONS_ENABLED ? AutoPotion.class : null,
},
{
// Target Handlers
diff --git a/L2J_Mobius_Classic_2.0_Zaken/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java b/L2J_Mobius_Classic_2.0_Zaken/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
new file mode 100644
index 0000000000..7f2ed62f90
--- /dev/null
+++ b/L2J_Mobius_Classic_2.0_Zaken/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
@@ -0,0 +1,106 @@
+/*
+ * 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 handlers.voicedcommandhandlers;
+
+import java.util.HashMap;
+import java.util.concurrent.Future;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.ThreadPoolManager;
+import com.l2jmobius.gameserver.handler.IVoicedCommandHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.actor.tasks.player.AutoPotionTask;
+import com.l2jmobius.gameserver.model.events.EventType;
+import com.l2jmobius.gameserver.model.events.ListenerRegisterType;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterEvent;
+import com.l2jmobius.gameserver.model.events.annotations.RegisterType;
+import com.l2jmobius.gameserver.model.events.impl.character.player.OnPlayerLogout;
+
+/**
+ * @author Gigi, Mobius
+ */
+public class AutoPotion implements IVoicedCommandHandler
+{
+ private static final HashMap> AUTO_POTION_TASKS = new HashMap<>();
+ private static final int POTION_TASK_DELAY = 1000; // 1 second
+
+ private static final String[] VOICED_COMMANDS =
+ {
+ "apon",
+ "apoff"
+ };
+
+ public static AutoPotion getInstance()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
+ {
+ if (!Config.AUTO_POTIONS_ENABLED || (activeChar == null))
+ {
+ return false;
+ }
+ if (activeChar.getLevel() < Config.AUTO_POTION_MIN_LVL)
+ {
+ activeChar.sendMessage("You need to be at least " + Config.AUTO_POTION_MIN_LVL + " to use auto potions.");
+ return false;
+ }
+
+ final int playerOID = activeChar.getObjectId();
+ if (command.equals("apon"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ AUTO_POTION_TASKS.put(activeChar.getObjectId(), ThreadPoolManager.scheduleAtFixedRate(new AutoPotionTask(activeChar), POTION_TASK_DELAY, POTION_TASK_DELAY));
+ activeChar.sendMessage("Auto potions is enabled.");
+ return true;
+ }
+ else if (command.equals("apoff"))
+ {
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ activeChar.sendMessage("Auto potions is disabled.");
+ }
+ return false;
+ }
+
+ @RegisterEvent(EventType.ON_PLAYER_LOGOUT)
+ @RegisterType(ListenerRegisterType.GLOBAL)
+ public void OnPlayerLogout(OnPlayerLogout event)
+ {
+ final int playerOID = event.getActiveChar().getObjectId();
+ if (AUTO_POTION_TASKS.containsKey(playerOID))
+ {
+ AUTO_POTION_TASKS.get(playerOID).cancel(true);
+ AUTO_POTION_TASKS.remove(playerOID);
+ }
+ }
+
+ @Override
+ public String[] getVoicedCommandList()
+ {
+ return VOICED_COMMANDS;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/Config.java b/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/Config.java
index 9da6d932c5..da8bea079f 100644
--- a/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/Config.java
@@ -109,6 +109,7 @@ public final class Config
// Custom Config File Definitions
// --------------------------------------------------
public static final String CUSTOM_ALLOWED_PLAYER_RACES_CONFIG_FILE = "./config/Custom/AllowedPlayerRaces.ini";
+ public static final String CUSTOM_AUTO_POTIONS_CONFIG_FILE = "./config/Custom/AutoPotions.ini";
public static final String CUSTOM_BANKING_CONFIG_FILE = "./config/Custom/Banking.ini";
public static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
public static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
@@ -1051,6 +1052,18 @@ public final class Config
public static boolean ALLOW_DWARF;
public static boolean ALLOW_KAMAEL;
public static boolean ALLOW_ERTHEIA;
+ public static boolean AUTO_POTIONS_ENABLED;
+ public static boolean AUTO_POTIONS_IN_OLYMPIAD;
+ public static int AUTO_POTION_MIN_LVL;
+ public static boolean AUTO_CP_ENABLED;
+ public static boolean AUTO_HP_ENABLED;
+ public static boolean AUTO_MP_ENABLED;
+ public static int AUTO_CP_PERCENTAGE;
+ public static int AUTO_HP_PERCENTAGE;
+ public static int AUTO_MP_PERCENTAGE;
+ public static List AUTO_CP_ITEM_IDS;
+ public static List AUTO_HP_ITEM_IDS;
+ public static List AUTO_MP_ITEM_IDS;
public static boolean CUSTOM_STARTING_LOC;
public static int CUSTOM_STARTING_LOC_X;
public static int CUSTOM_STARTING_LOC_Y;
@@ -2312,6 +2325,34 @@ public final class Config
ALLOW_KAMAEL = AllowedPlayerRaces.getBoolean("AllowKamael", true);
ALLOW_ERTHEIA = AllowedPlayerRaces.getBoolean("AllowErtheia", true);
+ // Load AutoPotions config file (if exists)
+ final PropertiesParser AutoPotions = new PropertiesParser(CUSTOM_AUTO_POTIONS_CONFIG_FILE);
+
+ AUTO_POTIONS_ENABLED = AutoPotions.getBoolean("AutoPotionsEnabled", false);
+ AUTO_POTIONS_IN_OLYMPIAD = AutoPotions.getBoolean("AutoPotionsInOlympiad", false);
+ AUTO_POTION_MIN_LVL = AutoPotions.getInt("AutoPotionMinimumLevel", 1);
+ AUTO_CP_ENABLED = AutoPotions.getBoolean("AutoCpEnabled", true);
+ AUTO_HP_ENABLED = AutoPotions.getBoolean("AutoHpEnabled", true);
+ AUTO_MP_ENABLED = AutoPotions.getBoolean("AutoMpEnabled", true);
+ AUTO_CP_PERCENTAGE = AutoPotions.getInt("AutoCpPercentage", 70);
+ AUTO_HP_PERCENTAGE = AutoPotions.getInt("AutoHpPercentage", 70);
+ AUTO_MP_PERCENTAGE = AutoPotions.getInt("AutoMpPercentage", 70);
+ AUTO_CP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoCpItemIds", "0").split(","))
+ {
+ AUTO_CP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_HP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoHpItemIds", "0").split(","))
+ {
+ AUTO_HP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+ AUTO_MP_ITEM_IDS = new ArrayList<>();
+ for (String s : AutoPotions.getString("AutoMpItemIds", "0").split(","))
+ {
+ AUTO_MP_ITEM_IDS.add(Integer.parseInt(s));
+ }
+
// Load Banking config file (if exists)
final PropertiesParser Banking = new PropertiesParser(CUSTOM_BANKING_CONFIG_FILE);
diff --git a/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java b/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
new file mode 100644
index 0000000000..0819aebf24
--- /dev/null
+++ b/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/gameserver/model/actor/tasks/player/AutoPotionTask.java
@@ -0,0 +1,105 @@
+/*
+ * 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 com.l2jmobius.gameserver.model.actor.tasks.player;
+
+import com.l2jmobius.Config;
+import com.l2jmobius.gameserver.handler.ItemHandler;
+import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
+
+/**
+ * @author Mobius
+ */
+public class AutoPotionTask implements Runnable
+{
+ private final L2PcInstance _player;
+
+ public AutoPotionTask(L2PcInstance player)
+ {
+ _player = player;
+ }
+
+ @Override
+ public void run()
+ {
+ if ((_player == null) || (_player.isOnlineInt() != 1) || _player.isAlikeDead() || (!Config.AUTO_POTIONS_IN_OLYMPIAD && _player.isInOlympiadMode()))
+ {
+ return;
+ }
+
+ boolean success = false;
+ if (Config.AUTO_HP_ENABLED)
+ {
+ final boolean restoreHP = ((_player.getStatus().getCurrentHp() / _player.getMaxHp()) * 100) < Config.AUTO_HP_PERCENTAGE;
+ for (int itemId : Config.AUTO_HP_ITEM_IDS)
+ {
+ final L2ItemInstance hpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((hpPotion != null) && (hpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreHP)
+ {
+ ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(_player, hpPotion, false);
+ _player.sendMessage("Auto potion: Restored HP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_CP_ENABLED)
+ {
+ final boolean restoreCP = ((_player.getStatus().getCurrentCp() / _player.getMaxCp()) * 100) < Config.AUTO_CP_PERCENTAGE;
+ for (int itemId : Config.AUTO_CP_ITEM_IDS)
+ {
+ final L2ItemInstance cpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((cpPotion != null) && (cpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreCP)
+ {
+ ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(_player, cpPotion, false);
+ _player.sendMessage("Auto potion: Restored CP.");
+ break;
+ }
+ }
+ }
+ }
+ if (Config.AUTO_MP_ENABLED)
+ {
+ final boolean restoreMP = ((_player.getStatus().getCurrentMp() / _player.getMaxMp()) * 100) < Config.AUTO_MP_PERCENTAGE;
+ for (int itemId : Config.AUTO_MP_ITEM_IDS)
+ {
+ final L2ItemInstance mpPotion = _player.getInventory().getItemByItemId(itemId);
+ if ((mpPotion != null) && (mpPotion.getCount() > 0))
+ {
+ success = true;
+ if (restoreMP)
+ {
+ ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(_player, mpPotion, false);
+ _player.sendMessage("Auto potion: Restored MP.");
+ break;
+ }
+ }
+ }
+ }
+
+ if (!success)
+ {
+ _player.sendMessage("Auto potion: You are out of potions!");
+ }
+ }
+}