PKHeX/PKHeX.Core/Legality/Verifiers/MarkVerifier.cs

155 lines
5.5 KiB
C#
Raw Normal View History

using static PKHeX.Core.LegalityCheckStrings;
using static PKHeX.Core.RibbonIndex;
2020-04-06 23:32:23 +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
{
protected override CheckIdentifier Identifier => CheckIdentifier.RibbonMark;
public override void Verify(LegalityAnalysis data)
2020-04-06 23:32:23 +00:00
{
var pk = data.Entity;
if (pk is not IRibbonIndex m)
return;
2020-04-06 23:32:23 +00:00
2023-09-28 23:40:23 +00:00
if (!MarkRules.IsEncounterMarkAllowed(data.EncounterOriginal, data.Entity)) // Shedinja doesn't copy Ribbons or Marks
VerifyNoMarksPresent(data, m);
else
VerifyMarksPresent(data, m);
2020-04-06 23:32:23 +00:00
VerifyAffixedRibbonMark(data, m);
2023-02-28 03:12:27 +00:00
// temp logic to catch this case; in the future we will need more robust checks for encounters
if (data.EncounterMatch is WC9 { RibbonMarkCharismatic: true } && pk is IRibbonSetMark8 { RibbonMarkCharismatic: false })
2023-02-28 03:12:27 +00:00
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, GetRibbonNameSafe(MarkCharismatic))));
else if (data.EncounterMatch is EncounterStatic9 { RibbonMarkCrafty: true } && pk is IRibbonSetMark8 { RibbonMarkCrafty: false })
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, GetRibbonNameSafe(MarkCrafty))));
}
private void VerifyNoMarksPresent(LegalityAnalysis data, IRibbonIndex m)
{
for (var x = MarkLunchtime; x <= MarkSlump; x++)
{
if (m.GetRibbon((int)x))
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, GetRibbonNameSafe(x))));
2020-04-06 23:32:23 +00:00
}
}
2020-04-06 23:32:23 +00:00
private void VerifyMarksPresent(LegalityAnalysis data, IRibbonIndex m)
{
bool hasOne = false;
for (var mark = MarkLunchtime; mark <= MarkSlump; mark++)
2020-04-06 23:32:23 +00:00
{
bool has = m.GetRibbon((int)mark);
if (!has)
continue;
if (hasOne)
{
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, GetRibbonNameSafe(mark))));
return;
}
2020-04-06 23:32:23 +00:00
bool result = MarkRules.IsEncounterMarkValid(mark, data.Entity, data.EncounterMatch);
if (!result)
2020-04-06 23:32:23 +00:00
{
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, GetRibbonNameSafe(mark))));
return;
2020-04-06 23:32:23 +00:00
}
hasOne = true;
}
}
private static string GetRibbonNameSafe(RibbonIndex index)
{
if (index >= MAX_COUNT)
return index.ToString();
var expect = $"Ribbon{index}";
return RibbonStrings.GetName(expect);
}
Enforce weather legality for SWSH (#3221) * Add weather types by location Creates a dictionary of possible weather types for each SWSH location. Unlisted locations may only have Normal weather or do not have any encounter slots. * Prune unused weather from static encounters Some encounters were too permissive with weather, e.g. Sandstorm in Fields of Honor and Challenge Beach; Snowstorm at Dyna Tree Hill. A few crossover areas that would have limited the possible weathers were marked with a "(c)". An example is Nidorina from Giant's Bed crossing to Frostpoint Field, where Raining and Thunderstorm do not occur. This additionally organizes encounters by location. * Move location-weather dictionary to EncounterArea8 * Verify weather marks on encounterslot/static encounters * Adds some static encounters available through weather bleed Weathers aren't normally available, but these static encounters are close enough to the boundary that the weather in an adjacent area can be used to spawn them. - Frostpoint Field Snorlax with Raining/Thunderstorm from Giant's Bed - Snowslide Slope Amaura with Raining/Thunderstorm from Giant's Bed - Frigid Sea Carracosta with Intense_Sun from Three-Point Pass - Frigid Sea Magmortar with Intense_Sun from Three-Point Pass - Ballimere Lake Corviknight with Snowstorm from Giant's Bed - Ballimere Lake Cryogonal with Snowstorm from Giant's Bed - Ballimere Lake Tyrunt with all weather from Giant's Bed - Lakeside Cave Ferrothorn with all weather from Ballimere Lake - Tunnel to the Top Golbat with all weather from Path to the Peak * Defer weather marks if incompatible, enforce encounterslot weather This uses the area weather to check fishing slots and tentatively adds some tables for weather bleed encounterslots. * Warm-Up Tunnel gets weather bleed from Training Lowlands * Update for base PKHeX * Handle weather bleed for SWSH encounter slots Co-authored-by: Skadiv <62726360+Skadiv@users.noreply.github.com> * Minor clean Having duplicate weather marks is illegal, so just auto-partial match them instead of checking the other marks. * Rearrange slot weather check logic * Claim reserved byte in SWSH pkl * No need for two variable names now * Valid weather marks on tree/fishing should return with main weather * Fix tree/fishing deferral and add another surf slot weather bleed * Disallow tree/fishing encounters from using bleed tables None are currently known at this time, and only hidden grass encounters have a weather bleed table * Condense bleed expression, combine tree/fish flag check * Move weather-bleed check into EncounterArea8 Makes the dictionaries private instead of internal. Co-authored-by: Skadiv <62726360+Skadiv@users.noreply.github.com>
2021-07-26 21:28:05 +00:00
private void VerifyAffixedRibbonMark(LegalityAnalysis data, IRibbonIndex m)
{
if (m is not IRibbonSetAffixed a)
return;
var affixValue = a.AffixedRibbon;
if (affixValue == -1) // None
return;
var affix = (RibbonIndex)affixValue;
var max = MarkRules.GetMaxAffixValue(data.Info.EvoChainsAllGens);
2023-07-08 15:40:57 +00:00
if ((sbyte)max == -1 || affix > max)
{
data.AddLine(GetInvalid(string.Format(LRibbonMarkingAffixedF_0, GetRibbonNameSafe(affix))));
return;
}
if (m is not PKM pk)
return;
2023-09-28 23:40:23 +00:00
if (MarkRules.IsEncounterMarkLost(data.EncounterOriginal, data.Entity))
{
VerifyShedinjaAffixed(data, affix, pk, m);
return;
}
EnsureHasRibbon(data, m, affix);
}
private void VerifyShedinjaAffixed(LegalityAnalysis data, RibbonIndex affix, PKM pk, IRibbonIndex r)
{
// 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;
if (affix.IsEncounterMark8())
{
if (!MarkRules.IsEncounterMarkValid(affix, pk, enc))
data.AddLine(GetInvalid(string.Format(LRibbonMarkingAffixedF_0, GetRibbonNameSafe(affix))));
return;
}
if (enc.Generation <= 4 && (pk.Ball != (int)Ball.Poke || IsMoveSetEvolvedShedinja(pk)))
{
// Evolved in a prior generation.
EnsureHasRibbon(data, r, affix);
return;
}
var clone = pk.Clone();
clone.Species = (int) Species.Nincada;
var args = new RibbonVerifierArguments(clone, enc, data.Info.EvoChainsAllGens);
affix.Fix(args, true);
var name = GetRibbonNameSafe(affix);
bool invalid = RibbonVerifier.IsValidExtra(affix, args);
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)
}
private void EnsureHasRibbon(LegalityAnalysis data, IRibbonIndex m, RibbonIndex affix)
{
var hasRibbon = m.GetRibbonIndex(affix);
if (!hasRibbon)
data.AddLine(GetInvalid(string.Format(LRibbonMarkingAffixedF_0, GetRibbonNameSafe(affix))));
2020-04-06 23:32:23 +00:00
}
}