BlueGit

timfa questward

Files

questward / server / tests / passive-regen.test.js

passive-regen.test.js

passive-regen.test.js 1.1 KiB Download Raw
1import test from "node:test";
2import assert from "node:assert/strict";
3import { EcsWorld } from "../src/ecs/world.js";
4import { Component } from "../src/ecs/components.js";
5import { stepPassiveHealthRegen } from "../src/combat/service.js";
6import
7{
8 markHealthDamaged,
9 PASSIVE_HP_REGEN_DELAY_MS
10} from "../../shared/combat/passiveRegen.js";
11
12test("passive health regen waits one minute after damage", () =>
13{
14 const ecs = new EcsWorld();
15 const entityId = 1;
16 const handle = ecs.spawn(entityId);
17 ecs.add(handle, Component.position, { tileX: 8, tileY: 8 });
18 ecs.add(handle, Component.health, { current: 10, max: 100 });
19 const world = {
20 ecs,
21 chunkIsSimulating: () => true
22 };
23 const now = 1_000_000;
24 markHealthDamaged(ecs.get(handle, Component.health), now);
25 stepPassiveHealthRegen(world, now + PASSIVE_HP_REGEN_DELAY_MS - 1, 1);
26 assert.equal(ecs.get(handle, Component.health).current, 10);
27 const events = stepPassiveHealthRegen(world, now + PASSIVE_HP_REGEN_DELAY_MS + 10_000, 10);
28 assert.ok(events.some((event) => event.type === "entity-health"));
29 assert.ok(ecs.get(handle, Component.health).current > 10);
30});