mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:40:44 +00:00
can create alliance between humans
This commit is contained in:
@@ -12,6 +12,7 @@ import {TerrainLayer} from "./graphics/layers/TerrainLayer";
|
||||
import {WinCheckExecution} from "../core/execution/WinCheckExecution";
|
||||
import {SendAllianceRequestUIEvent} from "./graphics/layers/UILayer";
|
||||
import {createCanvas} from "./graphics/Utils";
|
||||
import {AllianceRequestReplyUIEvent as SendAllianceRequestReplyUIEvent} from "./graphics/layers/EventsDisplay";
|
||||
|
||||
|
||||
|
||||
@@ -125,6 +126,7 @@ export class ClientGame {
|
||||
this.eventBus.on(PlayerEvent, (e) => this.playerEvent(e))
|
||||
this.eventBus.on(MouseUpEvent, (e) => this.inputEvent(e))
|
||||
this.eventBus.on(SendAllianceRequestUIEvent, (e) => this.onSendAllianceRequest(e))
|
||||
this.eventBus.on(SendAllianceRequestReplyUIEvent, (e) => this.onAllianceRequestReplyUIEvent(e))
|
||||
|
||||
this.renderer.initialize()
|
||||
this.input.initialize()
|
||||
@@ -282,6 +284,16 @@ export class ClientGame {
|
||||
})
|
||||
}
|
||||
|
||||
private onAllianceRequestReplyUIEvent(event: SendAllianceRequestReplyUIEvent) {
|
||||
this.sendIntent({
|
||||
type: "allianceRequestReply",
|
||||
clientID: this.id,
|
||||
requestor: event.allianceRequest.requestor().id(),
|
||||
recipient: event.allianceRequest.recipient().id(),
|
||||
accept: event.accepted,
|
||||
})
|
||||
}
|
||||
|
||||
private sendSpawnIntent(cell: Cell) {
|
||||
this.sendIntent({
|
||||
type: "spawn",
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import {nullable} from "zod";
|
||||
import {EventBus} from "../../../core/EventBus";
|
||||
import {AllianceRequestEvent, AllianceRequestReplyEvent, Game} from "../../../core/game/Game";
|
||||
import {EventBus, GameEvent} from "../../../core/EventBus";
|
||||
import {AllianceRequest, AllianceRequestEvent, AllianceRequestReplyEvent, Game} from "../../../core/game/Game";
|
||||
import {ClientID} from "../../../core/Schemas";
|
||||
import {Layer} from "./Layer";
|
||||
|
||||
export class AllianceRequestReplyUIEvent implements GameEvent {
|
||||
constructor(
|
||||
public readonly allianceRequest: AllianceRequest,
|
||||
public readonly accepted: boolean,
|
||||
) { }
|
||||
}
|
||||
|
||||
interface Event {
|
||||
description: string;
|
||||
buttons?: {
|
||||
@@ -72,12 +79,12 @@ export class EventsDisplay implements Layer {
|
||||
{
|
||||
text: "Accept",
|
||||
className: "btn",
|
||||
action: () => alert('accepted'),
|
||||
action: () => this.eventBus.emit(new AllianceRequestReplyUIEvent(event.allianceRequest, true)),
|
||||
},
|
||||
{
|
||||
text: "Reject",
|
||||
className: "btn btn-info",
|
||||
action: () => alert('rejected'),
|
||||
action: () => this.eventBus.emit(new AllianceRequestReplyUIEvent(event.allianceRequest, false)),
|
||||
}
|
||||
],
|
||||
highlight: true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../game/Game";
|
||||
|
||||
export class AllianceRequestExecutionReply implements Execution {
|
||||
export class AllianceRequestReplyExecution implements Execution {
|
||||
private active = true
|
||||
private mg: MutableGame = null
|
||||
private requestor: MutablePlayer;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerInfo, TerraNullius, Tile, PlayerType, Alliance} from "../game/Game";
|
||||
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerInfo, TerraNullius, Tile, PlayerType, Alliance, AllianceRequestReplyEvent} from "../game/Game";
|
||||
import {AttackIntent, BoatAttackIntentSchema, GameID, Intent, Turn} from "../Schemas";
|
||||
import {AttackExecution} from "./AttackExecution";
|
||||
import {SpawnExecution} from "./SpawnExecution";
|
||||
@@ -10,6 +10,7 @@ import {FakeHumanExecution} from "./FakeHumanExecution";
|
||||
import Usernames from '../../../resources/Usernames.txt'
|
||||
import {simpleHash} from "../Util";
|
||||
import {AllianceRequestExecution} from "./AllianceRequestExecution";
|
||||
import {AllianceRequestReplyExecution} from "./AllianceRequestReplyExecution";
|
||||
|
||||
|
||||
|
||||
@@ -58,7 +59,10 @@ export class Executor {
|
||||
)
|
||||
} else if (intent.type == "allianceRequest") {
|
||||
return new AllianceRequestExecution(intent.requestor, intent.recipient)
|
||||
} else {
|
||||
} else if (intent.type == "allianceRequestReply") {
|
||||
return new AllianceRequestReplyExecution(intent.requestor, intent.recipient, intent.accept)
|
||||
}
|
||||
else {
|
||||
throw new Error(`intent type ${intent} not found`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user