diff --git a/TODO.txt b/TODO.txt index c748989cc..be56734d8 100644 --- a/TODO.txt +++ b/TODO.txt @@ -92,7 +92,7 @@ * make names bigger DONE 9/3/2024 * boats leave trails DONE 9/3/2024 * send boat even if touching DONE 9/4/2024 -* when attacking by boat, attack execution only starts from boat pixel +* when attacking by boat, attack execution only starts from boat pixel DONE 9/4/2024 * directed expansion * more random names for game id & client id * Make fake humans diff --git a/src/client/ClientGame.ts b/src/client/ClientGame.ts index 56434269c..86571536a 100644 --- a/src/client/ClientGame.ts +++ b/src/client/ClientGame.ts @@ -286,6 +286,8 @@ export class ClientGame { attackerID: this.myPlayer.id(), targetID: targetID, troops: troops, + sourceX: null, + sourceY: null, targetX: cell.x, targetY: cell.y }) diff --git a/src/core/Schemas.ts b/src/core/Schemas.ts index 686c867cf..3017c50cf 100644 --- a/src/core/Schemas.ts +++ b/src/core/Schemas.ts @@ -24,6 +24,7 @@ export type ClientIntentMessage = z.infer export type ClientJoinMessage = z.infer export type ClientLeaveMessage = z.infer +// TODO: create Cell schema export interface Lobby { id: string; @@ -42,8 +43,10 @@ export const AttackIntentSchema = BaseIntentSchema.extend({ attackerID: z.string(), targetID: z.string().nullable(), troops: z.number(), - targetX: z.number(), - targetY: z.number() + sourceX: z.number().nullable(), + sourceY: z.number().nullable(), + targetX: z.number().nullable(), + targetY: z.number().nullable() }); diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index 8bf624c26..f46b925f4 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -28,7 +28,7 @@ export const devConfig = new class extends DefaultConfig { troopAdditionRate(player: Player): number { if (player.isBot()) { - return 10000 + return 100000 } else { return 100000 } diff --git a/src/core/execution/AttackExecution.ts b/src/core/execution/AttackExecution.ts index 8945bd1ef..6545e4050 100644 --- a/src/core/execution/AttackExecution.ts +++ b/src/core/execution/AttackExecution.ts @@ -17,6 +17,7 @@ export class AttackExecution implements Execution { private troops: number, private _ownerID: PlayerID, private targetID: PlayerID | null, + private sourceCell: Cell | null, private targetCell: Cell | null, ) { } @@ -54,16 +55,18 @@ export class AttackExecution implements Execution { } } // Existing attack on same target, add troops - if (otherAttack._owner == this._owner && otherAttack.targetID == this.targetID) { + if (otherAttack._owner == this._owner && otherAttack.targetID == this.targetID && this.sourceCell == otherAttack.sourceCell) { otherAttack.troops += this.troops - otherAttack.refreshToConquer() this.active = false return } } } - - this.refreshToConquer() + if (this.sourceCell != null) { + this.addNeighbors(mg.tile(this.sourceCell)) + } else { + this.refreshToConquer() + } } private refreshToConquer() { diff --git a/src/core/execution/BoatAttackExecution.ts b/src/core/execution/BoatAttackExecution.ts index 70f88eff4..778de6eb4 100644 --- a/src/core/execution/BoatAttackExecution.ts +++ b/src/core/execution/BoatAttackExecution.ts @@ -118,7 +118,7 @@ export class BoatAttackExecution implements Execution { return } this.attacker.conquer(this.dst) - this.mg.addExecution(new AttackExecution(this.troops, this.attacker.id(), this.targetID, null)) + this.mg.addExecution(new AttackExecution(this.troops, this.attacker.id(), this.targetID, this.dst.cell(), null)) this.boat.delete() this.active = false return diff --git a/src/core/execution/BotExecution.ts b/src/core/execution/BotExecution.ts index 49c3d3292..5b1743e75 100644 --- a/src/core/execution/BotExecution.ts +++ b/src/core/execution/BotExecution.ts @@ -67,6 +67,7 @@ export class BotExecution implements Execution { this.bot.troops() / 20, this.bot.id(), toAttack.isPlayer() ? toAttack.id() : null, + null, null )) } diff --git a/src/core/execution/ExecutionManager.ts b/src/core/execution/ExecutionManager.ts index 0dfb32ceb..2b27e64a2 100644 --- a/src/core/execution/ExecutionManager.ts +++ b/src/core/execution/ExecutionManager.ts @@ -22,11 +22,14 @@ export class Executor { createExec(intent: Intent): Execution { if (intent.type == "attack") { + const source: Cell | null = intent.sourceX != null && intent.sourceY != null ? new Cell(intent.sourceX, intent.sourceY) : null + const target: Cell | null = intent.targetX != null && intent.targetY != null ? new Cell(intent.targetX, intent.targetY) : null return new AttackExecution( intent.troops, intent.attackerID, intent.targetID, - new Cell(intent.targetX, intent.targetY) + source, + target, ) } else if (intent.type == "spawn") { return new SpawnExecution(