Style cleanup
This commit is contained in:
@@ -12,8 +12,7 @@ public abstract class ItemScript : IDeepCloneable
|
||||
}
|
||||
|
||||
protected IItem Item { get; private set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the script with the given parameters for a specific item
|
||||
/// </summary>
|
||||
|
||||
@@ -11,14 +11,14 @@ public abstract class PokeballScript : ItemScript
|
||||
}
|
||||
|
||||
public abstract byte GetCatchRate(IPokemon target);
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnUseWithTarget(IPokemon target)
|
||||
{
|
||||
var battleData = target.BattleData;
|
||||
if (battleData == null)
|
||||
return;
|
||||
|
||||
|
||||
battleData.Battle.AttempCapture(battleData.SideIndex, battleData.Position, Item);
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,7 @@ using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
[MeansImplicitUse]
|
||||
[AttributeUsage(AttributeTargets.Class), MeansImplicitUse]
|
||||
public class ItemScriptAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -11,11 +11,11 @@ public abstract class Plugin
|
||||
protected Plugin()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
protected Plugin(PluginConfiguration configuration)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The name of the plugin. Mostly used for debugging purposes.
|
||||
/// </summary>
|
||||
|
||||
@@ -6,8 +6,7 @@ namespace PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
/// <summary>
|
||||
/// Helper attribute to register scripts through reflection.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
[MeansImplicitUse]
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false), MeansImplicitUse]
|
||||
public class ScriptAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -64,7 +64,7 @@ public class ScriptRegistry
|
||||
// This is more performant than using Activator.CreateInstance.
|
||||
_scriptTypes[(category, name)] = Expression.Lambda<Func<Script>>(Expression.New(constructor)).Compile();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Register an item script type with the given name.
|
||||
/// </summary>
|
||||
@@ -83,32 +83,32 @@ public class ScriptRegistry
|
||||
// This is more performant than using Activator.CreateInstance.
|
||||
var parameterExpression = Expression.Parameter(typeof(IItem), "item");
|
||||
var newExpression = Expression.New(constructor, parameterExpression);
|
||||
_itemScriptTypes[name] = Expression.Lambda<Func<IItem, ItemScript>>(newExpression, parameterExpression).Compile();
|
||||
_itemScriptTypes[name] =
|
||||
Expression.Lambda<Func<IItem, ItemScript>>(newExpression, parameterExpression).Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a battle stat calculator.
|
||||
/// </summary>
|
||||
public void RegisterBattleStatCalculator<T>(T battleStatCalculator)
|
||||
where T : IBattleStatCalculator => _battleStatCalculator = battleStatCalculator;
|
||||
public void RegisterBattleStatCalculator<T>(T battleStatCalculator) where T : IBattleStatCalculator =>
|
||||
_battleStatCalculator = battleStatCalculator;
|
||||
|
||||
/// <summary>
|
||||
/// Register a damage calculator.
|
||||
/// </summary>
|
||||
public void RegisterDamageCalculator<T>(T damageCalculator)
|
||||
where T : IDamageCalculator => _damageCalculator = damageCalculator;
|
||||
public void RegisterDamageCalculator<T>(T damageCalculator) where T : IDamageCalculator =>
|
||||
_damageCalculator = damageCalculator;
|
||||
|
||||
/// <summary>
|
||||
/// Register a misc library.
|
||||
/// </summary>
|
||||
public void RegisterMiscLibrary<T>(T miscLibrary) where T : IMiscLibrary
|
||||
=> _miscLibrary = miscLibrary;
|
||||
|
||||
public void RegisterMiscLibrary<T>(T miscLibrary) where T : IMiscLibrary => _miscLibrary = miscLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Register a capture library.
|
||||
/// </summary>
|
||||
public void RegisterCaptureLibrary<T>(T captureLibrary) where T : ICaptureLibrary
|
||||
=> _captureLibrary = captureLibrary;
|
||||
public void RegisterCaptureLibrary<T>(T captureLibrary) where T : ICaptureLibrary =>
|
||||
_captureLibrary = captureLibrary;
|
||||
|
||||
internal IReadOnlyDictionary<(ScriptCategory category, StringKey name), Func<Script>> ScriptTypes => _scriptTypes;
|
||||
internal IReadOnlyDictionary<StringKey, Func<IItem, ItemScript>> ItemScriptTypes => _itemScriptTypes;
|
||||
|
||||
@@ -9,14 +9,14 @@ namespace PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
public static class ScriptUtils
|
||||
{
|
||||
private static readonly Dictionary<Type, StringKey> NameCache = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resolve name from the <see cref="ScriptAttribute"/> of the given script.
|
||||
/// </summary>
|
||||
public static StringKey ResolveName(this Script script) => ResolveName(script.GetType());
|
||||
|
||||
|
||||
public static StringKey ResolveName<T>() where T : Script => ResolveName(typeof(T));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resolve name from the <see cref="ScriptAttribute"/> of the given type.
|
||||
/// </summary>
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace PkmnLib.Dynamic.ScriptHandling;
|
||||
public abstract class Script : IDeepCloneable
|
||||
{
|
||||
internal event Action<Script>? OnRemoveEvent;
|
||||
|
||||
|
||||
private int _suppressCount;
|
||||
|
||||
public void RemoveSelf()
|
||||
@@ -76,14 +76,14 @@ public abstract class Script : IDeepCloneable
|
||||
public virtual void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Override to customize whether the move can be selected at all.
|
||||
/// </summary>
|
||||
public virtual void PreventMoveSelection(IMoveChoice choice, ref bool prevent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public virtual void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice)
|
||||
{
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public abstract class Script : IDeepCloneable
|
||||
public virtual void ChangeMove(IMoveChoice choice, ref StringKey moveName)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Changes the targets of a move choice. This allows for changing the targets of a move before the move starts.
|
||||
/// </summary>
|
||||
@@ -267,7 +267,7 @@ public abstract class Script : IDeepCloneable
|
||||
public virtual void BypassDefensiveStatBoosts(IExecutingMove move, IPokemon target, byte hit, ref bool bypass)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This function allows a script to bypass evasion stat boosts for a move hit.
|
||||
/// If this is true, the move will handle the evasion stat boosts as if the target has no positive stat boosts.
|
||||
@@ -527,11 +527,11 @@ public abstract class Script : IDeepCloneable
|
||||
public virtual void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public virtual void BlockOutgoingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Custom triggers for scripts. This allows scripts to run custom events that are not part of the
|
||||
/// standard battle flow.
|
||||
@@ -555,7 +555,8 @@ public abstract class Script : IDeepCloneable
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref int modifiedAccuracy)
|
||||
public virtual void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
|
||||
ref int modifiedAccuracy)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public enum ScriptCategory
|
||||
/// <see cref="IMoveChoice"/> and <see cref="IExecutingMove"/>
|
||||
/// </summary>
|
||||
Move = 0,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A volatile script effect that is attached to a move choice.
|
||||
/// </summary>
|
||||
@@ -54,7 +54,7 @@ public enum ScriptCategory
|
||||
/// A special script for weather, for use on battles.
|
||||
/// </summary>
|
||||
Weather = 7,
|
||||
|
||||
|
||||
Terrain = 8,
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -38,11 +38,7 @@ public class ScriptContainer : IEnumerable<ScriptContainer>, IDeepCloneable
|
||||
yield return this;
|
||||
}
|
||||
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
/// <summary>
|
||||
/// Assigns a new script to this container. If there was a script already, it is removed.
|
||||
@@ -65,7 +61,7 @@ public class ScriptContainer : IEnumerable<ScriptContainer>, IDeepCloneable
|
||||
}
|
||||
Script = null;
|
||||
}
|
||||
|
||||
|
||||
public void ClearWithoutRemoving()
|
||||
{
|
||||
Script = null;
|
||||
|
||||
@@ -66,5 +66,4 @@ public static class ScriptExecution
|
||||
itemScript.OnUse();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,16 +44,10 @@ public class ScriptIterator : IEnumerable<ScriptContainer>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<ScriptContainer> GetEnumerator()
|
||||
{
|
||||
return GetAsEnumerable().GetEnumerator();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
public IEnumerator<ScriptContainer> GetEnumerator() => GetAsEnumerable().GetEnumerator();
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class ScriptResolver
|
||||
{
|
||||
script.OnInitialize(parameters);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ScriptResolver
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
var effect = item.BattleEffect;
|
||||
if (effect == null)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ public interface IScriptSet : IEnumerable<ScriptContainer>
|
||||
/// Gets a script from the set using its unique name.
|
||||
/// </summary>
|
||||
ScriptContainer? Get(StringKey scriptKey);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a script from the set using its type.
|
||||
/// </summary>
|
||||
@@ -155,8 +155,5 @@ public class ScriptSet : IScriptSet
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<StringKey> GetScriptNames() =>
|
||||
_scripts
|
||||
.Select(x => x.Script)
|
||||
.WhereNotNull()
|
||||
.Select(s => s.Name);
|
||||
_scripts.Select(x => x.Script).WhereNotNull().Select(s => s.Name);
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public interface IScriptSource
|
||||
/// Gets an iterator over all scripts that are relevant for this source.
|
||||
/// </summary>
|
||||
ScriptIterator GetScripts();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The number of scripts that are expected to be relevant for this source. This generally is
|
||||
/// The number of its own scripts + the number of scripts for any parents.
|
||||
|
||||
Reference in New Issue
Block a user