2018-03-31 07:43:41 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Wild Encounter Slot data
|
|
|
|
|
/// </summary>
|
2018-03-30 23:31:40 +00:00
|
|
|
|
public class EncounterSlot : IEncounterable, IGeneration, ILocation, IVersion
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
2017-01-05 06:25:45 +00:00
|
|
|
|
public int Species { get; set; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int Form { get; set; }
|
Gen 1 move analysis improvement. Adapted the valid moves to take into account that move deleter and move reminder do not exits in generation 1 (#1037)
* Fix getMoves with min level, when SkipWhile and TakeWhile is used together the index i in TakeWhile is calculated from the enumerator that results of the SkipWhile function, not the index of the initial array, those giving an incorrect index to check Levels array in the TakeWhile
* Fix getMoves when levelmin or levelmax is above max level in the levels array, TakeWhile and SkipWhile return empty list if the while goes beyond the last element of the array
* Include player hatched egg in the list of possible encounters for parseMoves only if the pokemon was an egg
Also change the valur of WasEgg for gen1,2,3 pokemon if the encounter analyzed is not an egg
add the non egg encounters to the list instead of checking the non-egg encounter inside parseMovesWasEggPreRelearn
* Fix for gen3 egg encounters
Remove non-egg encounters without special moves if there is an egg encounter because egg encounter already cover every possible move combination
Do not add daycare egg encounter for gen3 unhatched egg if there is another encounter, that means is an event or gift egg, not a daycare egg
Remove duplicate encounters
* Gift egg should not allow inherited moves even it they dont have special moves
Those gift eggs are hatched only with the species base moves
* Added getEncounterMoves functions, to be used for generation 1 encounters to find what moves have a pokemon at the moment of being caught because there is no move reminder in generation 1
* Added GBEncounterData, structure for refactor the tuples used in generation 1 and 2 encounters
* Add LevelMin and LevelMax to IEncounterable to get the encounter moves by the min level of the generation 1 EncounterLink
Add iGeneration to difference generation 1 and generation 2 encounters for GB Era pokemon
* Mark generation in gen 1 and 2 encounters
There is no need to mark the generation in gen 3 to 7 encounters because in that generations it match the pokemon generation number
* Add min level for generation 1 moves in getMoves functions
Add function to return the default moves for a GB encounters, for generation 1 games that included both moves from level up table and level 1 moves from personal table
Fix getMoves with min level when the moves list is empty, like Raichu generation 1
* Add maxSpecies to getBaseSpecies function for gen1 pokemon with a gen2 egg encounter
Refactor VC Encounter changing Tuples for GBData class
* Fixed for gen 2 Checks
Also do not search for generation1 encounter if the gen2 pokemon have met location from crystal
* Fix VC wild encounters, should be stored as array or else other verifyEncounter functions wont work
* Add generation 1 parse moves function including default moves
* Clean-up get encounters
* Verify empty moves for generation 1 encounters, in generation 1 does not exits move deleter
That means when a move slot have been used by a level up move or a TM/HM/Tutor move it cant be empty again
Does not apply if generation 2 tradeback is allowed, in generation 2 there is a move deleter
* Added two edge cases for pokemon that learn in red/blue and yellow different moves at the same level, this combinations can not exits until a later level when they learn again one of the levels in the other game, only happen for flareon and vaporeon
* Check incompatible moves between evolution species, it is for species that learn a move in a level as an evolved species and a move at a upper level as a preevolution
Also added most edge cases for the min slots used for generation 1 games, i think every weird combination is already covered
* Fix gen 1 eevee and evolutions move checks
* Cleanup
* Move the code to change valid moves for generation 1 to a function
* Fix getMoveMinLevelGBEncounter
* getUsedMoveSlots, removed wild Butterfree edge case, it is not possible
* Filter the min level of the encounter by the possible games the pokemon could be originated, yellow pikachu and kadabra can be detected
2017-04-09 00:17:20 +00:00
|
|
|
|
public int LevelMin { get; set; }
|
|
|
|
|
public int LevelMax { get; set; }
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
Fix flute level amp direction
The inputs to "IsLevelWithinRange" are the highest value the
lowest-level can be, and the lowest value the highest level can be...
seems confusing (hence the original error).
If a slot is 6-7, with a wild encounter (flute), we can go +/-3 from
6-7, which is 3-10.
With an encounter of level 5, the inputs are: 5+3, and 5-3 (8, 2).
Since 8>lvlmin and 2<lvlhi, we can get a level 5 pkm from the slot
(using a negative flute yielding a -1 adjustment).
I could probably refactor it to be a 3-input signature (lvl, lvlneg,
lvlpos), and have it do LevelMin - lvlneg <= lvl && lvl <= LevelMax +
lvlpos
I should probably refactor these methods to do minLevel & maxLevel (so
baseSpecies.Level to CurrentLevel for pkm that lost their original met
data) but nothing needs the extra logic at this time.
2019-09-20 05:37:56 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets if the specified level inputs are within range of the <see cref="LevelMin"/> and <see cref="LevelMax"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="lvl">Single level</param>
|
|
|
|
|
/// <returns>True if within slot's range, false if impossible.</returns>
|
|
|
|
|
/// <remarks>Use <see cref="IsLevelWithinRange(int, int)"/> if <see cref="lvl"/> can have a range of values</remarks>
|
2019-09-13 06:20:52 +00:00
|
|
|
|
public bool IsLevelWithinRange(int lvl) => LevelMin <= lvl && lvl <= LevelMax;
|
Fix flute level amp direction
The inputs to "IsLevelWithinRange" are the highest value the
lowest-level can be, and the lowest value the highest level can be...
seems confusing (hence the original error).
If a slot is 6-7, with a wild encounter (flute), we can go +/-3 from
6-7, which is 3-10.
With an encounter of level 5, the inputs are: 5+3, and 5-3 (8, 2).
Since 8>lvlmin and 2<lvlhi, we can get a level 5 pkm from the slot
(using a negative flute yielding a -1 adjustment).
I could probably refactor it to be a 3-input signature (lvl, lvlneg,
lvlpos), and have it do LevelMin - lvlneg <= lvl && lvl <= LevelMax +
lvlpos
I should probably refactor these methods to do minLevel & maxLevel (so
baseSpecies.Level to CurrentLevel for pkm that lost their original met
data) but nothing needs the extra logic at this time.
2019-09-20 05:37:56 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets if the specified level inputs are within range of the <see cref="LevelMin"/> and <see cref="LevelMax"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="min">Highest value the low end of levels can be</param>
|
|
|
|
|
/// <param name="max">Lowest value the high end of levels can be</param>
|
|
|
|
|
/// <returns>True if within slot's range, false if impossible.</returns>
|
2019-09-13 06:20:52 +00:00
|
|
|
|
public bool IsLevelWithinRange(int min, int max) => LevelMin <= min && max <= LevelMax;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public SlotType Type { get; set; } = SlotType.Any;
|
|
|
|
|
public EncounterType TypeEncounter { get; set; } = EncounterType.None;
|
|
|
|
|
public int SlotNumber { get; set; }
|
Gen 1 move analysis improvement. Adapted the valid moves to take into account that move deleter and move reminder do not exits in generation 1 (#1037)
* Fix getMoves with min level, when SkipWhile and TakeWhile is used together the index i in TakeWhile is calculated from the enumerator that results of the SkipWhile function, not the index of the initial array, those giving an incorrect index to check Levels array in the TakeWhile
* Fix getMoves when levelmin or levelmax is above max level in the levels array, TakeWhile and SkipWhile return empty list if the while goes beyond the last element of the array
* Include player hatched egg in the list of possible encounters for parseMoves only if the pokemon was an egg
Also change the valur of WasEgg for gen1,2,3 pokemon if the encounter analyzed is not an egg
add the non egg encounters to the list instead of checking the non-egg encounter inside parseMovesWasEggPreRelearn
* Fix for gen3 egg encounters
Remove non-egg encounters without special moves if there is an egg encounter because egg encounter already cover every possible move combination
Do not add daycare egg encounter for gen3 unhatched egg if there is another encounter, that means is an event or gift egg, not a daycare egg
Remove duplicate encounters
* Gift egg should not allow inherited moves even it they dont have special moves
Those gift eggs are hatched only with the species base moves
* Added getEncounterMoves functions, to be used for generation 1 encounters to find what moves have a pokemon at the moment of being caught because there is no move reminder in generation 1
* Added GBEncounterData, structure for refactor the tuples used in generation 1 and 2 encounters
* Add LevelMin and LevelMax to IEncounterable to get the encounter moves by the min level of the generation 1 EncounterLink
Add iGeneration to difference generation 1 and generation 2 encounters for GB Era pokemon
* Mark generation in gen 1 and 2 encounters
There is no need to mark the generation in gen 3 to 7 encounters because in that generations it match the pokemon generation number
* Add min level for generation 1 moves in getMoves functions
Add function to return the default moves for a GB encounters, for generation 1 games that included both moves from level up table and level 1 moves from personal table
Fix getMoves with min level when the moves list is empty, like Raichu generation 1
* Add maxSpecies to getBaseSpecies function for gen1 pokemon with a gen2 egg encounter
Refactor VC Encounter changing Tuples for GBData class
* Fixed for gen 2 Checks
Also do not search for generation1 encounter if the gen2 pokemon have met location from crystal
* Fix VC wild encounters, should be stored as array or else other verifyEncounter functions wont work
* Add generation 1 parse moves function including default moves
* Clean-up get encounters
* Verify empty moves for generation 1 encounters, in generation 1 does not exits move deleter
That means when a move slot have been used by a level up move or a TM/HM/Tutor move it cant be empty again
Does not apply if generation 2 tradeback is allowed, in generation 2 there is a move deleter
* Added two edge cases for pokemon that learn in red/blue and yellow different moves at the same level, this combinations can not exits until a later level when they learn again one of the levels in the other game, only happen for flareon and vaporeon
* Check incompatible moves between evolution species, it is for species that learn a move in a level as an evolved species and a move at a upper level as a preevolution
Also added most edge cases for the min slots used for generation 1 games, i think every weird combination is already covered
* Fix gen 1 eevee and evolutions move checks
* Cleanup
* Move the code to change valid moves for generation 1 to a function
* Fix getMoveMinLevelGBEncounter
* getUsedMoveSlots, removed wild Butterfree edge case, it is not possible
* Filter the min level of the encounter by the possible games the pokemon could be originated, yellow pikachu and kadabra can be detected
2017-04-09 00:17:20 +00:00
|
|
|
|
public int Generation { get; set; } = -1;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
internal EncounterSlotPermissions _perm;
|
|
|
|
|
public EncounterSlotPermissions Permissions => _perm ?? (_perm = new EncounterSlotPermissions());
|
2018-03-30 23:31:40 +00:00
|
|
|
|
public GameVersion Version { get; set; }
|
2017-05-17 04:09:53 +00:00
|
|
|
|
|
2018-03-30 23:31:40 +00:00
|
|
|
|
internal EncounterArea Area { private get; set; }
|
2018-01-02 20:00:41 +00:00
|
|
|
|
public int Location { get => Area.Location; set { } }
|
|
|
|
|
public bool EggEncounter => false;
|
|
|
|
|
public int EggLocation { get => 0; set { } }
|
|
|
|
|
|
2017-12-03 20:20:49 +00:00
|
|
|
|
public EncounterSlot Clone()
|
|
|
|
|
{
|
|
|
|
|
var slot = (EncounterSlot) MemberwiseClone();
|
|
|
|
|
if (_perm != null)
|
|
|
|
|
slot._perm = Permissions.Clone();
|
|
|
|
|
return slot;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 00:33:03 +00:00
|
|
|
|
public bool FixedLevel => LevelMin == LevelMax;
|
2017-01-04 04:51:33 +00:00
|
|
|
|
|
2017-12-03 20:20:49 +00:00
|
|
|
|
public bool IsMatchStatic(int index, int count) => index == Permissions.StaticIndex && count == Permissions.StaticCount;
|
|
|
|
|
public bool IsMatchMagnet(int index, int count) => index == Permissions.MagnetPullIndex && count == Permissions.MagnetPullCount;
|
|
|
|
|
|
2019-03-18 05:19:37 +00:00
|
|
|
|
private const string wild = "Wild Encounter";
|
|
|
|
|
public string Name => wild;
|
|
|
|
|
|
|
|
|
|
public string LongName
|
2017-02-15 06:06:15 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Type == SlotType.Any)
|
|
|
|
|
return wild;
|
2019-02-08 05:40:20 +00:00
|
|
|
|
return $"{wild} {Type.ToString().Replace('_', ' ')}";
|
2017-02-15 06:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
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-31 07:43:41 +00:00
|
|
|
|
{
|
|
|
|
|
var version = this.GetCompatibleVersion((GameVersion)SAV.Game);
|
2019-09-19 02:58:23 +00:00
|
|
|
|
int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)SAV.Language);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
int level = LevelMin;
|
2018-11-20 00:14:49 +00:00
|
|
|
|
var pk = PKMConverter.GetBlank(Generation, Version);
|
2018-04-01 03:37:36 +00:00
|
|
|
|
SAV.ApplyToPKM(pk);
|
|
|
|
|
|
2018-03-31 07:43:41 +00:00
|
|
|
|
pk.Species = Species;
|
|
|
|
|
pk.Language = lang;
|
|
|
|
|
pk.CurrentLevel = level;
|
2018-04-28 23:30:56 +00:00
|
|
|
|
pk.Version = (int)version;
|
2019-09-19 02:58:23 +00:00
|
|
|
|
pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, lang, Generation);
|
2018-12-30 06:24:34 +00:00
|
|
|
|
pk.Ball = (int)Type.GetBall();
|
2018-03-31 07:43:41 +00:00
|
|
|
|
pk.Language = lang;
|
2018-12-30 06:24:34 +00:00
|
|
|
|
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
|
|
|
|
pk.AltForm = GetWildAltForm(pk, Form, SAV);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
SetMetData(pk, level, Location);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
SetPINGA(pk, criteria);
|
|
|
|
|
SetEncounterMoves(pk, version, level);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
SetFormatSpecificData(pk);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
|
|
|
|
|
if (pk.Format < 6)
|
|
|
|
|
return pk;
|
|
|
|
|
|
|
|
|
|
SAV.ApplyHandlingTrainerInfo(pk);
|
|
|
|
|
pk.SetRandomEC();
|
|
|
|
|
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
2018-04-29 16:31:13 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
private void SetEncounterMoves(PKM pk, GameVersion version, int level)
|
|
|
|
|
{
|
|
|
|
|
var moves = this is EncounterSlotMoves m ? m.Moves : MoveLevelUp.GetEncounterMoves(pk, level, version);
|
|
|
|
|
pk.Moves = moves;
|
|
|
|
|
pk.SetMaximumPPCurrent(moves);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
private void SetFormatSpecificData(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
if (pk is PK1 pk1)
|
|
|
|
|
{
|
|
|
|
|
if (Species == 64 && Version == GameVersion.YW) // Kadabra
|
|
|
|
|
pk1.Catch_Rate = 96;
|
|
|
|
|
else if (Species == 148 && Version == GameVersion.YW) // Dragonair
|
|
|
|
|
pk1.Catch_Rate = 27;
|
|
|
|
|
else
|
|
|
|
|
pk1.Catch_Rate = PersonalTable.RB[Species].CatchRate; // RB
|
|
|
|
|
}
|
|
|
|
|
else if (pk is PK2 pk2)
|
|
|
|
|
{
|
|
|
|
|
if (Version == GameVersion.C && this is EncounterSlot1 slot)
|
|
|
|
|
pk2.Met_TimeOfDay = slot.Time.RandomValidTime();
|
|
|
|
|
}
|
|
|
|
|
else if (pk is XK3 xk3)
|
|
|
|
|
{
|
|
|
|
|
xk3.FatefulEncounter = true; // PokeSpot
|
|
|
|
|
}
|
|
|
|
|
else if (pk is PK4 pk4)
|
|
|
|
|
{
|
|
|
|
|
pk4.EncounterType = TypeEncounter.GetIndex();
|
|
|
|
|
}
|
|
|
|
|
else if (pk is PK6 pk6)
|
|
|
|
|
{
|
|
|
|
|
if (Permissions.IsDexNav)
|
|
|
|
|
{
|
|
|
|
|
var eggMoves = MoveEgg.GetEggMoves(pk, Species, pk.AltForm, Version);
|
|
|
|
|
if (eggMoves.Length > 0)
|
|
|
|
|
pk6.RelearnMove1 = eggMoves[Util.Rand.Next(eggMoves.Length)];
|
|
|
|
|
}
|
|
|
|
|
pk.SetRandomMemory6();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
private void SetPINGA(PKM pk, EncounterCriteria criteria)
|
2018-12-30 06:24:34 +00:00
|
|
|
|
{
|
|
|
|
|
int gender = criteria.GetGender(-1, pk.PersonalInfo);
|
|
|
|
|
int nature = (int)criteria.GetNature(Nature.Random);
|
|
|
|
|
|
|
|
|
|
var ability = Util.Rand.Next(2);
|
|
|
|
|
if (Type == SlotType.HiddenGrotto) // don't force hidden for DexNav
|
|
|
|
|
ability = 2;
|
|
|
|
|
|
|
|
|
|
var pidtype = GetPIDType();
|
|
|
|
|
if (pidtype == PIDType.PokeSpot)
|
|
|
|
|
PIDGenerator.SetRandomPokeSpotPID(pk, nature, gender, ability, SlotNumber);
|
|
|
|
|
else
|
|
|
|
|
PIDGenerator.SetRandomWildPID(pk, pk.Format, nature, ability, gender, pidtype);
|
|
|
|
|
pk.Gender = gender;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetMetData(PKM pk, int level, int location)
|
|
|
|
|
{
|
|
|
|
|
if (pk.Format <= 2 && Version != GameVersion.C)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
pk.Met_Location = location;
|
|
|
|
|
pk.Met_Level = level;
|
|
|
|
|
|
|
|
|
|
if (pk.Format >= 4)
|
|
|
|
|
pk.MetDate = DateTime.Today;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int GetWildAltForm(PKM pk, int form, ITrainerInfo SAV)
|
2018-05-10 02:21:44 +00:00
|
|
|
|
{
|
2019-09-10 07:21:51 +00:00
|
|
|
|
if (form < 30) // specified form
|
2018-05-10 02:21:44 +00:00
|
|
|
|
{
|
|
|
|
|
switch (pk.Species)
|
|
|
|
|
{
|
2019-09-10 07:21:51 +00:00
|
|
|
|
case (int)Core.Species.Minior:
|
|
|
|
|
return Util.Rand.Next(7, 14);
|
|
|
|
|
default:
|
|
|
|
|
return form;
|
2018-05-10 02:21:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-10 07:21:51 +00:00
|
|
|
|
if (form == 31) // flagged as totally random
|
2018-05-10 02:21:44 +00:00
|
|
|
|
return Util.Rand.Next(pk.PersonalInfo.FormeCount);
|
2019-09-10 07:21:51 +00:00
|
|
|
|
|
|
|
|
|
int spec = pk.Species;
|
|
|
|
|
if (spec == (int)Core.Species.Scatterbug || spec == (int)Core.Species.Spewpa || spec == (int)Core.Species.Vivillon)
|
2018-05-10 02:21:44 +00:00
|
|
|
|
return Legal.GetVivillonPattern(SAV.Country, SAV.SubRegion);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-29 16:31:13 +00:00
|
|
|
|
private PIDType GetPIDType()
|
|
|
|
|
{
|
|
|
|
|
if (Version == GameVersion.XD)
|
|
|
|
|
return PIDType.PokeSpot;
|
|
|
|
|
return PIDType.None; // depends on format, let the program auto-detect.
|
|
|
|
|
}
|
2016-11-08 16:43:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|