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