using PkmnLib.Dynamic.ScriptHandling; using PkmnLib.Static; namespace PkmnLib.Dynamic.Models.Choices; /// /// A choice to use an item /// public interface IItemChoice : ITurnChoice { /// /// The item that is used. /// IItem Item { get; } /// /// The target Pokémon of the item, if any. /// IPokemon? GetTargetPokemon(IBattle battle); } /// public class ItemChoice : TurnChoice, IItemChoice { /// 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); /// /// The item that is used. /// public IItem Item { get; } /// public IPokemon? GetTargetPokemon(IBattle battle) { if (TargetPokemon != null) return TargetPokemon; if (!TargetSide.HasValue || !TargetPosition.HasValue) return null; var side = battle.Sides[TargetSide.Value]; return side.Pokemon[TargetPosition.Value]; } /// /// The target side of the item, if any. /// private byte? TargetSide { get; } /// /// The target position of the item, if any. /// private byte? TargetPosition { get; } /// /// The target Pokémon of the item, if any. This is used for party members. /// private IPokemon? TargetPokemon { get; } /// public override int ScriptCount => User.ScriptCount; /// public override void GetOwnScripts(List> scripts) { } /// public override void CollectScripts(List> scripts) { User.CollectScripts(scripts); } /// public override string ToString() => $"ItemChoice: User: {User}, Item: {Item.Name}, TargetSide: {TargetSide}, TargetPosition: {TargetPosition}"; protected bool Equals(ItemChoice other) => other.User == User && other.Item.Equals(Item) && other.TargetSide == TargetSide && other.TargetPosition == TargetPosition; /// public override bool Equals(object? obj) { if (obj is null) return false; if (ReferenceEquals(this, obj)) return true; if (obj is not ItemChoice other) return false; return Equals(other); } /// public override int GetHashCode() => HashCode.Combine(User, Item, TargetSide, TargetPosition); }