Adds more abilities
This commit is contained in:
@@ -1,14 +1,24 @@
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Static.Species;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Dynamic.Events;
|
||||
|
||||
/// <summary>
|
||||
/// AbilityTriggerEvent is triggered when a Pokémon's ability is activated.
|
||||
/// </summary>
|
||||
public record AbilityTriggerEvent : IEventData
|
||||
{
|
||||
/// <summary>
|
||||
/// The Pokémon whose ability is being triggered.
|
||||
/// </summary>
|
||||
public IPokemon Pokemon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The ability that is being triggered for the Pokémon.
|
||||
/// </summary>
|
||||
public IAbility? Ability { get; }
|
||||
|
||||
/// <inheritdoc cref="AbilityTriggerEvent"/>
|
||||
public AbilityTriggerEvent(IPokemon pokemon)
|
||||
{
|
||||
Pokemon = pokemon;
|
||||
|
||||
@@ -20,5 +20,8 @@ public class SerializedAbility
|
||||
/// </summary>
|
||||
public string[] Flags { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the ability can be changed by effects such as Skill Swap or Role Play.
|
||||
/// </summary>
|
||||
public bool? CanBeChanged { get; set; }
|
||||
}
|
||||
@@ -814,6 +814,10 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses an item on this Pokémon.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public void UseItem(IItem item)
|
||||
{
|
||||
// TODO: actually consume the item
|
||||
@@ -851,6 +855,7 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
}
|
||||
|
||||
RecalculateBoostedStats();
|
||||
this.RunScriptHook(script => script.OnAfterStatBoostChange(this, stat, selfInflicted, change));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -418,6 +418,13 @@ public abstract class Script : IDeepCloneable
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function allows a script to run after a stat boost change has been applied.
|
||||
/// </summary>
|
||||
public virtual void OnAfterStatBoostChange(IPokemon pokemon, Statistic stat, bool selfInflicted, sbyte change)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function allows a script attached to a Pokemon or its parents to prevent an incoming
|
||||
/// secondary effect. This means the move will still hit and do damage, but not trigger its
|
||||
|
||||
@@ -37,6 +37,34 @@ public static class ScriptExecution
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a hook on all scripts in a source.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void RunScriptHook(this IEnumerable<IScriptSource> sources, Action<Script> hook)
|
||||
{
|
||||
var iterator = sources.Distinct().SelectMany(x => x.GetScripts()).ToArray();
|
||||
List<ScriptCategory>? suppressedCategories = null;
|
||||
foreach (var container in iterator)
|
||||
{
|
||||
if (container.IsEmpty)
|
||||
continue;
|
||||
var script = container.Script;
|
||||
script.OnBeforeAnyHookInvoked(ref suppressedCategories);
|
||||
}
|
||||
foreach (var container in iterator)
|
||||
{
|
||||
if (container.IsEmpty)
|
||||
continue;
|
||||
var script = container.Script;
|
||||
if (script.IsSuppressed)
|
||||
continue;
|
||||
if (suppressedCategories != null && suppressedCategories.Contains(script.Category))
|
||||
continue;
|
||||
hook(script);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a hook on all scripts in a list of sources. Note that this does not walk through the parents of the
|
||||
/// sources, but only the sources themselves.
|
||||
|
||||
Reference in New Issue
Block a user