Style cleanup

This commit is contained in:
2025-03-02 17:19:57 +01:00
parent c0bc905c46
commit 284ab3079c
175 changed files with 588 additions and 650 deletions

View File

@@ -18,7 +18,7 @@ public class AfterYou : Script
var queue = move.User.BattleData!.Battle.ChoiceQueue;
if (queue == null)
return;
// If the queue doesn't change, the move fails
if (!queue.MovePokemonChoiceNext(target))
{

View File

@@ -45,11 +45,11 @@ public class AuroraVeil : Script
var numberOfTurns = 5;
var dict = new Dictionary<StringKey, object?>()
{
{ "duration", numberOfTurns }
{ "duration", numberOfTurns },
};
move.User.RunScriptHook(x => x.CustomTrigger(CustomTriggers.AuroraVeilDuration, dict));
numberOfTurns = (int)dict.GetOrDefault("duration", numberOfTurns)!;
var script = side.VolatileScripts.StackOrAdd(ScriptUtils.ResolveName<AuroraVeilEffect>(), () =>
{
var effect = new AuroraVeilEffect(numberOfTurns);

View File

@@ -24,13 +24,12 @@ public class Autotomize : Script
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var user = move.User;
if (user.ChangeStatBoost(Statistic.Speed, 2, true) &&
user.ChangeWeightInKgBy(-100.0f))
if (user.ChangeStatBoost(Statistic.Speed, 2, true) && user.ChangeWeightInKgBy(-100.0f))
{
var battle = user.BattleData?.Battle;
battle?.EventHook.Invoke(new DialogEvent("pokemon_became_nimble", new Dictionary<string, object>()
{
{ "pokemon", user }
{ "pokemon", user },
}));
}
}

View File

@@ -6,8 +6,5 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
public class BanefulBunker : ProtectionScript
{
/// <inheritdoc />
protected override Script GetEffectScript()
{
return new BanefulBunkerEffect();
}
protected override Script GetEffectScript() => new BanefulBunkerEffect();
}

View File

@@ -20,14 +20,14 @@ public class BatonPass : Script
var battleData = user.BattleData;
if (battleData == null)
return;
var statBoosts = user.StatBoost;
var volatileScripts = user.Volatile.Select(x => x.Script).WhereNotNull().ToList();
foreach (var container in user.Volatile)
{
container.ClearWithoutRemoving();
}
var side = battleData.Battle.Sides[battleData.SideIndex];
side.SwapPokemon(battleData.Position, toSwitch);
@@ -36,7 +36,7 @@ public class BatonPass : Script
toSwitch.StatBoost.SetStatistic(stat, statBoosts.GetStatistic(stat));
}
toSwitch.RecalculateBoostedStats();
foreach (var script in volatileScripts)
{
toSwitch.Volatile.Add(script);

View File

@@ -15,7 +15,7 @@ public class BeakBlast : Script
choice.User.Volatile.Add(new BeakBlastEffect());
battleData.Battle.EventHook.Invoke(new DialogEvent("beak_blast_charge", new Dictionary<string, object>()
{
{ "user", choice.User }
{ "user", choice.User },
}));
}

View File

@@ -8,6 +8,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
public class BeatUp : Script
{
private IPokemon[]? _relevantPartyMembers;
private static IEnumerable<IPokemon> GetRelevantPartyMembers(IPokemon user)
{
var battleData = user.BattleData;
@@ -17,12 +18,12 @@ public class BeatUp : Script
var party = battleData.Battle.Parties.FirstOrDefault(x => x.Party.Contains(user));
return party?.Party.WhereNotNull().Where(x => x.IsUsable && x.StatusScript.IsEmpty) ?? [];
}
/// <inheritdoc />
public override void ChangeNumberOfHits(IMoveChoice choice, ref byte numberOfHits)
{
var relevantPartyMembers = _relevantPartyMembers ??= GetRelevantPartyMembers(choice.User).ToArray();
numberOfHits = (byte)relevantPartyMembers.Count();
if (numberOfHits == 0)
numberOfHits = 1;

View File

@@ -12,7 +12,7 @@ public class Belch : Script
var battleData = choice.User.BattleData;
if (battleData == null)
return;
if (battleData.ConsumedItems.All(x => x.Category != ItemCategory.Berry))
prevent = true;
}

View File

@@ -14,7 +14,7 @@ public class BellyDrum : Script
move.GetHitData(target, hit).Fail();
return;
}
target.Damage(maxHealthHalved, DamageSource.Misc);
// Raising the user's Attack by 12 stages should always set it to +6.
target.ChangeStatBoost(Statistic.Attack, 12, true);

View File

@@ -9,13 +9,13 @@ public class Bestow : Script
var user = move.User;
var userHeldItem = user.RemoveHeldItemForBattle();
var targetHeldItem = target.HeldItem;
if (userHeldItem == null || targetHeldItem != null)
{
move.GetHitData(target, hit).Fail();
return;
}
_ = target.SetHeldItem(userHeldItem);
}
}

