Implementation of pet auto potion.

This commit is contained in:
MobiusDevelopment 2022-08-09 21:04:31 +00:00
parent ca82640f13
commit c347ae7b99
44 changed files with 428 additions and 60 deletions

View File

@ -659,6 +659,9 @@ EnableAutoPlay = True
# Default: True
EnableAutoPotion = True
# Default: True
EnableAutoPetPotion = True
# Default: True
EnableAutoSkill = True

View File

@ -928,7 +928,7 @@
<set name="commissionItemType" val="POTION" />
<set name="is_sellable" val="false" />
<skills>
<skill id="2038" level="1" /> <!-- Quick Healing Potion -->
<skill id="49100" level="1" /> <!-- Pet's HP Recovery Potion -->
</skills>
</item>
<item id="93968" name="Best STR Dye (STR +3)" additionalName="3rd Class Transfer" type="EtcItem">

View File

@ -1,9 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../xsd/skills.xsd">
<skill id="49100" toLevel="1" name="Pet HP Recovery Potion">
<!-- AUTO GENERATED SKILL TODO: FIX IT -->
<icon>icon.skill0000</icon>
<isMagic>2</isMagic> <!-- Static Skill -->
<magicLevel>1</magicLevel>
<operateType>A1</operateType>
<magicCriticalRate>5</magicCriticalRate>
<hitCancelTime>0</hitCancelTime>
<targetType>PET</targetType>
<affectScope>SINGLE</affectScope>
<effects>
<effect name="Hp">
<amount>80</amount>
<mode>DIFF</mode>
</effect>
</effects>
</skill>
<skill id="49101" toLevel="1" name="1st Pet Evolution">
<!-- AUTO GENERATED SKILL TODO: FIX IT -->

View File

@ -618,6 +618,7 @@ public class Config
public static boolean BOTREPORT_ALLOW_REPORTS_FROM_SAME_CLAN_MEMBERS;
public static boolean ENABLE_AUTO_PLAY;
public static boolean ENABLE_AUTO_POTION;
public static boolean ENABLE_AUTO_PET_POTION;
public static boolean ENABLE_AUTO_SKILL;
public static boolean ENABLE_AUTO_ITEM;
public static boolean AUTO_PLAY_ATTACK_ACTION;
@ -2147,6 +2148,7 @@ public class Config
BOTREPORT_ALLOW_REPORTS_FROM_SAME_CLAN_MEMBERS = generalConfig.getBoolean("AllowReportsFromSameClanMembers", false);
ENABLE_AUTO_PLAY = generalConfig.getBoolean("EnableAutoPlay", true);
ENABLE_AUTO_POTION = generalConfig.getBoolean("EnableAutoPotion", true);
ENABLE_AUTO_PET_POTION = generalConfig.getBoolean("EnableAutoPetPotion", true);
ENABLE_AUTO_SKILL = generalConfig.getBoolean("EnableAutoSkill", true);
ENABLE_AUTO_ITEM = generalConfig.getBoolean("EnableAutoItem", true);
AUTO_PLAY_ATTACK_ACTION = generalConfig.getBoolean("AutoPlayAttackAction", true);

View File

