Skip to content

Commit

Permalink
siegewar - divided pillage between attackers
Browse files Browse the repository at this point in the history
* With previous code, pillage was multiplied by each soldier
* This was a little hard to work with, as the max allowed num players at flag
  often had to reduced to 1 to receive good plunder feature benefits.
* I resolve this issue by setting up plunder to be a set amount per
  tick, but DIVIDED among all soldiers at the flag
* Thus one Soldier at flag receive a nice maximum steal,
  and also if multiple Soldiers wish to score timed points together to help win a siege,
  this does not need to be limited by config.

TESTING
* Started siege PASS
* Scored timed attacker points PASS
* Stole pillage from town PASS
* Smoke testing PASS
  • Loading branch information
Goosius1 committed Mar 4, 2020
1 parent 78032ea commit cc6777e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 49 deletions.
12 changes: 7 additions & 5 deletions src/com/palmergames/bukkit/config/ConfigNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1872,8 +1872,10 @@ public enum ConfigNodes {
"war.siege.switches.pillaging_enabled",
"true",
"# If this is true, then pillaging is enabled,",
"# Pillaging represents an attacker raiding the countryside around a besieged town.",
"# If this is enabled, then with each siege point gain, an attacking soldier also steals a small amount from the town bank.",
"# Pillaging represents attackers raiding the countryside around a besieged town.",
"# If this is enabled, then with each siege war tick, attacking soldiers steal a small amount from the town bank.",
"# The pillaged amount does not vary with the number of attacking soldiers at the banner.",
"# Rather it is divided up between all the attacking soldiers.",
"# ",
"# This feature is highly recommended, because:",
"# 1. Attackers are motivated to invade territory by receiving immediate financial rewards.",
Expand Down Expand Up @@ -1906,13 +1908,13 @@ public enum ConfigNodes {
WAR_SIEGE_PILLAGE_AMOUNT_PER_PLOT(
"war.siege.money.pillage_amount_per_plot",
"0.02",
"# This value specifies how much an attacking soldier near the siege-banner pillages during each siege-war-tick.",
"# This value specifies how much attacking soldiers near the siege-banner will steal from the town during each siege-war-tick.",
"# The value should be high enough to motivate the defender to come out and fight.",
"# The value should be low enough that the pillage cap (previous config) is only hit late in the siege (if at all).",
"# An starting configuration might be calculated after assuming a total of about 10 hours of pillaging over a full 3 day siege",
"# ",
"# Example: Value 0.02. A nation attacks a size 100 town.",
"# Assume that the attacking nation uses two soldiers for each assault.",
"# These soldiers will pillage 4 gold per 20 seconds, 12 per minute. and 720 per hour from the town."),
"# The attacking soldiers will pillage 2 gold per 20 seconds, 6 per minute. 360 per hour, and 3600 over 10 hours."),
WAR_SIEGE_NATION_COST_REFUND_PERCENTAGE_ON_DELETE(
"war.siege.money.nation_cost_refund_percentage_on_delete",
"80.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private static void evaluateSiegeZone(SiegeZone siegeZone) {

int attackPointInstancesAwarded = 0;
int defencePointInstancesAwarded = 0;
List<Player> pillagingPlayers = new ArrayList<>();

//Evaluate the siege zone only if the siege is 'in progress'.
if(siegeZone.getSiege().getStatus() != SiegeStatus.IN_PROGRESS)
Expand Down Expand Up @@ -185,16 +186,7 @@ private static void evaluateSiegeZone(SiegeZone siegeZone) {

if(attackPointsAwarded) {
attackPointInstancesAwarded++;

//Pillage
double maximumPillageAmount = TownySettings.getWarSiegeMaximumPillageAmountPerPlot() * siegeZone.getDefendingTown().getTownBlocks().size();
if(TownySettings.getWarSiegePillagingEnabled()
&& TownySettings.isUsingEconomy()
&& !siegeZone.getDefendingTown().isNeutral()
&& siegeZone.getDefendingTown().getSiege().getTotalPillageAmount() < maximumPillageAmount)
{
SiegeWarMoneyUtil.pillageTown(player, siegeZone.getAttackingNation(), siegeZone.getDefendingTown());
}
pillagingPlayers.add(player);
}

} else if (defencePointInstancesAwarded <= TownySettings.getWarSiegeMaxPlayersPerSideForTimedPoints()
Expand Down Expand Up @@ -226,24 +218,25 @@ private static void evaluateSiegeZone(SiegeZone siegeZone) {

if(attackPointsAwarded) {
attackPointInstancesAwarded++;

//Pillage
double maximumPillageAmount = TownySettings.getWarSiegeMaximumPillageAmountPerPlot() * siegeZone.getDefendingTown().getTownBlocks().size();
if(TownySettings.getWarSiegePillagingEnabled()
&& TownySettings.isUsingEconomy()
&& !siegeZone.getDefendingTown().isNeutral()
&& siegeZone.getDefendingTown().getSiege().getTotalPillageAmount() < maximumPillageAmount)
{
SiegeWarMoneyUtil.pillageTown(player, siegeZone.getAttackingNation(), siegeZone.getDefendingTown());
}
pillagingPlayers.add(player);
}
}
}
}
} catch (NotRegisteredException e) {
}
}


