feat: sieges capture progress scaling

This commit is contained in:
darksaid98 committed 2023-07-31 23:36:44 +02:00
1 parent f6d67221d5
commit 3dfb8026a9
2 files changed
+77 -45

No files matched your search

@@ -33,7 +33,7 @@ import java.util.stream.Stream;
public class Siege extends Battle {
public static final Duration SIEGE_DURATION = Duration.ofMinutes(60);
public static final int MAX_SIEGE_PROGRESS_MINUTES = 8; // How many minutes attackers will need to be on point uncontested for to reach 100%
public static final int MAX_SIEGE_PROGRESS = 60 * MAX_SIEGE_PROGRESS_MINUTES; // On reaching this, the attackers win. 1 point is added per second
public static final int MAX_SIEGE_PROGRESS = 60 * 10 * MAX_SIEGE_PROGRESS_MINUTES; // On reaching this, the attackers win. 10 points is added per second
public static final Duration ATTACKERS_MUST_TOUCH_END = Duration.ofMinutes(40); // If point is not touched in this much time, defenders win
public static final Duration ATTACKERS_MUST_TOUCH_REVERT = Duration.ofMinutes(2); // If point is not touched in this much time, siege progress begins reverting
public static final int BATTLEFIELD_RANGE = 500;
@@ -233,6 +233,11 @@ public class Siege extends Battle {
}
public void setSiegeProgress(int siegeProgress) {
if (siegeProgress < 0) {
siegeProgress = 0;
} else if (siegeProgress > MAX_SIEGE_PROGRESS) {
siegeProgress = MAX_SIEGE_PROGRESS;
}
this.siegeProgress = siegeProgress;
}
@@ -289,28 +294,34 @@ public class Siege extends Battle {
p.showBossBar(activeBossBar);
}
String color = "<yellow>";
switch (progressDirection) {
final String color = switch (progressDirection) {
case UP -> {
if (getAttackerSide().getSide().equals(BattleSide.ATTACKER)) {
activeBossBar.color(BossBar.Color.RED);
color = "<red>";
yield "<red>";
} else {
activeBossBar.color(BossBar.Color.BLUE);
color = "<blue>";
yield "<blue>";
}
}
case CONTESTED, UNCONTESTED -> activeBossBar.color(BossBar.Color.YELLOW);
case CONTESTED -> {
activeBossBar.color(BossBar.Color.YELLOW);
yield "<yellow>";
}
case UNCONTESTED -> {
activeBossBar.color(BossBar.Color.WHITE);
yield "<white>";
}
case DOWN -> {
if (getAttackerSide().getSide().equals(BattleSide.ATTACKER)) {
activeBossBar.color(BossBar.Color.BLUE);
color = "<blue>";
yield "<blue>";
} else {
activeBossBar.color(BossBar.Color.RED);
color = "<red>";
yield "<red>";
}
}
}
};
if (Instant.now().isBefore(getEndTime())) {
activeBossBar.name(
@@ -18,16 +18,16 @@ import java.time.Duration;
import java.time.Instant;
import static com.github.alathra.AlathranWars.conflict.battle.siege.Siege.*;
import static com.github.alathra.AlathranWars.enums.CaptureProgressDirection.*;
public class SiegeRunnable implements Runnable {
// Settings
private static final Duration ANNOUNCEMENT_COOLDOWN = Duration.ofMinutes(5);
private final static int CAPTURE_MAX_ELEVATION = 10;
private final static int CAPTURE_RANGE = 10;
private final @NotNull Siege siege;
// Variables
private @NotNull CaptureProgressDirection oldProgressDirection = CaptureProgressDirection.UNCONTESTED;
private @NotNull CaptureProgressDirection oldProgressDirection = UNCONTESTED;
private Instant nextAnnouncement;
private ScheduledTask task;
private @Nullable Laser beam;
@@ -49,7 +49,7 @@ public class SiegeRunnable implements Runnable {
task = Main.getPaperLib().scheduling().globalRegionalScheduler().runAtFixedRate(this, 0L, 20L);
siege.updateDisplayBar(CaptureProgressDirection.CONTESTED);
siege.updateDisplayBar(CONTESTED);
}
/**
@@ -70,7 +70,7 @@ public class SiegeRunnable implements Runnable {
task = Main.getPaperLib().scheduling().globalRegionalScheduler().runAtFixedRate(this, 0L, 20L);
siege.updateDisplayBar(CaptureProgressDirection.CONTESTED);
siege.updateDisplayBar(CONTESTED);
}
public void cancel() {
@@ -99,11 +99,13 @@ public class SiegeRunnable implements Runnable {
siege.calculateBattlefieldPlayers(townSpawn.toCenterLocation());
// Progress the siege
final @NotNull CaptureProgressDirection progressDirection = getSiegeProgressDirection(townSpawn);
final int attackersOnPoint = getPeopleOnPoint(townSpawn, BattleSide.ATTACKER);
final int defendersOnPoint = getPeopleOnPoint(townSpawn, BattleSide.DEFENDER);
final @NotNull CaptureProgressDirection progressDirection = getSiegeProgressDirection(attackersOnPoint, defendersOnPoint);
// Siege is past max time or attackers haven't touched in time, defenders won
if (
(!progressDirection.equals(CaptureProgressDirection.CONTESTED) && !progressDirection.equals(CaptureProgressDirection.UP)) &&
(!progressDirection.equals(CONTESTED) && !progressDirection.equals(UP)) &&
(Instant.now().isAfter(siege.getEndTime()) ||
Instant.now().isAfter(siege.getLastTouched().plus(ATTACKERS_MUST_TOUCH_END)))
) {
@@ -120,35 +122,52 @@ public class SiegeRunnable implements Runnable {
}
switch (progressDirection) {
case UP -> siege.setSiegeProgress(siege.getSiegeProgress() + 1);
case DOWN -> siege.setSiegeProgress(siege.getSiegeProgress() - 1);
case UP -> {
final int playerOnPointDiff = attackersOnPoint - defendersOnPoint;
// If you have less than 5 people contesting you get (4 + excessPlayers) points per second
if (playerOnPointDiff < 5) {
siege.setSiegeProgress(siege.getSiegeProgress() + (4 + playerOnPointDiff));
} else {
siege.setSiegeProgress(siege.getSiegeProgress() + 10);
}
}
case DOWN -> siege.setSiegeProgress(siege.getSiegeProgress() - 10);
}
if (oldProgressDirection != progressDirection) {
switch (progressDirection) {
case UP -> siege.getPlayersOnBattlefield().forEach(p -> p.sendMessage(
ColorParser.of("<prefix>The Attackers are capturing the home block.")
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
.build()
));
case CONTESTED, UNCONTESTED -> {
/*if ()
siege.getAttackers().forEach(p -> p.sendMessage(
ColorParser.of("<prefix>The home block is being contested.")
case UP -> {
siege.getPlayersOnBattlefield().forEach(p -> p.sendMessage(
ColorParser.of("<prefix>The Attackers are capturing the home block.")
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
.build()
));
siege.getDefenders().forEach(p -> p.sendMessage(
ColorParser.of("<prefix>The home block is being contested.")
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
.build()
));*/
}
case DOWN -> siege.getPlayersOnBattlefield().forEach(p -> p.sendMessage(
ColorParser.of("<prefix>The Defenders re-secured the home block.")
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
.build()
));
case CONTESTED -> {
if (oldProgressDirection.equals(UNCONTESTED))
siege.getPlayersOnBattlefield().forEach(p -> p.sendMessage(
ColorParser.of("<prefix>The home block is being contested.")
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
.build()
));
}
case UNCONTESTED -> {
if (oldProgressDirection.equals(UP) || oldProgressDirection.equals(CONTESTED) || oldProgressDirection.equals(DOWN))
siege.getPlayersOnBattlefield().forEach(p -> p.sendMessage(
ColorParser.of("<prefix>The home block is no longer being contested.")
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
.build()
));
}
case DOWN -> {
if (oldProgressDirection.equals(UP) || oldProgressDirection.equals(CONTESTED))
siege.getPlayersOnBattlefield().forEach(p -> p.sendMessage(
ColorParser.of("<prefix>The Defenders re-secured the home block.")
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
.build()
));
}
}
}
@@ -185,9 +204,7 @@ public class SiegeRunnable implements Runnable {
return onPoint;
}
public @NotNull CaptureProgressDirection getSiegeProgressDirection(@NotNull Location townSpawn) {
int attackersOnPoint = getPeopleOnPoint(townSpawn, BattleSide.ATTACKER);
int defendersOnPoint = getPeopleOnPoint(townSpawn, BattleSide.DEFENDER);
public @NotNull CaptureProgressDirection getSiegeProgressDirection(int attackersOnPoint, int defendersOnPoint) {
final boolean attackersAreOnPoint = attackersOnPoint > 0;
final boolean defendersAreOnPoint = defendersOnPoint > 0;
@@ -195,21 +212,25 @@ public class SiegeRunnable implements Runnable {
siege.setLastTouched(Instant.now());
if (attackersAreOnPoint && defendersAreOnPoint) {
return CaptureProgressDirection.CONTESTED;
if (attackersOnPoint > defendersOnPoint)
return UP;
return CONTESTED;
} else if (attackersAreOnPoint && !defendersAreOnPoint) {
if (siege.getSiegeProgress() == MAX_SIEGE_PROGRESS)
return CaptureProgressDirection.CONTESTED;
return CONTESTED;
return CaptureProgressDirection.UP;
return UP;
} else {
if (siege.getSiegeProgress() == 0)
return CaptureProgressDirection.UNCONTESTED;
return UNCONTESTED;
// If the attackers haven't touched in a while, begin reverting progress
if (Instant.now().isAfter(siege.getLastTouched().plus(ATTACKERS_MUST_TOUCH_REVERT))) {
return CaptureProgressDirection.DOWN;
return DOWN;
} else {
return CaptureProgressDirection.UNCONTESTED;
return UNCONTESTED;
}
}
}