Support for Bide
This commit is contained in:
parent
ecdc9c7654
commit
83b316ad53
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using PkmnLib.Dynamic.Events;
|
using PkmnLib.Dynamic.Events;
|
||||||
using PkmnLib.Dynamic.Libraries;
|
using PkmnLib.Dynamic.Libraries;
|
||||||
using PkmnLib.Dynamic.Models.BattleFlow;
|
using PkmnLib.Dynamic.Models.BattleFlow;
|
||||||
|
@ -92,6 +93,8 @@ public interface IBattle : IScriptSource, IDeepCloneable
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void ValidateBattleState();
|
void ValidateBattleState();
|
||||||
|
|
||||||
|
bool HasForcedTurn(IPokemon pokemon, [NotNullWhen(true)] out ITurnChoice? choice);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks whether a choice is actually possible.
|
/// Checks whether a choice is actually possible.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -229,11 +232,31 @@ public class BattleImpl : ScriptSource, IBattle
|
||||||
HasEnded = true;
|
HasEnded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool HasForcedTurn(IPokemon pokemon, [NotNullWhen(true)] out ITurnChoice? choice)
|
||||||
|
{
|
||||||
|
var battleData = pokemon.BattleData;
|
||||||
|
if (battleData == null)
|
||||||
|
{
|
||||||
|
choice = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ITurnChoice? forcedChoice = null;
|
||||||
|
pokemon.RunScriptHook(
|
||||||
|
script => script.ForceTurnSelection(battleData.SideIndex, battleData.Position, ref forcedChoice));
|
||||||
|
choice = forcedChoice;
|
||||||
|
return choice != null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool CanUse(ITurnChoice choice)
|
public bool CanUse(ITurnChoice choice)
|
||||||
{
|
{
|
||||||
if (!choice.User.IsUsable)
|
if (!choice.User.IsUsable)
|
||||||
return false;
|
return false;
|
||||||
|
if (HasForcedTurn(choice.User, out var forcedChoice) && choice != forcedChoice)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (choice is IMoveChoice moveChoice)
|
if (choice is IMoveChoice moveChoice)
|
||||||
{
|
{
|
||||||
// TODO: Hook to change number of PP needed.
|
// TODO: Hook to change number of PP needed.
|
||||||
|
|
|
@ -83,6 +83,10 @@ public abstract class Script : IDeepCloneable
|
||||||
public virtual void PreventMoveSelection(IMoveChoice choice, ref bool prevent)
|
public virtual void PreventMoveSelection(IMoveChoice choice, ref bool prevent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This function is ran just before the start of the turn. Everyone has made its choices here,
|
/// This function is ran just before the start of the turn. Everyone has made its choices here,
|
||||||
|
|
|
@ -810,21 +810,27 @@
|
||||||
"flags": [
|
"flags": [
|
||||||
"mirror",
|
"mirror",
|
||||||
"ignore-substitute"
|
"ignore-substitute"
|
||||||
]
|
],
|
||||||
|
"effect": {
|
||||||
|
"name": "bestow"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "bide",
|
"name": "bide",
|
||||||
"type": "normal",
|
"type": "normal",
|
||||||
"power": 0,
|
"power": 0,
|
||||||
"pp": 10,
|
"pp": 10,
|
||||||
"accuracy": 0,
|
"accuracy": 255,
|
||||||
"priority": 1,
|
"priority": 1,
|
||||||
"target": "Self",
|
"target": "Self",
|
||||||
"category": "physical",
|
"category": "physical",
|
||||||
"flags": [
|
"flags": [
|
||||||
"contact",
|
"contact",
|
||||||
"protect"
|
"protect"
|
||||||
]
|
],
|
||||||
|
"effect": {
|
||||||
|
"name": "bide"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "bind",
|
"name": "bind",
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
using PkmnLib.Dynamic.Models;
|
||||||
|
using PkmnLib.Dynamic.ScriptHandling;
|
||||||
|
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||||
|
|
||||||
|
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
|
||||||
|
|
||||||
|
[Script(ScriptCategory.Move, "bestow")]
|
||||||
|
public class Bestow : Script
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
|
||||||
|
{
|
||||||
|
var user = move.User;
|
||||||
|
var userHeldItem = user.HeldItem;
|
||||||
|
var targetHeldItem = target.HeldItem;
|
||||||
|
|
||||||
|
if (userHeldItem == null || targetHeldItem != null)
|
||||||
|
{
|
||||||
|
move.GetHitData(target, hit).Fail();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = target.SetHeldItem(userHeldItem);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
using System.Linq;
|
||||||
|
using PkmnLib.Dynamic.Models;
|
||||||
|
using PkmnLib.Dynamic.ScriptHandling;
|
||||||
|
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||||
|
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
|
||||||
|
|
||||||
|
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
|
||||||
|
|
||||||
|
[Script(ScriptCategory.Move, "bide")]
|
||||||
|
public class Bide : Script
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
|
||||||
|
{
|
||||||
|
var bideEffect = move.User.Volatile.Get<BideEffect>();
|
||||||
|
if (bideEffect == null)
|
||||||
|
{
|
||||||
|
bideEffect = new BideEffect(move.User);
|
||||||
|
move.User.Volatile.Add(bideEffect);
|
||||||
|
}
|
||||||
|
|
||||||
|
bideEffect.Turns += 1;
|
||||||
|
if (bideEffect.Turns < 2)
|
||||||
|
return;
|
||||||
|
var lastPokemon = bideEffect.HitBy.LastOrDefault(x => x.BattleData?.IsOnBattlefield == true);
|
||||||
|
lastPokemon?.Damage(bideEffect.DamageTaken, DamageSource.MoveDamage);
|
||||||
|
|
||||||
|
RemoveSelf();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using PkmnLib.Dynamic.Models;
|
||||||
|
using PkmnLib.Dynamic.Models.Choices;
|
||||||
|
using PkmnLib.Dynamic.ScriptHandling;
|
||||||
|
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||||
|
|
||||||
|
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
|
||||||
|
|
||||||
|
[Script(ScriptCategory.Pokemon, "bide")]
|
||||||
|
public class BideEffect : Script
|
||||||
|
{
|
||||||
|
private readonly IPokemon? _owner;
|
||||||
|
public byte Turns;
|
||||||
|
public uint DamageTaken;
|
||||||
|
public readonly List<IPokemon> HitBy = [];
|
||||||
|
|
||||||
|
private BideEffect()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public BideEffect(IPokemon owner)
|
||||||
|
{
|
||||||
|
_owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void OnIncomingHit(IExecutingMove move, IPokemon target, byte hit)
|
||||||
|
{
|
||||||
|
HitBy.Add(move.User);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void OnDamage(IPokemon pokemon, DamageSource source, uint oldHealth, uint newHealth)
|
||||||
|
{
|
||||||
|
DamageTaken += oldHealth - newHealth;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ITurnChoice? _choice;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice)
|
||||||
|
{
|
||||||
|
if (_owner == null)
|
||||||
|
return;
|
||||||
|
var ownerBattleData = _owner.BattleData;
|
||||||
|
if (ownerBattleData == null)
|
||||||
|
return;
|
||||||
|
if (ownerBattleData.SideIndex != sideIndex || ownerBattleData.Position != position)
|
||||||
|
return;
|
||||||
|
if (_choice != null)
|
||||||
|
{
|
||||||
|
choice = _choice;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bideMove = _owner.Moves.FirstOrDefault(x => x?.MoveData.Name == "bide");
|
||||||
|
if (bideMove == null)
|
||||||
|
{
|
||||||
|
if (!_owner.Library.StaticLibrary.Moves.TryGet("bide", out var moveData))
|
||||||
|
throw new Exception("Move 'bide' not found in move library.");
|
||||||
|
|
||||||
|
bideMove = new LearnedMoveImpl(moveData, MoveLearnMethod.Unknown);
|
||||||
|
}
|
||||||
|
|
||||||
|
choice = _choice = new MoveChoice(_owner, bideMove, sideIndex, position);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue