Custom auto potion system.
Contributed by gigilo1968.
This commit is contained in:
@@ -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<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;
|
||||
@@ -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);
|
||||
|
||||
|
@@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user