Battle end reports the real outcome

Both result screens set IsDestroyed before ClearBattle, which derived the
result from that flag, so BattleEndedEvent.Result was always "defeat".
The screens now pass the outcome in.
This commit is contained in:
cthangover committed 2026-10-21 13:22:17 +02:00
1 parent 10f5b3455b
commit 392b1caf0a
1 file changed
+10 -4
+10 -4
View File
@@ -292,7 +292,7 @@ namespace Cthangover.Core.Battle
return; return;
IsDestroyed = true; IsDestroyed = true;
_battleSpeedControl?.ResetToNormal(); _battleSpeedControl?.ResetToNormal();
ClearBattle(); ClearBattle("defeat");
deadground?.Show(); deadground?.Show();
} }
@@ -307,7 +307,7 @@ namespace Cthangover.Core.Battle
return; return;
IsDestroyed = true; IsDestroyed = true;
_battleSpeedControl?.ResetToNormal(); _battleSpeedControl?.ResetToNormal();
ClearBattle(); ClearBattle("victory");
winground?.Show(); winground?.Show();
} }
@@ -346,7 +346,13 @@ namespace Cthangover.Core.Battle
} }
} }
private void ClearBattle() /// <summary>
/// Stops the battle and publishes <see cref="BattleEndedEvent"/>. The
/// outcome is passed in by the caller: both screens set
/// <see cref="IsDestroyed"/> before clearing, so it cannot be derived
/// from that flag (it used to be, and every battle reported "defeat").
/// </summary>
private void ClearBattle(string result)
{ {
BattleActionMachine?.StopMachine(); BattleActionMachine?.StopMachine();
ActiveCharacter = null; ActiveCharacter = null;
@@ -355,7 +361,7 @@ namespace Cthangover.Core.Battle
OnBattleCleared?.Invoke(); OnBattleCleared?.Invoke();
ModEventBus.Publish(new BattleEndedEvent ModEventBus.Publish(new BattleEndedEvent
{ {
Result = IsDestroyed ? "defeat" : "victory", Result = result,
}); });
} }
} }