namespace PkmnLib.Dynamic.Models; /// /// Types of targets an item can have. /// [Flags] public enum ItemTargetType { /// /// The item does not require a target. /// None = 0, /// /// The item targets Pokémon that are part of the user's own team. /// OwnPokemon = 1, /// /// The item targets allied Pokémon. /// AllyPokemon = 2, /// /// The item targets opposing Pokémon. /// FoePokemon = 4, } /// /// Helper methods for ItemTargetType. /// public static class ItemTargetTypeHelpers { /// /// Determines if the given target is valid based on the ItemTargetType. /// public static bool IsValidTarget(this ItemTargetType targetType, IBattle battle, IPokemon user, IPokemon target) { if (targetType == ItemTargetType.None) return true; if (targetType.HasFlag(ItemTargetType.OwnPokemon)) { var userParty = battle.Parties.FirstOrDefault(x => x.Party.Contains(user)); var targetParty = battle.Parties.FirstOrDefault(x => x.Party.Contains(target)); if (userParty is not null && targetParty is not null && userParty == targetParty) return true; } if (targetType.HasFlag(ItemTargetType.AllyPokemon)) { if (user.BattleData?.BattleSide == target.BattleData?.BattleSide) return true; } if (targetType.HasFlag(ItemTargetType.FoePokemon)) { var userParty = battle.Parties.FirstOrDefault(x => x.Party.Contains(user)); var targetParty = battle.Parties.FirstOrDefault(x => x.Party.Contains(target)); if (userParty is not null && targetParty is not null && userParty != targetParty) return true; } return false; } }