| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { EcsWorld } from "../src/ecs/world.js"; |
| 4 | import { Component } from "../src/ecs/components.js"; |
| 5 | import { stepStatusEffects } from "../src/statusEffects/service.js"; |
| 6 | import { applyStatusEffect, emptyStatusEffects, StatusEffectType } from "../../shared/statusEffects/rules.js"; |
| 7 | |
| 8 | test("health regen accumulates fractional HP across ticks", () => |
| 9 | { |
| 10 | const ecs = new EcsWorld(); |
| 11 | const entityId = 1; |
| 12 | const handle = ecs.spawn(entityId); |
| 13 | ecs.add(handle, Component.character, { characterId: 9 }); |
| 14 | ecs.add(handle, Component.health, { current: 10, max: 100 }); |
| 15 | const status = ecs.add(handle, Component.statusEffects, emptyStatusEffects()); |
| 16 | applyStatusEffect(status, { |
| 17 | type: StatusEffectType.healthRegen, |
| 18 | amountPerSecond: 1, |
| 19 | durationMs: 60_000 |
| 20 | }, 1_000_000); |
| 21 | const world = { ecs }; |
| 22 | const dt = 1 / 20; |
| 23 | for (let i = 0; i < 20; i++) |
| 24 | { stepStatusEffects(world, 1_000_000 + i * 50, dt); } |
| 25 | const health = ecs.get(handle, Component.health); |
| 26 | assert.ok(health.current >= 10.9, `expected ~11 HP after 1s, got ${health.current}`); |
| 27 | }); |