View File

@@ -9,13 +9,13 @@ public class Bounce : Script
/// <inheritdoc />
public override void PreventMove(IExecutingMove move, ref bool prevent)
{
if (move.User.Volatile.Contains<ChargeBounceEffect>())
if (move.User.Volatile.Contains<ChargeBounceEffect>())
return;
move.User.Volatile.Add(new ChargeBounceEffect(move.User));
move.User.BattleData?.Battle.EventHook.Invoke(new DialogEvent("bounce_charge", new Dictionary<string, object>()
{
{ "user", move.User }
{ "user", move.User },
}));
prevent = true;
}

View File

@@ -12,9 +12,9 @@ public class BugBite : Script
var battleData = user.BattleData;
if (battleData == null)
return;
var targetHeldItem = target.HeldItem;
if (targetHeldItem is not { Category: ItemCategory.Berry })
{
move.GetHitData(target, hit).Fail();

View File

@@ -19,8 +19,8 @@ public class BurnUp : Script
move.GetHitData(target, hit).Fail();
return;
}
if (move.User.HasStatus("frozen"))
if (move.User.HasStatus("frozen"))
move.User.ClearStatus();
move.User.RemoveType(fireType);
}

View File

@@ -9,7 +9,7 @@ namespace PkmnLib.Dynamic.Events;
public class ChangeAllTargetStats : Script
{
private sbyte _amount;
/// <inheritdoc />
public override void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
{

View File

@@ -10,7 +10,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
public class ChangeMultipleUserStatBoosts : Script
{
private Dictionary<Statistic, sbyte> _statBoosts = new();
/// <inheritdoc />
public override void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
{
@@ -21,7 +21,7 @@ public class ChangeMultipleUserStatBoosts : Script
foreach (var par in parameters)
{
if (!Enum.TryParse<Statistic>(par.Key, true, out var stat))
if (!Enum.TryParse<Statistic>(par.Key, true, out var stat))
continue;
if (par.Value is sbyte value)
{
@@ -30,7 +30,6 @@ public class ChangeMultipleUserStatBoosts : Script
}
}
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
@@ -40,4 +39,4 @@ public class ChangeMultipleUserStatBoosts : Script
move.User.ChangeStatBoost(stat.Key, stat.Value, true, batchId);
}
}
}
}

View File

@@ -8,6 +8,6 @@ public class ChipAway : Script
bypass = true;
/// <inheritdoc />
public override void BypassEvasionStatBoosts(IExecutingMove move, IPokemon target, byte hitIndex, ref bool bypass)
=> bypass = true;
public override void
BypassEvasionStatBoosts(IExecutingMove move, IPokemon target, byte hitIndex, ref bool bypass) => bypass = true;
}

View File

