Replace all raw string comparisons with StringKey, source generator that creates cache keys for all names for Gen7 plugin
All checks were successful
Build / Build (push) Successful in 2m21s

This commit is contained in:
2026-08-27 18:30:57 +02:00
parent 3a58f55bbf
commit 942be8eaeb
160 changed files with 1035 additions and 491 deletions

View File

@@ -30,7 +30,7 @@ public class DesolateLands : HarshSunlight, IScriptFailMove, IScriptOnSwitchOut,
/// <inheritdoc />
public void FailMove(IExecutingMove move, ref bool fail)
{
if (move.UseMove.MoveType.Name == "water")
if (move.UseMove.MoveType.Name == TypeNames.Water)
fail = true;
}

View File

@@ -17,7 +17,7 @@ public class Hail : Script, ILimitedTurnsScript, IScriptOnEndTurn, IAIInfoScript
/// <inheritdoc />
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
/// <inheritdoc />
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)
{

View File

@@ -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";
/// <inheritdoc />
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
/// <inheritdoc />
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);
}

View File

@@ -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;
}

View File

@@ -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";
/// <inheritdoc />
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;
}
}
}

View File

@@ -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<uint> 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);
}
/// <inheritdoc />
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;
}
/// <inheritdoc />
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);
}

View File

@@ -36,7 +36,7 @@ public class StrongWinds : Script, IScriptOnSwitchOut, IScriptChangeTypesForMove
public void ChangeTypesForMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> 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;