How can I filter a list of scriptable objects by an enum type and then pick a random index from the filtered list?
Hello.
I am making a turn-based combat system and currently trying to improve the computer enemy 'AI'. At the moment, all enemy 'moves' are created from a Scriptable Object (EnemyMove) which are then stored in a list (EnemyMoveList). The EnemyMove contains an Enum dictating the type of move (MoveType) it is (Attack, Heal, Buff).
Within my battle system code I currently have coded the enemy to pick a random move from their movelist when it is their turn.
public void EnemyMoveSetup()
{
int enemyMoveIndex = Random.Range(0, thisEnemyMoveList.enemyMoveList.Count);
if (enemyMoveIndex >= 0)
{
thisEnemyMove = thisEnemyMoveList.enemyMoveList[enemyMoveIndex];
}
}
I would now like to expand this so that they enemy will pick a heal move when under a certain percentage of their health.
What I am struggling with is how to filter the EnemyMoveList to choose only EnemyMove's of the type Heal and then allow the enemy to pick a random index from the new filtered list. Is this possible? I am still fairly new to Unity and C# but feel like this should start to be within my reach! I have found it difficult to find another question like this within the forums.
Thanks in advance!
Your answer
Follow this Question
Related Questions
How to sort List of Lists by a certain Value (C#) 1 Answer
ScriptableObject not Serializing? 0 Answers
Why is my List adding to same array object again and again in update? 1 Answer
items not adding to list 1 Answer
Unity 5.2 Scene Fade 0 Answers