Fix swapping party not properly packing

This commit is contained in:
2026-01-09 09:21:28 +01:00
parent 4928157cd4
commit 123c3773d2

View File

@@ -74,6 +74,17 @@ public class PokemonPartyImpl : IPokemonParty
/// Swaps two Pokemon in the party around.
/// </summary>
public void Swap(int index1, int index2)
{
(_pokemon[index1], _pokemon[index2]) = (_pokemon[index2], _pokemon[index1]);
var originalIndex1Value = _pokemon[index1];
var originalIndex2Value = _pokemon[index2];
Pack();
var newIndex1 = Array.IndexOf(_pokemon, originalIndex1Value);
var newIndex2 = Array.IndexOf(_pokemon, originalIndex2Value);
OnSwap?.Invoke(this, (newIndex1, newIndex2));
}
private void SwapWithoutPack(int index1, int index2)
{
(_pokemon[index1], _pokemon[index2]) = (_pokemon[index2], _pokemon[index1]);
OnSwap?.Invoke(this, (index1, index2));
@@ -106,7 +117,7 @@ public class PokemonPartyImpl : IPokemonParty
{
if (_pokemon[j] == null)
continue;
Swap(i, j);
SwapWithoutPack(i, j);
break;
}
}