Added first script, bugfixes
This commit is contained in:
parent
5b495ac871
commit
7c0bd879b8
@ -1,10 +1,14 @@
|
|||||||
|
using JetBrains.Annotations;
|
||||||
|
using PkmnLib.Static.Utils;
|
||||||
|
|
||||||
namespace PkmnLib.Dynamic.ScriptHandling;
|
namespace PkmnLib.Dynamic.ScriptHandling;
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Class)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
[MeansImplicitUse]
|
||||||
public class ScriptAttribute : Attribute
|
public class ScriptAttribute : Attribute
|
||||||
{
|
{
|
||||||
public ScriptCategory Category { get; }
|
public ScriptCategory Category { get; }
|
||||||
public string Name { get; }
|
public StringKey Name { get; }
|
||||||
|
|
||||||
public ScriptAttribute(ScriptCategory category, string name)
|
public ScriptAttribute(ScriptCategory category, string name)
|
||||||
{
|
{
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using PkmnLib.Dynamic.Libraries;
|
using PkmnLib.Dynamic.Libraries;
|
||||||
|
using PkmnLib.Static.Utils;
|
||||||
|
|
||||||
namespace PkmnLib.Dynamic.ScriptHandling;
|
namespace PkmnLib.Dynamic.ScriptHandling;
|
||||||
|
|
||||||
public class ScriptRegistry
|
public class ScriptRegistry
|
||||||
{
|
{
|
||||||
private Dictionary<(ScriptCategory category, string name), Func<Script>> _scriptTypes = new();
|
private Dictionary<(ScriptCategory category, StringKey name), Func<Script>> _scriptTypes = new();
|
||||||
private IBattleStatCalculator? _battleStatCalculator;
|
private IBattleStatCalculator? _battleStatCalculator;
|
||||||
private IDamageCalculator? _damageCalculator;
|
private IDamageCalculator? _damageCalculator;
|
||||||
private IMiscLibrary? _miscLibrary;
|
private IMiscLibrary? _miscLibrary;
|
||||||
@ -24,10 +25,8 @@ public class ScriptRegistry
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterScriptType(ScriptCategory category, string name, Type type)
|
public void RegisterScriptType(ScriptCategory category, StringKey name, Type type)
|
||||||
{
|
{
|
||||||
if (name == null)
|
|
||||||
throw new ArgumentNullException(nameof(name));
|
|
||||||
if (type == null)
|
if (type == null)
|
||||||
throw new ArgumentNullException(nameof(type));
|
throw new ArgumentNullException(nameof(type));
|
||||||
|
|
||||||
@ -49,7 +48,7 @@ public class ScriptRegistry
|
|||||||
public void RegisterMiscLibrary<T>(T miscLibrary) where T : IMiscLibrary
|
public void RegisterMiscLibrary<T>(T miscLibrary) where T : IMiscLibrary
|
||||||
=> _miscLibrary = miscLibrary;
|
=> _miscLibrary = miscLibrary;
|
||||||
|
|
||||||
internal Dictionary<(ScriptCategory category, string name), Func<Script>> ScriptTypes => _scriptTypes;
|
internal Dictionary<(ScriptCategory category, StringKey name), Func<Script>> ScriptTypes => _scriptTypes;
|
||||||
internal IBattleStatCalculator? BattleStatCalculator => _battleStatCalculator;
|
internal IBattleStatCalculator? BattleStatCalculator => _battleStatCalculator;
|
||||||
internal IDamageCalculator? DamageCalculator => _damageCalculator;
|
internal IDamageCalculator? DamageCalculator => _damageCalculator;
|
||||||
internal IMiscLibrary? MiscLibrary => _miscLibrary;
|
internal IMiscLibrary? MiscLibrary => _miscLibrary;
|
||||||
|
52
PkmnLib.Static/Utils/NumericHelpers.cs
Normal file
52
PkmnLib.Static/Utils/NumericHelpers.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
namespace PkmnLib.Static.Utils;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper methods for numeric operations.
|
||||||
|
/// </summary>
|
||||||
|
public static class NumericHelpers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Multiplies two values. If this overflows, returns <see cref="byte.MaxValue"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static byte MultiplyOrMax(this byte value, byte multiplier)
|
||||||
|
{
|
||||||
|
var result = value * multiplier;
|
||||||
|
return result > byte.MaxValue ? byte.MaxValue : (byte)result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Multiplies two values. If this overflows, returns <see cref="byte.MaxValue"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static byte MultiplyOrMax(this byte value, float multiplier)
|
||||||
|
{
|
||||||
|
var result = value * multiplier;
|
||||||
|
return result > byte.MaxValue ? byte.MaxValue : (byte)result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Multiplies two values. If this overflows, returns <see cref="sbyte.MaxValue"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static sbyte MultiplyOrMax(this sbyte value, sbyte multiplier)
|
||||||
|
{
|
||||||
|
var result = value * multiplier;
|
||||||
|
return result > sbyte.MaxValue ? sbyte.MaxValue : (sbyte)result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Multiplies two values. If this overflows, returns <see cref="ushort.MaxValue"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static ushort MultiplyOrMax(this ushort value, ushort multiplier)
|
||||||
|
{
|
||||||
|
var result = value * multiplier;
|
||||||
|
return result > ushort.MaxValue ? ushort.MaxValue : (ushort)result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Multiplies two values. If this overflows, returns <see cref="short.MaxValue"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static short MultiplyOrMax(this short value, short multiplier)
|
||||||
|
{
|
||||||
|
var result = value * multiplier;
|
||||||
|
return result > short.MaxValue ? short.MaxValue : (short)result;
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,8 @@ public readonly record struct StringKey
|
|||||||
/// <inheritdoc cref="StringKey"/>
|
/// <inheritdoc cref="StringKey"/>
|
||||||
public StringKey(string key)
|
public StringKey(string key)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(key))
|
||||||
|
throw new ArgumentException("Key cannot be null or whitespace.", nameof(key));
|
||||||
_key = key;
|
_key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
|
|||||||
{
|
{
|
||||||
if (executingMove.UseMove.Category == MoveCategory.Status)
|
if (executingMove.UseMove.Category == MoveCategory.Status)
|
||||||
return 0;
|
return 0;
|
||||||
var basePower = hitData.BasePower;
|
var basePower = executingMove.UseMove.BasePower;
|
||||||
executingMove.RunScriptHook(script =>
|
executingMove.RunScriptHook(script =>
|
||||||
script.ChangeBasePower(executingMove, target, hitNumber, ref basePower));
|
script.ChangeBasePower(executingMove, target, hitNumber, ref basePower));
|
||||||
return basePower;
|
return basePower;
|
||||||
|
25
Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Acrobatics.cs
Normal file
25
Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Acrobatics.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using PkmnLib.Dynamic.Models;
|
||||||
|
using PkmnLib.Dynamic.ScriptHandling;
|
||||||
|
using PkmnLib.Static.Utils;
|
||||||
|
|
||||||
|
namespace PkmnLib.Plugin.Gen7.Moves;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The user nimbly strikes the target. If the user is not holding an item, this attack inflicts massive damage.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Does double base power if the user is not holding an item.
|
||||||
|
/// </remarks>
|
||||||
|
[Script(ScriptCategory.Move, "acrobatics")]
|
||||||
|
public class Acrobatics : Script
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string Name => "acrobatics";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref byte basePower)
|
||||||
|
{
|
||||||
|
if (move.User.HeldItem == null)
|
||||||
|
basePower = basePower.MultiplyOrMax(2);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user