PkmnLib.NET/PkmnLib.Dynamic/Models/LearnedMove.cs

139 lines
3.6 KiB
C#
Raw Normal View History

2024-07-27 14:26:45 +00:00
using PkmnLib.Static.Moves;
using PkmnLib.Static.Utils;
2024-07-27 14:26:45 +00:00
namespace PkmnLib.Dynamic.Models;
/// <summary>
/// The different ways a move can be learned.
/// </summary>
public enum MoveLearnMethod
{
/// <summary>
/// We do not know the learn method.
/// </summary>
Unknown,
/// <summary>
/// The move is learned by leveling up.
/// </summary>
LevelUp,
/// <summary>
/// The move is learned when the Pokémon is hatched from an egg.
/// </summary>
Egg,
/// <summary>
/// The move is learned by using a tutor in the game.
/// </summary>
Tutor,
/// <summary>
/// The move is learned by using a TM or HM.
/// </summary>
Machine,
/// <summary>
/// The move is learned when the Pokémon changes form.
/// </summary>
2024-08-23 07:24:00 +00:00
FormChange,
2024-07-27 14:26:45 +00:00
}
/// <summary>
/// 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 : IDeepCloneable
2024-07-27 14:26:45 +00:00
{
/// <summary>
/// The immutable move information of the move.
/// </summary>
IMoveData MoveData { get; }
/// <summary>
/// The maximal power points for this move.
/// </summary>
byte MaxPp { get; }
2025-03-02 16:19:57 +00:00
/// <summary>
/// The current power points for this move.
/// </summary>
byte CurrentPp { get; }
2024-07-27 14:26:45 +00:00
/// <summary>
/// The way the move has been learned.
/// </summary>
MoveLearnMethod LearnMethod { get; }
/// <summary>
/// Try and reduce the PP by a certain amount. If the amount is higher than the current uses,
/// return false. Otherwise, reduce the PP, and return true.
/// </summary>
bool TryUse(byte amount = 1);
/// <summary>
/// Set the remaining PP to the max amount of PP.
/// </summary>
void RestoreAllUses();
/// <summary>
/// Restore the remaining PP by a certain amount. Will prevent it from going above max PP.
/// </summary>
void RestoreUses(byte amount);
}
/// <inheritdoc />
public class LearnedMoveImpl : ILearnedMove
{
private byte _maxPpModification = 0;
2025-03-02 16:19:57 +00:00
2024-07-28 10:52:17 +00:00
/// <inheritdoc cref="LearnedMoveImpl" />
2024-07-27 14:26:45 +00:00
public LearnedMoveImpl(IMoveData moveData, MoveLearnMethod learnMethod)
{
MoveData = moveData;
LearnMethod = learnMethod;
CurrentPp = MaxPp;
}
2025-03-02 16:19:57 +00:00
public LearnedMoveImpl(IMoveData moveData, MoveLearnMethod learnMethod, byte pp) : this(moveData, learnMethod)
{
CurrentPp = pp;
}
2024-07-27 14:26:45 +00:00
/// <inheritdoc />
public IMoveData MoveData { get; }
/// <inheritdoc />
public byte MaxPp => (byte)(MoveData.BaseUsages + _maxPpModification);
/// <inheritdoc />
public MoveLearnMethod LearnMethod { get; }
2025-03-02 16:19:57 +00:00
2024-07-28 10:52:17 +00:00
/// <summary>
/// The available power points for this move.
/// </summary>
2024-07-27 14:26:45 +00:00
public byte CurrentPp { get; private set; }
2025-03-02 16:19:57 +00:00
2024-07-28 10:52:17 +00:00
/// <summary>
/// Try to use the move. This subtracts the amount of PP from the current PP. If the amount requested is
/// higher than the current PP, this will return false, and the PP will not be reduced.
/// </summary>
2024-07-27 14:26:45 +00:00
public bool TryUse(byte amount = 1)
{
if (CurrentPp < amount)
return false;
2025-03-02 16:19:57 +00:00
2024-07-27 14:26:45 +00:00
CurrentPp -= amount;
return true;
}
2024-07-28 10:52:17 +00:00
/// <summary>
/// Restore the PP to the maximum amount of PP.
/// </summary>
2024-07-27 14:26:45 +00:00
public void RestoreAllUses() => CurrentPp = MaxPp;
2024-07-28 10:52:17 +00:00
/// <summary>
/// Restore the PP by a certain amount. This will prevent the PP from going above the maximum PP.
/// </summary>
2024-07-27 14:26:45 +00:00
public void RestoreUses(byte amount) => CurrentPp = (byte)Math.Min(CurrentPp + amount, MaxPp);
}