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>
|
2020-05-20 04:07:30 +00:00
|
|
|
|
public class EncounterEgg : IEncounterable
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2019-11-19 04:01:48 +00:00
|
|
|
|
public int Species { get; }
|
|
|
|
|
public int Form { get; }
|
2017-05-28 04:17:53 +00:00
|
|
|
|
public string Name => "Egg";
|
2019-03-18 05:19:37 +00:00
|
|
|
|
public string LongName => "Egg";
|
2017-05-28 04:17:53 +00:00
|
|
|
|
public bool EggEncounter => true;
|
|
|
|
|
public int LevelMin => Level;
|
|
|
|
|
public int LevelMax => Level;
|
2019-11-19 04:01:48 +00:00
|
|
|
|
public readonly int Level;
|
2020-05-17 19:32:28 +00:00
|
|
|
|
public int Generation { get; }
|
2020-05-20 04:46:05 +00:00
|
|
|
|
public GameVersion Version { get; }
|
2019-11-19 04:01:48 +00:00
|
|
|
|
|
2020-05-20 04:46:05 +00:00
|
|
|
|
public EncounterEgg(int species, int form, int level, int gen, GameVersion game)
|
2019-11-19 04:01:48 +00:00
|
|
|
|
{
|
|
|
|
|
Species = species;
|
|
|
|
|
Form = form;
|
|
|
|
|
Level = level;
|
2020-05-17 19:32:28 +00:00
|
|
|
|
Generation = gen;
|
2020-05-20 04:46:05 +00:00
|
|
|
|
Version = game;
|
2019-11-19 04:01:48 +00:00
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
|
2018-12-30 06:24:34 +00:00
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
{
|
2020-05-31 19:12:48 +00:00
|
|
|
|
int gen = Generation;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
var version = Version;
|
|
|
|
|
var pk = PKMConverter.GetBlank(gen, version);
|
2018-12-30 06:24:34 +00:00
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
sav.ApplyTo(pk);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
|
|
|
|
pk.Species = Species;
|
2020-06-17 02:46:22 +00:00
|
|
|
|
pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, sav.Language, gen);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
pk.CurrentLevel = Level;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.Version = (int)version;
|
2020-05-31 19:12:48 +00:00
|
|
|
|
pk.Ball = (int)Ball.Poke;
|
2018-03-29 03:56:58 +00:00
|
|
|
|
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
int[] moves = SetEncounterMoves(pk, version);
|
|
|
|
|
SetPINGA(pk, criteria);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2020-05-31 19:12:48 +00:00
|
|
|
|
if (gen <= 2 && version != GameVersion.C)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
return pk;
|
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
SetMetData(pk);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2020-05-31 19:12:48 +00:00
|
|
|
|
if (gen < 3)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
return pk;
|
|
|
|
|
|
2020-05-31 19:12:48 +00:00
|
|
|
|
if (gen >= 4)
|
2020-06-17 02:46:22 +00:00
|
|
|
|
pk.SetEggMetData(version, (GameVersion)sav.Game);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2020-05-31 19:12:48 +00:00
|
|
|
|
if (gen < 6)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
return pk;
|
2020-05-31 19:12:48 +00:00
|
|
|
|
if (gen == 6)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
pk.SetHatchMemory6();
|
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
SetAltForm(pk, sav);
|
2018-12-30 06:24:34 +00:00
|
|
|
|
|
|
|
|
|
pk.SetRandomEC();
|
|
|
|
|
pk.RelearnMoves = moves;
|
|
|
|
|
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
private void SetAltForm(PKM pk, ITrainerInfo sav)
|
2018-12-30 06:24:34 +00:00
|
|
|
|
{
|
2018-05-10 02:21:44 +00:00
|
|
|
|
switch (Species)
|
|
|
|
|
{
|
2019-09-10 07:21:51 +00:00
|
|
|
|
case (int)Core.Species.Minior:
|
2018-05-10 02:21:44 +00:00
|
|
|
|
pk.AltForm = Util.Rand.Next(7, 14);
|
|
|
|
|
break;
|
2019-09-10 07:21:51 +00:00
|
|
|
|
case (int)Core.Species.Scatterbug:
|
|
|
|
|
case (int)Core.Species.Spewpa:
|
|
|
|
|
case (int)Core.Species.Vivillon:
|
2020-06-17 02:46:22 +00:00
|
|
|
|
pk.AltForm = Legal.GetVivillonPattern((byte)sav.Country, (byte)sav.SubRegion);
|
2018-05-10 02:21:44 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-12-30 06:24:34 +00:00
|
|
|
|
}
|
2018-05-10 02:21:44 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
private static void SetPINGA(PKM pk, EncounterCriteria criteria)
|
2018-12-30 06:24:34 +00:00
|
|
|
|
{
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.SetRandomIVs(flawless: 3);
|
|
|
|
|
if (pk.Format <= 2)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
int gender = criteria.GetGender(-1, pk.PersonalInfo);
|
|
|
|
|
int nature = (int)criteria.GetNature(Nature.Random);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
if (pk.Format <= 5)
|
|
|
|
|
{
|
|
|
|
|
pk.SetPIDGender(gender);
|
|
|
|
|
pk.Gender = gender;
|
|
|
|
|
pk.SetPIDNature(nature);
|
|
|
|
|
pk.Nature = nature;
|
|
|
|
|
pk.RefreshAbility(pk.PIDAbility);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pk.PID = Util.Rand32();
|
|
|
|
|
pk.Nature = nature;
|
|
|
|
|
pk.Gender = gender;
|
|
|
|
|
pk.RefreshAbility(Util.Rand.Next(2));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SetMetData(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
pk.Met_Level = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk);
|
|
|
|
|
pk.Met_Location = Math.Max(0, EncounterSuggestion.GetSuggestedEggMetLocation(pk));
|
2018-03-29 03:40:07 +00:00
|
|
|
|
}
|
2018-05-10 02:21:44 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
private int[] SetEncounterMoves(PKM pk, GameVersion version)
|
|
|
|
|
{
|
|
|
|
|
int[] moves = GetCurrentEggMoves(pk, version);
|
|
|
|
|
pk.Moves = moves;
|
|
|
|
|
pk.SetMaximumPPCurrent(moves);
|
|
|
|
|
return moves;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int[] GetCurrentEggMoves(PKM pk, GameVersion version)
|
2018-05-10 02:21:44 +00:00
|
|
|
|
{
|
2019-11-19 06:20:55 +00:00
|
|
|
|
var moves = MoveEgg.GetEggMoves(pk, Species, Form, version);
|
2018-05-10 02:21:44 +00:00
|
|
|
|
if (moves.Length == 0)
|
2019-02-09 19:37:20 +00:00
|
|
|
|
return MoveLevelUp.GetEncounterMoves(pk, Level, version);
|
2018-07-23 00:14:22 +00:00
|
|
|
|
if (moves.Length >= 4 || pk.Format < 6)
|
|
|
|
|
return moves;
|
|
|
|
|
|
|
|
|
|
// Sprinkle in some default level up moves
|
2019-11-19 06:20:55 +00:00
|
|
|
|
var lvl = Legal.GetBaseEggMoves(pk, Species, Form, version, Level);
|
2018-07-23 00:14:22 +00:00
|
|
|
|
return lvl.Concat(moves).ToArray();
|
2018-05-10 02:21:44 +00:00
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2018-07-04 16:15:20 +00:00
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
public sealed class EncounterEggSplit : EncounterEgg
|
2018-07-04 16:15:20 +00:00
|
|
|
|
{
|
2019-11-19 04:01:48 +00:00
|
|
|
|
public int OtherSpecies { get; }
|
2020-05-20 04:46:05 +00:00
|
|
|
|
public EncounterEggSplit(int species, int form, int level, int gen, GameVersion game, int otherSpecies) : base(species, form, level, gen, game) => OtherSpecies = otherSpecies;
|
2018-07-04 16:15:20 +00:00
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|