mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-07 23:08:47 -05:00
Refactoring
add GameVersion to generation fix generating pk2 eggs relocate some logic
This commit is contained in:
@@ -43,6 +43,17 @@ public enum GameVersion
|
||||
|
||||
public static partial class Extensions
|
||||
{
|
||||
public static int GetGeneration(this GameVersion g)
|
||||
{
|
||||
if (GameVersion.Gen1.Contains(g)) return 1;
|
||||
if (GameVersion.Gen2.Contains(g)) return 2;
|
||||
if (GameVersion.Gen3.Contains(g)) return 3;
|
||||
if (GameVersion.Gen4.Contains(g)) return 4;
|
||||
if (GameVersion.Gen5.Contains(g)) return 5;
|
||||
if (GameVersion.Gen6.Contains(g)) return 6;
|
||||
if (GameVersion.Gen7.Contains(g)) return 7;
|
||||
return -1;
|
||||
}
|
||||
public static bool Contains(this GameVersion g1, GameVersion g2)
|
||||
{
|
||||
if (g1 == g2 || g1 == GameVersion.Any)
|
||||
|
||||
@@ -19,11 +19,12 @@ public class EncounterEgg : IEncounterable
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV)
|
||||
{
|
||||
var pk = PKMConverter.GetBlank(SAV.Generation);
|
||||
int gen = Game.GetGeneration();
|
||||
var pk = PKMConverter.GetBlank(gen);
|
||||
SAV.ApplyToPKM(pk);
|
||||
|
||||
pk.Species = Species;
|
||||
pk.Nickname = PKX.GetSpeciesNameGeneration(Species, pk.Language, SAV.Generation);
|
||||
pk.Nickname = PKX.GetSpeciesNameGeneration(Species, SAV.Language, gen);
|
||||
pk.CurrentLevel = Level;
|
||||
pk.Version = (int)Game;
|
||||
|
||||
@@ -42,30 +43,23 @@ public PKM ConvertToPKM(ITrainerInfo SAV)
|
||||
pk.Ball = 4;
|
||||
|
||||
pk.Met_Level = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk);
|
||||
pk.Met_Location = EncounterSuggestion.GetSuggestedEggMetLocation(pk);
|
||||
pk.Met_Location = Math.Max(0, EncounterSuggestion.GetSuggestedEggMetLocation(pk));
|
||||
|
||||
if (pk.Format < 4)
|
||||
return pk;
|
||||
|
||||
bool traded = (int)Game == SAV.Game;
|
||||
pk.Egg_Location = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(pk, traded);
|
||||
pk.EggMetDate = pk.MetDate = DateTime.Today;
|
||||
var today = pk.MetDate = DateTime.Today;
|
||||
if (pk.GenNumber >= 4)
|
||||
{
|
||||
pk.Egg_Location = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(pk, traded);
|
||||
pk.EggMetDate = today;
|
||||
}
|
||||
|
||||
if (pk.Format < 6)
|
||||
return pk;
|
||||
|
||||
if (pk.Format != SAV.Generation)
|
||||
{
|
||||
pk.HT_Name = SAV.OT;
|
||||
pk.HT_Gender = SAV.Gender;
|
||||
pk.HT_Friendship = pk.OT_Friendship;
|
||||
if (SAV.Generation == 6)
|
||||
{
|
||||
pk.Geo1_Country = SAV.Country;
|
||||
pk.Geo1_Region = SAV.SubRegion;
|
||||
}
|
||||
}
|
||||
if (SAV.Generation == 6)
|
||||
SAV.ApplyHandlingTrainerInfo(pk);
|
||||
if (pk.Gen6)
|
||||
pk.SetHatchMemory6();
|
||||
|
||||
pk.SetRandomEC();
|
||||
|
||||
@@ -49,9 +49,17 @@ public static int GetSuggestedEncounterEggMetLevel(PKM pkm)
|
||||
|
||||
public static int GetSuggestedEncounterEggLocationEgg(PKM pkm, bool traded = false)
|
||||
{
|
||||
if (pkm.Gen4)
|
||||
return traded ? 2002 : 2000;
|
||||
return traded ? 30002 : 60002;
|
||||
switch (pkm.GenNumber)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return 0;
|
||||
case 4:
|
||||
return traded ? 2002 : 2000;
|
||||
default:
|
||||
return traded ? 30002 : 60002;
|
||||
}
|
||||
}
|
||||
|
||||
private static EncounterStatic GetSuggestedEncounterWild(EncounterArea area, int loc = -1)
|
||||
@@ -124,6 +132,13 @@ public static int GetSuggestedEggMetLocation(PKM pkm)
|
||||
case GameVersion.US:
|
||||
case GameVersion.UM:
|
||||
return 50; // Route 4
|
||||
|
||||
case GameVersion.GD:
|
||||
case GameVersion.SV:
|
||||
case GameVersion.C:
|
||||
case GameVersion.GSC:
|
||||
case GameVersion.RBY:
|
||||
return pkm.Format > 2 ? Legal.Transfer2 : pkm.Met_Level == 0 ? 0 : 16; // Goldenrod City (if crystal)
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -34,5 +34,22 @@ public static void ApplyToPKM(this ITrainerInfo info, PKM pk)
|
||||
pk.Region = info.SubRegion;
|
||||
pk.ConsoleRegion = info.ConsoleRegion;
|
||||
}
|
||||
|
||||
public static void ApplyHandlingTrainerInfo(this ITrainerInfo SAV, PKM pk)
|
||||
{
|
||||
if (pk.Format == SAV.Generation)
|
||||
return;
|
||||
|
||||
pk.HT_Name = SAV.OT;
|
||||
pk.HT_Gender = SAV.Gender;
|
||||
pk.HT_Friendship = pk.OT_Friendship;
|
||||
pk.CurrentHandler = 1;
|
||||
|
||||
if (SAV.Generation == 6)
|
||||
{
|
||||
pk.Geo1_Country = SAV.Country;
|
||||
pk.Geo1_Region = SAV.SubRegion;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,10 +191,10 @@ public static void SetMaximumPPCurrent(this PKM pk, int[] Moves = null)
|
||||
if (Moves == null)
|
||||
Moves = pk.Moves;
|
||||
|
||||
pk.Move1_PP = pk.GetMovePP(Moves[0], pk.Move1_PPUps);
|
||||
pk.Move2_PP = pk.GetMovePP(Moves[1], pk.Move2_PPUps);
|
||||
pk.Move3_PP = pk.GetMovePP(Moves[2], pk.Move3_PPUps);
|
||||
pk.Move4_PP = pk.GetMovePP(Moves[3], pk.Move4_PPUps);
|
||||
pk.Move1_PP = Moves.Length <= 0 ? 0 : pk.GetMovePP(Moves[0], pk.Move1_PPUps);
|
||||
pk.Move2_PP = Moves.Length <= 1 ? 0 : pk.GetMovePP(Moves[1], pk.Move2_PPUps);
|
||||
pk.Move3_PP = Moves.Length <= 2 ? 0 : pk.GetMovePP(Moves[2], pk.Move3_PPUps);
|
||||
pk.Move4_PP = Moves.Length <= 3 ? 0 : pk.GetMovePP(Moves[3], pk.Move4_PPUps);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user