Fix : Donation when max pop already reached (#904)

## Description:

Only donate up to what the receiving player can get so we don't silently
loose troops

See the chat here :

![image](https://github.com/user-attachments/assets/95b0917c-b7f3-47a0-b3a0-156110e727aa)


## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:

theodoreleon.aetarax

---------

Co-authored-by: tnhnblgl <51187395+tnhnblgl@users.noreply.github.com>
This commit is contained in:
Théodore Léon
2025-06-02 22:27:24 +02:00
committed by 1brucben
parent e763ade705
commit 8dc6941fe7
+5 -1
View File
@@ -30,6 +30,10 @@ export class DonateTroopsExecution implements Execution {
if (this.troops === null) {
this.troops = mg.config().defaultDonationAmount(this.sender);
}
const maxDonation =
mg.config().maxPopulation(this.recipient) -
this.recipient.totalPopulation();
this.troops = Math.min(this.troops, maxDonation);
}
tick(ticks: number): void {
@@ -41,7 +45,7 @@ export class DonateTroopsExecution implements Execution {
this.recipient.updateRelation(this.sender, 50);
} else {
consolex.warn(
`cannot send tropps from ${this.sender} to ${this.recipient}`,
`cannot send troops from ${this.sender} to ${this.recipient}`,
);
}
this.active = false;