94 lines
3.3 KiB
C#
94 lines
3.3 KiB
C#
using System;
|
|
using JetBrains.Annotations;
|
|
using PkmnLibSharp.Utils;
|
|
using Interface = PkmnLibSharp.FFI.StaticData.StaticStatisticSet;
|
|
|
|
namespace PkmnLibSharp.StaticData
|
|
{
|
|
public class StaticStatisticSet<T> : HandleType where T : struct, IConvertible
|
|
{
|
|
protected StaticStatisticSet(FFIHandle handle) : base(handle)
|
|
{
|
|
}
|
|
|
|
public static StaticStatisticSet<T> Create(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed)
|
|
{
|
|
var handle = typeof(T) switch
|
|
{
|
|
{ } t when t == typeof(ushort) => Interface.static_statistic_set_u16_new(Convert.ToUInt16(hp),
|
|
Convert.ToUInt16(attack), Convert.ToUInt16(defense), Convert.ToUInt16(specialAttack),
|
|
Convert.ToUInt16(specialDefense), Convert.ToUInt16(speed)),
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
return Resolver.Instance.ResolveStaticStatisticSet<T>(handle.Resolve());
|
|
}
|
|
|
|
[PublicAPI]
|
|
public T GetStatistic(Statistic statistic)
|
|
{
|
|
switch (statistic)
|
|
{
|
|
case Statistic.HP when _hp.HasValue:
|
|
return _hp.Value;
|
|
case Statistic.Attack when _attack.HasValue:
|
|
return _attack.Value;
|
|
case Statistic.Defense when _defense.HasValue:
|
|
return _defense.Value;
|
|
case Statistic.SpecialAttack when _specialAttack.HasValue:
|
|
return _specialAttack.Value;
|
|
case Statistic.SpecialDefense when _specialDefense.HasValue:
|
|
return _specialDefense.Value;
|
|
case Statistic.Speed when _speed.HasValue:
|
|
return _speed.Value;
|
|
}
|
|
|
|
object p = typeof(T) switch
|
|
{
|
|
{ } t when t == typeof(ushort) => Interface.static_statistic_set_u16_get_stat(Handle, statistic),
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
switch (statistic)
|
|
{
|
|
case Statistic.HP:
|
|
_hp = (T)p;
|
|
break;
|
|
case Statistic.Attack:
|
|
_attack = (T)p;
|
|
break;
|
|
case Statistic.Defense:
|
|
_defense = (T)p;
|
|
break;
|
|
case Statistic.SpecialAttack:
|
|
_specialAttack = (T)p;
|
|
break;
|
|
case Statistic.SpecialDefense:
|
|
_specialDefense = (T)p;
|
|
break;
|
|
case Statistic.Speed:
|
|
_speed = (T)p;
|
|
break;
|
|
}
|
|
|
|
return (T)p;
|
|
}
|
|
|
|
private T? _hp;
|
|
public T HP => GetStatistic(Statistic.HP);
|
|
|
|
private T? _attack;
|
|
public T Attack => GetStatistic(Statistic.Attack);
|
|
|
|
private T? _defense;
|
|
public T Defense => GetStatistic(Statistic.Defense);
|
|
|
|
private T? _specialAttack;
|
|
public T SpecialAttack => GetStatistic(Statistic.SpecialAttack);
|
|
|
|
private T? _specialDefense;
|
|
public T SpecialDefense => GetStatistic(Statistic.SpecialDefense);
|
|
|
|
private T? _speed;
|
|
public T Speed => GetStatistic(Statistic.Speed);
|
|
|
|
}
|
|
} |