Files
2026-08-16 19:10:31 +02:00

15 lines
1.8 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
==> Dispatch: phase 2 combat
supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty'
supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty'
`engine/combat.py` done — the only file touched.
**API** (for the gate integrator and AI/bow workers):
- `hit_chance(attacker, defender, hit_bonus=0.0) -> float` — plan formula `clamp(0.7 + (acc−eva)*0.05 + hit_bonus, 0.1, 0.95)`
- `attack(attacker, defender, log=None, hit_bonus=0.0, base_power=None) -> AttackResult` — resolves one attack: roll hit → `max(0, power + weapon_bonus − armor)` → crit doubles → HP clamps at 0 → logs. `hit_bonus` (negative, pre-clamp) and `base_power` cover ranged distance penalties / `ranged_power` so behaviors and the bow reuse the same resolution. `AttackResult(hit, crit, damage, killed)` drives entity removal and Phase 4 juice.
**Verified:** 1000 simulated attacks → 94.6% hit (expected 95%), 9% crit (expected 10%), avg dmg 3.10 vs 3.13 expected; clamps at both ends; 0-damage hit vs armor-8 dragon (no crash); kill → HP 0, XP awarded, exact `"You defeated the Goblin! (+12 XP)"` log; player-death and miss logs both directions; log trimmed to last 50; weapon bonus picked up from `equipped_weapon.power` (Phase 3 items land without touching this file). `tests/smoke.py --phase 1` still PASS.
Notes:
- Log goes through the session's list (`attack(..., session.log)` once `game_state.py` lands) — that type is `list[str]`, matching what was asked.
- Combat tuning constants live module-level here instead of `constants.py` so parallel Phase 2 workers never edit the same file; `attack()` awards XP but leaves level-ups to `entities/player.py` per plan §7. Entity removal from the floor is the caller's job, signaled by `killed`.