Files
OpenFrontIO/src/core/execution/EmojiExecution.ts
T
falc 07916d46bf Changed consolex to console logging (#1036)
## 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
2025-06-05 16:14:27 +02:00

73 lines
1.8 KiB
TypeScript

import {
AllPlayers,
Execution,
Game,
Player,
PlayerID,
PlayerType,
} from "../game/Game";
import { flattenedEmojiTable } from "../Util";
export class EmojiExecution implements Execution {
private requestor: Player;
private recipient: Player | typeof AllPlayers;
private active = true;
constructor(
private senderID: PlayerID,
private recipientID: PlayerID | typeof AllPlayers,
private emoji: number,
) {}
init(mg: Game, ticks: number): void {
if (!mg.hasPlayer(this.senderID)) {
console.warn(`EmojiExecution: sender ${this.senderID} not found`);
this.active = false;
return;
}
if (this.recipientID !== AllPlayers && !mg.hasPlayer(this.recipientID)) {
console.warn(`EmojiExecution: recipient ${this.recipientID} not found`);
this.active = false;
return;
}
this.requestor = mg.player(this.senderID);
this.recipient =
this.recipientID === AllPlayers
? AllPlayers
: mg.player(this.recipientID);
}
tick(ticks: number): void {
const emojiString = flattenedEmojiTable[this.emoji];
if (emojiString === undefined) {
console.warn(
`cannot send emoji ${this.emoji} from ${this.requestor} to ${this.recipient}`,
);
} else if (this.requestor.canSendEmoji(this.recipient)) {
this.requestor.sendEmoji(this.recipient, emojiString);
if (
emojiString === "🖕" &&
this.recipient !== AllPlayers &&
this.recipient.type() === PlayerType.FakeHuman
) {
this.recipient.updateRelation(this.requestor, -100);
}
} else {
console.warn(
`cannot send emoji from ${this.requestor} to ${this.recipient}`,
);
}
this.active = false;
}
isActive(): boolean {
return this.active;
}
activeDuringSpawnPhase(): boolean {
return false;
}
}