Fix stand-still commands and ally pathing

This commit is contained in:
2026-06-22 23:09:57 +09:00
parent 3de598511c
commit e06b8dab58
2 changed files with 95 additions and 5 deletions

View File

@@ -1106,6 +1106,11 @@ export class BattleScene extends Phaser.Scene {
this.centerCameraOnTile(unit.x, unit.y);
}
if (this.phase === 'moving' && this.selectedUnit?.id === unit.id) {
this.moveSelectedUnit(unit.x, unit.y);
return;
}
if (this.phase === 'targeting' && this.selectedUnit) {
if (unit.hp > 0 && this.targetingAction) {
if (this.selectedUsable && this.selectedUsable.effect !== 'damage') {
@@ -1214,6 +1219,7 @@ export class BattleScene extends Phaser.Scene {
const fromX = unit.x;
const fromY = unit.y;
const stayingInPlace = fromX === x && fromY === y;
unit.x = x;
unit.y = y;
this.pendingMove = { unit, fromX, fromY, toX: x, toY: y };
@@ -1224,7 +1230,9 @@ export class BattleScene extends Phaser.Scene {
const targetX = this.tileCenterX(x);
const targetY = this.tileCenterY(y);
this.moveUnitView(unit, x, y, view);
if (!stayingInPlace) {
this.moveUnitView(unit, x, y, view);
}
this.showCommandMenu(unit, pointer?.x ?? targetX, pointer?.y ?? targetY);
this.renderUnitDetail(unit, '공격, 책략, 도구, 대기 중 하나를 선택하세요.\n우클릭하면 이동을 취소합니다.');
}
@@ -1240,9 +1248,10 @@ export class BattleScene extends Phaser.Scene {
{ x: 0, y: 1 },
{ x: 0, y: -1 }
];
const costs = new Map<string, number>([[this.tileKey(unit.x, unit.y), 0]]);
const originKey = this.tileKey(unit.x, unit.y);
const costs = new Map<string, number>([[originKey, 0]]);
const queue = [{ x: unit.x, y: unit.y, cost: 0 }];
const reachable = new Map<string, { x: number; y: number; cost: number }>();
const reachable = new Map<string, { x: number; y: number; cost: number }>([[originKey, { x: unit.x, y: unit.y, cost: 0 }]]);
while (queue.length > 0) {
queue.sort((a, b) => a.cost - b.cost);
@@ -1254,7 +1263,7 @@ export class BattleScene extends Phaser.Scene {
directions.forEach((direction) => {
const nextX = current.x + direction.x;
const nextY = current.y + direction.y;
if (!this.isInBounds(nextX, nextY) || this.isOccupied(nextX, nextY, unit.id)) {
if (!this.isInBounds(nextX, nextY) || this.isMovementBlocked(unit, nextX, nextY)) {
return;
}
@@ -1271,7 +1280,9 @@ export class BattleScene extends Phaser.Scene {
costs.set(key, nextCost);
const tile = { x: nextX, y: nextY, cost: nextCost };
reachable.set(key, tile);
if (!this.isOccupied(nextX, nextY, unit.id)) {
reachable.set(key, tile);
}
queue.push(tile);
});
}
@@ -1300,6 +1311,15 @@ export class BattleScene extends Phaser.Scene {
return battleUnits.some((unit) => unit.id !== exceptUnitId && unit.hp > 0 && unit.x === x && unit.y === y);
}
private isMovementBlocked(unit: UnitData, x: number, y: number) {
return battleUnits.some((other) => {
if (other.id === unit.id || other.hp <= 0 || other.x !== x || other.y !== y) {
return false;
}
return other.faction !== unit.faction;
});
}
private tileCenterX(x: number) {
return this.tileTopLeftX(x) + this.layout.tileSize / 2;
}