@@ -27,8 +27,7 @@ public class Conversion2 : Script
if (indexOfNext == -1)
return x;
return x.Take(indexOfNext);
})
.SelectMany(x => x)
}).SelectMany(x => x)
// We only want the last move choice by the target
.OfType<IMoveChoice>().FirstOrDefault(x => x.User == target);
if (lastMoveByTarget == null)
@@ -42,11 +41,9 @@ public class Conversion2 : Script
var type = typeLibrary.GetAllEffectivenessFromAttacking(lastMoveByTarget.ChosenMove.MoveData.MoveType)
.Where(x => x.effectiveness < 1)
// Shuffle them randomly, but deterministically
.OrderBy(_ => move.User.BattleData.Battle.Random.GetInt())
.ThenBy(x => x.type.Value)
.OrderBy(_ => move.User.BattleData.Battle.Random.GetInt()).ThenBy(x => x.type.Value)
// And grab the first one
.Select(x => x.type)
.FirstOrDefault();
.Select(x => x.type).FirstOrDefault();
if (type == null)
{
move.GetHitData(target, hit).Fail();

View File

@@ -10,9 +10,7 @@ public class Copycat : Script
/// <inheritdoc />
public override void ChangeMove(IMoveChoice choice, ref StringKey moveName)
{
var lastMove = choice.User.BattleData?.Battle.PreviousTurnChoices
.SelectMany(x => x)
.OfType<IMoveChoice>()
var lastMove = choice.User.BattleData?.Battle.PreviousTurnChoices.SelectMany(x => x).OfType<IMoveChoice>()
.LastOrDefault();
if (lastMove == null || !lastMove.ChosenMove.MoveData.CanCopyMove())
{

View File

@@ -14,7 +14,7 @@ public class CoreEnforcer : Script
return;
var turnChoices = battleData.Battle.PreviousTurnChoices.Last();
var currentChoiceIndex = turnChoices.IndexOf(move.MoveChoice);
if (currentChoiceIndex == -1 ||
if (currentChoiceIndex == -1 ||
!turnChoices.Take(currentChoiceIndex).Any(choice => choice is IMoveChoice or IItemChoice))
{
move.GetHitData(target, hit).Fail();

View File

@@ -16,13 +16,13 @@ public class Defog : Script
"toxic_spikes",
"stealth_rock",
};
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
if (target.BattleData == null)
return;
var targetSide = target.BattleData.Battle.Sides[target.BattleData.SideIndex];
foreach (var effect in DefoggedEffects)
{

View File

@@ -9,17 +9,17 @@ public class Dig : Script
/// <inheritdoc />
public override void PreventMove(IExecutingMove move, ref bool prevent)
{
if (move.User.Volatile.Contains<DigEffect>())
if (move.User.Volatile.Contains<DigEffect>())
return;
move.User.Volatile.Add(new DigEffect(move.User));
move.User.BattleData?.Battle.EventHook.Invoke(new DialogEvent("dig_charge", new Dictionary<string, object>()
{
{ "user", move.User }
{ "user", move.User },
}));
prevent = true;
}
/// <inheritdoc />
public override void OnBeforeMove(IExecutingMove move)
{

View File

@@ -13,10 +13,7 @@ public class Disable : Script
if (battleData == null)
return;
var choiceQueue = battleData.Battle.PreviousTurnChoices;
var lastMove = choiceQueue
.SelectMany(x => x)
.OfType<IMoveChoice>()
.LastOrDefault(x => x.User == target);
var lastMove = choiceQueue.SelectMany(x => x).OfType<IMoveChoice>().LastOrDefault(x => x.User == target);
if (lastMove == null)
{
move.GetHitData(target, hit).Fail();

View File

@@ -9,13 +9,13 @@ public class Dive : Script
/// <inheritdoc />
public override void PreventMove(IExecutingMove move, ref bool prevent)
{
if (move.User.Volatile.Contains<DiveEffect>())
if (move.User.Volatile.Contains<DiveEffect>())
return;
move.User.Volatile.Add(new DigEffect(move.User));
move.User.BattleData?.Battle.EventHook.Invoke(new DialogEvent("dive_charge", new Dictionary<string, object>()
{
{ "user", move.User }
{ "user", move.User },
}));
prevent = true;
}

View File

@@ -24,7 +24,7 @@ public class DoublePowerIfTargetDamagedInTurn : Script
var battle = move.User.BattleData?.Battle;
if (battle == null)
return;
if (target.BattleData == null)
if (target.BattleData == null)
return;
var side = battle.Sides[target.BattleData.SideIndex];
var data = side.VolatileScripts.Get<DoublePowerIfTargetDamagedInTurnData>();

View File

@@ -7,7 +7,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
public class Drain : Script
{
public float DrainModifier { get; set; } = 0.5f;
/// <inheritdoc />
public override void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
{

View File

@@ -9,7 +9,7 @@ public class DreamEater : Script
if (!target.HasStatus("asleep"))
block = true;
}
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{

View File

@@ -12,7 +12,8 @@ public class Electrify : Script
if (choiceQueue == null)
return;
if (choiceQueue.FirstOrDefault(x => x is IMoveChoice moveChoice && moveChoice.User == target) is not IMoveChoice choice)
if (choiceQueue.FirstOrDefault(x => x is IMoveChoice moveChoice && moveChoice.User == target) is not IMoveChoice
choice)
{
move.GetHitData(target, hit).Fail();
return;

View File

@@ -9,15 +9,15 @@ public class ElectroBall : Script
var user = move.User;
var targetSpeed = target.BoostedStats.Speed;
var userSpeed = user.BoostedStats.Speed;
var ratio = (float) userSpeed / targetSpeed;
var ratio = (float)userSpeed / targetSpeed;
basePower = ratio switch
{
> 4 => 150,
> 3 => 120,
> 2 => 80,
> 1 => 60,
_ => 40
_ => 40,
};
}
}

View File

@@ -14,17 +14,14 @@ public class Encore : Script
return;
var currentTurn = battle.ChoiceQueue!.LastRanChoice;
var lastMove = battle.PreviousTurnChoices
.SelectMany(x => x)
.OfType<IMoveChoice>()
.TakeWhile(x => x != currentTurn)
.LastOrDefault(x => x.User == target);
var lastMove = battle.PreviousTurnChoices.SelectMany(x => x).OfType<IMoveChoice>()
.TakeWhile(x => x != currentTurn).LastOrDefault(x => x.User == target);
if (lastMove == null)
{
move.GetHitData(target, hit).Fail();
return;
}
var effect = new EncoreEffect(target, lastMove.ChosenMove.MoveData.Name, 3);
target.Volatile.Add(effect);
}

View File

@@ -13,13 +13,13 @@ public class Entrainment : Script
move.GetHitData(target, hit).Fail();
return;
}
if (userAbility.HasFlag("cant_be_copied") || targetAbility?.HasFlag("cant_be_changed") != false)
{
move.GetHitData(target, hit).Fail();
return;
}
target.ChangeAbility(userAbility);
}
}

View File

@@ -9,5 +9,4 @@ public class Eruption : Script
{
basePower = Math.Max((byte)(150 * move.User.CurrentHealth / move.User.BoostedStats.Hp), (byte)1);
}
}

View File

@@ -15,7 +15,7 @@ public class Flail : Script
< 10 => 100,
< 17 => 80,
< 33 => 40,
_ => 20
_ => 20,
};
}
}

