# Health Regeneration and Pets Implementation Plan > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. **Goal:** Porter dans le jeu Godot la régénération passive automatique des PV et rendre le familier créé avec la partie réellement configurable, persistant et utile en exploration/combat, conformément aux comportements de référence de DCWASCII. **Architecture:** La formule de régénération reste une règle de domaine pure, appelée une seule fois à la fin de chaque tour résolu et appliquée silencieusement au joueur puis au familier vivant. Le familier reste l’agrégat `CompanionState` existant, enrichi avec son identité, ses caractéristiques de régénération et une IA agressive/défensive/soutien; la création, les transitions d’étage, l’UI et la sauvegarde consomment cet agrégat sans dupliquer les règles. **Tech Stack:** Godot 4.7, GDScript, GUT 9.5, scènes `.tscn`, sauvegardes JSON. **Spec:** Référence fonctionnelle `../DCWASCII/README.md` sections « Familier jouable » et « Système de soins », ainsi que `../DCWASCII/dcw/entities/{player,companion}.py`, `../DCWASCII/dcw/game.py`, `../DCWASCII/dcw/ai/companion_behaviors.py`. ## Global Constraints - Préserver tous les changements locaux déjà présents; ne pas réinitialiser ni réécrire les modifications non liées. - Régénération ASCII: `max(1, Endurance / 3)`, bonus `regen_bonus`, amplification de 15 % par rang de compétence Régénération au-delà du rang de base 1, puis multiplicateur de difficulté (1,5 / 1 / 0,75 / 0,5). - La régénération est silencieuse, plafonnée aux PV max, active dès le niveau 1, une fois par tour consommé, et ne ranime jamais une entité morte. - Le familier est optionnel, autonome, persistant, suit le joueur entre les étages et sa mort ne termine pas la partie. - Conserver les coutures publiques et les sauvegardes existantes compatibles. --- ### Task 1: Passive health regeneration rule **Files:** - Create: `scripts/domain/combat/health_regeneration.gd` - Test: `tests/unit/test_health_regeneration.gd` **Interfaces:** - Produces: `HealthRegeneration.amount(endurance: int, regeneration_skill: int, perk_bonus: int, difficulty_id: StringName) -> int` - Produces: `HealthRegeneration.apply(actor: ActorState, endurance: int, regeneration_skill: int, perk_bonus: int, difficulty_id: StringName) -> int` - [ ] **Step 1: Write the failing formula and cap/death tests** - [ ] **Step 2: Run the focused test and confirm RED because the rule does not exist** - [ ] **Step 3: Implement the exact ASCII formula and difficulty multipliers** - [ ] **Step 4: Run the focused test and confirm GREEN** ### Task 2: End-of-turn regeneration integration **Files:** - Modify: `scripts/game/game.gd` - Modify: `scripts/domain/entities/companion_state.gd` - Test: `tests/e2e/test_health_regeneration_e2e.gd` **Interfaces:** - Consumes: `HealthRegeneration.apply(...)` - Produces: automatic, silent player/pet healing through normal `submit_player_action` gameplay turns. - [ ] **Step 1: Add an E2E test that damages the player, consumes real movement turns and observes exact healing without a regeneration journal event** - [ ] **Step 2: Run it and confirm RED because completed turns do not heal** - [ ] **Step 3: Add one centralized end-of-turn hook using the character model’s effective Endurance/skill/perk values and the run difficulty** - [ ] **Step 4: Extend the test to a living pet and confirm dead actors remain at zero** - [ ] **Step 5: Run focused unit/E2E tests and confirm GREEN** ### Task 3: Configurable pet identity and persistence **Files:** - Modify: `scripts/domain/run/run_settings.gd` - Modify: `scripts/domain/entities/companion_state.gd` - Modify: `scripts/presentation/menu/character_creation.gd` - Modify: `scenes/menu/CharacterCreation.tscn` - Modify: `scripts/infrastructure/save/save_repository.gd` - Modify: `scripts/presentation/companion_panel.gd` - Test: `tests/unit/test_companion.gd` - Test: `tests/unit/test_save_repository.gd` - Test: `tests/e2e/test_new_run_creation_e2e.gd` **Interfaces:** - Produces: optional `RunSettings.pet_name` and `RunSettings.pet_species`, with backward-compatible defaults. - Produces: `CompanionState.name`, `species`, Endurance/skill/perk regeneration fields serialized with the companion. - [ ] **Step 1: Add failing tests for identity defaults/custom values and save/load round-trip** - [ ] **Step 2: Run focused tests and confirm RED** - [ ] **Step 3: Add name/species fields shown only when the pet checkbox is enabled and pass them through `RunSettings`** - [ ] **Step 4: Persist the complete companion record while accepting legacy companion records** - [ ] **Step 5: Show name, species and PV in the companion panel** - [ ] **Step 6: Run focused tests and confirm GREEN** ### Task 4: Functional autonomous pet behavior and floor following **Files:** - Modify: `scripts/domain/ai/companion_behaviors.gd` - Modify: `scripts/domain/turn_resolver.gd` - Modify: `scripts/game/game.gd` - Test: `tests/unit/test_companion.gd` - Test: `tests/e2e/test_pet_companion_e2e.gd` **Interfaces:** - Consumes: existing stances `FOLLOW`, `DEFEND`, `SUPPORT` as backward-compatible storage identifiers. - Produces: aggressive chase/attack for `FOLLOW`, threat interception for `DEFEND`, low-PV player healing for `SUPPORT`, nearest-target enemy attacks, and adjacent pet placement after floor changes. - [ ] **Step 1: Add one failing behavior test for aggressive chase and one for support healing** - [ ] **Step 2: Run focused tests and confirm RED for the missing decisions** - [ ] **Step 3: Implement deterministic nearest-enemy pursuit and a bounded support-heal action** - [ ] **Step 4: Resolve heal actions and make enemies pursue/attack the nearer living player or pet, with ties favoring the pet** - [ ] **Step 5: Add an E2E floor-transition assertion that the pet is placed next to the player** - [ ] **Step 6: Run pet unit/integration/E2E tests and confirm GREEN** ### Task 5: Verification and parity evidence **Files:** - Modify: `docs/parity/ASCII_TEST_MATRIX.md` only if a new explicit mapping row/note is required. - [ ] **Step 1: Run unit tests for regeneration, companions, settings and saves** - [ ] **Step 2: Run pet/new-run/regeneration E2E tests** - [ ] **Step 3: Run the project verification script and inspect failures** - [ ] **Step 4: Confirm `git diff --check` and review the final diff for unrelated changes**