PKHeX/PKHeX.Core/Legality/Areas/EncounterArea8g.cs
Kurt 7654ce2123 Add initial legality checks for GO->HOME transfers
took me less than an hour to do these changes, and i can flag bad form movesets no problemo

Expect tightening of restrictions (ball, level, shininess) later
if someone wants to curate met date restrictions, go ahead!
2020-11-10 22:10:53 -08:00

101 lines
3.8 KiB
C#

using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
{
/// <inheritdoc />
/// <summary>
/// <see cref="GameVersion.GO"/> encounter area for direct-to-HOME transfers.
/// </summary>
public sealed class EncounterArea8g : EncounterArea
{
private EncounterArea8g() : base(GameVersion.GO) { }
internal static EncounterArea8g[] GetArea(EncounterArea7g lgpe, int maxSpecies, HashSet<int> banlist, IEnumerable<int> extras)
{
var area = new EncounterArea8g { Location = Locations.GO8, Type = SlotType.GoPark };
var lgpeEncounters = lgpe.Slots.Select(z => GetSlot(area, z.Species, z.Form, GameVersion.GG, z.LevelMin));
var other = GetSlots(area, maxSpecies, banlist, extras);
area.Slots = other.Concat(lgpeEncounters).ToArray();
return new[] { area };
}
private static EncounterSlot8GO GetSlot(EncounterArea8g area, int species, int form, GameVersion baseOrigin, int min = 1)
{
return new EncounterSlot8GO(area, species, form, baseOrigin, min, 40);
}
private static IEnumerable<EncounterSlot> GetSlots(EncounterArea8g area, int maxSpecies, HashSet<int> banlist, IEnumerable<int> extras)
{
// Gen7: GO transfers to LGPE cannot send Mew.
// Gen8: GO transfers to HOME can send Mew. Iterate from here.
// However, Mew transfers with LGPE base moves. Because everything <= 151 uses LGPE level-up table. Handle manually!
yield return GetSlot(area, (int)Species.Mew, 0, GameVersion.GG);
const int start = (int)Species.Mew + 1;
var speciesList = Enumerable.Range(start, maxSpecies - start + 1).Concat(extras);
var pt7 = PersonalTable.USUM;
var pt8 = PersonalTable.SWSH;
foreach (var species in speciesList)
{
if (banlist.Contains(species))
continue;
var pi8 = (PersonalInfoSWSH)pt8[species];
if (pi8.IsPresentInGame)
{
for (int f = 0; f < pi8.FormeCount; f++)
{
if (IsDisallowedDuplicateForm(species, f))
continue;
yield return GetSlot(area, species, f, GameVersion.SWSH);
}
}
else if (species <= Legal.MaxAbilityID_7_USUM)
{
var pi7 = pt7[species];
for (int f = 0; f < pi7.FormeCount; f++)
{
if (IsDisallowedDuplicateForm(species, f))
continue;
yield return GetSlot(area, species, f, GameVersion.USUM);
}
}
}
}
private static bool IsDisallowedDuplicateForm(int species, int f)
{
if (AltFormInfo.IsBattleOnlyForm(species, f, 8))
return true;
if (AltFormInfo.IsFusedForm(species, f, 8))
return true;
return false;
}
public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pkm, IReadOnlyList<EvoCriteria> chain)
{
if (pkm.TSV == 0) // HOME doesn't assign TSV=0 to accounts.
yield break;
foreach (var slot in Slots)
{
foreach (var evo in chain)
{
if (slot.Species != evo.Species)
continue;
if (!slot.IsLevelWithinRange(pkm.Met_Level))
break;
if (slot.Form != evo.Form)
break;
yield return slot;
break;
}
}
}
}
}