implemented visibility, so pegs can only scope out as far as they can see.
This commit is contained in:
@@ -7,7 +7,7 @@ public partial class Peg : HoverableNode
|
||||
{
|
||||
[Signal]
|
||||
public delegate void DeathEventHandler(Peg THIS);
|
||||
public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _visibility = 4, _movement = 0, _disposition;
|
||||
public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _movement = 0, _disposition, _visibility;
|
||||
public Vector2I _address;
|
||||
public List<Vector2I> _path = new();
|
||||
public PegController _pegController;
|
||||
@@ -36,12 +36,6 @@ public partial class Peg : HoverableNode
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (action == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_staminaRemaining -= action._cost;
|
||||
return action;
|
||||
}
|
||||
|
||||
@@ -68,10 +62,28 @@ public partial class Peg : HoverableNode
|
||||
return pathsOverZeroCount.OrderBy(p => p.Count).ToList()[0];
|
||||
}
|
||||
|
||||
public virtual List<Vector2I> GetVisibleCells()
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
return [.. map._cells.Where(c => (c - _address).Length() <= _visibility)];
|
||||
}
|
||||
|
||||
public virtual List<Vector2I> GetGoals()
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
return [.. map._cells.Where(c => c.Y == (_disposition == 1 ? map._lastOpenRow : map._firstOpenRow)).Where(c => !map._astar.IsPointSolid(c))];
|
||||
TileMapLayer pathLayer = _pegController._playArea.GetNode<TileMapLayer>("PathLayer");
|
||||
List<Vector2I> pl = [.. pathLayer.GetUsedCells()];
|
||||
List<Vector2I> visible = GetVisibleCells();
|
||||
if (_id == 4)
|
||||
for (int i = 0; i < pl.Count; i++)
|
||||
{
|
||||
Vector2I cell = pl[i];
|
||||
pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(cell,0,Vector2I.Down + Vector2I.Right*(visible.IndexOf(cell) > -1 ? 1 : 4)));
|
||||
|
||||
}
|
||||
List<Vector2I> unoccupied = [.. visible.Where(c => !map._astar.IsPointSolid(c))];
|
||||
List<Vector2I> closest = [.. unoccupied.Where(c => c.Y == (_disposition == -1 ? unoccupied.Min(c => c.Y) : unoccupied.Max(c => c.Y))).OrderByDescending(c => Math.Abs(c.X - _address.X))];
|
||||
return closest;
|
||||
}
|
||||
|
||||
public Vector2 GetPositionFromAddress()
|
||||
|
||||
+9
-9
@@ -5,6 +5,8 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
@@ -52,6 +54,7 @@ public partial class PegController : TurnController
|
||||
{
|
||||
HostilePeg newHostilePeg = Globals.GetRandomFromList(_hostilePegScenes).Instantiate<HostilePeg>();
|
||||
newHostilePeg._id = _pegsCreated;
|
||||
newHostilePeg.Scale *= _pegsCreated == 4 ? 1.5f : 1f;
|
||||
newHostilePeg.Death += HandlePegRemoval;
|
||||
newHostilePeg.Click += HandlePegClick;
|
||||
|
||||
@@ -80,6 +83,7 @@ public partial class PegController : TurnController
|
||||
|
||||
if (action != null)
|
||||
{
|
||||
action.DoImmediately(peg);
|
||||
string key = action._priority + ":" + loop;
|
||||
if (!_tweenStages.ContainsKey(key))
|
||||
{
|
||||
@@ -90,24 +94,23 @@ public partial class PegController : TurnController
|
||||
{
|
||||
anyPegsActed = true;
|
||||
}
|
||||
peg._staminaRemaining -= action._cost;
|
||||
}
|
||||
}
|
||||
loop++;
|
||||
}
|
||||
ProcessTween();
|
||||
}
|
||||
|
||||
public void HandlePegClick(Node CLICKED_NODE, int CLICK_TYPE)
|
||||
{
|
||||
TileMapLayer pathLayer = _playArea.GetNode<TileMapLayer>("PathLayer");
|
||||
if (CLICKED_NODE is not Peg peg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (CLICK_TYPE == 0)
|
||||
{
|
||||
if (peg._staminaRemaining <= 0){
|
||||
return;
|
||||
}
|
||||
TileMapLayer pathLayer = _playArea.GetNode<TileMapLayer>("PathLayer");
|
||||
List<Vector2I> newPath = peg.GetBestPath();
|
||||
|
||||
pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(c,0,Vector2I.Down*4));
|
||||
@@ -138,7 +141,7 @@ public partial class PegController : TurnController
|
||||
|
||||
public void Initiate()
|
||||
{
|
||||
List<Vector2I> positions = [.. _playArea.GetNode<TileMapLayer>("InitialPositions").GetUsedCells()];
|
||||
List<Vector2I> positions = [.. _playArea.GetNode<TileMapLayer>("InitialPositions").GetUsedCells().OrderBy(c => c.Y).ThenBy(c => c.X)];
|
||||
|
||||
AddHostilePegs(positions);
|
||||
}
|
||||
@@ -181,12 +184,9 @@ public partial class PegController : TurnController
|
||||
{
|
||||
_pegs[i].StartTurn();
|
||||
}
|
||||
|
||||
HandlePegSort();
|
||||
|
||||
|
||||
HandlePegTurn();
|
||||
|
||||
ProcessTween();
|
||||
}
|
||||
|
||||
public void SetPeg(Peg PEG, Vector2I CELL)
|
||||
|
||||
@@ -9,7 +9,6 @@ public partial class BasicMovement : PegAction
|
||||
base._Ready();
|
||||
_category = "movement";
|
||||
_priority = 0;
|
||||
_healthChange = 0;
|
||||
_cost = 1;
|
||||
_range = 2^32;
|
||||
_usesMax = 2^32;
|
||||
@@ -17,23 +16,28 @@ public partial class BasicMovement : PegAction
|
||||
}
|
||||
|
||||
public override Tween CreateAnimation(Peg PEG)
|
||||
{
|
||||
PegController pegController = PEG._pegController;
|
||||
Map map = pegController._playArea._map;
|
||||
Vector2I cell = PEG._path[0];
|
||||
Tween subtween = CreateTween();
|
||||
subtween.TweenProperty(PEG, "global_position", map.GetCellPositionFromAddress(cell), 0.25f);
|
||||
PEG._path.RemoveAt(0);
|
||||
return subtween;
|
||||
}
|
||||
|
||||
public override void DoImmediately(Peg PEG)
|
||||
{
|
||||
List<Vector2I> path = PEG.GetBestPath();
|
||||
PegController pegController = PEG._pegController;
|
||||
Map map = pegController._playArea._map;
|
||||
if (path?.Count == 0)
|
||||
{
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
Vector2I cell = path[0];
|
||||
|
||||
map.SetCellPeg(cell, PEG);
|
||||
PEG._path.Add(cell);
|
||||
|
||||
Tween subtween = CreateTween();
|
||||
subtween.TweenProperty(PEG, "global_position", map.GetCellPositionFromAddress(cell), 0.25f);
|
||||
|
||||
return subtween;
|
||||
}
|
||||
|
||||
public override bool MeetsCriteria(Peg PEG)
|
||||
|
||||
@@ -9,7 +9,6 @@ public partial class Shortbow : PegAction
|
||||
base._Ready();
|
||||
_category = "attack";
|
||||
_priority = 1;
|
||||
_healthChange = -1;
|
||||
_cost = 2;
|
||||
_range = 1;
|
||||
_usesMax = 1;
|
||||
@@ -24,7 +23,7 @@ public partial class Shortbow : PegAction
|
||||
subtween.TweenProperty(_image, "global_position", target, 0.5f);
|
||||
subtween.TweenCallback(Callable.From(() =>
|
||||
{
|
||||
PEG._pegController._playerController.ChangeHealth(_healthChange, this);
|
||||
PEG._pegController._playerController.ChangeHealth(-1, this);
|
||||
Position = Vector2.Zero;
|
||||
Visible = false;
|
||||
}));
|
||||
|
||||
@@ -9,7 +9,6 @@ public partial class Shortsword : PegAction
|
||||
base._Ready();
|
||||
_category = "attack";
|
||||
_priority = 1;
|
||||
_healthChange = -2;
|
||||
_cost = 2;
|
||||
_range = 0;
|
||||
_usesMax = 1;
|
||||
@@ -18,14 +17,14 @@ public partial class Shortsword : PegAction
|
||||
|
||||
public override Tween CreateAnimation(Peg PEG)
|
||||
{
|
||||
Vector2 target = PEG._disposition * Vector2.Up * PEG._pegController._playArea._map._cellSize;
|
||||
GD.Print(target);
|
||||
Vector2 target = PEG._disposition * Vector2.Down * PEG._pegController._playArea._map._cellSize;
|
||||
// GD.Print(target);
|
||||
Tween subtween = CreateTween();
|
||||
subtween.TweenProperty(_image, "visible", true, 0.0f);
|
||||
subtween.TweenProperty(_image, "position", target, 0.5f);
|
||||
subtween.TweenCallback(Callable.From(() =>
|
||||
{
|
||||
PEG._pegController._playerController.ChangeHealth(_healthChange, this);
|
||||
PEG._pegController._playerController.ChangeHealth(-2, this);
|
||||
_image.Position = Vector2.Zero;
|
||||
_image.Visible = false;
|
||||
}));
|
||||
|
||||
@@ -7,5 +7,6 @@ public partial class Archer : HostilePeg
|
||||
{
|
||||
base._Ready();
|
||||
_stamina = 2;
|
||||
_visibility = 4;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,5 +7,6 @@ public partial class Infantry : HostilePeg
|
||||
{
|
||||
base._Ready();
|
||||
_stamina = 3;
|
||||
_visibility = 3;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-1
@@ -4,7 +4,7 @@ using System;
|
||||
public partial class PegAction : Node2D
|
||||
{
|
||||
public string _category;
|
||||
public int _priority, _healthChange, _cost, _range, _usesMax, _usesRemaining, _triggers = 0;
|
||||
public int _priority, _cost, _range, _usesMax, _usesRemaining, _triggers = 0;
|
||||
public Sprite2D _image;
|
||||
|
||||
public override void _Ready()
|
||||
@@ -18,6 +18,11 @@ public partial class PegAction : Node2D
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual void DoImmediately(Peg PEG)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual bool MeetsCriteria(Peg PEG)
|
||||
{
|
||||
return PEG._staminaRemaining >= _cost
|
||||
|
||||
Reference in New Issue
Block a user