PkmnLib.NET/PkmnLib.Dynamic/Models/BattleParty.cs

53 lines
1.6 KiB
C#
Raw Normal View History

using PkmnLib.Static.Utils;
2024-07-27 14:26:45 +00:00
namespace PkmnLib.Dynamic.Models;
/// <summary>
/// A battle party is a wrapper around a Pokemon party that provides additional functionality for battles.
/// It indicates for which side and position the party is responsible.
/// </summary>
public interface IBattleParty : IDeepCloneable
2024-07-27 14:26:45 +00:00
{
/// <summary>
/// The backing Pokemon party.
/// </summary>
2024-07-27 14:26:45 +00:00
IPokemonParty Party { get; }
/// <summary>
/// Whether the party is responsible for the specified side and position.
/// </summary>
bool IsResponsibleForIndex(ResponsibleIndex index);
/// <summary>
/// Whether the party has a living Pokemon left that is not in the field.
/// </summary>
2024-07-27 14:26:45 +00:00
bool HasPokemonNotInField();
}
/// <summary>
/// A position on the battlefield that a party is responsible for.
/// Contains the index of the side and the position on that side.
/// </summary>
public record struct ResponsibleIndex(byte Side, byte Position);
/// <inheritdoc />
public class BattlePartyImpl : IBattleParty
{
private readonly ResponsibleIndex[] _responsibleIndices;
/// <inheritdoc cref="BattlePartyImpl"/>
public BattlePartyImpl(IPokemonParty party, ResponsibleIndex[] responsibleIndices)
{
Party = party;
_responsibleIndices = responsibleIndices;
}
/// <inheritdoc />
public IPokemonParty Party { get; }
/// <inheritdoc />
public bool IsResponsibleForIndex(ResponsibleIndex index) => _responsibleIndices.Contains(index);
/// <inheritdoc />
public bool HasPokemonNotInField() => Party.Any(x => x is { IsUsable: true, BattleData.IsOnBattlefield: false });
2024-07-27 14:26:45 +00:00
}