From e3cb4ef7ac89774981ec952086a923b3f00ef554 Mon Sep 17 00:00:00 2001 From: cojoedmo Date: Thu, 25 Jun 2026 03:29:46 -0400 Subject: [PATCH] fixed earlier problem --- Enemy.cs | 6 +++--- EnemyController.cs | 34 ++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Enemy.cs b/Enemy.cs index 65ccea5..71ef6bd 100644 --- a/Enemy.cs +++ b/Enemy.cs @@ -16,8 +16,8 @@ public partial class Enemy : StaticBody2D public int _damage = 1, _health = 2, _stamina, _staminaRemaining, _visibilityRange = 4, _hitRange, _attackCost = 1; public Dictionary _priorities = new() { - {"attack", 0}, // 0 to 999999 reserved for attacking priorities - {"movement", 1000000} // 1000000 to 1999999 reserved for movement priorities + {"attack", 1000000}, // 1000000 to 1999999 reserved for attack priorities + {"movement", 0} // 0 to 999999 reserved for movement priorities }; public Vector2I _address = -Vector2I.One, _range = Vector2I.Up; public List _path = new(), _pathStored = new(); @@ -115,7 +115,7 @@ public partial class Enemy : StaticBody2D Tween subtween = CreateTween(); subtween.TweenProperty(this, "global_position", CONTROLLER._playArea._map.GetCellPositionFromAddress(PATH_STEP), 0.25f); int key = _priorities["movement"] + CONTROLLER._actionLoop; - + GD.Print(key); if (!CONTROLLER._tweenStages.ContainsKey(key)) { CONTROLLER._tweenStages[key] = new(); diff --git a/EnemyController.cs b/EnemyController.cs index 40a3998..e60ee3c 100644 --- a/EnemyController.cs +++ b/EnemyController.cs @@ -9,7 +9,7 @@ public partial class EnemyController : TurnController { public int _actionLoop = 0; public PackedScene _enemyScene = GD.Load("res://Enemy.tscn"); - public List _enemies = new(), _remainingEnemies = new(); + public List _enemies = new(); public PlayerController _playerController; public Dictionary> _tweenStages = new(); public Tween _tween; @@ -53,6 +53,11 @@ public partial class EnemyController : TurnController } } + + public List GetRemainingEnemies() + { + return [.. _enemies.Where(e => e.CanMove(this) || e.CanAttack(this))]; + } public void HandleEnemyActions() { @@ -62,16 +67,20 @@ public partial class EnemyController : TurnController _enemies.ForEach(e => e._path.Clear()); - _remainingEnemies = [.. _enemies.Where(e => e.CanMove(this) || e.CanAttack(this))]; - while (_remainingEnemies.Count > 0) + List remainingEnemies = GetRemainingEnemies(); + while (remainingEnemies.Count > 0) { - for (int i = 0; i < _remainingEnemies.Count; i++) + for (int i = 0; i < remainingEnemies.Count; i++) { - Enemy enemy = _remainingEnemies[i]; + Enemy enemy = remainingEnemies[i]; + if (!enemy.CanMove(this) && !enemy.CanAttack(this)) + { + GD.Print(i); + } HandleEnemyPathing(enemy); HandleEnemyAttacking(enemy); - HandleEnemyStaminaCheck(enemy); } + remainingEnemies = GetRemainingEnemies(); _actionLoop++; } } @@ -117,6 +126,7 @@ public partial class EnemyController : TurnController if (path.Count == 0) { + // ENEMY.Move(ENEMY._path.LastOrDefault(ENEMY._address), this); return; } @@ -135,14 +145,6 @@ public partial class EnemyController : TurnController _enemies = [.. _enemies.OrderBy(e => e._address.Y).ThenBy(e => e._path.Count).ThenBy(e => Math.Abs(e._address.X - _playArea._map._maxX / 2))]; } - public void HandleEnemyStaminaCheck(Enemy ENEMY) - { - if (ENEMY._staminaRemaining <= 0) - { - _remainingEnemies.Remove(ENEMY); - return; - } - } public void Initiate() { @@ -153,8 +155,8 @@ public partial class EnemyController : TurnController public void ProcessTween() { - _tweenStages.OrderBy(s => s.Key); - + _tweenStages = _tweenStages.OrderBy(s => s.Key).ToDictionary(); + GD.Print(string.Join(", ", _tweenStages.Keys)); if (_tweenStages.Count <= 0) { return;