Skip to content

Commit

Permalink
Add gen1->gen7 IV legality check
Browse files Browse the repository at this point in the history
Also fix gen1/2 evo tree trimming error, thanks BeyondTheHorizon!
Also fix an exception when no static encounter can be generated for
1->7, match is now generated by checking gen1 and reusing the static
encounter creation info (now moved to core).
  • Loading branch information
kwsch committed Mar 10, 2017
1 parent 0715f13 commit efd25a2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion PKHeX/Legality/Analysis.cs
Expand Up @@ -293,7 +293,7 @@ public EncounterStatic getSuggestedMetInfo()
}

var encounter = Legal.getStaticLocation(pkm);
if (loc != -1)
if (loc != -1 && encounter != null)
encounter.Location = loc;
return encounter;
}
Expand Down
25 changes: 10 additions & 15 deletions PKHeX/Legality/Checks.cs
Expand Up @@ -313,11 +313,15 @@ private void verifyEVs()
}
private void verifyIVs()
{
var e = EncounterMatch as EncounterStatic;
if ((EncounterMatch as EncounterStatic)?.IV3 == true)
{
if (pkm.IVs.Count(iv => iv == 31) < 3)
int IVCount = 3;
if (e.Version == GameVersion.RBY && pkm.Species == 151)
IVCount = 5; // VC Mew
if (pkm.IVs.Count(iv => iv == 31) < IVCount)
{
AddLine(Severity.Invalid, "Should have at least 3 IVs = 31.", CheckIdentifier.IVs);
AddLine(Severity.Invalid, $"Should have at least {IVCount} IVs = 31.", CheckIdentifier.IVs);
return;
}
}
Expand All @@ -334,8 +338,9 @@ private void verifyIVs()
int[] IVs;
switch (((MysteryGift) EncounterMatch).Format)
{
case 6: IVs = ((WC6)EncounterMatch).IVs; break;
case 7: IVs = ((WC7)EncounterMatch).IVs; break;
case 6: IVs = ((WC6)EncounterMatch).IVs; break;
case 5: IVs = ((PGF)EncounterMatch).IVs; break;
default: IVs = null; break;
}

Expand Down Expand Up @@ -659,18 +664,8 @@ private CheckResult verifyVCEncounter(int baseSpecies)
if (!exceptions)
AddLine(new CheckResult(Severity.Invalid, "Special encounter is not available to Virtual Console games.", CheckIdentifier.Encounter));
}

EncounterMatch = new EncounterStatic
{
Species = species,
Gift = true, // Forces Poké Ball
Ability = Legal.TransferSpeciesDefaultAbility_1.Contains(species) ? 1 : 4, // Hidden by default, else first
Shiny = species == 151 ? (bool?)false : null,
Fateful = species == 151,
Location = 30013,
EggLocation = 0,
Version = GameVersion.RBY
};

EncounterMatch = Legal.getRBYStaticTransfer(species);
var ematch = (EncounterStatic) EncounterMatch;

if (pkm.Met_Location != ematch.Location)
Expand Down
27 changes: 24 additions & 3 deletions PKHeX/Legality/Core.cs
Expand Up @@ -878,9 +878,30 @@ where slots.Any()
Location = area.Location, Slots = slots,
}).OrderBy(area => area.Slots.Min(x => x.LevelMin)).FirstOrDefault();
}
internal static EncounterStatic getStaticLocation(PKM pkm)
internal static EncounterStatic getRBYStaticTransfer(int species)
{
return getStaticEncounters(pkm, 100).OrderBy(s => s.Level).FirstOrDefault();
return new EncounterStatic
{
Species = species,
Gift = true, // Forces Poké Ball
Ability = TransferSpeciesDefaultAbility_1.Contains(species) ? 1 : 4, // Hidden by default, else first
Shiny = species == 151 ? (bool?)false : null,
Fateful = species == 151,
Location = 30013,
EggLocation = 0,
IV3 = true,
Version = GameVersion.RBY
};
}
internal static EncounterStatic getStaticLocation(PKM pkm, int species = -1)
{
switch (pkm.GenNumber)
{
case 1:
return getRBYStaticTransfer(species);
default:
return getStaticEncounters(pkm, 100).OrderBy(s => s.Level).FirstOrDefault();
}
}

public static int getLowestLevel(PKM pkm, int refSpecies = -1)
Expand Down Expand Up @@ -1123,7 +1144,7 @@ internal static DexLevel[][] getEvolutionChainsAllGens(PKM pkm, object Encounter
continue;

GensEvoChains[gen] = getEvolutionChain(pkm, Encounter, CompleteEvoChain.First().Species, lvl);
if (!pkm.HasOriginalMetLocation && gen >= pkm.GenNumber )
if (gen > 2 && !pkm.HasOriginalMetLocation && gen >= pkm.GenNumber)
//Remove previous evolutions bellow transfer level
//For example a gen3 charizar in format 7 with current level 36 and met level 36
//chain level for charmander is 35, is bellow met level
Expand Down

0 comments on commit efd25a2

Please sign in to comment.