//Pillage
double maximumPillageAmount = TownySettings.getWarSiegeMaximumPillageAmountPerPlot() * siegeZone.getDefendingTown().getTownBlocks().size();
if(TownySettings.getWarSiegePillagingEnabled()
&& TownySettings.isUsingEconomy()
&& !siegeZone.getDefendingTown().isNeutral()
&& siegeZone.getDefendingTown().getSiege().getTotalPillageAmount() < maximumPillageAmount)
{
SiegeWarMoneyUtil.pillageTown(pillagingPlayers, siegeZone.getAttackingNation(), siegeZone.getDefendingTown());
}

//Save siege zone to db if it was changed
if(attackPointInstancesAwarded > 0 || defencePointInstancesAwarded > 0) {
universe.getDataSource().saveSiegeZone(siegeZone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.palmergames.bukkit.towny.war.siegewar.locations.SiegeZone;
import org.bukkit.entity.Player;

import java.util.List;

public class SiegeWarMoneyUtil {

/**
Expand Down Expand Up @@ -87,38 +89,45 @@ public static void giveOneWarChestToWinnerTown(SiegeZone siegeZone, Town winnerT
}

/**
* This method steals money from the defending town and gives it to an attacking player
*
* @param player the attacking player
* This method steals money from the defending town and gives it to one or more attacking players
* The full steal amount is divided between all pillaging players
*
* @param pillagingPlayers the players doing the pillaging
* @param attackingNation the attacking nation
* @param defendingTown the defending town
*/
public static void pillageTown(Player player, Nation attackingNation, Town defendingTown) {
public static void pillageTown(List<Player> pillagingPlayers, Nation attackingNation, Town defendingTown) {

try {
double fullPillageAmount = TownySettings.getWarSiegePillageAmountPerPlot() * defendingTown.getTownBlocks().size();
if(pillagingPlayers.size() > 0) {
double fullPillageAmountForAllPlayers = TownySettings.getWarSiegePillageAmountPerPlot() * defendingTown.getTownBlocks().size();
double fullPillageAmountForOnePlayer = fullPillageAmountForAllPlayers / pillagingPlayers.size();

TownyUniverse universe = TownyUniverse.getInstance();
Resident pillagingResident = universe.getDataSource().getResident(player.getName());
for (Player player : pillagingPlayers) {
TownyUniverse universe = TownyUniverse.getInstance();
Resident pillagingResident = universe.getDataSource().getResident(player.getName());

if (defendingTown.getAccount().canPayFromHoldings(fullPillageAmount)) {
defendingTown.getAccount().payTo(fullPillageAmount, pillagingResident, "Town pillaged by attacker");
defendingTown.getSiege().increaseTotalPillageAmount(fullPillageAmount);
universe.getDataSource().saveResident(pillagingResident);
universe.getDataSource().saveTown(defendingTown);
} else {
double actualPillageAmount = defendingTown.getAccount().getHoldingBalance();
defendingTown.getAccount().payTo(actualPillageAmount, pillagingResident, "Towny pillaged by attacker");
defendingTown.getSiege().increaseTotalPillageAmount(actualPillageAmount);
if (defendingTown.getAccount().canPayFromHoldings(fullPillageAmountForOnePlayer)) {
defendingTown.getAccount().payTo(fullPillageAmountForOnePlayer, pillagingResident, "Town pillaged by attacker");
defendingTown.getSiege().increaseTotalPillageAmount(fullPillageAmountForOnePlayer);
universe.getDataSource().saveResident(pillagingResident);
universe.getDataSource().saveTown(defendingTown);
} else {
double actualPillageAmount = defendingTown.getAccount().getHoldingBalance();
defendingTown.getAccount().payTo(actualPillageAmount, pillagingResident, "Towny pillaged by attacker");
defendingTown.getSiege().increaseTotalPillageAmount(actualPillageAmount);

TownyMessaging.sendGlobalMessage(
String.format(
TownySettings.getLangString("msg_siege_war_town_ruined_from_pillage"),
defendingTown.getFormattedName(),
attackingNation.getFormattedName()));
TownyMessaging.sendGlobalMessage(
String.format(
TownySettings.getLangString("msg_siege_war_town_ruined_from_pillage"),
defendingTown.getFormattedName(),
attackingNation.getFormattedName()));

universe.getDataSource().saveResident(pillagingResident);
universe.getDataSource().removeTown(defendingTown);
universe.getDataSource().saveResident(pillagingResident);
universe.getDataSource().removeTown(defendingTown);
break;
}
}
}
} catch (EconomyException x) {
x.printStackTrace();
Expand Down

0 comments on commit cc6777e

Please sign in to comment.