Fixes and reworking of item use
All checks were successful
Build / Build (push) Successful in 57s

This commit is contained in:
2025-11-08 11:43:07 +01:00
parent fa05cdd773
commit 21ec4b28c7
11 changed files with 150 additions and 34 deletions

View File

@@ -11,40 +11,67 @@ public interface IItemChoice : ITurnChoice
/// <summary>
/// The item that is used.
/// </summary>
public IItem Item { get; }
IItem Item { get; }
/// <summary>
/// The side the move is targeted at.
/// The target Pokémon of the item, if any.
/// </summary>
byte? TargetSide { get; }
/// <summary>
/// The position the move is targeted at.
/// </summary>
byte? TargetPosition { get; }
IPokemon? GetTargetPokemon(IBattle battle);
}
/// <inheritdoc cref="IItemChoice"/>
public class ItemChoice : TurnChoice, IItemChoice
{
/// <inheritdoc cref="ItemChoice"/>
public ItemChoice(IPokemon user, IItem item, byte? targetSide, byte? targetPosition) : base(user)
private ItemChoice(IPokemon user, IItem item, byte? targetSide, byte? targetPosition, IPokemon? targetPokemon) :
base(user)
{
Item = item;
TargetSide = targetSide;
TargetPosition = targetPosition;
TargetPokemon = targetPokemon;
}
public static ItemChoice CreateWithoutTarget(IPokemon user, IItem item) =>
new(user, item, null, null, null);
public static ItemChoice CreateForOpponent(IPokemon user, IItem item, byte targetSide, byte targetPosition) =>
new(user, item, targetSide, targetPosition, null);
public static ItemChoice CreateForPartyMember(IPokemon user, IItem item, IPokemon targetPokemon) =>
new(user, item, null, null, targetPokemon);
/// <summary>
/// The item that is used.
/// </summary>
public IItem Item { get; }
/// <inheritdoc />
public byte? TargetSide { get; }
public IPokemon? GetTargetPokemon(IBattle battle)
{
if (TargetPokemon != null)
return TargetPokemon;
/// <inheritdoc />
public byte? TargetPosition { get; }
if (!TargetSide.HasValue || !TargetPosition.HasValue)
return null;
var side = battle.Sides[TargetSide.Value];
return side.Pokemon[TargetPosition.Value];
}
/// <summary>
/// The target side of the item, if any.
/// </summary>
private byte? TargetSide { get; }
/// <summary>
/// The target position of the item, if any.
/// </summary>
private byte? TargetPosition { get; }
/// <summary>
/// The target Pokémon of the item, if any. This is used for party members.
/// </summary>
private IPokemon? TargetPokemon { get; }
/// <inheritdoc />
public override int ScriptCount => User.ScriptCount;