Skip to content

Commit

Permalink
Fix the direction of the threshold to actually match the way SW works.
Browse files Browse the repository at this point in the history
Add the ability to determine the future points balance while mid-battle
session.
  • Loading branch information
LlmDl committed Aug 6, 2024
1 parent f607dda commit 0cbcdb6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.gmail.goosius.siegewar.objects.Siege;
import com.gmail.goosius.siegewar.settings.SiegeWarSettings;
import com.gmail.goosius.siegewar.tasks.SiegeWarTimerTaskController;
import com.gmail.goosius.siegewar.utils.SiegeWarBattleSessionUtil;
import com.gmail.goosius.siegewar.utils.SiegeWarBlockProtectionUtil;
import com.gmail.goosius.siegewar.utils.SiegeWarBlockUtil;
import com.gmail.goosius.siegewar.utils.SiegeWarDistanceUtil;
Expand Down Expand Up @@ -472,7 +473,8 @@ public void onTownyKeepInventoryEvent(PlayerKeepsInventoryEvent event) {
Siege siege = SiegeWarAPI.getActiveSiegeAtLocation(event.getLocation());
if (!SiegeSide.isDefender(siege, event.getPlayer()))
return;
if (siege.getSiegeBalance() > SiegeWarSettings.getDefendersDropInventoryWhenLosingThreshold())
if (SiegeWarBattleSessionUtil.getSiegeBalanceIfSessionEndedNow(siege)
< SiegeWarSettings.getDefendersDropInventoryWhenLosingThreshold())
return;

event.setCancelled(true);
Expand All @@ -487,7 +489,7 @@ public void onTownyKeepInventoryEvent(PlayerKeepsInventoryEvent event) {
// But we don't want defenders that are losing too greatly to keep their inventories.
if (SiegeWarSettings.isDefendersDropInventoryWhenLosingEnabled()
&& SiegeSide.isDefender(siege, event.getPlayer())
&& siege.getSiegeBalance() <= SiegeWarSettings.getDefendersDropInventoryWhenLosingThreshold())
&& SiegeWarBattleSessionUtil.getSiegeBalanceIfSessionEndedNow(siege) >= SiegeWarSettings.getDefendersDropInventoryWhenLosingThreshold())
return;

SiegeWarInventoryUtil.degradeInventory(event.getPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,9 @@ public enum ConfigNodes {
"# ie: They defenders are losing by a great number."),
KEEP_INVENTORY_ON_SIEGEZONE_DEATH_DISABLE_FOR_DEFENDERS_THRESHOLD(
"keep_inventory_on_siegezone_death.disable_for_defenders.threshold",
"-500",
"500",
"",
"# The threshold required to cause defenders to lose their inventory. If the Siege point balance is equal to or lower than this number",
"# The threshold required to cause defenders to lose their inventory. If the Siege point balance is equal to or greater than this number",
"# and disable_for_defenders is enabled, defenders will not keep their inventories."),

SPECIAL_VICTORY_EFFECTS(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ private static void unjailPlayers(Nation attacker, Town defender) {
Messaging.sendGlobalMessage(Translatable.of("msg_attackers_have_triggered_a_jail_break_freeing", StringMgmt.join(freedNames, ", ")));
}

public static int getSiegeBalanceIfSessionEndedNow(Siege siege) {
int siegeBalanceAdjustment = calculateSiegeBalanceAdjustment(siege);
int futureBalance = siege.getSiegeBalance() + siegeBalanceAdjustment;
if(SiegeWarSettings.getSiegeBalanceCapValue() != -1) {
futureBalance = Math.min(futureBalance, SiegeWarSettings.getSiegeBalanceCapValue());
}
return futureBalance;
}

public static void evaluateBattleSessions() {
BattleSession battleSession = BattleSession.getBattleSession();

Expand Down

0 comments on commit 0cbcdb6

Please sign in to comment.