mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-21 03:16:15 +00:00
send fire emoji to other players
This commit is contained in:
@@ -8,6 +8,26 @@ import {BreakAllianceExecution} from "../execution/alliance/BreakAllianceExecuti
|
||||
export type PlayerID = string
|
||||
export type Tick = number
|
||||
|
||||
export enum Emoji {
|
||||
ThumbsUp = "👍",
|
||||
ThumbsDown = "👎",
|
||||
Smile = "😊",
|
||||
Sad = "😢",
|
||||
Heart = "❤️",
|
||||
Fire = "🔥",
|
||||
}
|
||||
|
||||
export const AllPlayers = "AllPlayers" as const;
|
||||
|
||||
export class EmojiMessage {
|
||||
constructor(
|
||||
public readonly sender: Player,
|
||||
public readonly recipient: Player | typeof AllPlayers,
|
||||
public readonly emoji: Emoji,
|
||||
public readonly createdAt: Tick
|
||||
) { }
|
||||
}
|
||||
|
||||
export class Cell {
|
||||
|
||||
private strRepr: string
|
||||
@@ -156,6 +176,8 @@ export interface Player {
|
||||
// Targets of player and all allies.
|
||||
transitiveTargets(): Player[]
|
||||
toString(): string
|
||||
canSendEmoji(recipient: Player | typeof AllPlayers): boolean
|
||||
outgoingEmojis(): EmojiMessage[]
|
||||
}
|
||||
|
||||
export interface MutablePlayer extends Player {
|
||||
@@ -178,6 +200,8 @@ export interface MutablePlayer extends Player {
|
||||
target(other: Player): void
|
||||
targets(): MutablePlayer[]
|
||||
transitiveTargets(): MutablePlayer[]
|
||||
// Null means send to all Players
|
||||
sendEmoji(recipient: Player | typeof AllPlayers, emoji: Emoji): void
|
||||
}
|
||||
|
||||
export interface Game {
|
||||
@@ -241,4 +265,8 @@ export class AllianceExpiredEvent implements GameEvent {
|
||||
|
||||
export class TargetPlayerEvent implements GameEvent {
|
||||
constructor(public readonly player: Player, public readonly target: Player) { }
|
||||
}
|
||||
|
||||
export class EmojiMessageEvent implements GameEvent {
|
||||
constructor(public readonly message: EmojiMessage) { }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import {MutablePlayer, Tile, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, MutableGame, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick, TargetPlayerEvent} from "./Game";
|
||||
import {MutablePlayer, Tile, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, MutableGame, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick, TargetPlayerEvent, Emoji, EmojiMessage, EmojiMessageEvent, AllPlayers} from "./Game";
|
||||
import {ClientID} from "../Schemas";
|
||||
import {simpleHash} from "../Util";
|
||||
import {CellString, GameImpl} from "./GameImpl";
|
||||
@@ -26,6 +26,8 @@ export class PlayerImpl implements MutablePlayer {
|
||||
|
||||
private targets_: Target[] = []
|
||||
|
||||
private outgoingEmojis_: EmojiMessage[] = []
|
||||
|
||||
constructor(private gs: GameImpl, private readonly playerInfo: PlayerInfo, private _troops) {
|
||||
this._name = playerInfo.name;
|
||||
}
|
||||
@@ -207,6 +209,29 @@ export class PlayerImpl implements MutablePlayer {
|
||||
return [...new Set(ts)]
|
||||
}
|
||||
|
||||
sendEmoji(recipient: Player | typeof AllPlayers, emoji: Emoji): void {
|
||||
if (recipient == this) {
|
||||
throw Error(`Cannot send emoji to oneself: ${this}`)
|
||||
}
|
||||
const msg = new EmojiMessage(this, recipient, emoji, this.gs.ticks())
|
||||
this.outgoingEmojis_.push(msg)
|
||||
this.gs.eventBus.emit(new EmojiMessageEvent(msg))
|
||||
}
|
||||
|
||||
outgoingEmojis(): EmojiMessage[] {
|
||||
return null
|
||||
}
|
||||
|
||||
canSendEmoji(recipient: Player | null): boolean {
|
||||
const prevMsgs = this.outgoingEmojis_.filter(msg => msg.recipient == recipient)
|
||||
for (const msg of prevMsgs) {
|
||||
if (this.gs.ticks() - msg.createdAt < this.gs.config().emojiMessageCooldown()) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
hash(): number {
|
||||
return simpleHash(this.id()) * (this.troops() + this.numTilesOwned());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user