Implements an initial version of Baton Pass.
Will probably need some additional work in the future.
This commit is contained in:
parent
92ab67ddf8
commit
0ad692a921
|
@ -1,4 +1,5 @@
|
|||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Dynamic.Models.Choices;
|
||||
|
||||
|
@ -31,6 +32,8 @@ public interface IMoveChoice : ITurnChoice
|
|||
/// The underlying script of the move.
|
||||
/// </summary>
|
||||
ScriptContainer Script { get; set; }
|
||||
|
||||
Dictionary<StringKey, object?>? AdditionalData { get; }
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IMoveChoice"/>
|
||||
|
@ -69,6 +72,9 @@ public class MoveChoice : TurnChoice, IMoveChoice
|
|||
/// <inheritdoc />
|
||||
public ScriptContainer Script { get; set; } = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public Dictionary<StringKey, object?>? AdditionalData { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int ScriptCount => 1 + User.ScriptCount;
|
||||
|
||||
|
|
|
@ -65,4 +65,9 @@ public class ScriptContainer : IEnumerable<ScriptContainer>, IDeepCloneable
|
|||
}
|
||||
Script = null;
|
||||
}
|
||||
|
||||
public void ClearWithoutRemoving()
|
||||
{
|
||||
Script = null;
|
||||
}
|
||||
}
|
|
@ -728,7 +728,10 @@
|
|||
"priority": 0,
|
||||
"target": "Self",
|
||||
"category": "status",
|
||||
"flags": []
|
||||
"flags": [],
|
||||
"effect": {
|
||||
"name": "baton_pass"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "beak_blast",
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue