From 942be8eaeba615be1d6c3e271068b0b0692b6dcb Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 27 Aug 2026 18:30:57 +0200 Subject: [PATCH] Replace all raw string comparisons with StringKey, source generator that creates cache keys for all names for Gen7 plugin --- AI/AIRunner/Program.cs | 4 +- Directory.Packages.props | 9 + .../AI/Explicit/ExplicitAI.Utilities.cs | 7 +- PkmnLib.Dynamic/AI/Explicit/ExplicitAI.cs | 9 +- PkmnLib.Dynamic/Models/Battle.cs | 2 +- PkmnLib.Dynamic/Models/Pokemon.cs | 4 +- PkmnLib.NET.slnx | 1 + PkmnLib.Static/Utils/StringKey.cs | 8 +- .../Models/IntegrationTestAction.cs | 4 +- .../AnalyzerReleases.Shipped.md | 3 + .../AnalyzerReleases.Unshipped.md | 10 + .../DataConstantsGenerator.cs | 59 ++++++ .../Emit/ConstantClassEmitter.cs | 73 +++++++ .../EquatableArray.cs | 52 +++++ .../Parsing/DataExtractor.cs | 196 ++++++++++++++++++ .../PkmnLib.Plugin.Gen7.SourceGen.csproj | 42 ++++ .../DataTests/GeneratedConstantsTests.cs | 105 ++++++++++ .../DataTests/MoveDataTests.cs | 2 +- .../Scripts/Moves/DreamEaterTests.cs | 6 +- .../AI/AIDamageFunctions.cs | 2 +- .../AI/AIHelperFunctions.cs | 84 ++++---- .../AI/AISwitchFunctions.cs | 34 +-- .../PkmnLib.Plugin.Gen7/Common/MoveFlags.cs | 39 ---- .../PkmnLib.Plugin.Gen7.csproj | 3 + .../Scripts/Abilities/Aftermath.cs | 4 +- .../Scripts/Abilities/Anticipation.cs | 6 +- .../Scripts/Abilities/AuraBreak.cs | 2 +- .../Scripts/Abilities/BattleBond.cs | 8 +- .../Scripts/Abilities/Damp.cs | 2 +- .../Scripts/Abilities/DarkAura.cs | 2 +- .../Scripts/Abilities/Disguise.cs | 10 +- .../Scripts/Abilities/DrySkin.cs | 4 +- .../Scripts/Abilities/EffectSpore.cs | 6 +- .../Scripts/Abilities/FairyAura.cs | 2 +- .../Scripts/Abilities/FlashFire.cs | 2 +- .../Scripts/Abilities/FlowerGift.cs | 6 +- .../Scripts/Abilities/Fluffy.cs | 2 +- .../Scripts/Abilities/Forecast.cs | 8 +- .../Scripts/Abilities/Forewarn.cs | 72 +++++-- .../Scripts/Abilities/Galvanize.cs | 6 +- .../Scripts/Abilities/Heatproof.cs | 2 +- .../Scripts/Abilities/Justified.cs | 2 +- .../Scripts/Abilities/LightningRod.cs | 4 +- .../Scripts/Abilities/LiquidVoice.cs | 2 +- .../Scripts/Abilities/MagnetPull.cs | 4 +- .../Scripts/Abilities/Minus.cs | 3 +- .../Scripts/Abilities/MotorDrive.cs | 2 +- .../Scripts/Abilities/Multitype.cs | 84 +++----- .../Scripts/Abilities/Mummy.cs | 4 +- .../Scripts/Abilities/Normalize.cs | 4 +- .../Scripts/Abilities/Pixilate.cs | 6 +- .../Scripts/Abilities/Plus.cs | 3 +- .../Scripts/Abilities/PowerConstruct.cs | 6 +- .../Scripts/Abilities/QuickFeet.cs | 2 +- .../Scripts/Abilities/RKSSystem.cs | 4 +- .../Scripts/Abilities/Rattled.cs | 2 +- .../Scripts/Abilities/Refrigerate.cs | 6 +- .../Scripts/Abilities/SandForce.cs | 4 +- .../Scripts/Abilities/SapSipper.cs | 2 +- .../Scripts/Abilities/Schooling.cs | 8 +- .../Scripts/Abilities/Scrappy.cs | 6 +- .../Scripts/Abilities/ShieldsDown.cs | 4 +- .../Scripts/Abilities/StanceChange.cs | 4 +- .../Scripts/Abilities/Steelworker.cs | 2 +- .../Scripts/Abilities/StormDrain.cs | 4 +- .../Scripts/Abilities/ThickFat.cs | 2 +- .../Scripts/Abilities/VoltAbsorb.cs | 2 +- .../Scripts/Abilities/WaterAbsorb.cs | 2 +- .../Scripts/Abilities/WaterBubble.cs | 4 +- .../Scripts/Abilities/WaterCompaction.cs | 2 +- .../Scripts/Abilities/ZenMode.cs | 8 +- .../Scripts/Battle/FairyLockEffect.cs | 4 +- .../Scripts/Battle/Gravity.cs | 2 +- .../Scripts/Battle/IonDelugeEffect.cs | 4 +- .../Scripts/Battle/MudSportEffect.cs | 2 +- .../Scripts/Battle/UproarEffect.cs | 2 +- .../Scripts/Battle/WaterSportEffect.cs | 2 +- .../Scripts/Items/Pokeballs/MoonBall.cs | 4 +- .../Scripts/Items/Pokeballs/NetBall.cs | 5 +- .../Scripts/Moves/Block.cs | 4 +- .../Scripts/Moves/Bounce.cs | 2 +- .../Scripts/Moves/BurnUp.cs | 4 +- .../Scripts/Moves/Camouflage.cs | 22 +- .../Scripts/Moves/Captivate.cs | 2 +- .../Scripts/Moves/Conversion2.cs | 5 +- .../Scripts/Moves/Curse.cs | 2 +- .../Scripts/Moves/Drain.cs | 2 +- .../Scripts/Moves/DreamEater.cs | 8 +- .../Scripts/Moves/FireFang.cs | 2 +- .../Scripts/Moves/FirePledge.cs | 7 +- .../Scripts/Moves/FlameWheel.cs | 4 +- .../Scripts/Moves/FlareBlitz.cs | 2 +- .../Scripts/Moves/FlowerShield.cs | 2 +- .../Scripts/Moves/FlyingPress.cs | 2 +- .../Scripts/Moves/ForestsCurse.cs | 2 +- .../Scripts/Moves/FreezeDry.cs | 4 +- .../Scripts/Moves/FreezeShock.cs | 2 +- .../Scripts/Moves/FusionBolt.cs | 2 +- .../Scripts/Moves/FusionFlare.cs | 2 +- .../Scripts/Moves/GearUp.cs | 2 +- .../Scripts/Moves/GrassPledge.cs | 7 +- .../Scripts/Moves/HealBell.cs | 2 +- .../PkmnLib.Plugin.Gen7/Scripts/Moves/Hex.cs | 2 +- .../Scripts/Moves/HyperspaceFury.cs | 5 +- .../Scripts/Moves/IceBurn.cs | 2 +- .../Scripts/Moves/IceFang.cs | 2 +- .../Scripts/Moves/Judgement.cs | 45 ++-- .../Scripts/Moves/KingsShield.cs | 2 +- .../Scripts/Moves/LastResort.cs | 2 +- .../Scripts/Moves/LeechSeed.cs | 2 +- .../Scripts/Moves/MagnetRise.cs | 2 +- .../Scripts/Moves/MagneticFlux.cs | 2 +- .../Scripts/Moves/MeFirst.cs | 3 +- .../Scripts/Moves/MeanLook.cs | 4 +- .../Scripts/Moves/MultiAttack.cs | 2 +- .../Scripts/Moves/NaturePower.cs | 32 +-- .../Scripts/Moves/Refresh.cs | 24 ++- .../Scripts/Moves/Rototiller.cs | 2 +- .../Scripts/Moves/Round.cs | 5 +- .../Scripts/Moves/SimpleBeam.cs | 2 +- .../PkmnLib.Plugin.Gen7/Scripts/Moves/Soak.cs | 4 +- .../Scripts/Moves/TechnoBlast.cs | 19 +- .../Scripts/Moves/TrickOrTreat.cs | 2 +- .../Scripts/Moves/WaterPledge.cs | 7 +- .../Scripts/Moves/WeatherBall.cs | 8 +- .../Scripts/Moves/WorrySeed.cs | 2 +- .../Scripts/Pokemon/ChargeEffect.cs | 2 +- .../Scripts/Pokemon/DefenseCurlEffect.cs | 5 +- .../Scripts/Pokemon/FireSpinEffect.cs | 6 +- .../Scripts/Pokemon/FlashFireEffect.cs | 2 +- .../Scripts/Pokemon/FocusPunchEffect.cs | 2 +- .../Scripts/Pokemon/ForesightEffect.cs | 6 +- .../Scripts/Pokemon/FuryCutterEffect.cs | 2 +- .../Pokemon/HealEachEndOfTurnEffect.cs | 2 +- .../Scripts/Pokemon/IngrainEffect.cs | 8 +- .../Scripts/Pokemon/LeechSeedEffect.cs | 2 +- .../Scripts/Pokemon/MagmaStormEffect.cs | 4 +- .../Scripts/Pokemon/MagnetRiseEffect.cs | 5 +- .../Scripts/Pokemon/MiracleEyeEffect.cs | 4 +- .../Scripts/Pokemon/PowderEffect.cs | 2 +- .../Scripts/Pokemon/RoostEffect.cs | 2 +- .../Scripts/Pokemon/SmackDownEffect.cs | 2 +- .../Scripts/Pokemon/TelekinesisEffect.cs | 2 +- .../Scripts/Pokemon/ThousandArrowsEffect.cs | 4 +- .../Scripts/Side/EchoedVoiceData.cs | 2 +- .../Scripts/Side/FlowerVeilEffect.cs | 4 +- .../Scripts/Side/SeaOfFireEffect.cs | 2 +- .../Scripts/Side/StealthRockEffect.cs | 2 +- .../Scripts/Status/Frozen.cs | 2 +- .../Scripts/Terrain/ElectricTerrain.cs | 2 +- .../Scripts/Terrain/GrassyTerrain.cs | 4 +- .../Scripts/Terrain/MistyTerrain.cs | 2 +- .../Scripts/Terrain/PsychicTerrain.cs | 2 +- .../Scripts/Weather/DesolateLands.cs | 2 +- .../Scripts/Weather/Hail.cs | 4 +- .../Scripts/Weather/HarshSunlight.cs | 11 +- .../Scripts/Weather/PrimordialSea.cs | 2 +- .../Scripts/Weather/Rain.cs | 18 +- .../Scripts/Weather/Sandstorm.cs | 9 +- .../Scripts/Weather/StrongWinds.cs | 2 +- 160 files changed, 1035 insertions(+), 491 deletions(-) create mode 100644 Plugins/PkmnLib.Plugin.Gen7.SourceGen/AnalyzerReleases.Shipped.md create mode 100644 Plugins/PkmnLib.Plugin.Gen7.SourceGen/AnalyzerReleases.Unshipped.md create mode 100644 Plugins/PkmnLib.Plugin.Gen7.SourceGen/DataConstantsGenerator.cs create mode 100644 Plugins/PkmnLib.Plugin.Gen7.SourceGen/Emit/ConstantClassEmitter.cs create mode 100644 Plugins/PkmnLib.Plugin.Gen7.SourceGen/EquatableArray.cs create mode 100644 Plugins/PkmnLib.Plugin.Gen7.SourceGen/Parsing/DataExtractor.cs create mode 100644 Plugins/PkmnLib.Plugin.Gen7.SourceGen/PkmnLib.Plugin.Gen7.SourceGen.csproj create mode 100644 Plugins/PkmnLib.Plugin.Gen7.Tests/DataTests/GeneratedConstantsTests.cs delete mode 100644 Plugins/PkmnLib.Plugin.Gen7/Common/MoveFlags.cs diff --git a/AI/AIRunner/Program.cs b/AI/AIRunner/Program.cs index b3b4d10..9fe10ee 100644 --- a/AI/AIRunner/Program.cs +++ b/AI/AIRunner/Program.cs @@ -3,6 +3,7 @@ using System.CommandLine.Parsing; using PkmnLib.Dynamic.AI; using PkmnLib.Dynamic.Libraries; using PkmnLib.Plugin.Gen7; +using PkmnLib.Static.Utils; using Serilog; using Serilog.Core; using Serilog.Events; @@ -93,7 +94,8 @@ internal static class Program return; } - var ai = _availableAIs!.FirstOrDefault(a => a.Name == aiName); + StringKey aiKey = aiName; + var ai = _availableAIs!.FirstOrDefault(a => a.Name == aiKey); if (ai == null) { result.AddError( diff --git a/Directory.Packages.props b/Directory.Packages.props index b322d93..552d85b 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -20,5 +20,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/PkmnLib.Dynamic/AI/Explicit/ExplicitAI.Utilities.cs b/PkmnLib.Dynamic/AI/Explicit/ExplicitAI.Utilities.cs index c91db12..4414f37 100644 --- a/PkmnLib.Dynamic/AI/Explicit/ExplicitAI.Utilities.cs +++ b/PkmnLib.Dynamic/AI/Explicit/ExplicitAI.Utilities.cs @@ -18,6 +18,7 @@ public partial class ExplicitAI private static readonly StringKey ShieldsDownName = "shields_down"; private static readonly StringKey HarshSunlightName = "harsh_sunlight"; private static readonly StringKey DesolateLandsName = "desolate_lands"; + private static readonly StringKey PrimordialSeaName = "primordial_sea"; private static readonly StringKey BulletproofName = "bulletproof"; private static readonly StringKey FlashFireName = "flash_fire"; private static readonly StringKey LightningRodName = "lightning_rod"; @@ -33,6 +34,8 @@ public partial class ExplicitAI private static readonly StringKey FireName = "fire"; private static readonly StringKey ElectricName = "electric"; private static readonly StringKey WaterName = "water"; + private static readonly StringKey KomalaName = "komala"; + private static readonly StringKey MiniorName = "minior"; private static bool CanBePoisoned(IPokemon pokemon, IBattle battle) { @@ -49,9 +52,9 @@ public partial class ExplicitAI if ((pokemon.ActiveAbility?.Name == LeafGuardName && battle.WeatherName == HarshSunlightName) || battle.WeatherName == DesolateLandsName) return false; - if (pokemon.ActiveAbility?.Name == ComatoseName && pokemon.Species.Name == "komala") + if (pokemon.ActiveAbility?.Name == ComatoseName && pokemon.Species.Name == KomalaName) return false; - if (pokemon.ActiveAbility?.Name == ShieldsDownName && pokemon.Species.Name == "minior" && + if (pokemon.ActiveAbility?.Name == ShieldsDownName && pokemon.Species.Name == MiniorName && pokemon.Form.Name.Contains("-meteor")) return false; return true; diff --git a/PkmnLib.Dynamic/AI/Explicit/ExplicitAI.cs b/PkmnLib.Dynamic/AI/Explicit/ExplicitAI.cs index 8378117..928186b 100644 --- a/PkmnLib.Dynamic/AI/Explicit/ExplicitAI.cs +++ b/PkmnLib.Dynamic/AI/Explicit/ExplicitAI.cs @@ -313,9 +313,9 @@ public partial class ExplicitAI : PokemonAI, IExplicitAI } // Primal weather - if (battle.WeatherName == "primordial_sea" && aiMove.Move.MoveType.Name == "fire") + if (battle.WeatherName == PrimordialSeaName && aiMove.Move.MoveType.Name == FireName) return true; - if (battle.WeatherName == "desolate_lands" && aiMove.Move.MoveType.Name == "water") + if (battle.WeatherName == DesolateLandsName && aiMove.Move.MoveType.Name == WaterName) return true; // Check if the move will fail based on the handlers @@ -453,13 +453,16 @@ public partial class ExplicitAI : PokemonAI, IExplicitAI return true; } + private static readonly StringKey TruantName = "truant"; + private static readonly StringKey TruantEffectName = "truant_effect"; + private static bool CanAttack(IPokemon pokemon) { if (pokemon.Volatile.Contains("requires_recharge")) return false; if (pokemon.HasStatus("frozen") || pokemon.HasStatus("sleep")) return false; - if (pokemon.ActiveAbility?.Name == "truant" && pokemon.Volatile.Contains("truant_effect")) + if (pokemon.ActiveAbility?.Name == TruantName && pokemon.Volatile.Contains(TruantEffectName)) return false; if (pokemon.Volatile.Contains("flinch_effect")) return false; diff --git a/PkmnLib.Dynamic/Models/Battle.cs b/PkmnLib.Dynamic/Models/Battle.cs index 1bedfb8..47ebe11 100644 --- a/PkmnLib.Dynamic/Models/Battle.cs +++ b/PkmnLib.Dynamic/Models/Battle.cs @@ -467,7 +467,7 @@ public class BattleImpl : ScriptSource, IBattle var oldWeatherName = WeatherScript.Script?.Name; if (weatherName.HasValue) { - if (weatherName == oldWeatherName) + if (oldWeatherName == weatherName.Value) { // Extend duration of existing weather if (_weatherScript.Script is ILimitedTurnsScript existingWeatherScript) diff --git a/PkmnLib.Dynamic/Models/Pokemon.cs b/PkmnLib.Dynamic/Models/Pokemon.cs index a24735b..4a2749e 100644 --- a/PkmnLib.Dynamic/Models/Pokemon.cs +++ b/PkmnLib.Dynamic/Models/Pokemon.cs @@ -1482,12 +1482,14 @@ public class PokemonImpl : ScriptSource, IPokemon return true; } + private static readonly StringKey FlyingTypeName = "flying"; + /// public bool IsFloating { get { - var isFloating = Types.Any(x => x.Name == "flying"); + var isFloating = Types.Any(x => x.Name == FlyingTypeName); this.RunScriptHook(x => x.IsFloating(this, ref isFloating)); return isFloating; } diff --git a/PkmnLib.NET.slnx b/PkmnLib.NET.slnx index 6c370fa..ed91553 100644 --- a/PkmnLib.NET.slnx +++ b/PkmnLib.NET.slnx @@ -15,6 +15,7 @@ + diff --git a/PkmnLib.Static/Utils/StringKey.cs b/PkmnLib.Static/Utils/StringKey.cs index eb67f11..346e311 100644 --- a/PkmnLib.Static/Utils/StringKey.cs +++ b/PkmnLib.Static/Utils/StringKey.cs @@ -58,7 +58,7 @@ public readonly struct StringKey : IEquatable, IEquatable return obj switch { StringKey other => Equals(other), - string str => Equals(str), + string str => string.Equals(_key, str, StringComparison.InvariantCultureIgnoreCase), _ => false, }; } @@ -67,16 +67,22 @@ public readonly struct StringKey : IEquatable, IEquatable public bool Equals(StringKey other) => _hashCode == other._hashCode; /// + [Obsolete("Comparing a StringKey to a string uses a slow culture-aware string comparison. " + + "Compare against a cached StringKey (e.g. a generated constant) instead.")] public bool Equals(string other) => string.Equals(_key, other, StringComparison.InvariantCultureIgnoreCase); /// public override int GetHashCode() => _hashCode; /// + [Obsolete("Comparing a StringKey to a string uses a slow culture-aware string comparison. " + + "Compare against a cached StringKey (e.g. a generated constant) instead.")] public static bool operator ==(StringKey? left, string? right) => (left is null && right is null) || (right != null && (left?.Equals(right) ?? false)); /// + [Obsolete("Comparing a StringKey to a string uses a slow culture-aware string comparison. " + + "Compare against a cached StringKey (e.g. a generated constant) instead.")] public static bool operator !=(StringKey? left, string? right) => !(left == right); /// diff --git a/PkmnLib.Tests/Integration/Models/IntegrationTestAction.cs b/PkmnLib.Tests/Integration/Models/IntegrationTestAction.cs index 3b9a801..9e97c20 100644 --- a/PkmnLib.Tests/Integration/Models/IntegrationTestAction.cs +++ b/PkmnLib.Tests/Integration/Models/IntegrationTestAction.cs @@ -3,6 +3,7 @@ using System.Text.Json.Serialization; using CSPath; using PkmnLib.Dynamic.Models; using PkmnLib.Dynamic.Models.Choices; +using PkmnLib.Static.Utils; using JsonSerializer = System.Text.Json.JsonSerializer; namespace PkmnLib.Tests.Integration.Models; @@ -39,7 +40,8 @@ public class SetMoveChoiceAction : IntegrationTestAction { var user = battle.Sides[Place[0]].Pokemon[Place[1]]; await Assert.That(user).IsNotNull(); - var move = user!.Moves.First(m => m?.MoveData.Name == Move); + StringKey moveName = Move; + var move = user!.Moves.First(m => m?.MoveData.Name == moveName); await Assert.That(move).IsNotNull(); var res = battle.TrySetChoice(new MoveChoice(user, move!, Target[0], Target[1])); await Assert.That(res).IsTrue(); diff --git a/Plugins/PkmnLib.Plugin.Gen7.SourceGen/AnalyzerReleases.Shipped.md b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/AnalyzerReleases.Shipped.md new file mode 100644 index 0000000..60b59dd --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/AnalyzerReleases.Shipped.md @@ -0,0 +1,3 @@ +; Shipped analyzer releases +; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md + diff --git a/Plugins/PkmnLib.Plugin.Gen7.SourceGen/AnalyzerReleases.Unshipped.md b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/AnalyzerReleases.Unshipped.md new file mode 100644 index 0000000..7281e5d --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/AnalyzerReleases.Unshipped.md @@ -0,0 +1,10 @@ +; Unshipped analyzer release +; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md + +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|------- +PKMN7G000 | PkmnLib.SourceGen | Error | DataConstantsGenerator +PKMN7G001 | PkmnLib.SourceGen | Error | DataConstantsGenerator +PKMN7G002 | PkmnLib.SourceGen | Error | DataConstantsGenerator \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7.SourceGen/DataConstantsGenerator.cs b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/DataConstantsGenerator.cs new file mode 100644 index 0000000..e27da53 --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/DataConstantsGenerator.cs @@ -0,0 +1,59 @@ +using Microsoft.CodeAnalysis; +using PkmnLib.Plugin.Gen7.SourceGen.Emit; +using PkmnLib.Plugin.Gen7.SourceGen.Parsing; + +namespace PkmnLib.Plugin.Gen7.SourceGen; + +/// +/// Generates public static readonly StringKey constant classes (move names, type names, +/// move flags, etc.) from the Gen 7 data files, which are exposed to the generator as +/// AdditionalFiles. +/// +[Generator] +public sealed class DataConstantsGenerator : IIncrementalGenerator +{ + private static readonly DiagnosticDescriptor ParseFailure = new("PKMN7G000", "Data file parse failure", "{0}", + "PkmnLib.SourceGen", DiagnosticSeverity.Error, true); + + private static readonly DiagnosticDescriptor DuplicateIdentifier = new("PKMN7G001", "Duplicate constant identifier", + "{0}", "PkmnLib.SourceGen", DiagnosticSeverity.Error, true); + + private static readonly DiagnosticDescriptor UnusableName = new("PKMN7G002", "Unusable constant name", "{0}", + "PkmnLib.SourceGen", DiagnosticSeverity.Error, true); + + public void Initialize(IncrementalGeneratorInitializationContext context) + { + var results = context.AdditionalTextsProvider + .Where(static text => DataExtractor.IsKnownFile(Path.GetFileName(text.Path))).Select(static (text, ct) => + DataExtractor.Extract(Path.GetFileName(text.Path), text.GetText(ct)?.ToString())); + + context.RegisterSourceOutput(results, static (context, result) => + { + foreach (var diagnostic in result.Diagnostics) + { + Report(context, diagnostic); + } + foreach (var spec in result.Classes) + { + var diagnostics = new List(); + var source = ConstantClassEmitter.Emit(spec, diagnostics); + foreach (var diagnostic in diagnostics) + { + Report(context, diagnostic); + } + context.AddSource($"{spec.ClassName}.g.cs", source); + } + }); + } + + private static void Report(SourceProductionContext context, ExtractionDiagnostic diagnostic) + { + var descriptor = diagnostic.Id switch + { + "PKMN7G001" => DuplicateIdentifier, + "PKMN7G002" => UnusableName, + _ => ParseFailure, + }; + context.ReportDiagnostic(Diagnostic.Create(descriptor, Location.None, diagnostic.Message)); + } +} \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7.SourceGen/Emit/ConstantClassEmitter.cs b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/Emit/ConstantClassEmitter.cs new file mode 100644 index 0000000..5ab8023 --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/Emit/ConstantClassEmitter.cs @@ -0,0 +1,73 @@ +using System.Text; +using PkmnLib.Plugin.Gen7.SourceGen.Parsing; + +namespace PkmnLib.Plugin.Gen7.SourceGen.Emit; + +/// +/// Emits a constants class of public static readonly StringKey fields for a +/// . +/// +public static class ConstantClassEmitter +{ + public static string Emit(ClassSpec spec, List diagnostics) + { + var sb = new StringBuilder(); + sb.AppendLine($"// "); + sb.AppendLine("#nullable enable"); + sb.AppendLine("using PkmnLib.Static.Utils;"); + sb.AppendLine(); + sb.AppendLine("namespace PkmnLib.Plugin.Gen7.Common;"); + sb.AppendLine(); + sb.AppendLine($"public static class {spec.ClassName}"); + sb.AppendLine("{"); + var seen = new Dictionary(StringComparer.Ordinal); + foreach (var name in spec.Names) + { + var identifier = Sanitize(name); + if (identifier.Length == 0) + { + diagnostics.Add(new ExtractionDiagnostic("PKMN7G002", + $"Name '{name}' in {spec.ClassName} does not produce a usable identifier and was skipped.")); + continue; + } + if (seen.TryGetValue(identifier, out var existing)) + { + diagnostics.Add(new ExtractionDiagnostic("PKMN7G001", + $"Names '{existing}' and '{name}' in {spec.ClassName} both map to identifier '{identifier}'; '{name}' was skipped.")); + continue; + } + seen.Add(identifier, name); + sb.AppendLine($" public static readonly StringKey {identifier} = \"{name}\";"); + } + sb.AppendLine("}"); + return sb.ToString(); + } + + /// + /// Converts a raw data name to a PascalCase identifier: segments split on _/- + /// runs, non-alphanumeric characters stripped, and a leading _ added when the result + /// would start with a digit. + /// + public static string Sanitize(string raw) + { + var sb = new StringBuilder(raw.Length); + var newSegment = true; + foreach (var c in raw) + { + if (c is '_' or '-') + { + newSegment = true; + continue; + } + if (!char.IsLetterOrDigit(c)) + continue; + sb.Append(newSegment ? char.ToUpperInvariant(c) : c); + newSegment = false; + } + if (sb.Length == 0) + return string.Empty; + if (char.IsDigit(sb[0])) + sb.Insert(0, '_'); + return sb.ToString(); + } +} \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7.SourceGen/EquatableArray.cs b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/EquatableArray.cs new file mode 100644 index 0000000..99757a1 --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/EquatableArray.cs @@ -0,0 +1,52 @@ +using System.Collections; + +namespace PkmnLib.Plugin.Gen7.SourceGen; + +/// +/// An immutable array wrapper with sequence-based equality, so that incremental generator pipeline +/// values containing collections cache correctly. +/// +public readonly struct EquatableArray : IEquatable>, IReadOnlyList where T : IEquatable +{ + private readonly T[]? _array; + + public EquatableArray(T[] array) + { + _array = array; + } + + public int Count => _array?.Length ?? 0; + + public T this[int index] => _array![index]; + + public bool Equals(EquatableArray other) + { + if (Count != other.Count) + return false; + for (var i = 0; i < Count; i++) + { + if (!this[i].Equals(other[i])) + return false; + } + return true; + } + + public override bool Equals(object? obj) => obj is EquatableArray other && Equals(other); + + public override int GetHashCode() + { + unchecked + { + var hash = 17; + for (var i = 0; i < Count; i++) + { + hash = hash * 31 + this[i].GetHashCode(); + } + return hash; + } + } + + public IEnumerator GetEnumerator() => ((IEnumerable)(_array ?? [])).GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); +} \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7.SourceGen/Parsing/DataExtractor.cs b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/Parsing/DataExtractor.cs new file mode 100644 index 0000000..62970da --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/Parsing/DataExtractor.cs @@ -0,0 +1,196 @@ +using System.Text.Json; + +namespace PkmnLib.Plugin.Gen7.SourceGen.Parsing; + +/// +/// A single generated constants class: its name and the raw data names it should contain. +/// +public sealed record ClassSpec(string ClassName, string SourceFile, EquatableArray Names); + +/// +/// A diagnostic produced during extraction, kept as plain data so pipeline values stay equatable. +/// +public sealed record ExtractionDiagnostic(string Id, string Message); + +/// +/// The result of extracting all constant classes from a single data file. +/// +public sealed record ExtractionResult( + EquatableArray Classes, + EquatableArray Diagnostics); + +/// +/// Extracts the names for the generated constant classes from the Gen 7 data files. +/// +public static class DataExtractor +{ + private static readonly HashSet KnownFiles = new(StringComparer.Ordinal) + { + "Moves.jsonc", "Abilities.jsonc", "Items.json", "Pokemon.json", "Types.csv", "Natures.csv", + }; + + /// + /// Matches the runtime's JsonOptions: the data files contain // comments + /// (including Items.json, despite its extension) and may contain trailing commas. + /// + private static readonly JsonDocumentOptions JsonOptions = new() + { + CommentHandling = JsonCommentHandling.Skip, + AllowTrailingCommas = true, + }; + + public static bool IsKnownFile(string fileName) => KnownFiles.Contains(fileName); + + /// + /// Extracts the constant classes for a data file. Never throws: a generator that throws is + /// silently disabled by IDE hosts, so failures are reported as diagnostics instead. + /// + public static ExtractionResult Extract(string fileName, string? text) + { + if (text is null) + { + return Error(fileName, "file content could not be read"); + } + try + { + return fileName switch + { + "Moves.jsonc" => ExtractMoves(fileName, text), + "Abilities.jsonc" => ExtractTopLevelKeys(fileName, text, "AbilityNames"), + "Items.json" => ExtractItems(fileName, text), + "Pokemon.json" => ExtractSpecies(fileName, text), + "Types.csv" => ExtractTypes(fileName, text), + "Natures.csv" => ExtractNatures(fileName, text), + _ => new ExtractionResult(new EquatableArray([]), + new EquatableArray([])), + }; + } + catch (Exception e) + { + return Error(fileName, e.Message); + } + } + + private static ExtractionResult Error(string fileName, string message) => + new(new EquatableArray([]), new EquatableArray([ + new ExtractionDiagnostic("PKMN7G000", $"Failed to parse data file '{fileName}': {message}"), + ])); + + private static ExtractionResult ExtractMoves(string fileName, string text) + { + var moveNames = new HashSet(StringComparer.Ordinal); + var flags = new HashSet(StringComparer.Ordinal); + var effectNames = new HashSet(StringComparer.Ordinal); + using var doc = JsonDocument.Parse(text, JsonOptions); + foreach (var move in doc.RootElement.GetProperty("data").EnumerateArray()) + { + Add(moveNames, move.GetProperty("name").GetString()); + if (move.TryGetProperty("flags", out var flagsElement)) + { + foreach (var flag in flagsElement.EnumerateArray()) + { + Add(flags, flag.GetString()); + } + } + if (move.TryGetProperty("effect", out var effect) && effect.TryGetProperty("name", out var effectName)) + { + Add(effectNames, effectName.GetString()); + } + } + return Result(Class("MoveNames", fileName, moveNames), Class("MoveFlags", fileName, flags), + Class("MoveEffectNames", fileName, effectNames)); + } + + private static ExtractionResult ExtractTopLevelKeys(string fileName, string text, string className) + { + var names = new HashSet(StringComparer.Ordinal); + using var doc = JsonDocument.Parse(text, JsonOptions); + foreach (var property in doc.RootElement.EnumerateObject()) + { + if (!property.Name.StartsWith("$", StringComparison.Ordinal)) + Add(names, property.Name); + } + return Result(Class(className, fileName, names)); + } + + private static ExtractionResult ExtractItems(string fileName, string text) + { + var names = new HashSet(StringComparer.Ordinal); + using var doc = JsonDocument.Parse(text, JsonOptions); + foreach (var item in doc.RootElement.EnumerateArray()) + { + Add(names, item.GetProperty("name").GetString()); + } + return Result(Class("ItemNames", fileName, names)); + } + + private static ExtractionResult ExtractSpecies(string fileName, string text) + { + var speciesNames = new HashSet(StringComparer.Ordinal); + var formNames = new HashSet(StringComparer.Ordinal); + using var doc = JsonDocument.Parse(text, JsonOptions); + foreach (var property in doc.RootElement.EnumerateObject()) + { + if (property.Name.StartsWith("$", StringComparison.Ordinal)) + continue; + Add(speciesNames, property.Name); + if (property.Value.TryGetProperty("formes", out var formes)) + { + foreach (var forme in formes.EnumerateObject()) + { + Add(formNames, forme.Name); + } + } + } + return Result(Class("SpeciesNames", fileName, speciesNames), Class("FormNames", fileName, formNames)); + } + + private static ExtractionResult ExtractTypes(string fileName, string text) + { + var names = new HashSet(StringComparer.Ordinal); + var header = FirstLine(text); + var cells = header.Split(header.Contains('|') ? '|' : ','); + for (var i = 1; i < cells.Length; i++) + { + Add(names, cells[i]); + } + return Result(Class("TypeNames", fileName, names)); + } + + private static ExtractionResult ExtractNatures(string fileName, string text) + { + var names = new HashSet(StringComparer.Ordinal); + var lines = text.Split('\n'); + for (var i = 1; i < lines.Length; i++) + { + var line = lines[i].Trim(); + if (line.Length == 0) + continue; + Add(names, line.Split(line.Contains('|') ? '|' : ',')[0]); + } + return Result(Class("NatureNames", fileName, names)); + } + + private static string FirstLine(string text) + { + var index = text.IndexOf('\n'); + return (index < 0 ? text : text.Substring(0, index)).Trim(); + } + + private static void Add(HashSet names, string? raw) + { + var name = raw?.Trim().ToLowerInvariant(); + if (!string.IsNullOrEmpty(name)) + names.Add(name!); + } + + private static ClassSpec Class(string className, string fileName, HashSet names) + { + var sorted = names.ToArray(); + Array.Sort(sorted, StringComparer.Ordinal); + return new ClassSpec(className, fileName, new EquatableArray(sorted)); + } + + private static ExtractionResult Result(params ClassSpec[] classes) => + new(new EquatableArray(classes), new EquatableArray([])); +} \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7.SourceGen/PkmnLib.Plugin.Gen7.SourceGen.csproj b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/PkmnLib.Plugin.Gen7.SourceGen.csproj new file mode 100644 index 0000000..5730843 --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7.SourceGen/PkmnLib.Plugin.Gen7.SourceGen.csproj @@ -0,0 +1,42 @@ + + + + netstandard2.0 + true + true + + $(GetTargetPathDependsOn);GetDependencyTargetPaths + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Plugins/PkmnLib.Plugin.Gen7.Tests/DataTests/GeneratedConstantsTests.cs b/Plugins/PkmnLib.Plugin.Gen7.Tests/DataTests/GeneratedConstantsTests.cs new file mode 100644 index 0000000..f7faf45 --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7.Tests/DataTests/GeneratedConstantsTests.cs @@ -0,0 +1,105 @@ +using PkmnLib.Dynamic.Libraries; +using PkmnLib.Plugin.Gen7.Common; +using PkmnLib.Static.Utils; + +namespace PkmnLib.Plugin.Gen7.Tests.DataTests; + +/// +/// Validates that the source-generated constant classes stay in sync with the data files: every +/// generated constant must resolve in the loaded library, and every library entry must have a +/// generated constant. +/// +public class GeneratedConstantsTests +{ + private static readonly IDynamicLibrary Library = LibraryHelpers.LoadLibrary(); + + private static HashSet ConstantsOf(Type type) => type.GetFields() + .Where(x => x is { IsStatic: true, IsPublic: true } && x.FieldType == typeof(StringKey)) + .Select(x => (StringKey)x.GetValue(null)!).ToHashSet(); + + [Test] + public async Task MoveNamesMatchMoveLibrary() + { + var constants = ConstantsOf(typeof(MoveNames)); + var libraryNames = Library.StaticLibrary.Moves.Select(x => x.Name).ToHashSet(); + await Assert.That(constants.Where(x => !libraryNames.Contains(x))).IsEmpty(); + await Assert.That(libraryNames.Where(x => !constants.Contains(x))).IsEmpty(); + } + + [Test] + public async Task AbilityNamesMatchAbilityLibrary() + { + var constants = ConstantsOf(typeof(AbilityNames)); + var libraryNames = Library.StaticLibrary.Abilities.Select(x => x.Name).ToHashSet(); + await Assert.That(constants.Where(x => !libraryNames.Contains(x))).IsEmpty(); + await Assert.That(libraryNames.Where(x => !constants.Contains(x))).IsEmpty(); + } + + [Test] + public async Task ItemNamesMatchItemLibrary() + { + var constants = ConstantsOf(typeof(ItemNames)); + var libraryNames = Library.StaticLibrary.Items.Select(x => x.Name).ToHashSet(); + await Assert.That(constants.Where(x => !libraryNames.Contains(x))).IsEmpty(); + await Assert.That(libraryNames.Where(x => !constants.Contains(x))).IsEmpty(); + } + + [Test] + public async Task SpeciesNamesMatchSpeciesLibrary() + { + var constants = ConstantsOf(typeof(SpeciesNames)); + var libraryNames = Library.StaticLibrary.Species.Select(x => x.Name).ToHashSet(); + await Assert.That(constants.Where(x => !libraryNames.Contains(x))).IsEmpty(); + await Assert.That(libraryNames.Where(x => !constants.Contains(x))).IsEmpty(); + } + + [Test] + public async Task FormNamesMatchSpeciesForms() + { + var constants = ConstantsOf(typeof(FormNames)); + var libraryNames = Library.StaticLibrary.Species.SelectMany(x => x.Forms.Keys).ToHashSet(); + await Assert.That(constants.Where(x => !libraryNames.Contains(x))).IsEmpty(); + await Assert.That(libraryNames.Where(x => !constants.Contains(x))).IsEmpty(); + } + + [Test] + public async Task NatureNamesMatchNatureLibrary() + { + var constants = ConstantsOf(typeof(NatureNames)); + var libraryNames = Library.StaticLibrary.Natures.Select(x => x.Name).ToHashSet(); + await Assert.That(constants.Where(x => !libraryNames.Contains(x))).IsEmpty(); + await Assert.That(libraryNames.Where(x => !constants.Contains(x))).IsEmpty(); + } + + [Test] + public async Task TypeNamesMatchTypeLibrary() + { + var constants = ConstantsOf(typeof(TypeNames)); + var libraryNames = new HashSet(); + for (byte index = 1; Library.StaticLibrary.Types.TryGetTypeIdentifierFromIndex(index, out var type); index++) + { + libraryNames.Add(type.Name); + } + await Assert.That(constants.Where(x => !libraryNames.Contains(x))).IsEmpty(); + await Assert.That(libraryNames.Where(x => !constants.Contains(x))).IsEmpty(); + } + + [Test] + public async Task MoveFlagsMatchMoveData() + { + var constants = ConstantsOf(typeof(MoveFlags)); + var libraryNames = Library.StaticLibrary.Moves.SelectMany(x => x.Flags).ToHashSet(); + await Assert.That(constants.Where(x => !libraryNames.Contains(x))).IsEmpty(); + await Assert.That(libraryNames.Where(x => !constants.Contains(x))).IsEmpty(); + } + + [Test] + public async Task MoveEffectNamesMatchMoveData() + { + var constants = ConstantsOf(typeof(MoveEffectNames)); + var libraryNames = Library.StaticLibrary.Moves.Where(x => x.SecondaryEffect != null) + .Select(x => x.SecondaryEffect!.Name).ToHashSet(); + await Assert.That(constants.Where(x => !libraryNames.Contains(x))).IsEmpty(); + await Assert.That(libraryNames.Where(x => !constants.Contains(x))).IsEmpty(); + } +} \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7.Tests/DataTests/MoveDataTests.cs b/Plugins/PkmnLib.Plugin.Gen7.Tests/DataTests/MoveDataTests.cs index 088c74f..2d952b5 100644 --- a/Plugins/PkmnLib.Plugin.Gen7.Tests/DataTests/MoveDataTests.cs +++ b/Plugins/PkmnLib.Plugin.Gen7.Tests/DataTests/MoveDataTests.cs @@ -72,7 +72,7 @@ public class MoveDataTests var moveLibrary = library.StaticLibrary.Moves; foreach (var move in moveLibrary) { - if (move.SecondaryEffect?.Name != "set_status") + if (move.SecondaryEffect?.Name != MoveEffectNames.SetStatus) continue; yield return () => new SetStatusTestCaseData(library, move); } diff --git a/Plugins/PkmnLib.Plugin.Gen7.Tests/Scripts/Moves/DreamEaterTests.cs b/Plugins/PkmnLib.Plugin.Gen7.Tests/Scripts/Moves/DreamEaterTests.cs index e28b8df..de2d3a2 100644 --- a/Plugins/PkmnLib.Plugin.Gen7.Tests/Scripts/Moves/DreamEaterTests.cs +++ b/Plugins/PkmnLib.Plugin.Gen7.Tests/Scripts/Moves/DreamEaterTests.cs @@ -59,7 +59,7 @@ public class DreamEaterTests { // Arrange var (script, move, target, _) = CreateTestSetup(100); - target.HasStatus(new StringKey("asleep")).Returns(false); + target.HasStatus(new StringKey("sleep")).Returns(false); var block = false; // Act @@ -77,7 +77,7 @@ public class DreamEaterTests { // Arrange var (script, move, target, _) = CreateTestSetup(100); - target.HasStatus(new StringKey("asleep")).Returns(true); + target.HasStatus(new StringKey("sleep")).Returns(true); var block = false; // Act @@ -96,7 +96,7 @@ public class DreamEaterTests { // Arrange var (script, move, target, _) = CreateTestSetup(100); - target.HasStatus(new StringKey("asleep")).Returns(false); + target.HasStatus(new StringKey("sleep")).Returns(false); var comatose = Substitute.For(); comatose.Name.Returns(new StringKey("comatose")); target.ActiveAbility.Returns(comatose); diff --git a/Plugins/PkmnLib.Plugin.Gen7/AI/AIDamageFunctions.cs b/Plugins/PkmnLib.Plugin.Gen7/AI/AIDamageFunctions.cs index 9bbc5bb..b23b83f 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/AI/AIDamageFunctions.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/AI/AIDamageFunctions.cs @@ -27,7 +27,7 @@ public static class AIDamageFunctions { score += 10; if ((option.Move.Move.HasFlag(MoveFlags.MultiHit) && target.CurrentHealth == target.MaxHealth && - target.ActiveAbility?.Name == "sturdy") || target.HasHeldItem("focus_sash")) + target.ActiveAbility?.Name == AbilityNames.Sturdy) || target.HasHeldItem(ItemNames.FocusSash)) { score += 8; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/AI/AIHelperFunctions.cs b/Plugins/PkmnLib.Plugin.Gen7/AI/AIHelperFunctions.cs index 949f32d..4256868 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/AI/AIHelperFunctions.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/AI/AIHelperFunctions.cs @@ -17,7 +17,7 @@ public static class AIHelperFunctions if (move.User.BattleData?.SideIndex != target.BattleData?.SideIndex) desireMult = -1; - if (!ignoreContrary && !fixedChange && target.ActiveAbility?.Name == "contrary") + if (!ignoreContrary && !fixedChange && target.ActiveAbility?.Name == AbilityNames.Contrary) { if (desireMult > 0 && wholeEffect) { @@ -39,10 +39,10 @@ public static class AIHelperFunctions if (expectedEndOfTurnDamage >= target.CurrentHealth) return wholeEffect ? ExplicitAI.MoveUselessScore : score; - if (!move.User.HasMoveWithEffect("power_trip")) + if (!move.User.HasMoveWithEffect(MoveEffectNames.PowerTrip)) { - var foeIsAware = target.BattleData?.BattleSide.Pokemon.Any(x => x?.ActiveAbility?.Name == "unaware") != - true; + var foeIsAware = + target.BattleData?.BattleSide.Pokemon.Any(x => x?.ActiveAbility?.Name == AbilityNames.Unaware) != true; if (!foeIsAware) { return wholeEffect ? ExplicitAI.MoveUselessScore : score; @@ -56,7 +56,7 @@ public static class AIHelperFunctions { continue; } - if (!fixedChange && target.ActiveAbility?.Name == "simple") + if (!fixedChange && target.ActiveAbility?.Name == AbilityNames.Simple) { increment *= 2; } @@ -88,7 +88,7 @@ public static class AIHelperFunctions var desireMult = -1; if (move.User.BattleData?.SideIndex == target.BattleData?.SideIndex) desireMult = 1; - if (!ignoreContrary && !fixedChange && target.ActiveAbility?.Name == "contrary") + if (!ignoreContrary && !fixedChange && target.ActiveAbility?.Name == AbilityNames.Contrary) { if (desireMult > 0 && wholeEffect) { @@ -109,7 +109,7 @@ public static class AIHelperFunctions return wholeEffect ? ExplicitAI.MoveUselessScore : score; var foeIsAware = false; - if (target.BattleData?.BattleSide.Pokemon.All(x => x?.ActiveAbility?.Name != "unaware") == true) + if (target.BattleData?.BattleSide.Pokemon.All(x => x?.ActiveAbility?.Name != AbilityNames.Unaware) == true) { foeIsAware = true; } @@ -125,7 +125,7 @@ public static class AIHelperFunctions { continue; } - if (!fixedChange && target.ActiveAbility?.Name == "simple") + if (!fixedChange && target.ActiveAbility?.Name == AbilityNames.Simple) { decrement *= 2; } @@ -152,7 +152,7 @@ public static class AIHelperFunctions { if (!fixedChange && pokemon.StatBoost.GetStatistic(stat) == StatBoostStatisticSet.MaxStatBoost) return false; - if (!pokemon.HasMoveWithEffect("power_trip", "baton_pass")) + if (!pokemon.HasMoveWithEffect(MoveEffectNames.PowerTrip, MoveEffectNames.BatonPass)) return true; switch (stat) @@ -160,7 +160,8 @@ public static class AIHelperFunctions case Statistic.Attack: { if (!pokemon.Moves.WhereNotNull().Any(x => x.MoveData.Category == MoveCategory.Physical && - x.MoveData.SecondaryEffect?.Name != "foul_play")) + x.MoveData.SecondaryEffect?.Name != + MoveEffectNames.FoulPlay)) { return false; } @@ -170,7 +171,8 @@ public static class AIHelperFunctions { var opponentSide = pokemon.BattleData!.Battle.Sides.First(x => x != pokemon.BattleData.BattleSide); return opponentSide.Pokemon.WhereNotNull().Any(x => x.Moves.WhereNotNull().Any(y => - y.MoveData.Category == MoveCategory.Physical || y.MoveData.SecondaryEffect?.Name == "psyshock")); + y.MoveData.Category == MoveCategory.Physical || + y.MoveData.SecondaryEffect?.Name == MoveEffectNames.Psyshock)); } case Statistic.SpecialAttack: { @@ -184,11 +186,12 @@ public static class AIHelperFunctions { var opponentSide = pokemon.BattleData!.Battle.Sides.First(x => x != pokemon.BattleData.BattleSide); return opponentSide.Pokemon.WhereNotNull().Any(x => x.Moves.WhereNotNull().Any(y => - y.MoveData.Category == MoveCategory.Special && y.MoveData.SecondaryEffect?.Name != "psyshock")); + y.MoveData.Category == MoveCategory.Special && + y.MoveData.SecondaryEffect?.Name != MoveEffectNames.Psyshock)); } case Statistic.Speed: { - if (!pokemon.HasMoveWithEffect("electro_ball", "power_trip")) + if (!pokemon.HasMoveWithEffect(MoveEffectNames.ElectroBall, MoveEffectNames.PowerTrip)) { var targetSpeed = pokemon.BoostedStats.Speed; var opponentSide = pokemon.BattleData!.Battle.Sides.First(x => x != pokemon.BattleData.BattleSide); @@ -228,13 +231,15 @@ public static class AIHelperFunctions case Statistic.Attack: { return pokemon.Moves.WhereNotNull().Any(x => x.MoveData.Category == MoveCategory.Physical && - x.MoveData.SecondaryEffect?.Name != FoulPlayAbilityName); + x.MoveData.SecondaryEffect?.Name != + MoveEffectNames.FoulPlay); } case Statistic.Defense: { var opponentSide = pokemon.BattleData!.Battle.Sides.First(x => x != pokemon.BattleData.BattleSide); return opponentSide.Pokemon.WhereNotNull().Any(x => x.Moves.WhereNotNull().Any(y => - y.MoveData.Category == MoveCategory.Physical || y.MoveData.SecondaryEffect?.Name == "psyshock")); + y.MoveData.Category == MoveCategory.Physical || + y.MoveData.SecondaryEffect?.Name == MoveEffectNames.Psyshock)); } case Statistic.SpecialAttack: { @@ -244,11 +249,12 @@ public static class AIHelperFunctions { var opponentSide = pokemon.BattleData!.Battle.Sides.First(x => x != pokemon.BattleData.BattleSide); return opponentSide.Pokemon.WhereNotNull().Any(x => x.Moves.WhereNotNull().Any(y => - y.MoveData.Category == MoveCategory.Special && y.MoveData.SecondaryEffect?.Name != "psyshock")); + y.MoveData.Category == MoveCategory.Special && + y.MoveData.SecondaryEffect?.Name != MoveEffectNames.Psyshock)); } case Statistic.Speed: { - if (!pokemon.HasMoveWithEffect("electro_ball")) + if (!pokemon.HasMoveWithEffect(MoveEffectNames.ElectroBall)) { var targetSpeed = pokemon.BoostedStats.Speed; var opponentSide = pokemon.BattleData!.Battle.Sides.First(x => x != pokemon.BattleData.BattleSide); @@ -266,8 +272,6 @@ public static class AIHelperFunctions return true; } - private static readonly StringKey FoulPlayAbilityName = "foul_play"; - private static void GetTargetStatRaiseScoreOne(ref int score, IPokemon target, Statistic stat, sbyte increment, AIMoveState move, float desireMult = 1) { @@ -311,7 +315,7 @@ public static class AIHelperFunctions { var hasPhysicalMoves = target.Moves.WhereNotNull().Any(x => x.MoveData.Category == MoveCategory.Physical && - x.MoveData.SecondaryEffect?.Name != FoulPlayAbilityName); + x.MoveData.SecondaryEffect?.Name != MoveEffectNames.FoulPlay); var inc = hasPhysicalMoves ? 8 : 12; score += (int)(inc * incMult); } @@ -340,15 +344,15 @@ public static class AIHelperFunctions else score += (int)(8 * incMult); } - if (target.HasMoveWithEffect("electro_ball", "power_trip")) + if (target.HasMoveWithEffect(MoveEffectNames.ElectroBall, MoveEffectNames.PowerTrip)) { score += (int)(5 * incMult); } - if (opponentSide.Pokemon.WhereNotNull().Any(x => x.HasMoveWithEffect("gyro_ball"))) + if (opponentSide.Pokemon.WhereNotNull().Any(x => x.HasMoveWithEffect(MoveEffectNames.GyroBall))) { score -= (int)(5 * incMult); } - if (target.ActiveAbility?.Name == "speed_boost") + if (target.ActiveAbility?.Name == AbilityNames.SpeedBoost) { score -= (int)(15 * (target.Opposes(move.User) ? 1 : desireMult)); } @@ -393,11 +397,11 @@ public static class AIHelperFunctions break; } } - if (target.HasMoveWithEffect("power_trip")) + if (target.HasMoveWithEffect(MoveEffectNames.PowerTrip)) { score += (int)(5 * increment * desireMult); } - if (opponentSide.Pokemon.WhereNotNull().Any(x => x.HasMoveWithEffect("punishment"))) + if (opponentSide.Pokemon.WhereNotNull().Any(x => x.HasMoveWithEffect(MoveEffectNames.Punishment))) { score -= (int)(5 * increment * desireMult); } @@ -445,7 +449,7 @@ public static class AIHelperFunctions { var hasPhysicalMoves = target.Moves.WhereNotNull().Any(x => x.MoveData.Category == MoveCategory.Physical && - x.MoveData.SecondaryEffect?.Name != FoulPlayAbilityName); + x.MoveData.SecondaryEffect?.Name != MoveEffectNames.FoulPlay); var dec = hasPhysicalMoves ? 8 : 12; score += (int)(dec * decMult); } @@ -475,11 +479,11 @@ public static class AIHelperFunctions score += (int)(8 * decMult); break; } - if (opponentSide.Pokemon.WhereNotNull().Any(x => x.HasMoveWithEffect("electro_ball"))) + if (opponentSide.Pokemon.WhereNotNull().Any(x => x.HasMoveWithEffect(MoveEffectNames.ElectroBall))) { score += (int)(5 * decMult); } - if (target.ActiveAbility?.Name == "speed_boost") + if (target.ActiveAbility?.Name == AbilityNames.SpeedBoost) { score -= (int)(15 * (target.Opposes(move.User) ? 1 : desireMult)); } @@ -502,11 +506,11 @@ public static class AIHelperFunctions break; } } - if (target.HasMoveWithEffect("power_trip")) + if (target.HasMoveWithEffect(MoveEffectNames.PowerTrip)) { score += (int)(5 * decrement * desireMult); } - if (opponentSide.Pokemon.WhereNotNull().Any(x => x.HasMoveWithEffect("punishment"))) + if (opponentSide.Pokemon.WhereNotNull().Any(x => x.HasMoveWithEffect(MoveEffectNames.Punishment))) { score -= (int)(5 * decrement * desireMult); } @@ -545,13 +549,13 @@ public static class AIHelperFunctions { if (move.Move.SecondaryEffect is null) return 0; - if (move.User.ActiveAbility?.Name == "sheer_force") + if (move.User.ActiveAbility?.Name == AbilityNames.SheerForce) return -999; if (target is not null && target.BattleData?.Position != move.User.BattleData?.Position && - target.ActiveAbility?.Name == "shield_dust") + target.ActiveAbility?.Name == AbilityNames.ShieldDust) return -999; - if ((move.Move.SecondaryEffect.Chance < 100 && move.User.ActiveAbility?.Name == "serene_grace") || + if ((move.Move.SecondaryEffect.Chance < 100 && move.User.ActiveAbility?.Name == AbilityNames.SereneGrace) || move.User.BattleData?.BattleSide.VolatileScripts.Contains() == true) { return 5; @@ -574,38 +578,38 @@ public static class AIHelperFunctions return true; if (pokemon.ActiveAbility != null) { - if (pokemon.ActiveAbility.Name == "guts" && status != ScriptUtils.ResolveName() && + if (pokemon.ActiveAbility.Name == AbilityNames.Guts && status != ScriptUtils.ResolveName() && status != ScriptUtils.ResolveName() && IsStatRaiseWorthwhile(pokemon, Statistic.Attack, 1, true)) { return true; } - if (pokemon.ActiveAbility.Name == "marvel_scale" && + if (pokemon.ActiveAbility.Name == AbilityNames.MarvelScale && IsStatRaiseWorthwhile(pokemon, Statistic.Defense, 1, true)) { return true; } - if (pokemon.ActiveAbility.Name == "quick_feet" && status != ScriptUtils.ResolveName() && + if (pokemon.ActiveAbility.Name == AbilityNames.QuickFeet && status != ScriptUtils.ResolveName() && status != ScriptUtils.ResolveName() && IsStatRaiseWorthwhile(pokemon, Statistic.Speed, 1, true)) { return true; } - if (pokemon.ActiveAbility.Name == "flare_boost" && status == ScriptUtils.ResolveName() && + if (pokemon.ActiveAbility.Name == AbilityNames.FlareBoost && status == ScriptUtils.ResolveName() && IsStatRaiseWorthwhile(pokemon, Statistic.SpecialAttack, 1, true)) { return true; } - if (pokemon.ActiveAbility.Name == "toxic_boost" && + if (pokemon.ActiveAbility.Name == AbilityNames.ToxicBoost && (status == ScriptUtils.ResolveName() || status == ScriptUtils.ResolveName()) && IsStatRaiseWorthwhile(pokemon, Statistic.Attack, 1, true)) { return true; } - if (pokemon.ActiveAbility.Name == "poison_heal" && status == ScriptUtils.ResolveName()) + if (pokemon.ActiveAbility.Name == AbilityNames.PoisonHeal && status == ScriptUtils.ResolveName()) { return true; } - if (pokemon.ActiveAbility.Name == "magic_guard") + if (pokemon.ActiveAbility.Name == AbilityNames.MagicGuard) { if (status != ScriptUtils.ResolveName() && status != ScriptUtils.ResolveName() && status != ScriptUtils.ResolveName()) diff --git a/Plugins/PkmnLib.Plugin.Gen7/AI/AISwitchFunctions.cs b/Plugins/PkmnLib.Plugin.Gen7/AI/AISwitchFunctions.cs index 11a5616..739299d 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/AI/AISwitchFunctions.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/AI/AISwitchFunctions.cs @@ -26,8 +26,6 @@ public static class AISwitchFunctions return effect.Turns <= 1; } - private static readonly StringKey PoisonHealAbilityName = "poison_heal"; - /// /// Switch out if the Pokémon is expected to take significant end-of-turn damage. /// @@ -50,7 +48,7 @@ public static class AISwitchFunctions return true; var statusScript = pokemon.StatusScript.Script; if (statusScript is BadlyPoisoned { Turns: > 0 } badlyPoisoned && - pokemon.ActiveAbility?.Name != PoisonHealAbilityName) + pokemon.ActiveAbility?.Name != AbilityNames.PoisonHeal) { var poisonDamage = pokemon.MaxHealth / 8; var nextToxicDamage = pokemon.MaxHealth * badlyPoisoned.GetPoisonMultiplier(); @@ -92,28 +90,18 @@ public static class AISwitchFunctions return bigThreat; } - private static readonly StringKey ImmunityAbilityName = "immunity"; - private static readonly StringKey InsomniaAbilityName = "insomnia"; - private static readonly StringKey LimberAbilityName = "limber"; - private static readonly StringKey MagmaArmorAbilityName = "magma_armor"; - private static readonly StringKey VitalSpiritAbilityName = "vital_spirit"; - private static readonly StringKey WaterBubbleAbilityName = "water_bubble"; - private static readonly StringKey WaterVeilAbilityName = "water_veil"; - private static readonly StringKey NaturalCureAbilityName = "natural_cure"; - private static readonly StringKey RegeneratorAbilityName = "regenerator"; - private static readonly Dictionary> StatusCureAbilities = new() { { - ImmunityAbilityName, + AbilityNames.Immunity, [ScriptUtils.ResolveName(), ScriptUtils.ResolveName()] }, - { InsomniaAbilityName, [ScriptUtils.ResolveName()] }, - { LimberAbilityName, [ScriptUtils.ResolveName()] }, - { MagmaArmorAbilityName, [ScriptUtils.ResolveName()] }, - { VitalSpiritAbilityName, [ScriptUtils.ResolveName()] }, - { WaterBubbleAbilityName, [ScriptUtils.ResolveName()] }, - { WaterVeilAbilityName, [ScriptUtils.ResolveName()] }, + { AbilityNames.Insomnia, [ScriptUtils.ResolveName()] }, + { AbilityNames.Limber, [ScriptUtils.ResolveName()] }, + { AbilityNames.MagmaArmor, [ScriptUtils.ResolveName()] }, + { AbilityNames.VitalSpirit, [ScriptUtils.ResolveName()] }, + { AbilityNames.WaterBubble, [ScriptUtils.ResolveName()] }, + { AbilityNames.WaterVeil, [ScriptUtils.ResolveName()] }, }; /// @@ -138,7 +126,7 @@ public static class AISwitchFunctions // Check abilities that cure specific status conditions var canCureStatus = false; - if (abilityName == NaturalCureAbilityName) + if (abilityName == AbilityNames.NaturalCure) { canCureStatus = true; } @@ -161,7 +149,7 @@ public static class AISwitchFunctions // Don't bother curing a poisoning if Toxic Spikes will just re-poison if (pokemon.StatusScript.Script is Poisoned or BadlyPoisoned && - !reserves.Any(p => p.Types.Any(t => t.Name == "poison"))) + !reserves.Any(p => p.Types.Any(t => t.Name == TypeNames.Poison))) { if (pokemon.BattleData!.BattleSide.VolatileScripts.TryGet(out _)) { @@ -177,7 +165,7 @@ public static class AISwitchFunctions if (ai.Random.GetInt(100) < 70) return true; } - else if (abilityName == RegeneratorAbilityName) + else if (abilityName == AbilityNames.Regenerator) { // Not worth healing if battler would lose more HP from switching back in later if (entryHazardDamage >= pokemon.MaxHealth / 3) diff --git a/Plugins/PkmnLib.Plugin.Gen7/Common/MoveFlags.cs b/Plugins/PkmnLib.Plugin.Gen7/Common/MoveFlags.cs deleted file mode 100644 index 00280f4..0000000 --- a/Plugins/PkmnLib.Plugin.Gen7/Common/MoveFlags.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace PkmnLib.Plugin.Gen7.Common; - -public static class MoveFlags -{ - public static readonly StringKey Ballistics = "ballistics"; - public static readonly StringKey Bite = "bite"; - public static readonly StringKey CantRepeat = "cant_repeat"; - public static readonly StringKey Charge = "charge"; - public static readonly StringKey Contact = "contact"; - public static readonly StringKey Dance = "dance"; - public static readonly StringKey Defrost = "defrost"; - public static readonly StringKey Distance = "distance"; - public static readonly StringKey EffectiveAgainstFly = "effective_against_fly"; - public static readonly StringKey EffectiveAgainstUnderground = "effective_against_underground"; - public static readonly StringKey EffectiveAgainstUnderwater = "effective_against_underwater"; - public static readonly StringKey Gravity = "gravity"; - public static readonly StringKey Heal = "heal"; - public static readonly StringKey HitFlying = "hit_flying"; - public static readonly StringKey HitUnderground = "hit_underground"; - public static readonly StringKey HitUnderwater = "hit_underwater"; - public static readonly StringKey IgnoreSubstitute = "ignore_substitute"; - public static readonly StringKey LimitMoveChoice = "limit_move_choice"; - public static readonly StringKey Mental = "mental"; - public static readonly StringKey Mirror = "mirror"; - public static readonly StringKey MultiHit = "multi_hit"; - public static readonly StringKey NoRedirection = "no_redirection"; - public static readonly StringKey NonSkyBattle = "non_sky_battle"; - public static readonly StringKey NotSketchable = "not_sketchable"; - public static readonly StringKey Powder = "powder"; - public static readonly StringKey Protect = "protect"; - public static readonly StringKey Pulse = "pulse"; - public static readonly StringKey Punch = "punch"; - public static readonly StringKey Recoil = "recoil"; - public static readonly StringKey Recharge = "recharge"; - public static readonly StringKey Reflectable = "reflectable"; - public static readonly StringKey Snatch = "snatch"; - public static readonly StringKey Sound = "sound"; - public static readonly StringKey UsableWhileAsleep = "usable_while_asleep"; -} \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/PkmnLib.Plugin.Gen7.csproj b/Plugins/PkmnLib.Plugin.Gen7/PkmnLib.Plugin.Gen7.csproj index 1312403..74d36ad 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/PkmnLib.Plugin.Gen7.csproj +++ b/Plugins/PkmnLib.Plugin.Gen7/PkmnLib.Plugin.Gen7.csproj @@ -7,9 +7,12 @@ + + diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Aftermath.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Aftermath.cs index 2fdfc50..e91f9f3 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Aftermath.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Aftermath.cs @@ -9,8 +9,6 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; [Script(ScriptCategory.Ability, "aftermath")] public class Aftermath : Script, IScriptOnIncomingHit, IScriptOnFaint { - private static readonly StringKey DampAbilityName = new("damp"); - private IExecutingMove? _lastAttack; /// @@ -35,7 +33,7 @@ public class Aftermath : Script, IScriptOnIncomingHit, IScriptOnFaint // Aftermath does not trigger if a Pokémon with Damp is on the field var battle = user.BattleData.Battle; var hasDamp = battle.Sides.SelectMany(side => side.Pokemon).WhereNotNull() - .Any(p => p.ActiveAbility?.Name == DampAbilityName); + .Any(p => p.ActiveAbility?.Name == AbilityNames.Damp); if (hasDamp) return; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Anticipation.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Anticipation.cs index bf7ba26..c4ed410 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Anticipation.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Anticipation.cs @@ -30,10 +30,10 @@ public class Anticipation : Script, IScriptOnOpponentSwitchIn // Either the move is super effective against the owner or typeLibrary.GetEffectiveness(move.MoveData.MoveType, _owner.Types) > 1.0f || // the move is a OHKO move - move.MoveData.SecondaryEffect?.Name == "one_hit_ko" || + move.MoveData.SecondaryEffect?.Name == MoveEffectNames.OneHitKo || // the move is a self-destruct move - move.MoveData.SecondaryEffect?.Name == "self_destruct" || - move.MoveData.SecondaryEffect?.Name == "explosion"); + move.MoveData.SecondaryEffect?.Name == MoveEffectNames.SelfDestruct || + move.MoveData.SecondaryEffect?.Name == MoveEffectNames.Explosion); if (relevantMoves) { diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/AuraBreak.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/AuraBreak.cs index bc4301a..768d3dc 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/AuraBreak.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/AuraBreak.cs @@ -16,7 +16,7 @@ public class AuraBreak : Script, IScriptCustomTrigger return; var typeName = auraArgs.Move.UseMove.MoveType.Name; - if (typeName == "dark" || typeName == "fairy") + if (typeName == TypeNames.Dark || typeName == TypeNames.Fairy) { // Reverse the aura effect by reducing power by 25% auraArgs.AuraEffect *= 0.75f; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/BattleBond.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/BattleBond.cs index 29445d0..0be27da 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/BattleBond.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/BattleBond.cs @@ -12,8 +12,8 @@ public class BattleBond : Script, IScriptChangeNumberOfHits, IScriptOnOpponentFa /// public void OnOpponentFaints(IExecutingMove move, IPokemon target, byte hit) { - if (move.User.Species.Name == "greninja" && move.User.Form.Name != "ash" && - move.User.Species.TryGetForm("ash", out var ashForm)) + if (move.User.Species.Name == SpeciesNames.Greninja && move.User.Form.Name != FormNames.Ash && + move.User.Species.TryGetForm(FormNames.Ash, out var ashForm)) { move.User.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(move.User)); move.User.ChangeForm(ashForm); @@ -23,14 +23,14 @@ public class BattleBond : Script, IScriptChangeNumberOfHits, IScriptOnOpponentFa /// public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower) { - if (move.UseMove.Name == "water_shuriken" && move.User.Form.Name == "ash") + if (move.UseMove.Name == MoveNames.WaterShuriken && move.User.Form.Name == FormNames.Ash) basePower = 20; } /// public void ChangeNumberOfHits(IMoveChoice choice, ref byte numberOfHits) { - if (choice.ChosenMove.MoveData.Name == "water_shuriken" && choice.User.Form.Name == "ash") + if (choice.ChosenMove.MoveData.Name == MoveNames.WaterShuriken && choice.User.Form.Name == FormNames.Ash) { numberOfHits = 3; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Damp.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Damp.cs index cb3c546..266277f 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Damp.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Damp.cs @@ -13,7 +13,7 @@ public class Damp : Script, IScriptFailIncomingMove /// public void FailIncomingMove(IExecutingMove move, IPokemon target, ref bool fail) { - if (move.UseMove.Name == "self_destruct" || move.UseMove.Name == "explosion") + if (move.UseMove.Name == MoveNames.SelfDestruct || move.UseMove.Name == MoveNames.Explosion) { fail = true; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/DarkAura.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/DarkAura.cs index 6ed0722..12d2fbf 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/DarkAura.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/DarkAura.cs @@ -12,7 +12,7 @@ public class DarkAura : Script, IScriptChangeDamageModifier /// public void ChangeDamageModifier(IExecutingMove move, IPokemon target, byte hit, ref float modifier) { - if (move.GetHitData(target, hit).Type?.Name == "dark") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Dark) { var auraModifier = 5448f / 4096f; var args = new CustomTriggers.ModifyAuraEffectArgs(move, target, hit, auraModifier); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Disguise.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Disguise.cs index 0bd9c26..96e54fd 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Disguise.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Disguise.cs @@ -19,17 +19,17 @@ public class Disguise : Script, IScriptChangeIncomingDamage return; if (source is not DamageSource.MoveDamage and not DamageSource.Confusion) return; - if (pokemon.Form.Name == "busted" || pokemon.Form.Name == "totem-busted") + if (pokemon.Form.Name == FormNames.Busted || pokemon.Form.Name == FormNames.TotemBusted) return; IForm form; - if (pokemon.Form.Name == "default") + if (pokemon.Form.Name == FormNames.Default) { - if (!pokemon.Species.TryGetForm("busted", out form!)) + if (!pokemon.Species.TryGetForm(FormNames.Busted, out form!)) return; } - else if (pokemon.Form.Name == "totem-disguised") + else if (pokemon.Form.Name == FormNames.TotemDisguised) { - if (!pokemon.Species.TryGetForm("totem-busted", out form!)) + if (!pokemon.Species.TryGetForm(FormNames.TotemBusted, out form!)) return; } else diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/DrySkin.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/DrySkin.cs index 874d3e9..0d962b8 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/DrySkin.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/DrySkin.cs @@ -26,11 +26,11 @@ public class DrySkin : Script, IScriptChangeDamageModifier, IScriptOnEndTurn, IA public void ChangeDamageModifier(IExecutingMove move, IPokemon target, byte hit, ref float modifier) { var hitType = move.GetHitData(target, hit).Type; - if (hitType?.Name == "fire") + if (hitType?.Name == TypeNames.Fire) { modifier *= 1.25f; } - else if (hitType?.Name == "water") + else if (hitType?.Name == TypeNames.Water) { modifier = 0; target.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(target)); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/EffectSpore.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/EffectSpore.cs index afe75b2..4337e51 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/EffectSpore.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/EffectSpore.cs @@ -13,11 +13,11 @@ public class EffectSpore : Script, IScriptOnIncomingHit /// public void OnIncomingHit(IExecutingMove move, IPokemon target, byte hit) { - if (move.User.Types.Any(x => x.Name == "grass")) + if (move.User.Types.Any(x => x.Name == TypeNames.Grass)) return; - if (move.User.ActiveAbility?.Name == "effect_spore") + if (move.User.ActiveAbility?.Name == AbilityNames.EffectSpore) return; - if (move.User.HasHeldItem("safety_goggles")) + if (move.User.HasHeldItem(ItemNames.SafetyGoggles)) return; if (!move.GetHitData(target, hit).IsContact) return; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/FairyAura.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/FairyAura.cs index bf3e4e3..02d580d 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/FairyAura.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/FairyAura.cs @@ -13,7 +13,7 @@ public class FairyAura : Script, IScriptChangeDamageModifier /// public void ChangeDamageModifier(IExecutingMove move, IPokemon target, byte hit, ref float modifier) { - if (move.GetHitData(target, hit).Type?.Name == "fairy") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Fairy) { var auraModifier = 5448f / 4096f; var args = new CustomTriggers.ModifyAuraEffectArgs(move, target, hit, auraModifier); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/FlashFire.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/FlashFire.cs index 00ae2de..970d2d9 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/FlashFire.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/FlashFire.cs @@ -16,7 +16,7 @@ public class FlashFire : Script, IScriptChangeIncomingEffectiveness public void ChangeIncomingEffectiveness(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref float effectiveness) { - if (executingMove.GetHitData(target, hitIndex).Type?.Name != "fire") + if (executingMove.GetHitData(target, hitIndex).Type?.Name != TypeNames.Fire) return; effectiveness = 0f; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/FlowerGift.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/FlowerGift.cs index 833a0ea..a9e1d9d 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/FlowerGift.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/FlowerGift.cs @@ -28,10 +28,10 @@ public class FlowerGift : Script, IScriptOnWeatherChange return; if (weatherName != ScriptUtils.ResolveName()) return; - if (_pokemon.Species.Name != "cherrim") + if (_pokemon.Species.Name != SpeciesNames.Cherrim) return; EventBatchId batchId = new(); - if (_pokemon.Species.TryGetForm("sunshine", out var form) && _pokemon.Form != form) + if (_pokemon.Species.TryGetForm(FormNames.Sunshine, out var form) && _pokemon.Form != form) { _pokemon.ChangeForm(form, batchId); } @@ -47,7 +47,7 @@ public class FlowerGift : Script, IScriptOnWeatherChange script.OnRemoved(_pokemon); } - if (_pokemon.Species.Name != "cherrim") + if (_pokemon.Species.Name != SpeciesNames.Cherrim) return; EventBatchId batchId = new(); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Fluffy.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Fluffy.cs index cfb6a44..25b51e7 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Fluffy.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Fluffy.cs @@ -12,7 +12,7 @@ public class Fluffy : Script, IScriptChangeDamageModifier /// public void ChangeDamageModifier(IExecutingMove move, IPokemon target, byte hit, ref float modifier) { - if (move.GetHitData(target, hit).Type?.Name == "fire") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Fire) { modifier *= 2f; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Forecast.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Forecast.cs index b3607dd..29322bd 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Forecast.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Forecast.cs @@ -45,21 +45,21 @@ public class Forecast : Script, IScriptOnSwitchIn, IScriptOnWeatherChange private static void ChangeForm(IPokemon pokemon, StringKey? weather) { - if (pokemon.Species.Name != "castform") + if (pokemon.Species.Name != SpeciesNames.Castform) return; if (weather == ScriptUtils.ResolveName() && - pokemon.Species.TryGetForm("sunny", out var sunnyForm) && pokemon.Form != sunnyForm) + pokemon.Species.TryGetForm(FormNames.Sunny, out var sunnyForm) && pokemon.Form != sunnyForm) { pokemon.ChangeForm(sunnyForm); } else if (weather == ScriptUtils.ResolveName() && - pokemon.Species.TryGetForm("rainy", out var rainyForm) && pokemon.Form != rainyForm) + pokemon.Species.TryGetForm(FormNames.Rainy, out var rainyForm) && pokemon.Form != rainyForm) { pokemon.ChangeForm(rainyForm); } else if (weather == ScriptUtils.ResolveName() && - pokemon.Species.TryGetForm("snowy", out var snowyForm) && pokemon.Form != snowyForm) + pokemon.Species.TryGetForm(FormNames.Snowy, out var snowyForm) && pokemon.Form != snowyForm) { pokemon.ChangeForm(snowyForm); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Forewarn.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Forewarn.cs index c244584..331aac1 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Forewarn.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Forewarn.cs @@ -37,28 +37,64 @@ public class Forewarn : Script, IScriptOnSwitchIn }); } + private static readonly Dictionary FixedBasePowers = new() + { + // 150 BP: Specific moves + [MoveNames.BlastBurn] = 150, + [MoveNames.Eruption] = 150, + [MoveNames.WaterSpout] = 150, + [MoveNames.Fissure] = 150, + [MoveNames.Guillotine] = 150, + [MoveNames.HornDrill] = 150, + [MoveNames.SheerCold] = 150, + // 120 BP: Counter, Metal Burst, Mirror Coat + [MoveNames.Counter] = 120, + [MoveNames.MetalBurst] = 120, + [MoveNames.MirrorCoat] = 120, + // 80 BP: List of variable power and fixed-damage moves + [MoveNames.CrushGrip] = 80, + [MoveNames.DragonRage] = 80, + [MoveNames.ElectroBall] = 80, + [MoveNames.Endeavor] = 80, + [MoveNames.FinalGambit] = 80, + [MoveNames.Flail] = 80, + [MoveNames.Fling] = 80, + [MoveNames.Frustration] = 80, + [MoveNames.GrassKnot] = 80, + [MoveNames.GuardianOfAlola] = 80, + [MoveNames.GyroBall] = 80, + [MoveNames.HeatCrash] = 80, + [MoveNames.HeavySlam] = 80, + [MoveNames.HiddenPower] = 80, + [MoveNames.LowKick] = 80, + [MoveNames.NaturalGift] = 80, + [MoveNames.NaturesMadness] = 80, + [MoveNames.NightShade] = 80, + [MoveNames.Present] = 80, + [MoveNames.Psywave] = 80, + [MoveNames.Punishment] = 80, + [MoveNames.Return] = 80, + [MoveNames.Reversal] = 80, + [MoveNames.SeismicToss] = 80, + [MoveNames.SonicBoom] = 80, + [MoveNames.SpitUp] = 80, + [MoveNames.SuperFang] = 80, + [MoveNames.TrumpCard] = 80, + [MoveNames.WringOut] = 80, + // 20 BP: Stored Power, Power Trip + [MoveNames.StoredPower] = 20, + [MoveNames.PowerTrip] = 20, + }; + private static byte GetBasePower(IMoveData moveData) { // OHKO moves (handled by secondary effect) - if (moveData.SecondaryEffect?.Name == "one_hit_ko") + if (moveData.SecondaryEffect?.Name == MoveEffectNames.OneHitKo) return 150; - return moveData.Name.ToString() switch - { - // 150 BP: Specific moves - "blast_burn" or "eruption" or "water_spout" or "fissure" or "guillotine" or "horn_drill" - or "sheer_cold" => 150, - // 120 BP: Counter, Metal Burst, Mirror Coat - "counter" or "metal_burst" or "mirror_coat" => 120, - // 80 BP: List of variable power and fixed-damage moves - "crush_grip" or "dragon_rage" or "electro_ball" or "endeavor" or "final_gambit" or "flail" or "fling" - or "frustration" or "grass_knot" or "guardian_of_alola" or "gyro_ball" or "heat_crash" or "heavy_slam" - or "hidden_power" or "low_kick" or "natural_gift" or "natures_madness" or "night_shade" or "present" - or "psywave" or "punishment" or "return" or "reversal" or "seismic_toss" or "sonic_boom" or "spit_up" - or "super_fang" or "trump_card" or "wring_out" => 80, - // 20 BP: Stored Power, Power Trip - "stored_power" or "power_trip" => 20, - _ => moveData.BasePower == 0 ? (byte)1 : moveData.BasePower, - }; + if (FixedBasePowers.TryGetValue(moveData.Name, out var fixedBasePower)) + return fixedBasePower; + + return moveData.BasePower == 0 ? (byte)1 : moveData.BasePower; } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Galvanize.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Galvanize.cs index 4312b56..24ed853 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Galvanize.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Galvanize.cs @@ -12,8 +12,8 @@ public class Galvanize : Script, IScriptChangeMoveType, IScriptChangeDamageModif /// public void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier? typeIdentifier) { - if (typeIdentifier?.Name == "normal" && - move.Battle.Library.StaticLibrary.Types.TryGetTypeIdentifier("electric", out var electricType)) + if (typeIdentifier?.Name == TypeNames.Normal && + move.Battle.Library.StaticLibrary.Types.TryGetTypeIdentifier(TypeNames.Electric, out var electricType)) { typeIdentifier = electricType; } @@ -22,7 +22,7 @@ public class Galvanize : Script, IScriptChangeMoveType, IScriptChangeDamageModif /// public void ChangeDamageModifier(IExecutingMove move, IPokemon target, byte hit, ref float modifier) { - if (move.GetHitData(target, hit).Type?.Name == "electric") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Electric) modifier *= 1.2f; } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Heatproof.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Heatproof.cs index 1fcaeca..b832f58 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Heatproof.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Heatproof.cs @@ -11,7 +11,7 @@ public class Heatproof : Script, IScriptChangeBasePower /// public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower) { - if (move.GetHitData(target, hit).Type?.Name == "fire") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Fire) { basePower = (ushort)(basePower / 2); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Justified.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Justified.cs index 57c2e9f..30667ef 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Justified.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Justified.cs @@ -11,7 +11,7 @@ public class Justified : Script, IScriptOnIncomingHit /// public void OnIncomingHit(IExecutingMove move, IPokemon target, byte hit) { - if (move.GetHitData(target, hit).Type?.Name != "dark") + if (move.GetHitData(target, hit).Type?.Name != TypeNames.Dark) return; EventBatchId batchId = new(); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/LightningRod.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/LightningRod.cs index 11dde85..96ba5f5 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/LightningRod.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/LightningRod.cs @@ -11,7 +11,7 @@ public class LightningRod : Script, IScriptChangeIncomingTargets, IScriptChangeE /// public void ChangeIncomingTargets(IMoveChoice moveChoice, ref IReadOnlyList targets) { - if (moveChoice.ChosenMove.MoveData.MoveType.Name == "electric" && targets.Count == 1) + if (moveChoice.ChosenMove.MoveData.MoveType.Name == TypeNames.Electric && targets.Count == 1) { targets = [moveChoice.User]; } @@ -20,7 +20,7 @@ public class LightningRod : Script, IScriptChangeIncomingTargets, IScriptChangeE /// public void ChangeEffectiveness(IExecutingMove move, IPokemon target, byte hit, ref float effectiveness) { - if (move.GetHitData(target, hit).Type?.Name != "electric") + if (move.GetHitData(target, hit).Type?.Name != TypeNames.Electric) return; effectiveness = 0f; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/LiquidVoice.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/LiquidVoice.cs index 3e3083b..8c13198 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/LiquidVoice.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/LiquidVoice.cs @@ -12,7 +12,7 @@ public class LiquidVoice : Script, IScriptChangeMoveType public void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier? typeIdentifier) { if (move.UseMove.HasFlag(MoveFlags.Sound) && - move.Battle.Library.StaticLibrary.Types.TryGetTypeIdentifier("water", out var waterType)) + move.Battle.Library.StaticLibrary.Types.TryGetTypeIdentifier(TypeNames.Water, out var waterType)) { typeIdentifier = waterType; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/MagnetPull.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/MagnetPull.cs index 4e68279..b1817f6 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/MagnetPull.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/MagnetPull.cs @@ -11,14 +11,14 @@ public class MagnetPull : Script, IScriptPreventOpponentRunAway, IScriptPreventO /// public void PreventOpponentRunAway(IFleeChoice choice, ref bool prevent) { - if (choice.User.Types.Any(x => x.Name == "steel")) + if (choice.User.Types.Any(x => x.Name == TypeNames.Steel)) prevent = true; } /// public void PreventOpponentSwitch(ISwitchChoice choice, ref bool prevent) { - if (choice.User.Types.Any(x => x.Name == "steel")) + if (choice.User.Types.Any(x => x.Name == TypeNames.Steel)) prevent = true; } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Minus.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Minus.cs index 520ef61..e506d50 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Minus.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Minus.cs @@ -15,7 +15,8 @@ public class Minus : Script, IScriptChangeOffensiveStatValue var battleData = move.User.BattleData; if (battleData is null) return; - if (battleData.BattleSide.Pokemon.WhereNotNull().Any(x => x.IsUsable && x.ActiveAbility?.Name == "plus")) + if (battleData.BattleSide.Pokemon.WhereNotNull() + .Any(x => x.IsUsable && x.ActiveAbility?.Name == AbilityNames.Plus)) { value = value.MultiplyOrMax(1.5f); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/MotorDrive.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/MotorDrive.cs index 7802ff2..2d14d4e 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/MotorDrive.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/MotorDrive.cs @@ -11,7 +11,7 @@ public class MotorDrive : Script, IScriptIsInvulnerableToMove /// public void IsInvulnerableToMove(IExecutingMove move, IPokemon target, ref bool invulnerable) { - if (move.UseMove.MoveType.Name != "electric") + if (move.UseMove.MoveType.Name != TypeNames.Electric) return; invulnerable = true; move.Battle.EventHook.Invoke(new AbilityTriggerEvent(target)); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Multitype.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Multitype.cs index df405d6..f312d1a 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Multitype.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Multitype.cs @@ -8,72 +8,40 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; [Script(ScriptCategory.Ability, "multitype")] public class Multitype : Script, IScriptOnAfterHeldItemChange { + private static readonly Dictionary PlateForms = new() + { + [ItemNames.FistPlate] = FormNames.ArceusFighting, + [ItemNames.FlamePlate] = FormNames.ArceusFire, + [ItemNames.ZapPlate] = FormNames.ArceusElectric, + [ItemNames.DracoPlate] = FormNames.ArceusDragon, + [ItemNames.DreadPlate] = FormNames.ArceusDark, + [ItemNames.EarthPlate] = FormNames.ArceusGround, + [ItemNames.IciclePlate] = FormNames.ArceusIce, + [ItemNames.InsectPlate] = FormNames.ArceusBug, + [ItemNames.IronPlate] = FormNames.ArceusSteel, + [ItemNames.MeadowPlate] = FormNames.ArceusGrass, + [ItemNames.MindPlate] = FormNames.ArceusPsychic, + [ItemNames.PixiePlate] = FormNames.ArceusFairy, + [ItemNames.SkyPlate] = FormNames.ArceusFlying, + [ItemNames.SplashPlate] = FormNames.ArceusWater, + [ItemNames.SpookyPlate] = FormNames.ArceusGhost, + [ItemNames.StonePlate] = FormNames.ArceusRock, + [ItemNames.ToxicPlate] = FormNames.ArceusPoison, + }; + /// public void OnAfterHeldItemChange(IPokemon pokemon, IItem? previous, IItem? item) { - if (pokemon.Species.Name != "arceus") + if (pokemon.Species.Name != SpeciesNames.Arceus) return; - if (item is null && pokemon.Form.Name != "default") + if (item is null && pokemon.Form.Name != FormNames.Default) { pokemon.ChangeForm(pokemon.Species.GetDefaultForm()); } - else if (item is not null && item.Name.ToString().EndsWith("_plate", StringComparison.OrdinalIgnoreCase)) + else if (item is not null && PlateForms.TryGetValue(item.Name, out var formName) && + pokemon.Species.TryGetForm(formName, out var form)) { - var platePrefix = item.Name.ToString().Replace("_plate", string.Empty, StringComparison.OrdinalIgnoreCase); - switch (platePrefix) - { - case "fist" when pokemon.Species.TryGetForm("arceus_fighting", out var fightingForm): - pokemon.ChangeForm(fightingForm); - break; - case "flame" when pokemon.Species.TryGetForm("arceus_fire", out var fireForm): - pokemon.ChangeForm(fireForm); - break; - case "shock" when pokemon.Species.TryGetForm("arceus_electric", out var electricForm): - pokemon.ChangeForm(electricForm); - break; - case "draco" when pokemon.Species.TryGetForm("arceus_dragon", out var dragonForm): - pokemon.ChangeForm(dragonForm); - break; - case "dread" when pokemon.Species.TryGetForm("arceus_dark", out var darkForm): - pokemon.ChangeForm(darkForm); - break; - case "earth" when pokemon.Species.TryGetForm("arceus_ground", out var groundForm): - pokemon.ChangeForm(groundForm); - break; - case "icicle" when pokemon.Species.TryGetForm("arceus_ice", out var iceForm): - pokemon.ChangeForm(iceForm); - break; - case "insect" when pokemon.Species.TryGetForm("arceus_bug", out var bugForm): - pokemon.ChangeForm(bugForm); - break; - case "iron" when pokemon.Species.TryGetForm("arceus_steel", out var steelForm): - pokemon.ChangeForm(steelForm); - break; - case "meadow" when pokemon.Species.TryGetForm("arceus_grass", out var grassForm): - pokemon.ChangeForm(grassForm); - break; - case "mind" when pokemon.Species.TryGetForm("arceus_psychic", out var psychicForm): - pokemon.ChangeForm(psychicForm); - break; - case "pixie" when pokemon.Species.TryGetForm("arceus_fairy", out var fairyForm): - pokemon.ChangeForm(fairyForm); - break; - case "sky" when pokemon.Species.TryGetForm("arceus_flying", out var flyingForm): - pokemon.ChangeForm(flyingForm); - break; - case "splash" when pokemon.Species.TryGetForm("arceus_water", out var waterForm): - pokemon.ChangeForm(waterForm); - break; - case "spooky" when pokemon.Species.TryGetForm("arceus_ghost", out var ghostForm): - pokemon.ChangeForm(ghostForm); - break; - case "stone" when pokemon.Species.TryGetForm("arceus_rock", out var rockForm): - pokemon.ChangeForm(rockForm); - break; - case "toxic" when pokemon.Species.TryGetForm("arceus_poison", out var poisonForm): - pokemon.ChangeForm(poisonForm); - break; - } + pokemon.ChangeForm(form); } } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Mummy.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Mummy.cs index b85501c..6d40503 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Mummy.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Mummy.cs @@ -11,8 +11,8 @@ public class Mummy : Script, IScriptOnIncomingHit /// public void OnIncomingHit(IExecutingMove move, IPokemon target, byte hit) { - if (!move.GetHitData(target, hit).IsContact || move.User.ActiveAbility?.Name == "mummy" || - !move.Battle.Library.StaticLibrary.Abilities.TryGet("mummy", out var mummyAbility)) + if (!move.GetHitData(target, hit).IsContact || move.User.ActiveAbility?.Name == AbilityNames.Mummy || + !move.Battle.Library.StaticLibrary.Abilities.TryGet(AbilityNames.Mummy, out var mummyAbility)) return; move.Battle.EventHook.Invoke(new AbilityTriggerEvent(target)); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Normalize.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Normalize.cs index 3320f33..b2e0f34 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Normalize.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Normalize.cs @@ -11,14 +11,14 @@ public class Normalize : Script, IScriptChangeMoveType, IScriptChangeBasePower /// public void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier? typeIdentifier) { - if (move.Battle.Library.StaticLibrary.Types.TryGetTypeIdentifier("normal", out var normalType)) + if (move.Battle.Library.StaticLibrary.Types.TryGetTypeIdentifier(TypeNames.Normal, out var normalType)) typeIdentifier = normalType; } /// public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower) { - if (move.GetHitData(target, hit).Type?.Name == "normal") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Normal) basePower = (ushort)(basePower * 1.2f); // Boost Normal-type moves by 30% } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Pixilate.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Pixilate.cs index 2311a60..a179a61 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Pixilate.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Pixilate.cs @@ -11,15 +11,15 @@ public class Pixilate : Script, IScriptChangeMoveType, IScriptChangeBasePower /// public void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier? typeIdentifier) { - if (typeIdentifier?.Name == "normal" && - move.Battle.Library.StaticLibrary.Types.TryGetTypeIdentifier("fairy", out var fairyType)) + if (typeIdentifier?.Name == TypeNames.Normal && + move.Battle.Library.StaticLibrary.Types.TryGetTypeIdentifier(TypeNames.Fairy, out var fairyType)) typeIdentifier = fairyType; } /// public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower) { - if (move.GetHitData(target, hit).Type?.Name == "fairy") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Fairy) basePower = (ushort)(basePower * 1.2f); // Boost Normal-type moves by 30% } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Plus.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Plus.cs index fcb784e..768a451 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Plus.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Plus.cs @@ -15,7 +15,8 @@ public class Plus : Script, IScriptChangeOffensiveStatValue var battleData = move.User.BattleData; if (battleData is null) return; - if (battleData.BattleSide.Pokemon.WhereNotNull().Any(x => x.IsUsable && x.ActiveAbility?.Name == "minus")) + if (battleData.BattleSide.Pokemon.WhereNotNull() + .Any(x => x.IsUsable && x.ActiveAbility?.Name == AbilityNames.Minus)) { value = value.MultiplyOrMax(1.5f); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/PowerConstruct.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/PowerConstruct.cs index bf0500c..6aea4a9 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/PowerConstruct.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/PowerConstruct.cs @@ -23,13 +23,13 @@ public class PowerConstruct : Script, IScriptOnEndTurn { if (_pokemon?.BattleData?.Battle == null) return; - if (_pokemon.Species.Name != "zygarde") + if (_pokemon.Species.Name != SpeciesNames.Zygarde) return; if (_pokemon.CurrentHealth > _pokemon.BoostedStats.Hp / 2) return; - if (_pokemon.Form.Name != "10" || _pokemon.Form.Name != "50") + if (_pokemon.Form.Name != FormNames._10 || _pokemon.Form.Name != FormNames._50) return; - if (!_pokemon.Species.TryGetForm("complete", out var completeForm)) + if (!_pokemon.Species.TryGetForm(FormNames.Complete, out var completeForm)) return; _pokemon.ChangeForm(completeForm); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/QuickFeet.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/QuickFeet.cs index 04a1d2a..d629ba3 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/QuickFeet.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/QuickFeet.cs @@ -13,7 +13,7 @@ public class QuickFeet : Script, IScriptChangeSpeed { if (choice.User.StatusScript.IsEmpty) return; - if (choice.User.StatusScript.Script?.Name == "paralyzed") + if (choice.User.StatusScript.Script?.Name == ScriptUtils.ResolveName()) speed = speed.MultiplyOrMax(2); speed = speed.MultiplyOrMax(1.5f); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/RKSSystem.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/RKSSystem.cs index 1087480..307a941 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/RKSSystem.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/RKSSystem.cs @@ -11,9 +11,9 @@ public class RksSystem : Script, IScriptOnAfterHeldItemChange /// public void OnAfterHeldItemChange(IPokemon pokemon, IItem? previous, IItem? item) { - if (pokemon.Species.Name != "silvally") + if (pokemon.Species.Name != SpeciesNames.Silvally) return; - if (item is null && pokemon.Form.Name != "default") + if (item is null && pokemon.Form.Name != FormNames.Default) { pokemon.ChangeForm(pokemon.Species.GetDefaultForm()); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Rattled.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Rattled.cs index 4c15b2e..4ab881e 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Rattled.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Rattled.cs @@ -14,7 +14,7 @@ public class Rattled : Script, IScriptOnIncomingHit var type = move.GetHitData(target, hit).Type; if (type is null) return; - if (type.Value.Name != "bug" && type.Value.Name != "ghost" && type.Value.Name != "dark") + if (type.Value.Name != TypeNames.Bug && type.Value.Name != TypeNames.Ghost && type.Value.Name != TypeNames.Dark) return; target.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(target)); target.ChangeStatBoost(Statistic.Speed, 1, true, false); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Refrigerate.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Refrigerate.cs index e3e22dd..1b7e152 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Refrigerate.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Refrigerate.cs @@ -11,15 +11,15 @@ public class Refrigerate : Script, IScriptChangeMoveType, IScriptChangeBasePower /// public void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier? typeIdentifier) { - if (typeIdentifier?.Name == "normal" && - move.Battle.Library.StaticLibrary.Types.TryGetTypeIdentifier("ice", out var iceType)) + if (typeIdentifier?.Name == TypeNames.Normal && + move.Battle.Library.StaticLibrary.Types.TryGetTypeIdentifier(TypeNames.Ice, out var iceType)) typeIdentifier = iceType; } /// public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower) { - if (move.GetHitData(target, hit).Type?.Name == "ice") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Ice) basePower = (ushort)(basePower * 1.2f); // Boost Normal-type moves by 30% } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/SandForce.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/SandForce.cs index 74d2d25..b8846ca 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/SandForce.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/SandForce.cs @@ -14,8 +14,8 @@ public class SandForce : Script, IScriptChangeBasePower, IScriptCustomTrigger if (move.Battle.WeatherName == ScriptUtils.ResolveName()) { var type = move.GetHitData(target, hit).Type; - if (type != null && - (type.Value.Name == "rock" || type.Value.Name == "ground" || type.Value.Name == "steel")) + if (type != null && (type.Value.Name == TypeNames.Rock || type.Value.Name == TypeNames.Ground || + type.Value.Name == TypeNames.Steel)) { basePower = basePower.MultiplyOrMax(1.3f); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/SapSipper.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/SapSipper.cs index 60f2964..0f3a28a 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/SapSipper.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/SapSipper.cs @@ -11,7 +11,7 @@ public class SapSipper : Script, IScriptIsInvulnerableToMove /// public void IsInvulnerableToMove(IExecutingMove move, IPokemon target, ref bool invulnerable) { - if (move.GetHitData(target, 0).Type?.Name == "grass") + if (move.GetHitData(target, 0).Type?.Name == TypeNames.Grass) { invulnerable = true; move.Battle.EventHook.Invoke(new AbilityTriggerEvent(target)); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Schooling.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Schooling.cs index 70fc250..16ac290 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Schooling.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Schooling.cs @@ -29,15 +29,15 @@ public class Schooling : Script, IScriptOnEndTurn, IScriptOnSwitchIn if (pokemon is null) return; - if (pokemon.Species.Name != "wishiwashi" || pokemon.BattleData?.Battle == null) + if (pokemon.Species.Name != SpeciesNames.Wishiwashi || pokemon.BattleData?.Battle == null) return; // If Wishiwashi has less than 25% health, change to Solo form - if (pokemon.CurrentHealth < pokemon.MaxHealth / 4 && pokemon.Form.Name != "default") + if (pokemon.CurrentHealth < pokemon.MaxHealth / 4 && pokemon.Form.Name != FormNames.Default) { pokemon.ChangeForm(pokemon.Species.GetDefaultForm()); } - else if (pokemon.CurrentHealth >= pokemon.MaxHealth / 4 && pokemon.Form.Name != "school" && - pokemon.Species.TryGetForm("school", out var schoolForm)) + else if (pokemon.CurrentHealth >= pokemon.MaxHealth / 4 && pokemon.Form.Name != FormNames.School && + pokemon.Species.TryGetForm(FormNames.School, out var schoolForm)) { pokemon.ChangeForm(schoolForm); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Scrappy.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Scrappy.cs index cd75d21..2439b4e 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Scrappy.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Scrappy.cs @@ -13,9 +13,9 @@ public class Scrappy : Script, IScriptChangeTypesForMove IList types) { var hitType = executingMove.GetHitData(target, hitIndex).Type; - if (hitType?.Name != "normal" && hitType?.Name != "fighting") + if (hitType?.Name != TypeNames.Normal && hitType?.Name != TypeNames.Fighting) return; - if (types.Any(x => x.Name == "ghost")) - types.RemoveAll(x => x.Name == "ghost"); + if (types.Any(x => x.Name == TypeNames.Ghost)) + types.RemoveAll(x => x.Name == TypeNames.Ghost); } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ShieldsDown.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ShieldsDown.cs index 30304dc..9f1fd76 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ShieldsDown.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ShieldsDown.cs @@ -19,7 +19,7 @@ public class ShieldsDown : Script, IScriptOnEndTurn, IScriptOnSwitchIn if (pokemon is null) return; - if (pokemon.Species.Name != "minior" || pokemon.BattleData?.Battle == null) + if (pokemon.Species.Name != SpeciesNames.Minior || pokemon.BattleData?.Battle == null) return; if (pokemon.CurrentHealth < pokemon.MaxHealth / 2 && pokemon.Form.Name.ToString().EndsWith("-meteor")) { @@ -35,7 +35,7 @@ public class ShieldsDown : Script, IScriptOnEndTurn, IScriptOnSwitchIn pokemon.Form.Name.ToString().EndsWith("-meteor") == false) { var baseFormName = pokemon.Form.Name; - if (baseFormName == "default") + if (baseFormName == FormNames.Default) baseFormName = "blue"; var meteorFormName = baseFormName + "-meteor"; if (pokemon.Species.TryGetForm(meteorFormName, out var meteorFormData)) diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/StanceChange.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/StanceChange.cs index c9e48de..3916525 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/StanceChange.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/StanceChange.cs @@ -13,11 +13,11 @@ public class StanceChange : Script, IScriptOnBeforeMove /// public void OnBeforeMove(IExecutingMove move) { - if (move.User.Species.Name != "aegislash") + if (move.User.Species.Name != SpeciesNames.Aegislash) return; if (move.UseMove.Category is not (MoveCategory.Physical or MoveCategory.Special) || - move.User.Form.Name == "blade" || !move.User.Species.TryGetForm("blade", out var bladeForm)) + move.User.Form.Name == FormNames.Blade || !move.User.Species.TryGetForm(FormNames.Blade, out var bladeForm)) return; EventBatchId batchId = new(); move.Battle.EventHook.Invoke(new AbilityTriggerEvent(move.User) diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Steelworker.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Steelworker.cs index 4fd58bb..9ebf2e9 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Steelworker.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Steelworker.cs @@ -12,7 +12,7 @@ public class Steelworker : Script, IScriptChangeOffensiveStatValue public void ChangeOffensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint defensiveStat, ImmutableStatisticSet targetStats, Statistic stat, ref uint value) { - if (move.GetHitData(target, hit).Type?.Name == "steel") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Steel) { value = value.MultiplyOrMax(1.5f); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/StormDrain.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/StormDrain.cs index a25b0b1..1eaad7e 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/StormDrain.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/StormDrain.cs @@ -11,7 +11,7 @@ public class StormDrain : Script, IScriptChangeIncomingTargets, IScriptChangeEff /// public void ChangeIncomingTargets(IMoveChoice moveChoice, ref IReadOnlyList targets) { - if (moveChoice.ChosenMove.MoveData.MoveType.Name == "water" && targets.Count == 1) + if (moveChoice.ChosenMove.MoveData.MoveType.Name == TypeNames.Water && targets.Count == 1) { targets = [moveChoice.User]; } @@ -20,7 +20,7 @@ public class StormDrain : Script, IScriptChangeIncomingTargets, IScriptChangeEff /// public void ChangeEffectiveness(IExecutingMove move, IPokemon target, byte hit, ref float effectiveness) { - if (move.GetHitData(target, hit).Type?.Name != "water") + if (move.GetHitData(target, hit).Type?.Name != TypeNames.Water) return; effectiveness = 0f; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ThickFat.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ThickFat.cs index 43fe239..a54da84 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ThickFat.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ThickFat.cs @@ -12,7 +12,7 @@ public class ThickFat : Script, IScriptChangeMoveDamage public void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage) { var type = move.GetHitData(target, hit).Type; - if (type is not null && (type.Value.Name == "ice" || type.Value.Name == "fire")) + if (type is not null && (type.Value.Name == TypeNames.Ice || type.Value.Name == TypeNames.Fire)) { damage /= 2; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/VoltAbsorb.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/VoltAbsorb.cs index 9caaf2c..f5d98ae 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/VoltAbsorb.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/VoltAbsorb.cs @@ -11,7 +11,7 @@ public class VoltAbsorb : Script, IScriptIsInvulnerableToMove /// public void IsInvulnerableToMove(IExecutingMove move, IPokemon target, ref bool invulnerable) { - if (move.GetHitData(target, 0).Type?.Name != "electric") + if (move.GetHitData(target, 0).Type?.Name != TypeNames.Electric) return; invulnerable = true; target.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(target)); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterAbsorb.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterAbsorb.cs index f9efaec..b0c1415 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterAbsorb.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterAbsorb.cs @@ -11,7 +11,7 @@ public class WaterAbsorb : Script, IScriptIsInvulnerableToMove /// public void IsInvulnerableToMove(IExecutingMove move, IPokemon target, ref bool invulnerable) { - if (move.GetHitData(target, 0).Type?.Name != "water") + if (move.GetHitData(target, 0).Type?.Name != TypeNames.Water) return; invulnerable = true; target.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(target)); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterBubble.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterBubble.cs index f7500ad..eac9c56 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterBubble.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterBubble.cs @@ -18,14 +18,14 @@ public class WaterBubble : Script, IScriptChangeIncomingMoveDamage, IScriptChang /// public void ChangeIncomingMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage) { - if (move.GetHitData(target, hit).Type?.Name == "fire") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Fire) damage /= 2; } /// public void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage) { - if (move.GetHitData(target, hit).Type?.Name == "water") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Water) damage *= 2; } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterCompaction.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterCompaction.cs index ab87149..56234e7 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterCompaction.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterCompaction.cs @@ -11,7 +11,7 @@ public class WaterCompaction : Script, IScriptOnIncomingHit /// public void OnIncomingHit(IExecutingMove move, IPokemon target, byte hit) { - if (move.GetHitData(target, hit).Type?.Name != "water") + if (move.GetHitData(target, hit).Type?.Name != TypeNames.Water) return; target.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(target)); target.ChangeStatBoost(Statistic.Defense, 2, true, false); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ZenMode.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ZenMode.cs index 31c7ce2..710fb97 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ZenMode.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ZenMode.cs @@ -19,14 +19,14 @@ public class ZenMode : Script, IScriptOnEndTurn, IScriptOnSwitchIn if (pokemon is null) return; - if (pokemon.Species.Name != "darmanitan" || pokemon.BattleData?.Battle == null) + if (pokemon.Species.Name != SpeciesNames.Darmanitan || pokemon.BattleData?.Battle == null) return; - if (pokemon.CurrentHealth < pokemon.MaxHealth / 2 && pokemon.Form.Name != "zen" && - pokemon.Species.TryGetForm("zen", out var zenForm)) + if (pokemon.CurrentHealth < pokemon.MaxHealth / 2 && pokemon.Form.Name != FormNames.Zen && + pokemon.Species.TryGetForm(FormNames.Zen, out var zenForm)) { pokemon.ChangeForm(zenForm); } - else if (pokemon.CurrentHealth >= pokemon.MaxHealth / 2 && pokemon.Form.Name == "zen") + else if (pokemon.CurrentHealth >= pokemon.MaxHealth / 2 && pokemon.Form.Name == FormNames.Zen) { pokemon.ChangeForm(pokemon.Species.GetDefaultForm()); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/FairyLockEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/FairyLockEffect.cs index 6eebbb7..675394e 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/FairyLockEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/FairyLockEffect.cs @@ -8,14 +8,14 @@ public class FairyLockEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunAw /// public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) { - if (choice.User.Types.All(x => x.Name != "ghost")) + if (choice.User.Types.All(x => x.Name != TypeNames.Ghost)) prevent = true; } /// public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) { - if (choice.User.Types.All(x => x.Name != "ghost")) + if (choice.User.Types.All(x => x.Name != TypeNames.Ghost)) prevent = true; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/Gravity.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/Gravity.cs index 970eee6..464173e 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/Gravity.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/Gravity.cs @@ -12,7 +12,7 @@ public class Gravity : Script, IScriptFailIncomingMove, IScriptOnEndTurn, IScrip { var typeLibrary = target.Library.StaticLibrary.Types; - if (executingMove.UseMove.MoveType.Name != "ground") + if (executingMove.UseMove.MoveType.Name != TypeNames.Ground) return; // Remove all types that are immune to ground moves types.RemoveAll(x => typeLibrary.GetSingleEffectiveness(executingMove.UseMove.MoveType, x) == 0); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/IonDelugeEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/IonDelugeEffect.cs index b8d9397..83d73af 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/IonDelugeEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/IonDelugeEffect.cs @@ -6,8 +6,8 @@ public class IonDelugeEffect : Script, IScriptChangeMoveType, IScriptOnEndTurn /// public void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier? moveType) { - if (moveType?.Name == "normal" && - target.Library.StaticLibrary.Types.TryGetTypeIdentifier("electric", out var electricType)) + if (moveType?.Name == TypeNames.Normal && + target.Library.StaticLibrary.Types.TryGetTypeIdentifier(TypeNames.Electric, out var electricType)) { moveType = electricType; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/MudSportEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/MudSportEffect.cs index 3c284f1..6c1b7fd 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/MudSportEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/MudSportEffect.cs @@ -8,7 +8,7 @@ public class MudSportEffect : Script, IScriptChangeBasePower, IScriptOnEndTurn /// public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower) { - if (move.UseMove.MoveType.Name == "electric") + if (move.UseMove.MoveType.Name == TypeNames.Electric) { basePower = basePower.MultiplyOrMax(1352 / 4096f); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/UproarEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/UproarEffect.cs index 7095ec5..2522f43 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/UproarEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/UproarEffect.cs @@ -32,7 +32,7 @@ public class UproarEffect : Script, IScriptOnBeforeTurnStart, IScriptOnSecondary /// public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { - if (move.User == _placer && move.UseMove.Name == "uproar") + if (move.User == _placer && move.UseMove.Name == MoveNames.Uproar) _hasUsedUproar = true; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/WaterSportEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/WaterSportEffect.cs index 7f25037..c6aee91 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/WaterSportEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/WaterSportEffect.cs @@ -8,7 +8,7 @@ public class WaterSportEffect : Script, IScriptChangeMoveDamage, IScriptOnSwitch /// public void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage) { - if (move.UseMove.MoveType.Name == "fire") + if (move.UseMove.MoveType.Name == TypeNames.Fire) { damage = damage / 2; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/Pokeballs/MoonBall.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/Pokeballs/MoonBall.cs index 6b5d399..5a81f54 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/Pokeballs/MoonBall.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/Pokeballs/MoonBall.cs @@ -17,8 +17,8 @@ public class MoonBall : PokeballScript { switch (x) { - case ItemUseEvolution itemUseEvolution when itemUseEvolution.Item == "moon_ball": - case ItemGenderEvolution itemGenderEvolution when itemGenderEvolution.Item == "moon_ball": + case ItemUseEvolution itemUseEvolution when itemUseEvolution.Item == ItemNames.MoonBall: + case ItemGenderEvolution itemGenderEvolution when itemGenderEvolution.Item == ItemNames.MoonBall: return true; default: return false; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/Pokeballs/NetBall.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/Pokeballs/NetBall.cs index 6c6e740..f2054e6 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/Pokeballs/NetBall.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/Pokeballs/NetBall.cs @@ -8,13 +8,10 @@ public class NetBall : PokeballScript { } - private static readonly StringKey WaterType = "water"; - private static readonly StringKey BugType = "bug"; - /// public override void ChangeCatchRate(IPokemon target, ref byte catchRate) { - if (target.Types.Any(x => x.Name == WaterType || x.Name == BugType)) + if (target.Types.Any(x => x.Name == TypeNames.Water || x.Name == TypeNames.Bug)) { catchRate = catchRate.MultiplyOrMax(3.5f); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Block.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Block.cs index 2365d66..50aca60 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Block.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Block.cs @@ -5,12 +5,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves; [Script(ScriptCategory.Move, "block")] public class Block : Script, IScriptOnSecondaryEffect { - private static StringKey GhostTypeName => new("ghost"); - /// public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { - if (target.Types.Any(x => x.Name == GhostTypeName)) + if (target.Types.Any(x => x.Name == TypeNames.Ghost)) return; target.Volatile.Add(new BlockEffect()); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Bounce.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Bounce.cs index 94f6a1f..8efaa55 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Bounce.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Bounce.cs @@ -35,7 +35,7 @@ public class Bounce : Script, IScriptPreventMove, IScriptOnBeforeMove, IScriptOn var random = battle.Random; if (random.EffectChance(30, move, target, hit)) { - target.SetStatus("paralyzed", move.User); + target.SetStatus(ScriptUtils.ResolveName(), move.User); } } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/BurnUp.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/BurnUp.cs index e1a8189..c9f5142 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/BurnUp.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/BurnUp.cs @@ -10,7 +10,7 @@ public class BurnUp : Script, IScriptOnSecondaryEffect if (battleData == null) return; var typeLibrary = battleData.Battle.Library.StaticLibrary.Types; - if (!typeLibrary.TryGetTypeIdentifier("fire", out var fireType)) + if (!typeLibrary.TryGetTypeIdentifier(TypeNames.Fire, out var fireType)) return; if (!move.User.Types.Contains(fireType)) { @@ -18,7 +18,7 @@ public class BurnUp : Script, IScriptOnSecondaryEffect return; } - if (move.User.HasStatus("frozen")) + if (move.User.HasStatus(ScriptUtils.ResolveName())) move.User.ClearStatus(); move.User.RemoveType(fireType); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Camouflage.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Camouflage.cs index 93dfd62..5b62491 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Camouflage.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Camouflage.cs @@ -20,23 +20,23 @@ public class Camouflage : Script, IScriptOnSecondaryEffect var environmentCategory = battle.GetEnvironmentCategory(); return environmentCategory switch { - EnvironmentHelper.EnvironmentCategory.Electric when typesLibrary.TryGetTypeIdentifier("electric", + EnvironmentHelper.EnvironmentCategory.Electric when typesLibrary.TryGetTypeIdentifier(TypeNames.Electric, out var electricType) => electricType, - EnvironmentHelper.EnvironmentCategory.Fairy when typesLibrary.TryGetTypeIdentifier("fairy", + EnvironmentHelper.EnvironmentCategory.Fairy when typesLibrary.TryGetTypeIdentifier(TypeNames.Fairy, out var fairyType) => fairyType, - EnvironmentHelper.EnvironmentCategory.Grass when typesLibrary.TryGetTypeIdentifier("grass", + EnvironmentHelper.EnvironmentCategory.Grass when typesLibrary.TryGetTypeIdentifier(TypeNames.Grass, out var grassType) => grassType, - EnvironmentHelper.EnvironmentCategory.Psychic when typesLibrary.TryGetTypeIdentifier("psychic", + EnvironmentHelper.EnvironmentCategory.Psychic when typesLibrary.TryGetTypeIdentifier(TypeNames.Psychic, out var psychicType) => psychicType, - EnvironmentHelper.EnvironmentCategory.Rock when typesLibrary.TryGetTypeIdentifier("rock", out var rockType) - => rockType, - EnvironmentHelper.EnvironmentCategory.Ground when typesLibrary.TryGetTypeIdentifier("ground", + EnvironmentHelper.EnvironmentCategory.Rock when typesLibrary.TryGetTypeIdentifier(TypeNames.Rock, + out var rockType) => rockType, + EnvironmentHelper.EnvironmentCategory.Ground when typesLibrary.TryGetTypeIdentifier(TypeNames.Ground, out var groundType) => groundType, - EnvironmentHelper.EnvironmentCategory.Ice when typesLibrary.TryGetTypeIdentifier("ice", out var iceType) => - iceType, - EnvironmentHelper.EnvironmentCategory.Water when typesLibrary.TryGetTypeIdentifier("water", + EnvironmentHelper.EnvironmentCategory.Ice when typesLibrary.TryGetTypeIdentifier(TypeNames.Ice, + out var iceType) => iceType, + EnvironmentHelper.EnvironmentCategory.Water when typesLibrary.TryGetTypeIdentifier(TypeNames.Water, out var waterType) => waterType, - EnvironmentHelper.EnvironmentCategory.Normal when typesLibrary.TryGetTypeIdentifier("normal", + EnvironmentHelper.EnvironmentCategory.Normal when typesLibrary.TryGetTypeIdentifier(TypeNames.Normal, out var normalType) => normalType, _ => null, }; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Captivate.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Captivate.cs index 72f3f56..96e416f 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Captivate.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Captivate.cs @@ -14,7 +14,7 @@ public class Captivate : Script, IScriptOnSecondaryEffect move.GetHitData(target, hit).Fail(); return; } - if (target.ActiveAbility?.Name == "oblivious") + if (target.ActiveAbility?.Name == AbilityNames.Oblivious) { move.GetHitData(target, hit).Fail(); return; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Conversion2.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Conversion2.cs index 8ff8858..d5125fe 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Conversion2.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Conversion2.cs @@ -3,11 +3,14 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves; [Script(ScriptCategory.Move, "conversion_2")] public class Conversion2 : Script, IScriptOnSecondaryEffect { + // The typeless "none" type is not part of the type data, so no generated constant exists for it. + private static readonly StringKey NoneTypeName = "none"; + /// public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { var lastMoveByTarget = target.BattleData?.LastMoveChoice; - if (lastMoveByTarget == null || lastMoveByTarget.ChosenMove.MoveData.MoveType.Name == "none") + if (lastMoveByTarget == null || lastMoveByTarget.ChosenMove.MoveData.MoveType.Name == NoneTypeName) { move.GetHitData(target, hit).Fail(); return; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Curse.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Curse.cs index e763780..4def1fb 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Curse.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Curse.cs @@ -12,7 +12,7 @@ public class Curse : Script, IScriptOnSecondaryEffect if (battleData == null) return; var typeLibrary = battleData.Battle.Library.StaticLibrary.Types; - if (!typeLibrary.TryGetTypeIdentifier("ghost", out var ghostType)) + if (!typeLibrary.TryGetTypeIdentifier(TypeNames.Ghost, out var ghostType)) return; if (move.User.Types.Contains(ghostType)) { diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Drain.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Drain.cs index 415180f..12981b4 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Drain.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Drain.cs @@ -19,7 +19,7 @@ public class Drain : Script, IScriptOnInitialize, IScriptOnSecondaryEffect var user = move.User; var damage = move.GetHitData(target, hit).Damage; var healed = (uint)(damage * DrainModifier); - if (move.User.HasHeldItem("big_root")) + if (move.User.HasHeldItem(ItemNames.BigRoot)) healed = (uint)(healed * 1.3f); var invert = false; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/DreamEater.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/DreamEater.cs index c8260fb..04e4ab3 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/DreamEater.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/DreamEater.cs @@ -3,13 +3,11 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves; [Script(ScriptCategory.Move, "dream_eater")] public class DreamEater : Script, IScriptOnSecondaryEffect, IScriptBlockOutgoingHit { - private static readonly StringKey AsleepStatus = new("asleep"); - private static readonly StringKey ComatoseAbility = new("comatose"); - /// public void BlockOutgoingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block) { - if (!target.HasStatus(AsleepStatus) && target.ActiveAbility?.Name != ComatoseAbility) + if (!target.HasStatus(ScriptUtils.ResolveName()) && + target.ActiveAbility?.Name != AbilityNames.Comatose) block = true; } @@ -19,7 +17,7 @@ public class DreamEater : Script, IScriptOnSecondaryEffect, IScriptBlockOutgoing var user = move.User; var damage = move.GetHitData(target, hit).Damage; var healed = (uint)(damage * 0.5f); - if (move.User.HasHeldItem("big_root")) + if (move.User.HasHeldItem(ItemNames.BigRoot)) healed = (uint)(healed * 1.3f); var args = new CustomTriggers.ModifyDrainArgs(move, target, hit, damage, healed, false); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FireFang.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FireFang.cs index 2ae5c5e..d7ef08f 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FireFang.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FireFang.cs @@ -14,7 +14,7 @@ public class FireFang : Script, IScriptOnSecondaryEffect var random = battleData.Battle.Random; if (random.EffectChance(10, move, target, hit)) { - target.SetStatus("burned", move.User); + target.SetStatus(ScriptUtils.ResolveName(), move.User); } // It also has an independent 10% chance of causing the target to flinch, if the user attacks before the target. diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FirePledge.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FirePledge.cs index 33f1b4b..99bc675 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FirePledge.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FirePledge.cs @@ -16,18 +16,19 @@ public class FirePledge : Script, IScriptStopBeforeMove var pledgeMove = (IMoveChoice?)move.Battle.ChoiceQueue?.FirstOrDefault(x => x is IMoveChoice mc && mc.User.BattleData?.SideIndex == move.User.BattleData?.SideIndex && - (mc.ChosenMove.MoveData.Name == "water_pledge" || mc.ChosenMove.MoveData.Name == "grass_pledge")); + (mc.ChosenMove.MoveData.Name == MoveNames.WaterPledge || + mc.ChosenMove.MoveData.Name == MoveNames.GrassPledge)); if (pledgeMove is null) return; // If a pledge move is already queued, we stop the current move. stop = true; - if (pledgeMove.ChosenMove.MoveData.Name == "water_pledge") + if (pledgeMove.ChosenMove.MoveData.Name == MoveNames.WaterPledge) { pledgeMove.Volatile.Add(new FireWaterPledgeMove()); } - else if (pledgeMove.ChosenMove.MoveData.Name == "grass_pledge") + else if (pledgeMove.ChosenMove.MoveData.Name == MoveNames.GrassPledge) { pledgeMove.Volatile.Add(new FireGrassPledgeMove()); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlameWheel.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlameWheel.cs index db92c35..727d883 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlameWheel.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlameWheel.cs @@ -19,14 +19,14 @@ public class FlameWheel : Script, IScriptOnInitialize, IScriptOnSecondaryEffect /// public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { - if (move.User.HasStatus("frozen")) + if (move.User.HasStatus(ScriptUtils.ResolveName())) { move.User.ClearStatus(); } if (move.Battle.Random.EffectChance(_burnChance, move, target, hit)) { - target.SetStatus("burned", move.User); + target.SetStatus(ScriptUtils.ResolveName(), move.User); } } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlareBlitz.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlareBlitz.cs index e5719b3..356c4cd 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlareBlitz.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlareBlitz.cs @@ -15,7 +15,7 @@ public class FlareBlitz : Script, IScriptOnSecondaryEffect if (battleData.Battle.Random.EffectChance(10, move, target, hit)) { - target.SetStatus("burned", move.User); + target.SetStatus(ScriptUtils.ResolveName(), move.User); } var triggerArgs = new CustomTriggers.ModifyRecoilArgs(move, target, hit, hitData.Damage, (uint)recoilDamage); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlowerShield.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlowerShield.cs index 4629186..fb3fc80 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlowerShield.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlowerShield.cs @@ -11,7 +11,7 @@ public class FlowerShield : Script, IScriptOnSecondaryEffect var battleData = target.BattleData; if (battleData == null) return; - if (!battleData.Battle.Library.StaticLibrary.Types.TryGetTypeIdentifier("grass", out var grassType)) + if (!battleData.Battle.Library.StaticLibrary.Types.TryGetTypeIdentifier(TypeNames.Grass, out var grassType)) return; var batchId = new EventBatchId(); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlyingPress.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlyingPress.cs index 2214939..39b611f 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlyingPress.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlyingPress.cs @@ -8,7 +8,7 @@ public class FlyingPress : Script, IScriptChangeTypesForMove IList types) { var typeLibrary = executingMove.User.Library.StaticLibrary.Types; - if (!typeLibrary.TryGetTypeIdentifier("flying", out var flyingType)) + if (!typeLibrary.TryGetTypeIdentifier(TypeNames.Flying, out var flyingType)) return; types.Add(flyingType); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/ForestsCurse.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/ForestsCurse.cs index 57b86bf..309a360 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/ForestsCurse.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/ForestsCurse.cs @@ -12,7 +12,7 @@ public class ForestsCurse : Script, IScriptOnSecondaryEffect if (battleData == null) return; var typeLibrary = battleData.Battle.Library.StaticLibrary.Types; - if (!typeLibrary.TryGetTypeIdentifier("grass", out var grassType) || target.Types.Contains(grassType)) + if (!typeLibrary.TryGetTypeIdentifier(TypeNames.Grass, out var grassType) || target.Types.Contains(grassType)) { move.GetHitData(target, hit).Fail(); return; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FreezeDry.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FreezeDry.cs index 8913ad4..6a4f4b2 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FreezeDry.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FreezeDry.cs @@ -11,7 +11,7 @@ public class FreezeDry : Script, IScriptChangeEffectiveness, IScriptOnSecondaryE return; var typeLibrary = battleData.Battle.Library.StaticLibrary.Types; - if (!typeLibrary.TryGetTypeIdentifier("water", out var waterType)) + if (!typeLibrary.TryGetTypeIdentifier(TypeNames.Water, out var waterType)) return; var hitDataType = move.GetHitData(target, hit).Type; @@ -32,7 +32,7 @@ public class FreezeDry : Script, IScriptChangeEffectiveness, IScriptOnSecondaryE if (battleData.Battle.Random.EffectChance(10, move, target, hit)) { - target.SetStatus("frozen", move.User); + target.SetStatus(ScriptUtils.ResolveName(), move.User); } } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FreezeShock.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FreezeShock.cs index 49fa68a..aa06f81 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FreezeShock.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FreezeShock.cs @@ -17,7 +17,7 @@ public class FreezeShock : BaseChargeMove if (battleData.Battle.Random.EffectChance(30, move, target, hit)) { - target.SetStatus("paralyzed", move.User); + target.SetStatus(ScriptUtils.ResolveName(), move.User); } } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FusionBolt.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FusionBolt.cs index 62e4777..606d4d0 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FusionBolt.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FusionBolt.cs @@ -16,7 +16,7 @@ public class FusionBolt : Script, IScriptChangeDamageModifier .OfType().LastOrDefault(x => !x.HasFailed); // If Fusion Flare was used immediately preceding, Fusion Bolt's power is doubled. - if (choice is not null && choice.ChosenMove.MoveData.Name == "fusion_flare") + if (choice is not null && choice.ChosenMove.MoveData.Name == MoveNames.FusionFlare) { modifier *= 2; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FusionFlare.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FusionFlare.cs index 28fa8b6..aa54f29 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FusionFlare.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FusionFlare.cs @@ -16,7 +16,7 @@ public class FusionFlare : Script, IScriptChangeDamageModifier .OfType().LastOrDefault(x => !x.HasFailed); // If Fusion Bolt was used immediately preceding, Fusion Flare's power is doubled. - if (choice is not null && choice.ChosenMove.MoveData.Name == "fusion_bolt") + if (choice is not null && choice.ChosenMove.MoveData.Name == MoveNames.FusionBolt) { modifier *= 2; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/GearUp.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/GearUp.cs index dcc6ddb..d9b1798 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/GearUp.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/GearUp.cs @@ -15,7 +15,7 @@ public class GearUp : Script, IScriptOnSecondaryEffect foreach (var pokemon in side.Pokemon.WhereNotNull()) { var ability = pokemon.ActiveAbility?.Name; - if (ability != "plus" && ability != "minus") + if (ability != AbilityNames.Plus && ability != AbilityNames.Minus) continue; pokemon.ChangeStatBoost(Statistic.Attack, 1, pokemon == move.User, false, evtBatchId); pokemon.ChangeStatBoost(Statistic.SpecialAttack, 1, pokemon == move.User, false, evtBatchId); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/GrassPledge.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/GrassPledge.cs index a59af61..02bd9af 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/GrassPledge.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/GrassPledge.cs @@ -16,18 +16,19 @@ public class GrassPledge : Script, IScriptStopBeforeMove var pledgeMove = (IMoveChoice?)move.Battle.ChoiceQueue?.FirstOrDefault(x => x is IMoveChoice mc && mc.User.BattleData?.SideIndex == move.User.BattleData?.SideIndex && - (mc.ChosenMove.MoveData.Name == "water_pledge" || mc.ChosenMove.MoveData.Name == "fire_pledge")); + (mc.ChosenMove.MoveData.Name == MoveNames.WaterPledge || + mc.ChosenMove.MoveData.Name == MoveNames.FirePledge)); if (pledgeMove is null) return; // If a pledge move is already queued, we stop the current move. stop = true; - if (pledgeMove.ChosenMove.MoveData.Name == "water_pledge") + if (pledgeMove.ChosenMove.MoveData.Name == MoveNames.WaterPledge) { pledgeMove.Volatile.Add(new GrassWaterPledgeMove()); } - else if (pledgeMove.ChosenMove.MoveData.Name == "fire_pledge") + else if (pledgeMove.ChosenMove.MoveData.Name == MoveNames.FirePledge) { pledgeMove.Volatile.Add(new FireGrassPledgeMove()); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/HealBell.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/HealBell.cs index 385c54e..cf3c12d 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/HealBell.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/HealBell.cs @@ -14,7 +14,7 @@ public class HealBell : Script, IScriptOnSecondaryEffect foreach (var pokemon in party.Party.WhereNotNull()) { - if (pokemon.BattleData?.IsOnBattlefield == true && pokemon.ActiveAbility?.Name == "soundproof") + if (pokemon.BattleData?.IsOnBattlefield == true && pokemon.ActiveAbility?.Name == AbilityNames.Soundproof) continue; pokemon.ClearStatus(); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Hex.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Hex.cs index 144e4c2..f614161 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Hex.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Hex.cs @@ -6,7 +6,7 @@ public class Hex : Script, IScriptChangeBasePower /// public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower) { - if (!target.StatusScript.IsEmpty || target.ActiveAbility?.Name == "comatose") + if (!target.StatusScript.IsEmpty || target.ActiveAbility?.Name == AbilityNames.Comatose) { basePower = basePower.MultiplyOrMax(2); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/HyperspaceFury.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/HyperspaceFury.cs index ff82a28..8734e3b 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/HyperspaceFury.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/HyperspaceFury.cs @@ -21,12 +21,9 @@ public class HyperspaceFury : Script, IScriptFailMove, IScriptOnSecondaryEffect move.User.ChangeStatBoost(Statistic.Defense, -1, true, false); } - private static StringKey HoopaName = "hoopa"; - private static StringKey UnboundName = "unbound"; - public void FailMove(IExecutingMove move, ref bool fail) { - if (move.User.Species.Name != HoopaName || move.User.Form.Name != UnboundName) + if (move.User.Species.Name != SpeciesNames.Hoopa || move.User.Form.Name != FormNames.Unbound) { fail = true; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/IceBurn.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/IceBurn.cs index 8e01b24..e049dab 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/IceBurn.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/IceBurn.cs @@ -17,7 +17,7 @@ public class IceBurn : BaseChargeMove if (battleData.Battle.Random.EffectChance(30, move, target, hit)) { - target.SetStatus("burned", move.User); + target.SetStatus(ScriptUtils.ResolveName(), move.User); } } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/IceFang.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/IceFang.cs index 372f11c..7f01f87 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/IceFang.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/IceFang.cs @@ -14,7 +14,7 @@ public class IceFang : Script, IScriptOnSecondaryEffect var random = battleData.Battle.Random; if (random.EffectChance(10, move, target, hit)) { - target.SetStatus("frozen", move.User); + target.SetStatus(ScriptUtils.ResolveName(), move.User); } // It also has an independent 10% chance of causing the target to flinch, if the user attacks before the target. diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Judgement.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Judgement.cs index eb101da..5472a31 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Judgement.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Judgement.cs @@ -5,6 +5,27 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves; [Script(ScriptCategory.Move, "judgement")] public class Judgement : Script, IScriptChangeMoveType { + private static readonly Dictionary PlateTypes = new() + { + { ItemNames.DreadPlate, TypeNames.Dark }, + { ItemNames.EarthPlate, TypeNames.Ground }, + { ItemNames.FistPlate, TypeNames.Fighting }, + { ItemNames.FlamePlate, TypeNames.Fire }, + { ItemNames.IciclePlate, TypeNames.Ice }, + { ItemNames.InsectPlate, TypeNames.Bug }, + { ItemNames.IronPlate, TypeNames.Steel }, + { ItemNames.MeadowPlate, TypeNames.Grass }, + { ItemNames.MindPlate, TypeNames.Psychic }, + { ItemNames.PixiePlate, TypeNames.Fairy }, + { ItemNames.SkyPlate, TypeNames.Flying }, + { ItemNames.SpookyPlate, TypeNames.Ghost }, + { ItemNames.StonePlate, TypeNames.Rock }, + { ItemNames.ToxicPlate, TypeNames.Poison }, + { ItemNames.ZapPlate, TypeNames.Electric }, + { ItemNames.DracoPlate, TypeNames.Dragon }, + { ItemNames.SplashPlate, TypeNames.Water }, + }; + /// public void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier? moveType) { @@ -19,26 +40,10 @@ public class Judgement : Script, IScriptChangeMoveType return; var typeLibrary = target.Library.StaticLibrary.Types; - moveType = heldItem.Name.ToString().ToLowerInvariant() switch + if (PlateTypes.TryGetValue(heldItem.Name, out var typeName) && + typeLibrary.TryGetTypeIdentifier(typeName, out var type)) { - "dread_plate" when typeLibrary.TryGetTypeIdentifier("dark", out var dark) => dark, - "earth_plate" when typeLibrary.TryGetTypeIdentifier("ground", out var ground) => ground, - "fist_plate" when typeLibrary.TryGetTypeIdentifier("fighting", out var fighting) => fighting, - "flame_plate" when typeLibrary.TryGetTypeIdentifier("fire", out var fire) => fire, - "icicle_plate" when typeLibrary.TryGetTypeIdentifier("ice", out var ice) => ice, - "insect_plate" when typeLibrary.TryGetTypeIdentifier("bug", out var bug) => bug, - "iron_plate" when typeLibrary.TryGetTypeIdentifier("steel", out var steel) => steel, - "meadow_plate" when typeLibrary.TryGetTypeIdentifier("grass", out var grass) => grass, - "mind_plate" when typeLibrary.TryGetTypeIdentifier("psychic", out var psychic) => psychic, - "pixie_plate" when typeLibrary.TryGetTypeIdentifier("fairy", out var fairy) => fairy, - "sky_plate" when typeLibrary.TryGetTypeIdentifier("flying", out var flying) => flying, - "spooky_plate" when typeLibrary.TryGetTypeIdentifier("ghost", out var ghost) => ghost, - "stone_plate" when typeLibrary.TryGetTypeIdentifier("rock", out var rock) => rock, - "toxic_plate" when typeLibrary.TryGetTypeIdentifier("poison", out var poison) => poison, - "zap_plate" when typeLibrary.TryGetTypeIdentifier("electric", out var electric) => electric, - "draco_plate" when typeLibrary.TryGetTypeIdentifier("dragon", out var dragon) => dragon, - "splash_plate" when typeLibrary.TryGetTypeIdentifier("water", out var water) => water, - _ => moveType, - }; + moveType = type; + } } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/KingsShield.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/KingsShield.cs index 4640a04..dad8af9 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/KingsShield.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/KingsShield.cs @@ -14,7 +14,7 @@ public class KingsShield : ProtectionScript if (move.GetHitData(target, hit).HasFailed) return; // Default form is shield form - if (move.User.Species.Name == "aegislash" && move.User.Form.Name != "default") + if (move.User.Species.Name == SpeciesNames.Aegislash && move.User.Form.Name != FormNames.Default) { move.User.ChangeForm(move.User.Species.GetDefaultForm()); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/LastResort.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/LastResort.cs index 5ee1f5a..95fa4a3 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/LastResort.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/LastResort.cs @@ -12,7 +12,7 @@ public class LastResort : Script, IScriptPreventMoveSelection prevent = true; return; } - var userMoves = choice.User.Moves.WhereNotNull().Where(x => x.MoveData.Name != "last_resort").ToList(); + var userMoves = choice.User.Moves.WhereNotNull().Where(x => x.MoveData.Name != MoveNames.LastResort).ToList(); if (userMoves.Count == 0) { prevent = true; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/LeechSeed.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/LeechSeed.cs index 5745689..3136ed4 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/LeechSeed.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/LeechSeed.cs @@ -8,7 +8,7 @@ public class LeechSeed : Script, IScriptOnSecondaryEffect /// public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { - if (target.Types.Any(x => x.Name == "grass")) + if (target.Types.Any(x => x.Name == TypeNames.Grass)) { move.GetHitData(target, hit).Fail(); return; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MagnetRise.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MagnetRise.cs index ebe478e..54e7b81 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MagnetRise.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MagnetRise.cs @@ -9,7 +9,7 @@ public class MagnetRise : Script, IScriptOnSecondaryEffect public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { if (move.User.Volatile.Contains(ScriptUtils.ResolveName()) || - move.User.ActiveAbility?.Name == "levitate" || move.User.Volatile.Contains()) + move.User.ActiveAbility?.Name == AbilityNames.Levitate || move.User.Volatile.Contains()) { move.GetHitData(target, hit).Fail(); return; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MagneticFlux.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MagneticFlux.cs index fdbd0f9..014441f 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MagneticFlux.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MagneticFlux.cs @@ -12,7 +12,7 @@ public class MagneticFlux : Script, IScriptOnSecondaryEffect foreach (var pokemon in battleData.BattleSide.Pokemon.WhereNotNull()) { - if (pokemon.ActiveAbility?.Name != "plus" && pokemon.ActiveAbility?.Name != "minus") + if (pokemon.ActiveAbility?.Name != AbilityNames.Plus && pokemon.ActiveAbility?.Name != AbilityNames.Minus) continue; EventBatchId batch = new(); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MeFirst.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MeFirst.cs index b986e2c..fbf4337 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MeFirst.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MeFirst.cs @@ -28,7 +28,8 @@ public class MeFirst : Script, IScriptChangeMove choice.Fail(); return; } - if (!targetMove.ChosenMove.MoveData.CanCopyMove() || targetMove.ChosenMove.MoveData.Name == "metal_burst" || + if (!targetMove.ChosenMove.MoveData.CanCopyMove() || + targetMove.ChosenMove.MoveData.Name == MoveNames.MetalBurst || battleData.Battle.Library.MiscLibrary.IsReplacementChoice(targetMove)) { choice.Fail(); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MeanLook.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MeanLook.cs index 417d39b..eee993c 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MeanLook.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MeanLook.cs @@ -5,12 +5,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves; [Script(ScriptCategory.Move, "mean_look")] public class MeanLook : Script, IScriptOnSecondaryEffect { - private static StringKey GhostTypeName => new("ghost"); - /// public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { - if (target.Types.Any(x => x.Name == GhostTypeName)) + if (target.Types.Any(x => x.Name == TypeNames.Ghost)) return; var targetEffect = target.Volatile.Add(new MeanLookEffectTarget()); if (targetEffect == null) diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MultiAttack.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MultiAttack.cs index f5f8cba..4af9a72 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MultiAttack.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MultiAttack.cs @@ -8,7 +8,7 @@ public class MultiAttack : Script, IScriptChangeMoveType /// public void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier? moveType) { - if (move.User.ActiveAbility?.Name == "klutz") + if (move.User.ActiveAbility?.Name == AbilityNames.Klutz) return; if (move.Battle.Volatile.Contains()) return; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/NaturePower.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/NaturePower.cs index cdc51d6..00f5087 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/NaturePower.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/NaturePower.cs @@ -26,24 +26,24 @@ public class NaturePower : Script, IScriptChangeMove var environmentCategory = battle.GetEnvironmentCategory(); var moveName = environmentCategory switch { - EnvironmentHelper.EnvironmentCategory.Electric when movesLibrary.TryGet("thunderbolt", + EnvironmentHelper.EnvironmentCategory.Electric when movesLibrary.TryGet(MoveNames.Thunderbolt, out var thunderboltMove) => (StringKey?)thunderboltMove.Name, - EnvironmentHelper.EnvironmentCategory.Fairy when movesLibrary.TryGet("moonblast", out var moonblastMove) => - moonblastMove.Name, - EnvironmentHelper.EnvironmentCategory.Grass when movesLibrary.TryGet("energy_ball", out var energyballMove) - => energyballMove.Name, - EnvironmentHelper.EnvironmentCategory.Psychic when movesLibrary.TryGet("psychic", out var psychicMove) => - psychicMove.Name, - EnvironmentHelper.EnvironmentCategory.Rock when movesLibrary.TryGet("power_gem", out var rockMove) => + EnvironmentHelper.EnvironmentCategory.Fairy when movesLibrary.TryGet(MoveNames.Moonblast, + out var moonblastMove) => moonblastMove.Name, + EnvironmentHelper.EnvironmentCategory.Grass when movesLibrary.TryGet(MoveNames.EnergyBall, + out var energyballMove) => energyballMove.Name, + EnvironmentHelper.EnvironmentCategory.Psychic when movesLibrary.TryGet(MoveNames.Psychic, + out var psychicMove) => psychicMove.Name, + EnvironmentHelper.EnvironmentCategory.Rock when movesLibrary.TryGet(MoveNames.PowerGem, out var rockMove) => rockMove.Name, - EnvironmentHelper.EnvironmentCategory.Ground when movesLibrary.TryGet("earth_power", out var groundMove) => - groundMove.Name, - EnvironmentHelper.EnvironmentCategory.Ice when movesLibrary.TryGet("ice_beam", out var iceMove) => iceMove - .Name, - EnvironmentHelper.EnvironmentCategory.Water when movesLibrary.TryGet("hydro_pump", out var waterMove) => - waterMove.Name, - EnvironmentHelper.EnvironmentCategory.Normal when movesLibrary.TryGet("tri_attack", out var normalMove) => - normalMove.Name, + EnvironmentHelper.EnvironmentCategory.Ground when movesLibrary.TryGet(MoveNames.EarthPower, + out var groundMove) => groundMove.Name, + EnvironmentHelper.EnvironmentCategory.Ice when movesLibrary.TryGet(MoveNames.IceBeam, out var iceMove) => + iceMove.Name, + EnvironmentHelper.EnvironmentCategory.Water when movesLibrary.TryGet(MoveNames.HydroPump, out var waterMove) + => waterMove.Name, + EnvironmentHelper.EnvironmentCategory.Normal when movesLibrary.TryGet(MoveNames.TriAttack, + out var normalMove) => normalMove.Name, _ => null, }; return moveName; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Refresh.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Refresh.cs index 1c9847e..0cdb450 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Refresh.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Refresh.cs @@ -1,23 +1,27 @@ +using PkmnLib.Plugin.Gen7.Scripts.Status; + namespace PkmnLib.Plugin.Gen7.Scripts.Moves; [Script(ScriptCategory.Move, "refresh")] public class Refresh : Script, IScriptOnSecondaryEffect { + private static readonly StringKey[] CurableStatuses = + [ + ScriptUtils.ResolveName(), ScriptUtils.ResolveName(), + ScriptUtils.ResolveName(), ScriptUtils.ResolveName(), + ]; + /// public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { var userStatus = move.User.StatusScript; - switch (userStatus.Script?.Name) + if (userStatus.Script is { } statusScript && CurableStatuses.Contains(statusScript.Name)) { - case "paralyzed": - case "burned": - case "poisoned": - case "badly_poisoned": - move.User.ClearStatus(); - break; - default: - move.GetHitData(target, hit).Fail(); - break; + move.User.ClearStatus(); + } + else + { + move.GetHitData(target, hit).Fail(); } } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Rototiller.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Rototiller.cs index f08a55c..ba448bf 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Rototiller.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Rototiller.cs @@ -7,7 +7,7 @@ public class Rototiller : Script, IScriptOnSecondaryEffect public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { var pokemon = move.Battle.Sides.SelectMany(x => x.Pokemon).WhereNotNull() - .Where(x => x.Types.Any(y => y.Name == "grass")); + .Where(x => x.Types.Any(y => y.Name == TypeNames.Grass)); EventBatchId batchId = new(); foreach (var pkmn in pokemon) { diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Round.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Round.cs index 8954af0..5b0624c 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Round.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Round.cs @@ -14,8 +14,9 @@ public class Round : Script, IScriptOnAfterMove return; } - var otherRoundMoves = choiceQueue.Where(x => x is IMoveChoice mc && mc.ChosenMove.MoveData.Name == "round") - .Cast().ToList(); + var otherRoundMoves = choiceQueue + .Where(x => x is IMoveChoice mc && mc.ChosenMove.MoveData.Name == MoveNames.Round).Cast() + .ToList(); // We reverse the order here, as we're constantly pushing the choices to the front of the queue. // By reversing the order, we ensure that the first choice is the one that is up next. diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/SimpleBeam.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/SimpleBeam.cs index 12626b1..0ad2537 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/SimpleBeam.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/SimpleBeam.cs @@ -6,7 +6,7 @@ public class SimpleBeam : Script, IScriptOnSecondaryEffect /// public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { - if (!move.Battle.Library.StaticLibrary.Abilities.TryGet("simple", out var simpleAbility)) + if (!move.Battle.Library.StaticLibrary.Abilities.TryGet(AbilityNames.Simple, out var simpleAbility)) { move.GetHitData(target, hit).Fail(); return; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Soak.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Soak.cs index 770250e..96f10c8 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Soak.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Soak.cs @@ -6,7 +6,7 @@ public class Soak : Script, IScriptOnSecondaryEffect /// public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { - if (target.ActiveAbility?.Name == "multitype") + if (target.ActiveAbility?.Name == AbilityNames.Multitype) { move.GetHitData(target, hit).Fail(); return; @@ -14,7 +14,7 @@ public class Soak : Script, IScriptOnSecondaryEffect var typeLibrary = move.Battle.Library.StaticLibrary.Types; // If water type is not found, we can't do anything. - if (!typeLibrary.TryGetTypeIdentifier("water", out var waterType)) + if (!typeLibrary.TryGetTypeIdentifier(TypeNames.Water, out var waterType)) return; target.SetTypes([waterType]); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/TechnoBlast.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/TechnoBlast.cs index 8a33066..15826ce 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/TechnoBlast.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/TechnoBlast.cs @@ -3,6 +3,14 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves; [Script(ScriptCategory.Move, "techno_blast")] public class TechnoBlast : Script, IScriptChangeMoveType { + private static readonly Dictionary DriveTypes = new() + { + { ItemNames.BurnDrive, TypeNames.Fire }, + { ItemNames.ChillDrive, TypeNames.Ice }, + { ItemNames.DouseDrive, TypeNames.Water }, + { ItemNames.ShockDrive, TypeNames.Electric }, + }; + /// public void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier? moveType) { @@ -11,13 +19,10 @@ public class TechnoBlast : Script, IScriptChangeMoveType return; var typeLibrary = target.Library.StaticLibrary.Types; - moveType = heldItem.Name.ToString().ToLowerInvariant() switch + if (DriveTypes.TryGetValue(heldItem.Name, out var typeName) && + typeLibrary.TryGetTypeIdentifier(typeName, out var type)) { - "burn_drive" when typeLibrary.TryGetTypeIdentifier("fire", out var fire) => fire, - "chill_drive" when typeLibrary.TryGetTypeIdentifier("ice", out var ice) => ice, - "douse_drive" when typeLibrary.TryGetTypeIdentifier("water", out var water) => water, - "shock_drive" when typeLibrary.TryGetTypeIdentifier("electric", out var electric) => electric, - _ => moveType, - }; + moveType = type; + } } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/TrickOrTreat.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/TrickOrTreat.cs index d02d98b..8ceecfc 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/TrickOrTreat.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/TrickOrTreat.cs @@ -9,7 +9,7 @@ public class TrickOrTreat : Script, IScriptOnSecondaryEffect public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { var library = move.Battle.Library.StaticLibrary.Types; - if (!library.TryGetTypeIdentifier("ghost", out var ghostType) || target.Types.Contains(ghostType)) + if (!library.TryGetTypeIdentifier(TypeNames.Ghost, out var ghostType) || target.Types.Contains(ghostType)) { move.GetHitData(target, hit).Fail(); return; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/WaterPledge.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/WaterPledge.cs index eb465e7..696d464 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/WaterPledge.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/WaterPledge.cs @@ -16,18 +16,19 @@ public class WaterPledge : Script, IScriptStopBeforeMove var pledgeMove = (IMoveChoice?)move.Battle.ChoiceQueue?.FirstOrDefault(x => x is IMoveChoice mc && mc.User.BattleData?.SideIndex == move.User.BattleData?.SideIndex && - (mc.ChosenMove.MoveData.Name == "grass_pledge" || mc.ChosenMove.MoveData.Name == "fire_pledge")); + (mc.ChosenMove.MoveData.Name == MoveNames.GrassPledge || + mc.ChosenMove.MoveData.Name == MoveNames.FirePledge)); if (pledgeMove is null) return; // If a pledge move is already queued, we stop the current move. stop = true; - if (pledgeMove.ChosenMove.MoveData.Name == "grass_pledge") + if (pledgeMove.ChosenMove.MoveData.Name == MoveNames.GrassPledge) { pledgeMove.Volatile.Add(new GrassWaterPledgeMove()); } - else if (pledgeMove.ChosenMove.MoveData.Name == "fire_pledge") + else if (pledgeMove.ChosenMove.MoveData.Name == MoveNames.FirePledge) { pledgeMove.Volatile.Add(new FireWaterPledgeMove()); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/WeatherBall.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/WeatherBall.cs index 8be8ccc..b4a067a 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/WeatherBall.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/WeatherBall.cs @@ -21,16 +21,16 @@ public class WeatherBall : Script, IScriptChangeMoveType, IScriptChangeBasePower return; if (weather == ScriptUtils.ResolveName() && - typeLibrary.TryGetTypeIdentifier("fire", out var fireType)) + typeLibrary.TryGetTypeIdentifier(TypeNames.Fire, out var fireType)) typeIdentifier = fireType; else if (weather == ScriptUtils.ResolveName() && - typeLibrary.TryGetTypeIdentifier("water", out var waterType)) + typeLibrary.TryGetTypeIdentifier(TypeNames.Water, out var waterType)) typeIdentifier = waterType; else if (weather == ScriptUtils.ResolveName() && - typeLibrary.TryGetTypeIdentifier("ice", out var iceType)) + typeLibrary.TryGetTypeIdentifier(TypeNames.Ice, out var iceType)) typeIdentifier = iceType; else if (weather == ScriptUtils.ResolveName() && - typeLibrary.TryGetTypeIdentifier("rock", out var rockType)) + typeLibrary.TryGetTypeIdentifier(TypeNames.Rock, out var rockType)) typeIdentifier = rockType; } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/WorrySeed.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/WorrySeed.cs index 1fe4ebd..13c779c 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/WorrySeed.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/WorrySeed.cs @@ -7,7 +7,7 @@ public class WorrySeed : Script, IScriptOnSecondaryEffect public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { var abilityLibrary = move.Battle.Library.StaticLibrary.Abilities; - if (!abilityLibrary.TryGet("insomnia", out var ability)) + if (!abilityLibrary.TryGet(AbilityNames.Insomnia, out var ability)) { // Edge case: if the ability is not found, we should not change the ability. return; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/ChargeEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/ChargeEffect.cs index 4720784..20b928b 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/ChargeEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/ChargeEffect.cs @@ -11,7 +11,7 @@ public class ChargeEffect : Script, IScriptChangeDamageModifier, IScriptOnEndTur var library = target.BattleData?.Battle.Library; if (library == null) return; - if (!library.StaticLibrary.Types.TryGetTypeIdentifier("electric", out var electricType)) + if (!library.StaticLibrary.Types.TryGetTypeIdentifier(TypeNames.Electric, out var electricType)) return; if (move.UseMove.MoveType == electricType) modifier *= 2; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/DefenseCurlEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/DefenseCurlEffect.cs index 94fdfa3..7dadff5 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/DefenseCurlEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/DefenseCurlEffect.cs @@ -3,12 +3,9 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon; [Script(ScriptCategory.Pokemon, "defense_curl")] public class DefenseCurlEffect : Script, IScriptChangeBasePower { - private static StringKey RolloutName = "rollout"; - private static StringKey IceBallName = "ice_ball"; - public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower) { - if (move.UseMove.Name == RolloutName || move.UseMove.Name == IceBallName) + if (move.UseMove.Name == MoveNames.Rollout || move.UseMove.Name == MoveNames.IceBall) basePower = basePower.MultiplyOrMax(2); } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FireSpinEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FireSpinEffect.cs index bea3ce4..23afc04 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FireSpinEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FireSpinEffect.cs @@ -12,7 +12,7 @@ public class FireSpinEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunAwa { _owner = owner; _turns = turns; - _modifier = user.HasHeldItem("binding_band") ? 6f : 8f; + _modifier = user.HasHeldItem(ItemNames.BindingBand) ? 6f : 8f; } /// @@ -27,14 +27,14 @@ public class FireSpinEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunAwa /// public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) { - if (choice.User.Types.All(x => x.Name != "ghost")) + if (choice.User.Types.All(x => x.Name != TypeNames.Ghost)) prevent = true; } /// public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) { - if (choice.User.Types.All(x => x.Name != "ghost")) + if (choice.User.Types.All(x => x.Name != TypeNames.Ghost)) prevent = true; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FlashFireEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FlashFireEffect.cs index 9dd1b08..138b444 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FlashFireEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FlashFireEffect.cs @@ -7,7 +7,7 @@ public class FlashFireEffect : Script, IScriptChangeOffensiveStatValue public void ChangeOffensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint defensiveStat, ImmutableStatisticSet targetStats, Statistic stat, ref uint value) { - if (move.GetHitData(target, hit).Type?.Name == "fire") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Fire) { value = value.MultiplyOrMax(1.5f); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FocusPunchEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FocusPunchEffect.cs index 351995f..a1505ef 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FocusPunchEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FocusPunchEffect.cs @@ -10,7 +10,7 @@ public class FocusPunchEffect : Script, IScriptOnIncomingHit /// public void OnIncomingHit(IExecutingMove move, IPokemon target, byte hit) { - if (move.UseMove.SecondaryEffect?.Name == "one_hit_ko") + if (move.UseMove.SecondaryEffect?.Name == MoveEffectNames.OneHitKo) return; WasHit = true; target.BattleData?.Battle.EventHook.Invoke(new DialogEvent("focus_punch_lost_focus", diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/ForesightEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/ForesightEffect.cs index 18231e4..ed867b9 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/ForesightEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/ForesightEffect.cs @@ -11,9 +11,9 @@ public class ForesightEffect : Script, IScriptPreventStatBoostChange, IScriptCha public ForesightEffect(IReadOnlyTypeLibrary typeLibrary) { - typeLibrary.TryGetTypeIdentifier("normal", out _normalType); - typeLibrary.TryGetTypeIdentifier("fighting", out _fightingType); - typeLibrary.TryGetTypeIdentifier("ghost", out _ghostType); + typeLibrary.TryGetTypeIdentifier(TypeNames.Normal, out _normalType); + typeLibrary.TryGetTypeIdentifier(TypeNames.Fighting, out _fightingType); + typeLibrary.TryGetTypeIdentifier(TypeNames.Ghost, out _ghostType); } /// diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FuryCutterEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FuryCutterEffect.cs index be9e449..37ba691 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FuryCutterEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/FuryCutterEffect.cs @@ -8,7 +8,7 @@ public class FuryCutterEffect : Script, IScriptOnBeforeMove /// public void OnBeforeMove(IExecutingMove move) { - if (move.UseMove.Name != "fury_cutter") + if (move.UseMove.Name != MoveNames.FuryCutter) RemoveSelf(); } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/HealEachEndOfTurnEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/HealEachEndOfTurnEffect.cs index 6118944..2997317 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/HealEachEndOfTurnEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/HealEachEndOfTurnEffect.cs @@ -27,7 +27,7 @@ public class HealEachEndOfTurnEffect : Script, IScriptOnEndTurn return; var amount = _pokemon.BoostedStats.Hp * _healPercentage; - if (_pokemon.HasHeldItem("big_root")) + if (_pokemon.HasHeldItem(ItemNames.BigRoot)) amount *= 1.3f; _pokemon.Heal((uint)amount); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/IngrainEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/IngrainEffect.cs index 137885e..4fb590a 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/IngrainEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/IngrainEffect.cs @@ -14,14 +14,14 @@ public class IngrainEffect : Script, IScriptFailIncomingMove, IScriptOnEndTurn, /// public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) { - if (choice.User.Types.All(x => x.Name != "ghost")) + if (choice.User.Types.All(x => x.Name != TypeNames.Ghost)) prevent = true; } /// public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) { - if (choice.User.Types.All(x => x.Name != "ghost")) + if (choice.User.Types.All(x => x.Name != TypeNames.Ghost)) prevent = true; } @@ -35,7 +35,7 @@ public class IngrainEffect : Script, IScriptFailIncomingMove, IScriptOnEndTurn, /// public void FailIncomingMove(IExecutingMove move, IPokemon target, ref bool fail) { - if (move.UseMove.Name == "roar" || move.UseMove.Name == "whirlwind") + if (move.UseMove.Name == MoveNames.Roar || move.UseMove.Name == MoveNames.Whirlwind) { fail = true; } @@ -45,7 +45,7 @@ public class IngrainEffect : Script, IScriptFailIncomingMove, IScriptOnEndTurn, public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex, IList types) { - if (executingMove.UseMove.MoveType.Name == "ground") + if (executingMove.UseMove.MoveType.Name == TypeNames.Ground) { var typeLibrary = target.Library.StaticLibrary.Types; // Remove all types that are immune to ground moves diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/LeechSeedEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/LeechSeedEffect.cs index 6b54c2f..e234630 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/LeechSeedEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/LeechSeedEffect.cs @@ -20,7 +20,7 @@ public class LeechSeedEffect : Script, IScriptOnEndTurn, IAIInfoScriptExpectedEn damage = _owner.CurrentHealth; _owner.Damage(damage, DamageSource.Misc); - if (_owner.ActiveAbility?.Name == "liquid_ooze") + if (_owner.ActiveAbility?.Name == AbilityNames.LiquidOoze) _placer.Damage(damage, DamageSource.Misc); else _placer.Heal(damage); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/MagmaStormEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/MagmaStormEffect.cs index 3704f8d..7b4ee3e 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/MagmaStormEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/MagmaStormEffect.cs @@ -30,14 +30,14 @@ public class MagmaStormEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunA /// public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) { - if (choice.User.Types.All(x => x.Name != "ghost")) + if (choice.User.Types.All(x => x.Name != TypeNames.Ghost)) prevent = true; } /// public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) { - if (choice.User.Types.All(x => x.Name != "ghost")) + if (choice.User.Types.All(x => x.Name != TypeNames.Ghost)) prevent = true; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/MagnetRiseEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/MagnetRiseEffect.cs index bef6fc5..6675233 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/MagnetRiseEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/MagnetRiseEffect.cs @@ -4,14 +4,13 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon; public class MagnetRiseEffect : Script, IScriptChangeEffectiveness, IScriptOnEndTurn { private int _turnsRemaining = 4; - private static readonly StringKey IronBallName = "iron_ball"; /// public void ChangeEffectiveness(IExecutingMove move, IPokemon target, byte hit, ref float effectiveness) { - if (move.User.HasHeldItem(IronBallName)) + if (move.User.HasHeldItem(ItemNames.IronBall)) return; - if (move.UseMove.MoveType.Name == "ground") + if (move.UseMove.MoveType.Name == TypeNames.Ground) { effectiveness = 0.0f; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/MiracleEyeEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/MiracleEyeEffect.cs index 2adcb34..33d29c3 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/MiracleEyeEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/MiracleEyeEffect.cs @@ -15,9 +15,9 @@ public class MiracleEyeEffect : Script, IScriptPreventStatBoostChange, IScriptCh public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex, IList types) { - if (executingMove.UseMove.MoveType.Name != "psychic") + if (executingMove.UseMove.MoveType.Name != TypeNames.Psychic) return; - var darkType = types.FirstOrDefault(x => x.Name == "dark"); + var darkType = types.FirstOrDefault(x => x.Name == TypeNames.Dark); if (darkType == null) return; types.Remove(darkType); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/PowderEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/PowderEffect.cs index 5a35ee3..04f73d6 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/PowderEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/PowderEffect.cs @@ -8,7 +8,7 @@ public class PowderEffect : Script, IScriptBlockOutgoingHit public void BlockOutgoingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block) { var hit = executingMove.GetHitData(target, hitIndex); - if (hit.Type?.Name == "fire") + if (hit.Type?.Name == TypeNames.Fire) { executingMove.User.BattleData?.Battle.EventHook.Invoke(new DialogEvent("powder_explodes", new Dictionary diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/RoostEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/RoostEffect.cs index e06061f..f9e3d79 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/RoostEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/RoostEffect.cs @@ -7,7 +7,7 @@ public class RoostEffect : Script, IScriptOnEndTurn, IScriptChangeTypesForIncomi public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex, IList types) { - types.RemoveAll(x => x.Name == "flying"); + types.RemoveAll(x => x.Name == TypeNames.Flying); } /// diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/SmackDownEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/SmackDownEffect.cs index 7d8e46c..4374bf9 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/SmackDownEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/SmackDownEffect.cs @@ -9,7 +9,7 @@ public class SmackDownEffect : Script, IScriptChangeTypesForIncomingMove, IScrip { var typeLibrary = target.Library.StaticLibrary.Types; - if (executingMove.UseMove.MoveType.Name != "ground") + if (executingMove.UseMove.MoveType.Name != TypeNames.Ground) return; // Remove all types that are immune to ground moves types.RemoveAll(x => typeLibrary.GetSingleEffectiveness(executingMove.UseMove.MoveType, x) == 0); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/TelekinesisEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/TelekinesisEffect.cs index feb0648..5d5e588 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/TelekinesisEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/TelekinesisEffect.cs @@ -21,7 +21,7 @@ public class TelekinesisEffect : Script, IScriptChangeIncomingEffectiveness, ISc public void ChangeIncomingEffectiveness(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref float effectiveness) { - if (executingMove.UseMove.MoveType.Name == "ground") + if (executingMove.UseMove.MoveType.Name == TypeNames.Ground) effectiveness = 0; } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/ThousandArrowsEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/ThousandArrowsEffect.cs index 4bb554b..95c05d2 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/ThousandArrowsEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/ThousandArrowsEffect.cs @@ -13,9 +13,9 @@ public class ThousandArrowsEffect : Script, IScriptChangeTypesForIncomingMove, I public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex, IList types) { - if (executingMove.UseMove.MoveType.Name == "ground") + if (executingMove.UseMove.MoveType.Name == TypeNames.Ground) { - types.RemoveAll(x => x.Name == "flying"); + types.RemoveAll(x => x.Name == TypeNames.Flying); } } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/EchoedVoiceData.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/EchoedVoiceData.cs index b0afc66..4ef3bf5 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/EchoedVoiceData.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/EchoedVoiceData.cs @@ -12,7 +12,7 @@ public class EchoedVoiceData : Script, IScriptOnBeforeMoveChoice, IScriptStack public void OnBeforeMoveChoice(IMoveChoice moveChoice) { - if (moveChoice.ChosenMove.MoveData.Name != "echoed_voice") + if (moveChoice.ChosenMove.MoveData.Name != MoveNames.EchoedVoice) { RemoveSelf(); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/FlowerVeilEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/FlowerVeilEffect.cs index 38e69c9..2cf3c56 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/FlowerVeilEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/FlowerVeilEffect.cs @@ -29,7 +29,7 @@ public class FlowerVeilEffect : Script, IScriptPreventStatBoostChange, IScriptPr if (amount > 0) return; - if (target.Types.All(x => x.Name != "grass")) + if (target.Types.All(x => x.Name != TypeNames.Grass)) return; prevent = true; @@ -40,7 +40,7 @@ public class FlowerVeilEffect : Script, IScriptPreventStatBoostChange, IScriptPr { if (selfInflicted) return; - if (pokemon.Types.All(x => x.Name != "grass")) + if (pokemon.Types.All(x => x.Name != TypeNames.Grass)) return; preventStatus = true; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/SeaOfFireEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/SeaOfFireEffect.cs index aaaf884..6491dfa 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/SeaOfFireEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/SeaOfFireEffect.cs @@ -19,7 +19,7 @@ public class SeaOfFireEffect : Script, IScriptOnEndTurn foreach (var pokemon in side.Pokemon.WhereNotNull()) { - if (pokemon.Types.Any(x => x.Name == "fire")) + if (pokemon.Types.Any(x => x.Name == TypeNames.Fire)) continue; pokemon.Damage(pokemon.MaxHealth / 8, DamageSource.Misc); diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/StealthRockEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/StealthRockEffect.cs index e81b9be..3bb82d3 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/StealthRockEffect.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Side/StealthRockEffect.cs @@ -20,7 +20,7 @@ public class StealthRockEffect : Script, IScriptOnSwitchIn, IAIInfoScriptExpecte { var typeLibrary = pokemon.Library.StaticLibrary.Types; var effectiveness = 1.0f; - if (typeLibrary.TryGetTypeIdentifier("rock", out var rockType)) + if (typeLibrary.TryGetTypeIdentifier(TypeNames.Rock, out var rockType)) { effectiveness = typeLibrary.GetEffectiveness(rockType, pokemon.Types); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Frozen.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Frozen.cs index ccc4321..6372309 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Frozen.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Frozen.cs @@ -18,7 +18,7 @@ public class Frozen : Script, IScriptPreventMove, IScriptOnEndTurn /// public void PreventMove(IExecutingMove move, ref bool prevent) { - if (move.UseMove.MoveType.Name == "fire" || move.UseMove.HasFlag(MoveFlags.Defrost)) + if (move.UseMove.MoveType.Name == TypeNames.Fire || move.UseMove.HasFlag(MoveFlags.Defrost)) { _pokemon?.ClearStatus(); return; diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/ElectricTerrain.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/ElectricTerrain.cs index 8716700..38ecf87 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/ElectricTerrain.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/ElectricTerrain.cs @@ -12,7 +12,7 @@ public class ElectricTerrain : Script, IScriptChangeBasePower, IScriptPreventSta if (!IsAffectedByTerrain(move.User)) return; var type = move.GetHitData(target, hit).Type; - if (type?.Name == "electric") + if (type?.Name == TypeNames.Electric) basePower = basePower.MultiplyOrMax(1.5f); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/GrassyTerrain.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/GrassyTerrain.cs index 578ee42..50df819 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/GrassyTerrain.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/GrassyTerrain.cs @@ -14,7 +14,7 @@ public class GrassyTerrain : Script, IScriptChangeBasePower, IScriptOnEndTurn if (IsAffectedByTerrain(move.User)) { var type = move.GetHitData(target, hit).Type; - if (type?.Name == "grass") + if (type?.Name == TypeNames.Grass) { basePower = basePower.MultiplyOrMax(1.5f); } @@ -25,7 +25,7 @@ public class GrassyTerrain : Script, IScriptChangeBasePower, IScriptOnEndTurn if (IsAffectedByTerrain(target)) { var moveName = move.UseMove.Name; - if (moveName == "bulldoze" || moveName == "earthquake" || moveName == "magnitude") + if (moveName == MoveNames.Bulldoze || moveName == MoveNames.Earthquake || moveName == MoveNames.Magnitude) { basePower /= 2; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/MistyTerrain.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/MistyTerrain.cs index 7db0ca4..dbe1d5d 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/MistyTerrain.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/MistyTerrain.cs @@ -13,7 +13,7 @@ public class MistyTerrain : Script, IScriptChangeBasePower, IScriptPreventStatus { if (!IsAffectedByTerrain(target)) return; - if (move.GetHitData(target, hit).Type?.Name == "dragon") + if (move.GetHitData(target, hit).Type?.Name == TypeNames.Dragon) { basePower /= 2; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/PsychicTerrain.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/PsychicTerrain.cs index 9e7a31d..b394c3c 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/PsychicTerrain.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Terrain/PsychicTerrain.cs @@ -15,7 +15,7 @@ public class PsychicTerrain : Script, IScriptIsInvulnerableToMove, IScriptChange // It boosts the power of Psychic-type moves used by affected Pokémon by 50% (regardless of whether the target of // the move is affected by Psychic Terrain). var type = move.GetHitData(target, hit).Type; - if (type?.Name == "psychic") + if (type?.Name == TypeNames.Psychic) { basePower = basePower.MultiplyOrMax(1.5f); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/DesolateLands.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/DesolateLands.cs index 9bd279a..65d1847 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/DesolateLands.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/DesolateLands.cs @@ -30,7 +30,7 @@ public class DesolateLands : HarshSunlight, IScriptFailMove, IScriptOnSwitchOut, /// public void FailMove(IExecutingMove move, ref bool fail) { - if (move.UseMove.MoveType.Name == "water") + if (move.UseMove.MoveType.Name == TypeNames.Water) fail = true; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Hail.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Hail.cs index 1a4e0f3..3f916de 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Hail.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Hail.cs @@ -17,7 +17,7 @@ public class Hail : Script, ILimitedTurnsScript, IScriptOnEndTurn, IAIInfoScript /// public void OnEndTurn(IScriptSource owner, IBattle battle) { - if (!battle.Library.StaticLibrary.Types.TryGetTypeIdentifier("ice", out var iceType)) + if (!battle.Library.StaticLibrary.Types.TryGetTypeIdentifier(TypeNames.Ice, out var iceType)) { iceType = new TypeIdentifier(255, "non_existent"); } @@ -50,7 +50,7 @@ public class Hail : Script, ILimitedTurnsScript, IScriptOnEndTurn, IAIInfoScript /// public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage) { - if (pokemon.Types.Any(x => x.Name == "ice")) + if (pokemon.Types.Any(x => x.Name == TypeNames.Ice)) return; // Ice types are immune to Hail damage. if (_duration.HasValue) { diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/HarshSunlight.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/HarshSunlight.cs index 3fc9a82..bfb028e 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/HarshSunlight.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/HarshSunlight.cs @@ -30,16 +30,19 @@ public class HarshSunlight : Script, ILimitedTurnsScript, IScriptChangeBasePower } } + // Hydro Steam is not part of the gen 7 data files, so no generated constant exists for it. + private static readonly StringKey HydroSteamName = "hydro_steam"; + /// public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower) { var hitType = move.GetHitData(target, hit).Type; - if (hitType?.Name == "fire" || move.UseMove.Name == "hydro_steam") + if (hitType?.Name == TypeNames.Fire || move.UseMove.Name == HydroSteamName) { // Increase Fire-type move power by 50% in harsh sunlight basePower = (ushort)(basePower * 1.5); } - else if (hitType?.Name == "water") + else if (hitType?.Name == TypeNames.Water) { basePower = (ushort)(basePower * 0.5); } @@ -52,7 +55,7 @@ public class HarshSunlight : Script, ILimitedTurnsScript, IScriptChangeBasePower return; if (args is not CustomTriggers.BypassChargeMoveArgs bypassArgs) return; - if (bypassArgs.Move.UseMove.Name == "solar_beam" || bypassArgs.Move.UseMove.Name == "solar_blade") + if (bypassArgs.Move.UseMove.Name == MoveNames.SolarBeam || bypassArgs.Move.UseMove.Name == MoveNames.SolarBlade) { bypassArgs.Bypass = true; } @@ -70,7 +73,7 @@ public class HarshSunlight : Script, ILimitedTurnsScript, IScriptChangeBasePower /// public void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref int modifiedAccuracy) { - if (executingMove.UseMove.Name == "thunder" || executingMove.UseMove.Name == "hurricane") + if (executingMove.UseMove.Name == MoveNames.Thunder || executingMove.UseMove.Name == MoveNames.Hurricane) { modifiedAccuracy = (int)(modifiedAccuracy * 0.5); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/PrimordialSea.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/PrimordialSea.cs index b33b369..f0475a0 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/PrimordialSea.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/PrimordialSea.cs @@ -29,7 +29,7 @@ public class PrimordialSea : Rain, IScriptFailMove, IScriptOnSwitchOut, IScriptP public void FailMove(IExecutingMove move, ref bool fail) { - if (move.UseMove.MoveType.Name == "fire") + if (move.UseMove.MoveType.Name == TypeNames.Fire) fail = true; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Rain.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Rain.cs index 54d8b4c..132d2a9 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Rain.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Rain.cs @@ -28,25 +28,31 @@ public class Rain : Script, ILimitedTurnsScript, IScriptChangeBasePower, IScript public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower) { var hitType = move.GetHitData(target, hit).Type; - if (hitType?.Name == "water") + if (hitType?.Name == TypeNames.Water) { // Increase Water-type move power by 50% in rain basePower = (ushort)(basePower * 1.5); } - else if (hitType?.Name == "fire") + else if (hitType?.Name == TypeNames.Fire) { // Decrease Fire-type move power by 50% in rain basePower = (ushort)(basePower * 0.5); } } + // These moves are not part of the gen 7 data files, so no generated constants exist for them. + private static readonly StringKey BleakwindStormName = "bleakwind_storm"; + private static readonly StringKey WindboltStormName = "windbolt_storm"; + private static readonly StringKey SandsearStormName = "sandsear_storm"; + /// public void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref int modifiedAccuracy) { - modifiedAccuracy = executingMove.UseMove.Name.ToString() switch + var moveName = executingMove.UseMove.Name; + if (moveName == MoveNames.Thunder || moveName == MoveNames.Hurricane || moveName == BleakwindStormName || + moveName == WindboltStormName || moveName == SandsearStormName) { - "thunder" or "hurricane" or "bleakwind_storm" or "windbolt_storm" or "sandsear_storm" => 1000, - _ => modifiedAccuracy, - }; + modifiedAccuracy = 1000; + } } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Sandstorm.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Sandstorm.cs index c29359c..5feb6a8 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Sandstorm.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Sandstorm.cs @@ -11,7 +11,8 @@ public class Sandstorm : Script, IScriptChangeBasePower, IScriptChangeDefensiveS { if (!pokemon.IsUsable) continue; - if (pokemon.Types.Any(x => x.Name == "rock" || x.Name == "ground" || x.Name == "steel")) + if (pokemon.Types.Any(x => + x.Name == TypeNames.Rock || x.Name == TypeNames.Ground || x.Name == TypeNames.Steel)) { // Rock, Ground, and Steel types are immune to Sandstorm damage. continue; @@ -30,21 +31,21 @@ public class Sandstorm : Script, IScriptChangeBasePower, IScriptChangeDefensiveS public void ChangeDefensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint offensiveStat, ImmutableStatisticSet targetStats, Statistic stat, ref uint value) { - if (stat == Statistic.SpecialDefense && target.Types.Any(x => x.Name == "rock")) + if (stat == Statistic.SpecialDefense && target.Types.Any(x => x.Name == TypeNames.Rock)) value = value.MultiplyOrMax(1.5f); } /// public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower) { - if (move.UseMove.Name == "solar_beam") + if (move.UseMove.Name == MoveNames.SolarBeam) basePower /= 2; } /// public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage) { - if (pokemon.Types.Any(x => x.Name == "rock" || x.Name == "ground" || x.Name == "steel")) + if (pokemon.Types.Any(x => x.Name == TypeNames.Rock || x.Name == TypeNames.Ground || x.Name == TypeNames.Steel)) return; // Rock, Ground, and Steel types are immune to Sandstorm damage. damage += (int)(pokemon.MaxHealth / 16f); } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/StrongWinds.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/StrongWinds.cs index eaab98a..f527fd1 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/StrongWinds.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/StrongWinds.cs @@ -36,7 +36,7 @@ public class StrongWinds : Script, IScriptOnSwitchOut, IScriptChangeTypesForMove public void ChangeTypesForMove(IExecutingMove executingMove, IPokemon target, byte hitIndex, IList types) { - var flyingType = types.FirstOrDefault(x => x.Name == "flying"); + var flyingType = types.FirstOrDefault(x => x.Name == TypeNames.Flying); if (flyingType != null) { var typeLibrary = executingMove.Battle.Library.StaticLibrary.Types;