Custom auto potion system.
Contributed by gigilo1968.
This commit is contained in:
34
L2J_Mobius_2.5_Underground/dist/game/config/Custom/AutoPotions.ini
vendored
Normal file
34
L2J_Mobius_2.5_Underground/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
|
||||
|
||||
# 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
|
@@ -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
|
||||
|
106
L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
vendored
Normal file
106
L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPotion.java
vendored
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<Integer, Future<?>> 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;
|
||||
}
|
||||
}
|
@@ -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<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_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);
|
||||
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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!");
|
||||
}
|
||||
}
|
||||
}
|
@@ -91,6 +91,7 @@ Events:
|
||||
|
||||
Customs:
|
||||
-Allowed player races
|
||||
-Auto potions command
|
||||
-Banking
|
||||
-Champion monsters
|
||||
-Classmaster
|
||||
|
Reference in New Issue
Block a user