More move scripts
This commit is contained in:
@@ -172,6 +172,7 @@ public class BattleImpl : ScriptSource, IBattle
|
||||
CanFlee = canFlee;
|
||||
NumberOfSides = numberOfSides;
|
||||
PositionsPerSide = positionsPerSide;
|
||||
Volatile = new ScriptSet(this);
|
||||
var sides = new IBattleSide[numberOfSides];
|
||||
for (byte i = 0; i < numberOfSides; i++)
|
||||
sides[i] = new BattleSideImpl(i, positionsPerSide, this);
|
||||
@@ -399,7 +400,7 @@ public class BattleImpl : ScriptSource, IBattle
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IScriptSet Volatile { get; } = new ScriptSet();
|
||||
public IScriptSet Volatile { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public StringKey? WeatherName => WeatherScript.Script?.Name;
|
||||
|
||||
@@ -132,6 +132,9 @@ public class BattleChoiceQueue : IDeepCloneable
|
||||
public ITurnChoice? FirstOrDefault(Func<ITurnChoice, bool> predicate) =>
|
||||
_choices.Skip(_currentIndex).WhereNotNull().FirstOrDefault(predicate);
|
||||
|
||||
public IEnumerable<ITurnChoice> Where(Func<ITurnChoice, bool> predicate) =>
|
||||
_choices.Skip(_currentIndex).WhereNotNull().Where(predicate);
|
||||
|
||||
/// <summary>
|
||||
/// Removes a choice from the queue.
|
||||
/// </summary>
|
||||
|
||||
@@ -174,7 +174,7 @@ public class BattleSideImpl : ScriptSource, IBattleSide
|
||||
_fillablePositions[i] = true;
|
||||
}
|
||||
Battle = battle;
|
||||
VolatileScripts = new ScriptSet();
|
||||
VolatileScripts = new ScriptSet(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -55,6 +55,7 @@ public class MoveChoice : TurnChoice, IMoveChoice
|
||||
ChosenMove = usedMove;
|
||||
TargetSide = targetSide;
|
||||
TargetPosition = targetPosition;
|
||||
Volatile = new ScriptSet(this);
|
||||
|
||||
var secondaryEffect = usedMove.MoveData.SecondaryEffect;
|
||||
if (secondaryEffect != null)
|
||||
@@ -86,7 +87,7 @@ public class MoveChoice : TurnChoice, IMoveChoice
|
||||
public Dictionary<StringKey, object?>? AdditionalData { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IScriptSet Volatile { get; } = new ScriptSet();
|
||||
public IScriptSet Volatile { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int ScriptCount => 2 + User.ScriptCount;
|
||||
|
||||
@@ -37,6 +37,11 @@ public enum MoveLearnMethod
|
||||
/// The move is learned when the Pokémon changes form.
|
||||
/// </summary>
|
||||
FormChange,
|
||||
|
||||
/// <summary>
|
||||
/// The move is learned by using a move sketch.
|
||||
/// </summary>
|
||||
Sketch,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -487,6 +487,7 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
WeightInKg = form.Weight;
|
||||
HeightInMeters = form.Height;
|
||||
Happiness = species.BaseHappiness;
|
||||
Volatile = new ScriptSet(this);
|
||||
if (!library.StaticLibrary.Natures.TryGet(natureName, out var nature))
|
||||
throw new KeyNotFoundException($"Nature {natureName} not found.");
|
||||
Nature = nature;
|
||||
@@ -532,6 +533,7 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
AbilityIndex = form.FindAbilityIndex(ability) ??
|
||||
throw new KeyNotFoundException(
|
||||
$"Ability {ability.Name} not found on species {species.Name} form {form.Name}.");
|
||||
Volatile = new ScriptSet(this);
|
||||
_learnedMoves = serializedPokemon.Moves.Select(move =>
|
||||
{
|
||||
if (move == null)
|
||||
@@ -736,7 +738,7 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
public ScriptContainer StatusScript { get; } = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IScriptSet Volatile { get; } = new ScriptSet();
|
||||
public IScriptSet Volatile { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasHeldItem(StringKey itemName) => HeldItem?.Name == itemName;
|
||||
@@ -1097,6 +1099,11 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
{
|
||||
if (!Library.ScriptResolver.TryResolve(ScriptCategory.Status, status, null, out var statusScript))
|
||||
throw new KeyNotFoundException($"Status script {status} not found");
|
||||
var preventStatus = false;
|
||||
this.RunScriptHook(script => script.PreventStatusChange(this, status, ref preventStatus));
|
||||
if (preventStatus)
|
||||
return false;
|
||||
|
||||
StatusScript.Set(statusScript);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<LangVersion>12</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<WarningsAsErrors>nullable</WarningsAsErrors>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Dynamic.Models.Choices;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
@@ -12,6 +13,7 @@ namespace PkmnLib.Dynamic.ScriptHandling;
|
||||
/// changes. This allows for easily defining generational differences, and add effects that the
|
||||
/// developer might require.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Category} - {Name}")]
|
||||
public abstract class Script : IDeepCloneable
|
||||
{
|
||||
internal event Action<Script>? OnRemoveEvent;
|
||||
@@ -683,4 +685,12 @@ public abstract class Script : IDeepCloneable
|
||||
public virtual void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void PreventStatusChange(IPokemon pokemonImpl, StringKey status, ref bool preventStatus)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void PreventVolatileAdd(Script script, ref bool preventVolatileAdd)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
@@ -14,8 +15,11 @@ public interface IScriptSet : IEnumerable<ScriptContainer>
|
||||
/// <summary>
|
||||
/// Adds a script to the set. If the script with that name already exists in this set, this
|
||||
/// makes that script stack instead. The return value here is that script.
|
||||
/// If the script was blocked from being added, this will return null.
|
||||
/// </summary>
|
||||
ScriptContainer Add(Script script);
|
||||
/// <param name="script">The script to add.</param>
|
||||
/// <param name="forceAdd">If true, the script cannot be blocked, and will always be added</param>
|
||||
ScriptContainer? Add(Script script, bool forceAdd = false);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a script with a name to the set. If the script with that name already exists in this
|
||||
@@ -77,8 +81,15 @@ public interface IScriptSet : IEnumerable<ScriptContainer>
|
||||
/// <inheritdoc cref="IScriptSet"/>
|
||||
public class ScriptSet : IScriptSet
|
||||
{
|
||||
private IScriptSource _source;
|
||||
|
||||
private readonly List<ScriptContainer> _scripts = [];
|
||||
|
||||
public ScriptSet(IScriptSource source)
|
||||
{
|
||||
_source = source;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<ScriptContainer> GetEnumerator() => _scripts.GetEnumerator();
|
||||
|
||||
@@ -86,8 +97,16 @@ public class ScriptSet : IScriptSet
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
/// <inheritdoc />
|
||||
public ScriptContainer Add(Script script)
|
||||
public ScriptContainer? Add(Script script, bool forceAdd = false)
|
||||
{
|
||||
if (!forceAdd)
|
||||
{
|
||||
var preventVolatileAdd = false;
|
||||
_source.RunScriptHook(x => x.PreventVolatileAdd(script, ref preventVolatileAdd));
|
||||
if (preventVolatileAdd)
|
||||
return null;
|
||||
}
|
||||
|
||||
var existing = _scripts.FirstOrDefault(s => s.Script?.Name == script.Name);
|
||||
if (existing != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user