L2JMobius

Interlude Auto Potion

dramaa · 7 · 1961

Online dramaa

  • Baron
  • *****
    • Posts: 268
    • L2Equinox

dist/game/data/scripts/handlers/voicedcommandhandlers/AutoPot.java (new class.)(update https://ibb.co/yFBDSF1G)
Code: [Select]
package handlers.voicedcommandhandlers;

import java.util.ArrayList;
import java.util.List;

import org.l2jmobius.Config;
import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.xml.ItemData;
import org.l2jmobius.gameserver.handler.IVoicedCommandHandler;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.holders.SkillHolder;
import org.l2jmobius.gameserver.model.item.ItemTemplate;
import org.l2jmobius.gameserver.model.item.instance.Item;
import org.l2jmobius.gameserver.model.skill.AbnormalType;
import org.l2jmobius.gameserver.model.skill.Skill;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.ExShowScreenMessage;
import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
import org.l2jmobius.gameserver.taskmanager.AutoPotTaskManager;
import org.l2jmobius.gameserver.taskmanager.AutoUsePotManager;
import org.l2jmobius.gameserver.util.MathUtil;
import org.l2jmobius.gameserver.util.Util;

/**
 * [member=6902]oRiGiNaL[/member] Code Mobius
 * @Reworked Code Dramaa
 */
public class AutoPot implements IVoicedCommandHandler
{
private static final int PAGE_LIMIT = 7;
private static final String[] VOICED_COMMANDS =
{
"pot",
"playpotionh",
"playpotionm",
"playpotionc"
};

[member=79]override[/member]
public boolean useVoicedCommand(String command, Player player, String params)
{
if (!Config.ENABLE_AUTO_PPOT || (player == null))
{
return false;
}

if (Config.AUTO_POT_PREMIUM && !player.hasPremiumStatus())
{
player.sendPacket(new ExShowScreenMessage("This command is only available to premium players.", 5000));
player.sendMessage("This command is only available to premium players.");
player.sendPacket(ActionFailed.STATIC_PACKET);
return false;
}

switch (command)
{
case "pot":
{
if (params != null)
{
final String[] paramArray = params.toLowerCase().split(" ");
COMMAND: switch (paramArray[0])
{

case "percent":
{
if ((paramArray.length > 1) && Util.isDigit(paramArray[1]))
{
player.getAutoPlaySettings().setAutoHpPercent(Math.max(0, Math.min(100, Integer.parseInt(paramArray[1]))));
}
break COMMAND;
}
case "percentm":
{
if ((paramArray.length > 1) && Util.isDigit(paramArray[1]))
{
player.getAutoPlaySettings().setAutoMpPercent(Math.max(0, Math.min(100, Integer.parseInt(paramArray[1]))));
}
break COMMAND;
}
case "percentc":
{
if ((paramArray.length > 1) && Util.isDigit(paramArray[1]))
{
player.getAutoPlaySettings().setAutoCpPercent(Math.max(0, Math.min(100, Integer.parseInt(paramArray[1]))));
}
break COMMAND;
}
case "start":
{
AutoPotTaskManager.getInstance().startAutoPot(player);
AutoUsePotManager.getInstance().startAutoPotTask(player);
break COMMAND;
}
case "stop":
{
AutoPotTaskManager.getInstance().stopAutoPot(player);
AutoUsePotManager.getInstance().stopAutoPotTask(player);
break COMMAND;
}
}
}

final NpcHtmlMessage html = new NpcHtmlMessage();
String content = HtmCache.getInstance().getHtm(player, "data/html/mods/AutoPot/Main.htm");

content = content.replace("%potion_button%", Config.ENABLE_AUTO_POT ? "<br><table><tr><td height=31><center><button action=\"bypass voice .playpotionh\" value=\"Healing Potion\" width=95 height=21 back=\"bigbutton_over\" fore=\"bigbutton\"></center></td></tr></table>" + "<table width=295><tr><td height=31><center><table width=180><tr>" + "<td width=32 valign=\"middle\"><img src=\"icon.etc_potion_scarlet_i00\" width=32 height=32></td>" + "<td width=40><font color=\"CDB67F\">%percent%%</font></td>" + "<td><edit var=\"percentbox_hp\" width=30 height=13></td>" + "<td><button value=\"Apply\" action=\"bypass voice .pot percent $percentbox_hp\" width=65 height=21 back=\"L2UI_ch3.smallbutton2_over\" fore=\"L2UI_ch3.smallbutton2\"></td>" + "</tr></table></center></td></tr></table>" : "");

content = content.replace("%potion_buttonm%", Config.ENABLE_AUTO_POTM ? "<br><table><tr><td height=31><center><button action=\"bypass voice .playpotionm\" value=\"Mana Potion\" width=95 height=21 back=\"bigbutton_over\" fore=\"bigbutton\"></center></td></tr></table>" + "<table width=295><tr><td height=31><center><table width=180><tr>" + "<td width=32 valign=\"middle\"><img src=\"icon.etc_reagent_blue_i00\" width=32 height=32></td>" + "<td width=40><font color=\"CDB67F\">%percentm%%</font></td>" + "<td><edit var=\"percentbox_mp\" width=30 height=13></td>" + "<td><button value=\"Apply\" action=\"bypass voice .pot percentm $percentbox_mp\" width=65 height=21 back=\"L2UI_ch3.smallbutton2_over\" fore=\"L2UI_ch3.smallbutton2\"></td>" + "</tr></table></center></td></tr></table>" : "");

content = content.replace("%potion_buttonc%", Config.ENABLE_AUTO_POTC ? "<br><table><tr><td height=31><center><button action=\"bypass voice .playpotionc\" value=\"CP Potion\" width=95 height=21 back=\"bigbutton_over\" fore=\"bigbutton\"></center></td></tr></table>" + "<table width=295><tr><td height=31><center><table width=180><tr>" + "<td width=32 valign=\"middle\"><img src=\"icon.etc_cp_potion_i00\" width=32 height=32></td>" + "<td width=40><font color=\"CDB67F\">%percentc%%</font></td>" + "<td><edit var=\"percentbox_cp\" width=30 height=13></td>" + "<td><button value=\"Apply\" action=\"bypass voice .pot percentc $percentbox_cp\" width=65 height=21 back=\"L2UI_ch3.smallbutton2_over\" fore=\"L2UI_ch3.smallbutton2\"></td>" + "</tr></table></center></td></tr></table>" : "");

content = content.replace("%percent%", String.valueOf(player.getAutoPlaySettings().getAutoHpPercent()));
content = content.replace("%percentm%", String.valueOf(player.getAutoPlaySettings().getAutoMpPercent()));
content = content.replace("%percentc%", String.valueOf(player.getAutoPlaySettings().getAutoCpPercent()));
if (player.isAutoPot())
{
content = content.replace("%status_buttn%", "<table width=295><tr><td height=31><center><button action=\"bypass voice .pot stop\" value=\"Stop\" width=95 height=21 back=\"bigbutton_over\" fore=\"bigbutton\"></center></td></tr></table>");
}
else
{
content = content.replace("%status_buttn%", "<table width=295><tr><td height=31><center><button action=\"bypass voice .pot start\" value=\"Start\" width=95 height=21 back=\"bigbutton_over\" fore=\"bigbutton\"></center></td></tr></table>");
}

html.setHtml(content);
player.sendPacket(html);
break;
}

case "playpotionh":
{
final NpcHtmlMessage html = new NpcHtmlMessage();
final String content = HtmCache.getInstance().getHtm(player, "data/html/mods/AutoPot/Potion.htm");

// Generate the item list. Filter our some items.
List<ItemTemplate> items = new ArrayList<>();
POTION_SEARCH: for (Item item : player.getInventory().getItems())
{
final ItemTemplate template = item.getTemplate();
if (item.isEtcItem() && template.hasSkills() && !Config.DISABLED_AUTO_ITEMS.contains(item.getId()))
{
for (SkillHolder holder : template.getSkills())
{
final Skill skill = holder.getSkill();
if ((skill != null) && (skill.getAbnormalType() == AbnormalType.HP_RECOVER) && !items.contains(template))
{
items.add(template);
continue POTION_SEARCH;
}
}
}
}

// Manage item activation.
final String[] paramArray = params == null ? new String[0] : params.split(" ");
if (paramArray.length > 1)
{
final int itemId = Integer.parseInt(paramArray[1]);
if (Config.ENABLE_AUTO_POT && items.contains(ItemData.getInstance().getTemplate(itemId)))
{
if (player.getAutoUseSettings().getAutoHPItem() == itemId)
{
player.getAutoUseSettings().setAutoHPItem(0);
}
else
{
player.getAutoUseSettings().setAutoHPItem(itemId);
}
}
}

// Calculate page number.
final int max = MathUtil.countPagesNumber(items.size(), PAGE_LIMIT);
int page = params == null ? 1 : Integer.parseInt(paramArray[0]);
if (page > max)
{
page = max;
}

// Cut items list up to page number.
final StringBuilder sb = new StringBuilder();
items = items.subList(Math.max(0, (page - 1) * PAGE_LIMIT), Math.min(page * PAGE_LIMIT, items.size()));
if (items.isEmpty())
{
sb.append("<center><br>No potions found.<br></center>");
}
else
{
// Generate item table.
int row = 0;
for (ItemTemplate template : items)
{
sb.append(((row % 2) == 0 ? "<table width=\"295\" bgcolor=\"000000\"><tr>" : "<table width=\"295\"><tr>"));
if (player.getAutoUseSettings().getAutoHPItem() == template.getId())
{
sb.append("<td height=40 width=40><img src=\"" + template.getIcon() + "\" width=32 height=32></td><td width=190>" + template.getName() + "</td><td><button value=\" \" action=\"bypass voice .playpotionh " + page + " " + template.getId() + "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomout2\" fore=\"L2UI_CH3.mapbutton_zoomout1\"></td>");
}
else
{
sb.append("<td height=40 width=40><img src=\"" + template.getIcon() + "\" width=32 height=32></td><td width=190><font color=\"B09878\">" + template.getName() + "</font></td><td><button value=\" \" action=\"bypass voice .playpotionh " + page + " " + template.getId() + "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomin2\" fore=\"L2UI_CH3.mapbutton_zoomin1\"></td>");
}
sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=295 height=1>");
}

// Generate page footer.
sb.append("<br><img src=\"L2UI.SquareGray\" width=295 height=1><table width=\"100%\" bgcolor=000000><tr>");
if (page > 1)
{
sb.append("<td align=left width=70><a action=\"bypass voice .playpotionh " + (page - 1) + "\"><font color=\"CDB67F\">Previous</font></a></td>");
}
else
{
sb.append("<td align=left width=70><font color=\"B09878\">Previous</font></td>");
}
sb.append("<td align=center width=100>Page " + page + " of " + max + "</td>");
if (page < max)
{
sb.append("<td align=right width=70><a action=\"bypass voice .playpotionh " + (page + 1) + "\"><font color=\"CDB67F\">Next</font></a></td>");
}
else
{
sb.append("<td align=right width=70><font color=\"B09878\">Next</font></td>");
}
sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=295 height=1>");
}

// Replace and send the html.
html.setHtml(content.replace("%items%", sb.toString()));
player.sendPacket(html);
break;
}
case "playpotionm":
{
final NpcHtmlMessage html = new NpcHtmlMessage();
final String content = HtmCache.getInstance().getHtm(player, "data/html/mods/AutoPot/MPotion.htm");

// Generate the item list. Filter our some items.
List<ItemTemplate> items = new ArrayList<>();
POTION_SEARCH: for (Item item : player.getInventory().getItems())
{
final ItemTemplate template = item.getTemplate();
if (item.isEtcItem() && template.hasSkills() && !Config.DISABLED_AUTO_ITEMS.contains(item.getId()))
{
for (SkillHolder holder : template.getSkills())
{
final Skill skill = holder.getSkill();
if ((skill != null) && (skill.getAbnormalType() == AbnormalType.MP_RECOVER) && !items.contains(template))
{
items.add(template);
continue POTION_SEARCH;
}
}
}
}

// Manage item activation.
final String[] paramArray = params == null ? new String[0] : params.split(" ");
if (paramArray.length > 1)
{
final int itemId = Integer.parseInt(paramArray[1]);
if (Config.ENABLE_AUTO_POTM && items.contains(ItemData.getInstance().getTemplate(itemId)))
{
if (player.getAutoUseSettings().getAutoMPItem() == itemId)
{
player.getAutoUseSettings().setAutoMPItem(0);
}
else
{
player.getAutoUseSettings().setAutoMPItem(itemId);
}
}
}

// Calculate page number.
final int max = MathUtil.countPagesNumber(items.size(), PAGE_LIMIT);
int page = params == null ? 1 : Integer.parseInt(paramArray[0]);
if (page > max)
{
page = max;
}

// Cut items list up to page number.
final StringBuilder sb = new StringBuilder();
items = items.subList(Math.max(0, (page - 1) * PAGE_LIMIT), Math.min(page * PAGE_LIMIT, items.size()));
if (items.isEmpty())
{
sb.append("<center><br>No potions found.<br></center>");
}
else
{
// Generate item table.
int row = 0;
for (ItemTemplate template : items)
{
sb.append(((row % 2) == 0 ? "<table width=\"295\" bgcolor=\"000000\"><tr>" : "<table width=\"295\"><tr>"));
if (player.getAutoUseSettings().getAutoMPItem() == template.getId())
{
sb.append("<td height=40 width=40><img src=\"" + template.getIcon() + "\" width=32 height=32></td><td width=190>" + template.getName() + "</td><td><button value=\" \" action=\"bypass voice .playpotionm " + page + " " + template.getId() + "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomout2\" fore=\"L2UI_CH3.mapbutton_zoomout1\"></td>");
}
else
{
sb.append("<td height=40 width=40><img src=\"" + template.getIcon() + "\" width=32 height=32></td><td width=190><font color=\"B09878\">" + template.getName() + "</font></td><td><button value=\" \" action=\"bypass voice .playpotionm " + page + " " + template.getId() + "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomin2\" fore=\"L2UI_CH3.mapbutton_zoomin1\"></td>");
}
sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=295 height=1>");
}

// Generate page footer.
sb.append("<br><img src=\"L2UI.SquareGray\" width=295 height=1><table width=\"100%\" bgcolor=000000><tr>");
if (page > 1)
{
sb.append("<td align=left width=70><a action=\"bypass voice .playpotionm " + (page - 1) + "\"><font color=\"CDB67F\">Previous</font></a></td>");
}
else
{
sb.append("<td align=left width=70><font color=\"B09878\">Previous</font></td>");
}
sb.append("<td align=center width=100>Page " + page + " of " + max + "</td>");
if (page < max)
{
sb.append("<td align=right width=70><a action=\"bypass voice .playpotionm " + (page + 1) + "\"><font color=\"CDB67F\">Next</font></a></td>");
}
else
{
sb.append("<td align=right width=70><font color=\"B09878\">Next</font></td>");
}
sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=295 height=1>");
}

// Replace and send the html.
html.setHtml(content.replace("%items%", sb.toString()));
player.sendPacket(html);
break;
}
case "playpotionc":
{
final NpcHtmlMessage html = new NpcHtmlMessage();
final String content = HtmCache.getInstance().getHtm(player, "data/html/mods/AutoPot/CPotion.htm");

// Generate the item list. Filter our some items.
List<ItemTemplate> items = new ArrayList<>();
POTION_SEARCH: for (Item item : player.getInventory().getItems())
{
final ItemTemplate template = item.getTemplate();
if (item.isEtcItem() && template.hasSkills() && !Config.DISABLED_AUTO_ITEMS.contains(item.getId()))
{
for (SkillHolder holder : template.getSkills())
{
final Skill skill = holder.getSkill();
if ((skill != null) && (skill.getAbnormalType() == AbnormalType.CP_RECOVER) && !items.contains(template))
{
items.add(template);
continue POTION_SEARCH;
}
}
}
}

// Manage item activation.
final String[] paramArray = params == null ? new String[0] : params.split(" ");
if (paramArray.length > 1)
{
final int itemId = Integer.parseInt(paramArray[1]);
if (Config.ENABLE_AUTO_POTC && items.contains(ItemData.getInstance().getTemplate(itemId)))
{
if (player.getAutoUseSettings().getAutoCPItem() == itemId)
{
player.getAutoUseSettings().setAutoCPItem(0);
}
else
{
player.getAutoUseSettings().setAutoCPItem(itemId);
}
}
}

// Calculate page number.
final int max = MathUtil.countPagesNumber(items.size(), PAGE_LIMIT);
int page = params == null ? 1 : Integer.parseInt(paramArray[0]);
if (page > max)
{
page = max;
}

// Cut items list up to page number.
final StringBuilder sb = new StringBuilder();
items = items.subList(Math.max(0, (page - 1) * PAGE_LIMIT), Math.min(page * PAGE_LIMIT, items.size()));
if (items.isEmpty())
{
sb.append("<center><br>No potions found.<br></center>");
}
else
{
// Generate item table.
int row = 0;
for (ItemTemplate template : items)
{
sb.append(((row % 2) == 0 ? "<table width=\"295\" bgcolor=\"000000\"><tr>" : "<table width=\"295\"><tr>"));
if (player.getAutoUseSettings().getAutoCPItem() == template.getId())
{
sb.append("<td height=40 width=40><img src=\"" + template.getIcon() + "\" width=32 height=32></td><td width=190>" + template.getName() + "</td><td><button value=\" \" action=\"bypass voice .playpotionc " + page + " " + template.getId() + "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomout2\" fore=\"L2UI_CH3.mapbutton_zoomout1\"></td>");
}
else
{
sb.append("<td height=40 width=40><img src=\"" + template.getIcon() + "\" width=32 height=32></td><td width=190><font color=\"B09878\">" + template.getName() + "</font></td><td><button value=\" \" action=\"bypass voice .playpotionc " + page + " " + template.getId() + "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomin2\" fore=\"L2UI_CH3.mapbutton_zoomin1\"></td>");
}
sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=295 height=1>");
}

// Generate page footer.
sb.append("<br><img src=\"L2UI.SquareGray\" width=295 height=1><table width=\"100%\" bgcolor=000000><tr>");
if (page > 1)
{
sb.append("<td align=left width=70><a action=\"bypass voice .playpotionc " + (page - 1) + "\"><font color=\"CDB67F\">Previous</font></a></td>");
}
else
{
sb.append("<td align=left width=70><font color=\"B09878\">Previous</font></td>");
}
sb.append("<td align=center width=100>Page " + page + " of " + max + "</td>");
if (page < max)
{
sb.append("<td align=right width=70><a action=\"bypass voice .playpotionc " + (page + 1) + "\"><font color=\"CDB67F\">Next</font></a></td>");
}
else
{
sb.append("<td align=right width=70><font color=\"B09878\">Next</font></td>");
}
sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=295 height=1>");
}

// Replace and send the html.
html.setHtml(content.replace("%items%", sb.toString()));
player.sendPacket(html);
break;
}
}

return true;

}

[member=79]override[/member]
public String[] getVoicedCommandList()
{
return VOICED_COMMANDS;
}
}


Online dramaa

  • Baron
  • *****
    • Posts: 268
    • L2Equinox
gameserver/taskmanager/AutoPotTaskManager.java
Code: [Select]
/*
 * 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.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.l2jmobius.Config;
import org.l2jmobius.commons.threads.ThreadPool;
import org.l2jmobius.gameserver.model.actor.Player;

/**
 * [member=6902]oRiGiNaL[/member] Code Mobius
 * @Reworked Code Dramaa
 */
public class AutoPotTaskManager
{
private static final Set<Set<Player>> POOLS = ConcurrentHashMap.newKeySet();
private static final Map<Player, Integer> IDLE_COUNT = new ConcurrentHashMap<>();
private static final int POOL_SIZE = 300;
private static final int TASK_DELAY = 300;

protected AutoPotTaskManager()
{
}

private class AutoPot implements Runnable
{
private final Set<Player> _players;

public AutoPot(Set<Player> players)
{
_players = players;
}

[member=79]override[/member]
public void run()
{
if (_players.isEmpty())
{
return;
}

PLAY: for (Player player : _players)
{
if (!player.isOnline() || (player.isInOfflineMode() && !player.isOfflinePlay()) || !Config.ENABLE_AUTO_PPOT)
{
stopAutoPot(player);
continue PLAY;
}

if (player.isSitting() || player.isCastingNow() || (player.getQueuedSkill() != null))
{
continue PLAY;
}

}
}

}

public synchronized void startAutoPot(Player player)
{
for (Set<Player> pool : POOLS)
{
if (pool.contains(player))
{
return;
}
}

player.setAutoPot(true);

for (Set<Player> pool : POOLS)
{
if (pool.size() < POOL_SIZE)
{
player.onActionRequest();
pool.add(player);
return;
}
}

final Set<Player> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
player.onActionRequest();
pool.add(player);
ThreadPool.schedulePriorityTaskAtFixedRate(new AutoPot(pool), TASK_DELAY, TASK_DELAY);
POOLS.add(pool);
}

public void stopAutoPot(Player player)
{
for (Set<Player> pool : POOLS)
{
if (pool.remove(player))
{
player.setAutoPot(false);

// Pets must follow their owner.
if (player.hasServitor() || player.hasPet())
{
player.getSummon().followOwner();
}
IDLE_COUNT.remove(player);
return;
}
}
}

public static AutoPotTaskManager getInstance()
{
return SingletonHolder.INSTANCE;
}

private static class SingletonHolder
{
protected static final AutoPotTaskManager INSTANCE = new AutoPotTaskManager();
}
}
gameserver/model/holders/AutoPlaySettingsHolder.java
Code: [Select]
/*
 * 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.model.holders;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Mobius
 */
public class AutoPlaySettingsHolder
{
private final AtomicInteger _options = new AtomicInteger();
private final AtomicBoolean _pickup = new AtomicBoolean(true);
private final AtomicInteger _nextTargetMode = new AtomicInteger(1);
private final AtomicBoolean _shortRange = new AtomicBoolean();
private final AtomicBoolean _respectfulHunting = new AtomicBoolean(true);
+ private final AtomicInteger _autoHpPercent = new AtomicInteger(50);
+ private final AtomicInteger _autoCpPercent = new AtomicInteger(50);
+ private final AtomicInteger _autoMpPercent = new AtomicInteger(50);
private final AtomicInteger _autoPotionPercent = new AtomicInteger(50);

public AutoPlaySettingsHolder()
{
}

public int getOptions()
{
return _options.get();
}

public void setOptions(int options)
{
_options.set(options);
}

public boolean doPickup()
{
return _pickup.get();
}

public void setPickup(boolean value)
{
_pickup.set(value);
}

public int getNextTargetMode()
{
return _nextTargetMode.get();
}

public void setNextTargetMode(int nextTargetMode)
{
_nextTargetMode.set(nextTargetMode);
}

public boolean isShortRange()
{
return _shortRange.get();
}

public void setShortRange(boolean value)
{
_shortRange.set(value);
}

public boolean isRespectfulHunting()
{
return _respectfulHunting.get();
}

public void setRespectfulHunting(boolean value)
{
_respectfulHunting.set(value);
}

public int getAutoPotionPercent()
{
return _autoPotionPercent.get();
}

+ public int getAutoHpPercent()
+ {
+ return _autoHpPercent.get();
+ }
+
+ public int getAutoMpPercent()
+ {
+ return _autoMpPercent.get();
+ }
+
+ public int getAutoCpPercent()
+ {
+ return _autoCpPercent.get();
+ }
+
public void setAutoPotionPercent(int value)
{
_autoPotionPercent.set(value);
}

+ public void setAutoHpPercent(int value)
+ {
+ _autoHpPercent.set(value);
+ }
+
+ public void setAutoMpPercent(int value)
+ {
+ _autoMpPercent.set(value);
+ }
+
+ public void setAutoCpPercent(int value)
+ {
+ _autoCpPercent.set(value);
+ }
}


Online dramaa

  • Baron
  • *****
    • Posts: 268
    • L2Equinox
gameserver/model/holders/AutoUseSettingsHolder.java
Code: [Select]
/*
 * 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.model.holders;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Mobius
 */
public class AutoUseSettingsHolder
{
private final Collection<Integer> _autoSupplyItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoActions = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoBuffs = ConcurrentHashMap.newKeySet();
private final List<Integer> _autoSkills = new CopyOnWriteArrayList<>();
+ private final AtomicInteger _autoHPItem = new AtomicInteger();
+ private final AtomicInteger _autoCPItem = new AtomicInteger();
+ private final AtomicInteger _autoMPItem = new AtomicInteger();
private final AtomicInteger _autoPotionItem = new AtomicInteger();
private int _skillIndex = 0;

public AutoUseSettingsHolder()
{
}

public Collection<Integer> getAutoSupplyItems()
{
return _autoSupplyItems;
}

public Collection<Integer> getAutoActions()
{
return _autoActions;
}

public Collection<Integer> getAutoBuffs()
{
return _autoBuffs;
}

public List<Integer> getAutoSkills()
{
return _autoSkills;
}

public int getAutoPotionItem()
{
return _autoPotionItem.get();
}

+ public int getAutoHPItem()
+ {
+ return _autoHPItem.get();
+ }
+
+ public int getAutoCPItem()
+ {
+ return _autoCPItem.get();
+ }
+
+ public int getAutoMPItem()
+ {
+ return _autoMPItem.get();
+ }
+
public void setAutoPotionItem(int itemId)
{
_autoPotionItem.set(itemId);
}

+ public void setAutoHPItem(int itemId)
+ {
+ _autoHPItem.set(itemId);
+ }
+
+ public void setAutoMPItem(int itemId)
+ {
+ _autoMPItem.set(itemId);
+ }
+
+ public void setAutoCPItem(int itemId)
+ {
+ _autoCPItem.set(itemId);
+ }
+
public boolean isAutoSkill(int skillId)
{
return _autoSkills.contains(skillId) || _autoBuffs.contains(skillId);
}

public Integer getNextSkillId()
{
if (_skillIndex >= _autoSkills.size())
{
_skillIndex = 0;
}

Integer skillId = Integer.MIN_VALUE;
try
{
skillId = _autoSkills.get(_skillIndex);
}
catch (Exception e)
{
resetSkillOrder();
}

return skillId;
}

public void incrementSkillOrder()
{
_skillIndex++;
}

public void resetSkillOrder()
{
_skillIndex = 0;
}

public boolean isEmpty()
{
return _autoSupplyItems.isEmpty() && (_autoHPItem.get() == 0) && (_autoPotionItem.get() == 0) && (_autoCPItem.get() == 0) && (_autoMPItem.get() == 0) && _autoSkills.isEmpty() && _autoBuffs.isEmpty() && _autoActions.isEmpty();
}
}

gameserver/model/actor/Player.java

Code: [Select]
private final AutoPlaySettingsHolder _autoPlaySettings = new AutoPlaySettingsHolder();
private final AutoUseSettingsHolder _autoUseSettings = new AutoUseSettingsHolder();
private final AtomicBoolean _autoPlaying = new AtomicBoolean();
      + private final AtomicBoolean _autoPot = new AtomicBoolean();
-----------------------
public void setAutoPlaying(boolean value)
{
_autoPlaying.set(value);
}

+public void setAutoPot(boolean value)
+{
+ _autoPot.set(value);
+}

+public boolean isAutoPot()
+{
+ return _autoPot.get();
+}

public boolean isAutoPlaying()
{
return _autoPlaying.get();
}


Online dramaa

  • Baron
  • *****
    • Posts: 268
    • L2Equinox
gameserver/taskmanager/AutoUsePotManager.java (new class)
Code: [Select]
package org.l2jmobius.gameserver.taskmanager;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.l2jmobius.Config;
import org.l2jmobius.commons.threads.ThreadPool;
import org.l2jmobius.gameserver.handler.IItemHandler;
import org.l2jmobius.gameserver.handler.ItemHandler;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.item.EtcItem;
import org.l2jmobius.gameserver.model.item.instance.Item;

/**
 * [member=6902]oRiGiNaL[/member] Code Mobius
 * @Reworked Code Dramaa
 */
public class AutoUsePotManager
{
private static final Set<Set<Player>> POOLS = ConcurrentHashMap.newKeySet();
private static final int POOL_SIZE = 300;
private static final int TASK_DELAY = 300;

protected AutoUsePotManager()
{
}

private class AutoUse implements Runnable
{
private final Set<Player> _players;

public AutoUse(Set<Player> players)
{
_players = players;
}

[member=79]override[/member]
public void run()
{
if (_players.isEmpty())
{
return;
}

for (Player player : _players)
{
if (!player.isOnline() || (player.isInOfflineMode() && !player.isOfflinePlay()))
{
stopAutoPotTask(player);
continue;
}

if (player.isSitting() || player.isStunned() || player.isSleeping() || player.isParalyzed() || player.isAfraid() || player.isAlikeDead() || player.isMounted())
{
continue;
}

if (Config.ENABLE_AUTO_POT && (player.getCurrentHpPercent() < player.getAutoPlaySettings().getAutoHpPercent()))
{
final int itemId = player.getAutoUseSettings().getAutoHPItem();
if (itemId > 0)
{
final Item item = player.getInventory().getItemByItemId(itemId);
if (item == null)
{
player.getAutoUseSettings().setAutoHPItem(0);
}
else
{
final int reuseDelay = item.getReuseDelay();
if ((reuseDelay <= 0) || (player.getItemRemainingReuseTime(item.getObjectId()) <= 0))
{
final EtcItem etcItem = item.getEtcItem();
final IItemHandler handler = ItemHandler.getInstance().getHandler(etcItem);
if ((handler != null) && handler.useItem(player, item, false) && (reuseDelay > 0))
{
player.addTimeStampItem(item, reuseDelay);
}
}
}
}
}

if (Config.ENABLE_AUTO_POTC && (player.getCurrentCpPercent() < player.getAutoPlaySettings().getAutoCpPercent()))
{
final int itemId = player.getAutoUseSettings().getAutoCPItem();
if (itemId > 0)
{
final Item item = player.getInventory().getItemByItemId(itemId);
if (item == null)
{
player.getAutoUseSettings().setAutoCPItem(0);
}
else
{
final int reuseDelay = item.getReuseDelay();
if ((reuseDelay <= 0) || (player.getItemRemainingReuseTime(item.getObjectId()) <= 0))
{
final EtcItem etcItem = item.getEtcItem();
final IItemHandler handler = ItemHandler.getInstance().getHandler(etcItem);
if ((handler != null) && handler.useItem(player, item, false) && (reuseDelay > 0))
{
player.addTimeStampItem(item, reuseDelay);
}
}
}
}
}
if (Config.ENABLE_AUTO_POTM && (player.getCurrentMpPercent() < player.getAutoPlaySettings().getAutoMpPercent()))
{
final int itemId = player.getAutoUseSettings().getAutoMPItem();
if (itemId > 0)
{
final Item item = player.getInventory().getItemByItemId(itemId);
if (item == null)
{
player.getAutoUseSettings().setAutoMPItem(0);
}
else
{
final int reuseDelay = item.getReuseDelay();
if ((reuseDelay <= 0) || (player.getItemRemainingReuseTime(item.getObjectId()) <= 0))
{
final EtcItem etcItem = item.getEtcItem();
final IItemHandler handler = ItemHandler.getInstance().getHandler(etcItem);
if ((handler != null) && handler.useItem(player, item, false) && (reuseDelay > 0))
{
player.addTimeStampItem(item, reuseDelay);
}
}
}
}
}

}
}

}

public synchronized void startAutoPotTask(Player player)
{
for (Set<Player> pool : POOLS)
{
if (pool.contains(player))
{
return;
}
}

for (Set<Player> pool : POOLS)
{
if (pool.size() < POOL_SIZE)
{
pool.add(player);
return;
}
}

final Set<Player> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
pool.add(player);
ThreadPool.schedulePriorityTaskAtFixedRate(new AutoUse(pool), TASK_DELAY, TASK_DELAY);
POOLS.add(pool);
}

public void stopAutoPotTask(Player player)
{
player.getAutoUseSettings().resetSkillOrder();
for (Set<Player> pool : POOLS)
{
if (pool.remove(player))
{
return;
}
}
}

public static AutoUsePotManager getInstance()
{
return SingletonHolder.INSTANCE;
}

private static class SingletonHolder
{
protected static final AutoUsePotManager INSTANCE = new AutoUsePotManager();
}
}


Online dramaa

  • Baron
  • *****
    • Posts: 268
    • L2Equinox
dist/game/data/scripts/handlers/MasterHandler.java
Code: [Select]
import handlers.voicedcommandhandlers.AutoPlay;
+import handlers.voicedcommandhandlers.AutoPot;

and

Config.ENABLE_AUTO_PLAY ? AutoPlay.class : null,
+ Config.ENABLE_AUTO_POT ? AutoPot.class : null,

Config.java

Code: [Select]

public static boolean ENABLE_AUTO_PPOT;
public static boolean ENABLE_AUTO_POT;
public static boolean ENABLE_AUTO_POTC;
public static boolean ENABLE_AUTO_POTM;
public static boolean RESUME_AUTO_POT;
public static boolean AUTO_POT_PREMIUM;

and

// Load AutoPot config file (if exists)
final PropertiesParser autoPotConfig = new PropertiesParser(CUSTOM_AUTO_POT_CONFIG_FILE);
ENABLE_AUTO_PPOT = autoPotConfig.getBoolean("EnableAutoPpot", false);
ENABLE_AUTO_POT = autoPotConfig.getBoolean("EnableAutoPot", true);
ENABLE_AUTO_POTC = autoPotConfig.getBoolean("EnableAutoPotc", true);
ENABLE_AUTO_POTM = autoPotConfig.getBoolean("EnableAutoPotm", true);
AUTO_POT_LOGIN_MESSAGE = autoPotConfig.getString("AutoPotLoginMessage", "");
RESUME_AUTO_POT = autoPotConfig.getBoolean("ResumeAutoPot", false);
AUTO_POT_PREMIUM = autoPotConfig.getBoolean("AutoPotPremium", false);




Online dramaa

  • Baron
  • *****
    • Posts: 268
    • L2Equinox
HTML
Create New Folder > data/html/mods/AutoPot <

Main.html
Code: [Select]
<html>
<title>Auto Potion</title>
<body>
<center>
<br>
%potion_buttonc%
<br>
%potion_button%
<br>
%potion_buttonm%
<br>
%status_buttn%
</center>
</body>
</html>

CPotion.html
Code: [Select]
<html>
<title>Select CP Potion</title>
<body>
%items%
<table width=295>
<tr>
<td height=31>
<center><button action="bypass voice .pot" value="Back" width=95 height=21 back="bigbutton_over" fore="bigbutton"></center>
</td>
</tr>
</table>
</body>
</html>

MPotion.html
Code: [Select]
<html>
<title>Select Mana Potion</title>
<body>
%items%
<table width=295>
<tr>
<td height=31>
<center><button action="bypass voice .pot" value="Back" width=95 height=21 back="bigbutton_over" fore="bigbutton"></center>
</td>
</tr>
</table>
</body>
</html>

Potion.html
Code: [Select]
<html>
<title>Select Healing Potion</title>
<body>
%items%
<table width=295>
<tr>
<td height=31>
<center><button action="bypass voice .pot" value="Back" width=95 height=21 back="bigbutton_over" fore="bigbutton"></center>
</td>
</tr>
</table>
</body>
</html>

New .ini
game/config/custom/AutoPot.ini

Code: [Select]
# ---------------------------------------------------------------------------
# Auto Potion Settings
# ---------------------------------------------------------------------------

# Enable player .play voiced command.
# Default: False
EnableAutoPpot = True

# Default: True
EnableAutoPot = True
EnableAutoPotc = True
EnableAutoPotm = True

# Resume auto play upon enter game.
# Retail: False
ResumeAutoPot = False

# Enable .play command only for premium players.
# Premium System must be enabled.
# Default: False
AutoPotPremium = False

# Message send to players on login.
# Leave empty to disable.
# Example: You can use .play to automate farming.
AutoPotLoginMessage =


Online dramaa

  • Baron
  • *****
    • Posts: 268
    • L2Equinox
some of you wont understand why cp or mp items not appearing so there it is

gameserver/model/skill/AbnormalType.java
Code: [Select]
HP_RECOVER,
+ CP_RECOVER,
+ MP_RECOVER,

then you just add this line to:
Mana Potions:
      <set name="abnormalType" val="MP_RECOVER" />
CP Potions:
      <set name="abnormalType" val="CP_RECOVER" />