mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 06:22:19 +00:00
1ecd6c4ee1
Resolve #1652 1. Add the ability to toggle **gold donations** and **troop donations** for private lobbies ~2. Add relevant translations.~ 3. Refactor `canDonate` to be specific to gold and troop donations 4. Add placeholders for singleplayer mode if this is to be extended to support that too. 5. Add Tests for Donate logic <img width="1643" height="1788" alt="image" src="https://github.com/user-attachments/assets/82b93400-a1f0-45f0-8b2b-a7f78dc0c3e9" /> _Private Lobby_  _Testing Troop Send In Private Lobby_  _Troop Send Complete In Private Lobby_  Confirming that public teams still works - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [X] I have read and accepted the CLA agreement (only required once). regression is found: DISCORD_USERNAME: cool_clarky --------- Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> Co-authored-by: Drills Kibo <59177241+drillskibo@users.noreply.github.com>
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { Execution, Game, Player, PlayerID } from "../game/Game";
|
|
|
|
export class DonateTroopsExecution implements Execution {
|
|
private recipient: Player;
|
|
|
|
private active = true;
|
|
|
|
constructor(
|
|
private sender: Player,
|
|
private recipientID: PlayerID,
|
|
private troops: number | null,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
if (!mg.hasPlayer(this.recipientID)) {
|
|
console.warn(`DonateExecution recipient ${this.recipientID} not found`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
this.recipient = mg.player(this.recipientID);
|
|
this.troops ??= mg.config().defaultDonationAmount(this.sender);
|
|
const maxDonation =
|
|
mg.config().maxTroops(this.recipient) - this.recipient.troops();
|
|
this.troops = Math.min(this.troops, maxDonation);
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
if (this.troops === null) throw new Error("not initialized");
|
|
if (
|
|
this.sender.canDonateTroops(this.recipient) &&
|
|
this.sender.donateTroops(this.recipient, this.troops)
|
|
) {
|
|
this.recipient.updateRelation(this.sender, 50);
|
|
} else {
|
|
console.warn(
|
|
`cannot send troops from ${this.sender} to ${this.recipient}`,
|
|
);
|
|
}
|
|
this.active = false;
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|