Enemy Sword Action Only?

In the AI code for pathfinding:

    public override EnemyAIAction GetEnemyAIAction(GridPosition gridPosition)
    {
        //This is where we go the unit code to get the target value
        int targetCountAtGridPosition = unit.GetAction<ShootAction>().GetTargetCountAtPosition(gridPosition);

    }

…we see that the pathfinding is dependent upon the ShootAction script. What if I wanted to make a character that only performs a SwordAction, or a GrenadeAction. Would I just replace what is in the <> brackets?
Thanks so much!

1 Like

You’d think that but it’s not the case and here’s why; Only ShootAction has a GetTargetCountAtPosition() method. We specifically wrote that method in ShootAction for this specific use. You could just have that method in all the other actions, too, but then you need to have a MoveAction for each attack you’d want to implement.
I haven’t bothered to solve this in my own project but I have been aware of it. I think the simplest would just be to have a method that will count the enemies within a certain radius of a specific grid position. Then you can specify the radius in a serialized field and not bother linking one action to another

2 Likes

If my only attack actions are either melee(SwordAction) or range (ShootAction), then I could write two (basically) identical move scripts, based on whether I want an enemy to be one or the other.

Thanks for the help!

2 Likes

My solution to this was to create a BaseAttackAction class from which all of the attack actions inherit. Then in MoveAction, I iterate over each BaseAttackAction on the unit and get the best action from them, returning the best action from the choices.

2 Likes

Privacy & Terms