34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using PkmnLib.Plugin.Gen7.Scripts.MoveVolatile;
|
|
using PkmnLib.Plugin.Gen7.Scripts.Utils;
|
|
using PkmnLib.Static.Utils;
|
|
|
|
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
|
|
|
|
[Script(ScriptCategory.Move, "sleep_talk")]
|
|
public class SleepTalk : Script
|
|
{
|
|
/// <inheritdoc />
|
|
public override void ChangeMove(IMoveChoice choice, ref StringKey moveName)
|
|
{
|
|
if (!choice.User.HasStatus(ScriptUtils.ResolveName<Status.Sleep>()))
|
|
{
|
|
choice.Fail();
|
|
return;
|
|
}
|
|
var battleData = choice.User.BattleData;
|
|
if (battleData == null)
|
|
return;
|
|
|
|
var moves = choice.User.Moves.WhereNotNull().Where(x => x.MoveData.CanCopyMove())
|
|
.Where(x => x != choice.ChosenMove).OrderBy(_ => battleData.Battle.Random.GetInt()).FirstOrDefault();
|
|
if (moves == null)
|
|
{
|
|
choice.Fail();
|
|
return;
|
|
}
|
|
moveName = moves.MoveData.Name;
|
|
choice.Volatile.Add(new BypassSleepVolatile());
|
|
}
|
|
} |