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

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

View File

@@ -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<RainbowEffect>() == 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<Sleep>() &&
if (pokemon.ActiveAbility.Name == AbilityNames.Guts && status != ScriptUtils.ResolveName<Sleep>() &&
status != ScriptUtils.ResolveName<Frozen>() &&
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<Sleep>() &&
if (pokemon.ActiveAbility.Name == AbilityNames.QuickFeet && status != ScriptUtils.ResolveName<Sleep>() &&
status != ScriptUtils.ResolveName<Frozen>() && IsStatRaiseWorthwhile(pokemon, Statistic.Speed, 1, true))
{
return true;
}
if (pokemon.ActiveAbility.Name == "flare_boost" && status == ScriptUtils.ResolveName<Burned>() &&
if (pokemon.ActiveAbility.Name == AbilityNames.FlareBoost && status == ScriptUtils.ResolveName<Burned>() &&
IsStatRaiseWorthwhile(pokemon, Statistic.SpecialAttack, 1, true))
{
return true;
}
if (pokemon.ActiveAbility.Name == "toxic_boost" &&
if (pokemon.ActiveAbility.Name == AbilityNames.ToxicBoost &&
(status == ScriptUtils.ResolveName<Poisoned>() || status == ScriptUtils.ResolveName<BadlyPoisoned>()) &&
IsStatRaiseWorthwhile(pokemon, Statistic.Attack, 1, true))
{
return true;
}
if (pokemon.ActiveAbility.Name == "poison_heal" && status == ScriptUtils.ResolveName<Poisoned>())
if (pokemon.ActiveAbility.Name == AbilityNames.PoisonHeal && status == ScriptUtils.ResolveName<Poisoned>())
{
return true;
}
if (pokemon.ActiveAbility.Name == "magic_guard")
if (pokemon.ActiveAbility.Name == AbilityNames.MagicGuard)
{
if (status != ScriptUtils.ResolveName<Poisoned>() &&
status != ScriptUtils.ResolveName<BadlyPoisoned>() && status != ScriptUtils.ResolveName<Burned>())

View File

@@ -26,8 +26,6 @@ public static class AISwitchFunctions
return effect.Turns <= 1;
}
private static readonly StringKey PoisonHealAbilityName = "poison_heal";
/// <summary>
/// Switch out if the Pokémon is expected to take significant end-of-turn damage.
/// </summary>
@@ -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<StringKey, List<StringKey>> StatusCureAbilities = new()
{
{
ImmunityAbilityName,
AbilityNames.Immunity,
[ScriptUtils.ResolveName<Poisoned>(), ScriptUtils.ResolveName<BadlyPoisoned>()]
},
{ InsomniaAbilityName, [ScriptUtils.ResolveName<Sleep>()] },
{ LimberAbilityName, [ScriptUtils.ResolveName<Paralyzed>()] },
{ MagmaArmorAbilityName, [ScriptUtils.ResolveName<Frozen>()] },
{ VitalSpiritAbilityName, [ScriptUtils.ResolveName<Sleep>()] },
{ WaterBubbleAbilityName, [ScriptUtils.ResolveName<Burned>()] },
{ WaterVeilAbilityName, [ScriptUtils.ResolveName<Burned>()] },
{ AbilityNames.Insomnia, [ScriptUtils.ResolveName<Sleep>()] },
{ AbilityNames.Limber, [ScriptUtils.ResolveName<Paralyzed>()] },
{ AbilityNames.MagmaArmor, [ScriptUtils.ResolveName<Frozen>()] },
{ AbilityNames.VitalSpirit, [ScriptUtils.ResolveName<Sleep>()] },
{ AbilityNames.WaterBubble, [ScriptUtils.ResolveName<Burned>()] },
{ AbilityNames.WaterVeil, [ScriptUtils.ResolveName<Burned>()] },
};
/// <summary>
@@ -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<ToxicSpikesEffect>(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)