Make it so you cant shoot yourself
This commit is contained in:
@@ -94,6 +94,12 @@ export class TargetingSystem {
|
|||||||
const player = accessor.getCombatant(playerId);
|
const player = accessor.getCombatant(playerId);
|
||||||
if (!player || !player.inventory) return false;
|
if (!player || !player.inventory) return false;
|
||||||
|
|
||||||
|
// Prevent targeting self
|
||||||
|
if (this.cursor.x === player.pos.x && this.cursor.y === player.pos.y) {
|
||||||
|
console.log("Cannot target self!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const itemIdx = player.inventory.items.findIndex(it => it.id === this.targetingItemId);
|
const itemIdx = player.inventory.items.findIndex(it => it.id === this.targetingItemId);
|
||||||
if (itemIdx === -1) {
|
if (itemIdx === -1) {
|
||||||
console.log("Item not found!");
|
console.log("Item not found!");
|
||||||
|
|||||||
@@ -171,4 +171,33 @@ describe('TargetingSystem', () => {
|
|||||||
expect(mockGraphics.clear).toHaveBeenCalled();
|
expect(mockGraphics.clear).toHaveBeenCalled();
|
||||||
expect(mockSprite.setVisible).toHaveBeenCalledWith(false);
|
expect(mockSprite.setVisible).toHaveBeenCalledWith(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should prevent targeting self', () => {
|
||||||
|
const playerPos = { x: 1, y: 1 };
|
||||||
|
|
||||||
|
// Setup targeting
|
||||||
|
targetingSystem.startTargeting(
|
||||||
|
'item-1',
|
||||||
|
playerPos,
|
||||||
|
mockWorld,
|
||||||
|
{ getCombatant: vi.fn().mockReturnValue({ pos: playerPos, inventory: { items: [{ id: 'item-1' }] } }) } as any,
|
||||||
|
1 as EntityId,
|
||||||
|
new Uint8Array(100),
|
||||||
|
10
|
||||||
|
);
|
||||||
|
|
||||||
|
// Manually set cursor to player pos (startTargeting might do it, but we ensure it)
|
||||||
|
targetingSystem.updateCursor(playerPos, playerPos);
|
||||||
|
|
||||||
|
const callback = vi.fn();
|
||||||
|
const result = targetingSystem.executeThrow(
|
||||||
|
mockWorld,
|
||||||
|
1 as EntityId,
|
||||||
|
{ getCombatant: vi.fn().mockReturnValue({ pos: playerPos, inventory: { items: [{ id: 'item-1' }] } }) } as any,
|
||||||
|
callback
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result).toBe(false);
|
||||||
|
expect(callback).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user