51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using PkmnLibSharp.Utils;
|
|
using Interface = PkmnLibSharp.FFI.StaticData.Ability;
|
|
|
|
namespace PkmnLibSharp.StaticData
|
|
{
|
|
/// <summary>
|
|
/// An ability is a passive effect in battle that is attached to a Pokemon.
|
|
/// </summary>
|
|
public class Ability : HandleType
|
|
{
|
|
private string? _name;
|
|
|
|
/// <summary>
|
|
/// The name of the ability.
|
|
/// </summary>
|
|
public string Name => _name ??= Interface.ability_name(Handle).Result().PtrString()!;
|
|
|
|
private string? _effect;
|
|
|
|
/// <summary>
|
|
/// The name of the script effect of the ability.
|
|
/// </summary>
|
|
public string Effect => _effect ??= Interface.ability_effect(Handle).Result().PtrString()!;
|
|
|
|
/// <summary>
|
|
/// The parameters for the script effect of the ability.
|
|
/// </summary>
|
|
public IReadOnlyList<EffectParameter> Parameters { get; private set; } = null!;
|
|
|
|
/// <inheritdoc cref="Ability"/>
|
|
protected Ability(FFIHandle handle) : base(handle)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Instantiates a new ability.
|
|
/// </summary>
|
|
public static Ability Create(string name, string effect, IReadOnlyList<EffectParameter> parameters)
|
|
{
|
|
var parameterArray = parameters.Select(x => (FFIHandleValue)x.Handle).ToArray();
|
|
var arrayPtr = parameterArray.ArrayPtr();
|
|
var handle = Interface.ability_new(name.ToPtr(), effect.ToPtr(), arrayPtr, (ulong)parameterArray.LongLength)
|
|
.Result();
|
|
var ability = Resolver.Instance.ResolveAbility(handle.Resolve());
|
|
ability.Parameters = parameters;
|
|
return ability;
|
|
}
|
|
}
|
|
} |