From 3a365202f09a85d91a4933c003c73b9b061613ed Mon Sep 17 00:00:00 2001 From: dm94 Date: Thu, 10 Aug 2023 19:28:38 +0200 Subject: [PATCH] Defense Mode: Refactor --- .../deeme/behaviours/defense/DefenseMode.java | 39 +++++++++++++------ src/main/resources/plugin.json | 2 +- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/deeme/behaviours/defense/DefenseMode.java b/src/main/java/com/deeme/behaviours/defense/DefenseMode.java index e5f5e2ed..08f2832c 100644 --- a/src/main/java/com/deeme/behaviours/defense/DefenseMode.java +++ b/src/main/java/com/deeme/behaviours/defense/DefenseMode.java @@ -129,21 +129,21 @@ private boolean inGroupAttacked(int id) { } private boolean isUnderAttack() { + goToMemberAttacked(); + + return hasPreviusTarget() || hasAttacker() || friendUnderAttack(); + } + + private boolean hasPreviusTarget() { if (target != null && target.isValid() && target.getId() != heroapi.getId() && target.getLocationInfo().distanceTo(heroapi) < 2000) { return true; } - if (defenseConfig.respondAttacks) { - target = SharedFunctions.getAttacker(heroapi, players, heroapi); - if (target != null && target.isValid()) { - if (!getIgnoredPlayers().contains(target.getId())) { - return true; - } - target = null; - } - } + return false; + } + private boolean friendUnderAttack() { List ships = players.stream() .filter(Player::isValid) .filter(s -> (defenseConfig.helpList.contains(HelpList.CLAN) @@ -157,11 +157,22 @@ private boolean isUnderAttack() { target = getTarget(ships); - if (defenseConfig.goToGroup) { - goToMemberAttacked(); + return target != null && target.isValid(); + } + + private boolean hasAttacker() { + if (!defenseConfig.respondAttacks) { + return false; } - return target != null && target.isValid(); + target = SharedFunctions.getAttacker(heroapi, players, heroapi); + if (target != null && target.isValid()) { + if (!getIgnoredPlayers().contains(target.getId())) { + return true; + } + target = null; + } + return false; } private Ship getTarget(List ships) { @@ -184,6 +195,10 @@ private Ship getTarget(List ships) { } private void goToMemberAttacked() { + if (!defenseConfig.goToGroup) { + return; + } + GroupMember member = SharedFunctions.getMemberGroupAttacked(group, heroapi, configApi); if (member != null) { movement.moveTo(member.getLocation()); diff --git a/src/main/resources/plugin.json b/src/main/resources/plugin.json index 3b95e56a..ed0d3ee9 100644 --- a/src/main/resources/plugin.json +++ b/src/main/resources/plugin.json @@ -1,7 +1,7 @@ { "name": "DmPlugin", "author": "Dm94Dani", - "version": "2.0.2", + "version": "2.0.2 beta 2", "minVersion": "1.120", "supportedVersion": "1.127", "basePackage": "com.deeme",