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";
|
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;
|
|
|
|
|
public int Level;
|
|
|
|
|
|
2018-03-31 04:37:01 +00:00
|
|
|
|
public GameVersion Version { get; set; }
|
2018-03-29 03:38:07 +00:00
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted);
|
|
|
|
|
|
|
|
|
|
public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
{
|
2018-04-28 23:30:56 +00:00
|
|
|
|
int gen = Version.GetGeneration();
|
2019-02-09 19:37:20 +00:00
|
|
|
|
var version = Version;
|
2018-04-28 23:30:56 +00:00
|
|
|
|
if (gen < 2)
|
|
|
|
|
{
|
|
|
|
|
gen = 2;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
version = GameVersion.C;
|
2018-04-28 23:30:56 +00:00
|
|
|
|
}
|
2019-02-09 19:37:20 +00:00
|
|
|
|
var pk = PKMConverter.GetBlank(gen, version);
|
2018-12-30 06:24:34 +00:00
|
|
|
|
|
2018-03-29 03:40:07 +00:00
|
|
|
|
SAV.ApplyToPKM(pk);
|
|
|
|
|
|
|
|
|
|
pk.Species = Species;
|
2019-09-19 02:58:23 +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;
|
2018-12-30 06:24:34 +00:00
|
|
|
|
pk.Ball = 4;
|
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
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
if (pk.Format <= 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
|
|
|
|
|
2018-04-01 03:37:36 +00:00
|
|
|
|
if (pk.Format < 3)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
return pk;
|
|
|
|
|
|
2018-03-30 04:00:38 +00:00
|
|
|
|
if (pk.GenNumber >= 4)
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.SetEggMetData(version, (GameVersion)SAV.Game);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
|
|
|
|
if (pk.Format < 6)
|
|
|
|
|
return pk;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
if (pk.Format == 6)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
pk.SetHatchMemory6();
|
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
SetAltForm(pk, SAV);
|
|
|
|
|
|
|
|
|
|
pk.SetRandomEC();
|
|
|
|
|
pk.RelearnMoves = moves;
|
|
|
|
|
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetAltForm(PKM pk, ITrainerInfo SAV)
|
|
|
|
|
{
|
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:
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +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-02-09 19:37:20 +00:00
|
|
|
|
var moves = MoveEgg.GetEggMoves(pk, Species, pk.AltForm, 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-02-09 19:37:20 +00:00
|
|
|
|
var lvl = Legal.GetBaseEggMoves(pk, Species, 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
|
|
|
|
{
|
|
|
|
|
public int OtherSpecies;
|
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|