2021-04-21 22:20:16 +00:00
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
2022-11-25 01:42:17 +00:00
|
|
|
using static PKHeX.Core.RibbonIndex;
|
2020-04-06 23:32:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies the <see cref="RibbonIndex"/> values for markings.
|
|
|
|
/// </summary>
|
|
|
|
public sealed class MarkVerifier : Verifier
|
2020-04-06 23:32:23 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.RibbonMark;
|
|
|
|
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
2020-04-06 23:32:23 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var pk = data.Entity;
|
|
|
|
if (pk is not IRibbonIndex m)
|
|
|
|
return;
|
2020-04-06 23:32:23 +00:00
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
if (!MarkRules.IsEncounterMarkAllowed(data)) // Shedinja doesn't copy Ribbons or Marks
|
2022-06-18 18:04:24 +00:00
|
|
|
VerifyNoMarksPresent(data, m);
|
|
|
|
else
|
|
|
|
VerifyMarksPresent(data, m);
|
2020-04-06 23:32:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
VerifyAffixedRibbonMark(data, m);
|
|
|
|
}
|
2020-09-28 01:19:10 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void VerifyNoMarksPresent(LegalityAnalysis data, IRibbonIndex m)
|
|
|
|
{
|
2022-11-25 01:42:17 +00:00
|
|
|
for (var x = MarkLunchtime; x <= MarkSlump; x++)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (m.GetRibbon((int)x))
|
2022-11-25 01:42:17 +00:00
|
|
|
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, GetRibbonNameSafe(x))));
|
2020-04-06 23:32:23 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2020-04-06 23:32:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void VerifyMarksPresent(LegalityAnalysis data, IRibbonIndex m)
|
|
|
|
{
|
|
|
|
bool hasOne = false;
|
2022-11-25 01:42:17 +00:00
|
|
|
for (var mark = MarkLunchtime; mark <= MarkSlump; mark++)
|
2020-04-06 23:32:23 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
bool has = m.GetRibbon((int)mark);
|
|
|
|
if (!has)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (hasOne)
|
2021-01-23 05:17:41 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, GetRibbonNameSafe(mark))));
|
|
|
|
return;
|
2021-01-23 05:17:41 +00:00
|
|
|
}
|
2020-04-06 23:32:23 +00:00
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
bool result = MarkRules.IsMarkValid8(mark, data.Entity, data.EncounterMatch);
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!result)
|
2020-04-06 23:32:23 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, GetRibbonNameSafe(mark))));
|
|
|
|
return;
|
2020-04-06 23:32:23 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
hasOne = true;
|
2022-05-31 04:43:52 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2022-05-31 04:43:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static string GetRibbonNameSafe(RibbonIndex index)
|
|
|
|
{
|
2022-11-25 01:42:17 +00:00
|
|
|
if (index >= MAX_COUNT)
|
2022-06-18 18:04:24 +00:00
|
|
|
return index.ToString();
|
|
|
|
var expect = $"Ribbon{index}";
|
|
|
|
return RibbonStrings.GetName(expect);
|
|
|
|
}
|
2021-07-26 21:28:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void VerifyAffixedRibbonMark(LegalityAnalysis data, IRibbonIndex m)
|
|
|
|
{
|
|
|
|
if (m is not IRibbonSetAffixed a)
|
|
|
|
return;
|
2022-05-31 04:43:52 +00:00
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
var affixValue = a.AffixedRibbon;
|
|
|
|
if (affixValue == -1) // None
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2021-04-21 22:20:16 +00:00
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
var affix = (RibbonIndex)affixValue;
|
|
|
|
var max = MarkRules.GetMaxAffixValue(data.Entity.Format);
|
|
|
|
if (affix > max)
|
2021-04-21 22:20:16 +00:00
|
|
|
{
|
2022-11-25 01:42:17 +00:00
|
|
|
data.AddLine(GetInvalid(string.Format(LRibbonMarkingAffixedF_0, GetRibbonNameSafe(affix))));
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-04-21 22:20:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (m is not PKM pk)
|
|
|
|
return;
|
2021-04-21 22:20:16 +00:00
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
if (MarkRules.IsEncounterMarkLost(data))
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
VerifyShedinjaAffixed(data, affix, pk, m);
|
|
|
|
return;
|
2021-04-21 22:20:16 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
EnsureHasRibbon(data, m, affix);
|
|
|
|
}
|
2021-04-21 22:20:16 +00:00
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
private void VerifyShedinjaAffixed(LegalityAnalysis data, RibbonIndex affix, PKM pk, IRibbonIndex r)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
// Does not copy ribbons or marks, but retains the Affixed Ribbon value.
|
|
|
|
// Try re-verifying to see if it could have had the Ribbon/Mark.
|
|
|
|
|
|
|
|
var enc = data.EncounterOriginal;
|
2022-11-25 01:42:17 +00:00
|
|
|
if (affix.IsEncounterMark())
|
2021-04-21 22:20:16 +00:00
|
|
|
{
|
2022-11-25 01:42:17 +00:00
|
|
|
if (!MarkRules.IsMarkValid8(affix, pk, enc))
|
|
|
|
data.AddLine(GetInvalid(string.Format(LRibbonMarkingAffixedF_0, GetRibbonNameSafe(affix))));
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2021-04-21 22:20:16 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (enc.Generation <= 4 && (pk.Ball != (int)Ball.Poke || IsMoveSetEvolvedShedinja(pk)))
|
2021-04-21 22:20:16 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Evolved in a prior generation.
|
|
|
|
EnsureHasRibbon(data, r, affix);
|
|
|
|
return;
|
2020-09-28 01:19:10 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
var clone = pk.Clone();
|
|
|
|
clone.Species = (int) Species.Nincada;
|
2022-08-16 04:04:30 +00:00
|
|
|
var args = new RibbonVerifierArguments(clone, enc, data.Info.EvoChainsAllGens);
|
2022-11-25 01:42:17 +00:00
|
|
|
affix.Fix(args, true);
|
|
|
|
var name = GetRibbonNameSafe(affix);
|
|
|
|
bool invalid = RibbonVerifier.IsValidExtra(affix, args);
|
2022-06-18 18:04:24 +00:00
|
|
|
var severity = invalid ? Severity.Invalid : Severity.Fishy;
|
|
|
|
data.AddLine(Get(string.Format(LRibbonMarkingAffixedF_0, name), severity));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool IsMoveSetEvolvedShedinja(PKM pk)
|
|
|
|
{
|
|
|
|
// Check for gen3/4 exclusive moves that are Ninjask glitch only.
|
|
|
|
if (pk.HasMove((int) Move.Screech))
|
|
|
|
return true;
|
|
|
|
if (pk.HasMove((int) Move.SwordsDance))
|
|
|
|
return true;
|
|
|
|
if (pk.HasMove((int) Move.Slash))
|
|
|
|
return true;
|
|
|
|
if (pk.HasMove((int) Move.BatonPass))
|
|
|
|
return true;
|
|
|
|
return pk.HasMove((int)Move.Agility) && pk is PK8 pk8 && !pk8.GetMoveRecordFlag(12); // TR12 (Agility)
|
|
|
|
}
|
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
private void EnsureHasRibbon(LegalityAnalysis data, IRibbonIndex m, RibbonIndex affix)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-11-25 01:42:17 +00:00
|
|
|
var hasRibbon = m.GetRibbonIndex(affix);
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!hasRibbon)
|
2022-11-25 01:42:17 +00:00
|
|
|
data.AddLine(GetInvalid(string.Format(LRibbonMarkingAffixedF_0, GetRibbonNameSafe(affix))));
|
2020-04-06 23:32:23 +00:00
|
|
|
}
|
|
|
|
}
|