Skip to content

Commit

Permalink
- Fix edge-case scenario where towns that have grown via purchased
Browse files Browse the repository at this point in the history
townblocks are prevented from merging with another town.
    - Closes #7719.
  • Loading branch information
LlmDl committed Feb 22, 2025
1 parent 0a6997e commit dbbb313
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Towny/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<artifactId>towny</artifactId>
<packaging>jar</packaging>
<version>0.101.1.4</version>
<version>0.101.1.5</version>

<licenses>
<license>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3788,8 +3788,8 @@ private static void vetTownsForMergeAndThrow(Town remainingTown, Town succumbing
if (!remainingTown.isAllowedThisAmountOfResidents(newResidentsAmount, remainingTown.isCapital()))
throw new TownyException(Translatable.of("msg_town_merge_err_too_many_residents", TownySettings.getMaxResidentsForTown(remainingTown)));

if (!remainingTown.hasUnlimitedClaims() && townWouldHaveTooManyTownBlocks(remainingTown, succumbingTown, newResidentsAmount))
throw new TownyException(Translatable.of("msg_town_merge_err_too_many_townblocks", TownySettings.getMaxTownBlocks(remainingTown, newResidentsAmount)));
if (!remainingTown.hasUnlimitedClaims())
vetTownWouldHaveTooManyTownBlocksOrThrow(remainingTown, succumbingTown, newResidentsAmount);

if ((remainingTown.getPurchasedBlocks() + succumbingTown.getPurchasedBlocks()) > TownySettings.getMaxPurchasedBlocks(remainingTown, newResidentsAmount))
throw new TownyException(Translatable.of("msg_town_merge_err_too_many_purchased_townblocks", TownySettings.getMaxPurchasedBlocks(remainingTown, newResidentsAmount)));
Expand All @@ -3811,13 +3811,18 @@ private static void vetTownsForMergeAndThrow(Town remainingTown, Town succumbing
throw new TownyException(Translatable.of("msg_town_merge_other_offline", succumbingTown.getName(), succumbingTown.getMayor().getName()));
}

private static boolean townWouldHaveTooManyTownBlocks(Town remainingTown, Town succumbingTown, int newResidentsAmount) {
private static void vetTownWouldHaveTooManyTownBlocksOrThrow(Town remainingTown, Town succumbingTown, int newResidentsAmount) throws TownyException {
int newTownBonus = TownySettings.getNewTownBonusBlocks();
int succumbingTownTBAmount = succumbingTown.getNumTownBlocks();
if (newTownBonus > 0 && succumbingTown.getBonusBlocks() >= newTownBonus)
succumbingTownTBAmount = succumbingTownTBAmount - newTownBonus;

return (remainingTown.getNumTownBlocks() + succumbingTownTBAmount) > TownySettings.getMaxTownBlocks(remainingTown, newResidentsAmount);
int succumbingBonusBlocks = succumbingTown.getBonusBlocks() + (2 * newTownBonus);
int succumbingPurchasedBlocks = succumbingTown.getPurchasedBlocks();
int maxAllowedTownBlocks = TownySettings.getMaxTownBlocks(remainingTown, newResidentsAmount) + succumbingBonusBlocks + succumbingPurchasedBlocks;

if ((remainingTown.getNumTownBlocks() + succumbingTownTBAmount) > maxAllowedTownBlocks)
throw new TownyException(Translatable.of("msg_town_merge_err_too_many_townblocks", maxAllowedTownBlocks));
}

private static double[] getMergeCosts(Town remainingTown, Town succumbingTown, boolean admin) throws TownyException {
Expand Down
5 changes: 4 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10266,4 +10266,7 @@ v0.92.0.11:
- When added to a nation rank this rank will only be granted when a nation is of level 4 or greater.
- When a nation rank does not include this node it will not require any nation_level.
- Closes #7681 & #7541.
- Fix Town#getLevelNumber returning funny numbers on Towns. Make the code more understandable.
- Fix Town#getLevelNumber returning funny numbers on Towns. Make the code more understandable.
0.101.1.5:
- Fix edge-case scenario where towns that have grown via purchased townblocks are prevented from merging with another town.
- Closes #7719.

0 comments on commit dbbb313

Please sign in to comment.