2018-03-31 07:43:41 +00:00
|
|
|
|
using System;
|
2018-04-28 23:30:56 +00:00
|
|
|
|
using System.Linq;
|
2018-03-31 07:43:41 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public class EncounterSlotPermissions
|
|
|
|
|
{
|
2017-11-27 00:09:24 +00:00
|
|
|
|
public int StaticIndex { get; set; } = -1;
|
|
|
|
|
public int MagnetPullIndex { get; set; } = -1;
|
2017-06-18 20:02:02 +00:00
|
|
|
|
public int StaticCount { get; set; }
|
|
|
|
|
public int MagnetPullCount { get; set; }
|
2017-11-27 00:09:24 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public bool AllowDexNav { get; set; }
|
|
|
|
|
public bool Pressure { get; set; }
|
|
|
|
|
public bool DexNav { get; set; }
|
|
|
|
|
public bool WhiteFlute { get; set; }
|
|
|
|
|
public bool BlackFlute { get; set; }
|
|
|
|
|
public bool IsNormalLead => !(WhiteFlute || BlackFlute || DexNav);
|
2017-08-24 17:09:34 +00:00
|
|
|
|
public bool IsDexNav => AllowDexNav && DexNav;
|
2017-12-03 20:20:49 +00:00
|
|
|
|
public EncounterSlotPermissions Clone() => (EncounterSlotPermissions)MemberwiseClone();
|
2017-06-18 01:37:19 +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; }
|
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;
|
|
|
|
|
|
2017-02-15 06:06:15 +00:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
const string wild = "Wild Encounter";
|
|
|
|
|
if (Type == SlotType.Any)
|
|
|
|
|
return wild;
|
2017-09-30 05:58:25 +00:00
|
|
|
|
return $"{wild} {Type.ToString().Replace("_", " ")}";
|
2017-02-15 06:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-29 03:38:07 +00:00
|
|
|
|
|
2018-03-31 07:43:41 +00:00
|
|
|
|
public PKM ConvertToPKM(ITrainerInfo SAV)
|
|
|
|
|
{
|
|
|
|
|
var version = this.GetCompatibleVersion((GameVersion)SAV.Game);
|
|
|
|
|
int lang = (int)Legal.GetSafeLanguage(Generation, (LanguageID)SAV.Language);
|
|
|
|
|
int level = LevelMin;
|
|
|
|
|
var pk = PKMConverter.GetBlank(Generation);
|
|
|
|
|
int nature = Util.Rand.Next(25);
|
2018-04-01 03:37:36 +00:00
|
|
|
|
SAV.ApplyToPKM(pk);
|
|
|
|
|
|
2018-03-31 07:43:41 +00:00
|
|
|
|
pk.Species = Species;
|
2018-04-30 01:26:36 +00:00
|
|
|
|
int gender = pk.PersonalInfo.RandomGender;
|
2018-03-31 07:43:41 +00:00
|
|
|
|
pk.Language = lang;
|
|
|
|
|
pk.CurrentLevel = level;
|
2018-04-28 23:30:56 +00:00
|
|
|
|
pk.Version = (int)version;
|
2018-03-31 07:43:41 +00:00
|
|
|
|
pk.Nickname = PKX.GetSpeciesNameGeneration(Species, lang, Generation);
|
2018-04-29 05:56:10 +00:00
|
|
|
|
pk.Ball = GetBall();
|
2018-05-10 02:21:44 +00:00
|
|
|
|
pk.AltForm = GetWildAltForm(Form, pk, SAV);
|
2018-04-02 03:25:40 +00:00
|
|
|
|
|
|
|
|
|
if (pk.Format > 2 || Version == GameVersion.C)
|
|
|
|
|
{
|
|
|
|
|
pk.Met_Location = Location;
|
|
|
|
|
pk.Met_Level = level;
|
|
|
|
|
if (Version == GameVersion.C && pk is PK2 pk2 && this is EncounterSlot1 slot)
|
|
|
|
|
pk2.Met_TimeOfDay = slot.Time.RandomValidTime();
|
|
|
|
|
|
|
|
|
|
if (pk.Format >= 4)
|
|
|
|
|
pk.MetDate = DateTime.Today;
|
|
|
|
|
}
|
2018-03-31 07:43:41 +00:00
|
|
|
|
pk.Language = lang;
|
|
|
|
|
|
2018-04-30 01:26:36 +00:00
|
|
|
|
var ability = Util.Rand.Next(0, 2);
|
2018-04-29 16:31:13 +00:00
|
|
|
|
var pidtype = GetPIDType();
|
2018-04-30 01:26:36 +00:00
|
|
|
|
if (pidtype == PIDType.PokeSpot)
|
|
|
|
|
PIDGenerator.SetRandomPokeSpotPID(pk, nature, gender, ability, SlotNumber);
|
|
|
|
|
else
|
|
|
|
|
PIDGenerator.SetRandomWildPID(pk, pk.Format, nature, ability, gender, pidtype);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
|
|
|
|
|
if (Permissions.IsDexNav)
|
|
|
|
|
{
|
|
|
|
|
pk.RefreshAbility(2);
|
|
|
|
|
var eggMoves = Legal.GetEggMoves(pk, Species, pk.AltForm, Version);
|
|
|
|
|
if (eggMoves.Length > 0)
|
|
|
|
|
pk.RelearnMove1 = eggMoves[Util.Rand.Next(eggMoves.Length)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (pk.Format)
|
|
|
|
|
{
|
2018-04-30 04:08:49 +00:00
|
|
|
|
case 1 when Species == 64 && Version == GameVersion.YW: // Kadabra
|
|
|
|
|
((PK1)pk).Catch_Rate = 96;
|
|
|
|
|
break;
|
2018-05-08 05:12:12 +00:00
|
|
|
|
case 1 when Species == 148 && Version == GameVersion.YW: // Dragonair
|
|
|
|
|
((PK1)pk).Catch_Rate = 27;
|
|
|
|
|
break;
|
2018-03-31 07:43:41 +00:00
|
|
|
|
case 3:
|
|
|
|
|
case 4:
|
|
|
|
|
if (pk.Format == 4)
|
|
|
|
|
pk.EncounterType = TypeEncounter.GetIndex();
|
2018-05-10 00:50:56 +00:00
|
|
|
|
pk.Gender = gender;
|
2018-04-01 03:37:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
if (Type == SlotType.HiddenGrotto)
|
|
|
|
|
pk.RefreshAbility(2);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
pk.SetRandomMemory6();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var moves = this is EncounterSlotMoves m ? m.Moves : Legal.GetEncounterMoves(pk, level, version);
|
2018-04-28 23:30:56 +00:00
|
|
|
|
if (pk.Format == 1 && moves.All(z => z == 0))
|
|
|
|
|
moves = ((PersonalInfoG1)PersonalTable.RB[Species]).Moves;
|
2018-04-30 01:26:36 +00:00
|
|
|
|
else if (Version == GameVersion.XD)
|
|
|
|
|
pk.FatefulEncounter = true;
|
2018-03-31 07:43:41 +00:00
|
|
|
|
pk.Moves = moves;
|
|
|
|
|
pk.SetMaximumPPCurrent(moves);
|
|
|
|
|
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
|
|
|
|
if (pk.Format < 6)
|
|
|
|
|
return pk;
|
|
|
|
|
|
|
|
|
|
SAV.ApplyHandlingTrainerInfo(pk);
|
|
|
|
|
pk.SetRandomEC();
|
|
|
|
|
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
2018-04-29 16:31:13 +00:00
|
|
|
|
|
2018-05-10 02:21:44 +00:00
|
|
|
|
private static int GetWildAltForm(int form, PKM pk, ITrainerInfo SAV)
|
|
|
|
|
{
|
|
|
|
|
if (form < 30)
|
|
|
|
|
{
|
|
|
|
|
switch (pk.Species)
|
|
|
|
|
{
|
|
|
|
|
case 774: return Util.Rand.Next(7, 14); // Minior
|
|
|
|
|
default: return form;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (form == 31)
|
|
|
|
|
return Util.Rand.Next(pk.PersonalInfo.FormeCount);
|
|
|
|
|
if (pk.Species == 664 || pk.Species == 665 || pk.Species == 666)
|
|
|
|
|
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.
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-28 23:30:56 +00:00
|
|
|
|
private int GetBall()
|
|
|
|
|
{
|
|
|
|
|
if (Type == SlotType.BugContest)
|
|
|
|
|
return 24; // Sport
|
|
|
|
|
if (Type.HasFlag(SlotType.Safari))
|
|
|
|
|
return 5; // Safari
|
|
|
|
|
return 4; // Poké Ball
|
|
|
|
|
}
|
2016-11-08 16:43:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|