More generator updates

Blazing past 251, now stopped at 280 (trade ralts, gender mismatch??)
This commit is contained in:
Kurt
2018-05-08 20:13:55 -07:00
parent 4d60a5a64e
commit c21f8bf45f
5 changed files with 62 additions and 22 deletions

View File

@@ -59,6 +59,7 @@ public PKM ConvertToPKM(ITrainerInfo SAV)
SAV.ApplyToPKM(pk);
pk.Version = (int)version;
pk.Gender = pk.PersonalInfo.RandomGender;
pk.Language = lang;
var moves = Moves.Length != 0 ? Moves : Legal.GetEncounterMoves(pk, Level, version);
@@ -72,9 +73,8 @@ public PKM ConvertToPKM(ITrainerInfo SAV)
if (RibbonClassic)
pk.RibbonClassic = true;
if (OT)
pk.SetRandomMemory6();
else
pk.SetRandomMemory6();
if (!OT)
SAV.ApplyHandlingTrainerInfo(pk);
return pk;

View File

@@ -79,9 +79,14 @@ public PKM ConvertToPKM(ITrainerInfo SAV)
pk.Language = lang;
pk.CurrentLevel = level;
pk.Version = (int)version;
pk.AltForm = Form;
pk.Nickname = PKX.GetSpeciesNameGeneration(Species, lang, Generation);
pk.Ball = GetBall();
if (Form != 31)
pk.AltForm = Form;
else if (Species == 664 || Species == 665 || Species == 666)
pk.AltForm = Legal.GetVivillonPattern(SAV.Country, SAV.SubRegion);
else
pk.AltForm = Util.Rand.Next(pk.PersonalInfo.FormeCount);
if (pk.Format > 2 || Version == GameVersion.C)
{

View File

@@ -213,18 +213,8 @@ private static IEnumerable<EncounterStatic> GetStatic(PKM pk, IReadOnlyCollectio
var encs = EncounterStaticGenerator.GetPossible(pk);
foreach (var enc in encs)
{
if (enc.Generation == 4)
{
switch (pk.Species)
{
case 491 when enc.Location == 079 && !pk.Pt: // DP Darkrai
continue;
case 492 when enc.Location == 063 && !pk.Pt: // DP Shaymin
continue;
case 493 when enc.Location == 086: // Azure Flute Arceus
continue;
}
}
if (enc.IsUnobtainable(pk))
continue;
if (needs.Count == 0)
{
yield return enc;
@@ -270,7 +260,7 @@ private static IEnumerable<EncounterSlot> GetSlots(PKM pk, IReadOnlyCollection<i
var slots = EncounterSlotGenerator.GetPossible(pk);
foreach (var slot in slots)
{
if (IsImpossibleSlot(pk, slot))
if (slot.IsUnobtainable(pk))
continue;
if (needs.Count == 0)
@@ -285,7 +275,7 @@ private static IEnumerable<EncounterSlot> GetSlots(PKM pk, IReadOnlyCollection<i
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsImpossibleSlot(PKM pk, EncounterSlot slot)
private static bool IsUnobtainable(this EncounterSlot slot, PKM pk)
{
switch (slot.Generation)
{
@@ -305,5 +295,30 @@ private static bool IsImpossibleSlot(PKM pk, EncounterSlot slot)
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsUnobtainable(this EncounterStatic enc, PKM pk)
{
switch (enc.Generation)
{
case 4 when enc is EncounterStaticTyped t:
if (enc.Location == 193 && t.TypeEncounter == EncounterType.Surfing_Fishing) // Johto Route 45 surfing encounter. Unreachable Water tiles.
return true; // only hits for Roamer Raikou
break;
case 4:
switch (pk.Species)
{
case 491 when enc.Location == 079 && !pk.Pt: // DP Darkrai
return true;
case 492 when enc.Location == 063 && !pk.Pt: // DP Shaymin
return true;
case 493 when enc.Location == 086: // Azure Flute Arceus
return true;
}
break;
}
return false;
}
}
}

View File

@@ -9,7 +9,11 @@ private static void SetValuesFromSeedLCRNG(PKM pk, PIDType type, uint seed)
var rng = RNG.LCRNG;
var A = rng.Next(seed);
var B = rng.Next(A);
pk.PID = B & 0xFFFF0000 | A >> 16;
var pid = B & 0xFFFF0000 | A >> 16;
if (type == PIDType.Method_1_Unown || type == PIDType.Method_2_Unown || type == PIDType.Method_4_Unown)
pk.PID = (pid >> 16) | (pid << 16); // swap halves
else
pk.PID = pid;
var skipIV1Frame = type == PIDType.Method_2 || type == PIDType.Method_2_Unown;
if (skipIV1Frame)
@@ -74,11 +78,10 @@ private static void SetValuesFromSeedXDRNG(PKM pk, uint seed)
pk.SID = (int)((seed = rng.Next(seed)) >> 16);
seed = rng.Advance(seed, 2); // PID calls consumed
break;
case 196:
case 196: // Colo Espeon
pk.TID = (int)((seed = rng.Next(seed)) >> 16);
pk.SID = (int)((seed = rng.Next(seed)) >> 16);
seed = rng.Advance(seed, 5); // skip over Umbreon
seed = rng.Advance(seed, 2); // PID calls consumed
seed = rng.Advance(seed, 9); // PID calls consumed, skip over Umbreon
break;
}
var A = rng.Next(seed); // IV1

View File

@@ -263,5 +263,22 @@ public static bool CheckVivillonPattern(int form, int country, int region)
return ct.otherforms.Any(e => e.form == form && e.region.Contains(region));
}
/// <summary>
/// Compares the Vivillon pattern against its country and region to determine if the pattern is able to be obtained legally.
/// </summary>
/// <param name="country">Country ID</param>
/// <param name="region">Console Region ID</param>
public static int GetVivillonPattern(int country, int region)
{
CountryTable ct = RegionFormTable.Where(t => t.countryID == country).FirstOrDefault();
if (ct.otherforms == null) // empty struct = no forms referenced
return ct.mainform; // No subregion table
foreach (var sub in ct.otherforms)
if (sub.region.Contains(region))
return sub.form;
return ct.mainform;
}
}
}