Initial commit
This commit is contained in:
155
PkmnLib.Static/StatisticSet.cs
Normal file
155
PkmnLib.Static/StatisticSet.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
using System;
|
||||
|
||||
namespace PkmnLib.Static;
|
||||
|
||||
public record StaticStatisticSet<T>
|
||||
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; }
|
||||
|
||||
public StaticStatisticSet(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed)
|
||||
{
|
||||
Hp = hp;
|
||||
Attack = attack;
|
||||
Defense = defense;
|
||||
SpecialAttack = specialAttack;
|
||||
SpecialDefense = specialDefense;
|
||||
Speed = speed;
|
||||
}
|
||||
|
||||
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.")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public record StatisticSet<T> : StaticStatisticSet<T>
|
||||
where T : struct
|
||||
{
|
||||
public StatisticSet(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed) : base(hp, attack,
|
||||
defense, specialAttack, specialDefense, speed)
|
||||
{
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user