fixed units() returning empty when no units specified, moved canBuild logic to PlayerImpl

This commit is contained in:
Evan
2024-11-17 12:38:54 -08:00
parent 8f8de97d9b
commit 371a33b406
11 changed files with 145 additions and 70 deletions
+3
View File
@@ -89,6 +89,9 @@ export class UnitLayer implements Layer {
bfs(event.oldTile, euclDist(event.oldTile, 3)).forEach(t => {
this.clearCell(t.cell());
});
if (!event.unit.isActive()) {
return
}
bfs(event.unit.tile(), euclDist(event.unit.tile(), 3))
.forEach(t => this.paintCell(t.cell(), this.theme.borderColor(event.unit.owner().info()), 255));
bfs(event.unit.tile(), euclDist(event.unit.tile(), 2))
@@ -150,7 +150,7 @@ export class BuildMenu extends LitElement {
if (this.myPlayer == null) {
return false
}
return this.myPlayer.canBuild(item.unitType, this.game.tile(this.clickedCell))
return this.myPlayer.canBuild(item.unitType, this.game.tile(this.clickedCell)) != false
}
public onBuildSelected = (item: BuildItemDisplay) => {
@@ -1,7 +1,7 @@
import { EventBus } from "../../../../core/EventBus";
import { AllPlayers, Cell, Game, Player, UnitType } from "../../../../core/game/Game";
import { ClientID } from "../../../../core/Schemas";
import { and, bfs, dist, manhattanDist, manhattanDistWrapped, sourceDstOceanShore } from "../../../../core/Util";
import { and, bfs, dist, manhattanDist, manhattanDistWrapped, sourceDstOceanShore, targetTransportTile } from "../../../../core/Util";
import { ContextMenuEvent, MouseUpEvent } from "../../../InputHandler";
import { SendAllianceRequestIntentEvent, SendAttackIntentEvent, SendBoatAttackIntentEvent, SendBreakAllianceIntentEvent, SendDonateIntentEvent, SendEmojiIntentEvent, SendNukeIntentEvent, SendSpawnIntentEvent, SendTargetPlayerIntentEvent } from "../../../Transport";
import { TransformHandler } from "../../TransformHandler";
@@ -344,9 +344,9 @@ export class RadialMenu implements Layer {
}
if (myPlayerBordersOcean && otherPlayerBordersOcean) {
const [src, dst] = sourceDstOceanShore(this.game, myPlayer, other, this.clickedCell)
if (src != null && dst != null) {
if (manhattanDistWrapped(src.cell(), dst.cell(), this.game.width()) < this.game.config().boatMaxDistance()) {
const dst = targetTransportTile(this.game, tile)
if (dst != null) {
if (myPlayer.canBuild(UnitType.TransportShip, dst)) {
this.activateMenuElement(Slot.Boat, "#3f6ab1", boatIcon, () => {
this.eventBus.emit(
new SendBoatAttackIntentEvent(other.id(), this.clickedCell, this.uiState.attackRatio * myPlayer.troops())