2016-06-20 04:22:43 +00:00
|
|
|
|
using System;
|
2019-02-24 00:05:01 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
using System.Linq;
|
2020-12-25 20:30:26 +00:00
|
|
|
|
using static PKHeX.Core.GameVersion;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Object representing a <see cref="PKM"/>'s data and derived properties.
|
|
|
|
|
/// </summary>
|
2021-05-18 17:36:45 +00:00
|
|
|
|
public abstract class PKM : ISpeciesForm, ITrainerID, IGeneration, IShiny, ILangNick, IGameValueLimit, INature
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2022-02-13 02:48:33 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Valid file extensions that represent <see cref="PKM"/> data, without the leading '.'
|
|
|
|
|
/// </summary>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static readonly string[] Extensions = PKX.GetPKMExtensions();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract int SIZE_PARTY { get; }
|
|
|
|
|
public abstract int SIZE_STORED { get; }
|
2021-06-24 16:16:36 +00:00
|
|
|
|
public string Extension => GetType().Name.ToLowerInvariant();
|
2016-10-24 05:01:39 +00:00
|
|
|
|
public abstract PersonalInfo PersonalInfo { get; }
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public virtual IReadOnlyList<ushort> ExtraBytes => Array.Empty<ushort>();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Internal Attributes set on creation
|
2020-09-26 19:09:02 +00:00
|
|
|
|
public readonly byte[] Data; // Raw Storage
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2020-09-26 19:09:02 +00:00
|
|
|
|
protected PKM(byte[] data) => Data = data;
|
|
|
|
|
protected PKM(int size) => Data = new byte[size];
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public virtual byte[] EncryptedPartyData => Encrypt().AsSpan()[..SIZE_PARTY].ToArray();
|
|
|
|
|
public virtual byte[] EncryptedBoxData => Encrypt().AsSpan()[..SIZE_STORED].ToArray();
|
|
|
|
|
public virtual byte[] DecryptedPartyData => Write().AsSpan()[..SIZE_PARTY].ToArray();
|
|
|
|
|
public virtual byte[] DecryptedBoxData => Write().AsSpan()[..SIZE_STORED].ToArray();
|
2019-02-24 00:05:01 +00:00
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Rough indication if the data is junk or not.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract bool Valid { get; set; }
|
2016-10-02 17:18:31 +00:00
|
|
|
|
|
2017-04-09 21:06:50 +00:00
|
|
|
|
// Trash Bytes
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public abstract Span<byte> Nickname_Trash { get; }
|
|
|
|
|
public abstract Span<byte> OT_Trash { get; }
|
|
|
|
|
public virtual Span<byte> HT_Trash => Span<byte>.Empty;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected abstract byte[] Encrypt();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract int Format { get; }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private byte[] Write()
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
RefreshChecksum();
|
|
|
|
|
return Data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Surface Properties
|
|
|
|
|
public abstract int Species { get; set; }
|
|
|
|
|
public abstract string Nickname { get; set; }
|
|
|
|
|
public abstract int HeldItem { get; set; }
|
|
|
|
|
public abstract int Gender { get; set; }
|
|
|
|
|
public abstract int Nature { get; set; }
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public virtual int StatNature { get => Nature; set => Nature = value; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract int Ability { get; set; }
|
|
|
|
|
public abstract int CurrentFriendship { get; set; }
|
2020-12-11 04:42:30 +00:00
|
|
|
|
public abstract int Form { get; set; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract bool IsEgg { get; set; }
|
|
|
|
|
public abstract bool IsNicknamed { get; set; }
|
|
|
|
|
public abstract uint EXP { get; set; }
|
|
|
|
|
public abstract int TID { get; set; }
|
|
|
|
|
public abstract string OT_Name { get; set; }
|
|
|
|
|
public abstract int OT_Gender { get; set; }
|
|
|
|
|
public abstract int Ball { get; set; }
|
|
|
|
|
public abstract int Met_Level { get; set; }
|
|
|
|
|
|
|
|
|
|
// Battle
|
|
|
|
|
public abstract int Move1 { get; set; }
|
|
|
|
|
public abstract int Move2 { get; set; }
|
|
|
|
|
public abstract int Move3 { get; set; }
|
|
|
|
|
public abstract int Move4 { get; set; }
|
|
|
|
|
public abstract int Move1_PP { get; set; }
|
|
|
|
|
public abstract int Move2_PP { get; set; }
|
|
|
|
|
public abstract int Move3_PP { get; set; }
|
|
|
|
|
public abstract int Move4_PP { get; set; }
|
|
|
|
|
public abstract int Move1_PPUps { get; set; }
|
|
|
|
|
public abstract int Move2_PPUps { get; set; }
|
|
|
|
|
public abstract int Move3_PPUps { get; set; }
|
|
|
|
|
public abstract int Move4_PPUps { get; set; }
|
|
|
|
|
public abstract int EV_HP { get; set; }
|
|
|
|
|
public abstract int EV_ATK { get; set; }
|
|
|
|
|
public abstract int EV_DEF { get; set; }
|
|
|
|
|
public abstract int EV_SPE { get; set; }
|
|
|
|
|
public abstract int EV_SPA { get; set; }
|
|
|
|
|
public abstract int EV_SPD { get; set; }
|
|
|
|
|
public abstract int IV_HP { get; set; }
|
|
|
|
|
public abstract int IV_ATK { get; set; }
|
|
|
|
|
public abstract int IV_DEF { get; set; }
|
|
|
|
|
public abstract int IV_SPE { get; set; }
|
|
|
|
|
public abstract int IV_SPA { get; set; }
|
|
|
|
|
public abstract int IV_SPD { get; set; }
|
2019-01-12 06:25:48 +00:00
|
|
|
|
public abstract int Status_Condition { get; set; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract int Stat_Level { get; set; }
|
|
|
|
|
public abstract int Stat_HPMax { get; set; }
|
|
|
|
|
public abstract int Stat_HPCurrent { get; set; }
|
|
|
|
|
public abstract int Stat_ATK { get; set; }
|
|
|
|
|
public abstract int Stat_DEF { get; set; }
|
|
|
|
|
public abstract int Stat_SPE { get; set; }
|
|
|
|
|
public abstract int Stat_SPA { get; set; }
|
|
|
|
|
public abstract int Stat_SPD { get; set; }
|
|
|
|
|
|
|
|
|
|
// Hidden Properties
|
|
|
|
|
public abstract int Version { get; set; }
|
|
|
|
|
public abstract int SID { get; set; }
|
|
|
|
|
public abstract int PKRS_Strain { get; set; }
|
|
|
|
|
public abstract int PKRS_Days { get; set; }
|
|
|
|
|
|
|
|
|
|
public abstract uint EncryptionConstant { get; set; }
|
|
|
|
|
public abstract uint PID { get; set; }
|
|
|
|
|
|
|
|
|
|
// Misc Properties
|
|
|
|
|
public abstract int Language { get; set; }
|
|
|
|
|
public abstract bool FatefulEncounter { get; set; }
|
|
|
|
|
public abstract int TSV { get; }
|
|
|
|
|
public abstract int PSV { get; }
|
|
|
|
|
public abstract int Characteristic { get; }
|
2016-10-31 02:15:48 +00:00
|
|
|
|
public abstract int MarkValue { get; protected set; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract int Met_Location { get; set; }
|
|
|
|
|
public abstract int Egg_Location { get; set; }
|
|
|
|
|
public abstract int OT_Friendship { get; set; }
|
2017-10-23 04:01:08 +00:00
|
|
|
|
public virtual bool Japanese => Language == (int)LanguageID.Japanese;
|
|
|
|
|
public virtual bool Korean => Language == (int)LanguageID.Korean;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Future Properties
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public virtual int Met_Year { get => 0; set { } }
|
|
|
|
|
public virtual int Met_Month { get => 0; set { } }
|
|
|
|
|
public virtual int Met_Day { get => 0; set { } }
|
2020-08-02 18:25:23 +00:00
|
|
|
|
public virtual string HT_Name { get => string.Empty; set { } }
|
|
|
|
|
public virtual int HT_Gender { get => 0; set { } }
|
|
|
|
|
public virtual int HT_Friendship { get => 0; set { } }
|
|
|
|
|
public virtual byte Enjoyment { get => 0; set { } }
|
|
|
|
|
public virtual byte Fullness { get => 0; set { } }
|
|
|
|
|
public virtual int AbilityNumber { get => 0; set { } }
|
2016-08-10 14:02:31 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The date the Pokémon was met.
|
|
|
|
|
/// </summary>
|
2018-07-22 02:20:11 +00:00
|
|
|
|
/// <returns>
|
|
|
|
|
/// A DateTime representing the date the Pokémon was met.
|
|
|
|
|
/// Returns null if either the <see cref="PKM"/> format does not support dates or the stored date is invalid.</returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Not all <see cref="PKM"/> types support the <see cref="MetDate"/> property. In these cases, this property will return null.
|
|
|
|
|
/// If null is assigned to this property, it will be cleared.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public DateTime? MetDate
|
2016-08-10 14:02:31 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// Check to see if date is valid
|
2021-05-14 23:46:48 +00:00
|
|
|
|
if (!DateUtil.IsDateValid(2000 + Met_Year, Met_Month, Met_Day))
|
2016-08-10 14:02:31 +00:00
|
|
|
|
return null;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
return new DateTime(2000 + Met_Year, Met_Month, Met_Day);
|
2016-08-10 14:02:31 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value.HasValue)
|
|
|
|
|
{
|
|
|
|
|
// Only update the properties if a value is provided.
|
2016-08-10 14:07:16 +00:00
|
|
|
|
Met_Year = value.Value.Year - 2000;
|
2016-08-10 14:02:31 +00:00
|
|
|
|
Met_Month = value.Value.Month;
|
|
|
|
|
Met_Day = value.Value.Day;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Clear the Met Date.
|
|
|
|
|
// If code tries to access MetDate again, null will be returned.
|
|
|
|
|
Met_Year = 0;
|
|
|
|
|
Met_Month = 0;
|
|
|
|
|
Met_Day = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public virtual int Egg_Year { get => 0; set { } }
|
|
|
|
|
public virtual int Egg_Month { get => 0; set { } }
|
|
|
|
|
public virtual int Egg_Day { get => 0; set { } }
|
2016-08-10 14:02:31 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The date a Pokémon was met as an egg.
|
|
|
|
|
/// </summary>
|
2018-07-22 02:20:11 +00:00
|
|
|
|
/// <returns>
|
|
|
|
|
/// A DateTime representing the date the Pokémon was met as an egg.
|
|
|
|
|
/// Returns null if either the <see cref="PKM"/> format does not support dates or the stored date is invalid.</returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Not all <see cref="PKM"/> types support the <see cref="EggMetDate"/> property. In these cases, this property will return null.
|
|
|
|
|
/// If null is assigned to this property, it will be cleared.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public DateTime? EggMetDate
|
2016-08-10 14:02:31 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// Check to see if date is valid
|
2021-05-14 23:46:48 +00:00
|
|
|
|
if (!DateUtil.IsDateValid(2000 + Egg_Year, Egg_Month, Egg_Day))
|
2016-08-10 14:02:31 +00:00
|
|
|
|
return null;
|
2017-10-18 06:19:34 +00:00
|
|
|
|
return new DateTime(2000 + Egg_Year, Egg_Month, Egg_Day);
|
2016-08-10 14:02:31 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value.HasValue)
|
|
|
|
|
{
|
|
|
|
|
// Only update the properties if a value is provided.
|
2016-08-10 14:07:16 +00:00
|
|
|
|
Egg_Year = value.Value.Year - 2000;
|
2016-08-10 14:02:31 +00:00
|
|
|
|
Egg_Month = value.Value.Month;
|
|
|
|
|
Egg_Day = value.Value.Day;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Clear the Met Date.
|
|
|
|
|
// If code tries to access MetDate again, null will be returned.
|
|
|
|
|
Egg_Year = 0;
|
|
|
|
|
Egg_Month = 0;
|
|
|
|
|
Egg_Day = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public virtual int RelearnMove1 { get => 0; set { } }
|
|
|
|
|
public virtual int RelearnMove2 { get => 0; set { } }
|
|
|
|
|
public virtual int RelearnMove3 { get => 0; set { } }
|
|
|
|
|
public virtual int RelearnMove4 { get => 0; set { } }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Exposed but not Present in all
|
|
|
|
|
public abstract int CurrentHandler { get; set; }
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Maximums
|
|
|
|
|
public abstract int MaxMoveID { get; }
|
|
|
|
|
public abstract int MaxSpeciesID { get; }
|
|
|
|
|
public abstract int MaxItemID { get; }
|
|
|
|
|
public abstract int MaxAbilityID { get; }
|
|
|
|
|
public abstract int MaxBallID { get; }
|
|
|
|
|
public abstract int MaxGameID { get; }
|
2018-06-15 23:00:28 +00:00
|
|
|
|
public virtual int MinGameID => 0;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public abstract int MaxIV { get; }
|
|
|
|
|
public abstract int MaxEV { get; }
|
|
|
|
|
public abstract int OTLength { get; }
|
|
|
|
|
public abstract int NickLength { get; }
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Derived
|
2020-12-11 04:42:30 +00:00
|
|
|
|
public int SpecForm { get => Species + (Form << 11); set { Species = value & 0x7FF; Form = value >> 11; } }
|
2016-10-12 05:59:19 +00:00
|
|
|
|
public virtual int SpriteItem => HeldItem;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public virtual bool IsShiny => TSV == PSV;
|
2018-07-11 04:25:03 +00:00
|
|
|
|
public int TrainerID7 { get => (int)((uint)(TID | (SID << 16)) % 1000000); set => SetID7(TrainerSID7, value); }
|
|
|
|
|
public int TrainerSID7 { get => (int)((uint)(TID | (SID << 16)) / 1000000); set => SetID7(value, TrainerID7); }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-11-21 04:38:05 +00:00
|
|
|
|
public uint ShinyXor
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var pid = PID;
|
|
|
|
|
var upper = (pid >> 16) ^ (uint)SID;
|
|
|
|
|
return (pid & 0xFFFF) ^ (uint)TID ^ upper;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-10 18:31:20 +00:00
|
|
|
|
public int DisplayTID
|
|
|
|
|
{
|
2020-12-11 04:42:30 +00:00
|
|
|
|
get => Generation >= 7 ? TrainerID7 : TID;
|
|
|
|
|
set { if (Generation >= 7) TrainerID7 = value; else TID = value; }
|
2019-02-10 18:31:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int DisplaySID
|
|
|
|
|
{
|
2020-12-11 04:42:30 +00:00
|
|
|
|
get => Generation >= 7 ? TrainerSID7 : SID;
|
|
|
|
|
set { if (Generation >= 7) TrainerSID7 = value; else SID = value; }
|
2019-02-10 18:31:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-11 04:25:03 +00:00
|
|
|
|
private void SetID7(int sid7, int tid7)
|
|
|
|
|
{
|
|
|
|
|
var oid = (sid7 * 1_000_000) + (tid7 % 1_000_000);
|
|
|
|
|
TID = (ushort)oid;
|
|
|
|
|
SID = oid >> 16;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-20 04:36:03 +00:00
|
|
|
|
public bool E => Version == (int)GameVersion.E;
|
2020-12-25 20:30:26 +00:00
|
|
|
|
public bool FRLG => Version is (int)FR or (int)LG;
|
2017-03-20 04:36:03 +00:00
|
|
|
|
public bool Pt => (int)GameVersion.Pt == Version;
|
2020-12-25 20:30:26 +00:00
|
|
|
|
public bool HGSS => Version is (int)HG or (int)SS;
|
|
|
|
|
public bool BW => Version is (int)B or (int)W;
|
|
|
|
|
public bool B2W2 => Version is (int)B2 or (int)W2;
|
|
|
|
|
public bool XY => Version is (int)X or (int)Y;
|
|
|
|
|
public bool AO => Version is (int)AS or (int)OR;
|
|
|
|
|
public bool SM => Version is (int)SN or (int)MN;
|
|
|
|
|
public bool USUM => Version is (int)US or (int)UM;
|
|
|
|
|
public bool GO => Version is (int)GameVersion.GO;
|
|
|
|
|
public bool VC1 => Version is >= (int)RD and <= (int)YW;
|
|
|
|
|
public bool VC2 => Version is >= (int)GD and <= (int)C;
|
|
|
|
|
public bool LGPE => Version is (int)GP or (int)GE;
|
|
|
|
|
public bool SWSH => Version is (int)SW or (int)SH;
|
2021-11-20 02:23:49 +00:00
|
|
|
|
public bool BDSP => Version is (int)BD or (int)SP;
|
2022-02-05 01:35:15 +00:00
|
|
|
|
public bool LA => Version is (int)PLA;
|
2019-01-05 23:40:25 +00:00
|
|
|
|
|
2020-11-19 05:34:40 +00:00
|
|
|
|
public bool GO_LGPE => GO && Met_Location == Locations.GO7;
|
2020-11-12 05:22:13 +00:00
|
|
|
|
public bool GO_HOME => GO && Met_Location == Locations.GO8;
|
2017-01-26 06:51:52 +00:00
|
|
|
|
public bool VC => VC1 || VC2;
|
2020-11-12 05:22:13 +00:00
|
|
|
|
public bool GG => LGPE || GO_LGPE;
|
2021-11-20 02:23:49 +00:00
|
|
|
|
public bool Gen8 => Version is >= 44 and <= 49 || GO_HOME;
|
2020-12-25 20:30:26 +00:00
|
|
|
|
public bool Gen7 => Version is >= 30 and <= 33 || GG;
|
|
|
|
|
public bool Gen6 => Version is >= 24 and <= 29;
|
|
|
|
|
public bool Gen5 => Version is >= 20 and <= 23;
|
|
|
|
|
public bool Gen4 => Version is >= 7 and <= 12 and not 9;
|
|
|
|
|
public bool Gen3 => Version is >= 1 and <= 5 or 15;
|
|
|
|
|
public bool Gen2 => Version == (int)GSC; // Fixed value set by the Gen2 PKM classes
|
|
|
|
|
public bool Gen1 => Version == (int)RBY; // Fixed value set by the Gen1 PKM classes
|
2020-12-11 04:42:30 +00:00
|
|
|
|
public bool GenU => Generation <= 0;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2020-12-11 04:42:30 +00:00
|
|
|
|
public int Generation
|
2016-08-09 01:42:42 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (Gen8) return 8;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
if (Gen7) return 7;
|
2016-08-09 01:42:42 +00:00
|
|
|
|
if (Gen6) return 6;
|
|
|
|
|
if (Gen5) return 5;
|
|
|
|
|
if (Gen4) return 4;
|
|
|
|
|
if (Gen3) return 3;
|
2017-02-13 01:00:03 +00:00
|
|
|
|
if (Gen2) return Format; // 2
|
|
|
|
|
if (Gen1) return Format; // 1
|
Generation 1 and 2 legal Improvements (#1099)
* Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved.
Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves
Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter.
Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move
* Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible.
If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2.
Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves
Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon
Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves
* Check legal values of generation 1 type and catch rate
Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item)
Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves
* Filter ingame trades and static encounters with catch rate for generation 1 non tradeback
* Fix min moves for generation 1 metapod encounter
* Clean up
* Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up
Clean up type validation
Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch
* Clean-up
* Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array
* Fix generation 1 evolution chains and catch rate as default held item
* Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
|
|
|
|
if (VC1) return 1;
|
|
|
|
|
if (VC2) return 2;
|
2016-08-09 01:42:42 +00:00
|
|
|
|
return -1;
|
2018-01-10 23:40:33 +00:00
|
|
|
|
}
|
2016-08-09 01:42:42 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-01-10 23:40:33 +00:00
|
|
|
|
public int DebutGeneration => Legal.GetDebutGeneration(Species);
|
2021-07-30 23:22:10 +00:00
|
|
|
|
public bool PKRS_Infected { get => PKRS_Strain != 0; set => PKRS_Strain = value ? Math.Max(PKRS_Strain, 1) : 0; }
|
2019-03-21 23:48:17 +00:00
|
|
|
|
|
|
|
|
|
public bool PKRS_Cured
|
|
|
|
|
{
|
|
|
|
|
get => PKRS_Days == 0 && PKRS_Strain > 0;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
PKRS_Days = value ? 0 : 1;
|
|
|
|
|
PKRS_Infected = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public int CurrentLevel { get => Experience.GetLevel(EXP, PersonalInfo.EXPGrowth); set => EXP = Experience.GetEXP(Stat_Level = value, PersonalInfo.EXPGrowth); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int MarkCircle { get => Markings[0]; set { var marks = Markings; marks[0] = value; Markings = marks; } }
|
|
|
|
|
public int MarkTriangle { get => Markings[1]; set { var marks = Markings; marks[1] = value; Markings = marks; } }
|
|
|
|
|
public int MarkSquare { get => Markings[2]; set { var marks = Markings; marks[2] = value; Markings = marks; } }
|
|
|
|
|
public int MarkHeart { get => Markings[3]; set { var marks = Markings; marks[3] = value; Markings = marks; } }
|
|
|
|
|
public int MarkStar { get => Markings[4]; set { var marks = Markings; marks[4] = value; Markings = marks; } }
|
|
|
|
|
public int MarkDiamond { get => Markings[5]; set { var marks = Markings; marks[5] = value; Markings = marks; } }
|
2018-06-06 04:31:42 +00:00
|
|
|
|
public int IVTotal => IV_HP + IV_ATK + IV_DEF + IV_SPA + IV_SPD + IV_SPE;
|
|
|
|
|
public int EVTotal => EV_HP + EV_ATK + EV_DEF + EV_SPA + EV_SPD + EV_SPE;
|
2019-01-05 18:51:41 +00:00
|
|
|
|
public int MaximumIV => Math.Max(Math.Max(Math.Max(Math.Max(Math.Max(IV_HP, IV_ATK), IV_DEF), IV_SPA), IV_SPD), IV_SPE);
|
|
|
|
|
|
|
|
|
|
public int FlawlessIVCount
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int max = MaxIV;
|
|
|
|
|
int ctr = 0;
|
|
|
|
|
if (IV_HP == max) ++ctr;
|
|
|
|
|
if (IV_ATK == max) ++ctr;
|
|
|
|
|
if (IV_DEF == max) ++ctr;
|
|
|
|
|
if (IV_SPA == max) ++ctr;
|
|
|
|
|
if (IV_SPD == max) ++ctr;
|
|
|
|
|
if (IV_SPE == max) ++ctr;
|
|
|
|
|
return ctr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-24 04:24:01 +00:00
|
|
|
|
|
2018-09-16 17:48:04 +00:00
|
|
|
|
public string FileName => $"{FileNameWithoutExtension}.{Extension}";
|
|
|
|
|
|
2021-07-29 02:28:56 +00:00
|
|
|
|
public string FileNameWithoutExtension => EntityFileNamer.GetName(this);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public int[] IVs
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => new[] { IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_SPD };
|
2022-01-03 05:35:59 +00:00
|
|
|
|
set => SetIVs(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetIVs(ReadOnlySpan<int> value)
|
|
|
|
|
{
|
|
|
|
|
if (value.Length != 6)
|
|
|
|
|
return;
|
|
|
|
|
IV_HP = value[0];
|
|
|
|
|
IV_ATK = value[1];
|
|
|
|
|
IV_DEF = value[2];
|
|
|
|
|
IV_SPE = value[3];
|
|
|
|
|
IV_SPA = value[4];
|
|
|
|
|
IV_SPD = value[5];
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public int[] EVs
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => new[] { EV_HP, EV_ATK, EV_DEF, EV_SPE, EV_SPA, EV_SPD };
|
2016-06-20 04:22:43 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
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
|
|
|
|
if (value.Length != 6)
|
|
|
|
|
return;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
EV_HP = value[0]; EV_ATK = value[1]; EV_DEF = value[2];
|
|
|
|
|
EV_SPE = value[3]; EV_SPA = value[4]; EV_SPD = value[5];
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-12-04 04:53:37 +00:00
|
|
|
|
public int[] Stats
|
|
|
|
|
{
|
|
|
|
|
get => new[] { Stat_HPCurrent, Stat_ATK, Stat_DEF, Stat_SPE, Stat_SPA, Stat_SPD };
|
|
|
|
|
set
|
|
|
|
|
{
|
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
|
|
|
|
if (value.Length != 6)
|
2018-12-04 04:53:37 +00:00
|
|
|
|
return;
|
|
|
|
|
Stat_HPCurrent = value[0]; Stat_ATK = value[1]; Stat_DEF = value[2];
|
|
|
|
|
Stat_SPE = value[3]; Stat_SPA = value[4]; Stat_SPD = value[5];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public int[] Moves
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => new[] { Move1, Move2, Move3, Move4 };
|
2020-09-09 19:47:24 +00:00
|
|
|
|
set => SetMoves(value);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2022-02-10 03:21:45 +00:00
|
|
|
|
public void PushMove(int move)
|
|
|
|
|
{
|
|
|
|
|
if (move == 0 || (uint)move >= MaxMoveID)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var ct = MoveCount;
|
|
|
|
|
if (ct == 4)
|
|
|
|
|
ct = 0;
|
|
|
|
|
SetMove(ct, move);
|
|
|
|
|
HealPPIndex(ct);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int MoveCount => Convert.ToInt32(Move1 != 0) + Convert.ToInt32(Move2 != 0) + Convert.ToInt32(Move3 != 0) + Convert.ToInt32(Move4 != 0);
|
|
|
|
|
|
2020-01-19 00:46:38 +00:00
|
|
|
|
public void SetMoves(IReadOnlyList<int> value)
|
|
|
|
|
{
|
|
|
|
|
Move1 = value.Count > 0 ? value[0] : 0;
|
|
|
|
|
Move2 = value.Count > 1 ? value[1] : 0;
|
|
|
|
|
Move3 = value.Count > 2 ? value[2] : 0;
|
|
|
|
|
Move4 = value.Count > 3 ? value[3] : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-27 15:43:36 +00:00
|
|
|
|
public int[] RelearnMoves
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => new[] { RelearnMove1, RelearnMove2, RelearnMove3, RelearnMove4 };
|
2019-09-10 07:21:51 +00:00
|
|
|
|
set => SetRelearnMoves(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetRelearnMoves(IReadOnlyList<int> value)
|
|
|
|
|
{
|
|
|
|
|
RelearnMove1 = value.Count > 0 ? value[0] : 0;
|
|
|
|
|
RelearnMove2 = value.Count > 1 ? value[1] : 0;
|
|
|
|
|
RelearnMove3 = value.Count > 2 ? value[2] : 0;
|
|
|
|
|
RelearnMove4 = value.Count > 3 ? value[3] : 0;
|
2016-08-27 15:43:36 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
Implement PID-Ability corrections
Line 2211:
When the fields are loaded, if the user modifies the Ability on a <=Gen5
save file, if the ability is modified, the PID will be randomized to fit
the new PID.
When the Ability combobox is loaded, the personal entry may have 0 for
the ability2 (indicating same as ability1); if so, copy ability1 instead
of filtering it out.
When the Ability index is loaded, hidden ability is checked first, else
it tries to match: invalid, hidden (unflagged=illegal), if abilities
same use PIDAbility, else use the actual ability index.
2016-08-23 03:37:50 +00:00
|
|
|
|
public int PIDAbility
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-12-11 04:42:30 +00:00
|
|
|
|
if (Generation > 5 || Format > 5)
|
Implement PID-Ability corrections
Line 2211:
When the fields are loaded, if the user modifies the Ability on a <=Gen5
save file, if the ability is modified, the PID will be randomized to fit
the new PID.
When the Ability combobox is loaded, the personal entry may have 0 for
the ability2 (indicating same as ability1); if so, copy ability1 instead
of filtering it out.
When the Ability index is loaded, hidden ability is checked first, else
it tries to match: invalid, hidden (unflagged=illegal), if abilities
same use PIDAbility, else use the actual ability index.
2016-08-23 03:37:50 +00:00
|
|
|
|
return -1;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2020-12-25 20:30:26 +00:00
|
|
|
|
if (Version == (int) CXD)
|
2020-09-06 17:53:13 +00:00
|
|
|
|
return PersonalInfo.GetAbilityIndex(Ability); // Can mismatch; not tied to PID
|
2017-11-18 06:19:23 +00:00
|
|
|
|
return (int)((Gen5 ? PID >> 16 : PID) & 1);
|
Implement PID-Ability corrections
Line 2211:
When the fields are loaded, if the user modifies the Ability on a <=Gen5
save file, if the ability is modified, the PID will be randomized to fit
the new PID.
When the Ability combobox is loaded, the personal entry may have 0 for
the ability2 (indicating same as ability1); if so, copy ability1 instead
of filtering it out.
When the Ability index is loaded, hidden ability is checked first, else
it tries to match: invalid, hidden (unflagged=illegal), if abilities
same use PIDAbility, else use the actual ability index.
2016-08-23 03:37:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2016-10-31 02:15:48 +00:00
|
|
|
|
public virtual int[] Markings
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-31 02:15:48 +00:00
|
|
|
|
int[] mark = new int[8];
|
2016-06-20 04:22:43 +00:00
|
|
|
|
for (int i = 0; i < 8; i++)
|
2016-10-31 02:15:48 +00:00
|
|
|
|
mark[i] = (MarkValue >> i) & 1;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return mark;
|
|
|
|
|
}
|
2022-01-09 06:48:33 +00:00
|
|
|
|
set => SetMarkings(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void SetMarkings(ReadOnlySpan<int> value)
|
|
|
|
|
{
|
|
|
|
|
if (value.Length > 8)
|
|
|
|
|
return;
|
|
|
|
|
byte b = 0;
|
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
|
|
|
|
b |= (byte)(Math.Min(value[i], 1) << i);
|
|
|
|
|
MarkValue = b;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-15 03:06:11 +00:00
|
|
|
|
private int HPBitValPower => ((IV_HP & 2) >> 1) | ((IV_ATK & 2) >> 0) | ((IV_DEF & 2) << 1) | ((IV_SPE & 2) << 2) | ((IV_SPA & 2) << 3) | ((IV_SPD & 2) << 4);
|
|
|
|
|
public virtual int HPPower => Format < 6 ? ((40 * HPBitValPower) / 63) + 30 : 60;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2020-09-15 03:06:11 +00:00
|
|
|
|
private int HPBitValType => ((IV_HP & 1) >> 0) | ((IV_ATK & 1) << 1) | ((IV_DEF & 1) << 2) | ((IV_SPE & 1) << 3) | ((IV_SPA & 1) << 4) | ((IV_SPD & 1) << 5);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public virtual int HPType
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2020-09-15 03:06:11 +00:00
|
|
|
|
get => 15 * HPBitValType / 63;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2021-04-20 08:02:32 +00:00
|
|
|
|
var arr = HiddenPower.DefaultLowBits;
|
|
|
|
|
var bits = (uint)value >= arr.Length ? 0 : arr[value];
|
|
|
|
|
IV_HP = (IV_HP & ~1) + ((bits >> 0) & 1);
|
|
|
|
|
IV_ATK = (IV_ATK & ~1) + ((bits >> 1) & 1);
|
|
|
|
|
IV_DEF = (IV_DEF & ~1) + ((bits >> 2) & 1);
|
|
|
|
|
IV_SPE = (IV_SPE & ~1) + ((bits >> 3) & 1);
|
|
|
|
|
IV_SPA = (IV_SPA & ~1) + ((bits >> 4) & 1);
|
|
|
|
|
IV_SPD = (IV_SPD & ~1) + ((bits >> 5) & 1);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
// Misc Egg Facts
|
2021-11-20 02:23:49 +00:00
|
|
|
|
public bool WasEgg => IsEgg || !Locations.IsNoneLocation((GameVersion)Version, Egg_Location);
|
2019-05-11 03:46:49 +00:00
|
|
|
|
public bool WasTradedEgg => Egg_Location == GetTradedEggLocation();
|
|
|
|
|
public bool IsTradedEgg => Met_Location == GetTradedEggLocation();
|
2021-11-20 02:23:49 +00:00
|
|
|
|
private int GetTradedEggLocation() => Locations.TradedEggLocation(Generation, (GameVersion)Version);
|
2019-05-11 03:46:49 +00:00
|
|
|
|
|
2017-12-14 00:12:53 +00:00
|
|
|
|
public virtual bool IsUntraded => false;
|
2020-12-22 07:37:07 +00:00
|
|
|
|
public bool IsNative => Generation == Format;
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
public bool IsOriginValid => Species <= MaxSpeciesID;
|
2017-02-15 08:11:12 +00:00
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the <see cref="PKM"/> could inhabit a set of games.
|
|
|
|
|
/// </summary>
|
2020-06-17 02:46:22 +00:00
|
|
|
|
/// <param name="generation">Set of games.</param>
|
2017-02-15 08:11:12 +00:00
|
|
|
|
/// <param name="species"></param>
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <returns>True if could inhabit, False if not.</returns>
|
2020-06-17 02:46:22 +00:00
|
|
|
|
public bool InhabitedGeneration(int generation, int species = -1)
|
2016-10-24 05:01:39 +00:00
|
|
|
|
{
|
2017-02-15 08:11:12 +00:00
|
|
|
|
if (species < 0)
|
|
|
|
|
species = Species;
|
2017-02-05 02:27:28 +00:00
|
|
|
|
|
2021-01-16 20:01:40 +00:00
|
|
|
|
var format = Format;
|
|
|
|
|
if (format == generation)
|
2017-02-15 22:11:01 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
2017-02-15 08:11:12 +00:00
|
|
|
|
if (!IsOriginValid)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Sanity Check Species ID
|
2021-01-03 03:11:46 +00:00
|
|
|
|
if (species > Legal.GetMaxSpeciesOrigin(generation) && !EvolutionLegality.GetFutureGenEvolutions(generation).Contains(species))
|
2017-02-15 08:11:12 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2018-05-12 15:13:39 +00:00
|
|
|
|
// Trade generation 1 -> 2
|
2021-08-20 22:59:54 +00:00
|
|
|
|
if (format == 2 && generation == 1 && !Korean)
|
Generation 1 and 2 legal Improvements (#1099)
* Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved.
Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves
Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter.
Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move
* Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible.
If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2.
Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves
Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon
Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves
* Check legal values of generation 1 type and catch rate
Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item)
Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves
* Filter ingame trades and static encounters with catch rate for generation 1 non tradeback
* Fix min moves for generation 1 metapod encounter
* Clean up
* Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up
Clean up type validation
Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch
* Clean-up
* Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array
* Fix generation 1 evolution chains and catch rate as default held item
* Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
2018-05-12 15:13:39 +00:00
|
|
|
|
// Trade generation 2 -> 1
|
2021-08-20 22:59:54 +00:00
|
|
|
|
if (format == 1 && generation == 2 && ParseSettings.AllowGen1Tradeback)
|
Generation 1 and 2 legal Improvements (#1099)
* Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved.
Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves
Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter.
Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move
* Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible.
If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2.
Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves
Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon
Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves
* Check legal values of generation 1 type and catch rate
Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item)
Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves
* Filter ingame trades and static encounters with catch rate for generation 1 non tradeback
* Fix min moves for generation 1 metapod encounter
* Clean up
* Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up
Clean up type validation
Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch
* Clean-up
* Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array
* Fix generation 1 evolution chains and catch rate as default held item
* Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
2021-01-16 20:01:40 +00:00
|
|
|
|
if (format < generation)
|
Generation 1 and 2 legal Improvements (#1099)
* Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved.
Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves
Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter.
Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move
* Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible.
If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2.
Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves
Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon
Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves
* Check legal values of generation 1 type and catch rate
Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item)
Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves
* Filter ingame trades and static encounters with catch rate for generation 1 non tradeback
* Fix min moves for generation 1 metapod encounter
* Clean up
* Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up
Clean up type validation
Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch
* Clean-up
* Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array
* Fix generation 1 evolution chains and catch rate as default held item
* Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
|
|
|
|
return false; // Future
|
|
|
|
|
|
2020-12-11 04:42:30 +00:00
|
|
|
|
int gen = Generation;
|
2020-06-17 02:46:22 +00:00
|
|
|
|
return generation switch
|
2016-10-24 05:01:39 +00:00
|
|
|
|
{
|
2021-01-16 20:01:40 +00:00
|
|
|
|
1 => format == 1 || VC, // species compat checked via sanity above
|
|
|
|
|
2 => format == 2 || VC,
|
2019-10-08 01:40:09 +00:00
|
|
|
|
3 => Gen3,
|
2020-12-25 20:30:26 +00:00
|
|
|
|
4 => gen is >= 3 and <= 4,
|
|
|
|
|
5 => gen is >= 3 and <= 5,
|
|
|
|
|
6 => gen is >= 3 and <= 6,
|
|
|
|
|
7 => gen is >= 3 and <= 7 || VC,
|
|
|
|
|
8 => gen is >= 3 and <= 8 || VC,
|
2021-08-20 20:49:20 +00:00
|
|
|
|
_ => false,
|
2019-10-08 01:40:09 +00:00
|
|
|
|
};
|
2016-10-24 05:01:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 05:40:35 +00:00
|
|
|
|
/// <summary>
|
2017-02-12 17:52:26 +00:00
|
|
|
|
/// Checks if the PKM has its original met location.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Returns false if the Met Location has been overwritten via generational transfer.</returns>
|
2020-12-11 04:42:30 +00:00
|
|
|
|
public virtual bool HasOriginalMetLocation => !(Format < 3 || VC || (Generation <= 4 && Format != Generation));
|
2017-02-12 17:52:26 +00:00
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the current <see cref="Gender"/> is valid.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if valid, False if invalid.</returns>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public virtual bool IsGenderValid()
|
2017-03-25 07:01:02 +00:00
|
|
|
|
{
|
2017-05-19 02:16:11 +00:00
|
|
|
|
int gender = Gender;
|
2017-03-25 07:01:02 +00:00
|
|
|
|
int gv = PersonalInfo.Gender;
|
2021-07-13 07:25:51 +00:00
|
|
|
|
if (gv == PersonalInfo.RatioMagicGenderless)
|
2017-05-19 02:16:11 +00:00
|
|
|
|
return gender == 2;
|
2021-07-13 07:25:51 +00:00
|
|
|
|
if (gv == PersonalInfo.RatioMagicFemale)
|
2017-05-19 02:16:11 +00:00
|
|
|
|
return gender == 1;
|
2021-07-13 07:25:51 +00:00
|
|
|
|
if (gv == PersonalInfo.RatioMagicMale)
|
2017-05-19 02:16:11 +00:00
|
|
|
|
return gender == 0;
|
2017-03-25 07:01:02 +00:00
|
|
|
|
|
2020-12-11 04:42:30 +00:00
|
|
|
|
int gen = Generation;
|
2020-12-25 20:30:26 +00:00
|
|
|
|
if (gen is <= 2 or >= 6) // not 3-5
|
2018-05-11 01:53:23 +00:00
|
|
|
|
return gender == (gender & 1);
|
2017-03-25 07:01:02 +00:00
|
|
|
|
|
2017-09-29 05:20:27 +00:00
|
|
|
|
return gender == PKX.GetGenderFromPIDAndRatio(PID, gv);
|
2017-03-25 07:01:02 +00:00
|
|
|
|
}
|
2017-02-05 02:27:28 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the checksum of the <see cref="PKM"/>.
|
|
|
|
|
/// </summary>
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public abstract void RefreshChecksum();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if the data has a proper checksum.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>Returns true for structures that do not compute or contain a checksum in the structure.</remarks>
|
|
|
|
|
public abstract bool ChecksumValid { get; }
|
2017-02-05 02:27:28 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reorders moves and fixes PP if necessary.
|
|
|
|
|
/// </summary>
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public void FixMoves()
|
2016-08-21 16:09:22 +00:00
|
|
|
|
{
|
|
|
|
|
ReorderMoves();
|
|
|
|
|
|
2017-10-18 06:19:34 +00:00
|
|
|
|
if (Move1 == 0) Move1_PP = Move1_PPUps = 0;
|
|
|
|
|
if (Move2 == 0) Move2_PP = Move2_PPUps = 0;
|
|
|
|
|
if (Move3 == 0) Move3_PP = Move3_PPUps = 0;
|
|
|
|
|
if (Move4 == 0) Move4_PP = Move4_PPUps = 0;
|
2016-08-21 16:09:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reorders moves to put Empty entries last.
|
|
|
|
|
/// </summary>
|
2016-08-21 16:09:22 +00:00
|
|
|
|
private void ReorderMoves()
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-01-07 00:22:45 +00:00
|
|
|
|
if (Move1 == 0 && Move2 != 0)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-01-07 00:22:45 +00:00
|
|
|
|
Move1 = Move2;
|
|
|
|
|
Move1_PP = Move2_PP;
|
|
|
|
|
Move1_PPUps = Move2_PPUps;
|
|
|
|
|
Move2 = 0;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2019-01-07 00:22:45 +00:00
|
|
|
|
if (Move2 == 0 && Move3 != 0)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
Move2 = Move3;
|
|
|
|
|
Move2_PP = Move3_PP;
|
|
|
|
|
Move2_PPUps = Move3_PPUps;
|
2016-08-21 16:09:22 +00:00
|
|
|
|
Move3 = 0;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2019-01-07 00:22:45 +00:00
|
|
|
|
if (Move3 == 0 && Move4 != 0)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-01-07 00:22:45 +00:00
|
|
|
|
Move3 = Move4;
|
|
|
|
|
Move3_PP = Move4_PP;
|
|
|
|
|
Move3_PPUps = Move4_PPUps;
|
|
|
|
|
Move4 = 0;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-05 02:27:28 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies the desired Ability option.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="n">Ability Number (0/1/2)</param>
|
2020-11-29 23:02:57 +00:00
|
|
|
|
public virtual void RefreshAbility(int n)
|
2017-01-26 06:51:52 +00:00
|
|
|
|
{
|
|
|
|
|
AbilityNumber = 1 << n;
|
2020-09-06 17:53:13 +00:00
|
|
|
|
var abilities = PersonalInfo.Abilities;
|
|
|
|
|
if ((uint)n < abilities.Count)
|
2017-01-26 06:51:52 +00:00
|
|
|
|
Ability = abilities[n];
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the IV Judge Rating value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>IV Judge scales his response 0 (worst) to 3 (best).</remarks>
|
2021-03-14 23:16:55 +00:00
|
|
|
|
public int PotentialRating => IVTotal switch
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2021-03-14 23:16:55 +00:00
|
|
|
|
<= 90 => 0,
|
|
|
|
|
<= 120 => 1,
|
|
|
|
|
<= 150 => 2,
|
2021-08-20 20:49:20 +00:00
|
|
|
|
_ => 3,
|
2021-03-14 23:16:55 +00:00
|
|
|
|
};
|
2016-07-21 03:40:03 +00:00
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the current Battle Stats.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="p"><see cref="PersonalInfo"/> entry containing Base Stat Info</param>
|
|
|
|
|
/// <returns>Battle Stats (H/A/B/S/C/D)</returns>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public virtual ushort[] GetStats(PersonalInfo p)
|
2016-07-21 03:40:03 +00:00
|
|
|
|
{
|
|
|
|
|
int level = CurrentLevel;
|
|
|
|
|
|
2018-12-04 04:59:48 +00:00
|
|
|
|
ushort[] stats = this is IHyperTrain t ? GetStats(p, t, level) : GetStats(p, level);
|
2016-07-21 03:40:03 +00:00
|
|
|
|
// Account for nature
|
2019-11-16 01:34:18 +00:00
|
|
|
|
PKX.ModifyStatsForNature(stats, StatNature);
|
2018-12-04 04:59:48 +00:00
|
|
|
|
return stats;
|
2016-07-21 03:40:03 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-06-06 04:31:42 +00:00
|
|
|
|
private ushort[] GetStats(PersonalInfo p, IHyperTrain t, int level)
|
|
|
|
|
{
|
2018-12-04 04:59:48 +00:00
|
|
|
|
ushort[] stats = new ushort[6];
|
|
|
|
|
stats[0] = (ushort)(p.HP == 1 ? 1 : (((t.HT_HP ? 31 : IV_HP) + (2 * p.HP) + (EV_HP / 4) + 100) * level / 100) + 10);
|
|
|
|
|
stats[1] = (ushort)((((t.HT_ATK ? 31 : IV_ATK) + (2 * p.ATK) + (EV_ATK / 4)) * level / 100) + 5);
|
|
|
|
|
stats[2] = (ushort)((((t.HT_DEF ? 31 : IV_DEF) + (2 * p.DEF) + (EV_DEF / 4)) * level / 100) + 5);
|
|
|
|
|
stats[4] = (ushort)((((t.HT_SPA ? 31 : IV_SPA) + (2 * p.SPA) + (EV_SPA / 4)) * level / 100) + 5);
|
|
|
|
|
stats[5] = (ushort)((((t.HT_SPD ? 31 : IV_SPD) + (2 * p.SPD) + (EV_SPD / 4)) * level / 100) + 5);
|
|
|
|
|
stats[3] = (ushort)((((t.HT_SPE ? 31 : IV_SPE) + (2 * p.SPE) + (EV_SPE / 4)) * level / 100) + 5);
|
|
|
|
|
return stats;
|
2018-06-06 04:31:42 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-06-06 04:31:42 +00:00
|
|
|
|
private ushort[] GetStats(PersonalInfo p, int level)
|
|
|
|
|
{
|
2018-12-04 04:59:48 +00:00
|
|
|
|
ushort[] stats = new ushort[6];
|
|
|
|
|
stats[0] = (ushort)(p.HP == 1 ? 1 : ((IV_HP + (2 * p.HP) + (EV_HP / 4) + 100) * level / 100) + 10);
|
|
|
|
|
stats[1] = (ushort)(((IV_ATK + (2 * p.ATK) + (EV_ATK / 4)) * level / 100) + 5);
|
|
|
|
|
stats[2] = (ushort)(((IV_DEF + (2 * p.DEF) + (EV_DEF / 4)) * level / 100) + 5);
|
|
|
|
|
stats[4] = (ushort)(((IV_SPA + (2 * p.SPA) + (EV_SPA / 4)) * level / 100) + 5);
|
|
|
|
|
stats[5] = (ushort)(((IV_SPD + (2 * p.SPD) + (EV_SPD / 4)) * level / 100) + 5);
|
|
|
|
|
stats[3] = (ushort)(((IV_SPE + (2 * p.SPE) + (EV_SPE / 4)) * level / 100) + 5);
|
|
|
|
|
return stats;
|
2018-06-06 04:31:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies the specified stats to the <see cref="PKM"/>.
|
|
|
|
|
/// </summary>
|
2018-12-04 04:59:48 +00:00
|
|
|
|
/// <param name="stats">Battle Stats (H/A/B/S/C/D)</param>
|
|
|
|
|
public void SetStats(ushort[] stats)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2018-12-04 04:59:48 +00:00
|
|
|
|
Stat_HPMax = Stat_HPCurrent = stats[0];
|
|
|
|
|
Stat_ATK = stats[1];
|
|
|
|
|
Stat_DEF = stats[2];
|
|
|
|
|
Stat_SPE = stats[3];
|
|
|
|
|
Stat_SPA = stats[4];
|
|
|
|
|
Stat_SPD = stats[5];
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-02-05 02:27:28 +00:00
|
|
|
|
|
2019-01-12 18:54:38 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if Party Stats are present. False if not initialized (from stored format).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool PartyStatsPresent => Stat_HPMax != 0;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clears any status condition and refreshes the stats.
|
|
|
|
|
/// </summary>
|
2019-07-12 23:41:13 +00:00
|
|
|
|
public void ResetPartyStats()
|
2019-01-12 06:25:48 +00:00
|
|
|
|
{
|
|
|
|
|
SetStats(GetStats(PersonalInfo));
|
2019-07-12 23:41:13 +00:00
|
|
|
|
Stat_Level = CurrentLevel;
|
2019-01-12 06:25:48 +00:00
|
|
|
|
Status_Condition = 0;
|
2019-07-12 23:41:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Heal()
|
|
|
|
|
{
|
|
|
|
|
ResetPartyStats();
|
2019-02-21 06:08:28 +00:00
|
|
|
|
HealPP();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Restores PP to maximum based on the current PP Ups for each move.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void HealPP()
|
|
|
|
|
{
|
|
|
|
|
Move1_PP = GetMovePP(Move1, Move1_PPUps);
|
|
|
|
|
Move2_PP = GetMovePP(Move2, Move2_PPUps);
|
|
|
|
|
Move3_PP = GetMovePP(Move3, Move3_PPUps);
|
|
|
|
|
Move4_PP = GetMovePP(Move4, Move4_PPUps);
|
2019-01-12 06:25:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 03:21:45 +00:00
|
|
|
|
public int HealPPIndex(int index) => index switch
|
|
|
|
|
{
|
|
|
|
|
0 => Move1_PP = GetMovePP(Move1, Move1_PPUps),
|
|
|
|
|
1 => Move2_PP = GetMovePP(Move2, Move2_PPUps),
|
|
|
|
|
2 => Move3_PP = GetMovePP(Move3, Move3_PPUps),
|
|
|
|
|
3 => Move4_PP = GetMovePP(Move4, Move4_PPUps),
|
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index)),
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-12 18:54:38 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Enforces that Party Stat values are present.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if stats were refreshed, false if stats were already present.</returns>
|
|
|
|
|
public bool ForcePartyData()
|
|
|
|
|
{
|
|
|
|
|
if (PartyStatsPresent)
|
|
|
|
|
return false;
|
2019-07-12 23:41:13 +00:00
|
|
|
|
ResetPartyStats();
|
2019-01-12 18:54:38 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the <see cref="PKM"/> can hold its <see cref="HeldItem"/>.
|
|
|
|
|
/// </summary>
|
2020-06-17 02:46:22 +00:00
|
|
|
|
/// <param name="valid">Items that the <see cref="PKM"/> can hold.</param>
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <returns>True/False if the <see cref="PKM"/> can hold its <see cref="HeldItem"/>.</returns>
|
2020-06-17 02:46:22 +00:00
|
|
|
|
public virtual bool CanHoldItem(IReadOnlyList<ushort> valid) => valid.Contains((ushort)HeldItem);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deep clones the <see cref="PKM"/> object. The clone will not have any shared resources with the source.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Cloned <see cref="PKM"/> object</returns>
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract PKM Clone();
|
2016-07-22 06:49:52 +00:00
|
|
|
|
|
2018-03-22 04:10:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets Link Trade data for an <see cref="IsEgg"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="day">Day the <see cref="PKM"/> was traded.</param>
|
|
|
|
|
/// <param name="month">Month the <see cref="PKM"/> was traded.</param>
|
|
|
|
|
/// <param name="y">Day the <see cref="PKM"/> was traded.</param>
|
|
|
|
|
/// <param name="location">Link Trade location value.</param>
|
2019-05-11 03:46:49 +00:00
|
|
|
|
protected void SetLinkTradeEgg(int day, int month, int y, int location)
|
2018-03-22 04:10:23 +00:00
|
|
|
|
{
|
|
|
|
|
Met_Day = day;
|
|
|
|
|
Met_Month = month;
|
|
|
|
|
Met_Year = y - 2000;
|
|
|
|
|
Met_Location = location;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the PP of a Move ID with consideration of the amount of PP Ups applied.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="move">Move ID</param>
|
2020-06-20 23:23:03 +00:00
|
|
|
|
/// <param name="ppUpCount">PP Ups count</param>
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <returns>Current PP for the move.</returns>
|
2020-06-20 23:23:03 +00:00
|
|
|
|
public virtual int GetMovePP(int move, int ppUpCount) => GetBasePP(move) * (5 + ppUpCount) / 5;
|
2016-07-22 06:49:52 +00:00
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the base PP of a move ID depending on the <see cref="PKM"/>'s format.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="move">Move ID</param>
|
|
|
|
|
/// <returns>Amount of PP the move has by default (no PP Ups).</returns>
|
2018-10-27 15:53:09 +00:00
|
|
|
|
private int GetBasePP(int move)
|
2016-07-22 06:49:52 +00:00
|
|
|
|
{
|
2020-06-17 02:46:22 +00:00
|
|
|
|
var table = Legal.GetPPTable(this, Format);
|
|
|
|
|
if (move >= table.Count)
|
2016-07-22 06:49:52 +00:00
|
|
|
|
move = 0;
|
2020-06-17 02:46:22 +00:00
|
|
|
|
return table[move];
|
2016-07-22 06:49:52 +00:00
|
|
|
|
}
|
2016-07-29 05:33:16 +00:00
|
|
|
|
|
2017-08-26 00:44:15 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies a shiny <see cref="PID"/> to the <see cref="PKM"/>.
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// If a <see cref="PKM"/> originated in a generation prior to Generation 6, the <see cref="EncryptionConstant"/> is updated.
|
2019-10-26 19:58:55 +00:00
|
|
|
|
/// If a <see cref="PKM"/> is in the <see cref="GBPKM"/> format, it will update the <see cref="IVs"/> instead.
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// </remarks>
|
2018-10-27 15:53:09 +00:00
|
|
|
|
public virtual void SetShiny()
|
2016-07-29 05:33:16 +00:00
|
|
|
|
{
|
2020-01-26 05:49:52 +00:00
|
|
|
|
var rnd = Util.Rand;
|
2020-12-11 04:42:30 +00:00
|
|
|
|
do { PID = PKX.GetRandomPID(rnd, Species, Gender, Version, Nature, Form, PID); }
|
2019-11-21 04:38:05 +00:00
|
|
|
|
while (!IsShiny);
|
2019-02-22 04:41:04 +00:00
|
|
|
|
if (Format >= 6 && (Gen3 || Gen4 || Gen5))
|
2016-08-15 06:23:38 +00:00
|
|
|
|
EncryptionConstant = PID;
|
2016-07-29 05:33:16 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
2017-08-26 00:44:15 +00:00
|
|
|
|
/// Applies a shiny <see cref="SID"/> to the <see cref="PKM"/>.
|
2017-06-03 10:02:22 +00:00
|
|
|
|
/// </summary>
|
2020-10-25 17:42:48 +00:00
|
|
|
|
public void SetShinySID(Shiny shiny = Shiny.Random)
|
2017-06-03 10:02:22 +00:00
|
|
|
|
{
|
2020-10-25 17:42:48 +00:00
|
|
|
|
if (IsShiny && shiny.IsValid(this))
|
2020-01-26 05:49:52 +00:00
|
|
|
|
return;
|
2020-10-25 17:42:48 +00:00
|
|
|
|
|
2017-06-03 15:58:30 +00:00
|
|
|
|
var xor = TID ^ (PID >> 16) ^ (PID & 0xFFFF);
|
2020-10-25 17:42:48 +00:00
|
|
|
|
var bits = shiny switch
|
|
|
|
|
{
|
|
|
|
|
Shiny.AlwaysSquare => 0,
|
|
|
|
|
Shiny.AlwaysStar => 1,
|
2021-08-20 20:49:20 +00:00
|
|
|
|
_ => Util.Rand.Next(8),
|
2020-10-25 17:42:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SID = (int)xor ^ bits;
|
2017-06-03 10:02:22 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-03 10:02:22 +00:00
|
|
|
|
/// <summary>
|
2017-08-26 00:44:15 +00:00
|
|
|
|
/// Applies a <see cref="PID"/> to the <see cref="PKM"/> according to the specified <see cref="Gender"/>.
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// </summary>
|
2018-05-12 19:28:48 +00:00
|
|
|
|
/// <param name="gender"><see cref="Gender"/> to apply</param>
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
/// If a <see cref="PKM"/> originated in a generation prior to Generation 6, the <see cref="EncryptionConstant"/> is updated.
|
|
|
|
|
/// </remarks>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void SetPIDGender(int gender)
|
2016-07-29 05:54:29 +00:00
|
|
|
|
{
|
2020-01-26 05:49:52 +00:00
|
|
|
|
var rnd = Util.Rand;
|
2020-12-11 04:42:30 +00:00
|
|
|
|
do PID = PKX.GetRandomPID(rnd, Species, gender, Version, Nature, Form, PID);
|
2020-01-26 05:49:52 +00:00
|
|
|
|
while (IsShiny);
|
2019-02-22 04:41:04 +00:00
|
|
|
|
if (Format >= 6 && (Gen3 || Gen4 || Gen5))
|
2016-08-15 06:23:38 +00:00
|
|
|
|
EncryptionConstant = PID;
|
2016-07-30 05:30:06 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
2017-08-26 00:44:15 +00:00
|
|
|
|
/// Applies a <see cref="PID"/> to the <see cref="PKM"/> according to the specified <see cref="Gender"/>.
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// </summary>
|
2018-05-12 19:28:48 +00:00
|
|
|
|
/// <param name="nature"><see cref="Nature"/> to apply</param>
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
/// If a <see cref="PKM"/> originated in a generation prior to Generation 6, the <see cref="EncryptionConstant"/> is updated.
|
|
|
|
|
/// </remarks>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void SetPIDNature(int nature)
|
2016-07-30 05:30:06 +00:00
|
|
|
|
{
|
2020-01-26 05:49:52 +00:00
|
|
|
|
var rnd = Util.Rand;
|
2020-12-11 04:42:30 +00:00
|
|
|
|
do PID = PKX.GetRandomPID(rnd, Species, Gender, Version, nature, Form, PID);
|
2020-01-26 05:49:52 +00:00
|
|
|
|
while (IsShiny);
|
2019-02-22 04:41:04 +00:00
|
|
|
|
if (Format >= 6 && (Gen3 || Gen4 || Gen5))
|
2016-08-15 06:23:38 +00:00
|
|
|
|
EncryptionConstant = PID;
|
2016-07-29 05:54:29 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
2020-12-11 04:42:30 +00:00
|
|
|
|
/// Applies a <see cref="PID"/> to the <see cref="PKM"/> according to the specified <see cref="Form"/>.
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// </summary>
|
2020-12-11 04:42:30 +00:00
|
|
|
|
/// <param name="form"><see cref="Form"/> to apply</param>
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method should only be used for Unown originating in Generation 3 games.
|
|
|
|
|
/// If a <see cref="PKM"/> originated in a generation prior to Generation 6, the <see cref="EncryptionConstant"/> is updated.
|
|
|
|
|
/// </remarks>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void SetPIDUnown3(int form)
|
2016-08-28 01:42:07 +00:00
|
|
|
|
{
|
2021-06-24 07:36:04 +00:00
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
|
do PID = Util.Rand32(rnd); while (PKX.GetUnownForm(PID) != form);
|
2019-02-22 04:41:04 +00:00
|
|
|
|
if (Format >= 6 && (Gen3 || Gen4 || Gen5))
|
2018-02-09 02:47:52 +00:00
|
|
|
|
EncryptionConstant = PID;
|
2016-08-28 01:42:07 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Randomizes the IVs within game constraints.
|
|
|
|
|
/// </summary>
|
2018-05-12 19:28:48 +00:00
|
|
|
|
/// <param name="flawless">Count of flawless IVs to set. If none provided, a count will be detected.</param>
|
2017-05-23 04:55:05 +00:00
|
|
|
|
/// <returns>Randomized IVs if desired.</returns>
|
2018-03-29 03:56:58 +00:00
|
|
|
|
public int[] SetRandomIVs(int? flawless = null)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-12-13 02:06:39 +00:00
|
|
|
|
if (Version == (int)GameVersion.GO && flawless != 6)
|
|
|
|
|
return SetRandomIVsGO();
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
int[] ivs = new int[6];
|
2020-01-26 05:49:52 +00:00
|
|
|
|
var rnd = Util.Rand;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
for (int i = 0; i < 6; i++)
|
2020-01-26 05:49:52 +00:00
|
|
|
|
ivs[i] = rnd.Next(MaxIV + 1);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-03-29 03:56:58 +00:00
|
|
|
|
int count = flawless ?? GetFlawlessIVCount();
|
2017-11-02 16:05:44 +00:00
|
|
|
|
if (count != 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2017-11-02 16:05:44 +00:00
|
|
|
|
for (int i = 0; i < count; i++)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
ivs[i] = MaxIV;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
Util.Shuffle(ivs.AsSpan(), 0, ivs.Length, rnd); // Randomize IV order
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-12-13 02:06:39 +00:00
|
|
|
|
return IVs = ivs;
|
|
|
|
|
}
|
2017-11-02 16:05:44 +00:00
|
|
|
|
|
2021-09-18 00:56:15 +00:00
|
|
|
|
public int[] SetRandomIVsGO(int minIV = 0, int maxIV = 15)
|
2018-12-13 02:06:39 +00:00
|
|
|
|
{
|
|
|
|
|
int[] ivs = new int[6];
|
2020-01-26 05:49:52 +00:00
|
|
|
|
var rnd = Util.Rand;
|
2021-09-18 00:56:15 +00:00
|
|
|
|
ivs[0] = (rnd.Next(minIV, maxIV + 1) << 1) | 1; // hp
|
|
|
|
|
ivs[1] = ivs[4] = (rnd.Next(minIV, maxIV + 1) << 1) | 1; // attack
|
|
|
|
|
ivs[2] = ivs[5] = (rnd.Next(minIV, maxIV + 1) << 1) | 1; // defense
|
2020-01-26 05:49:52 +00:00
|
|
|
|
ivs[3] = rnd.Next(MaxIV + 1); // speed
|
2018-12-13 02:06:39 +00:00
|
|
|
|
return IVs = ivs;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2017-11-02 16:05:44 +00:00
|
|
|
|
|
2018-03-31 07:43:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Randomizes the IVs within game constraints.
|
|
|
|
|
/// </summary>
|
2018-05-12 19:28:48 +00:00
|
|
|
|
/// <param name="template">IV template to generate from</param>
|
|
|
|
|
/// <param name="flawless">Count of flawless IVs to set. If none provided, a count will be detected.</param>
|
2018-03-31 07:43:41 +00:00
|
|
|
|
/// <returns>Randomized IVs if desired.</returns>
|
2020-01-19 03:11:29 +00:00
|
|
|
|
public int[] SetRandomIVs(IReadOnlyList<int> template, int? flawless = null)
|
2018-03-31 07:43:41 +00:00
|
|
|
|
{
|
|
|
|
|
int count = flawless ?? GetFlawlessIVCount();
|
|
|
|
|
int[] ivs = new int[6];
|
2020-01-26 05:49:52 +00:00
|
|
|
|
var rnd = Util.Rand;
|
2018-03-31 07:43:41 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
2020-01-26 05:49:52 +00:00
|
|
|
|
ivs[i] = template[i] < 0 ? rnd.Next(MaxIV + 1) : template[i];
|
2018-03-31 07:43:41 +00:00
|
|
|
|
} while (ivs.Count(z => z == MaxIV) < count);
|
2018-04-30 01:26:36 +00:00
|
|
|
|
|
|
|
|
|
IVs = ivs;
|
2018-03-31 07:43:41 +00:00
|
|
|
|
return ivs;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-02 16:05:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the amount of flawless IVs that the <see cref="PKM"/> should have.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Count of IVs that should be max.</returns>
|
|
|
|
|
public int GetFlawlessIVCount()
|
|
|
|
|
{
|
2020-12-11 04:42:30 +00:00
|
|
|
|
if (Generation >= 6 && (Legal.Legends.Contains(Species) || Legal.SubLegends.Contains(Species)))
|
2017-11-02 16:05:44 +00:00
|
|
|
|
return 3;
|
2018-06-25 04:55:00 +00:00
|
|
|
|
if (XY)
|
|
|
|
|
{
|
|
|
|
|
if (PersonalInfo.EggGroup1 == 15) // Undiscovered
|
|
|
|
|
return 3;
|
2020-09-04 02:00:46 +00:00
|
|
|
|
if (Met_Location == 148 && Met_Level == 30) // Friend Safari
|
|
|
|
|
return 2;
|
2018-06-25 04:55:00 +00:00
|
|
|
|
}
|
2017-11-02 16:05:44 +00:00
|
|
|
|
if (VC)
|
2020-12-25 20:30:26 +00:00
|
|
|
|
return Species is (int)Core.Species.Mew or (int)Core.Species.Celebi ? 5 : 3;
|
2022-02-10 03:26:18 +00:00
|
|
|
|
if (this is IAlpha {IsAlpha: true})
|
|
|
|
|
return 3;
|
2017-11-02 16:05:44 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// <summary>
|
2018-02-03 23:32:45 +00:00
|
|
|
|
/// Applies all shared properties from the current <see cref="PKM"/> to <see cref="Destination"/> <see cref="PKM"/>.
|
2017-02-05 02:27:28 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Destination"><see cref="PKM"/> that receives property values.</param>
|
2018-02-03 23:32:45 +00:00
|
|
|
|
public void TransferPropertiesWithReflection(PKM Destination)
|
2016-10-02 17:18:31 +00:00
|
|
|
|
{
|
2017-03-03 05:00:41 +00:00
|
|
|
|
// Only transfer declared properties not defined in PKM.cs but in the actual type
|
2020-06-17 02:46:22 +00:00
|
|
|
|
var srcType = GetType();
|
|
|
|
|
var destType = Destination.GetType();
|
2021-02-15 21:52:49 +00:00
|
|
|
|
var srcProperties = ReflectUtil.GetPropertiesCanWritePublicDeclared(srcType);
|
|
|
|
|
var destProperties = ReflectUtil.GetPropertiesCanWritePublicDeclared(destType);
|
2018-02-03 23:32:45 +00:00
|
|
|
|
|
|
|
|
|
// Transfer properties in the order they are defined in the destination PKM format for best conversion
|
2020-06-17 02:46:22 +00:00
|
|
|
|
var shared = destProperties.Intersect(srcProperties);
|
2018-02-03 23:32:45 +00:00
|
|
|
|
foreach (string property in shared)
|
2016-10-02 17:18:31 +00:00
|
|
|
|
{
|
2021-01-17 08:05:07 +00:00
|
|
|
|
if (!BatchEditing.TryGetHasProperty(this, property, out var src))
|
|
|
|
|
continue;
|
2018-05-18 05:43:07 +00:00
|
|
|
|
var prop = src.GetValue(this);
|
2021-02-15 21:52:49 +00:00
|
|
|
|
if (prop is not (byte[] or null) && BatchEditing.TryGetHasProperty(Destination, property, out var pi))
|
2018-05-18 05:43:07 +00:00
|
|
|
|
ReflectUtil.SetValue(pi, Destination, prop);
|
2016-10-02 17:18:31 +00:00
|
|
|
|
}
|
2021-02-15 21:52:49 +00:00
|
|
|
|
|
|
|
|
|
// set shared properties for the Gen1/2 base class
|
|
|
|
|
if (Destination is GBPKM l)
|
|
|
|
|
l.ImportFromFuture(this);
|
2016-10-02 17:18:31 +00:00
|
|
|
|
}
|
2017-06-10 15:31:31 +00:00
|
|
|
|
|
2020-08-18 22:39:45 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the <see cref="PKM"/> has the <see cref="move"/> in its current move list.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool HasMove(int move) => Move1 == move || Move2 == move || Move3 == move || Move4 == move;
|
|
|
|
|
|
2020-09-05 19:11:43 +00:00
|
|
|
|
public int GetMoveIndex(int move) => Move1 == move ? 0 : Move2 == move ? 1 : Move3 == move ? 2 : Move4 == move ? 3 : -1;
|
|
|
|
|
|
2021-01-02 01:08:49 +00:00
|
|
|
|
public int GetMove(int index) => index switch
|
2020-09-05 19:11:43 +00:00
|
|
|
|
{
|
2021-01-02 01:08:49 +00:00
|
|
|
|
0 => Move1,
|
|
|
|
|
1 => Move2,
|
|
|
|
|
2 => Move3,
|
|
|
|
|
3 => Move4,
|
|
|
|
|
_ => throw new IndexOutOfRangeException(nameof(index)),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public int SetMove(int index, int value) => index switch
|
2020-09-05 19:11:43 +00:00
|
|
|
|
{
|
2021-01-02 01:08:49 +00:00
|
|
|
|
0 => Move1 = value,
|
|
|
|
|
1 => Move2 = value,
|
|
|
|
|
2 => Move3 = value,
|
|
|
|
|
3 => Move4 = value,
|
2021-08-20 20:49:20 +00:00
|
|
|
|
_ => throw new IndexOutOfRangeException(nameof(index)),
|
2021-01-02 01:08:49 +00:00
|
|
|
|
};
|
2020-09-05 19:11:43 +00:00
|
|
|
|
|
2017-06-10 15:31:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clears moves that a <see cref="PKM"/> may have, possibly from a future generation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ClearInvalidMoves()
|
|
|
|
|
{
|
|
|
|
|
uint invalid = 0;
|
|
|
|
|
var moves = Moves;
|
|
|
|
|
for (var i = 0; i < moves.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (moves[i] <= MaxMoveID)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
invalid++;
|
|
|
|
|
moves[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
if (invalid == 0)
|
|
|
|
|
return;
|
2017-06-10 15:39:04 +00:00
|
|
|
|
if (invalid == 4) // no moves remain
|
|
|
|
|
{
|
|
|
|
|
moves[0] = 1; // Pound
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Move1_PP = GetMovePP(1, Move1_PPUps);
|
2017-06-10 15:39:04 +00:00
|
|
|
|
}
|
2017-06-10 15:31:31 +00:00
|
|
|
|
|
|
|
|
|
Moves = moves;
|
|
|
|
|
FixMoves();
|
|
|
|
|
}
|
2019-01-05 18:51:41 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets one of the <see cref="EVs"/> based on its index within the array.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">Index to get</param>
|
2021-01-02 01:08:49 +00:00
|
|
|
|
public int GetEV(int index) => index switch
|
2019-01-05 18:51:41 +00:00
|
|
|
|
{
|
2021-01-02 01:08:49 +00:00
|
|
|
|
0 => EV_HP,
|
|
|
|
|
1 => EV_ATK,
|
|
|
|
|
2 => EV_DEF,
|
|
|
|
|
3 => EV_SPE,
|
|
|
|
|
4 => EV_SPA,
|
|
|
|
|
5 => EV_SPD,
|
2021-08-20 20:49:20 +00:00
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index)),
|
2021-01-02 01:08:49 +00:00
|
|
|
|
};
|
2019-01-05 18:51:41 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets one of the <see cref="IVs"/> based on its index within the array.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">Index to get</param>
|
2021-01-02 01:08:49 +00:00
|
|
|
|
public int GetIV(int index) => index switch
|
2019-01-05 18:51:41 +00:00
|
|
|
|
{
|
2021-01-02 01:08:49 +00:00
|
|
|
|
0 => IV_HP,
|
|
|
|
|
1 => IV_ATK,
|
|
|
|
|
2 => IV_DEF,
|
|
|
|
|
3 => IV_SPE,
|
|
|
|
|
4 => IV_SPA,
|
|
|
|
|
5 => IV_SPD,
|
2021-08-20 20:49:20 +00:00
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index)),
|
2021-01-02 01:08:49 +00:00
|
|
|
|
};
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|