mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-19 07:45:52 +00:00
radial menu can send attack
This commit is contained in:
+1
-1
@@ -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(),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user