92 lines
3.5 KiB
C#
92 lines
3.5 KiB
C#
using System;
|
|
using JetBrains.Annotations;
|
|
using PkmnLibSharp.Utils;
|
|
using Interface = PkmnLibSharp.FFI.StaticData.StatisticSet;
|
|
|
|
namespace PkmnLibSharp.StaticData
|
|
{
|
|
public class StatisticSet<T> : HandleType where T : struct, IConvertible
|
|
{
|
|
protected StatisticSet(FFIHandle handle) : base(handle)
|
|
{
|
|
}
|
|
|
|
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());
|
|
}
|
|
|
|
[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;
|
|
}
|
|
|
|
[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();
|
|
}
|
|
|
|
public T HP
|
|
{
|
|
get => GetStatistic(Statistic.HP);
|
|
set => SetStatistic(Statistic.HP, value);
|
|
}
|
|
|
|
public T Attack
|
|
{
|
|
get => GetStatistic(Statistic.Attack);
|
|
set => SetStatistic(Statistic.Attack, value);
|
|
}
|
|
|
|
public T Defense
|
|
{
|
|
get => GetStatistic(Statistic.Defense);
|
|
set => SetStatistic(Statistic.Defense, value);
|
|
}
|
|
|
|
public T SpecialAttack
|
|
{
|
|
get => GetStatistic(Statistic.SpecialAttack);
|
|
set => SetStatistic(Statistic.SpecialAttack, value);
|
|
}
|
|
|
|
public T SpecialDefense
|
|
{
|
|
get => GetStatistic(Statistic.SpecialDefense);
|
|
set => SetStatistic(Statistic.SpecialDefense, value);
|
|
}
|
|
|
|
public T Speed
|
|
{
|
|
get => GetStatistic(Statistic.Speed);
|
|
set => SetStatistic(Statistic.Speed, value);
|
|
}
|
|
}
|
|
} |