2020-04-06 23:32:23 +00:00
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies the <see cref="RibbonIndex"/> values for markings.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class MarkVerifier : Verifier
|
|
|
|
|
{
|
|
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.RibbonMark;
|
|
|
|
|
|
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2020-12-22 01:12:39 +00:00
|
|
|
|
if (pkm is not IRibbonIndex m)
|
2020-04-06 23:32:23 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (data.Info.Generation != 8)
|
|
|
|
|
VerifyNoMarksPresent(data, m);
|
|
|
|
|
else
|
|
|
|
|
VerifyMarksPresent(data, m);
|
2020-09-28 01:19:10 +00:00
|
|
|
|
|
|
|
|
|
VerifyAffixedRibbonMark(data, m);
|
2020-04-06 23:32:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void VerifyNoMarksPresent(LegalityAnalysis data, IRibbonIndex m)
|
|
|
|
|
{
|
2021-01-23 05:17:41 +00:00
|
|
|
|
for (var x = RibbonIndex.MarkLunchtime; x <= RibbonIndex.MarkSlump; x++)
|
|
|
|
|
{
|
|
|
|
|
if (m.GetRibbon((int)x))
|
|
|
|
|
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, x)));
|
|
|
|
|
}
|
2020-04-06 23:32:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void VerifyMarksPresent(LegalityAnalysis data, IRibbonIndex m)
|
|
|
|
|
{
|
|
|
|
|
bool hasOne = false;
|
|
|
|
|
for (var mark = RibbonIndex.MarkLunchtime; mark <= RibbonIndex.MarkSlump; mark++)
|
|
|
|
|
{
|
|
|
|
|
bool has = m.GetRibbon((int) mark);
|
|
|
|
|
if (!has)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (hasOne)
|
|
|
|
|
{
|
|
|
|
|
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, mark)));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 20:58:56 +00:00
|
|
|
|
bool result = IsMarkValid(mark, data.pkm, data.EncounterMatch);
|
2020-04-06 23:32:23 +00:00
|
|
|
|
if (!result)
|
|
|
|
|
{
|
|
|
|
|
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, mark)));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hasOne = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 20:58:56 +00:00
|
|
|
|
public static bool IsMarkValid(RibbonIndex mark, PKM pk, IEncounterable enc)
|
2020-04-06 23:32:23 +00:00
|
|
|
|
{
|
2020-11-04 20:58:56 +00:00
|
|
|
|
return IsMarkAllowedAny(enc) && IsMarkAllowedSpecific(mark, pk, enc);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-15 05:24:31 +00:00
|
|
|
|
public static bool IsMarkAllowedSpecific(RibbonIndex mark, PKM pk, IEncounterable x) => mark switch
|
2020-11-04 20:58:56 +00:00
|
|
|
|
{
|
2021-02-15 05:24:31 +00:00
|
|
|
|
RibbonIndex.MarkCurry when !IsMarkAllowedCurry(pk, x) => false,
|
2021-02-15 06:25:59 +00:00
|
|
|
|
RibbonIndex.MarkFishing when !IsMarkAllowedFishing(x) => false,
|
2021-01-02 01:08:49 +00:00
|
|
|
|
RibbonIndex.MarkDestiny => false,
|
|
|
|
|
_ => true
|
|
|
|
|
};
|
2020-11-04 20:58:56 +00:00
|
|
|
|
|
2021-01-02 01:08:49 +00:00
|
|
|
|
public static bool IsMarkAllowedAny(IEncounterable enc) => enc.Generation == 8 && enc switch
|
2020-11-04 20:58:56 +00:00
|
|
|
|
{
|
2021-02-02 04:34:04 +00:00
|
|
|
|
// Gen 8
|
|
|
|
|
WC8 or EncounterEgg or EncounterTrade or EncounterSlot8GO
|
2021-01-02 01:08:49 +00:00
|
|
|
|
or EncounterStatic8U or EncounterStatic8N or EncounterStatic8ND or EncounterStatic8NC
|
|
|
|
|
or EncounterStatic8 {Gift: true}
|
|
|
|
|
or EncounterStatic8 {ScriptedNoMarks: true}
|
|
|
|
|
=> false,
|
|
|
|
|
_ => true,
|
|
|
|
|
};
|
2020-11-04 20:58:56 +00:00
|
|
|
|
|
2021-02-15 05:24:31 +00:00
|
|
|
|
public static bool IsMarkAllowedCurry(PKM pkm, IEncounterable enc)
|
2020-11-04 20:58:56 +00:00
|
|
|
|
{
|
2021-02-15 06:25:59 +00:00
|
|
|
|
// Curry are only encounter slots, from the hidden table (not symbol). Slots taken from area's current weather(?).
|
|
|
|
|
if (enc is not EncounterSlot8 s)
|
2020-11-04 20:58:56 +00:00
|
|
|
|
return false;
|
2021-02-15 05:24:31 +00:00
|
|
|
|
|
2021-02-15 06:25:59 +00:00
|
|
|
|
var area = (EncounterArea8)s.Area;
|
|
|
|
|
if (area.PermitCrossover)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var weather = s.Weather;
|
|
|
|
|
if ((weather & AreaWeather8.All) == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (EncounterArea8.IsWildArea(s.Location))
|
2020-11-04 20:58:56 +00:00
|
|
|
|
return false;
|
2021-02-15 05:24:31 +00:00
|
|
|
|
var ball = pkm.Ball;
|
|
|
|
|
return (uint)(ball - 2) <= 2;
|
2020-04-06 23:32:23 +00:00
|
|
|
|
}
|
2020-09-28 01:19:10 +00:00
|
|
|
|
|
2021-02-15 06:25:59 +00:00
|
|
|
|
public static bool IsMarkAllowedFishing(IEncounterable enc)
|
|
|
|
|
{
|
|
|
|
|
// Fishing are only encounter slots, from the hidden table (not symbol).
|
|
|
|
|
if (enc is not EncounterSlot8 s)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var area = (EncounterArea8)s.Area;
|
|
|
|
|
if (area.PermitCrossover)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var weather = s.Weather;
|
|
|
|
|
return (weather & AreaWeather8.Fishing) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 01:19:10 +00:00
|
|
|
|
private void VerifyAffixedRibbonMark(LegalityAnalysis data, IRibbonIndex m)
|
|
|
|
|
{
|
2020-12-22 01:12:39 +00:00
|
|
|
|
if (m is not PK8 pk8)
|
2020-09-28 01:19:10 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var affix = pk8.AffixedRibbon;
|
|
|
|
|
if (affix == -1) // None
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ((byte)affix > (int)RibbonIndex.MarkSlump)
|
|
|
|
|
data.AddLine(GetInvalid(string.Format(LRibbonMarkingAffixedF_0, affix)));
|
|
|
|
|
else if (!pk8.GetRibbonIndex((RibbonIndex)affix))
|
|
|
|
|
data.AddLine(GetInvalid(string.Format(LRibbonMarkingAffixedF_0, (RibbonIndex)affix)));
|
|
|
|
|
}
|
2020-04-06 23:32:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|