Refactoring

add GameVersion to generation
fix generating pk2 eggs
relocate some logic
This commit is contained in:
Kurt
2018-03-29 21:00:38 -07:00
parent e74e7878cd
commit 2ea1fea5f5
5 changed files with 62 additions and 25 deletions

View File

@@ -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)

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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;
}
}
}
}

View File

@@ -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>