Surprisingly, more moves

This commit is contained in:
Deukhoofd 2025-04-17 17:51:42 +02:00
parent d02c05874b
commit c22ad1a793
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
17 changed files with 298 additions and 43 deletions

View File

@ -119,6 +119,8 @@ internal static class MoveTurnExecutor
break;
var hitIndex = i;
executingMove.RunScriptHook(x => x.OnBeforeHit(executingMove, target, hitIndex));
var useMove = executingMove.UseMove;
var hitType = useMove.MoveType;
executingMove.RunScriptHook(x => x.ChangeMoveType(executingMove, target, hitIndex, ref hitType));

View File

@ -312,7 +312,7 @@ public abstract class Script : IDeepCloneable
/// This function allows a script to change the actual offensive stat values used when calculating damage
/// </summary>
public virtual void ChangeOffensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint defensiveStat,
ref uint value)
ImmutableStatisticSet<uint> targetStats, ref uint value)
{
}
@ -320,7 +320,7 @@ public abstract class Script : IDeepCloneable
/// This function allows a script to change the actual defensive stat values used when calculating damage.
/// </summary>
public virtual void ChangeDefensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint offensiveStat,
ref uint value)
ImmutableStatisticSet<uint> targetStats, ref uint value)
{
}
@ -610,4 +610,8 @@ public abstract class Script : IDeepCloneable
public virtual void ChangeCategory(IExecutingMove move, IPokemon target, byte hitIndex, ref MoveCategory category)
{
}
public virtual void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
{
}
}

View File

@ -62,13 +62,15 @@ public class ScriptContainer : IReadOnlyScriptContainer
/// <summary>
/// Removes the script from this container.
/// </summary>
public void Clear()
public Script? Clear()
{
if (Script is not null)
{
Script.OnRemove();
}
var script = Script;
Script = null;
return script;
}
public void ClearWithoutRemoving()

View File

@ -83,7 +83,8 @@ public record ImmutableStatisticSet<T> where T : struct
/// A set of statistics that can be changed.
/// </summary>
/// <typeparam name="T"></typeparam>
public record StatisticSet<T> : ImmutableStatisticSet<T>, IEnumerable<T>, IDeepCloneable where T : struct
public record StatisticSet<T> : ImmutableStatisticSet<T>, IEnumerable<(Statistic statistic, T value)>, IDeepCloneable
where T : struct
{
/// <inheritdoc cref="StatisticSet{T}"/>
public StatisticSet() : base(default, default, default, default, default, default)
@ -214,14 +215,14 @@ public record StatisticSet<T> : ImmutableStatisticSet<T>, IEnumerable<T>, IDeepC
}
/// <inheritdoc />
public virtual IEnumerator<T> GetEnumerator()
public virtual IEnumerator<(Statistic, T)> GetEnumerator()
{
yield return Hp;
yield return Attack;
yield return Defense;
yield return SpecialAttack;
yield return SpecialDefense;
yield return Speed;
yield return (Statistic.Hp, Hp);
yield return (Statistic.Attack, Attack);
yield return (Statistic.Defense, Defense);
yield return (Statistic.SpecialAttack, SpecialAttack);
yield return (Statistic.SpecialDefense, SpecialDefense);
yield return (Statistic.Speed, Speed);
}
/// <inheritdoc />
@ -367,16 +368,16 @@ public record StatBoostStatisticSet : ClampedStatisticSet<sbyte>
}
/// <inheritdoc />
public override IEnumerator<sbyte> GetEnumerator()
public override IEnumerator<(Statistic, sbyte)> GetEnumerator()
{
yield return Hp;
yield return Attack;
yield return Defense;
yield return SpecialAttack;
yield return SpecialDefense;
yield return Speed;
yield return Evasion;
yield return Accuracy;
yield return (Statistic.Hp, Hp);
yield return (Statistic.Attack, Attack);
yield return (Statistic.Defense, Defense);
yield return (Statistic.SpecialAttack, SpecialAttack);
yield return (Statistic.SpecialDefense, SpecialDefense);
yield return (Statistic.Speed, Speed);
yield return (Statistic.Evasion, Evasion);
yield return (Statistic.Accuracy, Accuracy);
}
}

View File

