Addition of custom auto potions feature.
This commit is contained in:
34
L2J_Mobius_C6_Interlude/dist/game/config/custom/AutoPotions.ini
vendored
Normal file
34
L2J_Mobius_C6_Interlude/dist/game/config/custom/AutoPotions.ini
vendored
Normal file
@@ -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
|
||||
|
||||
# Minimum 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
|
@@ -90,6 +90,7 @@ public class Config
|
||||
private static final String BANK_CONFIG_FILE = "./config/custom/Bank.ini";
|
||||
private static final String CANCEL_SKILL_RESTORE_BUFFS_CONFIG_FILE = "./config/custom/CancelSkillRestoreBuffs.ini";
|
||||
private static final String CHAMPION_CONFIG_FILE = "./config/custom/Champion.ini";
|
||||
private static final String CUSTOM_AUTO_POTIONS_CONFIG_FILE = "./config/custom/AutoPotions.ini";
|
||||
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/custom/CustomMailManager.ini";
|
||||
private static final String MERCHANT_ZERO_SELL_PRICE_CONFIG_FILE = "./config/custom/MerchantZeroSellPrice.ini";
|
||||
private static final String OFFLINE_CONFIG_FILE = "./config/custom/Offline.ini";
|
||||
@@ -475,6 +476,19 @@ public class Config
|
||||
public static String CHAMP_TITLE;
|
||||
public static int CHAMPION_AURA;
|
||||
|
||||
public static boolean AUTO_POTIONS_ENABLED;
|
||||
public static boolean AUTO_POTIONS_IN_OLYMPIAD;
|
||||
public static int AUTO_POTION_MIN_LEVEL;
|
||||
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<Integer> AUTO_CP_ITEM_IDS;
|
||||
public static List<Integer> AUTO_HP_ITEM_IDS;
|
||||
public static List<Integer> AUTO_MP_ITEM_IDS;
|
||||
|
||||
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
|
||||
public static int CUSTOM_MAIL_MANAGER_DELAY;
|
||||
|
||||
@@ -1682,6 +1696,35 @@ public class Config
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadAutoPotionsConfig()
|
||||
{
|
||||
final PropertiesParser autoPotionsConfig = new PropertiesParser(CUSTOM_AUTO_POTIONS_CONFIG_FILE);
|
||||
AUTO_POTIONS_ENABLED = autoPotionsConfig.getBoolean("AutoPotionsEnabled", false);
|
||||
AUTO_POTIONS_IN_OLYMPIAD = autoPotionsConfig.getBoolean("AutoPotionsInOlympiad", false);
|
||||
AUTO_POTION_MIN_LEVEL = autoPotionsConfig.getInt("AutoPotionMinimumLevel", 1);
|
||||
AUTO_CP_ENABLED = autoPotionsConfig.getBoolean("AutoCpEnabled", true);
|
||||
AUTO_HP_ENABLED = autoPotionsConfig.getBoolean("AutoHpEnabled", true);
|
||||
AUTO_MP_ENABLED = autoPotionsConfig.getBoolean("AutoMpEnabled", true);
|
||||
AUTO_CP_PERCENTAGE = autoPotionsConfig.getInt("AutoCpPercentage", 70);
|
||||
AUTO_HP_PERCENTAGE = autoPotionsConfig.getInt("AutoHpPercentage", 70);
|
||||
AUTO_MP_PERCENTAGE = autoPotionsConfig.getInt("AutoMpPercentage", 70);
|
||||
AUTO_CP_ITEM_IDS = new ArrayList<>();
|
||||
for (String s : autoPotionsConfig.getString("AutoCpItemIds", "0").split(","))
|
||||
{
|
||||
AUTO_CP_ITEM_IDS.add(Integer.parseInt(s));
|
||||
}
|
||||
AUTO_HP_ITEM_IDS = new ArrayList<>();
|
||||
for (String s : autoPotionsConfig.getString("AutoHpItemIds", "0").split(","))
|
||||
{
|
||||
AUTO_HP_ITEM_IDS.add(Integer.parseInt(s));
|
||||
}
|
||||
AUTO_MP_ITEM_IDS = new ArrayList<>();
|
||||
for (String s : autoPotionsConfig.getString("AutoMpItemIds", "0").split(","))
|
||||
{
|
||||
AUTO_MP_ITEM_IDS.add(Integer.parseInt(s));
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadCustomMailManagerConfig()
|
||||
{
|
||||
final PropertiesParser customMailManagerConfig = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
|
||||
@@ -3142,6 +3185,7 @@ public class Config
|
||||
// Custom
|
||||
loadCancelSkillRestoreBuffsConfig();
|
||||
loadChampionConfig();
|
||||
loadAutoPotionsConfig();
|
||||
loadCustomMailManagerConfig();
|
||||
loadMerchantZeroPriceConfig();
|
||||
loadWeddingConfig();
|
||||
|
@@ -21,6 +21,7 @@ import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.gameserver.handler.voicedcommandhandlers.AutoPotion;
|
||||
import org.l2jmobius.gameserver.handler.voicedcommandhandlers.BankingCmd;
|
||||
import org.l2jmobius.gameserver.handler.voicedcommandhandlers.CTFCmd;
|
||||
import org.l2jmobius.gameserver.handler.voicedcommandhandlers.DMCmd;
|
||||
@@ -91,6 +92,11 @@ public class VoicedCommandHandler
|
||||
registerVoicedCommandHandler(new ExperienceGain());
|
||||
}
|
||||
|
||||
if (Config.AUTO_POTIONS_ENABLED)
|
||||
{
|
||||
registerVoicedCommandHandler(new AutoPotion());
|
||||
}
|
||||
|
||||
LOGGER.info("VoicedCommandHandler: Loaded " + _datatable.size() + " handlers.");
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.handler.voicedcommandhandlers;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.gameserver.handler.IVoicedCommandHandler;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.taskmanager.AutoPotionTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius, Gigi
|
||||
*/
|
||||
public class AutoPotion implements IVoicedCommandHandler
|
||||
{
|
||||
private static final String[] VOICED_COMMANDS =
|
||||
{
|
||||
"apon",
|
||||
"apoff"
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean useVoicedCommand(String command, PlayerInstance activeChar, String target)
|
||||
{
|
||||
if (!Config.AUTO_POTIONS_ENABLED || (activeChar == null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (activeChar.getLevel() < Config.AUTO_POTION_MIN_LEVEL)
|
||||
{
|
||||
activeChar.sendMessage("You need to be at least " + Config.AUTO_POTION_MIN_LEVEL + " to use auto potions.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (command.equals("apon"))
|
||||
{
|
||||
AutoPotionTaskManager.getInstance().add(activeChar);
|
||||
activeChar.sendMessage("Auto potions is enabled.");
|
||||
return true;
|
||||
}
|
||||
else if (command.equals("apoff"))
|
||||
{
|
||||
AutoPotionTaskManager.getInstance().remove(activeChar);
|
||||
activeChar.sendMessage("Auto potions is disabled.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getVoicedCommandList()
|
||||
{
|
||||
return VOICED_COMMANDS;
|
||||
}
|
||||
}
|
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.handler.ItemHandler;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
|
||||
/**
|
||||
* @author Mobius, Gigi
|
||||
*/
|
||||
public class AutoPotionTaskManager
|
||||
{
|
||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||
private static boolean _working = false;
|
||||
|
||||
public AutoPotionTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
PLAYER: for (PlayerInstance player : PLAYERS)
|
||||
{
|
||||
if ((player == null) || player.isAlikeDead() || !player.isOnline() || player.isInOfflineMode() || (!Config.AUTO_POTIONS_IN_OLYMPIAD && player.isInOlympiadMode()))
|
||||
{
|
||||
remove(player);
|
||||
continue PLAYER;
|
||||
}
|
||||
|
||||
boolean success = false;
|
||||
if (Config.AUTO_HP_ENABLED)
|
||||
{
|
||||
final boolean restoreHP = ((player.getStatus().getCurrentHp() / player.getMaxHp()) * 100) < Config.AUTO_HP_PERCENTAGE;
|
||||
HP: for (int itemId : Config.AUTO_HP_ITEM_IDS)
|
||||
{
|
||||
final ItemInstance hpPotion = player.getInventory().getItemByItemId(itemId);
|
||||
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
||||
{
|
||||
success = true;
|
||||
if (restoreHP)
|
||||
{
|
||||
ItemHandler.getInstance().getItemHandler(hpPotion.getItemId()).useItem(player, hpPotion);
|
||||
player.sendMessage("Auto potion: Restored HP.");
|
||||
break HP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Config.AUTO_CP_ENABLED)
|
||||
{
|
||||
final boolean restoreCP = ((player.getStatus().getCurrentCp() / player.getMaxCp()) * 100) < Config.AUTO_CP_PERCENTAGE;
|
||||
CP: for (int itemId : Config.AUTO_CP_ITEM_IDS)
|
||||
{
|
||||
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
||||
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
||||
{
|
||||
success = true;
|
||||
if (restoreCP)
|
||||
{
|
||||
ItemHandler.getInstance().getItemHandler(cpPotion.getItemId()).useItem(player, cpPotion);
|
||||
player.sendMessage("Auto potion: Restored CP.");
|
||||
break CP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Config.AUTO_MP_ENABLED)
|
||||
{
|
||||
final boolean restoreMP = ((player.getStatus().getCurrentMp() / player.getMaxMp()) * 100) < Config.AUTO_MP_PERCENTAGE;
|
||||
MP: for (int itemId : Config.AUTO_MP_ITEM_IDS)
|
||||
{
|
||||
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
||||
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
||||
{
|
||||
success = true;
|
||||
if (restoreMP)
|
||||
{
|
||||
ItemHandler.getInstance().getItemHandler(mpPotion.getItemId()).useItem(player, mpPotion);
|
||||
player.sendMessage("Auto potion: Restored MP.");
|
||||
break MP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!success)
|
||||
{
|
||||
player.sendMessage("Auto potion: You are out of potions!");
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(PlayerInstance player)
|
||||
{
|
||||
if (!PLAYERS.contains(player))
|
||||
{
|
||||
PLAYERS.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(PlayerInstance player)
|
||||
{
|
||||
PLAYERS.remove(player);
|
||||
}
|
||||
|
||||
public static AutoPotionTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final AutoPotionTaskManager INSTANCE = new AutoPotionTaskManager();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user