127 lines
4.7 KiB
C#
127 lines
4.7 KiB
C#
using System;
|
|
using JetBrains.Annotations;
|
|
using PkmnLibSharp.Utils;
|
|
using Interface = PkmnLibSharp.FFI.StaticData.StatisticSet;
|
|
|
|
namespace PkmnLibSharp.StaticData
|
|
{
|
|
/// <summary>
|
|
/// A collection of every individual stat. This set can hold any value that is valid for its integer
|
|
/// type, and can be modified at will.
|
|
/// </summary>
|
|
/// <typeparam name="T">
|
|
/// The integer type that this statistic set will use. This type must be one of the following: byte, sbyte, uint.
|
|
/// </typeparam>
|
|
public class StatisticSet<T> : HandleType where T : struct, IConvertible
|
|
{
|
|
/// <inheritdoc cref="StatisticSet{T}"/>
|
|
protected StatisticSet(FFIHandle handle) : base(handle)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new statistic set with given stats.
|
|
/// </summary>
|
|
public static StatisticSet<T> Create(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed)
|
|
{
|
|
var handle = typeof(T) switch
|
|
{
|
|
{ } t when t == typeof(byte) => Interface.statistic_set_u8_new(Convert.ToByte(hp),
|
|
Convert.ToByte(attack), Convert.ToByte(defense), Convert.ToByte(specialAttack),
|
|
Convert.ToByte(specialDefense), Convert.ToByte(speed)),
|
|
{ } t when t == typeof(uint) => Interface.statistic_set_u32_new(Convert.ToUInt32(hp),
|
|
Convert.ToUInt32(attack), Convert.ToUInt32(defense), Convert.ToUInt32(specialAttack),
|
|
Convert.ToUInt32(specialDefense), Convert.ToUInt32(speed)),
|
|
{ } t when t == typeof(sbyte) => Interface.statistic_set_i8_new(Convert.ToSByte(hp),
|
|
Convert.ToSByte(attack), Convert.ToSByte(defense), Convert.ToSByte(specialAttack),
|
|
Convert.ToSByte(specialDefense), Convert.ToSByte(speed)),
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
return Resolver.Instance.ResolveStatisticSet<T>(handle.Resolve());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the value of a specific stat
|
|
/// </summary>
|
|
[PublicAPI]
|
|
public T GetStatistic(Statistic statistic)
|
|
{
|
|
object p = typeof(T) switch
|
|
{
|
|
{ } t when t == typeof(byte) => Interface.statistic_set_u8_get_stat(Handle, statistic),
|
|
{ } t when t == typeof(uint) => Interface.statistic_set_u32_get_stat(Handle, statistic),
|
|
{ } t when t == typeof(sbyte) => Interface.statistic_set_i8_get_stat(Handle, statistic),
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
return (T)p;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Modify the value of a specific stat.
|
|
/// </summary>
|
|
[PublicAPI]
|
|
public void SetStatistic(Statistic statistic, T value)
|
|
{
|
|
if (typeof(T) == typeof(byte)) Interface.statistic_set_u8_set_stat(Handle, statistic, Convert.ToByte(value));
|
|
else if (typeof(T) == typeof(uint))
|
|
Interface.statistic_set_u32_set_stat(Handle, statistic, Convert.ToUInt32(value));
|
|
else if (typeof(T) == typeof(sbyte))
|
|
Interface.statistic_set_i8_set_stat(Handle, statistic, Convert.ToSByte(value));
|
|
else throw new ArgumentOutOfRangeException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// The health point stat value.
|
|
/// </summary>
|
|
public T HP
|
|
{
|
|
get => GetStatistic(Statistic.HP);
|
|
set => SetStatistic(Statistic.HP, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The physical attack stat value.
|
|
/// </summary>
|
|
public T Attack
|
|
{
|
|
get => GetStatistic(Statistic.Attack);
|
|
set => SetStatistic(Statistic.Attack, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The physical defense stat value.
|
|
/// </summary>
|
|
public T Defense
|
|
{
|
|
get => GetStatistic(Statistic.Defense);
|
|
set => SetStatistic(Statistic.Defense, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The special attack stat value.
|
|
/// </summary>
|
|
public T SpecialAttack
|
|
{
|
|
get => GetStatistic(Statistic.SpecialAttack);
|
|
set => SetStatistic(Statistic.SpecialAttack, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The special defense stat value.
|
|
/// </summary>
|
|
public T SpecialDefense
|
|
{
|
|
get => GetStatistic(Statistic.SpecialDefense);
|
|
set => SetStatistic(Statistic.SpecialDefense, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The speed stat value.
|
|
/// </summary>
|
|
public T Speed
|
|
{
|
|
get => GetStatistic(Statistic.Speed);
|
|
set => SetStatistic(Statistic.Speed, value);
|
|
}
|
|
}
|
|
} |