@ -8239,7 +8239,10 @@
"flags": [
"protect",
"mirror"
]
],
"effect": {
"name": "present"
}
},
{
"name": "prismatic_laser",
@ -8254,7 +8257,10 @@
"recharge",
"protect",
"mirror"
]
],
"effect": {
"name": "requires_recharge"
}
},
{
"name": "protect",
@ -8265,7 +8271,10 @@
"priority": 4,
"target": "Self",
"category": "status",
"flags": []
"flags": [],
"effect": {
"name": "protect"
}
},
{
"name": "psybeam",
@ -8279,7 +8288,11 @@
"flags": [
"protect",
"mirror"
]
],
"effect": {
"name": "confuse",
"chance": 10
}
},
{
"name": "psych_up",
@ -8292,7 +8305,10 @@
"category": "status",
"flags": [
"ignore-substitute"
]
],
"effect": {
"name": "psych_up"
}
},
{
"name": "psychic",
@ -8306,7 +8322,14 @@
"flags": [
"protect",
"mirror"
]
],
"effect": {
"name": "change_target_special_defense",
"chance": 10,
"parameters": {
"amount": -1
}
}
},
{
"name": "psychic_fangs",
@ -8321,7 +8344,10 @@
"contact",
"protect",
"mirror"
]
],
"effect": {
"name": "brick_break"
}
},
{
"name": "psychic_terrain",
@ -8334,7 +8360,10 @@
"category": "status",
"flags": [
"nonskybattle"
]
],
"effect": {
"name": "psychic_terrain"
}
},
{
"name": "psycho_boost",
@ -8348,7 +8377,13 @@
"flags": [
"protect",
"mirror"
]
],
"effect": {
"name": "change_user_special_attack",
"parameters": {
"amount": -2
}
}
},
{
"name": "psycho_cut",
@ -8362,7 +8397,10 @@
"flags": [
"protect",
"mirror"
]
],
"effect": {
"name": "increased_critical_stage"
}
},
{
"name": "psycho_shift",
@ -8376,7 +8414,10 @@
"flags": [
"protect",
"mirror"
]
],
"effect": {
"name": "psycho_shift"
}
},
{
"name": "psyshock",
@ -8390,7 +8431,10 @@
"flags": [
"protect",
"mirror"
]
],
"effect": {
"name": "psyshock"
}
},
{
"name": "psystrike",
@ -8404,7 +8448,10 @@
"flags": [
"protect",
"mirror"
]
],
"effect": {
"name": "psyshock"
}
},
{
"name": "psywave",
@ -8418,7 +8465,10 @@
"flags": [
"protect",
"mirror"
]
],
"effect": {
"name": "psywave"
}
},
{
"name": "pulverizing_pancake",
@ -8432,6 +8482,7 @@
"flags": [
"contact"
]
// No secondary effect
},
{
"name": "punishment",
@ -8446,7 +8497,10 @@
"contact",
"protect",
"mirror"
]
],
"effect": {
"name": "punishment"
}
},
{
"name": "purify",
@ -8461,7 +8515,10 @@
"protect",
"reflectable",
"heal"
]
],
"effect": {
"name": "purify"
}
},
{
"name": "pursuit",

View File

@ -136,9 +136,10 @@ public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
var origOffensiveStat = offensiveStat;
executingMove.RunScriptHook(script =>
script.ChangeOffensiveStatValue(executingMove, target, hitNumber, defensiveStat, ref offensiveStat));
executingMove.RunScriptHook(script =>
script.ChangeDefensiveStatValue(executingMove, target, hitNumber, origOffensiveStat, ref defensiveStat));
script.ChangeOffensiveStatValue(executingMove, target, hitNumber, defensiveStat, targetStats,
ref offensiveStat));
executingMove.RunScriptHook(script => script.ChangeDefensiveStatValue(executingMove, target, hitNumber,
origOffensiveStat, targetStats, ref defensiveStat));
var modifier = (float)offensiveStat / defensiveStat;
executingMove.RunScriptHook(script =>

View File

@ -18,7 +18,7 @@ public class Acupressure : Script
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
// If the target has no stats to raise, the move fails
if (target.StatBoost.All(s => s == 6))
if (target.StatBoost.All(s => s.value == 6))
{
move.GetHitData(target, hit).Fail();
return;

View File

@ -1,3 +1,4 @@
using PkmnLib.Static;
using PkmnLib.Static.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
@ -7,7 +8,7 @@ public class FoulPlay : Script
{
/// <inheritdoc />
public override void ChangeOffensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint _,
ref uint value)
ImmutableStatisticSet<uint> targetStats, ref uint value)
{
value = move.UseMove.Category == MoveCategory.Physical
? target.BoostedStats.Attack

View File

@ -0,0 +1,57 @@
using PkmnLib.Static.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "present")]
public class Present : Script
{
private bool _isHealing;
private byte _basePower;
/// <inheritdoc />
public override void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
{
var battleRandom = move.User.BattleData?.Battle.Random;
if (battleRandom == null)
return;
var percentRoll = battleRandom.GetFloat() * 100.0;
if (percentRoll < 20.0)
{
_isHealing = true;
_basePower = 0;
}
else
{
_isHealing = false;
_basePower = percentRoll switch
{
< 30 => 120,
< 60 => 80,
_ => 40,
};
}
}
/// <inheritdoc />
public override void ChangeCategory(IExecutingMove move, IPokemon target, byte hitIndex, ref MoveCategory category)
{
if (_isHealing)
category = MoveCategory.Status;
}
/// <inheritdoc />
public override void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref byte basePower)
{
basePower = _basePower;
}
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
if (!_isHealing)
return;
var healAmount = (ushort)(target.MaxHealth / 4);
target.Heal(healAmount);
}
}

