Files
PkmnLib.NET/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Conversion2.cs
Deukhoofd be5100df8a
All checks were successful
Build / Build (push) Successful in 39s
Implement stat drop handling for AI, Fixes for Conversion2
2026-05-23 12:57:15 +02:00

31 lines
1.2 KiB
C#

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "conversion_2")]
public class Conversion2 : Script, IScriptOnSecondaryEffect
{
/// <inheritdoc />
public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var lastMoveByTarget = target.BattleData?.LastMoveChoice;
if (lastMoveByTarget == null || lastMoveByTarget.ChosenMove.MoveData.MoveType.Name == "none")
{
move.GetHitData(target, hit).Fail();
return;
}
var typeLibrary = move.User.BattleData!.Battle.Library.StaticLibrary.Types;
// Get all types against which the last move would be not very effective
var type = typeLibrary.GetAllEffectivenessFromAttacking(lastMoveByTarget.ChosenMove.MoveData.MoveType)
.Where(x => x.effectiveness < 1)
// Shuffle them randomly, but deterministically
.OrderBy(_ => move.User.BattleData.Battle.Random.GetInt()).ThenBy(x => x.type.Value)
// And grab the first one
.Select(x => x.type).FirstOrDefault();
if (type == null)
{
move.GetHitData(target, hit).Fail();
return;
}
move.User.SetTypes([type]);
}
}