Initial work on scripts
This commit is contained in:
parent
e17fe767bc
commit
9186d0efcc
@ -1,6 +1,36 @@
|
|||||||
|
using PkmnLib.Dynamic.Libraries;
|
||||||
|
using PkmnLib.Dynamic.Models;
|
||||||
|
using PkmnLib.Static.Utils;
|
||||||
|
|
||||||
namespace PkmnLib.Dynamic.ScriptHandling;
|
namespace PkmnLib.Dynamic.ScriptHandling;
|
||||||
|
|
||||||
public abstract class Script
|
public abstract class Script
|
||||||
{
|
{
|
||||||
|
private bool _markedForDeletion;
|
||||||
|
private int _suppressCount;
|
||||||
|
|
||||||
|
public abstract string Name { get; }
|
||||||
|
public bool MarkForDeletion() => _markedForDeletion = true;
|
||||||
|
public bool IsMarkedForDeletion() => _markedForDeletion;
|
||||||
|
public int SuppressCount() => _suppressCount;
|
||||||
|
public bool IsSuppressed() => _suppressCount > 0;
|
||||||
|
public void Suppress() => _suppressCount++;
|
||||||
|
public void Unsuppress() => _suppressCount--;
|
||||||
|
|
||||||
|
public virtual void Stack()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnRemove()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnInitialize(IDynamicLibrary library, IReadOnlyDictionary<StringKey, object> parameters)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void ChangeStabModifier(IExecutingMove executingMove, IPokemon target, byte hitNumber,
|
||||||
|
ref float modifier)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace PkmnLib.Dynamic.ScriptHandling;
|
namespace PkmnLib.Dynamic.ScriptHandling;
|
||||||
|
|
||||||
@ -6,7 +7,14 @@ public class ScriptContainer : IEnumerable<ScriptContainer>
|
|||||||
{
|
{
|
||||||
private Script? _script = null;
|
private Script? _script = null;
|
||||||
|
|
||||||
|
[MemberNotNullWhen(false, nameof(ScriptHandling.Script))]
|
||||||
public bool IsEmpty => _script is null;
|
public bool IsEmpty => _script is null;
|
||||||
|
|
||||||
|
public Script? Script
|
||||||
|
{
|
||||||
|
get => _script;
|
||||||
|
set => _script = value;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IEnumerator<ScriptContainer> GetEnumerator()
|
public IEnumerator<ScriptContainer> GetEnumerator()
|
||||||
|
16
PkmnLib.Dynamic/ScriptHandling/ScriptExecution.cs
Normal file
16
PkmnLib.Dynamic/ScriptHandling/ScriptExecution.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
namespace PkmnLib.Dynamic.ScriptHandling;
|
||||||
|
|
||||||
|
public static class ScriptExecution
|
||||||
|
{
|
||||||
|
public static void RunScriptHook(this IScriptSource source, Action<Script> hook)
|
||||||
|
{
|
||||||
|
var iterator = source.GetScripts();
|
||||||
|
foreach (var container in iterator)
|
||||||
|
{
|
||||||
|
if (container.IsEmpty)
|
||||||
|
continue;
|
||||||
|
var script = container.Script;
|
||||||
|
hook(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using PkmnLib.Dynamic.Libraries;
|
using PkmnLib.Dynamic.Libraries;
|
||||||
using PkmnLib.Dynamic.Models;
|
using PkmnLib.Dynamic.Models;
|
||||||
|
using PkmnLib.Dynamic.ScriptHandling;
|
||||||
using PkmnLib.Static;
|
using PkmnLib.Static;
|
||||||
using PkmnLib.Static.Moves;
|
using PkmnLib.Static.Moves;
|
||||||
|
|
||||||
@ -51,7 +52,8 @@ public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
|
|||||||
if (executingMove.User.Types.Contains(hitData.Type))
|
if (executingMove.User.Types.Contains(hitData.Type))
|
||||||
{
|
{
|
||||||
var stabModifier = 1.5f;
|
var stabModifier = 1.5f;
|
||||||
// TODO: script hook to change the STAB modifier
|
executingMove.RunScriptHook(script =>
|
||||||
|
script.ChangeStabModifier(executingMove, target, hitNumber, ref stabModifier));
|
||||||
floatDamage = MathF.Floor(floatDamage * stabModifier);
|
floatDamage = MathF.Floor(floatDamage * stabModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +66,7 @@ public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
|
|||||||
};
|
};
|
||||||
// TODO: script hook to modify the damage
|
// TODO: script hook to modify the damage
|
||||||
// TODO: script hook to modify incoming damage
|
// TODO: script hook to modify incoming damage
|
||||||
|
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +88,7 @@ public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
|
|||||||
return false;
|
return false;
|
||||||
byte critStage = 0;
|
byte critStage = 0;
|
||||||
// TODO: script hook to modify the crit stage
|
// TODO: script hook to modify the crit stage
|
||||||
|
|
||||||
var random = battle.Random;
|
var random = battle.Random;
|
||||||
return critStage switch
|
return critStage switch
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user