View File

@ -0,0 +1,25 @@
using System;
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "psych_up")]
public class PsychUp : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var targetStats = target.StatBoost;
var userStats = move.User.StatBoost;
foreach (Statistic stat in Enum.GetValues(typeof(Statistic)))
{
var targetStat = targetStats.GetStatistic(stat);
var userStat = userStats.GetStatistic(stat);
if (targetStat != userStat)
{
userStats.SetStatistic(stat, targetStat);
}
}
move.User.RecalculateBoostedStats();
}
}

View File

@ -0,0 +1,12 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "psychic_terrain")]
public class PsychicTerrain : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var battleData = move.User.BattleData;
battleData?.Battle.SetTerrain(ScriptUtils.ResolveName<Terrain.PsychicTerrain>());
}
}

View File

@ -0,0 +1,19 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "psycho_shift")]
public class PsychoShift : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var statusScript = move.User.StatusScript;
var targetStatusScript = target.StatusScript;
if (statusScript.IsEmpty || !targetStatusScript.IsEmpty)
{
move.GetHitData(target, hit).Fail();
return;
}
var script = statusScript.Clear();
targetStatusScript.Set(script!);
}
}

View File

@ -0,0 +1,14 @@
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "psyshock")]
public class Psyshock : Script
{
/// <inheritdoc />
public override void ChangeDefensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint offensiveStat,
ImmutableStatisticSet<uint> targetStats, ref uint value)
{
value = targetStats.Defense;
}
}

View File

@ -0,0 +1,19 @@
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "psywave")]
public class Psywave : Script
{
/// <inheritdoc />
public override void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
if (move.User.BattleData == null)
return;
var random = move.User.BattleData.Battle.Random.GetInt(0, 10);
var level = (uint)move.User.Level;
var power = level.MultiplyOrMax(0.5f + 0.1f * random);
damage = power;
}
}

View File

@ -0,0 +1,21 @@
using System.Linq;
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "punishment")]
public class Punishment : Script
{
/// <inheritdoc />
public override void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref byte basePower)
{
if (move.User.BattleData == null)
return;
var totalPower = 60 + 20 * target.StatBoost.Count(x =>
x.statistic is not Statistic.Accuracy and Statistic.Evasion && x.value > 0);
if (totalPower > 200)
totalPower = 200;
basePower = (byte)totalPower;
}
}

View File

@ -0,0 +1,18 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "purify")]
public class Purify : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
if (target.StatusScript.IsEmpty)
{
move.GetHitData(target, hit).Fail();
return;
}
target.ClearStatus();
target.Heal(target.MaxHealth / 2);
}
}

View File

@ -1,3 +1,5 @@
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "power_trick")]
@ -5,14 +7,14 @@ public class PowerTrickEffect : Script
{
/// <inheritdoc />
public override void ChangeOffensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint defensiveStat,
ref uint value)
ImmutableStatisticSet<uint> targetStats, ref uint value)
{
value = defensiveStat;
}
/// <inheritdoc />
public override void ChangeDefensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint offensiveStat,
ref uint value)
ImmutableStatisticSet<uint> targetStats, ref uint value)
{
value = offensiveStat;
}