Skip to content

Commit cefb748

Browse files
committed
Charge reparations to every payer guild
1 parent e725575 commit cefb748

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

‎src/main/java/net/tfminecraft/simplefactions/guild/income/Ledger.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,6 @@ public double getIncome(Cashflow cashflow) {
297297
amount = getWarReparationsReceived();
298298
break;
299299
case WAR_REPARATIONS_PAYMENT:
300-
if (!guild.isBase()) {
301-
return 0;
302-
}
303300
amount = -getWarReparationsPayment();
304301
break;
305302
// No isBase() guard: the guild whose tables won declares it, and the capital picks its

‎src/test/java/net/tfminecraft/simplefactions/guild/income/WarReparationsLedgerTest.java‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,39 +49,50 @@ void payerMainGuild_paymentIsNegativePercentOfGross() {
4949
FactionManager.factions.add(payee);
5050

5151
Guild payerGuild = mockGuild(payer, true, 200.0);
52+
payerGuild.getTradeBreakdown().setUpkeep(125.0);
5253
when(payer.getOrCreateMainGuild()).thenReturn(payerGuild);
5354
Ledger ledger = new Ledger(payerGuild);
5455

5556
assertEquals(-50.0, ledger.getIncome(Cashflow.WAR_REPARATIONS_PAYMENT));
5657
}
5758

5859
@Test
59-
void payeeMainGuild_incomeIsPositiveFromPayerGross() {
60+
void payeeMainGuild_receivesDirectlyFromAllGuildsInPayerVassalTree() {
6061
Faction payer = mockFaction("atk");
62+
Faction vassal = mockFaction("vassal");
6163
Faction payee = mockFaction("def");
6264
when(payer.getWarReparationsObligations()).thenReturn(List.of(
6365
new WarReparationsObligation("def", 25, 10)));
66+
when(vassal.getWarReparationsObligations()).thenReturn(List.of(
67+
new WarReparationsObligation("def", 25, 10)));
6468
when(payee.getWarReparationsObligations()).thenReturn(List.of());
6569
FactionManager.factions.add(payer);
70+
FactionManager.factions.add(vassal);
6671
FactionManager.factions.add(payee);
6772

6873
Guild payerGuild = mockGuild(payer, true, 200.0);
74+
Guild payerBranch = mockGuild(payer, false, 80.0);
75+
Guild vassalMainGuild = mockGuild(vassal, true, 120.0);
6976
Guild payeeGuild = mockGuild(payee, true, 0.0);
7077
when(payer.getOrCreateMainGuild()).thenReturn(payerGuild);
7178
when(payee.getOrCreateMainGuild()).thenReturn(payeeGuild);
79+
when(payer.getGuildHandler().getGuilds()).thenReturn(List.of(payerGuild, payerBranch));
80+
when(vassal.getGuildHandler().getGuilds()).thenReturn(List.of(vassalMainGuild));
7281

7382
Ledger payeeLedger = new Ledger(payeeGuild);
74-
assertEquals(50.0, payeeLedger.getIncome(Cashflow.WAR_REPARATIONS));
83+
assertEquals(100.0, payeeLedger.getIncome(Cashflow.WAR_REPARATIONS));
84+
assertEquals(-20.0, payerBranch.getLedger().getIncome(Cashflow.WAR_REPARATIONS_PAYMENT));
85+
assertEquals(-30.0, vassalMainGuild.getLedger().getIncome(Cashflow.WAR_REPARATIONS_PAYMENT));
7586
}
7687

7788
@Test
78-
void subsidiaryGuild_reparationsAreZero() {
89+
void subsidiaryGuild_paysFromItsOwnGrossTrade() {
7990
Faction payer = mockFaction("atk");
8091
when(payer.getWarReparationsObligations()).thenReturn(List.of(
8192
new WarReparationsObligation("def", 25, 10)));
8293
Guild sub = mockGuild(payer, false, 200.0);
8394
Ledger ledger = new Ledger(sub);
84-
assertEquals(0.0, ledger.getIncome(Cashflow.WAR_REPARATIONS_PAYMENT));
95+
assertEquals(-50.0, ledger.getIncome(Cashflow.WAR_REPARATIONS_PAYMENT));
8596
assertEquals(0.0, ledger.getIncome(Cashflow.WAR_REPARATIONS));
8697
}
8798

@@ -102,6 +113,7 @@ void tributeAndReparationsTogether_doNotRecursivelyOverflow() {
102113
Guild suzerainGuild = mockGuild(suzerain, true, 0.0);
103114
when(tributary.getOrCreateMainGuild()).thenReturn(tributaryGuild);
104115
when(suzerain.getOrCreateMainGuild()).thenReturn(suzerainGuild);
116+
when(tributary.getGuildHandler().getGuilds()).thenReturn(List.of(tributaryGuild));
105117

106118
Ledger suzerainLedger = new Ledger(suzerainGuild);
107119
Ledger tributaryLedger = new Ledger(tributaryGuild);

0 commit comments

Comments
 (0)