Skip to content

Commit

Permalink
add vivillon edge cases
Browse files Browse the repository at this point in the history
sync with pkhex changes
  • Loading branch information
architdate committed Aug 3, 2021
1 parent ada38de commit eac0ec5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
45 changes: 42 additions & 3 deletions PKHeX.Core.AutoMod/AutoMod/APILegality.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,10 @@ private static void SetIVsPID(this PKM pk, IBattleTemplate set, PIDType method,
do PIDGenerator.SetRandomPokeSpotPID(pk, pk.Nature, pk.Gender, abil, es3ps.SlotNumber);
while (pk.PID % 25 != pk.Nature);
return;
case PGT { IsManaphyEgg:false } d:
case PCD d:
{
if (d.PK.PID != 1)
pk.PID = d.PK.PID;
if (d.Gift.PK.PID != 1)
pk.PID = d.Gift.PK.PID;
else if (pk.Nature != pk.PID % 25)
pk.SetPIDNature(pk.Nature);
return;
Expand Down Expand Up @@ -1039,6 +1039,10 @@ private static void FixEdgeCases(this PKM pk, IEncounterable enc)
// VC Games are locked to console region (modify based on language)
if (pk is PK7 pk7 && pk7.Generation <= 2)
pk7.FixVCRegion();

// Vivillon pattern fixes if necessary
if (pk is IGeoTrack && pk.Species is (int)Species.Vivillon or (int)Species.Spewpa or (int)Species.Scatterbug)
pk.FixVivillonRegion();
}

/// <summary>
Expand Down Expand Up @@ -1079,6 +1083,41 @@ public static void FixVCRegion(this PK7 pk7)
}
}

/// <summary>
/// Handle edge case vivillon legality if the trainerdata region is invalid
/// </summary>
/// <param name="pk">pkm to fix</param>
public static void FixVivillonRegion(this PKM pk)
{
if (pk is not IGeoTrack g)
return;
var valid = Vivillon3DS.IsPatternValid(pk.Form, g.ConsoleRegion);
if (valid)
return;
// 5: JP
// 7, 14: USA
// else: EUR
switch (pk.Form)
{
case 5:
g.ConsoleRegion = 0;
g.Region = 0;
g.Country = 1;
break;
case 7:
case 14:
g.ConsoleRegion = 1;
g.Region = 0;
g.Country = 49;
break;
default:
g.ConsoleRegion = 2;
g.Region = 0;
g.Country = 105;
break;
}
}

/// <summary>
/// Wrapper function for GetLegalFromTemplate but with a Timeout
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions PKHeX.Core.AutoMod/AutoMod/Legalization/ShowdownEdits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ public static void SetSpeciesLevel(this PKM pk, IBattleTemplate set, int Form, I
pk.CurrentLevel = set.Level;
if (pk.Met_Level > pk.CurrentLevel)
pk.Met_Level = pk.CurrentLevel;
if ((enc is EncounterSlot8 esl && esl.Weather is AreaWeather8.Heavy_Fog) || (enc is EncounterStatic8 est && est.Weather is AreaWeather8.Heavy_Fog))
pk.Met_Level = EncounterArea8.BoostLevel;
if (set.Level != 100 && set.Level == enc.LevelMin && (pk.Format == 3 || pk.Format == 4))
pk.EXP = Experience.GetEXP(enc.LevelMin + 1, PersonalTable.HGSS[enc.Species].EXPGrowth) - 1;

Expand Down Expand Up @@ -239,6 +237,7 @@ public static void SetMovesEVs(this PKM pk, IBattleTemplate set, IEncounterable
var la = new LegalityAnalysis(pk);
if (la.Parsed && !pk.FatefulEncounter)
{
// For dexnav. Certain encounters come with "random" relearn moves, and our requested moves might require one of them.
var relearn = la.GetSuggestedRelearnMoves(enc);
pk.ClearRelearnMoves();
pk.SetRelearnMoves(relearn);
Expand Down
2 changes: 2 additions & 0 deletions PKHeX.Core.AutoMod/AutoMod/Legalization/SimpleEdits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ public static void SetAllTrainerData(this PKM pk, ITrainerInfo trainer)
gt.Region = o.Region;
if (pk is PK7 pk7 && pk.Generation <= 2)
pk7.FixVCRegion();
if (pk.Species is (int)Species.Vivillon or (int)Species.Spewpa or (int)Species.Scatterbug)
pk.FixVivillonRegion();
return;
}

Expand Down
6 changes: 3 additions & 3 deletions PKHeX.Core.AutoMod/AutoMod/Trainers/PokeTrainerDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public class PokeTrainerDetails : ITrainerInfo, IRegionOrigin
public int Game => pkm.Version;
public int Language { get => pkm.Language; set => pkm.Language = value; }

public int Country { get => pkm is IGeoTrack gt ? gt.Country : 0; set { if (pkm is IGeoTrack gt) gt.Country = value; } }
public int Region { get => pkm is IGeoTrack gt ? gt.Region : 0; set { if (pkm is IGeoTrack gt) gt.Region = value; } }
public int ConsoleRegion { get => pkm is IGeoTrack gt ? gt.ConsoleRegion : 0; set { if (pkm is IGeoTrack gt) gt.ConsoleRegion = value; } }
public byte Country { get => pkm is IGeoTrack gt ? gt.Country : (byte)0; set { if (pkm is IGeoTrack gt) gt.Country = value; } }
public byte Region { get => pkm is IGeoTrack gt ? gt.Region : (byte)0; set { if (pkm is IGeoTrack gt) gt.Region = value; } }
public byte ConsoleRegion { get => pkm is IGeoTrack gt ? gt.ConsoleRegion : (byte)0; set { if (pkm is IGeoTrack gt) gt.ConsoleRegion = value; } }
public int Generation => pkm.Generation;

public static PokeTrainerDetails Clone(PokeTrainerDetails p) => new(p.pkm.Clone());
Expand Down

0 comments on commit eac0ec5

Please sign in to comment.