More moves implemented

This commit is contained in:
2025-03-08 15:48:33 +01:00
parent 77f1ab243b
commit 7f5088b763
15 changed files with 393 additions and 20 deletions

View File

@@ -0,0 +1,17 @@
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Battle;
[Script(ScriptCategory.Move, "ion_deluge")]
public class IonDelugeEffect : Script
{
/// <inheritdoc />
public override void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier moveType)
{
if (moveType.Name == "normal" &&
target.Library.StaticLibrary.Types.TryGetTypeIdentifier("electric", out var electricType))
{
moveType = electricType;
}
}
}

View File

@@ -0,0 +1,13 @@
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "ingrain")]
public class Ingrain : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
move.User.Volatile.Add(new IngrainEffect(move.User));
}
}

View File

@@ -0,0 +1,29 @@
using System.Linq;
using PkmnLib.Dynamic.Models.BattleFlow;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "instruct")]
public class Instruct : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
if (!target.IsUsable)
return;
var battleData = move.User.BattleData;
if (battleData == null)
return;
var lastMoveChoiceByTarget = battleData.Battle.PreviousTurnChoices.SelectMany(x => x)
.SkipWhile(x => x != move.MoveChoice).OfType<MoveChoice>().FirstOrDefault(x => x.User == target);
if (lastMoveChoiceByTarget == null || !battleData.Battle.CanUse(lastMoveChoiceByTarget))
{
move.GetHitData(target, hit).Fail();
return;
}
TurnRunner.ExecuteChoice(battleData.Battle, lastMoveChoiceByTarget);
}
}

View File

@@ -0,0 +1,13 @@
using PkmnLib.Plugin.Gen7.Scripts.Battle;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "ion_deluge")]
public class IonDeluge : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
move.User.BattleData?.Battle.Volatile.Add(new IonDelugeEffect());
}
}

View File

@@ -0,0 +1,38 @@
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "judgement")]
public class Judgement : Script
{
/// <inheritdoc />
public override void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier moveType)
{
var heldItem = move.User.HeldItem;
if (heldItem == null)
return;
var typeLibrary = target.Library.StaticLibrary.Types;
moveType = heldItem.Name.ToString().ToLowerInvariant() switch
{
"dread_plate" when typeLibrary.TryGetTypeIdentifier("dark", out var dark) => dark,
"earth_plate" when typeLibrary.TryGetTypeIdentifier("ground", out var ground) => ground,
"fist_plate" when typeLibrary.TryGetTypeIdentifier("fighting", out var fighting) => fighting,
"flame_plate" when typeLibrary.TryGetTypeIdentifier("fire", out var fire) => fire,
"icicle_plate" when typeLibrary.TryGetTypeIdentifier("ice", out var ice) => ice,
"insect_plate" when typeLibrary.TryGetTypeIdentifier("bug", out var bug) => bug,
"iron_plate" when typeLibrary.TryGetTypeIdentifier("steel", out var steel) => steel,
"meadow_plate" when typeLibrary.TryGetTypeIdentifier("grass", out var grass) => grass,
"mind_plate" when typeLibrary.TryGetTypeIdentifier("psychic", out var psychic) => psychic,
"pixie_plate" when typeLibrary.TryGetTypeIdentifier("fairy", out var fairy) => fairy,
"sky_plate" when typeLibrary.TryGetTypeIdentifier("flying", out var flying) => flying,
"spooky_plate" when typeLibrary.TryGetTypeIdentifier("ghost", out var ghost) => ghost,
"stone_plate" when typeLibrary.TryGetTypeIdentifier("rock", out var rock) => rock,
"toxic_plate" when typeLibrary.TryGetTypeIdentifier("poison", out var poison) => poison,
"zap_plate" when typeLibrary.TryGetTypeIdentifier("electric", out var electric) => electric,
"draco_plate" when typeLibrary.TryGetTypeIdentifier("dragon", out var dragon) => dragon,
"splash_plate" when typeLibrary.TryGetTypeIdentifier("water", out var water) => water,
_ => moveType,
};
}
}

View File

@@ -0,0 +1,16 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "kings_shield")]
public class KingsShield : ProtectionScript
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
base.OnSecondaryEffect(move, target, hit);
// Default form is shield form
if (move.User.Species.Name == "aegislash" && move.User.Form.Name != "default")
{
move.User.ChangeForm(move.User.Species.GetDefaultForm());
}
}
}

View File

@@ -0,0 +1,14 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "knock_off")]
public class KnockOff : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
if (target.RemoveHeldItemForBattle() is null)
{
move.GetHitData(target, hit).Fail();
}
}
}

View File

@@ -0,0 +1,13 @@
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "laser_focus")]
public class LaserFocus : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
target.Volatile.Add(new LaserFocusEffect());
}
}

View File

@@ -0,0 +1,40 @@
using System.Linq;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "last_resort")]
public class LastResort : Script
{
/// <inheritdoc />
public override void PreventMoveSelection(IMoveChoice choice, ref bool prevent)
{
var battleData = choice.User.BattleData;
if (battleData == null)
{
prevent = true;
return;
}
var userMoves = choice.User.Moves.WhereNotNull().Where(x => x.MoveData.Name != "last_resort").ToList();
if (userMoves.Count == 0)
{
prevent = true;
return;
}
// Grab all move choices
var movesForUserSinceEnteringField = battleData.Battle.PreviousTurnChoices
// Reading backwards
.Reverse().SelectMany(x => x.Reverse())
// We only care about move choices since the user entered the field
.TakeWhile(x => x is not SwitchChoice switchChoice || x.User != switchChoice.SwitchTo).OfType<MoveChoice>()
// We only care about the user's move choices
.Where(x => x.User == choice.User)
// Grab the chosen move, and remove duplicates
.Select(x => x.ChosenMove).Distinct().ToList();
if (!userMoves.All(x => movesForUserSinceEnteringField.Contains(x)))
{
prevent = true;
}
}
}

View File

@@ -0,0 +1,56 @@
using System.Linq;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "ingrain")]
public class IngrainEffect : Script
{
private readonly IPokemon _owner;
public IngrainEffect(IPokemon owner)
{
_owner = owner;
}
/// <inheritdoc />
public override void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public override void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public override void OnEndTurn(IBattle battle)
{
var heal = _owner.BoostedStats.Hp / 16;
_owner.Heal(heal);
}
/// <inheritdoc />
public override void FailIncomingMove(IExecutingMove move, IPokemon target, ref bool fail)
{
if (move.UseMove.Name == "roar" || move.UseMove.Name == "whirlwind")
{
fail = true;
}
}
/// <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")
return;
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);
}
}

View File

@@ -0,0 +1,18 @@
using PkmnLib.Static;
using PkmnLib.Static.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "kings_shield")]
public class KingsShield : ProtectionEffectScript
{
/// <inheritdoc />
public override void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
base.BlockIncomingHit(executingMove, target, hitIndex, ref block);
if (executingMove.UseMove.Category != MoveCategory.Status && executingMove.UseMove.HasFlag("contact"))
{
executingMove.User.ChangeStatBoost(Statistic.Accuracy, -2, false);
}
}
}

View File

@@ -0,0 +1,12 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "laser_focus")]
public class LaserFocusEffect : Script
{
/// <inheritdoc />
public override void ChangeCriticalStage(IExecutingMove move, IPokemon target, byte hit, ref byte stage)
{
stage = 100;
RemoveSelf();
}
}