@ -10602,7 +10602,7 @@ public class Player extends Playable
// Stop auto play.
AutoPlayTaskManager.getInstance().stopAutoPlay(this);
AutoUseTaskManager.getInstance().stopAutoUseTask(this);
sendPacket(new ExAutoPlaySettingSend(_autoPlaySettings.getOptions(), false, _autoPlaySettings.doPickup(), _autoPlaySettings.getNextTargetMode(), _autoPlaySettings.isShortRange(), _autoPlaySettings.getAutoPotionPercent(), _autoPlaySettings.isRespectfulHunting()));
sendPacket(new ExAutoPlaySettingSend(_autoPlaySettings.getOptions(), false, _autoPlaySettings.doPickup(), _autoPlaySettings.getNextTargetMode(), _autoPlaySettings.isShortRange(), _autoPlaySettings.getAutoPotionPercent(), _autoPlaySettings.isRespectfulHunting(), _autoPlaySettings.getAutoPetPotionPercent()));
restoreAutoShortcutVisual();
// Send info to nearby players.
@ -14627,6 +14627,7 @@ public class Player extends Playable
final boolean shortRange = settings.get(4) == 1;
final int potionPercent = settings.get(5);
final boolean respectfulHunting = settings.get(6) == 1;
final int petPotionPercent = settings.size() < 8 ? 0 : settings.get(7);
getAutoPlaySettings().setAutoPotionPercent(potionPercent);
getAutoPlaySettings().setOptions(options);
@ -14634,8 +14635,9 @@ public class Player extends Playable
getAutoPlaySettings().setNextTargetMode(nextTargetMode);
getAutoPlaySettings().setShortRange(shortRange);
getAutoPlaySettings().setRespectfulHunting(respectfulHunting);
getAutoPlaySettings().setAutoPetPotionPercent(petPotionPercent);
sendPacket(new ExAutoPlaySettingSend(options, active, pickUp, nextTargetMode, shortRange, potionPercent, respectfulHunting));
sendPacket(new ExAutoPlaySettingSend(options, active, pickUp, nextTargetMode, shortRange, potionPercent, respectfulHunting, petPotionPercent));
if (active)
{

View File

@ -30,6 +30,7 @@ public class AutoPlaySettingsHolder
private final AtomicBoolean _shortRange = new AtomicBoolean();
private final AtomicBoolean _respectfulHunting = new AtomicBoolean();
private final AtomicInteger _autoPotionPercent = new AtomicInteger();
private final AtomicInteger _autoPetPotionPercent = new AtomicInteger();
public AutoPlaySettingsHolder()
{
@ -94,4 +95,14 @@ public class AutoPlaySettingsHolder
{
_autoPotionPercent.set(value);
}
public int getAutoPetPotionPercent()
{
return _autoPetPotionPercent.get();
}
public void setAutoPetPotionPercent(int value)
{
_autoPetPotionPercent.set(value);
}
}

View File

@ -28,6 +28,7 @@ public class AutoUseSettingsHolder
{
private final Collection<Integer> _autoSupplyItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoPotionItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoPetPotionItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoActions = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoBuffs = ConcurrentHashMap.newKeySet();
private final List<Integer> _autoSkills = new CopyOnWriteArrayList<>();
@ -47,6 +48,11 @@ public class AutoUseSettingsHolder
return _autoPotionItems;
}
public Collection<Integer> getAutoPetPotionItems()
{
return _autoPetPotionItems;
}
public Collection<Integer> getAutoActions()
{
return _autoActions;
@ -99,6 +105,6 @@ public class AutoUseSettingsHolder
public boolean isEmpty()
{
return _autoSupplyItems.isEmpty() && _autoPotionItems.isEmpty() && _autoSkills.isEmpty() && _autoActions.isEmpty();
return _autoSupplyItems.isEmpty() && _autoPotionItems.isEmpty() && _autoPetPotionItems.isEmpty() && _autoSkills.isEmpty() && _autoActions.isEmpty();
}
}

View File

@ -39,6 +39,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
private int _nextTargetMode;
private boolean _shortRange;
private int _potionPercent;
private int _petPotionPercent;
private boolean _respectfulHunting;
@Override
@ -50,7 +51,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
_nextTargetMode = packet.readH();
_shortRange = packet.readC() == 1;
_potionPercent = packet.readD();
packet.readD(); // 272
_petPotionPercent = packet.readD(); // 272
_respectfulHunting = packet.readC() == 1;
return true;
}
@ -72,7 +73,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
return;
}
player.sendPacket(new ExAutoPlaySettingSend(_options, _active, _pickUp, _nextTargetMode, _shortRange, _potionPercent, _respectfulHunting));
player.sendPacket(new ExAutoPlaySettingSend(_options, _active, _pickUp, _nextTargetMode, _shortRange, _potionPercent, _respectfulHunting, _petPotionPercent));
player.getAutoPlaySettings().setAutoPotionPercent(_potionPercent);
if (!Config.ENABLE_AUTO_PLAY)
@ -80,7 +81,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
return;
}
final List<Integer> settings = new ArrayList<>(7);
final List<Integer> settings = new ArrayList<>(8);
settings.add(0, _options);
settings.add(1, _active ? 1 : 0);
settings.add(2, _pickUp ? 1 : 0);
@ -88,6 +89,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
settings.add(4, _shortRange ? 1 : 0);
settings.add(5, _potionPercent);
settings.add(6, _respectfulHunting ? 1 : 0);
settings.add(7, _petPotionPercent);
player.getVariables().setIntegerList(PlayerVariables.AUTO_USE_SETTINGS, settings);
player.getAutoPlaySettings().setOptions(_options);
@ -95,6 +97,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
player.getAutoPlaySettings().setNextTargetMode(_nextTargetMode);
player.getAutoPlaySettings().setShortRange(_shortRange);
player.getAutoPlaySettings().setRespectfulHunting(_respectfulHunting);
player.getAutoPlaySettings().setAutoPetPotionPercent(_petPotionPercent);
if (_active)
{

View File

@ -114,6 +114,7 @@ public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
else // auto potion
{
AutoUseTaskManager.getInstance().removeAutoPotionItem(player, item.getId());
AutoUseTaskManager.getInstance().removeAutoPetPotionItem(player, item.getId());
}
}
// auto skill
@ -147,12 +148,23 @@ public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
else
{
// auto potion
if ((_page == 23) && (_slot == 1))
if (_page == 23)
{
if (Config.ENABLE_AUTO_POTION && (item != null) && item.isPotion())
if (_slot == 1)
{
AutoUseTaskManager.getInstance().addAutoPotionItem(player, item.getId());
return;
if (Config.ENABLE_AUTO_POTION && (item != null) && item.isPotion())
{
AutoUseTaskManager.getInstance().addAutoPotionItem(player, item.getId());
return;
}
}
else if (_slot == 2)
{
if (Config.ENABLE_AUTO_PET_POTION && (item != null) && item.isPotion())
{
AutoUseTaskManager.getInstance().addAutoPetPotionItem(player, item.getId());
return;
}
}
}
// auto skill

View File

@ -32,8 +32,9 @@ public class ExAutoPlaySettingSend implements IClientOutgoingPacket
private final boolean _shortRange;
private final int _potionPercent;
private final boolean _respectfulHunting;
private final int _petPotionPercent;
public ExAutoPlaySettingSend(int options, boolean active, boolean pickUp, int nextTargetMode, boolean shortRange, int potionPercent, boolean respectfulHunting)
public ExAutoPlaySettingSend(int options, boolean active, boolean pickUp, int nextTargetMode, boolean shortRange, int potionPercent, boolean respectfulHunting, int petPotionPercent)
{
_options = options;
_active = active;
@ -42,6 +43,7 @@ public class ExAutoPlaySettingSend implements IClientOutgoingPacket
_shortRange = shortRange;
_potionPercent = potionPercent;
_respectfulHunting = respectfulHunting;
_petPotionPercent = petPotionPercent;
}
@Override
@ -54,7 +56,7 @@ public class ExAutoPlaySettingSend implements IClientOutgoingPacket
packet.writeH(_nextTargetMode);
packet.writeC(_shortRange ? 1 : 0);
packet.writeD(_potionPercent);
packet.writeD(0); // 272
packet.writeD(_petPotionPercent); // 272
packet.writeC(_respectfulHunting ? 1 : 0);
return true;
}

View File

