More moves implemented

This commit is contained in:
2025-02-03 11:40:26 +01:00
parent 0c5ca487d7
commit 51dfc4d07e
40 changed files with 639 additions and 65 deletions

View File

@@ -63,9 +63,9 @@ public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
_ => (uint)floatDamage,
};
executingMove.RunScriptHook(script =>
script.ChangeDamage(executingMove, target, hitNumber, ref damage));
script.ChangeMoveDamage(executingMove, target, hitNumber, ref damage));
target.RunScriptHook(script =>
script.ChangeIncomingDamage(executingMove, target, hitNumber, ref damage));
script.ChangeIncomingMoveDamage(executingMove, target, hitNumber, ref damage));
return damage;
}

View File

@@ -0,0 +1,27 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Battle;
[Script(ScriptCategory.Battle, "fairy_lock")]
public class FairyLockEffect : Script
{
private int _turns = 1;
/// <inheritdoc />
public override void PreventSelfRunAway(IFleeChoice choice, ref bool prevent)
{
prevent = true;
}
/// <inheritdoc />
public override void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent)
{
prevent = true;
}
/// <inheritdoc />
public override void OnEndTurn(IBattle battle)
{
if (_turns <= 0)
RemoveSelf();
_turns--;
}
}

View File

@@ -6,7 +6,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
public class BanefulBunker : ProtectionScript
{
/// <inheritdoc />
protected override ProtectionEffectScript GetEffectScript()
protected override Script GetEffectScript()
{
return new BanefulBunkerEffect();
}

View File

@@ -27,7 +27,7 @@ public class Counter : Script
}
/// <inheritdoc />
public override void ChangeDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
public override void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
var counterHelper = move.User.Volatile.Get<CounterHelperEffect>();
if (counterHelper == null || counterHelper.LastHitBy == null || counterHelper.LastHitBy != target)

View File

@@ -4,7 +4,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
public class DragonRage : Script
{
/// <inheritdoc />
public override void ChangeDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
public override void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
damage = 40;
}

View File

@@ -12,7 +12,7 @@ public class Electrify : Script
if (choiceQueue == null)
return;
if (choiceQueue.Where(x => x is IMoveChoice moveChoice && moveChoice.User == target) is not IMoveChoice choice)
if (choiceQueue.FirstOrDefault(x => x is IMoveChoice moveChoice && moveChoice.User == target) is not IMoveChoice choice)
{
move.GetHitData(target, hit).Fail();
return;

View File

@@ -0,0 +1,13 @@
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "embargo")]
public class Embargo : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
target.Volatile.Add(new EmbargoEffect());
}
}

View File

@@ -0,0 +1,31 @@
using System.Linq;
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "encore")]
public class Encore : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var battle = target.BattleData?.Battle;
if (battle == null)
return;
var currentTurn = battle.ChoiceQueue!.LastRanChoice;
var lastMove = battle.PreviousTurnChoices
.SelectMany(x => x)
.OfType<IMoveChoice>()
.TakeWhile(x => x != currentTurn)
.LastOrDefault(x => x.User == target);
if (lastMove == null)
{
move.GetHitData(target, hit).Fail();
return;
}
var effect = new EncoreEffect(target, lastMove.ChosenMove.MoveData.Name, 3);
target.Volatile.Add(effect);
}
}

View File

@@ -0,0 +1,18 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "endeavor")]
public class Endeavor : Script
{
/// <inheritdoc />
public override void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
var user = move.User;
var userHealth = user.CurrentHealth;
var targetHealth = target.CurrentHealth;
if (userHealth >= targetHealth)
{
return;
}
damage = targetHealth - userHealth;
}
}

View File

@@ -0,0 +1,10 @@
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "endure")]
public class Endure : ProtectionScript
{
/// <inheritdoc />
protected override Script GetEffectScript() => new EndureEffect();
}

View File

@@ -0,0 +1,25 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "entrainment")]
public class Entrainment : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var userAbility = move.User.ActiveAbility;
var targetAbility = target.ActiveAbility;
if (userAbility == targetAbility || userAbility == null)
{
move.GetHitData(target, hit).Fail();
return;
}
if (userAbility.HasFlag("cant_be_copied") || targetAbility?.HasFlag("cant_be_changed") != false)
{
move.GetHitData(target, hit).Fail();
return;
}
target.ChangeAbility(userAbility);
}
}

View File

@@ -0,0 +1,13 @@
using System;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "eruption")]
public class Eruption : Script
{
public override void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref byte basePower)
{
basePower = Math.Max((byte)(150 * move.User.CurrentHealth / move.User.BoostedStats.Hp), (byte)1);
}
}

View File

@@ -0,0 +1,11 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "explosion")]
public class Explosion : Script
{
/// <inheritdoc />
public override void OnAfterHits(IExecutingMove move, IPokemon target)
{
move.User.Damage(move.User.CurrentHealth * 10, DamageSource.Misc);
}
}

View File

@@ -0,0 +1,17 @@
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "facade")]
public class Facade : Script
{
/// <inheritdoc />
public override void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref byte basePower)
{
var status = move.User.StatusScript.Script?.Name;
if (status == "paralyzed" || status == "burned" || status == "poisoned")
{
basePower.MultiplyOrMax(2);
}
}
}

View File

@@ -0,0 +1,14 @@
using PkmnLib.Plugin.Gen7.Scripts.Battle;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "fairy_lock")]
public class FairyLock : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var battle = target.BattleData?.Battle;
battle?.Volatile.Add(new FairyLockEffect());
}
}

View File

