Fix turn choice ordering not functioning properly
This commit is contained in:
@@ -25,6 +25,7 @@ public class BattleChoiceQueue : IDeepCloneable
|
||||
/// <inheritdoc cref="BattleChoiceQueue"/>
|
||||
public BattleChoiceQueue(ITurnChoice[] choices)
|
||||
{
|
||||
Array.Sort(choices, TurnChoiceComparer.Instance!);
|
||||
_choices = choices;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,12 @@ public class TurnChoiceComparer : IComparer<ITurnChoice>
|
||||
private static CompareValues CompareForSameType(ITurnChoice x, ITurnChoice y)
|
||||
{
|
||||
// Higher speed goes first
|
||||
var speedComparison = x.Speed.CompareTo(y.Speed);
|
||||
var speedComparison = y.Speed.CompareTo(x.Speed);
|
||||
if (speedComparison != 0)
|
||||
return (CompareValues)speedComparison;
|
||||
// If speed is equal, we use the random values we've given to each choice to tiebreak.
|
||||
// This is to ensure that the order of choices is deterministic.
|
||||
return (CompareValues)x.RandomValue.CompareTo(y.RandomValue);
|
||||
return (CompareValues)y.RandomValue.CompareTo(x.RandomValue);
|
||||
}
|
||||
|
||||
private static CompareValues CompareImpl(ITurnChoice? x, ITurnChoice? y)
|
||||
@@ -46,7 +46,7 @@ public class TurnChoiceComparer : IComparer<ITurnChoice>
|
||||
if (y is IMoveChoice moveY)
|
||||
{
|
||||
// Higher priority goes first
|
||||
var priorityComparison = moveX.Priority.CompareTo(moveY.Priority);
|
||||
var priorityComparison = moveY.Priority.CompareTo(moveX.Priority);
|
||||
if (priorityComparison != 0)
|
||||
return (CompareValues)priorityComparison;
|
||||
return CompareForSameType(moveX, moveY);
|
||||
|
||||
Reference in New Issue
Block a user