radial menu can send attack

This commit is contained in:
evanpelle
2024-09-26 20:27:46 -07:00
parent 2f9269fa65
commit af0726a1af
8 changed files with 57 additions and 23 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ export const AttackIntentSchema = BaseIntentSchema.extend({
type: z.literal('attack'),
attackerID: z.string(),
targetID: z.string().nullable(),
troops: z.number(),
troops: z.number().nullable(),
sourceX: z.number().nullable(),
sourceY: z.number().nullable(),
targetX: z.number().nullable(),
+6 -2
View File
@@ -27,7 +27,7 @@ export class AttackExecution implements Execution {
private border = new Set<Tile>()
constructor(
private troops: number,
private troops: number | null,
private _ownerID: PlayerID,
private _targetID: PlayerID | null,
private sourceCell: Cell | null,
@@ -52,8 +52,12 @@ export class AttackExecution implements Execution {
this._owner = mg.player(this._ownerID)
this.target = this._targetID == this.mg.terraNullius().id() ? mg.terraNullius() : mg.player(this._targetID)
if (this.troops == null) {
this.troops = this.mg.config().attackAmount(this._owner, this.target)
}
this.troops = Math.min(this._owner.troops(), this.troops)
this._owner.setTroops(this._owner.troops() - this.troops)
this._owner.removeTroops(this.troops)
for (const exec of mg.executions()) {
if (exec.isActive() && exec instanceof AttackExecution && exec != this) {
+1
View File
@@ -120,6 +120,7 @@ export interface TerraNullius {
ownsTile(cell: Cell): boolean
isPlayer(): false
id(): PlayerID // always zero, maybe make it TerraNulliusID?
clientID(): ClientID
}
export interface Player {
+5
View File
@@ -1,3 +1,4 @@
import {ClientID} from "../Schemas";
import {TerraNullius, Cell, Tile, PlayerID} from "./Game";
import {GameImpl} from "./GameImpl";
@@ -8,10 +9,14 @@ export class TerraNulliusImpl implements TerraNullius {
constructor(private gs: GameImpl) {
}
clientID(): ClientID {
return "TERRA_NULLIUS_CLIENT_ID"
}
id(): PlayerID {
return null
}
ownsTile(cell: Cell): boolean {
return this.tiles.has(cell);
}