First couple abilities implemented
All checks were successful
Build / Build (push) Successful in 48s
All checks were successful
Build / Build (push) Successful in 48s
This commit is contained in:
@@ -263,6 +263,8 @@ public static class MoveTurnExecutor
|
||||
}
|
||||
}
|
||||
}
|
||||
if (target.IsFainted)
|
||||
executingMove.RunScriptHook(x => x.OnOpponentFaints(executingMove, target, hitIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
PkmnLib.Dynamic/Events/AbilityTriggerEvent.cs
Normal file
20
PkmnLib.Dynamic/Events/AbilityTriggerEvent.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Static.Species;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Dynamic.Events;
|
||||
|
||||
public record AbilityTriggerEvent : IEventData
|
||||
{
|
||||
public IPokemon Pokemon { get; }
|
||||
public IAbility? Ability { get; }
|
||||
|
||||
public AbilityTriggerEvent(IPokemon pokemon)
|
||||
{
|
||||
Pokemon = pokemon;
|
||||
Ability = pokemon.ActiveAbility;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public EventBatchId BatchId { get; init; }
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public static class AbilityDataLoader
|
||||
|
||||
var flags = serialized.Flags.Select(x => new StringKey(x)).ToImmutableHashSet();
|
||||
|
||||
var ability = new AbilityImpl(name, effectName, parameters, flags);
|
||||
var ability = new AbilityImpl(name, effectName, parameters, flags, serialized.CanBeChanged ?? true);
|
||||
return ability;
|
||||
}
|
||||
}
|
||||
@@ -19,4 +19,6 @@ public class SerializedAbility
|
||||
/// A collection of arbitrary flags that can be used to mark the ability with specific properties.
|
||||
/// </summary>
|
||||
public string[] Flags { get; set; } = [];
|
||||
|
||||
public bool? CanBeChanged { get; set; }
|
||||
}
|
||||
@@ -271,18 +271,25 @@ public class BattleSideImpl : ScriptSource, IBattleSide
|
||||
pokemon.SetBattleData(Battle, Index);
|
||||
pokemon.SetOnBattlefield(true);
|
||||
pokemon.SetBattleSidePosition(position);
|
||||
Battle.EventHook.Invoke(new SwitchEvent(Index, position, pokemon));
|
||||
pokemon.RunScriptHook(script => script.OnSwitchIn(pokemon, position));
|
||||
|
||||
foreach (var side in Battle.Sides)
|
||||
{
|
||||
if (side == this)
|
||||
continue;
|
||||
var scripts = new List<IEnumerable<ScriptContainer>>(10);
|
||||
foreach (var opponent in side.Pokemon.WhereNotNull())
|
||||
{
|
||||
opponent.MarkOpponentAsSeen(pokemon);
|
||||
pokemon.MarkOpponentAsSeen(opponent);
|
||||
|
||||
scripts.Clear();
|
||||
opponent.GetOwnScripts(scripts);
|
||||
opponent.RunScriptHook(script => script.OnOpponentSwitchIn(pokemon, position));
|
||||
}
|
||||
side.RunScriptHook(script => script.OnOpponentSwitchIn(pokemon, position));
|
||||
}
|
||||
Battle.EventHook.Invoke(new SwitchEvent(Index, position, pokemon));
|
||||
pokemon.RunScriptHook(script => script.OnSwitchIn(pokemon, position));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -46,6 +46,16 @@ public interface IHitData
|
||||
/// Fails the hit.
|
||||
/// </summary>
|
||||
void Fail();
|
||||
|
||||
/// <summary>
|
||||
/// Sets a flag on the hit data. This is used to mark certain conditions or states
|
||||
/// </summary>
|
||||
void SetFlag(StringKey flag);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a flag is set on the hit data.
|
||||
/// </summary>
|
||||
bool HasFlag(StringKey flag);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -71,6 +81,18 @@ public record HitData : IHitData
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Fail() => HasFailed = true;
|
||||
|
||||
private HashSet<StringKey>? _flags;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetFlag(StringKey flag)
|
||||
{
|
||||
_flags ??= [];
|
||||
_flags.Add(flag);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasFlag(StringKey flag) => _flags != null && _flags.Contains(flag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -401,7 +401,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable
|
||||
/// <summary>
|
||||
/// Changes the ability of the Pokémon.
|
||||
/// </summary>
|
||||
void ChangeAbility(IAbility ability);
|
||||
bool ChangeAbility(IAbility ability);
|
||||
|
||||
/// <summary>
|
||||
/// Whether the Pokémon is levitating. This is used for moves like Magnet Rise, and abilities such as
|
||||
@@ -1197,8 +1197,10 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ChangeAbility(IAbility ability)
|
||||
public bool ChangeAbility(IAbility ability)
|
||||
{
|
||||
if (!ability.CanBeChanged)
|
||||
return false;
|
||||
OverrideAbility = ability;
|
||||
if (Library.ScriptResolver.TryResolve(ScriptCategory.Ability, ability.Name, ability.Parameters,
|
||||
out var abilityScript))
|
||||
@@ -1210,6 +1212,7 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
{
|
||||
AbilityScript.Clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -546,6 +546,13 @@ public abstract class Script : IDeepCloneable
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is triggered on a Pokemon and its parents when an opponent switches in.
|
||||
/// </summary>
|
||||
public virtual void OnOpponentSwitchIn(IPokemon pokemon, byte position)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is triggered on a Pokemon and its parents when the given Pokemon consumes the
|
||||
/// held item it had.
|
||||
|
||||
@@ -34,10 +34,7 @@ public class ScriptResolver
|
||||
}
|
||||
|
||||
script = scriptCtor();
|
||||
if (parameters != null)
|
||||
{
|
||||
script.OnInitialize(parameters);
|
||||
}
|
||||
script.OnInitialize(parameters);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user