using PkmnLib.Static.Moves; 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 { /// /// The immutable move information of the move. /// IMoveData MoveData { get; } /// /// The maximal power points for this move. /// byte MaxPp { 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 IMoveData MoveData { get; } /// public byte MaxPp => (byte)(MoveData.BaseUsages + _maxPpModification); /// public MoveLearnMethod LearnMethod { get; } public byte CurrentPp { get; private set; } public bool TryUse(byte amount = 1) { if (CurrentPp < amount) return false; CurrentPp -= amount; return true; } public void RestoreAllUses() => CurrentPp = MaxPp; public void RestoreUses(byte amount) => CurrentPp = (byte)Math.Min(CurrentPp + amount, MaxPp); }