Implements an initial version of Baton Pass.
Will probably need some additional work in the future.
This commit is contained in:
48
Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/BatonPass.cs
Normal file
48
Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/BatonPass.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
using PkmnLib.Static;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
|
||||
|
||||
[Script(ScriptCategory.Move, "baton_pass")]
|
||||
public class BatonPass : Script
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
|
||||
{
|
||||
var user = move.User;
|
||||
var additionalData = move.MoveChoice.AdditionalData;
|
||||
if (additionalData == null)
|
||||
return;
|
||||
if (additionalData["to_switch"] is not IPokemon toSwitch)
|
||||
return;
|
||||
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);
|
||||
|
||||
foreach (Statistic stat in Enum.GetValues(typeof(Statistic)))
|
||||
{
|
||||
toSwitch.StatBoost.SetStatistic(stat, statBoosts.GetStatistic(stat));
|
||||
}
|
||||
toSwitch.RecalculateBoostedStats();
|
||||
|
||||
foreach (var script in volatileScripts)
|
||||
{
|
||||
toSwitch.Volatile.Add(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user