Simplify vc transfer checks

supply met level so the static encounter has a level to work with
instead of 0
Closes #1316

in other areas:
level 48 charizard VC1 transfer changed to mewtwo causes minlvl >
maxlevel, handle instead of throwing exception.
This commit is contained in:
Kurt 2017-07-09 08:47:17 -07:00
parent 04a11ae030
commit cb76d51e38
4 changed files with 28 additions and 24 deletions

View file

@ -119,12 +119,6 @@ namespace PKHeX.Core
UpdateInfo();
UpdateTypeInfo();
if (pk.Format > 2) // transferred
{
EncounterOriginalGB = EncounterMatch;
foreach (var z in VerifyVCEncounter(pkm, EncounterMatch.Species, EncounterMatch as GBEncounterData))
AddLine(z);
}
VerifyNickname();
VerifyDVs();
VerifyEVs();
@ -188,17 +182,28 @@ namespace PKHeX.Core
{ AddLine(Severity.Invalid, V187, CheckIdentifier.GameOrigin); return; }
UpdateInfo();
if (pkm.VC)
UpdateVCTransferInfo();
UpdateTypeInfo();
UpdateChecks();
}
private void UpdateVCTransferInfo()
{
EncounterOriginalGB = EncounterMatch;
if (pkm.VC1)
Info.EncounterMatch = EncounterGenerator.GetRBYStaticTransfer(pkm.Species, pkm.Met_Level);
else if (pkm.VC2)
Info.EncounterMatch = EncounterGenerator.GetGSStaticTransfer(pkm.Species, pkm.Met_Level);
foreach (var z in VerifyVCEncounter(pkm, EncounterOriginalGB.Species, EncounterOriginalGB as GBEncounterData, Info.EncounterMatch as EncounterStatic))
AddLine(z);
}
private void UpdateInfo()
{
Info = EncounterFinder.FindVerifiedEncounter(pkm);
Encounter = Info.Parse[0];
Parse.AddRange(Info.Parse);
}
private void UpdateTradebackG12()
{
if (pkm.Format == 1)
@ -260,9 +265,9 @@ namespace PKHeX.Core
if (pkm.Format >= 7)
{
if (pkm.VC1)
Info.EncounterMatch = EncounterGenerator.GetRBYStaticTransfer(pkm.Species);
Info.EncounterMatch = EncounterGenerator.GetRBYStaticTransfer(pkm.Species, pkm.Met_Level);
else if (pkm.VC2)
Info.EncounterMatch = EncounterGenerator.GetGSStaticTransfer(pkm.Species);
Info.EncounterMatch = EncounterGenerator.GetGSStaticTransfer(pkm.Species, pkm.Met_Level);
}
if (pkm.GenNumber <= 2 && pkm.TradebackStatus == TradebackType.Any && (EncounterMatch as GBEncounterData)?.Generation != pkm.GenNumber)

View file

@ -580,16 +580,10 @@ namespace PKHeX.Core
}
}
}
private static IEnumerable<CheckResult> VerifyVCEncounter(PKM pkm, int baseSpecies, GBEncounterData encounter)
private static IEnumerable<CheckResult> VerifyVCEncounter(PKM pkm, int baseSpecies, GBEncounterData encounter, EncounterStatic transfer)
{
// Sanitize Species to non-future species#
int species = pkm.Species;
if (pkm.VC1 && species > Legal.MaxSpeciesID_1 ||
pkm.VC2 && species > Legal.MaxSpeciesID_2)
species = baseSpecies;
// Check existing EncounterMatch
if (encounter == null)
if (encounter == null || transfer == null)
yield break; // Avoid duplicate invaild message
if (encounter.Encounter is EncounterStatic v && (GameVersion.GBCartEraOnly.Contains(v.Version) || v.Version == GameVersion.VCEvents))
@ -600,13 +594,12 @@ namespace PKHeX.Core
yield return new CheckResult(Severity.Invalid, V79, CheckIdentifier.Encounter);
}
var ematch = EncounterGenerator.GetRBYStaticTransfer(species);
if (pkm.Met_Location != ematch.Location)
if (pkm.Met_Location != transfer.Location)
yield return new CheckResult(Severity.Invalid, V81, CheckIdentifier.Encounter);
if (pkm.Egg_Location != ematch.EggLocation)
if (pkm.Egg_Location != transfer.EggLocation)
yield return new CheckResult(Severity.Invalid, V59, CheckIdentifier.Encounter);
if (species == 150 && pkm.Moves.Contains(6)) // pay day
if (baseSpecies == 150 && pkm.Moves.Contains(6)) // pay day
yield return new CheckResult(Severity.Invalid, V82, CheckIdentifier.Encounter);
}
#endregion

View file

@ -1301,12 +1301,14 @@ namespace PKHeX.Core
switch (pkm.GenNumber)
{
case 1:
return GetRBYStaticTransfer(species);
return GetRBYStaticTransfer(species, pkm.Met_Level);
case 2:
return GetGSStaticTransfer(species, pkm.Met_Level);
default:
return GetStaticEncounters(pkm, 100).OrderBy(s => s.Level).FirstOrDefault();
}
}
internal static EncounterStatic GetRBYStaticTransfer(int species)
internal static EncounterStatic GetRBYStaticTransfer(int species, int pkmMetLevel)
{
return new EncounterStatic
{
@ -1318,10 +1320,11 @@ namespace PKHeX.Core
Location = 30013,
EggLocation = 0,
IV3 = true,
Level = pkmMetLevel,
Version = GameVersion.RBY
};
}
internal static EncounterStatic GetGSStaticTransfer(int species)
internal static EncounterStatic GetGSStaticTransfer(int species, int pkmMetLevel)
{
return new EncounterStatic
{
@ -1333,6 +1336,7 @@ namespace PKHeX.Core
Location = 30004, // todo
EggLocation = 0,
IV3 = true,
Level = pkmMetLevel,
Version = GameVersion.GS
};
}

View file

@ -20,6 +20,8 @@ namespace PKHeX.Core
{
if (minLevel <= 1 && maxLevel >= 100)
return Moves;
if (minLevel > maxLevel)
return new int[0];
int start = Array.FindIndex(Levels, z => z >= minLevel);
if (start < 0)
return new int[0];