mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 10:10:55 +00:00
center button sends spawn event during spawn phase
This commit is contained in:
@@ -13,10 +13,11 @@ import {WinCheckExecution} from "../core/execution/WinCheckExecution";
|
||||
import {SendAttackIntentEvent, SendBoatAttackIntentEvent, SendBreakAllianceIntentEvent, SendSpawnIntentEvent, Transport} from "./Transport";
|
||||
import {createCanvas} from "./graphics/Utils";
|
||||
import {DisplayMessageEvent, MessageType} from "./graphics/layers/EventsDisplay";
|
||||
import {placeName} from "./graphics/NameBoxCalculator";
|
||||
|
||||
|
||||
|
||||
export function createClientGame(name: string, clientID: ClientID, playerID: PlayerID, ip: string | null, gameID: GameID, config: Config, terrainMap: TerrainMap): ClientGame {
|
||||
export function createClientGame(playerName: string, clientID: ClientID, playerID: PlayerID, ip: string | null, gameID: GameID, config: Config, terrainMap: TerrainMap): ClientGame {
|
||||
let eventBus = new EventBus()
|
||||
|
||||
let game = createGame(terrainMap, eventBus, config)
|
||||
@@ -27,11 +28,11 @@ export function createClientGame(name: string, clientID: ClientID, playerID: Pla
|
||||
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const socket = new WebSocket(`${wsProtocol}//${wsHost}`)
|
||||
|
||||
const transport = new Transport(socket, eventBus, gameID, clientID, playerID)
|
||||
const transport = new Transport(socket, eventBus, gameID, clientID, playerID, playerName)
|
||||
|
||||
|
||||
return new ClientGame(
|
||||
name,
|
||||
playerName,
|
||||
clientID,
|
||||
playerID,
|
||||
ip,
|
||||
@@ -194,7 +195,7 @@ export class ClientGame {
|
||||
}
|
||||
const tile = this.gs.tile(cell)
|
||||
if (tile.isLand() && !tile.hasOwner() && this.gs.inSpawnPhase()) {
|
||||
this.eventBus.emit(new SendSpawnIntentEvent(cell, this.playerName))
|
||||
this.eventBus.emit(new SendSpawnIntentEvent(cell))
|
||||
return
|
||||
}
|
||||
if (this.gs.inSpawnPhase()) {
|
||||
|
||||
@@ -26,7 +26,6 @@ export class SendAllianceReplyIntentEvent implements GameEvent {
|
||||
export class SendSpawnIntentEvent implements GameEvent {
|
||||
constructor(
|
||||
public readonly cell: Cell,
|
||||
public readonly playerName: string,
|
||||
) { }
|
||||
}
|
||||
|
||||
@@ -52,6 +51,7 @@ export class Transport {
|
||||
private gameID: GameID,
|
||||
private clientID: ClientID,
|
||||
private playerID: PlayerID,
|
||||
private playerName: string,
|
||||
) {
|
||||
this.eventBus.on(SendAllianceRequestIntentEvent, (e) => this.onSendAllianceRequest(e))
|
||||
this.eventBus.on(SendAllianceReplyIntentEvent, (e) => this.onAllianceRequestReplyUIEvent(e))
|
||||
@@ -94,7 +94,7 @@ export class Transport {
|
||||
type: "spawn",
|
||||
clientID: this.clientID,
|
||||
playerID: this.playerID,
|
||||
name: event.playerName,
|
||||
name: this.playerName,
|
||||
playerType: PlayerType.Human,
|
||||
x: event.cell.x,
|
||||
y: event.cell.y
|
||||
|
||||
@@ -3,7 +3,7 @@ import {Cell, Game, Player, PlayerID} from "../../../core/game/Game";
|
||||
import {ClientID} from "../../../core/Schemas";
|
||||
import {manhattanDist, sourceDstOceanShore} from "../../../core/Util";
|
||||
import {ContextMenuEvent, MouseUpEvent} from "../../InputHandler";
|
||||
import {SendAllianceRequestIntentEvent, SendAttackIntentEvent, SendBoatAttackIntentEvent, SendBreakAllianceIntentEvent} from "../../Transport";
|
||||
import {SendAllianceRequestIntentEvent, SendAttackIntentEvent, SendBoatAttackIntentEvent, SendBreakAllianceIntentEvent, SendSpawnIntentEvent} from "../../Transport";
|
||||
import {TransformHandler} from "../TransformHandler";
|
||||
import {MessageType} from "./EventsDisplay";
|
||||
import {Layer} from "./Layer";
|
||||
@@ -188,11 +188,6 @@ export class RadialMenu implements Layer {
|
||||
item.disabled = true
|
||||
this.updateMenuItemState(item)
|
||||
}
|
||||
const myPlayer = this.game.players().find(p => p.clientID() == this.clientID)
|
||||
if (!myPlayer) {
|
||||
console.warn('my player not found')
|
||||
return
|
||||
}
|
||||
|
||||
this.clickedCell = this.transformHandler.screenToWorldCoordinates(event.x, event.y)
|
||||
if (!this.game.isOnMap(this.clickedCell)) {
|
||||
@@ -201,6 +196,20 @@ export class RadialMenu implements Layer {
|
||||
const tile = this.game.tile(this.clickedCell)
|
||||
const other = tile.owner()
|
||||
|
||||
if (this.game.inSpawnPhase()) {
|
||||
if (tile.isLand() && !tile.hasOwner()) {
|
||||
this.isCenterButtonEnabled = true
|
||||
this.updateCenterButtonState()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const myPlayer = this.game.players().find(p => p.clientID() == this.clientID)
|
||||
if (!myPlayer) {
|
||||
console.warn('my player not found')
|
||||
return
|
||||
}
|
||||
|
||||
if (tile.owner() != myPlayer && tile.isLand() && myPlayer.sharesBorderWith(other)) {
|
||||
if (!other.isPlayer() || !myPlayer.isAlliedWith(other)) {
|
||||
this.isCenterButtonEnabled = true
|
||||
@@ -303,10 +312,17 @@ export class RadialMenu implements Layer {
|
||||
}
|
||||
|
||||
private handleCenterButtonClick() {
|
||||
if (!this.isCenterButtonEnabled) {
|
||||
return
|
||||
}
|
||||
console.log('Center button clicked');
|
||||
const clicked = this.game.tile(this.clickedCell)
|
||||
if (clicked.owner().clientID() != this.clientID) {
|
||||
this.eventBus.emit(new SendAttackIntentEvent(clicked.owner().id()))
|
||||
if (this.game.inSpawnPhase()) {
|
||||
this.eventBus.emit(new SendSpawnIntentEvent(this.clickedCell))
|
||||
} else {
|
||||
if (clicked.owner().clientID() != this.clientID) {
|
||||
this.eventBus.emit(new SendAttackIntentEvent(clicked.owner().id()))
|
||||
}
|
||||
}
|
||||
this.hideRadialMenu();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export const devConfig = new class extends DefaultConfig {
|
||||
return 95
|
||||
}
|
||||
numSpawnPhaseTurns(): number {
|
||||
return 40
|
||||
return 80
|
||||
}
|
||||
gameCreationRate(): number {
|
||||
return 2 * 1000
|
||||
|
||||
Reference in New Issue
Block a user