create alliance request flow

This commit is contained in:
evanpelle
2024-09-17 19:43:45 -07:00
parent 149ffaa026
commit 44877b8e59
8 changed files with 141 additions and 13 deletions
+11
View File
@@ -10,6 +10,7 @@ import {TerrainMap} from "../core/TerrainMapLoader";
import {and, bfs, dist, manhattanDist} from "../core/Util";
import {TerrainLayer} from "./graphics/layers/TerrainLayer";
import {WinCheckExecution} from "../core/execution/WinCheckExecution";
import {SendAllianceRequestEvent} from "./graphics/layers/UILayer";
@@ -121,6 +122,7 @@ export class ClientGame {
this.eventBus.on(PlayerEvent, (e) => this.playerEvent(e))
this.eventBus.on(MouseUpEvent, (e) => this.inputEvent(e))
this.eventBus.on(SendAllianceRequestEvent, (e) => this.onSendAllianceRequest(e))
this.renderer.initialize()
this.input.initialize()
@@ -269,6 +271,15 @@ export class ClientGame {
}
}
private onSendAllianceRequest(event: SendAllianceRequestEvent) {
this.sendIntent({
type: "allianceRequest",
clientID: this.id,
requestor: event.requestor.id(),
recipient: event.recipient.id(),
})
}
private sendSpawnIntent(cell: Cell) {
this.sendIntent({
type: "spawn",
+21 -4
View File
@@ -1,7 +1,7 @@
import {Theme} from "../../../core/configuration/Config";
import {EventBus} from "../../../core/EventBus";
import {GameEnv, Theme} from "../../../core/configuration/Config";
import {EventBus, GameEvent} from "../../../core/EventBus";
import {WinEvent} from "../../../core/execution/WinCheckExecution";
import {Game, Player} from "../../../core/Game";
import {AllianceRequest, Game, Player} from "../../../core/Game";
import {ClientID} from "../../../core/Schemas";
import {renderTroops} from "../Utils";
import winModalHtml from '../WinModal.html';
@@ -9,6 +9,12 @@ import {RightClickEvent} from "../../InputHandler";
import {Layer} from "./Layer";
import {TransformHandler} from "../TransformHandler";
export class SendAllianceRequestEvent implements GameEvent {
constructor(
public readonly requestor: Player,
public readonly recipient: Player
) { }
}
interface MenuOption {
label: string;
@@ -228,6 +234,13 @@ export class UILayer implements Layer {
if (owner.clientID() == this.clientID) {
return
}
// TODO: check if already allied with
const myPlayer = this.game.players().find(p => p.clientID() == this.clientID)
if (!myPlayer) {
console.warn('my player not found')
return
}
this.customMenu!.style.display = 'block';
this.customMenu!.style.left = `${e.x}px`;
@@ -235,7 +248,11 @@ export class UILayer implements Layer {
this.populateMenu([
{
label: "Request Alliance",
action: (): void => { },
action: (): void => {
this.eventBus.emit(
new SendAllianceRequestEvent(myPlayer, owner)
)
},
}
])
}