2022-01-03 05:35:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
2020-11-28 02:45:06 +00:00
|
|
|
|
using static PKHeX.Core.ParseSettings;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Logic to verify the current <see cref="PKM.RelearnMoves"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class VerifyRelearnMoves
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
internal static void DummyValid(CheckMoveResult p) => p.Set(MoveSource.Relearn, 0, Severity.Valid, L_AValid, CheckIdentifier.RelearnMove);
|
|
|
|
|
|
|
|
|
|
public static CheckMoveResult[] VerifyRelearn(PKM pk, IEncounterTemplate enc, CheckMoveResult[] result)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (ShouldNotHaveRelearnMoves(enc, pk))
|
|
|
|
|
return VerifyRelearnNone(pk, result);
|
2021-03-31 01:51:53 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
return enc switch
|
2020-11-07 20:25:15 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
IRelearn s when s.Relearn.Count != 0 => VerifyRelearnSpecifiedMoveset(pk, s.Relearn, result),
|
|
|
|
|
EncounterEgg e => VerifyEggMoveset(e, result, pk.RelearnMoves),
|
|
|
|
|
EncounterSlot6AO {CanDexNav:true} z when pk.RelearnMove1 != 0 => VerifyRelearnDexNav(pk, result, z),
|
|
|
|
|
EncounterSlot8b {IsUnderground:true} u => VerifyRelearnUnderground(pk, result, u),
|
|
|
|
|
_ => VerifyRelearnNone(pk, result),
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-11-07 20:25:15 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public static bool ShouldNotHaveRelearnMoves(IGeneration enc, PKM pk) => enc.Generation < 6 || pk.IsOriginalMovesetDeleted();
|
2018-12-28 04:24:24 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private static CheckMoveResult[] VerifyRelearnSpecifiedMoveset(PKM pk, IReadOnlyList<int> required, CheckMoveResult[] result)
|
|
|
|
|
{
|
|
|
|
|
CheckResult(pk.RelearnMove4, required[3], result[3]);
|
|
|
|
|
CheckResult(pk.RelearnMove3, required[2], result[2]);
|
|
|
|
|
CheckResult(pk.RelearnMove2, required[1], result[1]);
|
|
|
|
|
CheckResult(pk.RelearnMove1, required[0], result[0]);
|
|
|
|
|
return result;
|
2021-04-17 20:13:03 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
static void CheckResult(int move, int require, CheckMoveResult p)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (move == require)
|
2018-08-03 03:11:42 +00:00
|
|
|
|
{
|
2022-03-13 01:06:03 +00:00
|
|
|
|
DummyValid(p);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var c = string.Format(LMoveFExpect_0, MoveStrings[require]);
|
|
|
|
|
p.Set(MoveSource.Relearn, 0, Severity.Invalid, c, CheckIdentifier.RelearnMove);
|
2022-03-13 01:06:03 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private static void ParseExpectEmpty(CheckMoveResult p, int move)
|
|
|
|
|
{
|
|
|
|
|
if (move == 0)
|
|
|
|
|
DummyValid(p);
|
|
|
|
|
else
|
|
|
|
|
p.Set(MoveSource.Relearn, 0, Severity.Invalid, LMoveRelearnNone, CheckIdentifier.RelearnMove);
|
|
|
|
|
}
|
2021-11-20 02:23:49 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private static CheckMoveResult[] VerifyRelearnDexNav(PKM pk, CheckMoveResult[] result, EncounterSlot6AO slot)
|
|
|
|
|
{
|
|
|
|
|
// All other relearn moves must be empty.
|
|
|
|
|
ParseExpectEmpty(result[3], pk.RelearnMove4);
|
|
|
|
|
ParseExpectEmpty(result[2], pk.RelearnMove3);
|
|
|
|
|
ParseExpectEmpty(result[1], pk.RelearnMove2);
|
|
|
|
|
|
|
|
|
|
// DexNav Pokémon can have 1 random egg move as a relearn move.
|
|
|
|
|
var p = result[0];
|
|
|
|
|
if (!slot.CanBeDexNavMove(pk.RelearnMove1)) // not found
|
|
|
|
|
p.Set(MoveSource.Relearn, 6, Severity.Invalid, LMoveRelearnDexNav, CheckIdentifier.RelearnMove);
|
|
|
|
|
else
|
|
|
|
|
DummyValid(p);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-11-20 02:23:49 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private static CheckMoveResult[] VerifyRelearnUnderground(PKM pk, CheckMoveResult[] result, EncounterSlot8b slot)
|
|
|
|
|
{
|
|
|
|
|
// All other relearn moves must be empty.
|
|
|
|
|
ParseExpectEmpty(result[3], pk.RelearnMove4);
|
|
|
|
|
ParseExpectEmpty(result[2], pk.RelearnMove3);
|
|
|
|
|
ParseExpectEmpty(result[1], pk.RelearnMove2);
|
|
|
|
|
|
|
|
|
|
// Underground Pokémon can have 1 random egg move as a relearn move.
|
|
|
|
|
var p = result[0];
|
|
|
|
|
if (!slot.CanBeUndergroundMove(pk.RelearnMove1)) // not found
|
|
|
|
|
p.Set(MoveSource.Relearn, 0, Severity.Invalid, LMoveRelearnUnderground, CheckIdentifier.RelearnMove);
|
|
|
|
|
else
|
|
|
|
|
DummyValid(p);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private static CheckMoveResult[] VerifyRelearnNone(PKM pk, CheckMoveResult[] result)
|
|
|
|
|
{
|
|
|
|
|
// No relearn moves should be present.
|
|
|
|
|
ParseExpectEmpty(result[3], pk.RelearnMove4);
|
|
|
|
|
ParseExpectEmpty(result[2], pk.RelearnMove3);
|
|
|
|
|
ParseExpectEmpty(result[1], pk.RelearnMove2);
|
|
|
|
|
ParseExpectEmpty(result[0], pk.RelearnMove1);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
internal static CheckMoveResult[] VerifyEggMoveset(EncounterEgg e, CheckMoveResult[] result, int[] moves, CheckIdentifier type = CheckIdentifier.RelearnMove)
|
|
|
|
|
{
|
|
|
|
|
int gen = e.Generation;
|
|
|
|
|
var origins = MoveBreed.Process(gen, e.Species, e.Form, e.Version, moves, out var valid);
|
|
|
|
|
if (valid)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var msg = EggSourceUtil.GetSource(origins, gen, i);
|
|
|
|
|
result[i].Set(MoveSource.EggMove, gen, Severity.Valid, msg, type);
|
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
else
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
var expected = MoveBreed.GetExpectedMoves(moves, e);
|
|
|
|
|
origins = MoveBreed.Process(gen, e.Species, e.Form, e.Version, expected, out _);
|
|
|
|
|
for (int i = 0; i < moves.Length; i++)
|
2017-08-01 00:09:16 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
var msg = EggSourceUtil.GetSource(origins, gen, i);
|
|
|
|
|
var expect = expected[i];
|
|
|
|
|
var p = result[i];
|
|
|
|
|
if (moves[i] == expect)
|
2017-08-01 00:09:16 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
p.Set(MoveSource.EggMove, gen, Severity.Valid, msg, type);
|
2017-08-01 00:09:16 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
else
|
2021-04-05 01:30:01 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
msg = string.Format(LMoveRelearnFExpect_0, MoveStrings[expect], msg);
|
|
|
|
|
p.Set(MoveSource.EggMove, gen, Severity.Invalid, msg, type);
|
2021-04-05 01:30:01 +00:00
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-27 21:05:36 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
var dupe = IsAnyMoveDuplicate(moves);
|
|
|
|
|
if (dupe != NO_DUPE)
|
|
|
|
|
result[dupe].Set(MoveSource.EggMove, gen, Severity.Invalid, LMoveSourceDuplicate, type);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-04-17 20:13:03 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private const int NO_DUPE = -1;
|
|
|
|
|
|
|
|
|
|
private static int IsAnyMoveDuplicate(ReadOnlySpan<int> move)
|
|
|
|
|
{
|
|
|
|
|
int m1 = move[0];
|
|
|
|
|
int m2 = move[1];
|
|
|
|
|
|
|
|
|
|
if (m1 != 0 && m1 == m2)
|
|
|
|
|
return 1;
|
|
|
|
|
int m3 = move[2];
|
|
|
|
|
if (m3 != 0 && (m1 == m3 || m2 == m3))
|
|
|
|
|
return 2;
|
|
|
|
|
int m4 = move[3];
|
|
|
|
|
if (m4 != 0 && (m1 == m4 || m2 == m4 || m3 == m4))
|
|
|
|
|
return 3;
|
|
|
|
|
return NO_DUPE;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|