using PkmnLib.Static.Moves;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Models;
///
/// The different ways a move can be learned.
///
public enum MoveLearnMethod
{
///
/// We do not know the learn method.
///
Unknown,
///
/// The move is learned by leveling up.
///
LevelUp,
///
/// The move is learned when the Pokémon is hatched from an egg.
///
Egg,
///
/// The move is learned by using a tutor in the game.
///
Tutor,
///
/// The move is learned by using a TM or HM.
///
Machine,
///
/// The move is learned when the Pokémon changes form.
///
FormChange,
}
///
/// 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.
///
public interface ILearnedMove : IDeepCloneable
{
///
/// The immutable move information of the move.
///
IMoveData MoveData { get; }
///
/// The maximal power points for this move.
///
byte MaxPp { get; }
///
/// The current power points for this move.
///
byte CurrentPp { get; }
///
/// The way the move has been learned.
///
MoveLearnMethod LearnMethod { get; }
///
/// 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.
///
bool TryUse(byte amount = 1);
///
/// Set the remaining PP to the max amount of PP.
///
void RestoreAllUses();
///
/// Restore the remaining PP by a certain amount. Will prevent it from going above max PP.
///
void RestoreUses(byte amount);
}
///
public class LearnedMoveImpl : ILearnedMove
{
private byte _maxPpModification = 0;
///
public LearnedMoveImpl(IMoveData moveData, MoveLearnMethod learnMethod)
{
MoveData = moveData;
LearnMethod = learnMethod;
CurrentPp = MaxPp;
}
public LearnedMoveImpl(IMoveData moveData, MoveLearnMethod learnMethod, byte pp) : this(moveData, learnMethod)
{
CurrentPp = pp;
}
///
public IMoveData MoveData { get; }
///
public byte MaxPp => (byte)(MoveData.BaseUsages + _maxPpModification);
///
public MoveLearnMethod LearnMethod { get; }
///
/// The available power points for this move.
///
public byte CurrentPp { get; private set; }
///
/// 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.
///
public bool TryUse(byte amount = 1)
{
if (CurrentPp < amount)
return false;
CurrentPp -= amount;
return true;
}
///
/// Restore the PP to the maximum amount of PP.
///
public void RestoreAllUses() => CurrentPp = MaxPp;
///
/// Restore the PP by a certain amount. This will prevent the PP from going above the maximum PP.
///
public void RestoreUses(byte amount) => CurrentPp = (byte)Math.Min(CurrentPp + amount, MaxPp);
}