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>
|
2020-11-27 19:51:02 +00:00
|
|
|
|
/// <remarks>Wild encounter slots are found as random encounters in-game.</remarks>
|
2020-08-30 18:08:21 +00:00
|
|
|
|
public abstract class EncounterSlot : IEncounterable, ILocation
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
2020-12-22 01:05:05 +00:00
|
|
|
|
public int Species { get; protected init; }
|
|
|
|
|
public int Form { get; protected init; }
|
|
|
|
|
public int LevelMin { get; protected init; }
|
|
|
|
|
public int LevelMax { get; protected init; }
|
2020-08-21 23:35:49 +00:00
|
|
|
|
public abstract int Generation { get; }
|
2020-03-20 20:33:15 +00:00
|
|
|
|
public bool EggEncounter => false;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
public override string ToString() => $"{(Species) Species} @ {LevelMin}-{LevelMax}";
|
|
|
|
|
|
2020-08-30 17:23:22 +00:00
|
|
|
|
internal readonly EncounterArea Area;
|
2020-08-30 18:08:21 +00:00
|
|
|
|
public GameVersion Version => Area.Version;
|
2020-08-30 22:44:13 +00:00
|
|
|
|
public int Location => Area.Location;
|
|
|
|
|
public int EggLocation => 0;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
|
2020-08-30 17:23:22 +00:00
|
|
|
|
protected EncounterSlot(EncounterArea area) => Area = area;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
|
|
|
|
|
public EncounterSlot Clone() => (EncounterSlot)MemberwiseClone();
|
|
|
|
|
|
|
|
|
|
public bool FixedLevel => LevelMin == LevelMax;
|
|
|
|
|
|
|
|
|
|
private protected const string wild = "Wild Encounter";
|
|
|
|
|
public string Name => wild;
|
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>
|
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>
|
2020-08-21 23:35:49 +00:00
|
|
|
|
public bool IsLevelWithinRange(int min, int max) => LevelMin <= max && min <= LevelMax;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2019-09-20 05:54:53 +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>
|
|
|
|
|
/// <param name="minDecrease">Highest value the low end of levels can be</param>
|
|
|
|
|
/// <param name="maxIncrease">Lowest value the high end of levels can be</param>
|
|
|
|
|
/// <returns>True if within slot's range, false if impossible.</returns>
|
|
|
|
|
public bool IsLevelWithinRange(int lvl, int minDecrease, int maxIncrease) => LevelMin - minDecrease <= lvl && lvl <= LevelMax + maxIncrease;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets if the specified level inputs are within range of the <see cref="LevelMin"/> and <see cref="LevelMax"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="min">Lowest level allowed</param>
|
|
|
|
|
/// <param name="max">Highest level allowed</param>
|
|
|
|
|
/// <param name="minDecrease">Highest value the low end of levels can be</param>
|
|
|
|
|
/// <param name="maxIncrease">Lowest value the high end of levels can be</param>
|
|
|
|
|
/// <returns>True if within slot's range, false if impossible.</returns>
|
2020-08-21 23:35:49 +00:00
|
|
|
|
public bool IsLevelWithinRange(int min, int max, int minDecrease, int maxIncrease) => LevelMin - minDecrease <= max && min <= LevelMax + maxIncrease;
|
2019-03-18 05:19:37 +00:00
|
|
|
|
|
2019-11-28 20:56:26 +00:00
|
|
|
|
public virtual string LongName
|
2017-02-15 06:06:15 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-08-30 17:23:22 +00:00
|
|
|
|
if (Area!.Type == SlotType.Any)
|
2017-02-15 06:06:15 +00:00
|
|
|
|
return wild;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
return $"{wild} {Area!.Type.ToString().Replace('_', ' ')}";
|
2017-02-15 06:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-29 03:38:07 +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-31 07:43:41 +00:00
|
|
|
|
{
|
2018-11-20 00:14:49 +00:00
|
|
|
|
var pk = PKMConverter.GetBlank(Generation, Version);
|
2020-06-17 02:46:22 +00:00
|
|
|
|
sav.ApplyTo(pk);
|
2020-07-19 18:32:40 +00:00
|
|
|
|
ApplyDetails(sav, criteria, pk);
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
2018-04-01 03:37:36 +00:00
|
|
|
|
|
2020-07-19 18:32:40 +00:00
|
|
|
|
protected virtual void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
|
|
|
|
{
|
|
|
|
|
var version = this.GetCompatibleVersion((GameVersion) sav.Game);
|
|
|
|
|
int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID) sav.Language);
|
|
|
|
|
int level = LevelMin;
|
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);
|
2020-08-30 17:23:22 +00:00
|
|
|
|
|
2020-09-03 21:28:51 +00:00
|
|
|
|
var ball = Area.Type.GetRequiredBallValueWild(Generation, Location);
|
2020-08-30 17:23:22 +00:00
|
|
|
|
pk.Ball = (int)(ball == Ball.None ? Ball.Poke : ball);
|
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;
|
2020-12-11 04:42:30 +00:00
|
|
|
|
pk.Form = GetWildForm(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)
|
2020-07-19 18:32:40 +00:00
|
|
|
|
return;
|
2018-03-31 07:43:41 +00:00
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
sav.ApplyHandlingTrainerInfo(pk);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
pk.SetRandomEC();
|
|
|
|
|
}
|
2018-04-29 16:31:13 +00:00
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
protected virtual void SetEncounterMoves(PKM pk, GameVersion version, int level)
|
2019-02-09 19:37:20 +00:00
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
var moves = MoveLevelUp.GetEncounterMoves(pk, level, version);
|
2020-01-19 00:46:38 +00:00
|
|
|
|
pk.SetMoves(moves);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.SetMaximumPPCurrent(moves);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
protected virtual void SetFormatSpecificData(PKM pk) { }
|
2018-12-30 06:24:34 +00:00
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
protected virtual 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);
|
2020-08-30 17:23:22 +00:00
|
|
|
|
if (Area!.Type == SlotType.HiddenGrotto) // don't force hidden for DexNav
|
2018-12-30 06:24:34 +00:00
|
|
|
|
ability = 2;
|
|
|
|
|
|
2020-09-04 02:00:46 +00:00
|
|
|
|
if (Generation == 3 && Species == (int) Core.Species.Unown)
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
PIDGenerator.SetRandomWildPID(pk, pk.Format, nature, ability, gender);
|
|
|
|
|
ability ^= 1; // some nature-forms cannot have a certain PID-ability set, so just flip it as Unown doesn't have dual abilities.
|
2020-12-11 04:42:30 +00:00
|
|
|
|
} while (pk.Form != Form);
|
2020-09-04 02:00:46 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PIDGenerator.SetRandomWildPID(pk, pk.Format, nature, ability, gender);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
pk.Gender = gender;
|
2020-06-27 16:46:23 +00:00
|
|
|
|
pk.StatNature = nature;
|
2018-12-30 06:24:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-27 19:51:02 +00:00
|
|
|
|
private const int FormDynamic = FormVivillon;
|
|
|
|
|
private const int FormVivillon = 30;
|
|
|
|
|
private const int FormRandom = 31;
|
|
|
|
|
|
2020-12-11 04:42:30 +00:00
|
|
|
|
private static int GetWildForm(PKM pk, int form, ITrainerInfo sav)
|
2018-05-10 02:21:44 +00:00
|
|
|
|
{
|
2020-11-27 19:51:02 +00:00
|
|
|
|
if (form < FormDynamic) // specified form
|
2018-05-10 02:21:44 +00:00
|
|
|
|
{
|
2019-10-05 03:10:50 +00:00
|
|
|
|
if (pk.Species == (int) Core.Species.Minior)
|
|
|
|
|
return Util.Rand.Next(7, 14);
|
|
|
|
|
return form;
|
2018-05-10 02:21:44 +00:00
|
|
|
|
}
|
2020-11-27 19:51:02 +00:00
|
|
|
|
if (form == FormRandom) // flagged as totally random
|
2020-12-11 04:42:30 +00:00
|
|
|
|
return Util.Rand.Next(pk.PersonalInfo.FormCount);
|
2019-09-10 07:21:51 +00:00
|
|
|
|
|
|
|
|
|
int spec = pk.Species;
|
2020-07-31 20:53:42 +00:00
|
|
|
|
if ((int) Core.Species.Scatterbug <= spec && spec <= (int) Core.Species.Vivillon)
|
|
|
|
|
{
|
|
|
|
|
if (sav is IRegionOrigin o)
|
2020-10-04 21:15:13 +00:00
|
|
|
|
return Vivillon3DS.GetPattern((byte)o.Country, (byte)o.Region);
|
2020-07-31 20:53:42 +00:00
|
|
|
|
}
|
2018-05-10 02:21:44 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
public virtual string GetConditionString(out bool valid)
|
2018-04-29 16:31:13 +00:00
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
valid = true;
|
|
|
|
|
return LegalityCheckStrings.LEncCondition;
|
2018-04-29 16:31:13 +00:00
|
|
|
|
}
|
2016-11-08 16:43:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|