Imlements baneful bunker, data fixes

This commit is contained in:
2025-01-10 12:55:25 +01:00
parent 6434f9925c
commit 92ab67ddf8
12 changed files with 209 additions and 17 deletions

View File

@@ -0,0 +1,47 @@
using System;
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
public abstract class ProtectionScript : Script
{
protected abstract ProtectionEffectScript GetEffectScript();
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var battleData = target.BattleData;
if (battleData == null)
return;
// If the user goes last in the turn, the move will fail
if (battleData.Battle.ChoiceQueue is not null && !battleData.Battle.ChoiceQueue.HasNext())
{
move.GetHitData(target, hit).Fail();
return;
}
var failure = target.Volatile.Get<ProtectionFailureScript>();
if (failure == null)
{
failure = new ProtectionFailureScript();
target.Volatile.Add(failure);
}
var successive = failure.ProtectTurns;
// Each time, the chance of success is divided by 3.
var chance = 1.0 / Math.Pow(3, successive);
var random = target.BattleData!.Battle.Random.GetFloat();
if (random < chance)
{
failure.ProtectTurns++;
failure.UsedProtect = true;
target.Volatile.Add(GetEffectScript());
}
else
{
move.GetHitData(target, hit).Fail();
}
}
}