mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 13:59:48 +00:00
9c7e0ce32f
## Description: Answering issue: #1017 [Cleanup] Pass Player into the execution constructor instead of PlayerID I have tested the changes running and playing a full game. I do not know other way to test the changes, please inform me ❤️ ## 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: Lele --------- Co-authored-by: lva <lva@rovsing.dk>
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import {
|
|
AllPlayers,
|
|
Execution,
|
|
Game,
|
|
Player,
|
|
PlayerID,
|
|
PlayerType,
|
|
} from "../game/Game";
|
|
import { flattenedEmojiTable } from "../Util";
|
|
|
|
export class EmojiExecution implements Execution {
|
|
private recipient: Player | typeof AllPlayers;
|
|
|
|
private active = true;
|
|
|
|
constructor(
|
|
private requestor: Player,
|
|
private recipientID: PlayerID | typeof AllPlayers,
|
|
private emoji: number,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
if (this.recipientID !== AllPlayers && !mg.hasPlayer(this.recipientID)) {
|
|
console.warn(`EmojiExecution: recipient ${this.recipientID} not found`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|