2024-07-20 11:51:52 +00:00
|
|
|
namespace PkmnLib.Static;
|
|
|
|
|
2024-07-20 14:12:39 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A set of statistics that cannot be changed.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The size of the integer to be used</typeparam>
|
|
|
|
public record ImmutableStatisticSet<T>
|
2024-07-20 11:51:52 +00:00
|
|
|
where T : struct
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The health points stat value.
|
|
|
|
/// </summary>
|
|
|
|
public T Hp { get; protected set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The physical attack stat value.
|
|
|
|
/// </summary>
|
|
|
|
public T Attack { get; protected set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The physical defense stat value.
|
|
|
|
/// </summary>
|
|
|
|
public T Defense { get; protected set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The special attack stat value.
|
|
|
|
/// </summary>
|
|
|
|
public T SpecialAttack { get; protected set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The special defense stat value.
|
|
|
|
/// </summary>
|
|
|
|
public T SpecialDefense { get; protected set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The speed stat value.
|
|
|
|
/// </summary>
|
|
|
|
public T Speed { get; protected set; }
|
|
|
|
|
2024-07-20 14:12:39 +00:00
|
|
|
/// <inheritdoc cref="ImmutableStatisticSet{T}"/>
|
|
|
|
public ImmutableStatisticSet(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed)
|
2024-07-20 11:51:52 +00:00
|
|
|
{
|
|
|
|
Hp = hp;
|
|
|
|
Attack = attack;
|
|
|
|
Defense = defense;
|
|
|
|
SpecialAttack = specialAttack;
|
|
|
|
SpecialDefense = specialDefense;
|
|
|
|
Speed = speed;
|
|
|
|
}
|
|
|
|
|
2024-07-20 14:12:39 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets a statistic from the set.
|
|
|
|
/// </summary>
|
2024-07-20 11:51:52 +00:00
|
|
|
public T GetStatistic(Statistic stat)
|
|
|
|
{
|
|
|
|
return stat switch
|
|
|
|
{
|
|
|
|
Statistic.Hp => Hp,
|
|
|
|
Statistic.Attack => Attack,
|
|
|
|
Statistic.Defense => Defense,
|
|
|
|
Statistic.SpecialAttack => SpecialAttack,
|
|
|
|
Statistic.SpecialDefense => SpecialDefense,
|
|
|
|
Statistic.Speed => Speed,
|
|
|
|
_ => throw new ArgumentException("Invalid statistic.")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-20 14:12:39 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A set of statistics that can be changed.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
public record StatisticSet<T> : ImmutableStatisticSet<T>
|
2024-07-20 11:51:52 +00:00
|
|
|
where T : struct
|
|
|
|
{
|
2024-07-20 14:12:39 +00:00
|
|
|
/// <inheritdoc cref="StatisticSet{T}"/>
|
2024-07-20 11:51:52 +00:00
|
|
|
public StatisticSet(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed) : base(hp, attack,
|
|
|
|
defense, specialAttack, specialDefense, speed)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-07-20 14:12:39 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Modifies a statistic in the set.
|
|
|
|
/// </summary>
|
2024-07-20 11:51:52 +00:00
|
|
|
public void SetStatistic(Statistic stat, T value)
|
|
|
|
{
|
|
|
|
switch (stat)
|
|
|
|
{
|
|
|
|
case Statistic.Hp:
|
|
|
|
Hp = value;
|
|
|
|
break;
|
|
|
|
case Statistic.Attack:
|
|
|
|
Attack = value;
|
|
|
|
break;
|
|
|
|
case Statistic.Defense:
|
|
|
|
Defense = value;
|
|
|
|
break;
|
|
|
|
case Statistic.SpecialAttack:
|
|
|
|
SpecialAttack = value;
|
|
|
|
break;
|
|
|
|
case Statistic.SpecialDefense:
|
|
|
|
SpecialDefense = value;
|
|
|
|
break;
|
|
|
|
case Statistic.Speed:
|
|
|
|
Speed = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ArgumentException("Invalid statistic.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-20 14:12:39 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Increases a statistic in the set by a value.
|
|
|
|
/// </summary>
|
2024-07-20 11:51:52 +00:00
|
|
|
public void IncreaseStatistic(Statistic stat, T value)
|
|
|
|
{
|
|
|
|
switch (stat)
|
|
|
|
{
|
|
|
|
case Statistic.Hp:
|
|
|
|
Hp = (T)Convert.ChangeType(Convert.ToInt32(Hp) + Convert.ToInt32(value), typeof(T));
|
|
|
|
break;
|
|
|
|
case Statistic.Attack:
|
|
|
|
Attack = (T)Convert.ChangeType(Convert.ToInt32(Attack) + Convert.ToInt32(value), typeof(T));
|
|
|
|
break;
|
|
|
|
case Statistic.Defense:
|
|
|
|
Defense = (T)Convert.ChangeType(Convert.ToInt32(Defense) + Convert.ToInt32(value), typeof(T));
|
|
|
|
break;
|
|
|
|
case Statistic.SpecialAttack:
|
|
|
|
SpecialAttack =
|
|
|
|
(T)Convert.ChangeType(Convert.ToInt32(SpecialAttack) + Convert.ToInt32(value), typeof(T));
|
|
|
|
break;
|
|
|
|
case Statistic.SpecialDefense:
|
|
|
|
SpecialDefense =
|
|
|
|
(T)Convert.ChangeType(Convert.ToInt32(SpecialDefense) + Convert.ToInt32(value), typeof(T));
|
|
|
|
break;
|
|
|
|
case Statistic.Speed:
|
|
|
|
Speed = (T)Convert.ChangeType(Convert.ToInt32(Speed) + Convert.ToInt32(value), typeof(T));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ArgumentException("Invalid statistic.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-20 14:12:39 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Decreases a statistic in the set by a value.
|
|
|
|
/// </summary>
|
2024-07-20 11:51:52 +00:00
|
|
|
public void DecreaseStatistic(Statistic stat, T value)
|
|
|
|
{
|
|
|
|
switch (stat)
|
|
|
|
{
|
|
|
|
case Statistic.Hp:
|
|
|
|
Hp = (T)Convert.ChangeType(Convert.ToInt32(Hp) - Convert.ToInt32(value), typeof(T));
|
|
|
|
break;
|
|
|
|
case Statistic.Attack:
|
|
|
|
Attack = (T)Convert.ChangeType(Convert.ToInt32(Attack) - Convert.ToInt32(value), typeof(T));
|
|
|
|
break;
|
|
|
|
case Statistic.Defense:
|
|
|
|
Defense = (T)Convert.ChangeType(Convert.ToInt32(Defense) - Convert.ToInt32(value), typeof(T));
|
|
|
|
break;
|
|
|
|
case Statistic.SpecialAttack:
|
|
|
|
SpecialAttack =
|
|
|
|
(T)Convert.ChangeType(Convert.ToInt32(SpecialAttack) - Convert.ToInt32(value), typeof(T));
|
|
|
|
break;
|
|
|
|
case Statistic.SpecialDefense:
|
|
|
|
SpecialDefense =
|
|
|
|
(T)Convert.ChangeType(Convert.ToInt32(SpecialDefense) - Convert.ToInt32(value), typeof(T));
|
|
|
|
break;
|
|
|
|
case Statistic.Speed:
|
|
|
|
Speed = (T)Convert.ChangeType(Convert.ToInt32(Speed) - Convert.ToInt32(value), typeof(T));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ArgumentException("Invalid statistic.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|