@ -35,6 +35,7 @@ import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.instance.Guard;
import org.l2jmobius.gameserver.model.actor.instance.Pet;
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
import org.l2jmobius.gameserver.model.holders.AttachSkillHolder;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
@ -163,6 +164,34 @@ public class AutoUseTaskManager implements Runnable
}
}
if (Config.ENABLE_AUTO_PET_POTION && !isInPeaceZone)
{
final Pet pet = player.getPet();
if ((pet != null) && (pet.getCurrentHpPercent() <= player.getAutoPlaySettings().getAutoPetPotionPercent()))
{
POTIONS: for (Integer itemId : player.getAutoUseSettings().getAutoPetPotionItems())
{
final Item item = player.getInventory().getItemByItemId(itemId.intValue());
if (item == null)
{
player.getAutoUseSettings().getAutoPetPotionItems().remove(itemId);
continue POTIONS;
}
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_SKILL)
{
BUFFS: for (Integer skillId : player.getAutoUseSettings().getAutoBuffs())
@ -465,6 +494,18 @@ public class AutoUseTaskManager implements Runnable
stopAutoUseTask(player);
}
public void addAutoPetPotionItem(Player player, int itemId)
{
player.getAutoUseSettings().getAutoPetPotionItems().add(itemId);
startAutoUseTask(player);
}
public void removeAutoPetPotionItem(Player player, int itemId)
{
player.getAutoUseSettings().getAutoPetPotionItems().remove(itemId);
stopAutoUseTask(player);
}
public void addAutoBuff(Player player, int skillId)
{
player.getAutoUseSettings().getAutoBuffs().add(skillId);

View File

@ -659,6 +659,9 @@ EnableAutoPlay = True
# Default: True
EnableAutoPotion = True
# Default: True
EnableAutoPetPotion = True
# Default: True
EnableAutoSkill = True

View File

@ -927,7 +927,7 @@
<set name="commissionItemType" val="POTION" />
<set name="is_sellable" val="false" />
<skills>
<skill id="2038" level="1" /> <!-- Quick Healing Potion -->
<skill id="49100" level="1" /> <!-- Pet's HP Recovery Potion -->
</skills>
</item>
<item id="93968" name="Best STR Dye (STR +3)" additionalName="3rd Class" type="EtcItem">

View File

@ -1,9 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../xsd/skills.xsd">
<skill id="49100" toLevel="1" name="Pet HP Recovery Potion">
<!-- AUTO GENERATED SKILL TODO: FIX IT -->
<icon>icon.skill0000</icon>
<isMagic>2</isMagic> <!-- Static Skill -->
<magicLevel>1</magicLevel>
<operateType>A1</operateType>
<magicCriticalRate>5</magicCriticalRate>
<hitCancelTime>0</hitCancelTime>
<targetType>PET</targetType>
<affectScope>SINGLE</affectScope>
<effects>
<effect name="Hp">
<amount>80</amount>
<mode>DIFF</mode>
</effect>
</effects>
</skill>
<skill id="49101" toLevel="1" name="1st Pet Evolution">
<!-- AUTO GENERATED SKILL TODO: FIX IT -->

View File

@ -620,6 +620,7 @@ public class Config
public static boolean BOTREPORT_ALLOW_REPORTS_FROM_SAME_CLAN_MEMBERS;
public static boolean ENABLE_AUTO_PLAY;
public static boolean ENABLE_AUTO_POTION;
public static boolean ENABLE_AUTO_PET_POTION;
public static boolean ENABLE_AUTO_SKILL;
public static boolean ENABLE_AUTO_ITEM;
public static boolean AUTO_PLAY_ATTACK_ACTION;
@ -2246,6 +2247,7 @@ public class Config
BOTREPORT_ALLOW_REPORTS_FROM_SAME_CLAN_MEMBERS = generalConfig.getBoolean("AllowReportsFromSameClanMembers", false);
ENABLE_AUTO_PLAY = generalConfig.getBoolean("EnableAutoPlay", true);
ENABLE_AUTO_POTION = generalConfig.getBoolean("EnableAutoPotion", true);
ENABLE_AUTO_PET_POTION = generalConfig.getBoolean("EnableAutoPetPotion", true);
ENABLE_AUTO_SKILL = generalConfig.getBoolean("EnableAutoSkill", true);
ENABLE_AUTO_ITEM = generalConfig.getBoolean("EnableAutoItem", true);
AUTO_PLAY_ATTACK_ACTION = generalConfig.getBoolean("AutoPlayAttackAction", true);

View File

@ -10657,7 +10657,7 @@ public class Player extends Playable
// Stop auto play.
AutoPlayTaskManager.getInstance().stopAutoPlay(this);
AutoUseTaskManager.getInstance().stopAutoUseTask(this);
sendPacket(new ExAutoPlaySettingSend(_autoPlaySettings.getOptions(), false, _autoPlaySettings.doPickup(), _autoPlaySettings.getNextTargetMode(), _autoPlaySettings.isShortRange(), _autoPlaySettings.getAutoPotionPercent(), _autoPlaySettings.isRespectfulHunting()));
sendPacket(new ExAutoPlaySettingSend(_autoPlaySettings.getOptions(), false, _autoPlaySettings.doPickup(), _autoPlaySettings.getNextTargetMode(), _autoPlaySettings.isShortRange(), _autoPlaySettings.getAutoPotionPercent(), _autoPlaySettings.isRespectfulHunting(), _autoPlaySettings.getAutoPetPotionPercent()));
restoreAutoShortcutVisual();
// Send info to nearby players.
@ -14708,6 +14708,7 @@ public class Player extends Playable
final boolean shortRange = settings.get(4) == 1;
final int potionPercent = settings.get(5);
final boolean respectfulHunting = settings.get(6) == 1;
final int petPotionPercent = settings.size() < 8 ? 0 : settings.get(7);
getAutoPlaySettings().setAutoPotionPercent(potionPercent);
getAutoPlaySettings().setOptions(options);
@ -14715,8 +14716,9 @@ public class Player extends Playable
getAutoPlaySettings().setNextTargetMode(nextTargetMode);
getAutoPlaySettings().setShortRange(shortRange);
getAutoPlaySettings().setRespectfulHunting(respectfulHunting);
getAutoPlaySettings().setAutoPetPotionPercent(petPotionPercent);
sendPacket(new ExAutoPlaySettingSend(options, active, pickUp, nextTargetMode, shortRange, potionPercent, respectfulHunting));
sendPacket(new ExAutoPlaySettingSend(options, active, pickUp, nextTargetMode, shortRange, potionPercent, respectfulHunting, petPotionPercent));
if (active)
{

View File

@ -30,6 +30,7 @@ public class AutoPlaySettingsHolder
private final AtomicBoolean _shortRange = new AtomicBoolean();
private final AtomicBoolean _respectfulHunting = new AtomicBoolean();
private final AtomicInteger _autoPotionPercent = new AtomicInteger();
private final AtomicInteger _autoPetPotionPercent = new AtomicInteger();
public AutoPlaySettingsHolder()
{
@ -94,4 +95,14 @@ public class AutoPlaySettingsHolder
{
_autoPotionPercent.set(value);
}
public int getAutoPetPotionPercent()
{
return _autoPetPotionPercent.get();
}
public void setAutoPetPotionPercent(int value)
{
_autoPetPotionPercent.set(value);
}
}

View File

@ -28,6 +28,7 @@ public class AutoUseSettingsHolder
{
private final Collection<Integer> _autoSupplyItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoPotionItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoPetPotionItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoActions = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoBuffs = ConcurrentHashMap.newKeySet();
private final List<Integer> _autoSkills = new CopyOnWriteArrayList<>();
@ -47,6 +48,11 @@ public class AutoUseSettingsHolder
return _autoPotionItems;
}
public Collection<Integer> getAutoPetPotionItems()
{
return _autoPetPotionItems;
}
public Collection<Integer> getAutoActions()
{
return _autoActions;
@ -99,6 +105,6 @@ public class AutoUseSettingsHolder
public boolean isEmpty()
{
return _autoSupplyItems.isEmpty() && _autoPotionItems.isEmpty() && _autoSkills.isEmpty() && _autoActions.isEmpty();
return _autoSupplyItems.isEmpty() && _autoPotionItems.isEmpty() && _autoPetPotionItems.isEmpty() && _autoSkills.isEmpty() && _autoActions.isEmpty();
}
}

View File

@ -39,6 +39,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
private int _nextTargetMode;
private boolean _shortRange;
private int _potionPercent;
private int _petPotionPercent;
private boolean _respectfulHunting;
@Override
@ -50,7 +51,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
_nextTargetMode = packet.readH();
_shortRange = packet.readC() == 1;
_potionPercent = packet.readD();
packet.readD(); // 272
_petPotionPercent = packet.readD(); // 272
_respectfulHunting = packet.readC() == 1;
return true;
}
@ -72,7 +73,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
return;
}
player.sendPacket(new ExAutoPlaySettingSend(_options, _active, _pickUp, _nextTargetMode, _shortRange, _potionPercent, _respectfulHunting));
player.sendPacket(new ExAutoPlaySettingSend(_options, _active, _pickUp, _nextTargetMode, _shortRange, _potionPercent, _respectfulHunting, _petPotionPercent));
player.getAutoPlaySettings().setAutoPotionPercent(_potionPercent);
if (!Config.ENABLE_AUTO_PLAY)
@ -80,7 +81,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
return;
}
final List<Integer> settings = new ArrayList<>(7);
final List<Integer> settings = new ArrayList<>(8);
settings.add(0, _options);
settings.add(1, _active ? 1 : 0);
settings.add(2, _pickUp ? 1 : 0);
@ -88,6 +89,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
settings.add(4, _shortRange ? 1 : 0);
settings.add(5, _potionPercent);
settings.add(6, _respectfulHunting ? 1 : 0);
settings.add(7, _petPotionPercent);
player.getVariables().setIntegerList(PlayerVariables.AUTO_USE_SETTINGS, settings);
player.getAutoPlaySettings().setOptions(_options);
@ -95,6 +97,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
player.getAutoPlaySettings().setNextTargetMode(_nextTargetMode);
player.getAutoPlaySettings().setShortRange(_shortRange);
player.getAutoPlaySettings().setRespectfulHunting(_respectfulHunting);
player.getAutoPlaySettings().setAutoPetPotionPercent(_petPotionPercent);
if (_active)
{

View File

@ -114,6 +114,7 @@ public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
else // auto potion
{
AutoUseTaskManager.getInstance().removeAutoPotionItem(player, item.getId());
AutoUseTaskManager.getInstance().removeAutoPetPotionItem(player, item.getId());
}
}
// auto skill
@ -147,12 +148,23 @@ public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
else
{
// auto potion
if ((_page == 23) && (_slot == 1))
if (_page == 23)
{
if (Config.ENABLE_AUTO_POTION && (item != null) && item.isPotion())
if (_slot == 1)
{
AutoUseTaskManager.getInstance().addAutoPotionItem(player, item.getId());
return;
if (Config.ENABLE_AUTO_POTION && (item != null) && item.isPotion())
{
AutoUseTaskManager.getInstance().addAutoPotionItem(player, item.getId());
return;
}
}
else if (_slot == 2)
{
if (Config.ENABLE_AUTO_PET_POTION && (item != null) && item.isPotion())
{
AutoUseTaskManager.getInstance().addAutoPetPotionItem(player, item.getId());
return;
}
}
}
// auto skill

View File

@ -32,8 +32,9 @@ public class ExAutoPlaySettingSend implements IClientOutgoingPacket
private final boolean _shortRange;
private final int _potionPercent;
private final boolean _respectfulHunting;
private final int _petPotionPercent;
public ExAutoPlaySettingSend(int options, boolean active, boolean pickUp, int nextTargetMode, boolean shortRange, int potionPercent, boolean respectfulHunting)
public ExAutoPlaySettingSend(int options, boolean active, boolean pickUp, int nextTargetMode, boolean shortRange, int potionPercent, boolean respectfulHunting, int petPotionPercent)
{
_options = options;
_active = active;
@ -42,6 +43,7 @@ public class ExAutoPlaySettingSend implements IClientOutgoingPacket
_shortRange = shortRange;
_potionPercent = potionPercent;
_respectfulHunting = respectfulHunting;
_petPotionPercent = petPotionPercent;
}
@Override
@ -54,7 +56,7 @@ public class ExAutoPlaySettingSend implements IClientOutgoingPacket
packet.writeH(_nextTargetMode);
packet.writeC(_shortRange ? 1 : 0);
packet.writeD(_potionPercent);
packet.writeD(0); // 272
packet.writeD(_petPotionPercent); // 272
packet.writeC(_respectfulHunting ? 1 : 0);
return true;
}

View File

@ -35,6 +35,7 @@ import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.instance.Guard;
import org.l2jmobius.gameserver.model.actor.instance.Pet;
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
import org.l2jmobius.gameserver.model.holders.AttachSkillHolder;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
@ -163,6 +164,34 @@ public class AutoUseTaskManager implements Runnable
}
}
if (Config.ENABLE_AUTO_PET_POTION && !isInPeaceZone)
{
final Pet pet = player.getPet();
if ((pet != null) && (pet.getCurrentHpPercent() <= player.getAutoPlaySettings().getAutoPetPotionPercent()))
{
POTIONS: for (Integer itemId : player.getAutoUseSettings().getAutoPetPotionItems())
{
final Item item = player.getInventory().getItemByItemId(itemId.intValue());
if (item == null)
{
player.getAutoUseSettings().getAutoPetPotionItems().remove(itemId);
continue POTIONS;
}
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_SKILL)
{
BUFFS: for (Integer skillId : player.getAutoUseSettings().getAutoBuffs())
@ -465,6 +494,18 @@ public class AutoUseTaskManager implements Runnable
stopAutoUseTask(player);
}
public void addAutoPetPotionItem(Player player, int itemId)
{
player.getAutoUseSettings().getAutoPetPotionItems().add(itemId);
startAutoUseTask(player);
}
public void removeAutoPetPotionItem(Player player, int itemId)
{
player.getAutoUseSettings().getAutoPetPotionItems().remove(itemId);
stopAutoUseTask(player);
}
public void addAutoBuff(Player player, int skillId)
{
player.getAutoUseSettings().getAutoBuffs().add(skillId);

View File

@ -659,6 +659,9 @@ EnableAutoPlay = True
# Default: True
EnableAutoPotion = True
# Default: True
EnableAutoPetPotion = True
# Default: True
EnableAutoSkill = True

View File

@ -927,7 +927,7 @@
<set name="commissionItemType" val="POTION" />
<set name="is_sellable" val="false" />
<skills>
<skill id="2038" level="1" /> <!-- Quick Healing Potion -->
<skill id="49100" level="1" /> <!-- Pet's HP Recovery Potion -->
</skills>
</item>
<item id="93968" name="Best STR Dye (STR +3)" additionalName="3rd Class" type="EtcItem">

View File

@ -1,9 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../xsd/skills.xsd">
<skill id="49100" toLevel="1" name="Pet HP Recovery Potion">
<!-- AUTO GENERATED SKILL TODO: FIX IT -->
<icon>icon.skill0000</icon>
<isMagic>2</isMagic> <!-- Static Skill -->
<magicLevel>1</magicLevel>
<operateType>A1</operateType>
<magicCriticalRate>5</magicCriticalRate>
<hitCancelTime>0</hitCancelTime>
<targetType>PET</targetType>
<affectScope>SINGLE</affectScope>
<effects>
<effect name="Hp">
<amount>80</amount>
<mode>DIFF</mode>
</effect>
</effects>
</skill>
<skill id="49101" toLevel="1" name="1st Pet Evolution">
<!-- AUTO GENERATED SKILL TODO: FIX IT -->

View File

@ -621,6 +621,7 @@ public class Config
public static boolean BOTREPORT_ALLOW_REPORTS_FROM_SAME_CLAN_MEMBERS;
public static boolean ENABLE_AUTO_PLAY;
public static boolean ENABLE_AUTO_POTION;
public static boolean ENABLE_AUTO_PET_POTION;
public static boolean ENABLE_AUTO_SKILL;
public static boolean ENABLE_AUTO_ITEM;
public static boolean AUTO_PLAY_ATTACK_ACTION;
@ -2253,6 +2254,7 @@ public class Config
BOTREPORT_ALLOW_REPORTS_FROM_SAME_CLAN_MEMBERS = generalConfig.getBoolean("AllowReportsFromSameClanMembers", false);
ENABLE_AUTO_PLAY = generalConfig.getBoolean("EnableAutoPlay", true);
ENABLE_AUTO_POTION = generalConfig.getBoolean("EnableAutoPotion", true);
ENABLE_AUTO_PET_POTION = generalConfig.getBoolean("EnableAutoPetPotion", true);
ENABLE_AUTO_SKILL = generalConfig.getBoolean("EnableAutoSkill", true);
ENABLE_AUTO_ITEM = generalConfig.getBoolean("EnableAutoItem", true);
AUTO_PLAY_ATTACK_ACTION = generalConfig.getBoolean("AutoPlayAttackAction", true);

View File

@ -10833,7 +10833,7 @@ public class Player extends Playable
// Stop auto play.
AutoPlayTaskManager.getInstance().stopAutoPlay(this);
AutoUseTaskManager.getInstance().stopAutoUseTask(this);
sendPacket(new ExAutoPlaySettingSend(_autoPlaySettings.getOptions(), false, _autoPlaySettings.doPickup(), _autoPlaySettings.getNextTargetMode(), _autoPlaySettings.isShortRange(), _autoPlaySettings.getAutoPotionPercent(), _autoPlaySettings.isRespectfulHunting()));
sendPacket(new ExAutoPlaySettingSend(_autoPlaySettings.getOptions(), false, _autoPlaySettings.doPickup(), _autoPlaySettings.getNextTargetMode(), _autoPlaySettings.isShortRange(), _autoPlaySettings.getAutoPotionPercent(), _autoPlaySettings.isRespectfulHunting(), _autoPlaySettings.getAutoPetPotionPercent()));
restoreAutoShortcutVisual();
// Send info to nearby players.
@ -14888,6 +14888,7 @@ public class Player extends Playable
final boolean shortRange = settings.get(4) == 1;
final int potionPercent = settings.get(5);
final boolean respectfulHunting = settings.get(6) == 1;
final int petPotionPercent = settings.size() < 8 ? 0 : settings.get(7);
getAutoPlaySettings().setAutoPotionPercent(potionPercent);
getAutoPlaySettings().setOptions(options);
@ -14895,8 +14896,9 @@ public class Player extends Playable
getAutoPlaySettings().setNextTargetMode(nextTargetMode);
getAutoPlaySettings().setShortRange(shortRange);
getAutoPlaySettings().setRespectfulHunting(respectfulHunting);
getAutoPlaySettings().setAutoPetPotionPercent(petPotionPercent);
sendPacket(new ExAutoPlaySettingSend(options, active, pickUp, nextTargetMode, shortRange, potionPercent, respectfulHunting));
sendPacket(new ExAutoPlaySettingSend(options, active, pickUp, nextTargetMode, shortRange, potionPercent, respectfulHunting, petPotionPercent));
if (active)
{

View File

@ -30,6 +30,7 @@ public class AutoPlaySettingsHolder
private final AtomicBoolean _shortRange = new AtomicBoolean();
private final AtomicBoolean _respectfulHunting = new AtomicBoolean();
private final AtomicInteger _autoPotionPercent = new AtomicInteger();
private final AtomicInteger _autoPetPotionPercent = new AtomicInteger();
public AutoPlaySettingsHolder()
{
@ -94,4 +95,14 @@ public class AutoPlaySettingsHolder
{
_autoPotionPercent.set(value);
}
public int getAutoPetPotionPercent()
{
return _autoPetPotionPercent.get();
}
public void setAutoPetPotionPercent(int value)
{
_autoPetPotionPercent.set(value);
}
}

View File

@ -28,6 +28,7 @@ public class AutoUseSettingsHolder
{
private final Collection<Integer> _autoSupplyItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoPotionItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoPetPotionItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoActions = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoBuffs = ConcurrentHashMap.newKeySet();
private final List<Integer> _autoSkills = new CopyOnWriteArrayList<>();
@ -47,6 +48,11 @@ public class AutoUseSettingsHolder
return _autoPotionItems;
}
public Collection<Integer> getAutoPetPotionItems()
{
return _autoPetPotionItems;
}
public Collection<Integer> getAutoActions()
{
return _autoActions;
@ -99,6 +105,6 @@ public class AutoUseSettingsHolder
public boolean isEmpty()
{
return _autoSupplyItems.isEmpty() && _autoPotionItems.isEmpty() && _autoSkills.isEmpty() && _autoActions.isEmpty();
return _autoSupplyItems.isEmpty() && _autoPotionItems.isEmpty() && _autoPetPotionItems.isEmpty() && _autoSkills.isEmpty() && _autoActions.isEmpty();
}
}

View File

@ -39,6 +39,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
private int _nextTargetMode;
private boolean _shortRange;
private int _potionPercent;
private int _petPotionPercent;
private boolean _respectfulHunting;
@Override
@ -50,7 +51,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
_nextTargetMode = packet.readH();
_shortRange = packet.readC() == 1;
_potionPercent = packet.readD();
packet.readD(); // 272
_petPotionPercent = packet.readD(); // 272
_respectfulHunting = packet.readC() == 1;
return true;
}
@ -72,7 +73,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
return;
}
player.sendPacket(new ExAutoPlaySettingSend(_options, _active, _pickUp, _nextTargetMode, _shortRange, _potionPercent, _respectfulHunting));
player.sendPacket(new ExAutoPlaySettingSend(_options, _active, _pickUp, _nextTargetMode, _shortRange, _potionPercent, _respectfulHunting, _petPotionPercent));
player.getAutoPlaySettings().setAutoPotionPercent(_potionPercent);
if (!Config.ENABLE_AUTO_PLAY)
@ -80,7 +81,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
return;
}
final List<Integer> settings = new ArrayList<>(7);
final List<Integer> settings = new ArrayList<>(8);
settings.add(0, _options);
settings.add(1, _active ? 1 : 0);
settings.add(2, _pickUp ? 1 : 0);
@ -88,6 +89,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
settings.add(4, _shortRange ? 1 : 0);
settings.add(5, _potionPercent);
settings.add(6, _respectfulHunting ? 1 : 0);
settings.add(7, _petPotionPercent);
player.getVariables().setIntegerList(PlayerVariables.AUTO_USE_SETTINGS, settings);
player.getAutoPlaySettings().setOptions(_options);
@ -95,6 +97,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
player.getAutoPlaySettings().setNextTargetMode(_nextTargetMode);
player.getAutoPlaySettings().setShortRange(_shortRange);
player.getAutoPlaySettings().setRespectfulHunting(_respectfulHunting);
player.getAutoPlaySettings().setAutoPetPotionPercent(_petPotionPercent);
if (_active)
{

View File

@ -114,6 +114,7 @@ public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
else // auto potion
{
AutoUseTaskManager.getInstance().removeAutoPotionItem(player, item.getId());
AutoUseTaskManager.getInstance().removeAutoPetPotionItem(player, item.getId());
}
}
// auto skill
@ -147,12 +148,23 @@ public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
else
{
// auto potion
if ((_page == 23) && (_slot == 1))
if (_page == 23)
{
if (Config.ENABLE_AUTO_POTION && (item != null) && item.isPotion())
if (_slot == 1)
{
AutoUseTaskManager.getInstance().addAutoPotionItem(player, item.getId());
return;
if (Config.ENABLE_AUTO_POTION && (item != null) && item.isPotion())
{
AutoUseTaskManager.getInstance().addAutoPotionItem(player, item.getId());
return;
}
}
else if (_slot == 2)
{
if (Config.ENABLE_AUTO_PET_POTION && (item != null) && item.isPotion())
{
AutoUseTaskManager.getInstance().addAutoPetPotionItem(player, item.getId());
return;
}
}
}
// auto skill

View File

@ -32,8 +32,9 @@ public class ExAutoPlaySettingSend implements IClientOutgoingPacket
private final boolean _shortRange;
private final int _potionPercent;
private final boolean _respectfulHunting;
private final int _petPotionPercent;
public ExAutoPlaySettingSend(int options, boolean active, boolean pickUp, int nextTargetMode, boolean shortRange, int potionPercent, boolean respectfulHunting)
public ExAutoPlaySettingSend(int options, boolean active, boolean pickUp, int nextTargetMode, boolean shortRange, int potionPercent, boolean respectfulHunting, int petPotionPercent)
{
_options = options;
_active = active;
@ -42,6 +43,7 @@ public class ExAutoPlaySettingSend implements IClientOutgoingPacket
_shortRange = shortRange;
_potionPercent = potionPercent;
_respectfulHunting = respectfulHunting;
_petPotionPercent = petPotionPercent;
}
@Override
@ -54,7 +56,7 @@ public class ExAutoPlaySettingSend implements IClientOutgoingPacket
packet.writeH(_nextTargetMode);
packet.writeC(_shortRange ? 1 : 0);
packet.writeD(_potionPercent);
packet.writeD(0); // 272
packet.writeD(_petPotionPercent); // 272
packet.writeC(_respectfulHunting ? 1 : 0);
return true;
}

View File

@ -35,6 +35,7 @@ import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.instance.Guard;
import org.l2jmobius.gameserver.model.actor.instance.Pet;
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
import org.l2jmobius.gameserver.model.holders.AttachSkillHolder;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
@ -163,6 +164,34 @@ public class AutoUseTaskManager implements Runnable
}
}
if (Config.ENABLE_AUTO_PET_POTION && !isInPeaceZone)
{
final Pet pet = player.getPet();
if ((pet != null) && (pet.getCurrentHpPercent() <= player.getAutoPlaySettings().getAutoPetPotionPercent()))
{
POTIONS: for (Integer itemId : player.getAutoUseSettings().getAutoPetPotionItems())
{
final Item item = player.getInventory().getItemByItemId(itemId.intValue());
if (item == null)
{
player.getAutoUseSettings().getAutoPetPotionItems().remove(itemId);
continue POTIONS;
}
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_SKILL)
{
BUFFS: for (Integer skillId : player.getAutoUseSettings().getAutoBuffs())
@ -465,6 +494,18 @@ public class AutoUseTaskManager implements Runnable
stopAutoUseTask(player);
}
public void addAutoPetPotionItem(Player player, int itemId)
{
player.getAutoUseSettings().getAutoPetPotionItems().add(itemId);
startAutoUseTask(player);
}
public void removeAutoPetPotionItem(Player player, int itemId)
{
player.getAutoUseSettings().getAutoPetPotionItems().remove(itemId);
stopAutoUseTask(player);
}
public void addAutoBuff(Player player, int skillId)
{
player.getAutoUseSettings().getAutoBuffs().add(skillId);

View File

@ -659,6 +659,9 @@ EnableAutoPlay = True
# Default: True
EnableAutoPotion = True
# Default: True
EnableAutoPetPotion = True
# Default: True
EnableAutoSkill = True

View File

@ -927,7 +927,7 @@
<set name="commissionItemType" val="POTION" />
<set name="is_sellable" val="false" />
<skills>
<skill id="2038" level="1" /> <!-- Quick Healing Potion -->
<skill id="49100" level="1" /> <!-- Pet's HP Recovery Potion -->
</skills>
</item>
<item id="93968" name="Best STR Dye (STR +3)" additionalName="3rd Class" type="EtcItem">

View File

@ -1,9 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../xsd/skills.xsd">
<skill id="49100" toLevel="1" name="Pet's HP Recovery Potion">
<!-- AUTO GENERATED SKILL TODO: FIX IT -->
<icon>icon.skill0000</icon>
<isMagic>2</isMagic> <!-- Static Skill -->
<magicLevel>1</magicLevel>
<operateType>A1</operateType>
<magicCriticalRate>5</magicCriticalRate>
<hitCancelTime>0</hitCancelTime>
<targetType>PET</targetType>
<affectScope>SINGLE</affectScope>
<effects>
<effect name="Hp">
<amount>80</amount>
<mode>DIFF</mode>
</effect>
</effects>
</skill>
<skill id="49101" toLevel="1" name="1st Pet Evolution">
<!-- AUTO GENERATED SKILL TODO: FIX IT -->

View File

@ -621,6 +621,7 @@ public class Config
public static boolean BOTREPORT_ALLOW_REPORTS_FROM_SAME_CLAN_MEMBERS;
public static boolean ENABLE_AUTO_PLAY;
public static boolean ENABLE_AUTO_POTION;
public static boolean ENABLE_AUTO_PET_POTION;
public static boolean ENABLE_AUTO_SKILL;
public static boolean ENABLE_AUTO_ITEM;
public static boolean AUTO_PLAY_ATTACK_ACTION;
@ -2253,6 +2254,7 @@ public class Config
BOTREPORT_ALLOW_REPORTS_FROM_SAME_CLAN_MEMBERS = generalConfig.getBoolean("AllowReportsFromSameClanMembers", false);
ENABLE_AUTO_PLAY = generalConfig.getBoolean("EnableAutoPlay", true);
ENABLE_AUTO_POTION = generalConfig.getBoolean("EnableAutoPotion", true);
ENABLE_AUTO_PET_POTION = generalConfig.getBoolean("EnableAutoPetPotion", true);
ENABLE_AUTO_SKILL = generalConfig.getBoolean("EnableAutoSkill", true);
ENABLE_AUTO_ITEM = generalConfig.getBoolean("EnableAutoItem", true);
AUTO_PLAY_ATTACK_ACTION = generalConfig.getBoolean("AutoPlayAttackAction", true);

View File

@ -10887,7 +10887,7 @@ public class Player extends Playable
// Stop auto play.
AutoPlayTaskManager.getInstance().stopAutoPlay(this);
AutoUseTaskManager.getInstance().stopAutoUseTask(this);
sendPacket(new ExAutoPlaySettingSend(_autoPlaySettings.getOptions(), false, _autoPlaySettings.doPickup(), _autoPlaySettings.getNextTargetMode(), _autoPlaySettings.isShortRange(), _autoPlaySettings.getAutoPotionPercent(), _autoPlaySettings.isRespectfulHunting()));
sendPacket(new ExAutoPlaySettingSend(_autoPlaySettings.getOptions(), false, _autoPlaySettings.doPickup(), _autoPlaySettings.getNextTargetMode(), _autoPlaySettings.isShortRange(), _autoPlaySettings.getAutoPotionPercent(), _autoPlaySettings.isRespectfulHunting(), _autoPlaySettings.getAutoPetPotionPercent()));
restoreAutoShortcutVisual();
// Send info to nearby players.
@ -14977,6 +14977,7 @@ public class Player extends Playable
final boolean shortRange = settings.get(4) == 1;
final int potionPercent = settings.get(5);
final boolean respectfulHunting = settings.get(6) == 1;
final int petPotionPercent = settings.size() < 8 ? 0 : settings.get(7);
getAutoPlaySettings().setAutoPotionPercent(potionPercent);
getAutoPlaySettings().setOptions(options);
@ -14984,8 +14985,9 @@ public class Player extends Playable
getAutoPlaySettings().setNextTargetMode(nextTargetMode);
getAutoPlaySettings().setShortRange(shortRange);
getAutoPlaySettings().setRespectfulHunting(respectfulHunting);
getAutoPlaySettings().setAutoPetPotionPercent(petPotionPercent);
sendPacket(new ExAutoPlaySettingSend(options, active, pickUp, nextTargetMode, shortRange, potionPercent, respectfulHunting));
sendPacket(new ExAutoPlaySettingSend(options, active, pickUp, nextTargetMode, shortRange, potionPercent, respectfulHunting, petPotionPercent));
if (active)
{

View File

@ -30,6 +30,7 @@ public class AutoPlaySettingsHolder
private final AtomicBoolean _shortRange = new AtomicBoolean();
private final AtomicBoolean _respectfulHunting = new AtomicBoolean();
private final AtomicInteger _autoPotionPercent = new AtomicInteger();
private final AtomicInteger _autoPetPotionPercent = new AtomicInteger();
public AutoPlaySettingsHolder()
{
@ -94,4 +95,14 @@ public class AutoPlaySettingsHolder
{
_autoPotionPercent.set(value);
}
public int getAutoPetPotionPercent()
{
return _autoPetPotionPercent.get();
}
public void setAutoPetPotionPercent(int value)
{
_autoPetPotionPercent.set(value);
}
}

View File

@ -28,6 +28,7 @@ public class AutoUseSettingsHolder
{
private final Collection<Integer> _autoSupplyItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoPotionItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoPetPotionItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoActions = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoBuffs = ConcurrentHashMap.newKeySet();
private final List<Integer> _autoSkills = new CopyOnWriteArrayList<>();
@ -47,6 +48,11 @@ public class AutoUseSettingsHolder
return _autoPotionItems;
}
public Collection<Integer> getAutoPetPotionItems()
{
return _autoPetPotionItems;
}
public Collection<Integer> getAutoActions()
{
return _autoActions;
@ -99,6 +105,6 @@ public class AutoUseSettingsHolder
public boolean isEmpty()
{
return _autoSupplyItems.isEmpty() && _autoPotionItems.isEmpty() && _autoSkills.isEmpty() && _autoActions.isEmpty();
return _autoSupplyItems.isEmpty() && _autoPotionItems.isEmpty() && _autoPetPotionItems.isEmpty() && _autoSkills.isEmpty() && _autoActions.isEmpty();
}
}

View File

@ -39,6 +39,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
private int _nextTargetMode;
private boolean _shortRange;
private int _potionPercent;
private int _petPotionPercent;
private boolean _respectfulHunting;
@Override
@ -50,7 +51,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
_nextTargetMode = packet.readH();
_shortRange = packet.readC() == 1;
_potionPercent = packet.readD();
packet.readD(); // 272
_petPotionPercent = packet.readD(); // 272
_respectfulHunting = packet.readC() == 1;
return true;
}
@ -72,7 +73,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
return;
}
player.sendPacket(new ExAutoPlaySettingSend(_options, _active, _pickUp, _nextTargetMode, _shortRange, _potionPercent, _respectfulHunting));
player.sendPacket(new ExAutoPlaySettingSend(_options, _active, _pickUp, _nextTargetMode, _shortRange, _potionPercent, _respectfulHunting, _petPotionPercent));
player.getAutoPlaySettings().setAutoPotionPercent(_potionPercent);
if (!Config.ENABLE_AUTO_PLAY)
@ -80,7 +81,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
return;
}
final List<Integer> settings = new ArrayList<>(7);
final List<Integer> settings = new ArrayList<>(8);
settings.add(0, _options);
settings.add(1, _active ? 1 : 0);
settings.add(2, _pickUp ? 1 : 0);
@ -88,6 +89,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
settings.add(4, _shortRange ? 1 : 0);
settings.add(5, _potionPercent);
settings.add(6, _respectfulHunting ? 1 : 0);
settings.add(7, _petPotionPercent);
player.getVariables().setIntegerList(PlayerVariables.AUTO_USE_SETTINGS, settings);
player.getAutoPlaySettings().setOptions(_options);
@ -95,6 +97,7 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
player.getAutoPlaySettings().setNextTargetMode(_nextTargetMode);
player.getAutoPlaySettings().setShortRange(_shortRange);
player.getAutoPlaySettings().setRespectfulHunting(_respectfulHunting);
player.getAutoPlaySettings().setAutoPetPotionPercent(_petPotionPercent);
if (_active)
{

View File

@ -114,6 +114,7 @@ public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
else // auto potion
{
AutoUseTaskManager.getInstance().removeAutoPotionItem(player, item.getId());
AutoUseTaskManager.getInstance().removeAutoPetPotionItem(player, item.getId());
}
}
// auto skill
@ -147,12 +148,23 @@ public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
else
{
// auto potion
if ((_page == 23) && (_slot == 1))
if (_page == 23)
{
if (Config.ENABLE_AUTO_POTION && (item != null) && item.isPotion())
if (_slot == 1)
{
AutoUseTaskManager.getInstance().addAutoPotionItem(player, item.getId());
return;
if (Config.ENABLE_AUTO_POTION && (item != null) && item.isPotion())
{
AutoUseTaskManager.getInstance().addAutoPotionItem(player, item.getId());
return;
}
}
else if (_slot == 2)
{
if (Config.ENABLE_AUTO_PET_POTION && (item != null) && item.isPotion())
{
AutoUseTaskManager.getInstance().addAutoPetPotionItem(player, item.getId());
return;
}
}
}
// auto skill

View File

@ -32,8 +32,9 @@ public class ExAutoPlaySettingSend implements IClientOutgoingPacket
private final boolean _shortRange;
private final int _potionPercent;
private final boolean _respectfulHunting;
private final int _petPotionPercent;
public ExAutoPlaySettingSend(int options, boolean active, boolean pickUp, int nextTargetMode, boolean shortRange, int potionPercent, boolean respectfulHunting)
public ExAutoPlaySettingSend(int options, boolean active, boolean pickUp, int nextTargetMode, boolean shortRange, int potionPercent, boolean respectfulHunting, int petPotionPercent)
{
_options = options;
_active = active;
@ -42,6 +43,7 @@ public class ExAutoPlaySettingSend implements IClientOutgoingPacket
_shortRange = shortRange;
_potionPercent = potionPercent;
_respectfulHunting = respectfulHunting;
_petPotionPercent = petPotionPercent;
}
@Override
@ -54,7 +56,7 @@ public class ExAutoPlaySettingSend implements IClientOutgoingPacket
packet.writeH(_nextTargetMode);
packet.writeC(_shortRange ? 1 : 0);
packet.writeD(_potionPercent);
packet.writeD(0); // 272
packet.writeD(_petPotionPercent); // 272
packet.writeC(_respectfulHunting ? 1 : 0);
return true;
}

View File

@ -35,6 +35,7 @@ import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.instance.Guard;
import org.l2jmobius.gameserver.model.actor.instance.Pet;
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
import org.l2jmobius.gameserver.model.holders.AttachSkillHolder;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
@ -163,6 +164,34 @@ public class AutoUseTaskManager implements Runnable
}
}
if (Config.ENABLE_AUTO_PET_POTION && !isInPeaceZone)
{
final Pet pet = player.getPet();
if ((pet != null) && (pet.getCurrentHpPercent() <= player.getAutoPlaySettings().getAutoPetPotionPercent()))
{
POTIONS: for (Integer itemId : player.getAutoUseSettings().getAutoPetPotionItems())
{
final Item item = player.getInventory().getItemByItemId(itemId.intValue());
if (item == null)
{
player.getAutoUseSettings().getAutoPetPotionItems().remove(itemId);
continue POTIONS;
}
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_SKILL)
{
BUFFS: for (Integer skillId : player.getAutoUseSettings().getAutoBuffs())
@ -465,6 +494,18 @@ public class AutoUseTaskManager implements Runnable
stopAutoUseTask(player);
}
public void addAutoPetPotionItem(Player player, int itemId)
{
player.getAutoUseSettings().getAutoPetPotionItems().add(itemId);
startAutoUseTask(player);
}
public void removeAutoPetPotionItem(Player player, int itemId)
{
player.getAutoUseSettings().getAutoPetPotionItems().remove(itemId);
stopAutoUseTask(player);
}
public void addAutoBuff(Player player, int skillId)
{
player.getAutoUseSettings().getAutoBuffs().add(skillId);