undergoing a shift to change movement into another action that a peg can perform and giving pegs a list of actions order by priority
This commit is contained in:
@@ -7,49 +7,54 @@ 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, _movementCost = 1;
|
||||
public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _visibility = 4, _movement = 0;
|
||||
public Dictionary<string, int> _priorities = new()
|
||||
{
|
||||
{"ball", 1000000}, // 1000000 to 1999999 reserved for ball priorities
|
||||
{"act", 1000000}, // 1000000 to 1999999 reserved for action priorities
|
||||
{"movement", 0} // 0 to 999999 reserved for movement priorities
|
||||
};
|
||||
public Vector2I _address = -Vector2I.One, _range = Vector2I.Up;
|
||||
public List<Vector2I> _path = new();
|
||||
public PegController _pegController;
|
||||
public PegAction _action;
|
||||
public List<PegAction> _actions;
|
||||
public int _distanceToGoal
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetBestPath().Count;
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
ReprioritizeActions();
|
||||
}
|
||||
public virtual void Act()
|
||||
public virtual bool Act(int SUB_STEP)
|
||||
{
|
||||
if (_action == null)
|
||||
PegAction action = null;
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
if (_actions[i].MeetsCriteria(this))
|
||||
{
|
||||
action = _actions[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (action == null)
|
||||
{
|
||||
GD.Print("NO ACTION");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
Tween subtween = _action.CreateAnimation(this);
|
||||
if (!_pegController._tweenStages.ContainsKey(_action._priority))
|
||||
Tween subtween = action.CreateAnimation(this);
|
||||
int key = action._priority + SUB_STEP;
|
||||
if (!_pegController._tweenStages.ContainsKey(key))
|
||||
{
|
||||
_pegController._tweenStages[_action._priority] = new();
|
||||
_pegController._tweenStages[key] = new();
|
||||
}
|
||||
_pegController._tweenStages[_action._priority].Add(subtween);
|
||||
_staminaRemaining = Math.Max(_staminaRemaining - _action._cost, 0);
|
||||
}
|
||||
|
||||
public virtual bool CanAct()
|
||||
{
|
||||
return _staminaRemaining > 0
|
||||
&& _address.Y <= _action._range
|
||||
&& _action._usesRemaining > 0
|
||||
&& _staminaRemaining <= _action._cost;
|
||||
}
|
||||
|
||||
public virtual bool CanMove()
|
||||
{
|
||||
return _staminaRemaining > 0
|
||||
&& _address.Y > _pegController._playArea._map._firstOpenRow;
|
||||
_pegController._tweenStages[key].Add(subtween);
|
||||
_staminaRemaining -= action._cost;
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void CounterAct(Commander COMMANDER)
|
||||
@@ -67,8 +72,12 @@ public partial class Peg : HoverableNode
|
||||
{
|
||||
paths.Add(map.GetPath(_address, goals[i]));
|
||||
}
|
||||
|
||||
return paths.Where(p => p.Count > 0).OrderBy(p => p.Count).ToList()[0];
|
||||
List<List<Vector2I>> pathsOverZeroCount = [.. paths.Where(p => p.Count > 0)];
|
||||
if (pathsOverZeroCount.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
return pathsOverZeroCount.OrderBy(p => p.Count).ToList()[0];
|
||||
}
|
||||
|
||||
public virtual List<Vector2I> GetGoals()
|
||||
@@ -76,36 +85,27 @@ public partial class Peg : HoverableNode
|
||||
Map map = _pegController._playArea._map;
|
||||
return [.. map._cells.Where(c => c.Y == map._firstOpenRow).Where(c => !map._astar.IsPointSolid(c))];
|
||||
}
|
||||
|
||||
public virtual void Move(Vector2I PATH_STEP)
|
||||
{
|
||||
_pegController._playArea._map.SetCellPeg(PATH_STEP, this);
|
||||
_path.Add(PATH_STEP);
|
||||
|
||||
Tween subtween = CreateTween();
|
||||
subtween.TweenProperty(this, "global_position", _pegController._playArea._map.GetCellPositionFromAddress(PATH_STEP), 0.25f);
|
||||
int key = _priorities["movement"] + _pegController._actionLoop;
|
||||
|
||||
if (!_pegController._tweenStages.ContainsKey(key))
|
||||
{
|
||||
_pegController._tweenStages[key] = new();
|
||||
}
|
||||
|
||||
_pegController._tweenStages[key].Add(subtween);
|
||||
_staminaRemaining -= _movementCost;
|
||||
public Vector2 GetPositionFromAddress()
|
||||
{
|
||||
return _pegController._playArea._map.GetCellPositionFromAddress(_address);
|
||||
}
|
||||
|
||||
public void ReprioritizeActions()
|
||||
{
|
||||
_actions = [.. GetNode<Node>("Actions").GetChildren().Cast<PegAction>()];
|
||||
}
|
||||
|
||||
public virtual void StartTurn()
|
||||
{
|
||||
_staminaRemaining = _stamina;
|
||||
_action._usesRemaining = _action._usesMax;
|
||||
GD.Print("ACTION ",_action._usesRemaining,", ",_action._usesRemaining);
|
||||
_actions.ForEach(a => a.Reset());
|
||||
}
|
||||
|
||||
public virtual void ChangeHealth(int DELTA, Commander BALLER)
|
||||
public virtual void ChangeHealth(int DELTA, Commander COMMANDER)
|
||||
{
|
||||
_health += DELTA;
|
||||
CounterAct(BALLER);
|
||||
CounterAct(COMMANDER);
|
||||
if (_health <= 0)
|
||||
{
|
||||
EmitSignal(SignalName.Death, this);
|
||||
|
||||
Reference in New Issue
Block a user