mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-06 14:56:47 +00:00
send fire emoji to other players
This commit is contained in:
+17
-1
@@ -1,5 +1,5 @@
|
||||
import {EventBus, GameEvent} from "../core/EventBus"
|
||||
import {AllianceRequest, Cell, Game, Player, PlayerID, PlayerType} from "../core/game/Game"
|
||||
import {AllianceRequest, AllPlayers, Cell, Emoji, Player, PlayerID, PlayerType} from "../core/game/Game"
|
||||
import {ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, ClientLeaveMessageSchema, GameID, Intent, ServerMessage, ServerMessageSchema} from "../core/Schemas"
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ export class SendAllianceRequestIntentEvent implements GameEvent {
|
||||
public readonly recipient: Player
|
||||
) { }
|
||||
}
|
||||
|
||||
export class SendBreakAllianceIntentEvent implements GameEvent {
|
||||
constructor(
|
||||
public readonly requestor: Player,
|
||||
@@ -49,6 +50,10 @@ export class SendTargetPlayerIntentEvent implements GameEvent {
|
||||
) { }
|
||||
}
|
||||
|
||||
export class SendEmojiIntentEvent implements GameEvent {
|
||||
constructor(public readonly recipient: Player | typeof AllPlayers, public readonly emoji: Emoji) { }
|
||||
}
|
||||
|
||||
export class Transport {
|
||||
|
||||
public onconnect: () => {}
|
||||
@@ -68,6 +73,7 @@ export class Transport {
|
||||
this.eventBus.on(SendAttackIntentEvent, (e) => this.onSendAttackIntent(e))
|
||||
this.eventBus.on(SendBoatAttackIntentEvent, (e) => this.onSendBoatAttackIntent(e))
|
||||
this.eventBus.on(SendTargetPlayerIntentEvent, (e) => this.onSendTargetPlayerIntent(e))
|
||||
this.eventBus.on(SendEmojiIntentEvent, (e) => this.onSendEmojiIntent(e))
|
||||
}
|
||||
|
||||
connect(onconnect: () => void, onmessage: (message: ServerMessage) => void, isActive: () => boolean) {
|
||||
@@ -200,6 +206,16 @@ export class Transport {
|
||||
})
|
||||
}
|
||||
|
||||
private onSendEmojiIntent(event: SendEmojiIntentEvent) {
|
||||
this.sendIntent({
|
||||
type: "emoji",
|
||||
clientID: this.clientID,
|
||||
sender: this.playerID,
|
||||
recipient: event.recipient == AllPlayers ? AllPlayers : event.recipient.id(),
|
||||
emoji: event.emoji
|
||||
})
|
||||
}
|
||||
|
||||
private sendIntent(intent: Intent) {
|
||||
if (this.socket.readyState === WebSocket.OPEN) {
|
||||
const msg = ClientIntentMessageSchema.parse({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {nullable} from "zod";
|
||||
import {EventBus, GameEvent} from "../../../core/EventBus";
|
||||
import {AllianceExpiredEvent, AllianceRequestEvent, AllianceRequestReplyEvent, BrokeAllianceEvent, Game, Player, PlayerID, TargetPlayerEvent} from "../../../core/game/Game";
|
||||
import {AllianceExpiredEvent, AllianceRequestEvent, AllianceRequestReplyEvent, BrokeAllianceEvent, EmojiMessageEvent, Game, Player, PlayerID, TargetPlayerEvent} from "../../../core/game/Game";
|
||||
import {ClientID} from "../../../core/Schemas";
|
||||
import {Layer} from "./Layer";
|
||||
import {SendAllianceReplyIntentEvent} from "../../Transport";
|
||||
@@ -53,6 +53,7 @@ export class EventsDisplay implements Layer {
|
||||
this.eventBus.on(BrokeAllianceEvent, e => this.onBrokeAllianceEvent(e))
|
||||
this.eventBus.on(AllianceExpiredEvent, e => this.onAllianceExpiredEvent(e))
|
||||
this.eventBus.on(TargetPlayerEvent, e => this.onTargetPlayerEvent(e))
|
||||
this.eventBus.on(EmojiMessageEvent, e => this.onEmojiMessageEvent(e))
|
||||
this.renderTable()
|
||||
}
|
||||
|
||||
@@ -226,6 +227,21 @@ export class EventsDisplay implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
onEmojiMessageEvent(event: EmojiMessageEvent) {
|
||||
const myPlayer = this.game.playerByClientID(this.clientID)
|
||||
if (myPlayer == null) {
|
||||
return
|
||||
}
|
||||
if (event.message.recipient == myPlayer) {
|
||||
this.addEvent({
|
||||
description: `${event.message.sender.name()}:${event.message.emoji}`,
|
||||
type: MessageType.INFO,
|
||||
highlight: true,
|
||||
createdAt: this.game.ticks(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
addEvent(event: Event): void {
|
||||
this.events.push(event);
|
||||
this.renderTable()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {EventBus} from "../../../core/EventBus";
|
||||
import {Cell, Game, Player, PlayerID} from "../../../core/game/Game";
|
||||
import {AllPlayers, Cell, Emoji, Game, Player, PlayerID} from "../../../core/game/Game";
|
||||
import {ClientID} from "../../../core/Schemas";
|
||||
import {and, bfs, dist, manhattanDist, manhattanDistWrapped, sourceDstOceanShore} from "../../../core/Util";
|
||||
import {ContextMenuEvent, MouseUpEvent} from "../../InputHandler";
|
||||
import {SendAllianceRequestIntentEvent, SendAttackIntentEvent, SendBoatAttackIntentEvent, SendBreakAllianceIntentEvent, SendSpawnIntentEvent, SendTargetPlayerIntentEvent} from "../../Transport";
|
||||
import {SendAllianceRequestIntentEvent, SendAttackIntentEvent, SendBoatAttackIntentEvent, SendBreakAllianceIntentEvent, SendEmojiIntentEvent, SendSpawnIntentEvent, SendTargetPlayerIntentEvent} from "../../Transport";
|
||||
import {TransformHandler} from "../TransformHandler";
|
||||
import {MessageType} from "./EventsDisplay";
|
||||
import {Layer} from "./Layer";
|
||||
@@ -13,20 +13,14 @@ import allianceIcon from '../../../../resources/images/AllianceIconWhite.png';
|
||||
import boatIcon from '../../../../resources/images/BoatIconWhite.png';
|
||||
import swordIcon from '../../../../resources/images/SwordIconWhite.png';
|
||||
import targetIcon from '../../../../resources/images/TargetIconWhite.png';
|
||||
import emojiIcon from '../../../../resources/images/EmojiIconWhite.png';
|
||||
|
||||
|
||||
enum RadialElement {
|
||||
RequestAlliance,
|
||||
BreakAlliance,
|
||||
BoatAttack,
|
||||
Target,
|
||||
}
|
||||
|
||||
enum Slot {
|
||||
Alliance,
|
||||
Boat,
|
||||
Target,
|
||||
FOURTH
|
||||
Emoji
|
||||
}
|
||||
|
||||
export class RadialMenu implements Layer {
|
||||
@@ -38,7 +32,7 @@ export class RadialMenu implements Layer {
|
||||
[Slot.Alliance, {name: "alliance", disabled: true, action: () => { }, color: null, icon: null, defaultIcon: allianceIcon}],
|
||||
[Slot.Boat, {name: "boat", disabled: true, action: () => { }, color: null, icon: null, defaultIcon: boatIcon}],
|
||||
[Slot.Target, {name: "target", disabled: true, action: () => { }, defaultIcon: targetIcon}],
|
||||
|
||||
[Slot.Emoji, {name: "emoji", disabled: true, action: () => { }, defaultIcon: emojiIcon}],
|
||||
]);
|
||||
|
||||
private readonly menuSize = 190;
|
||||
@@ -230,6 +224,15 @@ export class RadialMenu implements Layer {
|
||||
return
|
||||
}
|
||||
|
||||
if (tile.hasOwner()) {
|
||||
const target = tile.owner() == myPlayer ? AllPlayers : (tile.owner() as Player)
|
||||
this.activateMenuElement(Slot.Emoji, "#ebe250", emojiIcon, () => {
|
||||
this.eventBus.emit(
|
||||
new SendEmojiIntentEvent(target, Emoji.Fire)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
if (tile.owner() != myPlayer && tile.isLand() && myPlayer.sharesBorderWith(other)) {
|
||||
if (other.isPlayer()) {
|
||||
if (!myPlayer.isAlliedWith(other)) {
|
||||
|
||||
Reference in New Issue
Block a user