finishing revert to older version
This commit is contained in:
+73
-80
@@ -11,12 +11,7 @@ public partial class EnemyController : TurnController
|
||||
public PackedScene _enemyScene = GD.Load<PackedScene>("res://Enemy.tscn");
|
||||
public List<Enemy> _enemies = new();
|
||||
public PlayerController _playerController;
|
||||
<<<<<<< HEAD
|
||||
public Tween _movementTween;
|
||||
=======
|
||||
public Dictionary<float, List<Tween>> _tweenStages = new();
|
||||
public Tween _tween;
|
||||
>>>>>>> f022333c9b378e5a77d8d2727f2a9cb16dd1b8f8
|
||||
|
||||
public void AddEnemies(int ENEMY_COUNT = 1)
|
||||
{
|
||||
@@ -58,52 +53,6 @@ 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()
|
||||
{
|
||||
List<Enemy> attackingEnemies = [.. _enemies.Where(e => e.CanAttack())];
|
||||
@@ -115,7 +64,64 @@ 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)
|
||||
{
|
||||
if (ENEMY._staminaRemaining <= 0){
|
||||
@@ -144,35 +150,29 @@ public partial class EnemyController : TurnController
|
||||
AddEnemies(positions);
|
||||
}
|
||||
|
||||
public void ProcessTweenStep(int STEP = 0)
|
||||
public void StepEnemies(int STEP)
|
||||
{
|
||||
if (_tweenStages.Count <= 0)
|
||||
Map map = _playArea._map;
|
||||
if (_movementTween != null)
|
||||
{
|
||||
return;
|
||||
_movementTween.Kill();
|
||||
}
|
||||
if (STEP >= _tweenStages.Count)
|
||||
_movementTween = CreateTween();
|
||||
_movementTween.TweenInterval(0.5f);
|
||||
|
||||
for (int i= 0; i < _enemies.Count; i++)
|
||||
{
|
||||
EndTurn();
|
||||
return;
|
||||
Enemy enemy = _enemies[i];
|
||||
_movementTween.Parallel().TweenProperty(enemy, "global_position", map.GetCellPositionFromAddress(enemy._path[STEP]), 0.25f);
|
||||
}
|
||||
|
||||
if (_tween != null)
|
||||
if (STEP < _enemies[0]._path.Count - 1)
|
||||
{
|
||||
_tween.Kill();
|
||||
_movementTween.TweenCallback(Callable.From(() => StepEnemies(STEP + 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++)
|
||||
else
|
||||
{
|
||||
Tween step = stageTweens[i];
|
||||
_tween.Parallel().TweenSubtween(step);
|
||||
_movementTween.TweenCallback(Callable.From(() => EndTurn()));
|
||||
}
|
||||
|
||||
_tween.TweenCallback(Callable.From(() => ProcessTweenStep(STEP + 1)));
|
||||
}
|
||||
|
||||
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
|
||||
@@ -191,20 +191,13 @@ public partial class EnemyController : TurnController
|
||||
{
|
||||
AddEnemies(1);
|
||||
|
||||
for (int i = 0; i < _enemies.Count; i++)
|
||||
{
|
||||
_enemies[i].StartTurn();
|
||||
}
|
||||
|
||||
SortEnemies();
|
||||
|
||||
EnemyAttacks();
|
||||
|
||||
await BuildEnemyPaths();
|
||||
|
||||
await BuildAnimationTween();
|
||||
|
||||
ProcessTweenStep();
|
||||
StepEnemies(0);
|
||||
}
|
||||
|
||||
public void SetEnemy(Enemy ENEMY, Vector2I CELL)
|
||||
|
||||
Reference in New Issue
Block a user