39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using PkmnLib.Plugin.Gen7.Scripts.Battle;
|
|
using PkmnLib.Plugin.Gen7.Scripts.Side;
|
|
|
|
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
|
|
|
|
[Script(ScriptCategory.Move, "future_sight")]
|
|
public class FutureSight : Script, IScriptStopBeforeMove
|
|
{
|
|
/// <inheritdoc />
|
|
public void StopBeforeMove(IExecutingMove move, ref bool prevent)
|
|
{
|
|
var battleData = move.User.BattleData;
|
|
if (battleData == null)
|
|
return;
|
|
var battle = battleData.Battle;
|
|
var moveChoice = move.MoveChoice;
|
|
|
|
prevent = true;
|
|
|
|
if (IsTargetAlreadySetToBeHit(battle, moveChoice.TargetSide, moveChoice.TargetPosition))
|
|
{
|
|
moveChoice.Fail();
|
|
return;
|
|
}
|
|
|
|
if (battle.Volatile.TryGet<FutureSightEffect>(out var effect))
|
|
effect.AddStrike(moveChoice);
|
|
else
|
|
battle.Volatile.Add(new FutureSightEffect(moveChoice));
|
|
}
|
|
|
|
private static bool IsTargetAlreadySetToBeHit(IBattle battle, byte side, byte position)
|
|
{
|
|
if (battle.Volatile.TryGet<FutureSightEffect>(out var futureSight) && futureSight.HasStrikeAt(side, position))
|
|
return true;
|
|
var doomDesire = battle.Sides[side].VolatileScripts.Get<DoomDesireEffect>();
|
|
return doomDesire != null && doomDesire.HasTarget(position);
|
|
}
|
|
} |