mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 19:03:25 +00:00
thread_split: send outgoing emoji messages
This commit is contained in:
@@ -328,12 +328,12 @@ export class EventsDisplay extends LitElement implements Layer {
|
||||
const myPlayer = this.game.playerByClientID(this.clientID);
|
||||
if (!myPlayer) return;
|
||||
|
||||
const recipient = update.recipientID == AllPlayers ? AllPlayers : this.game.playerBySmallID(update.recipientID)
|
||||
const sender = this.game.playerBySmallID(update.senderID) as PlayerView
|
||||
const recipient = update.emoji.recipientID == AllPlayers ? AllPlayers : this.game.playerBySmallID(update.emoji.recipientID)
|
||||
const sender = this.game.playerBySmallID(update.emoji.senderID) as PlayerView
|
||||
|
||||
if (recipient == myPlayer) {
|
||||
this.addEvent({
|
||||
description: `${sender.displayName()}:${update.message}`,
|
||||
description: `${sender.displayName()}:${update.emoji.message}`,
|
||||
unsafeDescription: true,
|
||||
type: MessageType.INFO,
|
||||
highlight: true,
|
||||
@@ -341,7 +341,7 @@ export class EventsDisplay extends LitElement implements Layer {
|
||||
});
|
||||
} else if (sender === myPlayer && recipient !== AllPlayers) {
|
||||
this.addEvent({
|
||||
description: `Sent ${(recipient as PlayerView).displayName()}: ${update.message}`,
|
||||
description: `Sent ${(recipient as PlayerView).displayName()}: ${update.emoji.message}`,
|
||||
unsafeDescription: true,
|
||||
type: MessageType.INFO,
|
||||
highlight: true,
|
||||
|
||||
+7
-10
@@ -82,14 +82,6 @@ export class Nation {
|
||||
) { }
|
||||
}
|
||||
|
||||
export class EmojiMessage {
|
||||
constructor(
|
||||
public readonly sender: Player,
|
||||
public readonly recipient: Player | typeof AllPlayers,
|
||||
public readonly emoji: string,
|
||||
public readonly createdAt: Tick
|
||||
) { }
|
||||
}
|
||||
|
||||
export class Cell {
|
||||
public index: number
|
||||
@@ -430,6 +422,7 @@ export interface PlayerUpdate {
|
||||
allies: number[]
|
||||
isTraitor: boolean
|
||||
targets: number[]
|
||||
outgoingEmojis: EmojiMessage[]
|
||||
}
|
||||
|
||||
|
||||
@@ -464,14 +457,18 @@ export interface TargetPlayerUpdate {
|
||||
targetID: number
|
||||
}
|
||||
|
||||
export interface EmojiUpdate {
|
||||
type: GameUpdateType.EmojiUpdate
|
||||
export interface EmojiMessage {
|
||||
message: string
|
||||
senderID: number
|
||||
recipientID: number | typeof AllPlayers
|
||||
createdAt: Tick
|
||||
}
|
||||
|
||||
export interface EmojiUpdate {
|
||||
type: GameUpdateType.EmojiUpdate
|
||||
emoji: EmojiMessage
|
||||
}
|
||||
|
||||
export interface DisplayMessageUpdate {
|
||||
type: GameUpdateType.DisplayEvent
|
||||
message: string
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Config } from "../configuration/Config";
|
||||
import { Cell, Execution, MutableGame, Game, MutablePlayer, PlayerID, PlayerInfo, Player, TerraNullius, Unit, MutableAllianceRequest, Alliance, Nation, UnitType, UnitInfo, DefenseBonus, GameUpdate, GameUpdateType, AllPlayers, GameUpdates, TerrainType } from "./Game";
|
||||
import { Cell, Execution, MutableGame, Game, MutablePlayer, PlayerID, PlayerInfo, Player, TerraNullius, Unit, MutableAllianceRequest, Alliance, Nation, UnitType, UnitInfo, DefenseBonus, GameUpdate, GameUpdateType, AllPlayers, GameUpdates, TerrainType, EmojiMessage } from "./Game";
|
||||
import { NationMap } from "./TerrainMapLoader";
|
||||
import { PlayerImpl } from "./PlayerImpl";
|
||||
import { TerraNulliusImpl } from "./TerraNulliusImpl";
|
||||
@@ -443,15 +443,10 @@ export class GameImpl implements MutableGame {
|
||||
})
|
||||
}
|
||||
|
||||
sendEmojiUpdate(sender: Player, recipient: Player | typeof AllPlayers, emoji: string): void {
|
||||
const recipientID = recipient === AllPlayers ? recipient : recipient.smallID();
|
||||
|
||||
sendEmojiUpdate(msg: EmojiMessage): void {
|
||||
this.addUpdate({
|
||||
type: GameUpdateType.EmojiUpdate,
|
||||
message: emoji,
|
||||
senderID: sender.smallID(),
|
||||
recipientID: recipientID,
|
||||
createdAt: this._ticks
|
||||
emoji: msg
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MutablePlayer, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick, EmojiMessage, AllPlayers, Gold, UnitType, Unit, MutableUnit, Relation, PlayerUpdate, GameUpdateType } from "./Game";
|
||||
import { MutablePlayer, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick, AllPlayers, Gold, UnitType, Unit, MutableUnit, Relation, PlayerUpdate, GameUpdateType, EmojiMessage } from "./Game";
|
||||
import { ClientID } from "../Schemas";
|
||||
import { assertNever, closestOceanShoreFromPlayer, distSortUnit, simpleHash, sourceDstOceanShore, within } from "../Util";
|
||||
import { CellString, GameImpl } from "./GameImpl";
|
||||
@@ -7,6 +7,7 @@ import { MessageType } from './Game';
|
||||
import { renderTroops } from "../../client/Utils";
|
||||
import { TerraNulliusImpl } from "./TerraNulliusImpl";
|
||||
import { manhattanDistFN, TileRef } from "./GameMap";
|
||||
import { Emoji } from "discord.js";
|
||||
|
||||
interface Target {
|
||||
tick: Tick
|
||||
@@ -77,7 +78,8 @@ export class PlayerImpl implements MutablePlayer {
|
||||
targetTroopRatio: this.targetTroopRatio(),
|
||||
allies: this.alliances().map(a => a.other(this).smallID()),
|
||||
isTraitor: this.isTraitor(),
|
||||
targets: this.targets().map(p => p.smallID())
|
||||
targets: this.targets().map(p => p.smallID()),
|
||||
outgoingEmojis: this.outgoingEmojis()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,9 +320,14 @@ export class PlayerImpl implements MutablePlayer {
|
||||
if (recipient == this) {
|
||||
throw Error(`Cannot send emoji to oneself: ${this}`)
|
||||
}
|
||||
const msg = new EmojiMessage(this, recipient, emoji, this.mg.ticks())
|
||||
const msg: EmojiMessage = {
|
||||
message: emoji,
|
||||
senderID: this.smallID(),
|
||||
recipientID: recipient == AllPlayers ? recipient : recipient.smallID(),
|
||||
createdAt: this.mg.ticks()
|
||||
}
|
||||
this.outgoingEmojis_.push(msg)
|
||||
this.mg.sendEmojiUpdate(this, recipient, emoji)
|
||||
this.mg.sendEmojiUpdate(msg)
|
||||
}
|
||||
|
||||
outgoingEmojis(): EmojiMessage[] {
|
||||
@@ -330,7 +337,8 @@ export class PlayerImpl implements MutablePlayer {
|
||||
}
|
||||
|
||||
canSendEmoji(recipient: Player | typeof AllPlayers): boolean {
|
||||
const prevMsgs = this.outgoingEmojis_.filter(msg => msg.recipient == recipient)
|
||||
const recipientID = recipient == AllPlayers ? AllPlayers : recipient.smallID()
|
||||
const prevMsgs = this.outgoingEmojis_.filter(msg => msg.recipientID == recipientID)
|
||||
for (const msg of prevMsgs) {
|
||||
if (this.mg.ticks() - msg.createdAt < this.mg.config().emojiMessageCooldown()) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user