Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -35,29 +35,30 @@ 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, IPokemon user, IPokemon target)
|
||||
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.Party.Contains(user));
|
||||
var targetParty = battle.Parties.FirstOrDefault(x => x.Party.Contains(target));
|
||||
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.BattleData?.BattleSide == target.BattleData?.BattleSide)
|
||||
if (user.BattleSide == target.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));
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user