center button sends spawn event during spawn phase

This commit is contained in:
evanpelle
2024-09-28 13:46:49 -07:00
parent 32763f61d8
commit 49cea45290
5 changed files with 35 additions and 17 deletions
+24 -8
View File
@@ -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();
}