Attempting to move into tile that blocks shouldnt result in wait action
This commit is contained in:
@@ -26,7 +26,8 @@ export type SimEvent =
|
||||
| { type: "exp-collected"; actorId: EntityId; amount: number; x: number; y: number }
|
||||
| { type: "orb-spawned"; orbId: EntityId; x: number; y: number }
|
||||
| { type: "leveled-up"; actorId: EntityId; level: number; x: number; y: number }
|
||||
| { type: "enemy-alerted"; enemyId: EntityId; x: number; y: number };
|
||||
| { type: "enemy-alerted"; enemyId: EntityId; x: number; y: number }
|
||||
| { type: "move-blocked"; actorId: EntityId; x: number; y: number };
|
||||
|
||||
|
||||
export type Stats = {
|
||||
|
||||
63
src/engine/simulation/__tests__/movement_block.test.ts
Normal file
63
src/engine/simulation/__tests__/movement_block.test.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { applyAction } from '../simulation';
|
||||
import type { World, CombatantActor, Action } from '../../../core/types';
|
||||
import { TileType } from '../../../core/terrain';
|
||||
import { GAME_CONFIG } from '../../../core/config/GameConfig';
|
||||
|
||||
describe('Movement Blocking Behavior', () => {
|
||||
let world: World;
|
||||
let player: CombatantActor;
|
||||
|
||||
beforeEach(() => {
|
||||
// minimalist world setup
|
||||
world = {
|
||||
width: 3,
|
||||
height: 3,
|
||||
tiles: new Array(9).fill(TileType.GRASS),
|
||||
actors: new Map(),
|
||||
exit: { x: 2, y: 2 }
|
||||
};
|
||||
|
||||
// Blocking wall at (1, 0)
|
||||
world.tiles[1] = TileType.WALL;
|
||||
|
||||
player = {
|
||||
id: 1,
|
||||
type: 'player',
|
||||
category: 'combatant',
|
||||
isPlayer: true,
|
||||
pos: { x: 0, y: 0 },
|
||||
speed: 100,
|
||||
energy: 0,
|
||||
stats: { ...GAME_CONFIG.player.initialStats }
|
||||
};
|
||||
|
||||
world.actors.set(player.id, player);
|
||||
});
|
||||
|
||||
it('should return move-blocked event when moving into a wall', () => {
|
||||
const action: Action = { type: 'move', dx: 1, dy: 0 }; // Try to move right into wall at (1,0)
|
||||
const events = applyAction(world, player.id, action);
|
||||
|
||||
expect(events).toHaveLength(1);
|
||||
expect(events[0]).toMatchObject({
|
||||
type: 'move-blocked',
|
||||
actorId: player.id,
|
||||
x: 1,
|
||||
y: 0
|
||||
});
|
||||
});
|
||||
|
||||
it('should return moved event when moving into empty space', () => {
|
||||
const action: Action = { type: 'move', dx: 0, dy: 1 }; // Move down to (0,1) - valid
|
||||
const events = applyAction(world, player.id, action);
|
||||
|
||||
expect(events).toHaveLength(1);
|
||||
expect(events[0]).toMatchObject({
|
||||
type: 'moved',
|
||||
actorId: player.id,
|
||||
from: { x: 0, y: 0 },
|
||||
to: { x: 0, y: 1 }
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -123,9 +123,9 @@ function handleMove(w: World, actor: Actor, action: { dx: number; dy: number },
|
||||
}
|
||||
|
||||
return events;
|
||||
} else {
|
||||
return [{ type: "waited", actorId: actor.id }];
|
||||
}
|
||||
|
||||
return [{ type: "move-blocked", actorId: actor.id, x: nx, y: ny }];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -405,10 +405,14 @@ export class GameScene extends Phaser.Scene {
|
||||
}
|
||||
|
||||
private commitPlayerAction(action: Action) {
|
||||
const playerEvents = applyAction(this.world, this.playerId, action, this.entityManager);
|
||||
|
||||
if (playerEvents.some(ev => ev.type === "move-blocked")) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.awaitingPlayer = false;
|
||||
this.followPlayer = true;
|
||||
|
||||
const playerEvents = applyAction(this.world, this.playerId, action, this.entityManager);
|
||||
|
||||
// Check for pickups right after move (before enemy turn, so you get it efficiently)
|
||||
if (action.type === "move") {
|
||||
|
||||
Reference in New Issue
Block a user