PkmnLib.NET/PkmnLib.Dynamic/Models/Choices/MoveChoice.cs

90 lines
2.3 KiB
C#
Raw Normal View History

2024-07-27 14:26:45 +00:00
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Static.Utils;
2024-07-27 14:26:45 +00:00
namespace PkmnLib.Dynamic.Models.Choices;
/// <summary>
/// The choice of a Pokémon to use a move.
/// </summary>
public interface IMoveChoice : ITurnChoice
{
/// <summary>
/// The move that is used.
/// </summary>
2024-08-10 09:18:10 +00:00
ILearnedMove ChosenMove { get; }
2024-07-27 14:26:45 +00:00
/// <summary>
/// The side the move is targeted at.
/// </summary>
byte TargetSide { get; }
/// <summary>
/// The position the move is targeted at.
/// </summary>
byte TargetPosition { get; }
/// <summary>
/// The priority of the move.
/// </summary>
sbyte Priority { get; set; }
/// <summary>
/// The underlying script of the move.
/// </summary>
ScriptContainer Script { get; set; }
Dictionary<StringKey, object?>? AdditionalData { get; }
2024-07-27 14:26:45 +00:00
}
/// <inheritdoc cref="IMoveChoice"/>
public class MoveChoice : TurnChoice, IMoveChoice
{
/// <inheritdoc cref="MoveChoice"/>
public MoveChoice(IPokemon user, ILearnedMove usedMove, byte targetSide, byte targetPosition) : base(user)
{
2024-08-10 09:18:10 +00:00
ChosenMove = usedMove;
2024-07-27 14:26:45 +00:00
TargetSide = targetSide;
TargetPosition = targetPosition;
2024-09-03 08:34:01 +00:00
var secondaryEffect = usedMove.MoveData.SecondaryEffect;
if (secondaryEffect != null)
{
2025-01-10 10:11:50 +00:00
if (user.Library.ScriptResolver.TryResolve(ScriptCategory.Move, secondaryEffect.Name,
secondaryEffect.Parameters, out var script))
2024-09-03 08:34:01 +00:00
{
Script.Set(script);
}
}
2024-07-27 14:26:45 +00:00
}
/// <inheritdoc />
2024-08-10 09:18:10 +00:00
public ILearnedMove ChosenMove { get; }
2024-07-27 14:26:45 +00:00
/// <inheritdoc />
public byte TargetSide { get; }
/// <inheritdoc />
public byte TargetPosition { get; }
/// <inheritdoc />
public sbyte Priority { get; set; }
/// <inheritdoc />
public ScriptContainer Script { get; set; } = new();
/// <inheritdoc />
public Dictionary<StringKey, object?>? AdditionalData { get; }
2024-07-27 14:26:45 +00:00
/// <inheritdoc />
public override int ScriptCount => 1 + User.ScriptCount;
/// <inheritdoc />
public override void GetOwnScripts(List<IEnumerable<ScriptContainer>> scripts) => scripts.Add(Script);
/// <inheritdoc />
public override void CollectScripts(List<IEnumerable<ScriptContainer>> scripts)
{
GetOwnScripts(scripts);
User.CollectScripts(scripts);
}
}