From 914e2d5c9b1d2e7a2a3dc254955e695ceff61c8f Mon Sep 17 00:00:00 2001 From: Christophe Del Vecchio Date: Thu, 1 Oct 2026 12:43:04 +0200 Subject: [PATCH] fix: harden gameplay state transitions --- .gitignore | 4 + Scripts/tests/test_gameplay_blockers.py | 96 +++++++++++++++ Source/pogo/Variant_Combat/AI/CombatEnemy.cpp | 73 +++++++----- .../AI/CombatStateTreeUtility.cpp | 2 +- .../pogo/Variant_Combat/CombatCharacter.cpp | 68 ++++++----- .../PlatformingCharacter.cpp | 25 ++-- .../SideScrollingCharacter.cpp | 2 + .../plans/2026-10-01-gameplay-blockers.md | 112 ++++++++++++++++++ 8 files changed, 314 insertions(+), 68 deletions(-) create mode 100644 Scripts/tests/test_gameplay_blockers.py create mode 100644 docs/superpowers/plans/2026-10-01-gameplay-blockers.md diff --git a/.gitignore b/.gitignore index edc4350..d78e39e 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,10 @@ ArchivedBuilds/ .DS_Store ._* +# --- Python tooling --- +__pycache__/ +*.py[cod] + # --- Per-developer content (keep Developers/ local) --- Content/Developers/ Content/Collections/ diff --git a/Scripts/tests/test_gameplay_blockers.py b/Scripts/tests/test_gameplay_blockers.py new file mode 100644 index 0000000..e0a6394 --- /dev/null +++ b/Scripts/tests/test_gameplay_blockers.py @@ -0,0 +1,96 @@ +"""Fast regression checks for gameplay control-flow blockers. + +These tests intentionally inspect the small C++ functions at issue. The Unreal +editor build remains the integration gate for syntax, types, and engine APIs. +""" +from pathlib import Path +import unittest + + +ROOT = Path(__file__).resolve().parents[2] + + +def source(relative_path: str) -> str: + return (ROOT / relative_path).read_text(encoding="utf-8") + + +def function_body(relative_path: str, signature: str) -> str: + text = source(relative_path) + start = text.index(signature) + open_brace = text.index("{", start) + depth = 0 + for index in range(open_brace, len(text)): + if text[index] == "{": + depth += 1 + elif text[index] == "}": + depth -= 1 + if depth == 0: + return text[open_brace + 1:index] + raise AssertionError(f"Unclosed function body for {signature}") + + +class GameplayBlockerTests(unittest.TestCase): + def test_set_character_speed_finishes_synchronously(self): + body = function_body( + "Source/pogo/Variant_Combat/AI/CombatStateTreeUtility.cpp", + "FStateTreeSetCharacterSpeedTask::EnterState", + ) + self.assertIn("return EStateTreeRunStatus::Succeeded;", body) + self.assertNotIn("return EStateTreeRunStatus::Running;", body) + + def test_dash_commits_state_only_after_montage_starts(self): + body = function_body( + "Source/pogo/Variant_Platforming/PlatformingCharacter.cpp", + "void APlatformingCharacter::DoDash()", + ) + self.assertIn("if (!AnimInstance || !DashMontage)", body) + self.assertIn("MontageLength <= 0.0f", body) + play = body.index("Montage_Play") + success_guard = body.index("MontageLength <= 0.0f") + state_commit = body.index("bIsDashing = true;") + self.assertLess(play, success_guard) + self.assertLess(success_guard, state_commit) + + def test_attacks_commit_state_only_after_montage_starts(self): + cases = [ + ("Source/pogo/Variant_Combat/CombatCharacter.cpp", "void ACombatCharacter::ComboAttack()", False), + ("Source/pogo/Variant_Combat/CombatCharacter.cpp", "void ACombatCharacter::ChargedAttack()", False), + ("Source/pogo/Variant_Combat/AI/CombatEnemy.cpp", "void ACombatEnemy::DoAIComboAttack()", True), + ("Source/pogo/Variant_Combat/AI/CombatEnemy.cpp", "void ACombatEnemy::DoAIChargedAttack()", True), + ] + for path, signature, must_finish_state_tree in cases: + with self.subTest(signature=signature): + body = function_body(path, signature) + self.assertIn("MontageLength <= 0.0f", body) + play = body.index("Montage_Play") + success_guard = body.index("MontageLength <= 0.0f") + state_commit = body.index("bIsAttacking = true;") + self.assertLess(play, success_guard) + self.assertLess(success_guard, state_commit) + if must_finish_state_tree: + self.assertGreaterEqual(body.count("OnAttackCompleted.ExecuteIfBound();"), 2) + + def test_side_scrolling_landed_calls_base_first(self): + body = function_body( + "Source/pogo/Variant_SideScrolling/SideScrollingCharacter.cpp", + "void ASideScrollingCharacter::Landed(const FHitResult& Hit)", + ) + self.assertIn("Super::Landed(Hit);", body) + self.assertLess(body.index("Super::Landed(Hit);"), body.index("bHasDoubleJumped = false;")) + + def test_attack_traces_deduplicate_actors(self): + cases = [ + ("Source/pogo/Variant_Combat/CombatCharacter.cpp", "ACombatCharacter::DoAttackTrace"), + ("Source/pogo/Variant_Combat/AI/CombatEnemy.cpp", "ACombatEnemy::DoAttackTrace"), + ] + for path, signature in cases: + with self.subTest(signature=signature): + body = function_body(path, signature) + self.assertIn("TSet DamagedActors;", body) + self.assertIn("DamagedActors.Contains(HitActor)", body) + self.assertIn("DamagedActors.Add(HitActor);", body) + self.assertLess(body.index("DamagedActors.Add(HitActor);"), body.index("Damageable->ApplyDamage")) + + +if __name__ == "__main__": + unittest.main() diff --git a/Source/pogo/Variant_Combat/AI/CombatEnemy.cpp b/Source/pogo/Variant_Combat/AI/CombatEnemy.cpp index 393957f..3ff7a4f 100644 --- a/Source/pogo/Variant_Combat/AI/CombatEnemy.cpp +++ b/Source/pogo/Variant_Combat/AI/CombatEnemy.cpp @@ -50,7 +50,21 @@ void ACombatEnemy::DoAIComboAttack() return; } - // raise the attacking flag + UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance(); + if (!AnimInstance || !ComboAttackMontage) + { + OnAttackCompleted.ExecuteIfBound(); + return; + } + + const float MontageLength = AnimInstance->Montage_Play(ComboAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true); + if (MontageLength <= 0.0f) + { + OnAttackCompleted.ExecuteIfBound(); + return; + } + + // raise the attacking flag only after the montage starts bIsAttacking = true; // choose how many times we're going to attack @@ -59,18 +73,8 @@ void ACombatEnemy::DoAIComboAttack() // reset the attack counter CurrentComboAttack = 0; - // play the attack montage - if (UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance()) - { - const float MontageLength = AnimInstance->Montage_Play(ComboAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true); - - // subscribe to montage completed and interrupted events - if (MontageLength > 0.0f) - { - // set the end delegate for the montage - AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ComboAttackMontage); - } - } + // set the end delegate for the montage + AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ComboAttackMontage); } void ACombatEnemy::DoAIChargedAttack() @@ -81,7 +85,21 @@ void ACombatEnemy::DoAIChargedAttack() return; } - // raise the attacking flag + UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance(); + if (!AnimInstance || !ChargedAttackMontage) + { + OnAttackCompleted.ExecuteIfBound(); + return; + } + + const float MontageLength = AnimInstance->Montage_Play(ChargedAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true); + if (MontageLength <= 0.0f) + { + OnAttackCompleted.ExecuteIfBound(); + return; + } + + // raise the attacking flag only after the montage starts bIsAttacking = true; // choose how many loops are we going to charge for @@ -90,18 +108,8 @@ void ACombatEnemy::DoAIChargedAttack() // reset the charge loop counter CurrentChargeLoop = 0; - // play the attack montage - if (UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance()) - { - const float MontageLength = AnimInstance->Montage_Play(ChargedAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true); - - // subscribe to montage completed and interrupted events - if (MontageLength > 0.0f) - { - // set the end delegate for the montage - AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ChargedAttackMontage); - } - } + // set the end delegate for the montage + AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ChargedAttackMontage); } void ACombatEnemy::AttackMontageEnded(UAnimMontage* Montage, bool bInterrupted) @@ -127,6 +135,7 @@ void ACombatEnemy::DoAttackTrace(FName DamageSourceBone) { // sweep for objects in front of the character to be hit by the attack TArray OutHits; + TSet DamagedActors; // start at the provided socket location, sweep forward const FVector TraceStart = GetMesh()->GetSocketLocation(DamageSourceBone); @@ -149,14 +158,22 @@ void ACombatEnemy::DoAttackTrace(FName DamageSourceBone) // iterate over each object hit for (const FHitResult& CurrentHit : OutHits) { + AActor* HitActor = CurrentHit.GetActor(); + if (!HitActor || DamagedActors.Contains(HitActor)) + { + continue; + } + /** does the actor have the player tag? */ - if (CurrentHit.GetActor()->ActorHasTag(FName("Player"))) + if (HitActor->ActorHasTag(FName("Player"))) { // check if the actor is damageable - ICombatDamageable* Damageable = Cast(CurrentHit.GetActor()); + ICombatDamageable* Damageable = Cast(HitActor); if (Damageable) { + DamagedActors.Add(HitActor); + // knock upwards and away from the impact normal const FVector Impulse = (CurrentHit.ImpactNormal * -MeleeKnockbackImpulse) + (FVector::UpVector * MeleeLaunchImpulse); diff --git a/Source/pogo/Variant_Combat/AI/CombatStateTreeUtility.cpp b/Source/pogo/Variant_Combat/AI/CombatStateTreeUtility.cpp index 4bd8a96..29d6043 100644 --- a/Source/pogo/Variant_Combat/AI/CombatStateTreeUtility.cpp +++ b/Source/pogo/Variant_Combat/AI/CombatStateTreeUtility.cpp @@ -240,7 +240,7 @@ EStateTreeRunStatus FStateTreeSetCharacterSpeedTask::EnterState(FStateTreeExecut // set the character's max ground speed InstanceData.Character->GetCharacterMovement()->MaxWalkSpeed = InstanceData.Speed; - return EStateTreeRunStatus::Running; + return EStateTreeRunStatus::Succeeded; } #if WITH_EDITOR diff --git a/Source/pogo/Variant_Combat/CombatCharacter.cpp b/Source/pogo/Variant_Combat/CombatCharacter.cpp index 1dc04bd..316577f 100644 --- a/Source/pogo/Variant_Combat/CombatCharacter.cpp +++ b/Source/pogo/Variant_Combat/CombatCharacter.cpp @@ -190,7 +190,19 @@ void ACombatCharacter::ResetHP() void ACombatCharacter::ComboAttack() { - // raise the attacking flag + UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance(); + if (!AnimInstance || !ComboAttackMontage) + { + return; + } + + const float MontageLength = AnimInstance->Montage_Play(ComboAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true); + if (MontageLength <= 0.0f) + { + return; + } + + // raise the attacking flag only after the montage starts bIsAttacking = true; // reset the combo count @@ -199,24 +211,25 @@ void ACombatCharacter::ComboAttack() // notify enemies they are about to be attacked NotifyEnemiesOfIncomingAttack(); - // play the attack montage - if (UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance()) - { - const float MontageLength = AnimInstance->Montage_Play(ComboAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true); - - // subscribe to montage completed and interrupted events - if (MontageLength > 0.0f) - { - // set the end delegate for the montage - AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ComboAttackMontage); - } - } - + // set the end delegate for the montage + AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ComboAttackMontage); } void ACombatCharacter::ChargedAttack() { - // raise the attacking flag + UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance(); + if (!AnimInstance || !ChargedAttackMontage) + { + return; + } + + const float MontageLength = AnimInstance->Montage_Play(ChargedAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true); + if (MontageLength <= 0.0f) + { + return; + } + + // raise the attacking flag only after the montage starts bIsAttacking = true; // reset the charge loop flag @@ -228,18 +241,8 @@ void ACombatCharacter::ChargedAttack() // notify enemies they are about to be attacked NotifyEnemiesOfIncomingAttack(); - // play the charged attack montage - if (UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance()) - { - const float MontageLength = AnimInstance->Montage_Play(ChargedAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true); - - // subscribe to montage completed and interrupted events - if (MontageLength > 0.0f) - { - // set the end delegate for the montage - AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ChargedAttackMontage); - } - } + // set the end delegate for the montage + AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ChargedAttackMontage); } void ACombatCharacter::AttackMontageEnded(UAnimMontage* Montage, bool bInterrupted) @@ -268,6 +271,7 @@ void ACombatCharacter::DoAttackTrace(FName DamageSourceBone) { // sweep for objects in front of the character to be hit by the attack TArray OutHits; + TSet DamagedActors; // start at the provided socket location, sweep forward const FVector TraceStart = GetMesh()->GetSocketLocation(DamageSourceBone); @@ -291,11 +295,19 @@ void ACombatCharacter::DoAttackTrace(FName DamageSourceBone) // iterate over each object hit for (const FHitResult& CurrentHit : OutHits) { + AActor* HitActor = CurrentHit.GetActor(); + if (!HitActor || DamagedActors.Contains(HitActor)) + { + continue; + } + // check if we've hit a damageable actor - ICombatDamageable* Damageable = Cast(CurrentHit.GetActor()); + ICombatDamageable* Damageable = Cast(HitActor); if (Damageable) { + DamagedActors.Add(HitActor); + // knock upwards and away from the impact normal const FVector Impulse = (CurrentHit.ImpactNormal * -MeleeKnockbackImpulse) + (FVector::UpVector * MeleeLaunchImpulse); diff --git a/Source/pogo/Variant_Platforming/PlatformingCharacter.cpp b/Source/pogo/Variant_Platforming/PlatformingCharacter.cpp index 53b8fea..f48d545 100644 --- a/Source/pogo/Variant_Platforming/PlatformingCharacter.cpp +++ b/Source/pogo/Variant_Platforming/PlatformingCharacter.cpp @@ -238,6 +238,19 @@ void APlatformingCharacter::DoDash() if (bHasDashed) return; + // Validate the montage before committing any dash state. + UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance(); + if (!AnimInstance || !DashMontage) + { + return; + } + + const float MontageLength = AnimInstance->Montage_Play(DashMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true); + if (MontageLength <= 0.0f) + { + return; + } + // raise the dash flags bIsDashing = true; bHasDashed = true; @@ -251,17 +264,7 @@ void APlatformingCharacter::DoDash() // enable the jump trails SetJumpTrailState(true); - // play the dash montage - if (UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance()) - { - const float MontageLength = AnimInstance->Montage_Play(DashMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true); - - // has the montage played successfully? - if (MontageLength > 0.0f) - { - AnimInstance->Montage_SetEndDelegate(OnDashMontageEnded, DashMontage); - } - } + AnimInstance->Montage_SetEndDelegate(OnDashMontageEnded, DashMontage); } void APlatformingCharacter::DoJumpStart() diff --git a/Source/pogo/Variant_SideScrolling/SideScrollingCharacter.cpp b/Source/pogo/Variant_SideScrolling/SideScrollingCharacter.cpp index b11faa5..994cf67 100644 --- a/Source/pogo/Variant_SideScrolling/SideScrollingCharacter.cpp +++ b/Source/pogo/Variant_SideScrolling/SideScrollingCharacter.cpp @@ -117,6 +117,8 @@ void ASideScrollingCharacter::NotifyHit(class UPrimitiveComponent* MyComp, AActo void ASideScrollingCharacter::Landed(const FHitResult& Hit) { + Super::Landed(Hit); + // reset the double jump bHasDoubleJumped = false; } diff --git a/docs/superpowers/plans/2026-10-01-gameplay-blockers.md b/docs/superpowers/plans/2026-10-01-gameplay-blockers.md new file mode 100644 index 0000000..453f72b --- /dev/null +++ b/docs/superpowers/plans/2026-10-01-gameplay-blockers.md @@ -0,0 +1,112 @@ +# Gameplay Blockers Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Remove the five identified gameplay deadlocks/regressions without changing the intended successful gameplay paths. + +**Architecture:** Keep fixes local to the existing character and StateTree implementations. Add a fast source-level regression suite for exact control-flow invariants, then compile the complete Unreal editor target as the integration gate. + +**Tech Stack:** Unreal Engine 5.8, C++20, Python 3 `unittest`, UnrealBuildTool on macOS. + +**Spec:** User request in this conversation: fix the five gameplay blockers identified by the project audit. + +## Global Constraints + +- Fix only: synchronous StateTree completion, dash montage failure, attack montage failure, Side Scrolling base landing call, and per-trace hit deduplication. +- Preserve successful montage behavior and Blueprint hooks. +- No dependency changes, broad refactor, commit, push, or binary asset edit. +- Tests must be observed failing before production edits and passing afterward. +- Final verification requires the regression suite, a full `pogoEditor Mac Development` build, and a clean tracked diff check. + +## Review Focus + +- A missing dash montage must not consume dash state or change gravity/trails. +- Missing player attack montages must leave the player available for the next input. +- Missing enemy attack montages must finish the waiting StateTree task. +- One actor exposed through multiple hit results must receive one damage event per trace. +- Side Scrolling landing must retain `ACharacter` landing notifications before resetting local jump state. + +--- + +### Task 1: Add the red regression suite + +**Files:** +- Create: `Scripts/tests/test_gameplay_blockers.py` + +**Interfaces:** +- Consumes: current C++ source text. +- Produces: five deterministic regression checks, one for each blocker. + +- [ ] Write tests that extract exact C++ function bodies and assert the required control-flow invariants. +- [ ] Run `python3 -m unittest Scripts.tests.test_gameplay_blockers -v`. +- [ ] Confirm all five tests fail against the current implementation for the expected missing guards/calls. + +### Task 2: Complete the synchronous StateTree speed task + +**Files:** +- Modify: `Source/pogo/Variant_Combat/AI/CombatStateTreeUtility.cpp:235-244` + +**Interfaces:** +- Consumes: StateTree task entry contract. +- Produces: `EnterState` returns `Succeeded` after applying `MaxWalkSpeed`. + +- [ ] Change only the terminal status from `Running` to `Succeeded`. +- [ ] Run the focused StateTree regression test and confirm green. + +### Task 3: Make montage startup transactional + +**Files:** +- Modify: `Source/pogo/Variant_Platforming/PlatformingCharacter.cpp:235-265` +- Modify: `Source/pogo/Variant_Combat/CombatCharacter.cpp:191-243` +- Modify: `Source/pogo/Variant_Combat/AI/CombatEnemy.cpp:45-105` + +**Interfaces:** +- Consumes: `UAnimInstance::Montage_Play`, where a value `<= 0` means startup failed. +- Produces: gameplay flags and side effects are committed only after successful montage startup; AI failure executes `OnAttackCompleted` so StateTree can advance. + +- [ ] Guard null AnimInstance and montage before mutating dash/attack state. +- [ ] Guard `Montage_Play <= 0` before mutating state. +- [ ] Keep delegate installation on the successful path. +- [ ] Notify enemy StateTree completion on both failure paths. +- [ ] Run the focused dash and attack regression tests and confirm green. + +### Task 4: Preserve base landing behavior + +**Files:** +- Modify: `Source/pogo/Variant_SideScrolling/SideScrollingCharacter.cpp:118-122` + +**Interfaces:** +- Consumes: `ACharacter::Landed` lifecycle. +- Produces: base landing notifications execute before local double-jump reset. + +- [ ] Call `Super::Landed(Hit)` first. +- [ ] Run the focused landing regression test and confirm green. + +### Task 5: Deduplicate melee hits per trace + +**Files:** +- Modify: `Source/pogo/Variant_Combat/CombatCharacter.cpp:267-310` +- Modify: `Source/pogo/Variant_Combat/AI/CombatEnemy.cpp:126-170` + +**Interfaces:** +- Consumes: `SweepMultiByObjectType` hit arrays, which may contain several components from one actor. +- Produces: a local `TSet` applies damage once per actor for each trace invocation. + +- [ ] Resolve and null-check `HitActor` once per result. +- [ ] Skip actors already present in the per-call set. +- [ ] Add the actor before calling `ApplyDamage`. +- [ ] Run the focused deduplication regression test and confirm green. + +### Task 6: Full verification and review + +**Files:** +- Verify all modified source and test files. + +**Interfaces:** +- Consumes: Tasks 1-5. +- Produces: green regression suite and compiled editor target. + +- [ ] Run `python3 -m unittest Scripts.tests.test_gameplay_blockers -v`. +- [ ] Build `pogoEditor Mac Development` with UnrealBuildTool. +- [ ] Run `git diff --check` and inspect `git diff --stat` plus `git status`. +- [ ] Request a fresh whole-change code review; fix only Critical/Important findings with another red-green cycle.