diff --git a/src/main/java/com/deeme/modules/SentinelModule.java b/src/main/java/com/deeme/modules/SentinelModule.java index 95be5875..27dba9dd 100644 --- a/src/main/java/com/deeme/modules/SentinelModule.java +++ b/src/main/java/com/deeme/modules/SentinelModule.java @@ -48,6 +48,7 @@ import java.util.Arrays; import java.util.Collection; +import java.util.Random; import javax.swing.JComponent; import javax.swing.JLabel; @@ -89,6 +90,8 @@ public class SentinelModule implements Module, Configurable, Ins private int groupLeaderID = 0; private long randomWaitTime = 0; + private Random rnd; + private Entity oldTarget; private Location lastSentinelLocation = null; @@ -162,6 +165,8 @@ public SentinelModule(Main main, PluginAPI api, AuthAPI auth, SafetyFinder safet this.runConfigInCircle = configApi.requireConfig("loot.run_config_in_circle"); this.configRun = configApi.requireConfig("general.run"); this.configRoam = configApi.requireConfig("general.roam"); + this.rnd = new Random(); + this.oldTarget = null; setup(); } @@ -288,6 +293,7 @@ private boolean followByPortals() { if (!sConfig.followByPortals || lastSentinelLocation == null) { return false; } + Portal portal = getNearestPortal(lastSentinelLocation); if (portal != null) { if (group.hasGroup() && masterID != 0) { @@ -322,6 +328,14 @@ private GameMap getWorkingMap() { } private boolean isAttacking() { + if (this.randomWaitTime > System.currentTimeMillis()) { + return this.oldTarget != null; + } + + if (sConfig.humanizer.addRandomTime) { + this.randomWaitTime = System.currentTimeMillis() + (rnd.nextInt(sConfig.humanizer.maxRandomTime) * 1000); + } + Entity target = getSentinelTarget(); if (target == null) { @@ -337,34 +351,37 @@ private boolean isAttacking() { } if (target == null && sConfig.autoAttack.autoAttackEnemies) { - target = shipAttacker.getEnemy(sConfig.autoAttack.rangeForEnemies); + target = this.shipAttacker.getEnemy(sConfig.autoAttack.rangeForEnemies); } if (target == null && sConfig.autoAttack.defendFromNPCs) { target = SharedFunctions.getAttacker(heroapi, npcs, heroapi); } + if (target != null) { setMode(extraConfigChangerLogic.getShipMode()); if (target instanceof Npc) { - isNpc = true; + this.isNpc = true; attacker.setTarget((Npc) target); attacker.tryLockAndAttack(); } else { - isNpc = false; + this.isNpc = false; shipAttacker.setTarget((Ship) target); shipAttacker.tryLockAndAttack(); } } + this.oldTarget = target; + return target != null; } private Entity getSentinelTarget() { - if (randomWaitTime > System.currentTimeMillis()) { - return null; - } - Entity target = null; if (sentinel.getTarget() != null) { + if (this.oldTarget != null && this.oldTarget.getId() == sentinel.getTarget().getId()) { + return this.oldTarget; + } + if (sConfig.autoAttack.helpAttackPlayers || sConfig.autoAttack.helpAttackEnemyPlayers) { target = players.stream() .filter(s -> (sentinel.getTarget().getId() == s.getId()) diff --git a/src/main/java/com/deeme/types/ShipAttacker.java b/src/main/java/com/deeme/types/ShipAttacker.java index c039a2c7..f075a081 100644 --- a/src/main/java/com/deeme/types/ShipAttacker.java +++ b/src/main/java/com/deeme/types/ShipAttacker.java @@ -57,6 +57,7 @@ public class ShipAttacker { private Random rnd; private int lastAttacked; + private static final int MIN_CLICK_DELAY = 250; private boolean firstAttack; private long isAttacking; @@ -110,9 +111,10 @@ private void tryLockTarget() { lastAttacked = target.getId(); firstAttack = true; - clickDelay = System.currentTimeMillis(); if (humanizerConfig.addRandomTime) { clickDelay = System.currentTimeMillis() + (rnd.nextInt(humanizerConfig.maxRandomTime) * 1000); + } else { + clickDelay = System.currentTimeMillis() + MIN_CLICK_DELAY; } } @@ -124,7 +126,7 @@ private void tryLockTarget() { if (System.currentTimeMillis() > clickDelay) { heroapi.setLocalTarget(target); target.trySelect(false); - clickDelay = System.currentTimeMillis(); + clickDelay = System.currentTimeMillis() + MIN_CLICK_DELAY; } } else { movement.moveTo(target.getDestination().orElse(target.getLocationInfo())); @@ -285,11 +287,10 @@ public Ship getEnemy(int maxDistance, List playersToIgnore, boolean ign && (ableToAttack || s.isAttacking()) && !s.hasEffect(290) && !(s instanceof Pet) - && !(ignoreInvisible && s.isInvisible()) - && !inGroup(s.getId()) + && !(ignoreInvisible && s.isInvisible())) + .filter(s -> !inGroup(s.getId()) && movement.canMove(s) && s.getLocationInfo().distanceTo(heroapi) <= maxDistance) - .sorted(Comparator.comparingDouble(s -> s.getLocationInfo().distanceTo(heroapi))).findAny() .orElse(null); } diff --git a/src/main/resources/plugin.json b/src/main/resources/plugin.json index 28145ac1..f7c8dc4a 100644 --- a/src/main/resources/plugin.json +++ b/src/main/resources/plugin.json @@ -1,7 +1,7 @@ { "name": "DmPlugin", "author": "Dm94Dani", - "version": "2.3.3 beta 2", + "version": "2.3.3 beta 4", "minVersion": "1.131", "supportedVersion": "1.131.2", "basePackage": "com.deeme",