From 50b2c04cb4a024eb8f25f8a1c9e1e2a0f72b2a35 Mon Sep 17 00:00:00 2001 From: jonathan Date: Tue, 4 Nov 2025 13:55:37 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20fighters=20keep=20fighti?= =?UTF-8?q?ng=20at=200=20hp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/CSharp/Common/Fight/FightHappening.cs | 13 ++++++++ scripts/CSharp/Common/Fight/FighterTurn.cs | 32 +++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/scripts/CSharp/Common/Fight/FightHappening.cs b/scripts/CSharp/Common/Fight/FightHappening.cs index e1df008..328710c 100644 --- a/scripts/CSharp/Common/Fight/FightHappening.cs +++ b/scripts/CSharp/Common/Fight/FightHappening.cs @@ -192,6 +192,8 @@ public partial class FightHappening : Node HappeningData.actionStaging = null; HappeningData.fightersEnterStaging = null; + RemoveDeadFighters(); + if (!FightWorld.Instance.allyFighters.IsAlive()) { ChangeState(FightState.EnemyWin); @@ -345,6 +347,17 @@ public partial class FightHappening : Node vesnaFighter.health = vesnaFighter.maxHealth; GD.Print("Vesna has been revived. This is for the current prototype only"); } + + private void RemoveDeadFighters() + { + foreach (var f in HappeningData.fighterTurn) + { + if (f.IsDead()) + { + HappeningData.fighterTurn.Remove(f); + } + } + } #endregion // Game Logic diff --git a/scripts/CSharp/Common/Fight/FighterTurn.cs b/scripts/CSharp/Common/Fight/FighterTurn.cs index 4f546d8..198afa5 100644 --- a/scripts/CSharp/Common/Fight/FighterTurn.cs +++ b/scripts/CSharp/Common/Fight/FighterTurn.cs @@ -1,9 +1,12 @@ using System; +using System.Collections; +using System.Collections.Generic; using System.Diagnostics; +using System.Linq; namespace Babushka.scripts.CSharp.Common.Fight; -public class FighterTurn +public class FighterTurn : IEnumerable { private class Node { @@ -13,7 +16,8 @@ public class FighterTurn private Node? _currentNode; - public FightWorld.Fighter Current => _currentNode?.fighter ?? throw new InvalidOperationException("No current fighter"); + public FightWorld.Fighter Current => + _currentNode?.fighter ?? throw new InvalidOperationException("No current fighter"); public void Next() { @@ -84,7 +88,7 @@ public class FighterTurn { // if removing current, keep current // it will be implicitly deleted by loss of reference on the next Next() call - + node.next = node.next.next; return true; } @@ -94,4 +98,26 @@ public class FighterTurn return false; } + + public IEnumerator GetEnumerator() + { + if (_currentNode == null) return Enumerable.Empty().GetEnumerator(); + + var list = new List(); + var n = _currentNode; + while (true) + { + list.Add(n.fighter); + if (n.next == _currentNode) + break; + n = n.next; + } + + return list.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } } \ No newline at end of file