2018-03-29 03:40:07 +00:00
|
|
|
|
using System;
|
2018-05-10 02:21:44 +00:00
|
|
|
|
using System.Linq;
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Egg Encounter Data
|
|
|
|
|
/// </summary>
|
2018-03-31 04:37:01 +00:00
|
|
|
|
public class EncounterEgg : IEncounterable, IVersion
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
public int Species { get; set; }
|
|
|
|
|
public string Name => "Egg";
|
|
|
|
|
public bool EggEncounter => true;
|
|
|
|
|
public int LevelMin => Level;
|
|
|
|
|
public int LevelMax => Level;
|
|
|
|
|
public int Level;
|
|
|
|
|
|
2018-03-31 04:37:01 +00:00
|
|
|
|
public GameVersion Version { get; set; }
|
2017-05-28 04:17:53 +00:00
|
|
|
|
public bool SplitBreed;
|
2018-03-29 03:38:07 +00:00
|
|
|
|
|
2018-03-29 03:40:07 +00:00
|
|
|
|
public PKM ConvertToPKM(ITrainerInfo SAV)
|
|
|
|
|
{
|
2018-04-28 23:30:56 +00:00
|
|
|
|
int gen = Version.GetGeneration();
|
|
|
|
|
if (gen < 2)
|
|
|
|
|
{
|
|
|
|
|
gen = 2;
|
|
|
|
|
Version = GameVersion.C;
|
|
|
|
|
}
|
2018-03-30 04:00:38 +00:00
|
|
|
|
var pk = PKMConverter.GetBlank(gen);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
SAV.ApplyToPKM(pk);
|
|
|
|
|
|
|
|
|
|
pk.Species = Species;
|
2018-03-30 04:00:38 +00:00
|
|
|
|
pk.Nickname = PKX.GetSpeciesNameGeneration(Species, SAV.Language, gen);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
pk.CurrentLevel = Level;
|
2018-03-31 04:37:01 +00:00
|
|
|
|
pk.Version = (int)Version;
|
2018-05-10 02:21:44 +00:00
|
|
|
|
int[] moves = GetCurrentEggMoves(pk);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
pk.Moves = moves;
|
|
|
|
|
pk.SetMaximumPPCurrent(moves);
|
2018-03-29 03:56:58 +00:00
|
|
|
|
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
|
|
|
|
|
|
|
|
|
pk.SetRandomIVs(flawless: 3);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2018-03-31 04:37:01 +00:00
|
|
|
|
if (pk.Format <= 2 && Version != GameVersion.C)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
return pk;
|
|
|
|
|
|
|
|
|
|
pk.Met_Level = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk);
|
2018-03-30 04:00:38 +00:00
|
|
|
|
pk.Met_Location = Math.Max(0, EncounterSuggestion.GetSuggestedEggMetLocation(pk));
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2018-04-01 03:37:36 +00:00
|
|
|
|
if (pk.Format < 3)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
return pk;
|
|
|
|
|
|
2018-04-01 03:37:36 +00:00
|
|
|
|
pk.Ball = 4;
|
|
|
|
|
|
2018-04-30 01:26:36 +00:00
|
|
|
|
int gender = pk.PersonalInfo.RandomGender;
|
2018-04-01 03:37:36 +00:00
|
|
|
|
int nature = Util.Rand.Next(25);
|
|
|
|
|
|
|
|
|
|
if (pk.Format <= 5)
|
|
|
|
|
{
|
|
|
|
|
pk.SetPIDGender(gender);
|
2018-04-30 01:26:36 +00:00
|
|
|
|
pk.Gender = gender;
|
2018-04-01 03:37:36 +00:00
|
|
|
|
pk.SetPIDNature(nature);
|
2018-04-30 01:26:36 +00:00
|
|
|
|
pk.Nature = nature;
|
2018-04-01 03:37:36 +00:00
|
|
|
|
pk.RefreshAbility(pk.PIDAbility);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pk.PID = Util.Rand32();
|
|
|
|
|
pk.Nature = nature;
|
|
|
|
|
pk.Gender = gender;
|
|
|
|
|
pk.RefreshAbility(Util.Rand.Next(2));
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 04:37:01 +00:00
|
|
|
|
bool traded = (int)Version == SAV.Game;
|
2018-03-30 04:00:38 +00:00
|
|
|
|
var today = pk.MetDate = DateTime.Today;
|
|
|
|
|
if (pk.GenNumber >= 4)
|
|
|
|
|
{
|
|
|
|
|
pk.Egg_Location = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(pk, traded);
|
|
|
|
|
pk.EggMetDate = today;
|
|
|
|
|
}
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
|
|
|
|
if (pk.Format < 6)
|
|
|
|
|
return pk;
|
2018-03-30 04:00:38 +00:00
|
|
|
|
if (pk.Gen6)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
pk.SetHatchMemory6();
|
|
|
|
|
|
2018-05-10 02:21:44 +00:00
|
|
|
|
switch (Species)
|
|
|
|
|
{
|
|
|
|
|
case 774: // Minior
|
|
|
|
|
pk.AltForm = Util.Rand.Next(7, 14);
|
|
|
|
|
break;
|
|
|
|
|
case 664: // Scatterbug
|
|
|
|
|
pk.AltForm = Legal.GetVivillonPattern(SAV.Country, SAV.SubRegion);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-29 03:40:07 +00:00
|
|
|
|
pk.SetRandomEC();
|
|
|
|
|
pk.RelearnMoves = moves;
|
|
|
|
|
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
2018-05-10 02:21:44 +00:00
|
|
|
|
|
|
|
|
|
private int[] GetCurrentEggMoves(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
var moves = Legal.GetEggMoves(pk, Species, pk.AltForm, Version);
|
|
|
|
|
if (moves.Length == 0)
|
|
|
|
|
moves = Legal.GetEncounterMoves(pk, Level, Version);
|
|
|
|
|
else if (moves.Length < 4 && pk.Format >= 6)
|
|
|
|
|
{
|
|
|
|
|
// Sprinkle in some default level up moves
|
|
|
|
|
var lvl = Legal.GetBaseEggMoves(pk, Species, Version, Level);
|
|
|
|
|
moves = lvl.Concat(moves).ToArray();
|
|
|
|
|
}
|
|
|
|
|
return moves;
|
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|