Support for potion auto use.
This commit is contained in:
@@ -860,6 +860,11 @@ public class PlayerInstance extends Playable
|
||||
private final Set<Integer> _whisperers = ConcurrentHashMap.newKeySet();
|
||||
|
||||
private ScheduledFuture<?> _autoPlayTask = null;
|
||||
private ScheduledFuture<?> _autoUseTask = null;
|
||||
private int _autoPotionPercent = 0;
|
||||
private final Collection<Integer> _autoSupplyItems = ConcurrentHashMap.newKeySet();
|
||||
private final Collection<Integer> _autoPotionItems = ConcurrentHashMap.newKeySet();
|
||||
private final Collection<Integer> _autoSkills = ConcurrentHashMap.newKeySet();
|
||||
|
||||
// Selling buffs system
|
||||
private boolean _isSellingBuffs = false;
|
||||
@@ -14071,8 +14076,8 @@ public class PlayerInstance extends Playable
|
||||
if ((_autoPlayTask != null) && !_autoPlayTask.isCancelled() && !_autoPlayTask.isDone())
|
||||
{
|
||||
_autoPlayTask.cancel(true);
|
||||
_autoPlayTask = null;
|
||||
}
|
||||
_autoPlayTask = null;
|
||||
}
|
||||
|
||||
public void startAutoPlayTask(boolean pickup, boolean longRange, boolean respectfulHunting)
|
||||
@@ -14157,4 +14162,127 @@ public class PlayerInstance extends Playable
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
private void stopAutoUseTask()
|
||||
{
|
||||
if ((_autoUseTask != null) && !_autoUseTask.isCancelled() && !_autoUseTask.isDone() && _autoSupplyItems.isEmpty() && _autoPotionItems.isEmpty() && _autoSkills.isEmpty())
|
||||
{
|
||||
_autoUseTask.cancel(true);
|
||||
_autoUseTask = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void startAutoUseTask()
|
||||
{
|
||||
if (_autoUseTask != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_autoUseTask = ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
if (hasBlockActions() || isControlBlocked() || isAlikeDead())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int itemId : _autoSupplyItems)
|
||||
{
|
||||
final ItemInstance item = _inventory.getItemByItemId(itemId);
|
||||
if (item == null)
|
||||
{
|
||||
removeAutoSupplyItem(itemId);
|
||||
continue;
|
||||
}
|
||||
final int reuseDelay = item.getReuseDelay();
|
||||
if ((reuseDelay <= 0) || (getItemRemainingReuseTime(item.getObjectId()) <= 0))
|
||||
{
|
||||
final EtcItem etcItem = item.getEtcItem();
|
||||
final IItemHandler handler = ItemHandler.getInstance().getHandler(etcItem);
|
||||
if ((handler != null) && handler.useItem(this, item, false) && (reuseDelay > 0))
|
||||
{
|
||||
addTimeStampItem(item, reuseDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getCurrentHpPercent() <= _autoPotionPercent)
|
||||
{
|
||||
for (int itemId : _autoPotionItems)
|
||||
{
|
||||
final ItemInstance item = _inventory.getItemByItemId(itemId);
|
||||
if (item == null)
|
||||
{
|
||||
removeAutoPotionItem(itemId);
|
||||
continue;
|
||||
}
|
||||
final int reuseDelay = item.getReuseDelay();
|
||||
if ((reuseDelay <= 0) || (getItemRemainingReuseTime(item.getObjectId()) <= 0))
|
||||
{
|
||||
final EtcItem etcItem = item.getEtcItem();
|
||||
final IItemHandler handler = ItemHandler.getInstance().getHandler(etcItem);
|
||||
if ((handler != null) && handler.useItem(this, item, false) && (reuseDelay > 0))
|
||||
{
|
||||
addTimeStampItem(item, reuseDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int skillId : _autoSkills)
|
||||
{
|
||||
final Skill skill = getKnownSkill(skillId);
|
||||
if (skill == null)
|
||||
{
|
||||
removeAutoSkill(skillId);
|
||||
continue;
|
||||
}
|
||||
if (!hasSkillReuse(skill.getReuseHashCode()))
|
||||
{
|
||||
doCast(skill);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void setAutoPotionPercent(int value)
|
||||
{
|
||||
_autoPotionPercent = value;
|
||||
}
|
||||
|
||||
public void addAutoSupplyItem(int itemId)
|
||||
{
|
||||
_autoSupplyItems.add(itemId);
|
||||
startAutoUseTask();
|
||||
}
|
||||
|
||||
public void removeAutoSupplyItem(int itemId)
|
||||
{
|
||||
_autoSupplyItems.remove(itemId);
|
||||
stopAutoUseTask();
|
||||
}
|
||||
|
||||
public void addAutoPotionItem(int itemId)
|
||||
{
|
||||
_autoPotionItems.add(itemId);
|
||||
startAutoUseTask();
|
||||
}
|
||||
|
||||
public void removeAutoPotionItem(int itemId)
|
||||
{
|
||||
_autoPotionItems.remove(itemId);
|
||||
stopAutoUseTask();
|
||||
}
|
||||
|
||||
public void addAutoSkill(int skillId)
|
||||
{
|
||||
_autoSkills.add(skillId);
|
||||
startAutoUseTask();
|
||||
}
|
||||
|
||||
public void removeAutoSkill(int skillId)
|
||||
{
|
||||
_autoSkills.remove(skillId);
|
||||
stopAutoUseTask();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ public class ExAutoPlaySetting implements IClientIncomingPacket
|
||||
|
||||
player.sendPacket(new ExAutoPlaySettingSend(_options, _active, _pickUp, _nextTargetMode, _longRange, _potionPercent, _respectfulHunting));
|
||||
|
||||
player.setAutoPotionPercent(_potionPercent);
|
||||
|
||||
if (_active)
|
||||
{
|
||||
player.startAutoPlayTask(_pickUp, _longRange, _respectfulHunting);
|
||||
|
||||
@@ -20,12 +20,13 @@ import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.gameserver.model.Shortcut;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
import org.l2jmobius.gameserver.model.skills.Skill;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.autoplay.ExActivateAutoShortcut;
|
||||
|
||||
/**
|
||||
* @author JoeAlisson
|
||||
* @author JoeAlisson, Mobius
|
||||
*/
|
||||
public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
|
||||
{
|
||||
@@ -49,36 +50,70 @@ public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
|
||||
return;
|
||||
}
|
||||
|
||||
final int slot = _room % 12;
|
||||
final int page = _room / 12;
|
||||
final Shortcut shortcut = player.getShortCut(slot, page);
|
||||
if (shortcut == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
client.sendPacket(new ExActivateAutoShortcut(_room, _activate));
|
||||
|
||||
final ItemInstance item = player.getInventory().getItemByObjectId(shortcut.getId());
|
||||
Skill skill = null;
|
||||
if (item == null)
|
||||
{
|
||||
skill = player.getKnownSkill(shortcut.getId());
|
||||
}
|
||||
|
||||
// stop
|
||||
if (!_activate)
|
||||
{
|
||||
client.sendPacket(new ExActivateAutoShortcut(_room, _activate));
|
||||
if (item != null)
|
||||
{
|
||||
// auto supply
|
||||
if (_room == -1)
|
||||
{
|
||||
player.removeAutoSupplyItem(item.getId());
|
||||
}
|
||||
else // auto potion
|
||||
{
|
||||
player.removeAutoPotionItem(item.getId());
|
||||
}
|
||||
}
|
||||
// TODO: auto skill
|
||||
if (skill != null)
|
||||
{
|
||||
player.removeAutoSkill(skill.getId());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// start
|
||||
if (_room == -1)
|
||||
{
|
||||
// TODO: auto supply
|
||||
client.sendPacket(new ExActivateAutoShortcut(_room, _activate));
|
||||
// auto supply
|
||||
if (item != null)
|
||||
{
|
||||
player.addAutoSupplyItem(item.getId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final int slot = _room % 12;
|
||||
final int page = _room / 12;
|
||||
final Shortcut shortcut = player.getShortCut(slot, page);
|
||||
if (shortcut != null)
|
||||
// auto potion
|
||||
if ((page == 23) && (slot == 1))
|
||||
{
|
||||
if ((page == 23) && (slot == 1))
|
||||
if ((item != null) && item.isPotion())
|
||||
{
|
||||
// auto potion
|
||||
final ItemInstance item = player.getInventory().getItemByObjectId(shortcut.getId());
|
||||
if ((item == null) || !item.isPotion())
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.addAutoPotionItem(item.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: auto skill
|
||||
client.sendPacket(new ExActivateAutoShortcut(_room, _activate));
|
||||
}
|
||||
// TODO: auto skill
|
||||
if (skill != null)
|
||||
{
|
||||
player.addAutoSkill(skill.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user