Update auto settings while task is active.

This commit is contained in:
MobiusDevelopment
2020-04-27 11:21:44 +00:00
parent 0cecbec5c5
commit 8fd9611c92
2 changed files with 28 additions and 12 deletions

View File

@@ -38,6 +38,7 @@ import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -862,7 +863,10 @@ public class PlayerInstance extends Playable
private ScheduledFuture<?> _autoPlayTask = null; private ScheduledFuture<?> _autoPlayTask = null;
private ScheduledFuture<?> _autoUseTask = null; private ScheduledFuture<?> _autoUseTask = null;
private int _autoPotionPercent = 0; private final AtomicBoolean _pickup = new AtomicBoolean();
private final AtomicBoolean _longRange = new AtomicBoolean();
private final AtomicBoolean _respectfulHunting = new AtomicBoolean();
private final AtomicInteger _autoPotionPercent = new AtomicInteger();
private final Collection<Integer> _autoSupplyItems = ConcurrentHashMap.newKeySet(); private final Collection<Integer> _autoSupplyItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoPotionItems = ConcurrentHashMap.newKeySet(); private final Collection<Integer> _autoPotionItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoSkills = ConcurrentHashMap.newKeySet(); private final Collection<Integer> _autoSkills = ConcurrentHashMap.newKeySet();
@@ -14068,6 +14072,10 @@ public class PlayerInstance extends Playable
public void startAutoPlayTask(boolean pickup, boolean longRange, boolean respectfulHunting) public void startAutoPlayTask(boolean pickup, boolean longRange, boolean respectfulHunting)
{ {
_pickup.set(pickup);
_longRange.set(longRange);
_respectfulHunting.set(respectfulHunting);
if (_autoPlayTask != null) if (_autoPlayTask != null)
{ {
return; return;
@@ -14088,7 +14096,7 @@ public class PlayerInstance extends Playable
} }
// Pickup. // Pickup.
if (pickup) if (_pickup.get())
{ {
for (ItemInstance droppedItem : World.getInstance().getVisibleObjectsInRange(this, ItemInstance.class, 200)) for (ItemInstance droppedItem : World.getInstance().getVisibleObjectsInRange(this, ItemInstance.class, 200))
{ {
@@ -14119,7 +14127,7 @@ public class PlayerInstance extends Playable
// Find target. // Find target.
MonsterInstance monster = null; MonsterInstance monster = null;
double closestDistance = Double.MAX_VALUE; double closestDistance = Double.MAX_VALUE;
for (MonsterInstance nearby : World.getInstance().getVisibleObjectsInRange(this, MonsterInstance.class, longRange ? 1400 : 600)) for (MonsterInstance nearby : World.getInstance().getVisibleObjectsInRange(this, MonsterInstance.class, _longRange.get() ? 1400 : 600))
{ {
// Skip unavailable monsters. // Skip unavailable monsters.
if ((nearby == null) || nearby.isAlikeDead()) if ((nearby == null) || nearby.isAlikeDead())
@@ -14127,7 +14135,7 @@ public class PlayerInstance extends Playable
continue; continue;
} }
// Check monster target. // Check monster target.
if (respectfulHunting && (nearby.getTarget() != null) && (nearby.getTarget() != this)) if (_respectfulHunting.get() && (nearby.getTarget() != null) && (nearby.getTarget() != this))
{ {
continue; continue;
} }
@@ -14200,7 +14208,7 @@ public class PlayerInstance extends Playable
} }
} }
if (Config.ENABLE_AUTO_POTION && (getCurrentHpPercent() <= _autoPotionPercent)) if (Config.ENABLE_AUTO_POTION && (getCurrentHpPercent() <= _autoPotionPercent.get()))
{ {
for (int itemId : _autoPotionItems) for (int itemId : _autoPotionItems)
{ {
@@ -14244,7 +14252,7 @@ public class PlayerInstance extends Playable
public void setAutoPotionPercent(int value) public void setAutoPotionPercent(int value)
{ {
_autoPotionPercent = value; _autoPotionPercent.set(value);
} }
public void addAutoSupplyItem(int itemId) public void addAutoSupplyItem(int itemId)

View File

@@ -39,6 +39,7 @@ import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -859,7 +860,10 @@ public class PlayerInstance extends Playable
private ScheduledFuture<?> _autoPlayTask = null; private ScheduledFuture<?> _autoPlayTask = null;
private ScheduledFuture<?> _autoUseTask = null; private ScheduledFuture<?> _autoUseTask = null;
private int _autoPotionPercent = 0; private final AtomicBoolean _pickup = new AtomicBoolean();
private final AtomicBoolean _longRange = new AtomicBoolean();
private final AtomicBoolean _respectfulHunting = new AtomicBoolean();
private final AtomicInteger _autoPotionPercent = new AtomicInteger();
private final Collection<Integer> _autoSupplyItems = ConcurrentHashMap.newKeySet(); private final Collection<Integer> _autoSupplyItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoPotionItems = ConcurrentHashMap.newKeySet(); private final Collection<Integer> _autoPotionItems = ConcurrentHashMap.newKeySet();
private final Collection<Integer> _autoSkills = ConcurrentHashMap.newKeySet(); private final Collection<Integer> _autoSkills = ConcurrentHashMap.newKeySet();
@@ -14015,6 +14019,10 @@ public class PlayerInstance extends Playable
public void startAutoPlayTask(boolean pickup, boolean longRange, boolean respectfulHunting) public void startAutoPlayTask(boolean pickup, boolean longRange, boolean respectfulHunting)
{ {
_pickup.set(pickup);
_longRange.set(longRange);
_respectfulHunting.set(respectfulHunting);
if (_autoPlayTask != null) if (_autoPlayTask != null)
{ {
return; return;
@@ -14035,7 +14043,7 @@ public class PlayerInstance extends Playable
} }
// Pickup. // Pickup.
if (pickup) if (_pickup.get())
{ {
for (ItemInstance droppedItem : World.getInstance().getVisibleObjectsInRange(this, ItemInstance.class, 200)) for (ItemInstance droppedItem : World.getInstance().getVisibleObjectsInRange(this, ItemInstance.class, 200))
{ {
@@ -14066,7 +14074,7 @@ public class PlayerInstance extends Playable
// Find target. // Find target.
MonsterInstance monster = null; MonsterInstance monster = null;
double closestDistance = Double.MAX_VALUE; double closestDistance = Double.MAX_VALUE;
for (MonsterInstance nearby : World.getInstance().getVisibleObjectsInRange(this, MonsterInstance.class, longRange ? 1400 : 600)) for (MonsterInstance nearby : World.getInstance().getVisibleObjectsInRange(this, MonsterInstance.class, _longRange.get() ? 1400 : 600))
{ {
// Skip unavailable monsters. // Skip unavailable monsters.
if ((nearby == null) || nearby.isAlikeDead()) if ((nearby == null) || nearby.isAlikeDead())
@@ -14074,7 +14082,7 @@ public class PlayerInstance extends Playable
continue; continue;
} }
// Check monster target. // Check monster target.
if (respectfulHunting && (nearby.getTarget() != null) && (nearby.getTarget() != this)) if (_respectfulHunting.get() && (nearby.getTarget() != null) && (nearby.getTarget() != this))
{ {
continue; continue;
} }
@@ -14147,7 +14155,7 @@ public class PlayerInstance extends Playable
} }
} }
if (Config.ENABLE_AUTO_POTION && (getCurrentHpPercent() <= _autoPotionPercent)) if (Config.ENABLE_AUTO_POTION && (getCurrentHpPercent() <= _autoPotionPercent.get()))
{ {
for (int itemId : _autoPotionItems) for (int itemId : _autoPotionItems)
{ {
@@ -14191,7 +14199,7 @@ public class PlayerInstance extends Playable
public void setAutoPotionPercent(int value) public void setAutoPotionPercent(int value)
{ {
_autoPotionPercent = value; _autoPotionPercent.set(value);
} }
public void addAutoSupplyItem(int itemId) public void addAutoSupplyItem(int itemId)