Half changes to switch to exit level, Ran out of credits, re added enemies
This commit is contained in:
@@ -16,13 +16,14 @@ describe('CombatLogic', () => {
|
||||
const setWall = (x: number, y: number) => {
|
||||
mockWorld.tiles[y * mockWorld.width + x] = TileType.WALL;
|
||||
};
|
||||
|
||||
|
||||
beforeEach(() => {
|
||||
mockWorld = {
|
||||
width: 10,
|
||||
height: 10,
|
||||
tiles: new Array(100).fill(TileType.EMPTY),
|
||||
exit: { x: 9, y: 9 }
|
||||
exit: { x: 9, y: 9 },
|
||||
trackPath: []
|
||||
};
|
||||
ecsWorld = new ECSWorld();
|
||||
// Shooter ID 1
|
||||
@@ -44,12 +45,12 @@ describe('CombatLogic', () => {
|
||||
it('should travel full path if no obstacles', () => {
|
||||
const start = { x: 0, y: 0 };
|
||||
const end = { x: 5, y: 0 };
|
||||
|
||||
|
||||
const result = traceProjectile(mockWorld, start, end, accessor);
|
||||
|
||||
|
||||
expect(result.blockedPos).toEqual(end);
|
||||
expect(result.hitActorId).toBeUndefined();
|
||||
expect(result.path).toHaveLength(6);
|
||||
expect(result.path).toHaveLength(6);
|
||||
});
|
||||
|
||||
it('should stop at wall', () => {
|
||||
@@ -58,7 +59,7 @@ describe('CombatLogic', () => {
|
||||
setWall(3, 0); // Wall at (3,0)
|
||||
|
||||
const result = traceProjectile(mockWorld, start, end, accessor);
|
||||
|
||||
|
||||
expect(result.blockedPos).toEqual({ x: 2, y: 0 });
|
||||
expect(result.hitActorId).toBeUndefined();
|
||||
});
|
||||
@@ -66,7 +67,7 @@ describe('CombatLogic', () => {
|
||||
it('should stop at enemy', () => {
|
||||
const start = { x: 0, y: 0 };
|
||||
const end = { x: 5, y: 0 };
|
||||
|
||||
|
||||
// Place enemy at (3,0)
|
||||
const enemyId = 2 as EntityId;
|
||||
const enemy = {
|
||||
@@ -79,36 +80,36 @@ describe('CombatLogic', () => {
|
||||
syncActor(enemy);
|
||||
|
||||
const result = traceProjectile(mockWorld, start, end, accessor, 1 as EntityId); // Shooter 1
|
||||
|
||||
|
||||
expect(result.blockedPos).toEqual({ x: 3, y: 0 });
|
||||
expect(result.hitActorId).toBe(enemyId);
|
||||
});
|
||||
|
||||
it('should ignore shooter position', () => {
|
||||
const start = { x: 0, y: 0 };
|
||||
const end = { x: 5, y: 0 };
|
||||
|
||||
// Shooter at start
|
||||
const shooter = {
|
||||
id: 1 as EntityId,
|
||||
type: 'player',
|
||||
category: 'combatant',
|
||||
pos: { x: 0, y: 0 },
|
||||
isPlayer: true
|
||||
};
|
||||
syncActor(shooter);
|
||||
const start = { x: 0, y: 0 };
|
||||
const end = { x: 5, y: 0 };
|
||||
|
||||
const result = traceProjectile(mockWorld, start, end, accessor, 1 as EntityId);
|
||||
|
||||
// Should not hit self
|
||||
expect(result.hitActorId).toBeUndefined();
|
||||
expect(result.blockedPos).toEqual(end);
|
||||
// Shooter at start
|
||||
const shooter = {
|
||||
id: 1 as EntityId,
|
||||
type: 'player',
|
||||
category: 'combatant',
|
||||
pos: { x: 0, y: 0 },
|
||||
isPlayer: true
|
||||
};
|
||||
syncActor(shooter);
|
||||
|
||||
const result = traceProjectile(mockWorld, start, end, accessor, 1 as EntityId);
|
||||
|
||||
// Should not hit self
|
||||
expect(result.hitActorId).toBeUndefined();
|
||||
expect(result.blockedPos).toEqual(end);
|
||||
});
|
||||
|
||||
it('should ignore non-combatant actors (e.g. items)', () => {
|
||||
const start = { x: 0, y: 0 };
|
||||
const end = { x: 5, y: 0 };
|
||||
|
||||
|
||||
// Item at (3,0)
|
||||
const item = {
|
||||
id: 99 as EntityId,
|
||||
@@ -119,10 +120,10 @@ describe('CombatLogic', () => {
|
||||
syncActor(item);
|
||||
|
||||
const result = traceProjectile(mockWorld, start, end, accessor);
|
||||
|
||||
|
||||
// Should pass through item
|
||||
expect(result.blockedPos).toEqual(end);
|
||||
expect(result.hitActorId).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user