mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-26 19:04:36 +00:00
77f57207be
## Description: Changed from consolex to console ## Please complete the following: - [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 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: @qqkedsi
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { Execution, Game, Gold, Player, PlayerID } from "../game/Game";
|
|
|
|
export class DonateGoldExecution implements Execution {
|
|
private sender: Player;
|
|
private recipient: Player;
|
|
|
|
private active = true;
|
|
|
|
constructor(
|
|
private senderID: PlayerID,
|
|
private recipientID: PlayerID,
|
|
private gold: Gold | null,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
if (!mg.hasPlayer(this.senderID)) {
|
|
console.warn(`DonateExecution: sender ${this.senderID} not found`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
if (!mg.hasPlayer(this.recipientID)) {
|
|
console.warn(`DonateExecution recipient ${this.recipientID} not found`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
this.sender = mg.player(this.senderID);
|
|
this.recipient = mg.player(this.recipientID);
|
|
if (this.gold === null) {
|
|
this.gold = this.sender.gold() / 3n;
|
|
}
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
if (this.gold === null) throw new Error("not initialized");
|
|
if (
|
|
this.sender.canDonate(this.recipient) &&
|
|
this.sender.donateGold(this.recipient, this.gold)
|
|
) {
|
|
this.recipient.updateRelation(this.sender, 50);
|
|
} else {
|
|
console.warn(
|
|
`cannot send gold from ${this.sender.name()} to ${this.recipient.name()}`,
|
|
);
|
|
}
|
|
this.active = false;
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|