155 lines
7.3 KiB
C#
155 lines
7.3 KiB
C#
using PkmnLibSharp.DynamicData.Libraries;
|
|
using PkmnLibSharp.StaticData;
|
|
using PkmnLibSharp.Utils;
|
|
using Form = PkmnLibSharp.StaticData.Form;
|
|
using Interface = PkmnLibSharp.FFI.DynamicData.Pokemon;
|
|
using Item = PkmnLibSharp.StaticData.Item;
|
|
using Species = PkmnLibSharp.StaticData.Species;
|
|
|
|
namespace PkmnLibSharp.DynamicData
|
|
{
|
|
public class Pokemon : HandleType
|
|
{
|
|
protected Pokemon(FFIHandle handle) : base(handle){}
|
|
|
|
public static Pokemon Create(DynamicLibrary dynamicLibrary, Species species, Form form, bool hiddenAbility, byte abilityIndex,
|
|
LevelInt level, uint uid, Gender gender, byte coloring, string nature)
|
|
{
|
|
var handle = Interface.pokemon_new(dynamicLibrary.Handle, species.Handle, form.Handle, hiddenAbility.ForeignBool(),
|
|
abilityIndex, level, uid, gender, coloring, nature.ToPtr())
|
|
.Result();
|
|
return Resolver.Instance.ResolvePokemon(handle.Resolve());
|
|
}
|
|
|
|
private DynamicLibrary? _library;
|
|
/// <summary>
|
|
/// The library data the Pokemon uses.
|
|
/// </summary>
|
|
public DynamicLibrary Library =>
|
|
_library ??= Resolver.Instance.ResolveDynamicLibrary(Interface.pokemon_library(Handle).Resolve());
|
|
|
|
/// <summary>
|
|
/// The species of the Pokemon.
|
|
/// </summary>
|
|
public Species Species => Resolver.Instance.ResolveSpecies(Interface.pokemon_species(Handle).Resolve());
|
|
|
|
/// <summary>
|
|
/// The form of the Pokemon.
|
|
/// </summary>
|
|
public Form Form => Resolver.Instance.ResolveForm(Interface.pokemon_form(Handle).Resolve());
|
|
|
|
/// <summary>
|
|
/// The species that should be displayed to the user. This handles stuff like the Illusion ability.
|
|
/// </summary>
|
|
public Species DisplaySpecies =>
|
|
Resolver.Instance.ResolveSpecies(Interface.pokemon_display_species(Handle).Resolve());
|
|
|
|
/// <summary>
|
|
/// The form that should be displayed to the user. This handles stuff like the Illusion ability.
|
|
/// </summary>
|
|
public Form DisplayForm => Resolver.Instance.ResolveForm(Interface.pokemon_display_form(Handle).Resolve());
|
|
|
|
public LevelInt Level => Interface.pokemon_level(Handle);
|
|
public uint Experience => Interface.pokemon_experience(Handle);
|
|
public uint UniqueIdentifier => Interface.pokemon_unique_identifier(Handle);
|
|
public Gender Gender => Interface.pokemon_gender(Handle);
|
|
public byte Coloring => Interface.pokemon_coloring(Handle);
|
|
public bool IsShiny => Coloring == 1;
|
|
|
|
public Item? HeldItem
|
|
{
|
|
get
|
|
{
|
|
var ptr = Interface.pokemon_held_item(Handle);
|
|
return ptr.IsNull ? null : Resolver.Instance.ResolveItem(ptr.Resolve());
|
|
}
|
|
}
|
|
|
|
public bool HasHeldItem(string name) => Interface.pokemon_has_held_item(Handle, name.ToPtr()) == 1;
|
|
|
|
public void SetHeldItem(Item? item)
|
|
{
|
|
if (item == null)
|
|
RemoveHeldItem();
|
|
else
|
|
Interface.pokemon_set_held_item(Handle, item.Handle);
|
|
}
|
|
|
|
public void RemoveHeldItem() => Interface.pokemon_remove_held_item(Handle);
|
|
|
|
public bool ConsumeHeldItem() => Interface.pokemon_consume_held_item(Handle).Result() == 1;
|
|
|
|
public uint CurrentHealth => Interface.pokemon_current_health(Handle);
|
|
public uint MaxHealth => Interface.pokemon_max_health(Handle);
|
|
public float Weight => Interface.pokemon_weight(Handle);
|
|
public float Height => Interface.pokemon_height(Handle);
|
|
|
|
public string? Nickname => Interface.pokemon_nickname(Handle).Result().PtrString();
|
|
public bool HasHiddenAbility => Interface.pokemon_real_ability_is_hidden(Handle) == 1;
|
|
public byte AbilityIndex => Interface.pokemon_real_ability_index(Handle);
|
|
|
|
private ExternValueArray<TypeIdentifier>? _types;
|
|
public ExternValueArray<TypeIdentifier> Types =>
|
|
_types ??= new ExternValueArray<TypeIdentifier>(() => Interface.pokemon_types_length(Handle),
|
|
arg => Interface.pokemon_types_get(Handle, arg).Result());
|
|
|
|
public LearnedMove? LearnedMove(ulong index)
|
|
{
|
|
var ptr = Interface.pokemon_learned_move_get(Handle, index);
|
|
return ptr.IsNull ? null : Resolver.Instance.ResolveLearnedMove(ptr.Resolve());
|
|
}
|
|
|
|
private StatisticSet<uint>? _flatStats;
|
|
public StatisticSet<uint> FlatStats =>
|
|
_flatStats ??=
|
|
Resolver.Instance.ResolveStatisticSet<uint>(Interface.pokemon_flat_stats(Handle).Resolve());
|
|
|
|
private StatisticSet<uint>? _boostedStats;
|
|
public StatisticSet<uint> BoostedStats =>
|
|
_boostedStats ??=
|
|
Resolver.Instance.ResolveStatisticSet<uint>(Interface.pokemon_boosted_stats(Handle).Resolve());
|
|
|
|
public sbyte GetStatBoost(Statistic statistic) => Interface.pokemon_get_stat_boost(Handle, statistic);
|
|
public byte GetIndividualValue(Statistic statistic) => Interface.pokemon_get_individual_value(Handle, statistic);
|
|
public byte GetEffortValue(Statistic statistic) => Interface.pokemon_get_effort_value(Handle, statistic);
|
|
|
|
public void SetIndividualValue(Statistic statistic, byte value) =>
|
|
Interface.pokemon_set_individual_value(Handle, statistic, value).Result();
|
|
|
|
public void SetEffortValue(Statistic statistic, byte value) =>
|
|
Interface.pokemon_set_effort_value(Handle, statistic, value).Result();
|
|
|
|
// TODO: Battle getter
|
|
public byte BattleSideIndex => Interface.pokemon_get_battle_side_index(Handle);
|
|
public byte BattleIndex => Interface.pokemon_get_battle_index(Handle);
|
|
public bool IsAbilityOverriden => Interface.pokemon_is_ability_overriden(Handle) == 1;
|
|
|
|
public Ability ActiveAbility =>
|
|
Resolver.Instance.ResolveAbility(Interface.pokemon_active_ability(Handle).Result().Resolve());
|
|
|
|
public bool AllowedExperienceGain => Interface.pokemon_allowed_experience_gain(Handle) == 1;
|
|
public Nature Nature => Resolver.Instance.ResolveNature(Interface.pokemon_nature(Handle).Resolve());
|
|
|
|
public void RecalculateFlatStats() => Interface.pokemon_recalculate_flat_stats(Handle).Result();
|
|
public void RecalculateBoostedStats() => Interface.pokemon_recalculate_boosted_stats(Handle).Result();
|
|
|
|
public void ChangeSpecies(Species species, Form form) =>
|
|
Interface.pokemon_change_species(Handle, species.Handle, form.Handle).Result();
|
|
|
|
public void ChangeForm(Form form) => Interface.pokemon_change_form(Handle, form.Handle).Result();
|
|
|
|
public bool IsUsable => Interface.pokemon_is_usable(Handle) == 1;
|
|
public bool IsFainted => Interface.pokemon_is_fainted(Handle) == 1;
|
|
public bool IsOnBattleField => Interface.pokemon_is_on_battlefield(Handle) == 1;
|
|
|
|
public void Damage(uint amount, DamageSource source) => Interface.pokemon_damage(Handle, amount, source).Result();
|
|
|
|
public bool Heal(uint amount, bool allowRevive) =>
|
|
Interface.pokemon_heal(Handle, amount, allowRevive.ForeignBool()) == 1;
|
|
|
|
public void LearnMove(string moveName, MoveLearnMethod learnMethod) =>
|
|
Interface.pokemon_learn_move(Handle, moveName.ToPtr(), learnMethod).Result();
|
|
|
|
public void ClearStatus() => Interface.pokemon_clear_status(Handle);
|
|
}
|
|
} |