From 5e0367ae5504b2706e643ec67fcf98b9fde92f40 Mon Sep 17 00:00:00 2001 From: Evan Date: Sun, 5 Jan 2025 20:04:55 -0800 Subject: [PATCH] bufix: NPC is targeted at the same time it allies with targeter, causing it to try to attack itself --- src/core/execution/AttackExecution.ts | 4 ++++ src/core/execution/FakeHumanExecution.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/execution/AttackExecution.ts b/src/core/execution/AttackExecution.ts index e9d6208ae..9dfbfa11e 100644 --- a/src/core/execution/AttackExecution.ts +++ b/src/core/execution/AttackExecution.ts @@ -55,6 +55,10 @@ 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._owner == this.target) { + throw new Error(`Player ${this._owner} cannot attack itself`) + } + if (this.troops == null) { this.troops = this.mg.config().attackAmount(this._owner, this.target) } diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index f7212cd7c..aad3a4cd7 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -165,7 +165,7 @@ export class FakeHumanExecution implements Execution { .filter(ally => ally.targets().length > 0) .map(ally => ({ ally: ally, t: ally.targets()[0] }))[0] ?? null - if (target != null && !this.player.isAlliedWith(target.t)) { + if (target != null && target.t != this.player && !this.player.isAlliedWith(target.t)) { this.player.updateRelation(target.ally, -20) this.enemy = target.t this.lastEnemyUpdateTick = this.mg.ticks()