Initial work on implementing Pokemon
This commit is contained in:
@@ -24,7 +24,38 @@ public interface IReadOnlyGrowthRateLibrary
|
||||
/// Whether the library is empty.
|
||||
/// </summary>
|
||||
bool IsEmpty { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the experience for a given growth key name and a certain level.
|
||||
/// </summary>
|
||||
uint CalculateExperience(StringKey key, LevelInt level);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the level for a given growth key name and a certain experience.
|
||||
/// </summary>
|
||||
LevelInt CalculateLevel(StringKey key, uint experience);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IReadOnlyGrowthRateLibrary"/>
|
||||
public class GrowthRateLibrary : DataLibrary<IGrowthRate>, IReadOnlyGrowthRateLibrary;
|
||||
public class GrowthRateLibrary : DataLibrary<IGrowthRate>, IReadOnlyGrowthRateLibrary
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public uint CalculateExperience(StringKey key, LevelInt level)
|
||||
{
|
||||
if (!TryGet(key, out var growthRate))
|
||||
{
|
||||
throw new KeyNotFoundException($"Growth rate {key} not found.");
|
||||
}
|
||||
return growthRate.CalculateExperience(level);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public LevelInt CalculateLevel(StringKey key, uint experience)
|
||||
{
|
||||
if (!TryGet(key, out var growthRate))
|
||||
{
|
||||
throw new KeyNotFoundException($"Growth rate {key} not found.");
|
||||
}
|
||||
return growthRate.CalculateLevel(experience);
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,10 @@ public record ImmutableStatisticSet<T>
|
||||
public record StatisticSet<T> : ImmutableStatisticSet<T>
|
||||
where T : struct
|
||||
{
|
||||
public StatisticSet() : base(default, default, default, default, default, default)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="StatisticSet{T}"/>
|
||||
public StatisticSet(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed) : base(hp, attack,
|
||||
defense, specialAttack, specialDefense, speed)
|
||||
@@ -266,6 +270,10 @@ public record StatBoostStatisticSet : ClampedStatisticSet<sbyte>
|
||||
/// <inheritdoc />
|
||||
protected override sbyte Max => 6;
|
||||
|
||||
public StatBoostStatisticSet() : base(0, 0, 0, 0, 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="StatBoostStatisticSet"/>
|
||||
public StatBoostStatisticSet(sbyte hp, sbyte attack, sbyte defense, sbyte specialAttack, sbyte specialDefense,
|
||||
sbyte speed) : base(hp, attack, defense, specialAttack, specialDefense, speed)
|
||||
@@ -284,6 +292,10 @@ public record IndividualValueStatisticSet : ClampedStatisticSet<byte>
|
||||
/// <inheritdoc />
|
||||
protected override byte Max => 31;
|
||||
|
||||
public IndividualValueStatisticSet() : base(0, 0, 0, 0, 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IndividualValueStatisticSet"/>
|
||||
public IndividualValueStatisticSet(byte hp, byte attack, byte defense, byte specialAttack, byte specialDefense,
|
||||
byte speed) : base(hp, attack, defense, specialAttack, specialDefense, speed)
|
||||
@@ -302,6 +314,10 @@ public record EffortValueStatisticSet : ClampedStatisticSet<byte>
|
||||
/// <inheritdoc />
|
||||
protected override byte Max => 252;
|
||||
|
||||
public EffortValueStatisticSet() : base(0, 0, 0, 0, 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="EffortValueStatisticSet"/>
|
||||
public EffortValueStatisticSet(byte hp, byte attack, byte defense, byte specialAttack, byte specialDefense,
|
||||
byte speed) : base(hp, attack, defense, specialAttack, specialDefense, speed)
|
||||
|
||||
7
PkmnLib.Static/Utils/EnumerableHelpers.cs
Normal file
7
PkmnLib.Static/Utils/EnumerableHelpers.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace PkmnLib.Static.Utils;
|
||||
|
||||
public static class EnumerableHelpers
|
||||
{
|
||||
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> enumerable) where T : class =>
|
||||
enumerable.Where(x => x is not null)!;
|
||||
}
|
||||
Reference in New Issue
Block a user