reverting to prior change
This commit is contained in:
+77
-75
@@ -11,8 +11,8 @@ public partial class EnemyController : TurnController
|
|||||||
public PackedScene _enemyScene = GD.Load<PackedScene>("res://Enemy.tscn");
|
public PackedScene _enemyScene = GD.Load<PackedScene>("res://Enemy.tscn");
|
||||||
public List<Enemy> _enemies = new();
|
public List<Enemy> _enemies = new();
|
||||||
public PlayerController _playerController;
|
public PlayerController _playerController;
|
||||||
|
public Dictionary<float, List<Tween>> _tweenStages = new();
|
||||||
public Tween _movementTween;
|
public Tween _tween;
|
||||||
|
|
||||||
public void AddEnemies(int ENEMY_COUNT = 1)
|
public void AddEnemies(int ENEMY_COUNT = 1)
|
||||||
{
|
{
|
||||||
@@ -54,6 +54,52 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task BuildAnimationTween()
|
||||||
|
{
|
||||||
|
_tweenStages.Clear();
|
||||||
|
for (int i= 0; i < _enemies.Count; i++)
|
||||||
|
{
|
||||||
|
Enemy enemy = _enemies[i];
|
||||||
|
await enemy.AnimateMovement(this);
|
||||||
|
}
|
||||||
|
_tweenStages.OrderBy(s => s.Key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task BuildEnemyPaths()
|
||||||
|
{
|
||||||
|
Map map = _playArea._map;
|
||||||
|
|
||||||
|
_enemies.ForEach(e => e._path.Clear());
|
||||||
|
|
||||||
|
while (_enemies.Any(e => e._staminaRemaining > 0) && _enemies.Any(e => e._address.Y > map.GetFirstOpenRow()))
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _enemies.Count; i++)
|
||||||
|
{
|
||||||
|
Enemy enemy = _enemies[i];
|
||||||
|
if (enemy._staminaRemaining <= 0 || enemy._address.Y <= map.GetFirstOpenRow())
|
||||||
|
{
|
||||||
|
enemy._path.Add(enemy._path.LastOrDefault(enemy._address));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Vector2I> path = enemy.GetBestPath(map);
|
||||||
|
|
||||||
|
if (path.Count == 0)
|
||||||
|
{
|
||||||
|
enemy._path.Add(enemy._path.LastOrDefault(enemy._address));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2I cell = path[0];
|
||||||
|
GD.Print(cell);
|
||||||
|
map.SetCellEnemy(cell, enemy);
|
||||||
|
enemy._path.Add(cell);
|
||||||
|
|
||||||
|
enemy._staminaRemaining--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void EnemyAttacks()
|
public void EnemyAttacks()
|
||||||
{
|
{
|
||||||
List<Enemy> attackingEnemies = [.. _enemies.Where(e => e.CanAttack())];
|
List<Enemy> attackingEnemies = [.. _enemies.Where(e => e.CanAttack())];
|
||||||
@@ -65,63 +111,6 @@ public partial class EnemyController : TurnController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task BuildEnemyPaths()
|
|
||||||
{
|
|
||||||
Map map = _playArea._map;
|
|
||||||
|
|
||||||
for (int i = 0; i < _enemies.Count; i++)
|
|
||||||
{
|
|
||||||
Enemy enemy = _enemies[i];
|
|
||||||
enemy.GetRemainingStamina(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
_enemies.ForEach(e => e._path.Clear());
|
|
||||||
|
|
||||||
if (_enemies.All(e => e._staminaRemaining <= 0))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (_enemies.Any(e => e._staminaRemaining > 0))
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _enemies.Count; i++)
|
|
||||||
{
|
|
||||||
Enemy enemy = _enemies[i];
|
|
||||||
if (enemy._staminaRemaining <= 0)
|
|
||||||
{
|
|
||||||
enemy.RemainInPlace();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (enemy._address.Y <= map.GetFirstOpenRow())
|
|
||||||
{
|
|
||||||
enemy.RemainInPlace();
|
|
||||||
enemy._staminaRemaining = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Vector2I> path = enemy.GetBestPath(map);
|
|
||||||
|
|
||||||
if (path.Count == 0)
|
|
||||||
{
|
|
||||||
enemy.RemainInPlace();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2I cell = path[0];
|
|
||||||
if (cell.Y <= enemy._address.Y) // if path would move enemy forward
|
|
||||||
{
|
|
||||||
map.SetCellEnemy(cell, enemy);
|
|
||||||
enemy._path.Add(cell);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
enemy.RemainInPlace();
|
|
||||||
}
|
|
||||||
|
|
||||||
enemy._staminaRemaining--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void HandleEnemyClick(Enemy ENEMY)
|
public void HandleEnemyClick(Enemy ENEMY)
|
||||||
{
|
{
|
||||||
@@ -151,29 +140,35 @@ public partial class EnemyController : TurnController
|
|||||||
AddEnemies(positions);
|
AddEnemies(positions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StepEnemies(int STEP)
|
public void ProcessTweenStep(int STEP = 0)
|
||||||
{
|
{
|
||||||
Map map = _playArea._map;
|
if (_tweenStages.Count <= 0)
|
||||||
if (_movementTween != null)
|
|
||||||
{
|
{
|
||||||
_movementTween.Kill();
|
return;
|
||||||
|
}
|
||||||
|
if (STEP >= _tweenStages.Count)
|
||||||
|
{
|
||||||
|
EndTurn();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
_movementTween = CreateTween();
|
|
||||||
_movementTween.TweenInterval(0.5f);
|
|
||||||
|
|
||||||
for (int i= 0; i < _enemies.Count; i++)
|
if (_tween != null)
|
||||||
{
|
{
|
||||||
Enemy enemy = _enemies[i];
|
_tween.Kill();
|
||||||
_movementTween.Parallel().TweenProperty(enemy, "global_position", map.GetCellPositionFromAddress(enemy._path[STEP]), 0.25f);
|
|
||||||
}
|
}
|
||||||
if (STEP < _enemies[0]._path.Count - 1)
|
|
||||||
|
_tween = CreateTween();
|
||||||
|
_tween.TweenInterval(0.5f);
|
||||||
|
|
||||||
|
float stage = _tweenStages.Keys.ElementAt(STEP);
|
||||||
|
List<Tween> stageTweens = _tweenStages[stage];
|
||||||
|
for (int i = 0; i < stageTweens.Count; i++)
|
||||||
{
|
{
|
||||||
_movementTween.TweenCallback(Callable.From(() => StepEnemies(STEP + 1)));
|
Tween step = stageTweens[i];
|
||||||
}
|
_tween.Parallel().TweenSubtween(step);
|
||||||
else
|
|
||||||
{
|
|
||||||
_movementTween.TweenCallback(Callable.From(() => EndTurn()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_tween.TweenCallback(Callable.From(() => ProcessTweenStep(STEP + 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
|
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
|
||||||
@@ -192,13 +187,20 @@ public partial class EnemyController : TurnController
|
|||||||
{
|
{
|
||||||
AddEnemies(1);
|
AddEnemies(1);
|
||||||
|
|
||||||
|
for (int i = 0; i < _enemies.Count; i++)
|
||||||
|
{
|
||||||
|
_enemies[i].StartTurn();
|
||||||
|
}
|
||||||
|
|
||||||
SortEnemies();
|
SortEnemies();
|
||||||
|
|
||||||
EnemyAttacks();
|
EnemyAttacks();
|
||||||
|
|
||||||
await BuildEnemyPaths();
|
await BuildEnemyPaths();
|
||||||
|
|
||||||
StepEnemies(0);
|
await BuildAnimationTween();
|
||||||
|
|
||||||
|
ProcessTweenStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetEnemy(Enemy ENEMY, Vector2I CELL)
|
public void SetEnemy(Enemy ENEMY, Vector2I CELL)
|
||||||
|
|||||||
Reference in New Issue
Block a user