@@ -0,0 +1,23 @@
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "fake_out")]
public class FakeOut : Script
{
/// <inheritdoc />
public override void StopBeforeMove(IExecutingMove move, ref bool stop)
{
var battleData = move.User.BattleData;
if (battleData == null)
return;
if (battleData.SwitchInTurn != battleData.Battle.CurrentTurnNumber)
stop = true;
}
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
target.Volatile.Add(new FlinchEffect());
}
}

View File

@@ -0,0 +1,14 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "false_swipe")]
public class FalseSwipe : Script
{
/// <inheritdoc />
public override void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
if (target.CurrentHealth - damage < 1)
{
damage = target.CurrentHealth - 1;
}
}
}

View File

@@ -0,0 +1,16 @@
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "fell_stinger")]
public class FellStinger : Script
{
/// <inheritdoc />
public override void OnAfterHits(IExecutingMove move, IPokemon target)
{
if (target.IsFainted)
{
move.User.ChangeStatBoost(Statistic.Attack, 2, true);
}
}
}

View File

@@ -0,0 +1,17 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "final_gambit")]
public class FinalGambit : Script
{
/// <inheritdoc />
public override void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
damage = move.User.CurrentHealth;
}
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
move.User.Damage(move.User.CurrentHealth * 10, DamageSource.Misc);
}
}

View File

@@ -0,0 +1,29 @@
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
public class FireFang : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var battleData = target.BattleData;
if (battleData == null)
return;
var random = battleData.Battle.Random;
if (random.EffectChance(10, move, target, hit))
{
target.SetStatus("burned");
}
// It also has an independent 10% chance of causing the target to flinch, if the user attacks before the target.
var choiceQueue = battleData.Battle.ChoiceQueue;
if (choiceQueue?.FirstOrDefault(x => x.User == target) != null)
{
if (random.EffectChance(10, move, target, hit))
{
target.Volatile.Add(new FlinchEffect());
}
}
}
}

View File

@@ -0,0 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "fire_pledge")]
public class FirePledge : Script
{
// TODO: pledge moves
}

View File

@@ -6,7 +6,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "protect")]
public class ProtectionScript : Script
{
protected virtual ProtectionEffectScript GetEffectScript() => new();
protected virtual Script GetEffectScript() => new ProtectionEffectScript();
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)

View File

@@ -27,7 +27,7 @@ public class ChargeBounceEffect : Script
}
/// <inheritdoc />
public override void ChangeIncomingDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
public override void ChangeIncomingMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
if (!move.UseMove.HasFlag("effective_against_fly"))
damage *= 2;

View File

@@ -26,7 +26,7 @@ public class DigEffect : Script
}
/// <inheritdoc />
public override void ChangeIncomingDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
public override void ChangeIncomingMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
if (!move.UseMove.HasFlag("effective_against_underground"))
damage *= 2;

View File

@@ -26,7 +26,7 @@ public class DiveEffect : Script
}
/// <inheritdoc />
public override void ChangeIncomingDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
public override void ChangeIncomingMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
if (!move.UseMove.HasFlag("effective_against_underwater"))
damage *= 2;

View File

@@ -0,0 +1,31 @@
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "embargo")]
public class EmbargoEffect : Script
{
private int _turns = 5;
/// <inheritdoc />
public override void PreventHeldItemConsume(IPokemon pokemon, IItem heldItem, ref bool prevented)
{
prevented = true;
}
/// <inheritdoc />
public override void Stack()
{
_turns = 5;
}
/// <inheritdoc />
public override void OnEndTurn(IBattle battle)
{
_turns--;
if (_turns == 0)
{
RemoveSelf();
}
}
}

View File

@@ -0,0 +1,42 @@
using PkmnLib.Plugin.Gen7.Scripts.Utils;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "encore")]
public class EncoreEffect : Script
{
private readonly IPokemon _owner;
private readonly StringKey _move;
private int _turns;
public EncoreEffect(IPokemon owner, StringKey move, int turns)
{
_owner = owner;
_move = move;
_turns = turns;
}
/// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice)
{
var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, _move, opposingSideIndex, position);
if (choice is IMoveChoice { ChosenMove.CurrentPp: <= 0 } moveChoice)
{
choice =
moveChoice.User.BattleData?.Battle.Library.MiscLibrary.ReplacementChoice(_owner, opposingSideIndex,
position);
}
}
/// <inheritdoc />
public override void OnEndTurn(IBattle battle)
{
_turns--;
if (_turns <= 0)
{
RemoveSelf();
}
}
}

View File

@@ -0,0 +1,15 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "endure")]
public class EndureEffect : Script
{
/// <inheritdoc />
public override void ChangeIncomingDamage(IPokemon pokemon, DamageSource source, ref uint damage)
{
if (damage > pokemon.CurrentHealth)
damage = pokemon.CurrentHealth - 1;
}
/// <inheritdoc />
public override void OnEndTurn(IBattle battle) => RemoveSelf();
}

View File

@@ -43,7 +43,7 @@ public class AuroraVeilEffect : Script
}
/// <inheritdoc />
public override void ChangeIncomingDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
public override void ChangeIncomingMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
var hitData = move.GetHitData(target, hit);
if (hitData.IsCritical)

View File

@@ -1,11 +1,12 @@
using System;
using System.Linq;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Utils;
public static class TurnChoiceHelper
{
public static IMoveChoice CreateMoveChoice(IPokemon owner, string moveName, byte targetSide, byte targetPosition)
public static IMoveChoice CreateMoveChoice(IPokemon owner, StringKey moveName, byte targetSide, byte targetPosition)
{
var move = owner.Moves.FirstOrDefault(x => x?.MoveData.Name == moveName);
if (move == null)