Implements more move effects

This commit is contained in:
2025-03-07 16:16:22 +01:00
parent 2c987e32ee
commit a6c73a9c04
15 changed files with 251 additions and 11 deletions

View File

@@ -0,0 +1,35 @@
using System.Linq;
namespace PkmnLib.Plugin.Gen7.Scripts.Battle;
[Script(ScriptCategory.Battle, "gravity")]
public class Gravity : Script
{
/// <inheritdoc />
public override void ChangeEffectiveness(IExecutingMove move, IPokemon target, byte hit, ref float effectiveness)
{
var battleData = target.BattleData;
if (battleData == null)
return;
if (move.UseMove.MoveType.Name == "ground")
{
var targetTypes = target.Types;
var typeLibrary = battleData.Battle.Library.StaticLibrary.Types;
effectiveness =
// Get the effectiveness of the move against each target type
targetTypes.Select(x => typeLibrary.GetSingleEffectiveness(move.UseMove.MoveType, x))
// Ignore all types that are immune to ground moves
.Where(x => x > 0)
// Multiply all effectiveness values together
.Aggregate(1.0f, (current, x) => current * x);
}
}
/// <inheritdoc />
public override void FailIncomingMove(IExecutingMove move, IPokemon target, ref bool fail)
{
if (move.UseMove.HasFlag("gravity"))
fail = true;
}
}

View File

@@ -22,7 +22,7 @@ public class ChangeMultipleUserStatBoosts : Script
foreach (var par in parameters)
{
if (!Enum.TryParse<Statistic>(par.Key, true, out var stat))
continue;
throw new ArgumentException($"Invalid stat name: {par.Key}");
if (par.Value is sbyte value)
{
_statBoosts[stat] = value;

View File

@@ -9,6 +9,6 @@ public class Frustration : Script
public override void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref byte basePower)
{
var friendship = move.User.Happiness;
basePower = Math.Min((byte)1, (byte)((255 - friendship) * 2 / 5));
basePower = Math.Max((byte)1, (byte)((255 - friendship) * 2 / 5));
}
}

View File

@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "gravity")]
public class Gravity : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var battleData = target.BattleData;
if (battleData == null)
return;
battleData.Battle.Volatile.StackOrAdd("gravity", () =>
{
battleData.Battle.Library.ScriptResolver.TryResolve(ScriptCategory.Battle, "gravity",
new Dictionary<StringKey, object?>(), out var script);
return script;
});
foreach (var pokemon in battleData.Battle.Sides.SelectMany(x => x.Pokemon).WhereNotNull())
{
var chargeBounceEffect = ScriptUtils.ResolveName<ChargeBounceEffect>();
if (pokemon.Volatile.Contains(chargeBounceEffect))
pokemon.Volatile.Remove(chargeBounceEffect);
var flyEffect = ScriptUtils.ResolveName<ChargeFlyEffect>();
if (pokemon.Volatile.Contains(flyEffect))
pokemon.Volatile.Remove(flyEffect);
// TODO: Sky Drop
}
}
}

View File

@@ -0,0 +1,19 @@
using System.Collections.Generic;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "grudge")]
public class Grudge : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
move.User.Volatile.StackOrAdd("grudge", () =>
{
move.User.Library.ScriptResolver.TryResolve(ScriptCategory.Pokemon, "grudge",
new Dictionary<StringKey, object?>(), out var script);
return script;
});
}
}

View File

@@ -0,0 +1,27 @@
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "guard_split")]
public class GuardSplit : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var user = move.User;
var userStats = user.FlatStats;
var targetStats = target.FlatStats;
var userDefense = userStats.GetStatistic(Statistic.Defense);
var targetDefense = targetStats.GetStatistic(Statistic.Defense);
var userSpecialDefense = userStats.GetStatistic(Statistic.SpecialDefense);
var targetSpecialDefense = targetStats.GetStatistic(Statistic.SpecialDefense);
var newDefense = (userDefense + targetDefense) / 2;
var newSpecialDefense = (userSpecialDefense + targetSpecialDefense) / 2;
userStats.SetStatistic(Statistic.Defense, newDefense);
userStats.SetStatistic(Statistic.SpecialDefense, newSpecialDefense);
user.RecalculateFlatStats();
}
}

View File

@@ -0,0 +1,29 @@
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "guard_swap")]
public class GuardSwap : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
EventBatchId eventBatchId = new();
var user = move.User;
var userStats = user.StatBoost;
var targetStats = target.StatBoost;
var userDefense = userStats.GetStatistic(Statistic.Defense);
var targetDefense = targetStats.GetStatistic(Statistic.Defense);
var userSpecialDefense = userStats.GetStatistic(Statistic.SpecialDefense);
var targetSpecialDefense = targetStats.GetStatistic(Statistic.SpecialDefense);
user.ChangeStatBoost(Statistic.Defense, (sbyte)(targetDefense - userDefense), true, eventBatchId);
user.ChangeStatBoost(Statistic.SpecialDefense, (sbyte)(targetSpecialDefense - userSpecialDefense), true,
eventBatchId);
target.ChangeStatBoost(Statistic.Defense, (sbyte)(userDefense - targetDefense), false, eventBatchId);
target.ChangeStatBoost(Statistic.SpecialDefense, (sbyte)(userSpecialDefense - targetSpecialDefense), false,
eventBatchId);
}
}

View File

@@ -0,0 +1,12 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "guardian_of_alola")]
public class GuardianOfAlola : Script
{
/// <inheritdoc />
public override void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
var maxHp = target.BoostedStats.Hp;
damage = (uint)(maxHp * (3f / 4f));
}
}

View File

@@ -0,0 +1,13 @@
using System;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "gyro_ball")]
public class GyroBall : Script
{
/// <inheritdoc />
public override void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref byte basePower)
{
basePower = Math.Min((byte)150, (byte)(25 * target.BoostedStats.Speed / move.User.BoostedStats.Speed + 1));
}
}

View File

@@ -0,0 +1,22 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "grudge")]
public class GrudgeEffect : Script
{
private ILearnedMove? _lastMove;
/// <inheritdoc />
public override void OnIncomingHit(IExecutingMove move, IPokemon target, byte hit)
{
_lastMove = move.ChosenMove;
}
/// <inheritdoc />
public override void OnFaint(IPokemon pokemon, DamageSource source)
{
if (_lastMove != null && source == DamageSource.MoveDamage)
{
_lastMove.SetCurrentPP(0);
}
}
}