From 284ab3079cb79b178e7f1a014818ede410f05679 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 2 Mar 2025 17:19:57 +0100 Subject: [PATCH] Style cleanup --- PkmnLib.Dataloader/AbilityDataLoader.cs | 4 +- PkmnLib.Dataloader/ItemDataLoader.cs | 12 ++-- PkmnLib.Dataloader/JsonOptions.cs | 2 +- PkmnLib.Dataloader/Models/SerializedItem.cs | 5 +- PkmnLib.Dataloader/Models/SerializedMove.cs | 5 +- .../Models/SerializedSpecies.cs | 10 ++- PkmnLib.Dataloader/MoveDataLoader.cs | 16 ++--- PkmnLib.Dataloader/NatureDataLoader.cs | 6 +- PkmnLib.Dataloader/SpeciesDataLoader.cs | 51 ++++++++------ PkmnLib.Dataloader/TypeDataLoader.cs | 2 + PkmnLib.Dynamic/AI/PassTurnAI.cs | 5 +- PkmnLib.Dynamic/AI/RandomAI.cs | 4 +- PkmnLib.Dynamic/Events/CaptureAttemptEvent.cs | 2 +- PkmnLib.Dynamic/Events/DialogEvent.cs | 4 +- PkmnLib.Dynamic/Events/ExperienceGainEvent.cs | 3 +- PkmnLib.Dynamic/Events/FaintEvent.cs | 2 +- PkmnLib.Dynamic/Events/FormChangeEvent.cs | 2 +- .../Events/Handling/EventBatchId.cs | 2 +- PkmnLib.Dynamic/Events/Handling/EventHook.cs | 2 +- PkmnLib.Dynamic/Events/HealEvent.cs | 1 - PkmnLib.Dynamic/Events/MoveMissEvent.cs | 2 +- PkmnLib.Dynamic/Events/MoveUseEvent.cs | 2 +- PkmnLib.Dynamic/Events/SpeciesChangeEvent.cs | 2 +- .../Libraries/BattleStatCalculator.cs | 8 +-- PkmnLib.Dynamic/Libraries/CaptureLibrary.cs | 4 +- PkmnLib.Dynamic/Libraries/DynamicLibrary.cs | 13 ++-- PkmnLib.Dynamic/Libraries/MiscLibrary.cs | 2 +- PkmnLib.Dynamic/Models/Battle.cs | 23 +++---- PkmnLib.Dynamic/Models/BattleChoiceQueue.cs | 16 ++--- .../Models/BattleFlow/MoveTurnExecutor.cs | 45 +++++++------ .../Models/BattleFlow/TargetResolver.cs | 7 +- .../Models/BattleFlow/TurnRunner.cs | 16 ++--- PkmnLib.Dynamic/Models/BattleResult.cs | 8 +-- PkmnLib.Dynamic/Models/BattleSide.cs | 32 ++++----- PkmnLib.Dynamic/Models/Choices/FleeChoice.cs | 5 +- PkmnLib.Dynamic/Models/Choices/ItemChoice.cs | 2 +- PkmnLib.Dynamic/Models/Choices/MoveChoice.cs | 6 +- PkmnLib.Dynamic/Models/Choices/PassChoice.cs | 1 - .../Models/Choices/TurnChoiceComparer.cs | 8 +-- PkmnLib.Dynamic/Models/DamageSource.cs | 4 +- PkmnLib.Dynamic/Models/ExecutingMove.cs | 4 +- PkmnLib.Dynamic/Models/LearnedMove.cs | 13 ++-- PkmnLib.Dynamic/Models/Pokemon.cs | 67 ++++++++++--------- PkmnLib.Dynamic/Models/PokemonParty.cs | 12 ++-- .../Models/Serialized/SerializedPokemon.cs | 4 +- PkmnLib.Dynamic/ScriptHandling/ItemScript.cs | 3 +- .../ScriptHandling/PokeballScript.cs | 4 +- .../Registry/ItemScriptAttribute.cs | 3 +- .../ScriptHandling/Registry/Plugin.cs | 4 +- .../Registry/ScriptAttribute.cs | 3 +- .../ScriptHandling/Registry/ScriptRegistry.cs | 22 +++--- .../ScriptHandling/Registry/ScriptUtils.cs | 6 +- PkmnLib.Dynamic/ScriptHandling/Script.cs | 17 ++--- .../ScriptHandling/ScriptCategory.cs | 4 +- .../ScriptHandling/ScriptContainer.cs | 8 +-- .../ScriptHandling/ScriptExecution.cs | 1 - .../ScriptHandling/ScriptIterator.cs | 14 ++-- .../ScriptHandling/ScriptResolver.cs | 4 +- PkmnLib.Dynamic/ScriptHandling/ScriptSet.cs | 7 +- .../ScriptHandling/ScriptSource.cs | 2 +- PkmnLib.Dynamic/StaticHelpers.cs | 2 +- PkmnLib.Static/GrowthRate.cs | 5 +- PkmnLib.Static/Item.cs | 10 +-- PkmnLib.Static/Libraries/DataLibrary.cs | 4 +- PkmnLib.Static/Libraries/GrowthRateLibrary.cs | 7 +- PkmnLib.Static/Libraries/ItemLibrary.cs | 2 +- PkmnLib.Static/Libraries/LibrarySettings.cs | 2 +- PkmnLib.Static/Libraries/MoveLibrary.cs | 3 + PkmnLib.Static/Libraries/SpeciesLibrary.cs | 6 +- PkmnLib.Static/Libraries/StaticLibrary.cs | 13 +++- PkmnLib.Static/Libraries/TypeLibrary.cs | 2 +- PkmnLib.Static/Moves/SecondaryEffect.cs | 4 +- PkmnLib.Static/Nature.cs | 9 +-- PkmnLib.Static/Species/Ability.cs | 10 ++- PkmnLib.Static/Species/Form.cs | 25 +++---- PkmnLib.Static/Species/Gender.cs | 2 + PkmnLib.Static/Species/LearnableMoves.cs | 12 ++-- PkmnLib.Static/Species/Species.cs | 7 +- PkmnLib.Static/Statistic.cs | 9 ++- PkmnLib.Static/StatisticSet.cs | 38 +++++------ PkmnLib.Static/Utils/DeepClone.cs | 25 ++++--- PkmnLib.Static/Utils/DictionaryHelpers.cs | 3 +- PkmnLib.Static/Utils/EnumerableHelpers.cs | 2 +- .../Utils/Errors/OutOfRangeException.cs | 1 - PkmnLib.Static/Utils/NumericHelpers.cs | 11 ++- PkmnLib.Static/Utils/Random.cs | 8 +-- PkmnLib.Static/Utils/StringKey.cs | 8 +-- PkmnLib.Tests/DataTests/MoveDataTests.cs | 15 ++--- .../Dataloader/SpeciesDataloaderTests.cs | 2 +- .../Dataloader/TypeDataloaderTests.cs | 4 +- PkmnLib.Tests/GlobalUsings.cs | 1 - .../Integration/IntegrationTestRunner.cs | 14 ++-- PkmnLib.Tests/Integration/LibraryHelpers.cs | 2 +- .../Models/IntegrationTestAction.cs | 10 +-- .../Models/IntegrationTestModel.cs | 5 +- PkmnLib.Tests/Static/DeepCloneTests.cs | 32 ++++----- PkmnLib.Tests/Static/GrowthRateTests.cs | 14 ++-- PkmnLib.Tests/Static/StringKeyTests.cs | 9 +-- .../DamageCalculatorTests.cs | 12 ++-- .../Scripts/Moves/AcrobaticsTests.cs | 3 +- Plugins/PkmnLib.Plugin.Gen7/Gen7Plugin.cs | 2 +- Plugins/PkmnLib.Plugin.Gen7/GlobalUsings.cs | 2 +- .../Libraries/Gen7BattleStatCalculator.cs | 29 ++++---- .../Libraries/Gen7CaptureLibrary.cs | 7 +- .../Libraries/Gen7DamageCalculator.cs | 16 ++--- .../Libraries/Gen7MiscLibrary.cs | 14 ++-- .../Scripts/Battle/FairyLockEffect.cs | 4 +- .../Scripts/CustomTriggers.cs | 4 +- .../Scripts/Items/StaticPokeball.cs | 5 +- .../Scripts/MoveVolatile/ElectrifyEffect.cs | 3 +- .../Scripts/Moves/AfterYou.cs | 2 +- .../Scripts/Moves/AuroraVeil.cs | 4 +- .../Scripts/Moves/Autotomize.cs | 5 +- .../Scripts/Moves/BanefulBunker.cs | 5 +- .../Scripts/Moves/BatonPass.cs | 6 +- .../Scripts/Moves/BeakBlast.cs | 2 +- .../Scripts/Moves/BeatUp.cs | 5 +- .../Scripts/Moves/Belch.cs | 2 +- .../Scripts/Moves/BellyDrum.cs | 2 +- .../Scripts/Moves/Bestow.cs | 4 +- .../Scripts/Moves/Bounce.cs | 6 +- .../Scripts/Moves/BugBite.cs | 4 +- .../Scripts/Moves/BurnUp.cs | 4 +- .../Scripts/Moves/ChangeAllTargetStats.cs | 2 +- .../Moves/ChangeMultipleUserStatBoosts.cs | 7 +- .../Scripts/Moves/ChipAway.cs | 4 +- .../Scripts/Moves/Conversion2.cs | 9 +-- .../Scripts/Moves/Copycat.cs | 4 +- .../Scripts/Moves/CoreEnforcer.cs | 2 +- .../Scripts/Moves/Defog.cs | 4 +- .../PkmnLib.Plugin.Gen7/Scripts/Moves/Dig.cs | 8 +-- .../Scripts/Moves/Disable.cs | 5 +- .../PkmnLib.Plugin.Gen7/Scripts/Moves/Dive.cs | 6 +- .../Moves/DoublePowerIfTargetDamagedInTurn.cs | 2 +- .../Scripts/Moves/Drain.cs | 2 +- .../Scripts/Moves/DreamEater.cs | 2 +- .../Scripts/Moves/Electrify.cs | 3 +- .../Scripts/Moves/ElectroBall.cs | 6 +- .../Scripts/Moves/Encore.cs | 9 +-- .../Scripts/Moves/Entrainment.cs | 4 +- .../Scripts/Moves/Eruption.cs | 1 - .../Scripts/Moves/Flail.cs | 2 +- .../Scripts/Moves/FlameBurst.cs | 2 +- .../Scripts/Moves/FlareBlitz.cs | 3 +- .../PkmnLib.Plugin.Gen7/Scripts/Moves/Fly.cs | 6 +- .../Scripts/Moves/FocusPunch.cs | 2 +- .../Scripts/Moves/FollowMe.cs | 4 +- .../Scripts/Moves/FreezeDry.cs | 6 +- .../Scripts/Moves/MultiHitMove.cs | 2 +- .../Scripts/Moves/OneHitKo.cs | 3 +- .../Scripts/Moves/ProtectionScript.cs | 2 +- .../Scripts/Moves/Recoil.cs | 2 +- .../Scripts/Moves/Struggle.cs | 5 +- .../Scripts/Pokemon/BideEffect.cs | 4 +- .../Scripts/Pokemon/BindEffect.cs | 5 +- .../Scripts/Pokemon/ChargeBounceEffect.cs | 2 +- .../Scripts/Pokemon/ChargeFlyEffect.cs | 2 +- .../Scripts/Pokemon/CounterHelperEffect.cs | 2 +- .../Scripts/Pokemon/DigEffect.cs | 1 + .../Scripts/Pokemon/DiveEffect.cs | 1 + .../Scripts/Pokemon/EmbargoEffect.cs | 2 +- .../Scripts/Pokemon/EncoreEffect.cs | 7 +- .../Scripts/Pokemon/FocusPunchEffect.cs | 4 +- .../Scripts/Pokemon/ForesightEffect.cs | 8 +-- .../Scripts/Pokemon/GhostCurseEffect.cs | 4 +- .../Pokemon/HealEachEndOfTurnEffect.cs | 4 +- .../Pokemon/ProtectionFailureScript.cs | 2 +- .../Scripts/Pokemon/RequiresRechargeEffect.cs | 4 +- .../Scripts/Side/AuroraVeilEffect.cs | 12 ++-- .../Scripts/Side/CraftyShieldEffect.cs | 2 +- .../Scripts/Side/DoomDesireEffect.cs | 8 +-- .../Scripts/Status/Sleep.cs | 1 - .../Scripts/Utils/CopyableMoves.cs | 2 +- .../Scripts/Utils/TurnChoiceHelper.cs | 2 +- .../Scripts/Weather/Hail.cs | 2 +- 175 files changed, 588 insertions(+), 650 deletions(-) diff --git a/PkmnLib.Dataloader/AbilityDataLoader.cs b/PkmnLib.Dataloader/AbilityDataLoader.cs index f443967..846d06f 100644 --- a/PkmnLib.Dataloader/AbilityDataLoader.cs +++ b/PkmnLib.Dataloader/AbilityDataLoader.cs @@ -47,7 +47,7 @@ public static class AbilityDataLoader var objects = LoadAbilitiesData(stream); if (objects == null) throw new InvalidDataException("Ability data is empty."); - + var abilities = objects.Select(x => DeserializeAbility(x.Key, x.Value)); foreach (var a in abilities) library.Add(a); @@ -60,7 +60,7 @@ public static class AbilityDataLoader var parameters = serialized.Parameters.ToDictionary(x => (StringKey)x.Key, x => x.Value.ToParameter()); StringKey? effectName = effect == null ? null! : new StringKey(effect); - + var flags = serialized.Flags.Select(x => new StringKey(x)).ToImmutableHashSet(); var ability = new AbilityImpl(name, effectName, parameters, flags); diff --git a/PkmnLib.Dataloader/ItemDataLoader.cs b/PkmnLib.Dataloader/ItemDataLoader.cs index 0b80521..63b9f91 100644 --- a/PkmnLib.Dataloader/ItemDataLoader.cs +++ b/PkmnLib.Dataloader/ItemDataLoader.cs @@ -26,15 +26,15 @@ public static class ItemDataLoader library.Add(i); return library; } - + public delegate IItem ItemFactoryDelegate(SerializedItem serialized, StringKey name, ItemCategory type, - BattleItemCategory battleType, int price, ImmutableHashSet flags, - ISecondaryEffect? effect, ISecondaryEffect? battleTriggerEffect, byte flingPower); + BattleItemCategory battleType, int price, ImmutableHashSet flags, ISecondaryEffect? effect, + ISecondaryEffect? battleTriggerEffect, byte flingPower); [PublicAPI] - public static ItemFactoryDelegate ItemConstructor { get; set; } = (_, name, type, battleType, price, flags, effect, - battleTriggerEffect, flingPower) => - new ItemImpl(name, type, battleType, price, flags, effect, battleTriggerEffect, flingPower); + public static ItemFactoryDelegate ItemConstructor { get; set; } = + (_, name, type, battleType, price, flags, effect, battleTriggerEffect, flingPower) => new ItemImpl(name, type, + battleType, price, flags, effect, battleTriggerEffect, flingPower); private static IItem DeserializeItem(SerializedItem serialized) { diff --git a/PkmnLib.Dataloader/JsonOptions.cs b/PkmnLib.Dataloader/JsonOptions.cs index 3322391..e687885 100644 --- a/PkmnLib.Dataloader/JsonOptions.cs +++ b/PkmnLib.Dataloader/JsonOptions.cs @@ -4,7 +4,7 @@ namespace PkmnLib.Dataloader; internal static class JsonOptions { - public static JsonSerializerOptions DefaultOptions => new JsonSerializerOptions() + public static JsonSerializerOptions DefaultOptions => new() { PropertyNameCaseInsensitive = true, AllowTrailingCommas = true, diff --git a/PkmnLib.Dataloader/Models/SerializedItem.cs b/PkmnLib.Dataloader/Models/SerializedItem.cs index fbbf53e..05baa84 100644 --- a/PkmnLib.Dataloader/Models/SerializedItem.cs +++ b/PkmnLib.Dataloader/Models/SerializedItem.cs @@ -14,7 +14,6 @@ public class SerializedItem public byte FlingPower { get; set; } public SerializedMoveEffect? Effect { get; set; } public SerializedMoveEffect? BattleEffect { get; set; } - - [JsonExtensionData] - public Dictionary? ExtensionData { get; set; } + + [JsonExtensionData] public Dictionary? ExtensionData { get; set; } } \ No newline at end of file diff --git a/PkmnLib.Dataloader/Models/SerializedMove.cs b/PkmnLib.Dataloader/Models/SerializedMove.cs index b394aba..f6bcc48 100644 --- a/PkmnLib.Dataloader/Models/SerializedMove.cs +++ b/PkmnLib.Dataloader/Models/SerializedMove.cs @@ -22,9 +22,8 @@ public class SerializedMove public string Category { get; set; } = null!; public string[] Flags { get; set; } = null!; public SerializedMoveEffect? Effect { get; set; } - - [JsonExtensionData] - public Dictionary? ExtensionData { get; set; } + + [JsonExtensionData] public Dictionary? ExtensionData { get; set; } } public class SerializedMoveEffect diff --git a/PkmnLib.Dataloader/Models/SerializedSpecies.cs b/PkmnLib.Dataloader/Models/SerializedSpecies.cs index 8e9855c..91c4513 100644 --- a/PkmnLib.Dataloader/Models/SerializedSpecies.cs +++ b/PkmnLib.Dataloader/Models/SerializedSpecies.cs @@ -20,9 +20,8 @@ public class SerializedSpecies public string[] Flags { get; set; } = []; public Dictionary Formes { get; set; } = null!; public SerializedEvolution[] Evolutions { get; set; } = []; - - [JsonExtensionData] - public Dictionary? ExtensionData { get; set; } + + [JsonExtensionData] public Dictionary? ExtensionData { get; set; } } public class SerializedForm @@ -38,9 +37,8 @@ public class SerializedForm public bool IsMega { get; set; } public SerializedMoves Moves { get; set; } = null!; public string[] Flags { get; set; } = []; - - [JsonExtensionData] - public Dictionary? ExtensionData { get; set; } + + [JsonExtensionData] public Dictionary? ExtensionData { get; set; } } public class SerializedEvolution diff --git a/PkmnLib.Dataloader/MoveDataLoader.cs b/PkmnLib.Dataloader/MoveDataLoader.cs index a00242d..1c682be 100644 --- a/PkmnLib.Dataloader/MoveDataLoader.cs +++ b/PkmnLib.Dataloader/MoveDataLoader.cs @@ -26,11 +26,12 @@ public static class MoveDataLoader return library; } - public static Func, MoveDataImpl> MoveConstructor = - (serialized, name, moveType, category, basePower, accuracy, baseUsages, target, priority, secondaryEffect, - flags) => new MoveDataImpl(name, moveType, category, basePower, accuracy, baseUsages, target, priority, - secondaryEffect, flags); + public static + Func, MoveDataImpl> MoveConstructor = + (serialized, name, moveType, category, basePower, accuracy, baseUsages, target, priority, secondaryEffect, + flags) => new MoveDataImpl(name, moveType, category, basePower, accuracy, baseUsages, target, priority, + secondaryEffect, flags); private static MoveDataImpl DeserializeMove(SerializedMove serialized, TypeLibrary typeLibrary) { @@ -55,9 +56,8 @@ public static class MoveDataLoader throw new InvalidDataException($"Target {target} is not a valid target."); var secondaryEffect = effect.ParseEffect(); - var move = MoveConstructor(serialized, serialized.Name, typeIdentifier, categoryEnum, power, accuracy, pp, targetEnum, - priority, secondaryEffect, flags.Select(x => (StringKey)x).ToImmutableHashSet()); + var move = MoveConstructor(serialized, serialized.Name, typeIdentifier, categoryEnum, power, accuracy, pp, + targetEnum, priority, secondaryEffect, flags.Select(x => (StringKey)x).ToImmutableHashSet()); return move; } - } \ No newline at end of file diff --git a/PkmnLib.Dataloader/NatureDataLoader.cs b/PkmnLib.Dataloader/NatureDataLoader.cs index 891a49d..a542ea4 100644 --- a/PkmnLib.Dataloader/NatureDataLoader.cs +++ b/PkmnLib.Dataloader/NatureDataLoader.cs @@ -13,7 +13,7 @@ public static class NatureDataLoader public static NatureLibrary LoadNatureLibrary(Stream stream) { var library = new NatureLibrary(); - + using var reader = new StreamReader(stream); var header = reader.ReadLine(); if (header == null) @@ -31,7 +31,7 @@ public static class NatureDataLoader var nature = values[0]; var increasedStat = values[1]; var decreasedStat = values[2]; - + var increasedModifier = 1.1f; var decreasedModifier = 0.9f; @@ -46,7 +46,7 @@ public static class NatureDataLoader decreasedStat = "Hp"; decreasedModifier = 1.0f; } - + if (!Enum.TryParse(increasedStat, out var increasedStatEnum)) throw new InvalidDataException($"Increased stat {increasedStat} is not a valid stat."); if (!Enum.TryParse(decreasedStat, out var decreasedStatEnum)) diff --git a/PkmnLib.Dataloader/SpeciesDataLoader.cs b/PkmnLib.Dataloader/SpeciesDataLoader.cs index c48ccd1..d646319 100644 --- a/PkmnLib.Dataloader/SpeciesDataLoader.cs +++ b/PkmnLib.Dataloader/SpeciesDataLoader.cs @@ -20,10 +20,10 @@ public static class SpeciesDataLoader var obj = JsonSerializer.Deserialize(stream, JsonOptions.DefaultOptions); if (obj == null) throw new InvalidDataException("Species data is empty."); - return obj.Where(x => x.Key != "$schema") - .ToDictionary(x => x.Key, x => x.Value.Deserialize(JsonOptions.DefaultOptions)); + return obj.Where(x => x.Key != "$schema").ToDictionary(x => x.Key, + x => x.Value.Deserialize(JsonOptions.DefaultOptions)); } - + public static SpeciesLibrary LoadSpecies(Stream[] streams, IReadOnlyTypeLibrary typeLibrary) { var library = new SpeciesLibrary(); @@ -35,7 +35,7 @@ public static class SpeciesDataLoader library.Add(s); return library; } - + public static SpeciesLibrary LoadSpecies(Stream stream, IReadOnlyTypeLibrary typeLibrary) { var library = new SpeciesLibrary(); @@ -48,34 +48,37 @@ public static class SpeciesDataLoader return library; } - public static Func, - IEnumerable, IReadOnlyList, IEnumerable, SpeciesImpl> SpeciesConstructor = - (_, id, name, genderRate, growthRate, captureRate, baseHappiness, forms, flags, evolutionData, - eggGroups) => - { - return new SpeciesImpl(id, name, genderRate, growthRate, - captureRate, baseHappiness, forms, - flags, evolutionData, eggGroups); - }; + public static + Func, + IEnumerable, IReadOnlyList, IEnumerable, SpeciesImpl> SpeciesConstructor = + (_, id, name, genderRate, growthRate, captureRate, baseHappiness, forms, flags, evolutionData, eggGroups) => + { + return new SpeciesImpl(id, name, genderRate, growthRate, captureRate, baseHappiness, forms, flags, + evolutionData, eggGroups); + }; private static SpeciesImpl DeserializeSpecies(SerializedSpecies serialized, IReadOnlyTypeLibrary typeLibrary) { var id = serialized.Id; var genderRate = serialized.GenderRatio; if (genderRate < -1.0 || genderRate > 100.0) + { throw new InvalidDataException( $"Gender rate for species {id} is invalid: {genderRate}. Must be between -1.0 and 100.0."); + } if (serialized.EggCycles < 0) + { throw new InvalidDataException( $"Egg cycles for species {id} is invalid: {serialized.EggCycles}. Must be greater than or equal to 0."); + } var forms = serialized.Formes.ToDictionary(x => (StringKey)x.Key, x => DeserializeForm(x.Key, x.Value, typeLibrary)); var evolutions = serialized.Evolutions.Select(DeserializeEvolution).ToList(); - var species = SpeciesConstructor(serialized, serialized.Id, serialized.Species, genderRate, serialized.GrowthRate, - serialized.CatchRate, serialized.BaseHappiness, forms, + var species = SpeciesConstructor(serialized, serialized.Id, serialized.Species, genderRate, + serialized.GrowthRate, serialized.CatchRate, serialized.BaseHappiness, forms, serialized.Flags.Select(x => new StringKey(x)), evolutions, serialized.EggGroups.Select(x => (StringKey)x)); return species; } @@ -85,11 +88,15 @@ public static class SpeciesDataLoader if (form == null) throw new ArgumentException("Form data is null.", nameof(form)); if (form.Height < 0.0) + { throw new InvalidDataException( $"Height for form {name} is invalid: {form.Height}. Must be greater than or equal to 0.0."); + } if (form.Weight < 0.0) + { throw new InvalidDataException( $"Weight for form {name} is invalid: {form.Weight}. Must be greater than or equal to 0.0."); + } var types = form.Types.Select(x => typeLibrary.TryGetTypeIdentifier(new StringKey(x), out var t) ? t @@ -105,25 +112,26 @@ public static class SpeciesDataLoader { var learnableMoves = new LearnableMovesImpl(); if (moves.LevelMoves != null) + { foreach (var levelMove in moves.LevelMoves) { learnableMoves.AddLevelMove((byte)levelMove.Level, new StringKey(levelMove.Name)); } + } if (moves.EggMoves != null) + { foreach (var eggMove in moves.EggMoves) { learnableMoves.AddEggMove(new StringKey(eggMove)); } + } return learnableMoves; } - private static ImmutableStatisticSet DeserializeStats(SerializedStats stats) - { - return new ImmutableStatisticSet(stats.Hp, stats.Attack, stats.Defense, stats.SpecialAttack, - stats.SpecialDefense, stats.Speed); - } + private static ImmutableStatisticSet DeserializeStats(SerializedStats stats) => + new(stats.Hp, stats.Attack, stats.Defense, stats.SpecialAttack, stats.SpecialDefense, stats.Speed); private static IEvolution DeserializeEvolution(SerializedEvolution evolution) { @@ -223,8 +231,7 @@ public static class SpeciesDataLoader { Name = evolution.Data.AsObject()["type"]?.GetValue() ?? throw new InvalidDataException("Type is null."), - Parameters = evolution.Data.AsObject() - .Where(x => x.Key != "type") + Parameters = evolution.Data.AsObject().Where(x => x.Key != "type") .ToDictionary(x => new StringKey(x.Key), x => x.Value!.ToParameter()), ToSpecies = evolution.Species, }, diff --git a/PkmnLib.Dataloader/TypeDataLoader.cs b/PkmnLib.Dataloader/TypeDataLoader.cs index dd0dcfb..20bf632 100644 --- a/PkmnLib.Dataloader/TypeDataLoader.cs +++ b/PkmnLib.Dataloader/TypeDataLoader.cs @@ -42,8 +42,10 @@ public static class TypeDataLoader { var effectiveness = float.Parse(values[i]); if (effectiveness < 0.0) + { throw new InvalidDataException( $"Effectiveness for {type} against {types[i]} is invalid: {effectiveness}. Must be greater than or equal to 0.0."); + } library.SetEffectiveness(typeId, (TypeIdentifier)i, effectiveness); } } diff --git a/PkmnLib.Dynamic/AI/PassTurnAI.cs b/PkmnLib.Dynamic/AI/PassTurnAI.cs index c7ffcfe..4d07d97 100644 --- a/PkmnLib.Dynamic/AI/PassTurnAI.cs +++ b/PkmnLib.Dynamic/AI/PassTurnAI.cs @@ -15,8 +15,5 @@ public class PassTurnAI : PokemonAI } /// - public override ITurnChoice GetChoice(IBattle battle, IPokemon pokemon) - { - return new PassChoice(pokemon); - } + public override ITurnChoice GetChoice(IBattle battle, IPokemon pokemon) => new PassChoice(pokemon); } \ No newline at end of file diff --git a/PkmnLib.Dynamic/AI/RandomAI.cs b/PkmnLib.Dynamic/AI/RandomAI.cs index ff4623e..fd20be5 100644 --- a/PkmnLib.Dynamic/AI/RandomAI.cs +++ b/PkmnLib.Dynamic/AI/RandomAI.cs @@ -11,7 +11,7 @@ namespace PkmnLib.Dynamic.AI; public class RandomAI : PokemonAI { private IRandom _random; - + /// public RandomAI() : base("Random") { @@ -45,6 +45,4 @@ public class RandomAI : PokemonAI } return new PassChoice(pokemon); } - - } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Events/CaptureAttemptEvent.cs b/PkmnLib.Dynamic/Events/CaptureAttemptEvent.cs index e92e06c..3ceae0a 100644 --- a/PkmnLib.Dynamic/Events/CaptureAttemptEvent.cs +++ b/PkmnLib.Dynamic/Events/CaptureAttemptEvent.cs @@ -13,7 +13,7 @@ public class CaptureAttemptEvent : IEventData public IPokemon Target { get; init; } public CaptureResult Result { get; init; } - + /// public EventBatchId BatchId { get; init; } } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Events/DialogEvent.cs b/PkmnLib.Dynamic/Events/DialogEvent.cs index a89dbda..7633f9a 100644 --- a/PkmnLib.Dynamic/Events/DialogEvent.cs +++ b/PkmnLib.Dynamic/Events/DialogEvent.cs @@ -4,7 +4,7 @@ public class DialogEvent : IEventData { /// public EventBatchId BatchId { get; init; } = new(); - + public DialogEvent(string message, Dictionary? parameters = null) { Message = message; @@ -12,6 +12,6 @@ public class DialogEvent : IEventData } public string Message { get; set; } - + public Dictionary? Parameters { get; set; } } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Events/ExperienceGainEvent.cs b/PkmnLib.Dynamic/Events/ExperienceGainEvent.cs index 028bbe0..7094430 100644 --- a/PkmnLib.Dynamic/Events/ExperienceGainEvent.cs +++ b/PkmnLib.Dynamic/Events/ExperienceGainEvent.cs @@ -10,12 +10,11 @@ public class ExperienceGainEvent : IEventData PreviousExperience = previousExperience; NewExperience = newExperience; } - + public IPokemon Pokemon { get; set; } public uint PreviousExperience { get; } public uint NewExperience { get; } - /// public EventBatchId BatchId { get; init; } } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Events/FaintEvent.cs b/PkmnLib.Dynamic/Events/FaintEvent.cs index ca84af6..5b2780a 100644 --- a/PkmnLib.Dynamic/Events/FaintEvent.cs +++ b/PkmnLib.Dynamic/Events/FaintEvent.cs @@ -17,7 +17,7 @@ public class FaintEvent : IEventData /// The Pokemon that fainted. /// public IPokemon Pokemon { get; init; } - + /// public EventBatchId BatchId { get; init; } = new(); } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Events/FormChangeEvent.cs b/PkmnLib.Dynamic/Events/FormChangeEvent.cs index 0547dd9..bd90f0b 100644 --- a/PkmnLib.Dynamic/Events/FormChangeEvent.cs +++ b/PkmnLib.Dynamic/Events/FormChangeEvent.cs @@ -13,7 +13,7 @@ public class FormChangeEvent : IEventData Pokemon = pokemon; Form = form; } - + /// public EventBatchId BatchId { get; init; } } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Events/Handling/EventBatchId.cs b/PkmnLib.Dynamic/Events/Handling/EventBatchId.cs index 559623a..ceb6b7c 100644 --- a/PkmnLib.Dynamic/Events/Handling/EventBatchId.cs +++ b/PkmnLib.Dynamic/Events/Handling/EventBatchId.cs @@ -14,7 +14,7 @@ public readonly record struct EventBatchId { Id = Guid.NewGuid(); } - + /// /// The unique identifier for this batch of events. /// diff --git a/PkmnLib.Dynamic/Events/Handling/EventHook.cs b/PkmnLib.Dynamic/Events/Handling/EventHook.cs index a43ea15..f4509a5 100644 --- a/PkmnLib.Dynamic/Events/Handling/EventHook.cs +++ b/PkmnLib.Dynamic/Events/Handling/EventHook.cs @@ -10,7 +10,7 @@ public class EventHook /// The event handler that is called when the event is triggered. /// public event EventHandler? Handler; - + /// /// Triggers the event, calling the handler with the given data. /// diff --git a/PkmnLib.Dynamic/Events/HealEvent.cs b/PkmnLib.Dynamic/Events/HealEvent.cs index 2456502..0fcd33d 100644 --- a/PkmnLib.Dynamic/Events/HealEvent.cs +++ b/PkmnLib.Dynamic/Events/HealEvent.cs @@ -30,7 +30,6 @@ public class HealEvent : IEventData /// public uint NewHealth { get; } - /// public EventBatchId BatchId { get; init; } = new(); } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Events/MoveMissEvent.cs b/PkmnLib.Dynamic/Events/MoveMissEvent.cs index b466491..44d21fd 100644 --- a/PkmnLib.Dynamic/Events/MoveMissEvent.cs +++ b/PkmnLib.Dynamic/Events/MoveMissEvent.cs @@ -17,7 +17,7 @@ public class MoveMissEvent : IEventData /// Data about the move that missed. /// public IExecutingMove ExecutingMove { get; } - + /// public EventBatchId BatchId { get; init; } } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Events/MoveUseEvent.cs b/PkmnLib.Dynamic/Events/MoveUseEvent.cs index 700d09b..030723e 100644 --- a/PkmnLib.Dynamic/Events/MoveUseEvent.cs +++ b/PkmnLib.Dynamic/Events/MoveUseEvent.cs @@ -17,7 +17,7 @@ public class MoveUseEvent : IEventData { ExecutingMove = executingMove; } - + /// public EventBatchId BatchId { get; init; } } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Events/SpeciesChangeEvent.cs b/PkmnLib.Dynamic/Events/SpeciesChangeEvent.cs index 97aadbd..4307cbf 100644 --- a/PkmnLib.Dynamic/Events/SpeciesChangeEvent.cs +++ b/PkmnLib.Dynamic/Events/SpeciesChangeEvent.cs @@ -15,7 +15,7 @@ public class SpeciesChangeEvent : IEventData Species = species; Form = form; } - + /// public EventBatchId BatchId { get; init; } } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Libraries/BattleStatCalculator.cs b/PkmnLib.Dynamic/Libraries/BattleStatCalculator.cs index 2275927..99b64c6 100644 --- a/PkmnLib.Dynamic/Libraries/BattleStatCalculator.cs +++ b/PkmnLib.Dynamic/Libraries/BattleStatCalculator.cs @@ -12,22 +12,22 @@ public interface IBattleStatCalculator /// Calculate all the flat stats of a Pokemon, disregarding stat boosts. /// void CalculateFlatStats(IPokemon pokemon, StatisticSet stats); - + /// /// Calculate a single flat stat of a Pokemon, disregarding stat boosts. /// uint CalculateFlatStat(IPokemon pokemon, Statistic stat); - + /// /// Calculate all the boosted stats of a Pokemon, including stat boosts. /// void CalculateBoostedStats(IPokemon pokemon, StatisticSet stats); - + /// /// Calculate a single boosted stat of a Pokemon, including stat boosts. /// uint CalculateBoostedStat(IPokemon pokemon, Statistic stat); - + /// /// Calculates the accuracy for a move, taking into account any accuracy modifiers. /// diff --git a/PkmnLib.Dynamic/Libraries/CaptureLibrary.cs b/PkmnLib.Dynamic/Libraries/CaptureLibrary.cs index c8341f0..fcb045d 100644 --- a/PkmnLib.Dynamic/Libraries/CaptureLibrary.cs +++ b/PkmnLib.Dynamic/Libraries/CaptureLibrary.cs @@ -15,8 +15,8 @@ public record struct CaptureResult public bool IsCaught { get; init; } public int Shakes { get; init; } public bool CriticalCapture { get; init; } - - public static CaptureResult Failed => new CaptureResult(false, 0, false); + + public static CaptureResult Failed => new(false, 0, false); } public interface ICaptureLibrary diff --git a/PkmnLib.Dynamic/Libraries/DynamicLibrary.cs b/PkmnLib.Dynamic/Libraries/DynamicLibrary.cs index 1bb237b..02874ac 100644 --- a/PkmnLib.Dynamic/Libraries/DynamicLibrary.cs +++ b/PkmnLib.Dynamic/Libraries/DynamicLibrary.cs @@ -31,12 +31,12 @@ public interface IDynamicLibrary /// calculators. /// IMiscLibrary MiscLibrary { get; } - + /// /// The capture library deals with the calculation of the capture rate of a Pokémon. /// ICaptureLibrary CaptureLibrary { get; } - + /// /// A holder of the script types that can be resolved by this library. /// @@ -66,12 +66,13 @@ public class DynamicLibraryImpl : IDynamicLibrary if (registry.CaptureLibrary is null) throw new InvalidOperationException("Capture library not found in plugins."); var scriptResolver = new ScriptResolver(registry.ScriptTypes, registry.ItemScriptTypes); - return new DynamicLibraryImpl(staticLibrary, registry.BattleStatCalculator, - registry.DamageCalculator, registry.MiscLibrary, registry.CaptureLibrary, scriptResolver); + return new DynamicLibraryImpl(staticLibrary, registry.BattleStatCalculator, registry.DamageCalculator, + registry.MiscLibrary, registry.CaptureLibrary, scriptResolver); } - + private DynamicLibraryImpl(IStaticLibrary staticLibrary, IBattleStatCalculator statCalculator, - IDamageCalculator damageCalculator, IMiscLibrary miscLibrary, ICaptureLibrary captureLibrary, ScriptResolver scriptResolver) + IDamageCalculator damageCalculator, IMiscLibrary miscLibrary, ICaptureLibrary captureLibrary, + ScriptResolver scriptResolver) { StaticLibrary = staticLibrary; StatCalculator = statCalculator; diff --git a/PkmnLib.Dynamic/Libraries/MiscLibrary.cs b/PkmnLib.Dynamic/Libraries/MiscLibrary.cs index c08f971..7549d4b 100644 --- a/PkmnLib.Dynamic/Libraries/MiscLibrary.cs +++ b/PkmnLib.Dynamic/Libraries/MiscLibrary.cs @@ -14,7 +14,7 @@ public interface IMiscLibrary /// moves left, yet wants to make a move. /// ITurnChoice ReplacementChoice(IPokemon user, byte targetSide, byte targetPosition); - + /// /// Gets the current time of day for the battle. /// diff --git a/PkmnLib.Dynamic/Models/Battle.cs b/PkmnLib.Dynamic/Models/Battle.cs index d118e02..7acf24c 100644 --- a/PkmnLib.Dynamic/Models/Battle.cs +++ b/PkmnLib.Dynamic/Models/Battle.cs @@ -94,7 +94,7 @@ public interface IBattle : IScriptSource, IDeepCloneable void ValidateBattleState(); bool HasForcedTurn(IPokemon pokemon, [NotNullWhen(true)] out ITurnChoice? choice); - + /// /// Checks whether a choice is actually possible. /// @@ -111,22 +111,22 @@ public interface IBattle : IScriptSource, IDeepCloneable void SetWeather(StringKey? weatherName); public IScriptSet Volatile { get; } - + /// /// Gets the current weather of the battle. If no weather is present, this returns null. /// StringKey? WeatherName { get; } void SetTerrain(StringKey? terrainName); - + StringKey? TerrainName { get; } - + /// /// Gets the turn choices of the previous turn. This is a list of lists, where each list represents the choices /// for a single turn. The outer list is ordered from oldest to newest turn. /// IReadOnlyList> PreviousTurnChoices { get; } - + CaptureResult AttempCapture(byte sideIndex, byte position, IItem item); } @@ -247,10 +247,10 @@ public class BattleImpl : ScriptSource, IBattle choice = null; return false; } - + ITurnChoice? forcedChoice = null; - pokemon.RunScriptHook( - script => script.ForceTurnSelection(battleData.SideIndex, battleData.Position, ref forcedChoice)); + pokemon.RunScriptHook(script => + script.ForceTurnSelection(battleData.SideIndex, battleData.Position, ref forcedChoice)); choice = forcedChoice; return choice != null; } @@ -262,7 +262,7 @@ public class BattleImpl : ScriptSource, IBattle return false; if (HasForcedTurn(choice.User, out var forcedChoice) && choice != forcedChoice) return false; - + if (choice is IMoveChoice moveChoice) { // TODO: Hook to change number of PP needed. @@ -365,7 +365,7 @@ public class BattleImpl : ScriptSource, IBattle /// public StringKey? WeatherName => _weatherScript.Script?.Name; - + private readonly ScriptContainer _terrainScript = new(); /// @@ -386,7 +386,6 @@ public class BattleImpl : ScriptSource, IBattle /// public StringKey? TerrainName => _terrainScript.Script?.Name; - private readonly List> _previousTurnChoices = new(); /// @@ -398,7 +397,7 @@ public class BattleImpl : ScriptSource, IBattle var target = GetPokemon(sideIndex, position); if (target is not { IsUsable: true }) return CaptureResult.Failed; - + var attemptCapture = Library.CaptureLibrary.TryCapture(target, item, Random); if (attemptCapture.IsCaught) { diff --git a/PkmnLib.Dynamic/Models/BattleChoiceQueue.cs b/PkmnLib.Dynamic/Models/BattleChoiceQueue.cs index c49333e..5813643 100644 --- a/PkmnLib.Dynamic/Models/BattleChoiceQueue.cs +++ b/PkmnLib.Dynamic/Models/BattleChoiceQueue.cs @@ -23,7 +23,7 @@ public class BattleChoiceQueue : IDeepCloneable { _choices = choices; } - + /// /// Dequeues the next turn choice to be executed. This gives back the choice and sets it to null in the queue. It /// also increments the internal index. @@ -40,18 +40,17 @@ public class BattleChoiceQueue : IDeepCloneable LastRanChoice = choice; return choice; } - + /// /// This reads what the next choice to execute will be, without modifying state. /// public ITurnChoice? Peek() => _currentIndex >= _choices.Length ? null : _choices[_currentIndex]; - + /// /// Checks if there are any more choices to execute. /// public bool HasNext() => _currentIndex < _choices.Length; - /// /// This resorts the yet to be executed choices. This can be useful for dealing with situations /// such as Pokémon changing forms just after the very start of a turn, when turn order has @@ -72,7 +71,7 @@ public class BattleChoiceQueue : IDeepCloneable choice.User.RunScriptHook(script => script.ChangeSpeed(choice, ref speed)); choice.Speed = speed; } - + // We only sort the choices that are left Array.Sort(_choices, currentIndex, length - currentIndex, TurnChoiceComparer.Instance!); } @@ -99,8 +98,9 @@ public class BattleChoiceQueue : IDeepCloneable _choices[_currentIndex] = choice; return true; } - + internal IReadOnlyList GetChoices() => _choices; - - public ITurnChoice? FirstOrDefault(Func predicate) => _choices.WhereNotNull().FirstOrDefault(predicate); + + public ITurnChoice? FirstOrDefault(Func predicate) => + _choices.WhereNotNull().FirstOrDefault(predicate); } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Models/BattleFlow/MoveTurnExecutor.cs b/PkmnLib.Dynamic/Models/BattleFlow/MoveTurnExecutor.cs index 0f01e9d..3023ac5 100644 --- a/PkmnLib.Dynamic/Models/BattleFlow/MoveTurnExecutor.cs +++ b/PkmnLib.Dynamic/Models/BattleFlow/MoveTurnExecutor.cs @@ -12,7 +12,7 @@ internal static class MoveTurnExecutor { var chosenMove = moveChoice.ChosenMove; var moveData = chosenMove.MoveData; - + var moveDataName = moveData.Name; moveChoice.RunScriptHook(x => x.ChangeMove(moveChoice, ref moveDataName)); if (moveData.Name != moveDataName) @@ -31,11 +31,11 @@ internal static class MoveTurnExecutor moveChoice.Script.Set(script); } } - } var targetType = moveData.Target; - var targets = TargetResolver.ResolveTargets(battle, moveChoice.TargetSide, moveChoice.TargetPosition, targetType); + var targets = + TargetResolver.ResolveTargets(battle, moveChoice.TargetSide, moveChoice.TargetPosition, targetType); moveChoice.RunScriptHook(x => x.ChangeTargets(moveChoice, ref targets)); byte numberOfHits = 1; @@ -46,7 +46,7 @@ internal static class MoveTurnExecutor } var executingMove = new ExecutingMoveImpl(targets, numberOfHits, chosenMove, moveData, moveChoice); - + var prevented = false; executingMove.RunScriptHook(x => x.PreventMove(executingMove, ref prevented)); if (prevented) @@ -56,9 +56,9 @@ internal static class MoveTurnExecutor // TODO: Modify the PP used by the move. if (!executingMove.ChosenMove.TryUse(ppUsed)) return; - + battle.EventHook.Invoke(new MoveUseEvent(executingMove)); - + var failed = false; executingMove.RunScriptHook(x => x.FailMove(executingMove, ref failed)); if (failed) @@ -66,12 +66,12 @@ internal static class MoveTurnExecutor // TODO: fail handling return; } - + var stopped = false; executingMove.RunScriptHook(x => x.StopBeforeMove(executingMove, ref stopped)); if (stopped) return; - + executingMove.RunScriptHook(x => x.OnBeforeMove(executingMove)); foreach (var target in targets.WhereNotNull()) { @@ -88,7 +88,7 @@ internal static class MoveTurnExecutor // TODO: fail handling return; } - + var isInvulnerable = false; target.RunScriptHook(x => x.IsInvulnerableToMove(executingMove, target, ref isInvulnerable)); if (isInvulnerable) @@ -96,7 +96,7 @@ internal static class MoveTurnExecutor // TODO: event? return; } - + var numberOfHits = executingMove.NumberOfHits; var targetHitStat = executingMove.GetTargetIndex(target) * numberOfHits; @@ -120,7 +120,7 @@ internal static class MoveTurnExecutor var effectiveness = battle.Library.StaticLibrary.Types.GetEffectiveness(hitType, target.Types); executingMove.RunScriptHook(x => x.ChangeEffectiveness(executingMove, target, hitIndex, ref effectiveness)); hitData.Effectiveness = effectiveness; - + var blockCritical = false; executingMove.RunScriptHook(x => x.BlockCriticalHit(executingMove, target, hitIndex, ref blockCritical)); target.RunScriptHook(x => x.BlockIncomingCriticalHit(executingMove, target, hitIndex, ref blockCritical)); @@ -129,10 +129,10 @@ internal static class MoveTurnExecutor var critical = battle.Library.DamageCalculator.IsCritical(battle, executingMove, target, hitIndex); hitData.IsCritical = critical; } - + var basePower = battle.Library.DamageCalculator.GetBasePower(executingMove, target, hitIndex, hitData); hitData.BasePower = basePower; - + hitData.Damage = battle.Library.DamageCalculator.GetDamage(executingMove, target, hitIndex, hitData); var accuracy = useMove.Accuracy; @@ -140,17 +140,17 @@ internal static class MoveTurnExecutor // modifying it. if (accuracy != 255) { - accuracy = battle.Library.StatCalculator.CalculateModifiedAccuracy(executingMove, target, - hitIndex, accuracy); + accuracy = battle.Library.StatCalculator.CalculateModifiedAccuracy(executingMove, target, hitIndex, + accuracy); } - + if (accuracy < 100 && battle.Random.GetInt(100) >= accuracy) { executingMove.RunScriptHook(x => x.OnMoveMiss(executingMove, target)); battle.EventHook.Invoke(new MoveMissEvent(executingMove)); break; } - + var blockIncomingHit = false; target.RunScriptHook(x => x.BlockIncomingHit(executingMove, target, hitIndex, ref blockIncomingHit)); executingMove.RunScriptHook(x => x.BlockOutgoingHit(executingMove, target, hitIndex, ref blockIncomingHit)); @@ -187,7 +187,7 @@ internal static class MoveTurnExecutor BatchId = hitEventBatch, }); target.Damage(damage, DamageSource.MoveDamage, hitEventBatch); - if (!target.IsFainted) + if (!target.IsFainted) target.RunScriptHook(x => x.OnIncomingHit(executingMove, target, hitIndex)); else executingMove.RunScriptHook(x => x.OnOpponentFaints(executingMove, target, hitIndex)); @@ -198,14 +198,16 @@ internal static class MoveTurnExecutor if (secondaryEffect != null) { var preventSecondary = false; - target.RunScriptHook(x => x.PreventSecondaryEffect(executingMove, target, hitIndex, ref preventSecondary)); + target.RunScriptHook(x => + x.PreventSecondaryEffect(executingMove, target, hitIndex, ref preventSecondary)); if (!preventSecondary) { var chance = secondaryEffect.Chance; if (chance < 0 || battle.Random.EffectChance(chance, executingMove, target, hitIndex)) { - executingMove.RunScriptHook(x => x.OnSecondaryEffect(executingMove, target, hitIndex)); + executingMove.RunScriptHook(x => + x.OnSecondaryEffect(executingMove, target, hitIndex)); } } } @@ -213,7 +215,7 @@ internal static class MoveTurnExecutor } } } - + if (numberOfHits == 0) { target.RunScriptHook(x => x.OnMoveMiss(executingMove, target)); @@ -224,6 +226,5 @@ internal static class MoveTurnExecutor { executingMove.RunScriptHook(x => x.OnAfterHits(executingMove, target)); } - } } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Models/BattleFlow/TargetResolver.cs b/PkmnLib.Dynamic/Models/BattleFlow/TargetResolver.cs index e77b0e7..76754d0 100644 --- a/PkmnLib.Dynamic/Models/BattleFlow/TargetResolver.cs +++ b/PkmnLib.Dynamic/Models/BattleFlow/TargetResolver.cs @@ -15,8 +15,8 @@ public static class TargetResolver return target switch { MoveTarget.Adjacent or MoveTarget.AdjacentAlly or MoveTarget.AdjacentAllySelf or MoveTarget.AdjacentOpponent - or MoveTarget.Any or MoveTarget.RandomOpponent - or MoveTarget.SelfUse => [battle.GetPokemon(side, position)], + or MoveTarget.Any or MoveTarget.RandomOpponent or MoveTarget.SelfUse => + [battle.GetPokemon(side, position)], MoveTarget.All => GetAllTargets(battle), MoveTarget.AllAdjacentOpponent => GetAllAdjacentAndOpponent(battle, side, position), MoveTarget.AllAdjacent => GetAllAdjacent(battle, side, position), @@ -144,7 +144,8 @@ public static class TargetResolver return [ - battle.GetPokemon(side, position), battle.GetPokemon(side, (byte)left), battle.GetPokemon(side, (byte)right), + battle.GetPokemon(side, position), battle.GetPokemon(side, (byte)left), + battle.GetPokemon(side, (byte)right), ]; } } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Models/BattleFlow/TurnRunner.cs b/PkmnLib.Dynamic/Models/BattleFlow/TurnRunner.cs index bc2d502..ec87d28 100644 --- a/PkmnLib.Dynamic/Models/BattleFlow/TurnRunner.cs +++ b/PkmnLib.Dynamic/Models/BattleFlow/TurnRunner.cs @@ -16,9 +16,11 @@ public static class TurnRunner { var queue = battle.ChoiceQueue; if (queue == null) + { throw new ArgumentNullException(nameof(battle.ChoiceQueue), "The battle's choice queue must be set before running a turn."); - + } + // We are now at the very beginning of a turn. We have assigned speeds and priorities to all // choices, and put them in the correct order. @@ -30,7 +32,7 @@ public static class TurnRunner { choice.RunScriptHook(script => script.OnBeforeTurnStart(choice)); } - + // Now we can properly begin executing choices. // One by one dequeue the turns, and run them. If the battle has ended we do not want to // continue running. @@ -41,7 +43,7 @@ public static class TurnRunner continue; ExecuteChoice(battle, next); } - + // If the battle is not ended, we have arrived at the normal end of a turn. and thus want // to run the end turn scripts. @@ -122,7 +124,6 @@ public static class TurnRunner userSide.SwapPokemon(battleData.Position, fleeChoice.SwitchTo); } - private static void ExecuteFleeChoice(IBattle battle, IFleeChoice fleeChoice) { var user = fleeChoice.User; @@ -131,7 +132,7 @@ public static class TurnRunner return; if (!battle.CanFlee) return; - + var preventFlee = false; fleeChoice.RunScriptHook(script => script.PreventSelfRunAway(fleeChoice, ref preventFlee)); if (preventFlee) @@ -148,10 +149,10 @@ public static class TurnRunner return; } } - + if (!battle.Library.MiscLibrary.CanFlee(battle, fleeChoice)) return; - + var userSide = battle.Sides[battleData.SideIndex]; userSide.MarkAsFled(); battle.ValidateBattleState(); @@ -171,5 +172,4 @@ public static class TurnRunner } itemChoice.Item.RunItemScript(battle.Library.ScriptResolver, target ?? user); } - } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Models/BattleResult.cs b/PkmnLib.Dynamic/Models/BattleResult.cs index 1c2ca03..62a24ce 100644 --- a/PkmnLib.Dynamic/Models/BattleResult.cs +++ b/PkmnLib.Dynamic/Models/BattleResult.cs @@ -10,22 +10,22 @@ public record struct BattleResult ConclusiveResult = conclusiveResult; WinningSide = winningSide; } - + /// /// An inconclusive battle result. This means no side has won. /// public static BattleResult Inconclusive => new(false, null); - + /// /// A conclusive battle result. This means one side has won. /// public static BattleResult Conclusive(byte winningSide) => new(true, winningSide); - + /// /// Whether the battle has a conclusive result. If false, no side has won. /// public bool ConclusiveResult { get; } - + /// /// The side that won the battle. If null, no side has won. /// diff --git a/PkmnLib.Dynamic/Models/BattleSide.cs b/PkmnLib.Dynamic/Models/BattleSide.cs index 335f740..895be12 100644 --- a/PkmnLib.Dynamic/Models/BattleSide.cs +++ b/PkmnLib.Dynamic/Models/BattleSide.cs @@ -14,48 +14,48 @@ public interface IBattleSide : IScriptSource, IDeepCloneable /// The index of the side on the battle. /// byte Index { get; } - + /// /// The number of Pokémon that can be on the side. /// byte NumberOfPositions { get; } - + /// /// A list of Pokémon currently on the battlefield. /// IReadOnlyList Pokemon { get; } - + /// /// The currently set choices for all Pokémon on the battlefield. Cleared when the turn starts. /// IReadOnlyList SetChoices { get; } - + /// /// Whether every Pokémon on this side has its choices /// bool AllChoicesSet { get; } - + /// /// The slots on the side that can still be filled. Once all slots are set to false, this side /// has lost the battle. /// IReadOnlyList FillablePositions { get; } - + /// /// A reference to the battle this side is in. /// IBattle Battle { get; } - + /// /// Whether this side has fled. /// bool HasFledBattle { get; } - + /// /// The volatile scripts that are attached to the side. /// IScriptSet VolatileScripts { get; } - + /// /// Returns true if there are slots that need to be filled with a new pokemon, that have parties /// responsible for them. Returns false if all slots are filled with usable pokemon, or slots are @@ -67,7 +67,7 @@ public interface IBattleSide : IScriptSource, IDeepCloneable /// Sets a choice for a Pokémon on this side. /// void SetChoice(byte position, ITurnChoice choice); - + /// /// Resets all choices on this side. /// @@ -110,12 +110,12 @@ public interface IBattleSide : IScriptSource, IDeepCloneable /// Checks whether the side has been defeated. /// bool IsDefeated(); - + /// /// The number of times this side has attempted to flee. /// uint FleeAttempts { get; } - + /// /// Registers a flee attempt for this side. /// @@ -150,7 +150,7 @@ public class BattleSideImpl : ScriptSource, IBattleSide Battle = battle; VolatileScripts = new ScriptSet(); } - + /// public byte Index { get; } @@ -158,6 +158,7 @@ public class BattleSideImpl : ScriptSource, IBattleSide public byte NumberOfPositions { get; } private readonly IPokemon?[] _pokemon; + /// public IReadOnlyList Pokemon => _pokemon; @@ -170,6 +171,7 @@ public class BattleSideImpl : ScriptSource, IBattleSide public bool AllChoicesSet => _setChoices.All(choice => choice is not null); private readonly bool[] _fillablePositions; + /// public IReadOnlyList FillablePositions => _fillablePositions; @@ -223,7 +225,7 @@ public class BattleSideImpl : ScriptSource, IBattleSide pokemon.RunScriptHook(script => script.OnRemove()); pokemon.SetOnBattlefield(false); } - + _pokemon[index] = null; } @@ -259,7 +261,7 @@ public class BattleSideImpl : ScriptSource, IBattleSide { Battle.EventHook.Invoke(new SwitchEvent(Index, position, null)); } - + return oldPokemon; } diff --git a/PkmnLib.Dynamic/Models/Choices/FleeChoice.cs b/PkmnLib.Dynamic/Models/Choices/FleeChoice.cs index 597a423..30d8e09 100644 --- a/PkmnLib.Dynamic/Models/Choices/FleeChoice.cs +++ b/PkmnLib.Dynamic/Models/Choices/FleeChoice.cs @@ -7,7 +7,6 @@ namespace PkmnLib.Dynamic.Models.Choices; /// public interface IFleeChoice : ITurnChoice { - } /// @@ -22,7 +21,9 @@ public class FleeTurnChoice : TurnChoice, IFleeChoice public override int ScriptCount => User.ScriptCount; /// - public override void GetOwnScripts(List> scripts) { } + public override void GetOwnScripts(List> scripts) + { + } /// public override void CollectScripts(List> scripts) => User.CollectScripts(scripts); diff --git a/PkmnLib.Dynamic/Models/Choices/ItemChoice.cs b/PkmnLib.Dynamic/Models/Choices/ItemChoice.cs index 80b6e72..e7634e5 100644 --- a/PkmnLib.Dynamic/Models/Choices/ItemChoice.cs +++ b/PkmnLib.Dynamic/Models/Choices/ItemChoice.cs @@ -12,7 +12,7 @@ public interface IItemChoice : ITurnChoice /// The item that is used. /// public IItem Item { get; } - + /// /// The side the move is targeted at. /// diff --git a/PkmnLib.Dynamic/Models/Choices/MoveChoice.cs b/PkmnLib.Dynamic/Models/Choices/MoveChoice.cs index e5c7e3a..3cb6177 100644 --- a/PkmnLib.Dynamic/Models/Choices/MoveChoice.cs +++ b/PkmnLib.Dynamic/Models/Choices/MoveChoice.cs @@ -32,9 +32,9 @@ public interface IMoveChoice : ITurnChoice /// The underlying script of the move. /// ScriptContainer Script { get; set; } - + Dictionary? AdditionalData { get; } - + IScriptSet Volatile { get; } } @@ -47,7 +47,7 @@ public class MoveChoice : TurnChoice, IMoveChoice ChosenMove = usedMove; TargetSide = targetSide; TargetPosition = targetPosition; - + var secondaryEffect = usedMove.MoveData.SecondaryEffect; if (secondaryEffect != null) { diff --git a/PkmnLib.Dynamic/Models/Choices/PassChoice.cs b/PkmnLib.Dynamic/Models/Choices/PassChoice.cs index 1cd5abd..ec99f0c 100644 --- a/PkmnLib.Dynamic/Models/Choices/PassChoice.cs +++ b/PkmnLib.Dynamic/Models/Choices/PassChoice.cs @@ -7,7 +7,6 @@ namespace PkmnLib.Dynamic.Models.Choices; /// public interface IPassChoice : ITurnChoice { - } public class PassChoice : TurnChoice, IPassChoice diff --git a/PkmnLib.Dynamic/Models/Choices/TurnChoiceComparer.cs b/PkmnLib.Dynamic/Models/Choices/TurnChoiceComparer.cs index b9084cf..27a7139 100644 --- a/PkmnLib.Dynamic/Models/Choices/TurnChoiceComparer.cs +++ b/PkmnLib.Dynamic/Models/Choices/TurnChoiceComparer.cs @@ -7,7 +7,7 @@ public class TurnChoiceComparer : IComparer { /// public static TurnChoiceComparer Instance { get; } = new(); - + private enum CompareValues { XEqualsY = 0, @@ -25,7 +25,7 @@ public class TurnChoiceComparer : IComparer // This is to ensure that the order of choices is deterministic. return (CompareValues)x.RandomValue.CompareTo(y.RandomValue); } - + private static CompareValues CompareImpl(ITurnChoice? x, ITurnChoice? y) { // Deal with possible null values @@ -77,10 +77,10 @@ public class TurnChoiceComparer : IComparer _ => CompareValues.XGreaterThanY, }; } - + return CompareValues.XLessThanY; } /// - public int Compare(ITurnChoice? x, ITurnChoice? y) => (int) CompareImpl(x, y); + public int Compare(ITurnChoice? x, ITurnChoice? y) => (int)CompareImpl(x, y); } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Models/DamageSource.cs b/PkmnLib.Dynamic/Models/DamageSource.cs index 9b1242f..5ed2a0d 100644 --- a/PkmnLib.Dynamic/Models/DamageSource.cs +++ b/PkmnLib.Dynamic/Models/DamageSource.cs @@ -19,13 +19,13 @@ public enum DamageSource /// The damage is done because of struggling. /// Struggle = 2, - + /// /// The damage is done because of a form change. /// This happens when the form of a Pokemon changes, and it has less max HP than it had before. /// FormChange = 3, - + /// /// The damage is done because of the weather. /// diff --git a/PkmnLib.Dynamic/Models/ExecutingMove.cs b/PkmnLib.Dynamic/Models/ExecutingMove.cs index 9b6c6f0..f948483 100644 --- a/PkmnLib.Dynamic/Models/ExecutingMove.cs +++ b/PkmnLib.Dynamic/Models/ExecutingMove.cs @@ -129,12 +129,12 @@ public interface IExecutingMove : IScriptSource /// Gets a hit based on its raw index. /// IHitData GetDataFromRawIndex(int index); - + /// /// Gets the targets of this move. /// IReadOnlyList Targets { get; } - + /// /// The underlying move choice. /// diff --git a/PkmnLib.Dynamic/Models/LearnedMove.cs b/PkmnLib.Dynamic/Models/LearnedMove.cs index 771eba1..0bc7269 100644 --- a/PkmnLib.Dynamic/Models/LearnedMove.cs +++ b/PkmnLib.Dynamic/Models/LearnedMove.cs @@ -54,7 +54,7 @@ public interface ILearnedMove : IDeepCloneable /// The maximal power points for this move. /// byte MaxPp { get; } - + /// /// The current power points for this move. /// @@ -86,7 +86,7 @@ public interface ILearnedMove : IDeepCloneable public class LearnedMoveImpl : ILearnedMove { private byte _maxPpModification = 0; - + /// public LearnedMoveImpl(IMoveData moveData, MoveLearnMethod learnMethod) { @@ -95,8 +95,7 @@ public class LearnedMoveImpl : ILearnedMove CurrentPp = MaxPp; } - public LearnedMoveImpl(IMoveData moveData, MoveLearnMethod learnMethod, byte pp) - : this(moveData, learnMethod) + public LearnedMoveImpl(IMoveData moveData, MoveLearnMethod learnMethod, byte pp) : this(moveData, learnMethod) { CurrentPp = pp; } @@ -109,12 +108,12 @@ public class LearnedMoveImpl : ILearnedMove /// public MoveLearnMethod LearnMethod { get; } - + /// /// The available power points for this move. /// public byte CurrentPp { get; private set; } - + /// /// Try to use the move. This subtracts the amount of PP from the current PP. If the amount requested is /// higher than the current PP, this will return false, and the PP will not be reduced. @@ -123,7 +122,7 @@ public class LearnedMoveImpl : ILearnedMove { if (CurrentPp < amount) return false; - + CurrentPp -= amount; return true; } diff --git a/PkmnLib.Dynamic/Models/Pokemon.cs b/PkmnLib.Dynamic/Models/Pokemon.cs index b07404e..fa42388 100644 --- a/PkmnLib.Dynamic/Models/Pokemon.cs +++ b/PkmnLib.Dynamic/Models/Pokemon.cs @@ -50,7 +50,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// The amount of experience of the Pokemon. /// uint Experience { get; } - + /// /// Increases the experience of the Pokemon. Returns whether any experience was gained. /// @@ -71,7 +71,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// currently not used, and can be used for other implementations. /// byte Coloring { get; } - + /// /// Whether the Pokemon is shiny. /// @@ -98,7 +98,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// The new weight in kilograms /// public bool ChangeWeightInKgBy(float weightInKg); - + /// /// The height of the Pokémon in meters. /// @@ -124,7 +124,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// The stats of the Pokemon including the stat boosts /// StatisticSet BoostedStats { get; } - + /// /// The maximum health of the Pokemon. /// @@ -171,12 +171,12 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// are null. /// IReadOnlyList Moves { get; } - + /// /// Checks whether the Pokemon has a specific move in its current moveset. /// bool HasMove(StringKey moveName); - + /// /// Swaps two moves of the Pokemon. /// @@ -201,7 +201,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// Whether or not this Pokemon was caught this battle. /// bool IsCaught { get; } - + public void MarkAsCaught(); /// @@ -240,7 +240,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// [MustUseReturnValue] IItem? RemoveHeldItem(); - + /// /// Removes the held item from the Pokemon for the duration of the battle. Returns the previously held item. /// @@ -249,7 +249,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// restored after the battle. /// IItem? RemoveHeldItemForBattle(); - + /// /// Restores the held item of a Pokémon if it was temporarily removed. /// @@ -273,7 +273,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// Suppresses the ability of the Pokémon. /// public void SuppressAbility(); - + /// /// Returns the currently active ability. /// @@ -322,7 +322,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// heal if the Pokemon has 0 health. If the amount healed is 0, this will return false. /// bool Heal(uint heal, bool allowRevive = false); - + /// /// Restores all PP of the Pokemon. /// @@ -337,10 +337,12 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// Checks whether the Pokémon has a specific non-volatile status. /// bool HasStatus(StringKey status); + /// /// Adds a non-volatile status to the Pokemon. /// void SetStatus(StringKey status); + /// /// Removes the current non-volatile status from the Pokemon. /// @@ -371,23 +373,23 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// Marks a Pokemon as seen in the battle. /// void MarkOpponentAsSeen(IPokemon pokemon); - + /// /// Removes a type from the Pokémon. Returns whether the type was removed. /// bool RemoveType(TypeIdentifier type); - + /// /// Adds a type to the Pokémon. Returns whether the type was added. It will not add the type if /// the Pokémon already has it. /// bool AddType(TypeIdentifier type); - + /// /// Replace the types of the Pokémon with the provided types. /// void SetTypes(IReadOnlyList types); - + void ChangeAbility(IAbility ability); /// @@ -431,17 +433,17 @@ public interface IPokemonBattleData : IDeepCloneable /// Adds an opponent to the list of seen opponents. /// void MarkOpponentAsSeen(IPokemon opponent); - + /// /// A list of items the Pokémon has consumed this battle. /// IReadOnlyList ConsumedItems { get; } - + /// /// Marks an item as consumed. /// void MarkItemAsConsumed(IItem itemName); - + uint SwitchInTurn { get; internal set; } } @@ -569,7 +571,7 @@ public class PokemonImpl : ScriptSource, IPokemon { BatchId = batchId, }); - + var newLevel = Library.StaticLibrary.GrowthRates.CalculateLevel(Species.GrowthRate, Experience); if (newLevel > Level) { @@ -579,7 +581,7 @@ public class PokemonImpl : ScriptSource, IPokemon { BatchId = batchId, }); - + if (newLevel >= maxLevel) { Experience = Library.StaticLibrary.GrowthRates.CalculateExperience(Species.GrowthRate, maxLevel); @@ -597,7 +599,7 @@ public class PokemonImpl : ScriptSource, IPokemon /// public byte Coloring { get; } - + /// public bool IsShiny => Coloring == 1; @@ -686,7 +688,11 @@ public class PokemonImpl : ScriptSource, IPokemon private List _types = new(); /// - public IReadOnlyList Types { get => _types; private set => _types = value.ToList(); } + public IReadOnlyList Types + { + get => _types; + private set => _types = value.ToList(); + } /// public bool IsEgg { get; private set; } @@ -730,7 +736,7 @@ public class PokemonImpl : ScriptSource, IPokemon HeldItem = null; return previous; } - + private IItem? _stolenHeldItem; /// @@ -753,7 +759,7 @@ public class PokemonImpl : ScriptSource, IPokemon return false; if (!Library.ScriptResolver.TryResolveBattleItemScript(HeldItem, out _)) return false; - + if (BattleData != null) { var prevented = false; @@ -761,7 +767,7 @@ public class PokemonImpl : ScriptSource, IPokemon if (prevented) return false; } - + // TODO: actually consume the item throw new NotImplementedException(); } @@ -798,12 +804,12 @@ public class PokemonImpl : ScriptSource, IPokemon RecalculateBoostedStats(); return true; } - + /// /// Whether the ability of the Pokémon is suppressed. /// public bool AbilitySuppressed { get; private set; } - + /// public void SuppressAbility() { @@ -933,7 +939,7 @@ public class PokemonImpl : ScriptSource, IPokemon this.RunScriptHook(script => script.ChangeIncomingDamage(this, source, ref dmg)); damage = dmg; } - + // If the damage is more than the current health, we cap it at the current health, to prevent // underflow. if (damage >= CurrentHealth) @@ -989,7 +995,7 @@ public class PokemonImpl : ScriptSource, IPokemon { if (IsFainted && !allowRevive) return false; - var maxAmount = this.BoostedStats.Hp - CurrentHealth; + var maxAmount = BoostedStats.Hp - CurrentHealth; if (heal > maxAmount) heal = maxAmount; if (heal == 0) @@ -1019,7 +1025,8 @@ public class PokemonImpl : ScriptSource, IPokemon { for (byte i = 0; i < Moves.Count; i++) { - if (Moves[i] is not null) continue; + if (Moves[i] is not null) + continue; index = i; break; } diff --git a/PkmnLib.Dynamic/Models/PokemonParty.cs b/PkmnLib.Dynamic/Models/PokemonParty.cs index 23e3871..def8511 100644 --- a/PkmnLib.Dynamic/Models/PokemonParty.cs +++ b/PkmnLib.Dynamic/Models/PokemonParty.cs @@ -10,7 +10,7 @@ public interface IPokemonParty : IReadOnlyList, IDeepCloneable { event EventHandler<(IPokemon?, int index)>? OnSwapInto; event EventHandler<(int index1, int index2)>? OnSwap; - + /// /// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon. /// @@ -28,7 +28,7 @@ public interface IPokemonParty : IReadOnlyList, IDeepCloneable /// This will return false if all Pokemon are fainted, or eggs, etc. /// bool HasUsablePokemon(); - + /// /// Packs the party so that all Pokémon are at the front, and the empty slots are at the back. /// @@ -46,7 +46,6 @@ public class PokemonParty : IPokemonParty _pokemon = new IPokemon[size]; } - /// public event EventHandler<(IPokemon?, int index)>? OnSwapInto; @@ -73,10 +72,9 @@ public class PokemonParty : IPokemonParty OnSwap?.Invoke(this, (index1, index2)); } - /// public bool HasUsablePokemon() => _pokemon.Any(p => p is { IsUsable: true }); - + /// public IEnumerator GetEnumerator() => ((IEnumerable)_pokemon).GetEnumerator(); @@ -95,11 +93,11 @@ public class PokemonParty : IPokemonParty // Pack the party so that all Pokémon are at the front. for (var i = 0; i < _pokemon.Length; i++) { - if (_pokemon[i] != null) + if (_pokemon[i] != null) continue; for (var j = i + 1; j < _pokemon.Length; j++) { - if (_pokemon[j] == null) + if (_pokemon[j] == null) continue; Swap(i, j); break; diff --git a/PkmnLib.Dynamic/Models/Serialized/SerializedPokemon.cs b/PkmnLib.Dynamic/Models/Serialized/SerializedPokemon.cs index c9f4e79..c814ee2 100644 --- a/PkmnLib.Dynamic/Models/Serialized/SerializedPokemon.cs +++ b/PkmnLib.Dynamic/Models/Serialized/SerializedPokemon.cs @@ -134,7 +134,7 @@ public record SerializedStats public SerializedStats() { } - + public SerializedStats(ImmutableStatisticSet stats) { Hp = stats.Hp; @@ -144,7 +144,7 @@ public record SerializedStats SpecialDefense = stats.SpecialDefense; Speed = stats.Speed; } - + public SerializedStats(long hp, long attack, long defense, long specialAttack, long specialDefense, long speed) { Hp = hp; diff --git a/PkmnLib.Dynamic/ScriptHandling/ItemScript.cs b/PkmnLib.Dynamic/ScriptHandling/ItemScript.cs index 996cdc3..1ab921c 100644 --- a/PkmnLib.Dynamic/ScriptHandling/ItemScript.cs +++ b/PkmnLib.Dynamic/ScriptHandling/ItemScript.cs @@ -12,8 +12,7 @@ public abstract class ItemScript : IDeepCloneable } protected IItem Item { get; private set; } - - + /// /// Initializes the script with the given parameters for a specific item /// diff --git a/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs b/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs index 5af4a0f..e697434 100644 --- a/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs +++ b/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs @@ -11,14 +11,14 @@ public abstract class PokeballScript : ItemScript } public abstract byte GetCatchRate(IPokemon target); - + /// public override void OnUseWithTarget(IPokemon target) { var battleData = target.BattleData; if (battleData == null) return; - + battleData.Battle.AttempCapture(battleData.SideIndex, battleData.Position, Item); } } \ No newline at end of file diff --git a/PkmnLib.Dynamic/ScriptHandling/Registry/ItemScriptAttribute.cs b/PkmnLib.Dynamic/ScriptHandling/Registry/ItemScriptAttribute.cs index e4e4d76..118c18b 100644 --- a/PkmnLib.Dynamic/ScriptHandling/Registry/ItemScriptAttribute.cs +++ b/PkmnLib.Dynamic/ScriptHandling/Registry/ItemScriptAttribute.cs @@ -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 { /// diff --git a/PkmnLib.Dynamic/ScriptHandling/Registry/Plugin.cs b/PkmnLib.Dynamic/ScriptHandling/Registry/Plugin.cs index c510498..f1b60d5 100644 --- a/PkmnLib.Dynamic/ScriptHandling/Registry/Plugin.cs +++ b/PkmnLib.Dynamic/ScriptHandling/Registry/Plugin.cs @@ -11,11 +11,11 @@ public abstract class Plugin protected Plugin() { } - + protected Plugin(PluginConfiguration configuration) { } - + /// /// The name of the plugin. Mostly used for debugging purposes. /// diff --git a/PkmnLib.Dynamic/ScriptHandling/Registry/ScriptAttribute.cs b/PkmnLib.Dynamic/ScriptHandling/Registry/ScriptAttribute.cs index adb8deb..b2cc6a8 100644 --- a/PkmnLib.Dynamic/ScriptHandling/Registry/ScriptAttribute.cs +++ b/PkmnLib.Dynamic/ScriptHandling/Registry/ScriptAttribute.cs @@ -6,8 +6,7 @@ namespace PkmnLib.Dynamic.ScriptHandling.Registry; /// /// Helper attribute to register scripts through reflection. /// -[AttributeUsage(AttributeTargets.Class, Inherited = false)] -[MeansImplicitUse] +[AttributeUsage(AttributeTargets.Class, Inherited = false), MeansImplicitUse] public class ScriptAttribute : Attribute { /// diff --git a/PkmnLib.Dynamic/ScriptHandling/Registry/ScriptRegistry.cs b/PkmnLib.Dynamic/ScriptHandling/Registry/ScriptRegistry.cs index fb4737f..c1d17a3 100644 --- a/PkmnLib.Dynamic/ScriptHandling/Registry/ScriptRegistry.cs +++ b/PkmnLib.Dynamic/ScriptHandling/Registry/ScriptRegistry.cs @@ -64,7 +64,7 @@ public class ScriptRegistry // This is more performant than using Activator.CreateInstance. _scriptTypes[(category, name)] = Expression.Lambda>(Expression.New(constructor)).Compile(); } - + /// /// Register an item script type with the given name. /// @@ -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>(newExpression, parameterExpression).Compile(); + _itemScriptTypes[name] = + Expression.Lambda>(newExpression, parameterExpression).Compile(); } /// /// Register a battle stat calculator. /// - public void RegisterBattleStatCalculator(T battleStatCalculator) - where T : IBattleStatCalculator => _battleStatCalculator = battleStatCalculator; + public void RegisterBattleStatCalculator(T battleStatCalculator) where T : IBattleStatCalculator => + _battleStatCalculator = battleStatCalculator; /// /// Register a damage calculator. /// - public void RegisterDamageCalculator(T damageCalculator) - where T : IDamageCalculator => _damageCalculator = damageCalculator; + public void RegisterDamageCalculator(T damageCalculator) where T : IDamageCalculator => + _damageCalculator = damageCalculator; /// /// Register a misc library. /// - public void RegisterMiscLibrary(T miscLibrary) where T : IMiscLibrary - => _miscLibrary = miscLibrary; - + public void RegisterMiscLibrary(T miscLibrary) where T : IMiscLibrary => _miscLibrary = miscLibrary; + /// /// Register a capture library. /// - public void RegisterCaptureLibrary(T captureLibrary) where T : ICaptureLibrary - => _captureLibrary = captureLibrary; + public void RegisterCaptureLibrary(T captureLibrary) where T : ICaptureLibrary => + _captureLibrary = captureLibrary; internal IReadOnlyDictionary<(ScriptCategory category, StringKey name), Func