Files
PkmnLib.NET/PkmnLib.Dynamic/Models/ItemTargetType.cs

68 lines
2.0 KiB
C#

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