fixed earlier problem
This commit is contained in:
@@ -16,8 +16,8 @@ public partial class Enemy : StaticBody2D
|
|||||||
public int _damage = 1, _health = 2, _stamina, _staminaRemaining, _visibilityRange = 4, _hitRange, _attackCost = 1;
|
public int _damage = 1, _health = 2, _stamina, _staminaRemaining, _visibilityRange = 4, _hitRange, _attackCost = 1;
|
||||||
public Dictionary<string, int> _priorities = new()
|
public Dictionary<string, int> _priorities = new()
|
||||||
{
|
{
|
||||||
{"attack", 0}, // 0 to 999999 reserved for attacking priorities
|
{"attack", 1000000}, // 1000000 to 1999999 reserved for attack priorities
|
||||||
{"movement", 1000000} // 1000000 to 1999999 reserved for movement priorities
|
{"movement", 0} // 0 to 999999 reserved for movement priorities
|
||||||
};
|
};
|
||||||
public Vector2I _address = -Vector2I.One, _range = Vector2I.Up;
|
public Vector2I _address = -Vector2I.One, _range = Vector2I.Up;
|
||||||
public List<Vector2I> _path = new(), _pathStored = new();
|
public List<Vector2I> _path = new(), _pathStored = new();
|
||||||
@@ -115,7 +115,7 @@ public partial class Enemy : StaticBody2D
|
|||||||
Tween subtween = CreateTween();
|
Tween subtween = CreateTween();
|
||||||
subtween.TweenProperty(this, "global_position", CONTROLLER._playArea._map.GetCellPositionFromAddress(PATH_STEP), 0.25f);
|
subtween.TweenProperty(this, "global_position", CONTROLLER._playArea._map.GetCellPositionFromAddress(PATH_STEP), 0.25f);
|
||||||
int key = _priorities["movement"] + CONTROLLER._actionLoop;
|
int key = _priorities["movement"] + CONTROLLER._actionLoop;
|
||||||
|
GD.Print(key);
|
||||||
if (!CONTROLLER._tweenStages.ContainsKey(key))
|
if (!CONTROLLER._tweenStages.ContainsKey(key))
|
||||||
{
|
{
|
||||||
CONTROLLER._tweenStages[key] = new();
|
CONTROLLER._tweenStages[key] = new();
|
||||||
|
|||||||
+18
-16
@@ -9,7 +9,7 @@ public partial class EnemyController : TurnController
|
|||||||
{
|
{
|
||||||
public int _actionLoop = 0;
|
public int _actionLoop = 0;
|
||||||
public PackedScene _enemyScene = GD.Load<PackedScene>("res://Enemy.tscn");
|
public PackedScene _enemyScene = GD.Load<PackedScene>("res://Enemy.tscn");
|
||||||
public List<Enemy> _enemies = new(), _remainingEnemies = new();
|
public List<Enemy> _enemies = new();
|
||||||
public PlayerController _playerController;
|
public PlayerController _playerController;
|
||||||
public Dictionary<int, List<Tween>> _tweenStages = new();
|
public Dictionary<int, List<Tween>> _tweenStages = new();
|
||||||
public Tween _tween;
|
public Tween _tween;
|
||||||
@@ -53,6 +53,11 @@ public partial class EnemyController : TurnController
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Enemy> GetRemainingEnemies()
|
||||||
|
{
|
||||||
|
return [.. _enemies.Where(e => e.CanMove(this) || e.CanAttack(this))];
|
||||||
|
}
|
||||||
|
|
||||||
public void HandleEnemyActions()
|
public void HandleEnemyActions()
|
||||||
{
|
{
|
||||||
@@ -62,16 +67,20 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
_enemies.ForEach(e => e._path.Clear());
|
_enemies.ForEach(e => e._path.Clear());
|
||||||
|
|
||||||
_remainingEnemies = [.. _enemies.Where(e => e.CanMove(this) || e.CanAttack(this))];
|
List<Enemy> remainingEnemies = GetRemainingEnemies();
|
||||||
while (_remainingEnemies.Count > 0)
|
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);
|
HandleEnemyPathing(enemy);
|
||||||
HandleEnemyAttacking(enemy);
|
HandleEnemyAttacking(enemy);
|
||||||
HandleEnemyStaminaCheck(enemy);
|
|
||||||
}
|
}
|
||||||
|
remainingEnemies = GetRemainingEnemies();
|
||||||
_actionLoop++;
|
_actionLoop++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,6 +126,7 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
if (path.Count == 0)
|
if (path.Count == 0)
|
||||||
{
|
{
|
||||||
|
// ENEMY.Move(ENEMY._path.LastOrDefault(ENEMY._address), this);
|
||||||
return;
|
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))];
|
_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()
|
public void Initiate()
|
||||||
{
|
{
|
||||||
@@ -153,8 +155,8 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
public void ProcessTween()
|
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)
|
if (_tweenStages.Count <= 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user