Support for deep cloning battles and Pokemon

This commit is contained in:
2024-12-29 13:51:59 +01:00
parent b3529fa22f
commit 40803f0269
13 changed files with 356 additions and 12 deletions

View File

@@ -11,7 +11,7 @@ namespace PkmnLib.Dynamic.Models;
/// A battle is a representation of a battle in the Pokemon games. It contains all the information needed
/// to simulate a battle, and can be used to simulate a battle between two parties.
/// </summary>
public interface IBattle : IScriptSource
public interface IBattle : IScriptSource, IDeepCloneable
{
/// <summary>
/// The library the battle uses for handling.

View File

@@ -1,5 +1,6 @@
using PkmnLib.Dynamic.Models.Choices;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Models;
@@ -11,7 +12,7 @@ namespace PkmnLib.Dynamic.Models;
/// It holds several helper functions to change the turn order while doing the execution. This is needed, as several
/// moves in Pokémon actively mess with this order.
/// </remarks>
public class BattleChoiceQueue
public class BattleChoiceQueue : IDeepCloneable
{
private readonly ITurnChoice?[] _choices;
private int _currentIndex;

View File

@@ -1,10 +1,12 @@
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Models;
/// <summary>
/// A battle party is a wrapper around a Pokemon party that provides additional functionality for battles.
/// It indicates for which side and position the party is responsible.
/// </summary>
public interface IBattleParty
public interface IBattleParty : IDeepCloneable
{
/// <summary>
/// The backing Pokemon party.

View File

@@ -8,7 +8,7 @@ namespace PkmnLib.Dynamic.Models;
/// <summary>
/// A side in a battle.
/// </summary>
public interface IBattleSide : IScriptSource
public interface IBattleSide : IScriptSource, IDeepCloneable
{
/// <summary>
/// The index of the side on the battle.

View File

@@ -1,11 +1,12 @@
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Models.Choices;
/// <summary>
/// A choice that is made at the beginning of a turn. This can be a switch, flee, item, or pass choice.
/// </summary>
public interface ITurnChoice : IScriptSource
public interface ITurnChoice : IScriptSource, IDeepCloneable
{
/// <summary>
/// The user of the turn choice

View File

@@ -1,4 +1,5 @@
using PkmnLib.Static.Moves;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Models;
@@ -42,7 +43,7 @@ public enum MoveLearnMethod
/// A learned move is the data attached to a Pokemon for a move it has learned. It has information
/// such as the remaining amount of users, how it has been learned, etc.
/// </summary>
public interface ILearnedMove
public interface ILearnedMove : IDeepCloneable
{
/// <summary>
/// The immutable move information of the move.

View File

@@ -12,7 +12,7 @@ namespace PkmnLib.Dynamic.Models;
/// <summary>
/// The data of a Pokemon.
/// </summary>
public interface IPokemon : IScriptSource
public interface IPokemon : IScriptSource, IDeepCloneable
{
/// <summary>
/// The library data of the Pokemon.
@@ -352,7 +352,7 @@ public interface IPokemon : IScriptSource
/// The data of the Pokémon related to being in a battle.
/// This is only set when the Pokémon is on the field in a battle.
/// </summary>
public interface IPokemonBattleData
public interface IPokemonBattleData : IDeepCloneable
{
/// <summary>
/// The battle the Pokémon is in.

View File

@@ -1,11 +1,12 @@
using System.Collections;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Models;
/// <summary>
/// A collection of Pokemon.
/// </summary>
public interface IPokemonParty : IReadOnlyList<IPokemon?>
public interface IPokemonParty : IReadOnlyList<IPokemon?>, IDeepCloneable
{
event EventHandler<(IPokemon?, int index)>? OnSwapInto;
event EventHandler<(int index1, int index2)>? OnSwap;

View File

@@ -12,7 +12,7 @@ namespace PkmnLib.Dynamic.ScriptHandling;
/// changes. This allows for easily defining generational differences, and add effects that the
/// developer might require.
/// </summary>
public abstract class Script
public abstract class Script : IDeepCloneable
{
internal event Action<Script>? OnRemoveEvent;

View File

@@ -1,5 +1,6 @@
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.ScriptHandling;
@@ -7,7 +8,7 @@ namespace PkmnLib.Dynamic.ScriptHandling;
/// A holder class for a script. This is used so we can cache a list of these, and iterate over them, even when
/// the underlying script changes.
/// </summary>
public class ScriptContainer : IEnumerable<ScriptContainer>
public class ScriptContainer : IEnumerable<ScriptContainer>, IDeepCloneable
{
/// <inheritdoc cref="ScriptContainer"/>
public ScriptContainer()