mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-17 05:34:37 +00:00
only send messages related to player
This commit is contained in:
@@ -132,7 +132,7 @@
|
|||||||
* auto reject alliance when event dissapears DONE 9/20/2024
|
* auto reject alliance when event dissapears DONE 9/20/2024
|
||||||
* first place has crown DONE 9/20/2024
|
* first place has crown DONE 9/20/2024
|
||||||
* can't attack ally DONE 9/20/2024
|
* can't attack ally DONE 9/20/2024
|
||||||
* add updates to eventbox: boats (max count, too far)
|
* add updates to eventbox: boats (max count, too far) DONE 9/20/2024
|
||||||
* make alliances expire
|
* make alliances expire
|
||||||
* color code events
|
* color code events
|
||||||
* broken alliances
|
* broken alliances
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {nullable} from "zod";
|
import {nullable} from "zod";
|
||||||
import {EventBus, GameEvent} from "../../../core/EventBus";
|
import {EventBus, GameEvent} from "../../../core/EventBus";
|
||||||
import {AllianceRequest, AllianceRequestEvent, AllianceRequestReplyEvent, BrokeAllianceEvent as BrokenAllianceEvent, Game} from "../../../core/game/Game";
|
import {AllianceRequest, AllianceRequestEvent, AllianceRequestReplyEvent, BrokeAllianceEvent as BrokenAllianceEvent, Game, PlayerID} from "../../../core/game/Game";
|
||||||
import {ClientID} from "../../../core/Schemas";
|
import {ClientID} from "../../../core/Schemas";
|
||||||
import {Layer} from "./Layer";
|
import {Layer} from "./Layer";
|
||||||
|
|
||||||
@@ -19,7 +19,11 @@ export enum MessageType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class DisplayMessageEvent implements GameEvent {
|
export class DisplayMessageEvent implements GameEvent {
|
||||||
constructor(public readonly message: string, public readonly type: MessageType) { }
|
constructor(
|
||||||
|
public readonly message: string,
|
||||||
|
public readonly type: MessageType,
|
||||||
|
public readonly playerID: PlayerID | null = null
|
||||||
|
) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Event {
|
interface Event {
|
||||||
@@ -88,6 +92,18 @@ export class EventsDisplay implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onDisplayMessageEvent(event: DisplayMessageEvent) {
|
onDisplayMessageEvent(event: DisplayMessageEvent) {
|
||||||
|
if (event.playerID != null) {
|
||||||
|
const myPlayer = this.game.playerByClientID(this.clientID)
|
||||||
|
if (myPlayer == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (myPlayer == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (myPlayer.id() != event.playerID) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
this.addEvent({
|
this.addEvent({
|
||||||
description: event.message,
|
description: event.message,
|
||||||
createdAt: this.game.ticks(),
|
createdAt: this.game.ticks(),
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export class BoatAttackExecution implements Execution {
|
|||||||
this.attacker = mg.player(this.attackerID)
|
this.attacker = mg.player(this.attackerID)
|
||||||
|
|
||||||
if (this.attacker.boats().length >= mg.config().boatMaxNumber()) {
|
if (this.attacker.boats().length >= mg.config().boatMaxNumber()) {
|
||||||
mg.displayMessage(`No boats available, max ${mg.config().boatMaxNumber()}`, MessageType.WARN)
|
mg.displayMessage(`No boats available, max ${mg.config().boatMaxNumber()}`, MessageType.WARN, this.attackerID)
|
||||||
this.active = false
|
this.active = false
|
||||||
this.attacker.addTroops(this.troops)
|
this.attacker.addTroops(this.troops)
|
||||||
return
|
return
|
||||||
@@ -78,7 +78,7 @@ export class BoatAttackExecution implements Execution {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (manhattanDistWrapped(this.src.cell(), this.dst.cell(), mg.width()) > mg.config().boatMaxDistance()) {
|
if (manhattanDistWrapped(this.src.cell(), this.dst.cell(), mg.width()) > mg.config().boatMaxDistance()) {
|
||||||
mg.displayMessage(`Cannot send boat: destination is too far away`, MessageType.WARN)
|
mg.displayMessage(`Cannot send boat: destination is too far away`, MessageType.WARN, this.attackerID)
|
||||||
this.active = false
|
this.active = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ export interface Game {
|
|||||||
inSpawnPhase(): boolean
|
inSpawnPhase(): boolean
|
||||||
addExecution(...exec: Execution[]): void
|
addExecution(...exec: Execution[]): void
|
||||||
config(): Config
|
config(): Config
|
||||||
displayMessage(message: string, type: MessageType): void
|
displayMessage(message: string, type: MessageType, playerID: PlayerID | null): void
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MutableGame extends Game {
|
export interface MutableGame extends Game {
|
||||||
|
|||||||
Reference in New Issue
Block a user