Implements several more moves

This commit is contained in:
2025-01-27 12:18:48 +01:00
parent 549b92048a
commit 3a75493912
26 changed files with 676 additions and 38 deletions

View File

@@ -28,6 +28,8 @@ public interface IReadOnlyTypeLibrary
/// This is equivalent to running get_single_effectiveness on each defending type, and multiplying the results with each other.
/// </summary>
float GetEffectiveness(TypeIdentifier attacking, IReadOnlyList<TypeIdentifier> defending);
IEnumerable<(TypeIdentifier type, float effectiveness)> GetAllEffectivenessFromAttacking(TypeIdentifier attacking);
}
/// <inheritdoc />
@@ -70,6 +72,17 @@ public class TypeLibrary : IReadOnlyTypeLibrary
defending.Aggregate<TypeIdentifier, float>(1,
(current, type) => current * GetSingleEffectiveness(attacking, type));
/// <inheritdoc />
public IEnumerable<(TypeIdentifier, float)> GetAllEffectivenessFromAttacking(TypeIdentifier attacking)
{
if (attacking.Value < 1 || attacking.Value > _effectiveness.Count)
throw new ArgumentOutOfRangeException(nameof(attacking));
for (var i = 0; i < _effectiveness.Count; i++)
{
yield return (new TypeIdentifier((byte)(i + 1)), _effectiveness[attacking.Value - 1][i]);
}
}
/// <summary>
/// Registers a new type in the library.
/// </summary>

View File

@@ -29,4 +29,16 @@ public enum Statistic : byte
/// Speed determines the order that a Pokémon can act in battle.
/// </summary>
Speed,
/// <summary>
/// Evasion determines the likelihood that a Pokémon will dodge an attack.
/// This is not part of base stats, but is a temporary stat boost.
/// </summary>
Evasion,
/// <summary>
/// Accuracy determines the likelihood that a Pokémon will hit an attack.
/// This is not part of base stats, but is a temporary stat boost.
/// </summary>
Accuracy,
}

View File

@@ -168,12 +168,24 @@ public record StatisticSet<T> : ImmutableStatisticSet<T>, IEnumerable<T>, IDeepC
Speed = Add(Speed, value);
break;
default:
throw new ArgumentException("Invalid statistic.");
SetUnknownStat(stat, Add(GetUnknownStat(stat), value));
break;
}
return true;
}
protected virtual T GetUnknownStat(Statistic stat)
{
throw new ArgumentException($"Invalid statistic {stat}");
}
protected virtual void SetUnknownStat(Statistic stat, T value)
{
throw new ArgumentException($"Invalid statistic {stat}");
}
/// <summary>
/// Decreases a statistic in the set by a value.
/// </summary>
@@ -200,14 +212,15 @@ public record StatisticSet<T> : ImmutableStatisticSet<T>, IEnumerable<T>, IDeepC
Speed = Subtract(Speed, value);
break;
default:
throw new ArgumentException("Invalid statistic.");
SetUnknownStat(stat, Subtract(GetUnknownStat(stat), value));
break;
}
return true;
}
/// <inheritdoc />
public IEnumerator<T> GetEnumerator()
public virtual IEnumerator<T> GetEnumerator()
{
yield return Hp;
yield return Attack;
@@ -332,6 +345,47 @@ public record StatBoostStatisticSet : ClampedStatisticSet<sbyte>
sbyte speed) : base(hp, attack, defense, specialAttack, specialDefense, speed)
{
}
/// <inheritdoc />
protected override sbyte GetUnknownStat(Statistic stat)
{
return stat switch
{
Statistic.Evasion => Evasion,
Statistic.Accuracy => Accuracy,
_ => throw new ArgumentException($"Invalid statistic {stat}"),
};
}
/// <inheritdoc />
/// <inheritdoc />
protected override void SetUnknownStat(Statistic stat, sbyte value)
{
switch (stat)
{
case Statistic.Evasion:
Evasion = value;
break;
case Statistic.Accuracy:
Accuracy = value;
break;
default:
throw new ArgumentException($"Invalid statistic {stat}");
}
}
/// <inheritdoc />
public override IEnumerator<sbyte> GetEnumerator()
{
yield return Hp;
yield return Attack;
yield return Defense;
yield return SpecialAttack;
yield return SpecialDefense;
yield return Speed;
yield return Evasion;
yield return Accuracy;
}
}
/// <summary>