Even more moves

This commit is contained in:
2025-04-19 13:01:10 +02:00
parent c22ad1a793
commit 807acf1947
19 changed files with 505 additions and 19 deletions

View File

@@ -99,8 +99,39 @@ public class BattleChoiceQueue : IDeepCloneable
return true;
}
/// <summary>
/// This moves the choice of a specific Pokémon to the end of the queue, making it the last choice to be executed.
/// </summary>
/// <returns>
/// Returns true if the Pokémon was found and moved, false otherwise.
/// </returns>
public bool MovePokemonChoiceLast(IPokemon pokemon)
{
var index = Array.FindIndex(_choices, _currentIndex, choice => choice?.User == pokemon);
if (index == -1)
return false;
var choice = _choices[index];
_choices[index] = null;
// Put all choices after the index of the choice forward
for (var i = index; i < _choices.Length - 1; i++)
_choices[i] = _choices[i + 1];
// And insert the choice at the end
_choices[^1] = choice;
return true;
}
internal IReadOnlyList<ITurnChoice?> GetChoices() => _choices;
public ITurnChoice? FirstOrDefault(Func<ITurnChoice, bool> predicate) =>
_choices.WhereNotNull().FirstOrDefault(predicate);
_choices.Skip(_currentIndex).WhereNotNull().FirstOrDefault(predicate);
public void Remove(ITurnChoice choice)
{
var index = Array.FindIndex(_choices, _currentIndex, x => x == choice);
if (index == -1)
return;
_choices[index] = null;
for (var i = index; i > _currentIndex; i--)
_choices[i] = _choices[i - 1];
}
}