|
9 | 9 | import net.tfminecraft.simplefactions.guild.GuildModifierOverride; |
10 | 10 | import net.tfminecraft.simplefactions.guild.branch.Branch; |
11 | 11 | import net.tfminecraft.simplefactions.guild.branch.BranchModifier; |
| 12 | +import net.tfminecraft.simplefactions.managers.FactionManager; |
12 | 13 | import net.tfminecraft.simplefactions.managers.ProvinceManager; |
| 14 | +import net.tfminecraft.simplefactions.managers.RelationManager; |
13 | 15 | import net.tfminecraft.simplefactions.objects.Faction; |
14 | 16 |
|
15 | 17 | /** |
@@ -65,6 +67,29 @@ public static double estimate( |
65 | 67 | return Math.round(net * 100.0) / 100.0; |
66 | 68 | } |
67 | 69 |
|
| 70 | + /** |
| 71 | + * The realm guild's infrastructure reaches every guild in the realm, so an |
| 72 | + * up or down of that branch is their incomes added together. |
| 73 | + */ |
| 74 | + public static boolean showsRealm(Guild guild, Branch branch) { |
| 75 | + return guild != null |
| 76 | + && guild.isBase() |
| 77 | + && branch != null |
| 78 | + && branch.getModifier(GuildModifier.INFRASTRUCTURE) != null; |
| 79 | + } |
| 80 | + |
| 81 | + public static double estimateRealm( |
| 82 | + Prepared prepared, |
| 83 | + Guild realmGuild, |
| 84 | + Map<GuildModifier, Double> current, |
| 85 | + Map<GuildModifier, Double> hypothetical) { |
| 86 | + double before = realmIncome(prepared, realmGuild, current); |
| 87 | + double after = realmIncome(prepared, realmGuild, hypothetical); |
| 88 | + double upkeepChange = Math.max(0.0, hypothetical.getOrDefault(GuildModifier.INFRASTRUCTURE_UPKEEP, 0.0)) |
| 89 | + - Math.max(0.0, current.getOrDefault(GuildModifier.INFRASTRUCTURE_UPKEEP, 0.0)); |
| 90 | + return Math.round((after - before - upkeepChange) * 100.0) / 100.0; |
| 91 | + } |
| 92 | + |
68 | 93 | public static Map<GuildModifier, Double> modifiers(Guild guild) { |
69 | 94 | EnumMap<GuildModifier, Double> amounts = new EnumMap<>(GuildModifier.class); |
70 | 95 | for (GuildModifier modifier : GuildModifier.values()) { |
@@ -105,6 +130,39 @@ private static ProvinceManager copy(ProvinceManager source) { |
105 | 130 | return snapshot; |
106 | 131 | } |
107 | 132 |
|
| 133 | + private static double realmIncome( |
| 134 | + Prepared prepared, Guild realmGuild, Map<GuildModifier, Double> amounts) { |
| 135 | + ProvinceManager snapshot = copy(prepared.snapshot); |
| 136 | + GuildModifierOverride.use(realmGuild, amounts); |
| 137 | + try { |
| 138 | + snapshot.recalculateQuiet(); |
| 139 | + double sum = 0; |
| 140 | + Faction realm = realmGuild.getFaction(); |
| 141 | + for (Guild guild : FactionManager.getAllGuilds()) { |
| 142 | + if (guild == null || !sameRealm(realm, guild.getFaction())) { |
| 143 | + continue; |
| 144 | + } |
| 145 | + sum += snapshot.getIncome(guild, false) * (1.0 - taxFraction(guild)); |
| 146 | + } |
| 147 | + return sum; |
| 148 | + } finally { |
| 149 | + GuildModifierOverride.clear(); |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + private static boolean sameRealm(Faction realm, Faction guildFaction) { |
| 154 | + if (realm == null || guildFaction == null) { |
| 155 | + return false; |
| 156 | + } |
| 157 | + if (realm == guildFaction) { |
| 158 | + return true; |
| 159 | + } |
| 160 | + if (realm.getId() != null && realm.getId().equalsIgnoreCase(guildFaction.getId())) { |
| 161 | + return true; |
| 162 | + } |
| 163 | + return RelationManager.sameRealm(realm, guildFaction); |
| 164 | + } |
| 165 | + |
108 | 166 | private static double income(ProvinceManager snapshot, Guild guild, Map<GuildModifier, Double> amounts) { |
109 | 167 | GuildModifierOverride.use(guild, amounts); |
110 | 168 | try { |
|
0 commit comments