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

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

View File

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

View File

@@ -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;
}
/// <inheritdoc />
@@ -27,14 +27,14 @@ public class FireSpinEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunAwa
/// <inheritdoc />
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;
}
/// <inheritdoc />
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;
}

View File

@@ -7,7 +7,7 @@ public class FlashFireEffect : Script, IScriptChangeOffensiveStatValue
public void ChangeOffensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint defensiveStat,
ImmutableStatisticSet<uint> 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);
}

View File

@@ -10,7 +10,7 @@ public class FocusPunchEffect : Script, IScriptOnIncomingHit
/// <inheritdoc />
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",

View File

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

View File

@@ -8,7 +8,7 @@ public class FuryCutterEffect : Script, IScriptOnBeforeMove
/// <inheritdoc />
public void OnBeforeMove(IExecutingMove move)
{
if (move.UseMove.Name != "fury_cutter")
if (move.UseMove.Name != MoveNames.FuryCutter)
RemoveSelf();
}
}

View File

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

View File

@@ -14,14 +14,14 @@ public class IngrainEffect : Script, IScriptFailIncomingMove, IScriptOnEndTurn,
/// <inheritdoc />
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;
}
/// <inheritdoc />
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,
/// <inheritdoc />
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<TypeIdentifier> 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

View File

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

View File

@@ -30,14 +30,14 @@ public class MagmaStormEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunA
/// <inheritdoc />
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;
}
/// <inheritdoc />
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;
}

View File

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

View File

@@ -15,9 +15,9 @@ public class MiracleEyeEffect : Script, IScriptPreventStatBoostChange, IScriptCh
public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> 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);

View File

@@ -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<string, object>

View File

@@ -7,7 +7,7 @@ public class RoostEffect : Script, IScriptOnEndTurn, IScriptChangeTypesForIncomi
public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> types)
{
types.RemoveAll(x => x.Name == "flying");
types.RemoveAll(x => x.Name == TypeNames.Flying);
}
/// <inheritdoc />

View File

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

View File

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

View File

@@ -13,9 +13,9 @@ public class ThousandArrowsEffect : Script, IScriptChangeTypesForIncomingMove, I
public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> 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);
}
}
}