Skip to content

feat: add combat system foundation#5

Merged
amirna2 merged 7 commits intomainfrom
feat/combat-foundation
Mar 2, 2026
Merged

feat: add combat system foundation#5
amirna2 merged 7 commits intomainfrom
feat/combat-foundation

Conversation

@amirna2
Copy link
Owner

@amirna2 amirna2 commented Mar 2, 2026

Summary

  • Add combat system foundation: types, deterministic RNG, combat effects, combat engine, and Lua loader support for enemies/combat rules
  • Add --script <file> and --trace CLI flags for automated game playback (echo commands, skip # comments)
  • Fix attack_goblin rule to guard against re-triggering combat with Not(InCombat())

Key changes

  • types/ — New EnemyDef, CombatState, combat-related effect types
  • engine/rng.go — Deterministic RNG for reproducible combat rolls
  • engine/combat.go — Combat engine: turn resolution, damage calc, enemy behavior selection
  • engine/effects/ — New combat effects (start_combat, damage, end_combat, etc.)
  • engine/rules/conditions.goInCombat() condition for rule matching
  • engine/state/ — Combat state tracking on game state
  • loader/Enemy() and combat Lua API constructors, validation for enemy defs
  • cli/EchoInput field, # comment skipping, --script and --trace flags
  • games/lost_crown/enemies.lua — Sample goblin enemy with loot and combat rules
  • docs/design/ — Combat PRD, design doc, and implementation plan

Test plan

  • go test ./engine/... — combat engine, RNG, effects, conditions, state tests
  • go test ./loader/... — combat content loading tests
  • go test ./cli/... — echo input, comment skipping, existing CLI tests
  • make build && bin/questcore --script games/lost_crown/scripts/test_combat.txt games/lost_crown/ — end-to-end script playback
  • make ci — full CI passes

🤖 Generated with Claude Code

amirna2 and others added 7 commits February 25, 2026 21:11
Phase 1 of the combat system implementation. Adds the core infrastructure
for turn-based 1v1 combat that runs through the existing rules pipeline.

- Types: CombatState, BehaviorEntry, LootEntry, PlayerStats on GameDef
- Deterministic RNG with position tracking for save/load
- State helpers: InCombat(), GetStat(), SetStat() with override layering
- New effects: start_combat, end_combat, damage, heal, set_stat
- Combat engine: DamageCalc (1d6+atk-def, min 1), EnemyTurn (weighted AI),
  default attack/defend/flee behavior
- Step() modifications: combat command restriction, go→flee rewrite,
  enemy turn after player turn, round management
- Loader: Enemy constructor, combat condition/effect Lua helpers,
  enemy stat/behavior/loot compilation, validation
- Parser: defend/block/guard and flee/escape aliases
- Content: Lost Crown cave goblin encounter with auto-engage
- Design docs: combat PRD, technical design, implementation plan

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Prevents re-triggering combat when already in combat.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add --script <file> and --trace CLI flags for running scripted command
sequences. Commands are echoed after the prompt so output reads like an
interactive session. Lines starting with # are treated as comments.

Includes sample combat test script at games/lost_crown/scripts/test_combat.txt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The path to the goblin requires: take book, read book, talk to elara,
ask about passage, then push wall. Updated script with correct sequence.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The damage effect set alive=false and emitted enemy_defeated but never
cleared combat state, allowing dead enemies to keep acting. Now clears
combat state and emits combat_ended alongside enemy_defeated.

Adds integration tests through Step() to verify combat ends on defeat,
dead enemies don't get turns, and post-combat behavior is correct.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add ProcessLoot() that rolls each item in the enemy's loot table against
its chance percentage, producing give_item effects for successful drops
and inc_counter for gold. Wired into Step() after enemy_defeated event.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace defer f.Close() with explicit close before return to avoid
exitAfterDefer warning from gocritic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@amirna2 amirna2 merged commit 49bda23 into main Mar 2, 2026
2 checks passed
@amirna2 amirna2 deleted the feat/combat-foundation branch March 2, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant