Jump to content

L2JC-Developer

Members
  • Posts

    14
  • Credits

  • Joined

  • Last visited

  • Feedback

    0%

Posts posted by L2JC-Developer

  1. Spoiler

     

    AutoPotions to l2jsunrice

    
    package handlers.voicedcommandhandlers;
    
    import l2r.gameserver.handler.IItemHandler;
    import l2r.gameserver.handler.IVoicedCommandHandler;
    import l2r.gameserver.handler.ItemHandler;
    import l2r.gameserver.model.actor.instance.L2PcInstance;
    import l2r.gameserver.model.items.instance.L2ItemInstance;
    
    import java.util.HashMap;
    
    /**
     * @author root
     * @date: 20/01/2021 at 23:15
     * Description : autocp / automp / autohp item use.
     */
    public class AutoPotion implements IVoicedCommandHandler {
    
        //*******Config Section*****************/
        //    *********************** Potion ItemID
        private static final int ID_HEAL_CP = 5592;
        private static final int ID_HEAL_MP = 728;
        private static final int ID_HEAL_HP = 1539;
        //*********************** USE FULL
        //Enable/Disable voicecoomand
        private static final boolean ACP_ON = true;
        //    Min lvl for use ACP
        private static final int ACP_MIN_LVL = 0;
        private static final int ACP_HP_LVL = 70;
        private static final int ACP_CP_LVL = 70;
        private static final int ACP_MP_LVL = 70;
        private static final int ACP_MILI_SECONDS_FOR_LOOP = 1000;
        //Only for premium user?
        private static final boolean ACP_PREMIUM = false;
        // Automatic regen : Default ACP/MP/HP
        private static final boolean ACP_CP = true;
        private static final boolean ACP_MP = true;
        private static final boolean ACP_HP = true;
        private static final HashMap<String, Thread> userAcpMap = new HashMap<String, Thread>();
    
        private static String[] _voicedCommands = {
                        "acpon",
                        "acpoff"
        };
    
        @Override
        public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params) {
            if (activeChar == null) {
                return false;
            }
    
            if (command.equals("acpon")) {
                if (!ACP_ON) {
                    activeChar.sendMessage("The function is disabled on the server!");
                    return false;
                } else {
                    if (userAcpMap.containsKey(activeChar.toString())) {
                        activeChar.sendMessage("Already included!");
                    } else {
                        activeChar.sendMessage("Acp enabled!");
                        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("Was not included");
                } else {
                    userAcpMap.remove(activeChar.toString()) //here we get thread and remove it from map
                            .interrupt(); //and interrupt it
                    activeChar.sendMessage("Disabled");
                }
            }
            return false;
        }
    
        @Override
        public String[] getVoicedCommandList() {
            return _voicedCommands;
        }
    
        private class AcpHealer implements Runnable {
    
            L2PcInstance activeChar;
    
            public AcpHealer(L2PcInstance activeChar) {
                this.activeChar = activeChar;
            }
    
            @Override
            public void run() {
                try {
                    while (true) {
    //                  Checking the level
                        if (activeChar.getLevel() >= ACP_MIN_LVL) {
    //                        We check if we need a premium
                            if (!(activeChar.isPremium() && ACP_PREMIUM)) {
    //                            Checking if we have at least one can of something
                                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) {
    //                               Checking our health
                                    if ((activeChar.getStatus().getCurrentHp() / activeChar.getMaxHp()) * 100 < ACP_HP_LVL && ACP_HP) {
                                        IItemHandler handlerHP = ItemHandler.getInstance().getHandler(hpBottle.getEtcItem());
                                        if (handlerHP != null) {
                                            handlerHP.useItem(activeChar, hpBottle, true);
                                            activeChar.sendMessage("ACP: Restored HP");
                                        }
                                    }
    //                               Checking our CP level
                                    if (cpBottle != null && cpBottle.getCount() > 0) {
                                        if ((activeChar.getStatus().getCurrentCp() / activeChar.getMaxCp()) * 100 < ACP_CP_LVL && ACP_CP) {
                                            IItemHandler handlerCP = ItemHandler.getInstance().getHandler(cpBottle.getEtcItem());
                                            if (handlerCP != null) {
                                                handlerCP.useItem(activeChar, cpBottle, true);
                                                activeChar.sendMessage("ACP: Restored CP");
                                            }
                                        }
                                    }
    //                              Checking our MP level
                                    if (mpBottle != null && mpBottle.getCount() > 0) {
                                        if ((activeChar.getStatus().getCurrentMp() / activeChar.getMaxMp()) * 100 < ACP_MP_LVL && ACP_MP) {
                                            IItemHandler handlerMP = ItemHandler.getInstance().getHandler(mpBottle.getEtcItem());
                                            if (handlerMP != null) {
                                                handlerMP.useItem(activeChar, mpBottle, true);
                                                activeChar.sendMessage("ACP: Restored MP");
                                            }
                                        }
                                    }
                                } else {
                                    activeChar.sendMessage("[ACP] Incorrect item count");
                                    return;
                                }
                            } else {
                                activeChar.sendMessage("Available only to premium characters!");
                                return;
                            }
                        } else {
                            activeChar.sendMessage("Available only " + ACP_MIN_LVL + " level!");
                            return;
                        }
                        Thread.sleep(ACP_MILI_SECONDS_FOR_LOOP);
                    }
                } catch (InterruptedException e) {
                    //nothing
                } catch (Exception e) {
                    _log.warn(e.getMessage(), e);
                    Thread.currentThread().interrupt();
                } finally {
                    userAcpMap.remove(activeChar.toString());
                }
            }
        }
    }


     

     

     

    • Thanks 1
  2. 8 minutes ago, Nightw0lf said:

    guys cmon trust is not builded after 2 posts... you need clients not friends.

    I can send you links to my profiles on the forums of the RU segment.I just haven't worked in the EU segment before. What is the problem that I created an account and a theme with my services?

  3. WTS instance zone cooldown service.  You can add / remove some zones.

    The service resets the rollback to the instance zone and allows the player to go to it again.

    Source code: owerworld

    for more info pm in skype or telegramm

    I can adapt to your source code for money:)

     

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock