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