public class Acp implements IVoicedCommandHandler {
private static String[] commands = {"acpon", "acpoff"};
// *********************** ИД Банок
private static int ID_HEAL_CP = 5592;
private static int ID_HEAL_MP = 6036;
private static int ID_HEAL_HP = 1539;
// *********************** USE FULL
// Включить / Выключить
private static boolean ACP_ON = true;
// Минимальный уровень, с которого можно использовать ACP
private static int ACP_MIN_LVL = 0;
// Указываеться в % уровень, с которого начинаем регенить
private static int ACP_HP_LVL = 70;
private static int ACP_CP_LVL = 70;
private static int ACP_MP_LVL = 70;
private static int ACP_MILI_SECONDS_FOR_LOOP = 1000;
// Только для премиумов?
private static boolean ACP_PREMIUM = false;
// Что именно автоматически регеним
private static boolean ACP_CP = true;
private static boolean ACP_MP = true;
private static boolean ACP_HP = true;
private static HashMap userAcpMap = new HashMap();
// private volatile boolean acpUserOn = false;
public static void main(String[] args) {
VoicedCommandHandler.getInstance().registerVoicedC ommandHandler(new Acp());
}
public static Acp getInstance() {
return null;
}
@Override
public String getDescription(String command) {
if (command.equals("acpon"))
return "Включить автоматическое восстановление HP/CP/MP";
else if (command.equals("acpoff"))
return "Выключить автоматическое восстановление HP/CP/MP";
return null;
}
@Override
public String[] getVoicedCommandList() {
return commands;
}
@Override
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target) {
// Есть ли такой вообще в мире
if (activeChar == null) {
return false;
}
if (command.equals("acpon")) {
if (!ACP_ON) {
activeChar.sendMessage("Функция отключена на сервере!");
return false;
} else {
if (userAcpMap.containsKey(activeChar.toString())) {
activeChar.sendMessage("Уже включено!");
} else {
activeChar.sendMessage("Acp включен!");
Thread t = new Thread(new AcpHealer(activeChar));
userAcpMap.put(activeChar.toString(), t);
t.start();
return true;
}
}
} else if (command.equals("acpoff")) {
if (!userAcpMap.containsKey(activeChar.toString())) {
activeChar.sendMessage("Не было включено");
} else {
userAcpMap.remove(activeChar.toString()) //here we get thread and remove it from map
.interrupt(); //and interrupt it
activeChar.sendMessage("Отключено");
}
}
return false;
}
private class AcpHealer implements Runnable {
L2PcInstance activeChar;
public AcpHealer(L2PcInstance activeChar) {
this.activeChar = activeChar;
}
@Override
public void run() {
try {
while (true) {
// Проверяем уровень
if (activeChar.getLevel() >= ACP_MIN_LVL) {
// Проверяем нужен ли нам премиум
if (!(activeChar.getPremiumService() > 1 && ACP_PREMIUM)) {
// Проверяем, есть ли у нас хотя бы одна банка чего-то
L2ItemInstance cpBottle = activeChar.getInventory().getItemByItemId(ID_HEAL_ CP);
L2ItemInstance hpBottle = activeChar.getInventory().getItemByItemId(ID_HEAL_ HP);
L2ItemInstance mpBottle = activeChar.getInventory().getItemByItemId(ID_HEAL_ MP);
if (hpBottle != null && hpBottle.getCount() > 0) {
// Проверяем наш уровень здоровья
if ((activeChar.getStatus().getCurrentHp() / activeChar.getMaxHp()) * 100 0) {
if ((activeChar.getStatus().getCurrentCp() / activeChar.getMaxCp()) * 100 0) {
if ((activeChar.getStatus().getCurrentMp() / activeChar.getMaxMp()) * 100