mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-07 13:45:15 -05:00
Move encountertype deferral to main generator
gen4->gen5/6 electrode will match static & wild slots, but deferral only defers within the same IEncounterable group.
This commit is contained in:
@@ -84,19 +84,27 @@ private static IEnumerable<IEncounterable> GetEncounters3(PKM pkm, LegalInfo inf
|
||||
private static IEnumerable<IEncounterable> GetEncounters4(PKM pkm, LegalInfo info)
|
||||
{
|
||||
info.PIDIV = MethodFinder.Analyze(pkm);
|
||||
var deferred = new List<IEncounterable>();
|
||||
var deferredPID = new List<IEncounterable>();
|
||||
var deferredEType = new List<IEncounterable>();
|
||||
|
||||
foreach (var z in GenerateRawEncounters4(pkm))
|
||||
{
|
||||
if (info.PIDIV.Type.IsCompatible4(z, pkm))
|
||||
yield return z;
|
||||
if (!info.PIDIV.Type.IsCompatible4(z, pkm))
|
||||
deferredPID.Add(z);
|
||||
else if (!IsEncounterTypeMatch(z, pkm.EncounterType))
|
||||
deferredEType.Add(z);
|
||||
else
|
||||
deferred.Add(z);
|
||||
yield return z;
|
||||
}
|
||||
if (deferred.Count == 0)
|
||||
|
||||
foreach (var z in deferredEType)
|
||||
yield return z;
|
||||
|
||||
if (deferredPID.Count == 0)
|
||||
yield break;
|
||||
|
||||
info.PIDIVMatches = false;
|
||||
foreach (var z in deferred)
|
||||
foreach (var z in deferredPID)
|
||||
yield return z;
|
||||
}
|
||||
private static IEnumerable<GBEncounterData> GenerateRawEncounters12(PKM pkm, GameVersion game)
|
||||
@@ -329,10 +337,6 @@ private static IEnumerable<IEncounterable> GenerateRawEncounters3(PKM pkm)
|
||||
}
|
||||
|
||||
// EncounterStatic
|
||||
private static bool IsEncounterTypeMatch(IEncounterable e, int type)
|
||||
{
|
||||
return e is EncounterStaticTyped t ? t.TypeEncounter.Contains(type) : type == 0;
|
||||
}
|
||||
private static bool IsValidCatchRatePK1(EncounterStatic e, PK1 pk1)
|
||||
{
|
||||
var catch_rate = pk1.Catch_Rate;
|
||||
@@ -376,31 +380,9 @@ private static IEnumerable<EncounterStatic> GetValidStaticEncounter(PKM pkm, Gam
|
||||
yield break;
|
||||
|
||||
// Back Check against pkm
|
||||
var enc = GetMatchingStaticEncounters(pkm, poss, lvl).ToList();
|
||||
|
||||
// Filter for encounter types; type is cleared on 6->7 transfer
|
||||
if (!pkm.Gen4 || pkm.Format >= 7)
|
||||
{
|
||||
foreach (var e in enc)
|
||||
yield return e;
|
||||
yield break;
|
||||
}
|
||||
|
||||
// Yield out if type matches, else defer to end if no matches were yielded
|
||||
int ctr = 0;
|
||||
int type = pkm.EncounterType;
|
||||
var pass = new List<EncounterStatic>();
|
||||
foreach (var e in enc)
|
||||
{
|
||||
if (IsEncounterTypeMatch(e, type))
|
||||
{ yield return e; ++ctr; }
|
||||
else pass.Add(e);
|
||||
}
|
||||
if (ctr != 0)
|
||||
yield break;
|
||||
|
||||
foreach (var e in pass)
|
||||
yield return e;
|
||||
var enc = GetMatchingStaticEncounters(pkm, poss, lvl);
|
||||
foreach (var z in enc)
|
||||
yield return z;
|
||||
}
|
||||
private static IEnumerable<EncounterStatic> GetMatchingStaticEncounters(PKM pkm, IEnumerable<EncounterStatic> poss, int lvl)
|
||||
{
|
||||
@@ -545,9 +527,7 @@ private static IEnumerable<EncounterSlot> GetValidWildEncounters(PKM pkm, GameVe
|
||||
bool IsSafariBall = pkm.Ball == 5;
|
||||
bool IsSportsBall = pkm.Ball == 0x18;
|
||||
bool IsHidden = pkm.AbilityNumber == 4; // hidden Ability
|
||||
int gen = pkm.GenNumber;
|
||||
int species = pkm.Species;
|
||||
bool CheckEncounterType = gen == 4 && pkm.Format != 7;
|
||||
|
||||
var deferred = new List<EncounterSlot>();
|
||||
foreach (EncounterSlot slot in s)
|
||||
@@ -558,7 +538,6 @@ private static IEnumerable<EncounterSlot> GetValidWildEncounters(PKM pkm, GameVe
|
||||
else if (IsHidden ^ IsHiddenAbilitySlot(slot)) { } // ability mismatch
|
||||
else if (IsSafariBall ^ IsSafariSlot(slot.Type)) { } // Safari Zone only ball
|
||||
else if (IsSportsBall ^ slot.Type == SlotType.BugContest) { } // BCC only ball
|
||||
else if (CheckEncounterType && !slot.TypeEncounter.Contains(pkm.EncounterType)) { } // incorrect encounter type
|
||||
else
|
||||
{
|
||||
yield return slot;
|
||||
@@ -1414,6 +1393,18 @@ internal static bool IsDexNavValid(PKM pkm)
|
||||
var d_areas = locs.Select(loc => GetValidEncounterSlots(pkm, loc, DexNav: true));
|
||||
return d_areas.Any(slots => slots.Any(slot => slot.Permissions.AllowDexNav && slot.Permissions.DexNav));
|
||||
}
|
||||
private static bool IsEncounterTypeMatch(IEncounterable e, int type)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
case EncounterStaticTyped t:
|
||||
return t.TypeEncounter.Contains(type);
|
||||
case EncounterSlot w:
|
||||
return w.TypeEncounter.Contains(type);
|
||||
default:
|
||||
return type == 0;
|
||||
}
|
||||
}
|
||||
internal static EncounterArea GetCaptureLocation(PKM pkm)
|
||||
{
|
||||
return (from area in GetEncounterSlots(pkm, 100)
|
||||
|
||||
Reference in New Issue
Block a user