Make Shoot Action Use All Action Points

If you want the game more like XCOM where shooting first uses up all the unit’s action points then you can add this code in the Unit script.

public bool TrySpendActionPointsToTakeAction(BaseAction baseAction)
    {
        if (CanSpendActionPointsToTakeAction(baseAction))
        {
            SpendActionPoints(baseAction.GetActionPointsCost());
            if (baseAction.GetActionName() == "Shoot") //New  code here
            {
                actionPoints = 0;
                OnAnyActionPointsChanged?.Invoke(this, EventArgs.Empty);
            }
            return true;
        } else
        {
            return false;
        }
    }
1 Like

It would be cleaner to override the GetActionPointsCost() method in the ShootAction class to simply return all the Units action points:

public virtual int GetActionPointsCost()
    {
        return unit.GetActionPoints();;
    }

The idea is that the Unit should just be able to use the BaseAction interface and not need to know anything about the derived actions.

1 Like

Should be override not virtual, but I agree. Override the cost in the ShootAction

3 Likes

Privacy & Terms