using Godot; using System; using System.Collections.Generic; using System.Linq; public partial class Enemy : StaticBody2D { [Signal] public delegate void DeathEventHandler(Enemy THIS); public int _damage = 1, _health = 2, _speed; public Vector2I _range = Vector2I.Up; public float _movement = 0; public GridMarker _gridMarker; public Commander _commander; public override void _Ready() { base._Ready(); } public override void _PhysicsProcess(double delta) { base._PhysicsProcess(delta); } public void Attack(Commander COMMANDER) { COMMANDER.TakeDamage(_damage, this); } public void CounterAttack(Commander COMMANDER) { } public List Pathfinding(List DESTINATIONS, bool INCLUDE_SELF = false) { PriorityQueue queue = new(); queue.Enqueue(_gridMarker, 0f); Dictionary cameFrom = new(), best = new(); Dictionary costSoFar = new(); cameFrom[_gridMarker] = null; costSoFar[_gridMarker] = 0f; GridMarker current; float newCost, priority; for (int i = 0; i < DESTINATIONS.Count; i++) { GridMarker destination = DESTINATIONS[i]; while (queue.Count > 0) { current = queue.Dequeue(); if (current == destination) { best = cameFrom; GD.Print("breaking at line 56"); continue; } List neighbors = current.GetMarkersInRange(1.5f); for (int j = 0; j < neighbors.Count; j++) { GridMarker next = neighbors[j]; if (next._occupant != null) { continue; } newCost = costSoFar[current] + 1; if (best.Count > 0 && newCost >= best.Count) { GD.Print("breaking at line 70"); break; } if (!costSoFar.TryGetValue(next, out float value) || newCost < value) { costSoFar[next] = newCost; priority = newCost; queue.Enqueue(next, priority); cameFrom[next] = current; } } } } GD.Print(best.Last().Value._address); List path = new(); GridMarker pathMarker = best.Last().Value; if (best.TryGetValue(pathMarker, out GridMarker marker)) { while (pathMarker != null) { path.Add(pathMarker); pathMarker = marker; } path.Reverse(); if (!INCLUDE_SELF) { path.Remove(_gridMarker); } } return path; } public void TakeDamage(int DAMAGE, Commander ATTACKER) { GD.Print(_health, _health - DAMAGE); _health -= DAMAGE; CounterAttack(ATTACKER); if (_health <= 0) { EmitSignal(SignalName.Death, this); } } }