View File

@@ -17,7 +17,7 @@ public class FlameBurst : Script
adjacentFoe.Damage(adjacentFoe.BoostedStats.Hp / 16, DamageSource.Misc, batchId);
}
}
private static IEnumerable<IPokemon?> GetAdjacentFoes(IPokemon pokemon)
{
var battleData = pokemon.BattleData;

View File

@@ -14,8 +14,7 @@ public class FlareBlitz : Script
{
target.SetStatus("burned");
}
var hitData = move.GetHitData(target, hit);
var recoilDamage = (uint)(hitData.Damage * (1 / 3));
move.User.Damage(recoilDamage, DamageSource.Misc);

View File

@@ -9,13 +9,13 @@ public class Fly : Script
/// <inheritdoc />
public override void PreventMove(IExecutingMove move, ref bool prevent)
{
if (move.User.Volatile.Contains<ChargeFlyEffect>())
if (move.User.Volatile.Contains<ChargeFlyEffect>())
return;
move.User.Volatile.Add(new ChargeFlyEffect(move.User));
move.User.BattleData?.Battle.EventHook.Invoke(new DialogEvent("fly_charge", new Dictionary<string, object>()
{
{ "user", move.User }
{ "user", move.User },
}));
prevent = true;
}

View File

@@ -13,7 +13,7 @@ public class FocusPunch : Script
choice.User.BattleData?.Battle.EventHook.Invoke(new DialogEvent("focus_punch_charge",
new Dictionary<string, object>()
{
{ "pokemon", choice.User }
{ "pokemon", choice.User },
}));
}

View File

@@ -10,13 +10,13 @@ public class FollowMe : Script
{
if (targets.Count != 1)
return;
var target = targets[0];
if (target == null)
return;
if (target.BattleData?.SideIndex != moveChoice.User.BattleData?.SideIndex)
return;
targets = [moveChoice.User];
}
}

View File

@@ -18,10 +18,8 @@ public class FreezeDry : Script
if (target.Types.Contains(waterType))
{
var effectivenessWithoutWater = target.Types
.Where(x => x != waterType)
.Select(x => typeLibrary.GetEffectiveness(x, target.Types))
.Aggregate(1f, (a, b) => a * b);
var effectivenessWithoutWater = target.Types.Where(x => x != waterType)
.Select(x => typeLibrary.GetEffectiveness(x, target.Types)).Aggregate(1f, (a, b) => a * b);
effectiveness = effectivenessWithoutWater * 2;
}
}

View File

@@ -17,7 +17,7 @@ public class MultiHitMove : Script
< 35 => 2,
< 70 => 3,
< 85 => 4,
_ => 5
_ => 5,
};
numberOfHits = (byte)newHits;
}

View File

@@ -6,7 +6,8 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
public class OneHitKo : Script
{
/// <inheritdoc />
public override void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref int modifiedAccuracy)
public override void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
{
var levelDifference = executingMove.User.Level - target.Level;
if (levelDifference < 0)

View File

@@ -20,7 +20,7 @@ public class ProtectionScript : Script
move.GetHitData(target, hit).Fail();
return;
}
var failure = target.Volatile.Get<ProtectionFailureScript>();
if (failure == null)
{

View File

@@ -8,7 +8,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
public class Recoil : Script
{
private float _recoilPercentage;
/// <inheritdoc />
public override void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
{

View File

@@ -25,7 +25,8 @@ public class Struggle : Script
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var damage = move.User.MaxHealth / 4;
if (damage == 0) damage = 1;
move.User.Damage(damage, DamageSource.Struggle, new());
if (damage == 0)
damage = 1;
move.User.Damage(damage, DamageSource.Struggle, new EventBatchId());
}
}