Skip to content

Commit

Permalink
Defense Mode: Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dm94 committed Aug 10, 2023
1 parent 83455a6 commit 3a36520
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
39 changes: 27 additions & 12 deletions src/main/java/com/deeme/behaviours/defense/DefenseMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player> ships = players.stream()
.filter(Player::isValid)
.filter(s -> (defenseConfig.helpList.contains(HelpList.CLAN)
Expand All @@ -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<Player> ships) {
Expand All @@ -184,6 +195,10 @@ private Ship getTarget(List<Player> ships) {
}

private void goToMemberAttacked() {
if (!defenseConfig.goToGroup) {
return;
}

GroupMember member = SharedFunctions.getMemberGroupAttacked(group, heroapi, configApi);
if (member != null) {
movement.moveTo(member.getLocation());
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 3a36520

Please sign in to comment.