using JetBrains.Annotations;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Models.Choices;
///
/// The choice of a Pokémon to use a move.
///
public interface IMoveChoice : ITurnChoice
{
///
/// The move that is used.
///
ILearnedMove ChosenMove { get; }
///
/// The side the move is targeted at.
///
byte TargetSide { get; }
///
/// The position the move is targeted at.
///
byte TargetPosition { get; }
///
/// The priority of the move.
///
sbyte Priority { get; set; }
///
/// The underlying script of the move.
///
ScriptContainer Script { get; set; }
///
/// Additional data that can be used by scripts to store information about the choice.
///
Dictionary? AdditionalData { get; }
///
/// Volatile effects that are applied to the move choice.
///
IScriptSet Volatile { get; }
}
///
[PublicAPI]
public class MoveChoice : TurnChoice, IMoveChoice
{
///
public MoveChoice(IPokemon user, ILearnedMove usedMove, byte targetSide, byte targetPosition) : base(user)
{
ChosenMove = usedMove;
TargetSide = targetSide;
TargetPosition = targetPosition;
Volatile = new ScriptSet(this);
var secondaryEffect = usedMove.MoveData.SecondaryEffect;
if (secondaryEffect != null)
{
if (user.Library.ScriptResolver.TryResolve(ScriptCategory.Move, secondaryEffect.Name,
secondaryEffect.Parameters, out var script))
{
Script.Set(script);
script.OnAddedToParent(this);
}
}
}
///
public ILearnedMove ChosenMove { get; }
///
public byte TargetSide { get; }
///
public byte TargetPosition { get; }
///
public sbyte Priority { get; set; }
///
public ScriptContainer Script { get; set; } = new();
///
public Dictionary? AdditionalData { get; }
///
public IScriptSet Volatile { get; }
///
public override int ScriptCount => 2 + User.ScriptCount;
///
public override void GetOwnScripts(List> scripts)
{
scripts.Add(Volatile);
scripts.Add(Script);
}
///
public override void CollectScripts(List> scripts)
{
GetOwnScripts(scripts);
User.CollectScripts(scripts);
}
}