2022-06-18 18:04:24 +00:00
|
|
|
using System;
|
2019-02-24 00:05:01 +00:00
|
|
|
using System.Collections.Generic;
|
2023-01-22 04:02:33 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2016-06-20 04:22:43 +00:00
|
|
|
using System.Linq;
|
2020-12-25 20:30:26 +00:00
|
|
|
using static PKHeX.Core.GameVersion;
|
2023-01-22 04:02:33 +00:00
|
|
|
using static System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Object representing a <see cref="PKM"/>'s data and derived properties.
|
|
|
|
/// </summary>
|
2023-01-22 04:02:33 +00:00
|
|
|
[DynamicallyAccessedMembers(PublicProperties | NonPublicProperties | PublicParameterlessConstructor)]
|
|
|
|
public abstract class PKM : ISpeciesForm, ITrainerID32, IGeneration, IShiny, ILangNick, IGameValueLimit, INature, IFatefulEncounter
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
/// <summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
/// Valid file extensions that represent <see cref="PKM"/> data, without the leading '.'
|
|
|
|
/// </summary>
|
|
|
|
public static readonly string[] Extensions = EntityFileExtension.GetExtensions();
|
|
|
|
public abstract int SIZE_PARTY { get; }
|
|
|
|
public abstract int SIZE_STORED { get; }
|
|
|
|
public string Extension => GetType().Name.ToLowerInvariant();
|
|
|
|
public abstract PersonalInfo PersonalInfo { get; }
|
2023-12-04 04:13:20 +00:00
|
|
|
public virtual ReadOnlySpan<ushort> ExtraBytes => [];
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Internal Attributes set on creation
|
|
|
|
public readonly byte[] Data; // Raw Storage
|
|
|
|
|
|
|
|
protected PKM(byte[] data) => Data = data;
|
2023-08-28 06:05:50 +00:00
|
|
|
protected PKM([ConstantExpected] int size) => Data = new byte[size];
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2022-08-05 18:23:28 +00:00
|
|
|
public virtual byte[] EncryptedPartyData => Encrypt().AsSpan(0, SIZE_PARTY).ToArray();
|
|
|
|
public virtual byte[] EncryptedBoxData => Encrypt().AsSpan(0, SIZE_STORED).ToArray();
|
|
|
|
public virtual byte[] DecryptedPartyData => Write().AsSpan(0, SIZE_PARTY).ToArray();
|
|
|
|
public virtual byte[] DecryptedBoxData => Write().AsSpan(0, SIZE_STORED).ToArray();
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Rough indication if the data is junk or not.
|
|
|
|
/// </summary>
|
|
|
|
public abstract bool Valid { get; set; }
|
|
|
|
|
|
|
|
// Trash Bytes
|
2024-02-23 03:20:54 +00:00
|
|
|
public abstract Span<byte> NicknameTrash { get; }
|
|
|
|
public abstract Span<byte> OriginalTrainerTrash { get; }
|
|
|
|
public virtual Span<byte> HandlingTrainerTrash => [];
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
protected abstract byte[] Encrypt();
|
|
|
|
public abstract EntityContext Context { get; }
|
2024-02-23 03:20:54 +00:00
|
|
|
public byte Format => Context.Generation();
|
2023-01-22 04:02:33 +00:00
|
|
|
public TrainerIDFormat TrainerIDDisplayFormat => this.GetTrainerIDFormat();
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
private byte[] Write()
|
|
|
|
{
|
|
|
|
RefreshChecksum();
|
|
|
|
return Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Surface Properties
|
2022-08-27 06:43:36 +00:00
|
|
|
public abstract ushort Species { get; set; }
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract string Nickname { get; set; }
|
|
|
|
public abstract int HeldItem { get; set; }
|
2024-02-23 03:20:54 +00:00
|
|
|
public abstract byte Gender { get; set; }
|
|
|
|
public abstract Nature Nature { get; set; }
|
|
|
|
public virtual Nature StatNature { get => Nature; set => Nature = value; }
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract int Ability { get; set; }
|
2024-02-23 03:20:54 +00:00
|
|
|
public abstract byte CurrentFriendship { get; set; }
|
2022-08-27 06:43:36 +00:00
|
|
|
public abstract byte Form { get; set; }
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract bool IsEgg { get; set; }
|
|
|
|
public abstract bool IsNicknamed { get; set; }
|
|
|
|
public abstract uint EXP { get; set; }
|
2023-01-22 04:02:33 +00:00
|
|
|
public abstract ushort TID16 { get; set; }
|
|
|
|
public abstract ushort SID16 { get; set; }
|
2024-02-23 03:20:54 +00:00
|
|
|
public abstract string OriginalTrainerName { get; set; }
|
|
|
|
public abstract byte OriginalTrainerGender { get; set; }
|
|
|
|
public abstract byte Ball { get; set; }
|
|
|
|
public abstract byte MetLevel { get; set; }
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
// Aliases of ID32
|
|
|
|
public uint TrainerTID7 { get => this.GetTrainerTID7(); set => this.SetTrainerTID7(value); }
|
|
|
|
public uint TrainerSID7 { get => this.GetTrainerSID7(); set => this.SetTrainerSID7(value); }
|
|
|
|
public uint DisplayTID { get => this.GetDisplayTID(); set => this.SetDisplayTID(value); }
|
|
|
|
public uint DisplaySID { get => this.GetDisplaySID(); set => this.SetDisplaySID(value); }
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Battle
|
2022-08-27 06:43:36 +00:00
|
|
|
public abstract ushort Move1 { get; set; }
|
|
|
|
public abstract ushort Move2 { get; set; }
|
|
|
|
public abstract ushort Move3 { get; set; }
|
|
|
|
public abstract ushort Move4 { get; set; }
|
2022-06-18 18:04:24 +00:00
|
|
|
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; }
|
|
|
|
public abstract int Status_Condition { get; set; }
|
2024-02-23 03:20:54 +00:00
|
|
|
public abstract byte Stat_Level { get; set; }
|
2022-06-18 18:04:24 +00:00
|
|
|
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
|
2024-02-23 03:20:54 +00:00
|
|
|
public abstract GameVersion Version { get; set; }
|
2023-01-22 04:02:33 +00:00
|
|
|
public abstract uint ID32 { get; set; }
|
2024-02-23 03:20:54 +00:00
|
|
|
public abstract int PokerusStrain { get; set; }
|
|
|
|
public abstract int PokerusDays { get; set; }
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
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; }
|
2023-01-22 04:02:33 +00:00
|
|
|
public abstract uint TSV { get; }
|
|
|
|
public abstract uint PSV { get; }
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract int Characteristic { get; }
|
2024-02-23 03:20:54 +00:00
|
|
|
public abstract ushort MetLocation { get; set; }
|
|
|
|
public abstract ushort EggLocation { get; set; }
|
|
|
|
public abstract byte OriginalTrainerFriendship { get; set; }
|
2022-06-18 18:04:24 +00:00
|
|
|
public virtual bool Japanese => Language == (int)LanguageID.Japanese;
|
|
|
|
public virtual bool Korean => Language == (int)LanguageID.Korean;
|
|
|
|
|
|
|
|
// Future Properties
|
2024-02-23 03:20:54 +00:00
|
|
|
public virtual byte MetYear { get => 0; set { } }
|
|
|
|
public virtual byte MetMonth { get => 0; set { } }
|
|
|
|
public virtual byte MetDay { get => 0; set { } }
|
|
|
|
public virtual string HandlingTrainerName { get => string.Empty; set { } }
|
|
|
|
public virtual byte HandlingTrainerGender { get => 0; set { } }
|
|
|
|
public virtual byte HandlingTrainerFriendship { get => 0; set { } }
|
2022-06-18 18:04:24 +00:00
|
|
|
public virtual byte Enjoyment { get => 0; set { } }
|
|
|
|
public virtual byte Fullness { get => 0; set { } }
|
|
|
|
public virtual int AbilityNumber { get => 0; set { } }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The date the Pokémon was met.
|
2017-10-24 06:12:58 +00:00
|
|
|
/// </summary>
|
2022-06-18 18:04:24 +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>
|
2023-01-22 04:02:33 +00:00
|
|
|
public DateOnly? MetDate
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
get
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Check to see if date is valid
|
2024-02-23 03:20:54 +00:00
|
|
|
if (!DateUtil.IsDateValid(2000 + MetYear, MetMonth, MetDay))
|
2022-06-18 18:04:24 +00:00
|
|
|
return null;
|
2024-02-23 03:20:54 +00:00
|
|
|
return new DateOnly(2000 + MetYear, MetMonth, MetDay);
|
2016-06-20 04:22:43 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
set
|
2016-08-10 14:02:31 +00:00
|
|
|
{
|
2024-03-09 03:30:21 +00:00
|
|
|
if (value is { } dt)
|
2016-08-10 14:02:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Only update the properties if a value is provided.
|
2024-03-09 03:30:21 +00:00
|
|
|
MetYear = (byte)(dt.Year - 2000);
|
|
|
|
MetMonth = (byte)dt.Month;
|
|
|
|
MetDay = (byte)dt.Day;
|
2016-08-10 14:02:31 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2016-08-10 14:02:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Clear the Met Date.
|
|
|
|
// If code tries to access MetDate again, null will be returned.
|
2024-02-23 03:20:54 +00:00
|
|
|
MetYear = 0;
|
|
|
|
MetMonth = 0;
|
|
|
|
MetDay = 0;
|
2016-08-10 14:02:31 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public virtual byte EggYear { get => 0; set { } }
|
|
|
|
public virtual byte EggMonth { get => 0; set { } }
|
|
|
|
public virtual byte EggDay { get => 0; set { } }
|
2016-08-10 14:02:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The date a Pokémon was met as an egg.
|
|
|
|
/// </summary>
|
|
|
|
/// <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>
|
2023-01-22 04:02:33 +00:00
|
|
|
public DateOnly? EggMetDate
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
// Check to see if date is valid
|
2024-02-23 03:20:54 +00:00
|
|
|
if (!DateUtil.IsDateValid(2000 + EggYear, EggMonth, EggDay))
|
2022-06-18 18:04:24 +00:00
|
|
|
return null;
|
2024-02-23 03:20:54 +00:00
|
|
|
return new DateOnly(2000 + EggYear, EggMonth, EggDay);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
set
|
2016-08-10 14:02:31 +00:00
|
|
|
{
|
2024-03-09 03:30:21 +00:00
|
|
|
if (value is { } dt)
|
2016-08-10 14:02:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Only update the properties if a value is provided.
|
2024-03-09 03:30:21 +00:00
|
|
|
EggYear = (byte)(dt.Year - 2000);
|
|
|
|
EggMonth = (byte)dt.Month;
|
|
|
|
EggDay = (byte)dt.Day;
|
2016-08-10 14:02:31 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2016-08-10 14:02:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Clear the Met Date.
|
|
|
|
// If code tries to access MetDate again, null will be returned.
|
2024-02-23 03:20:54 +00:00
|
|
|
EggYear = 0;
|
|
|
|
EggMonth = 0;
|
|
|
|
EggDay = 0;
|
2016-08-10 14:02:31 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-08-10 14:02:31 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public virtual ushort RelearnMove1 { get => 0; set { } }
|
|
|
|
public virtual ushort RelearnMove2 { get => 0; set { } }
|
|
|
|
public virtual ushort RelearnMove3 { get => 0; set { } }
|
|
|
|
public virtual ushort RelearnMove4 { get => 0; set { } }
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Exposed but not Present in all
|
2024-02-23 03:20:54 +00:00
|
|
|
public abstract byte CurrentHandler { get; set; }
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Maximums
|
2022-08-27 06:43:36 +00:00
|
|
|
public abstract ushort MaxMoveID { get; }
|
|
|
|
public abstract ushort MaxSpeciesID { get; }
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract int MaxItemID { get; }
|
|
|
|
public abstract int MaxAbilityID { get; }
|
|
|
|
public abstract int MaxBallID { get; }
|
2024-02-23 03:20:54 +00:00
|
|
|
public abstract GameVersion MaxGameID { get; }
|
|
|
|
public virtual GameVersion MinGameID => 0;
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract int MaxIV { get; }
|
|
|
|
public abstract int MaxEV { get; }
|
2022-11-25 01:42:17 +00:00
|
|
|
public abstract int MaxStringLengthOT { get; }
|
|
|
|
public abstract int MaxStringLengthNickname { get; }
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Derived
|
|
|
|
public virtual int SpriteItem => HeldItem;
|
|
|
|
public virtual bool IsShiny => TSV == PSV;
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public ushort ShinyXor
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
get
|
2019-11-21 04:38:05 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var tmp = ID32 ^ PID;
|
|
|
|
return (ushort)(tmp ^ (tmp >> 16));
|
2019-11-21 04:38:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-11-21 04:38:05 +00:00
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public bool E => Version == GameVersion.E;
|
|
|
|
public bool FRLG => Version is FR or LG;
|
|
|
|
public bool Pt => GameVersion.Pt == Version;
|
|
|
|
public bool HGSS => Version is HG or SS;
|
|
|
|
public bool BW => Version is B or W;
|
|
|
|
public bool B2W2 => Version is B2 or W2;
|
|
|
|
public bool XY => Version is X or Y;
|
|
|
|
public bool AO => Version is AS or OR;
|
|
|
|
public bool SM => Version is SN or MN;
|
|
|
|
public bool USUM => Version is US or UM;
|
|
|
|
public bool GO => Version is GameVersion.GO;
|
|
|
|
public bool VC1 => Version is >= RD and <= YW;
|
|
|
|
public bool VC2 => Version is >= GD and <= C;
|
|
|
|
public bool LGPE => Version is GP or GE;
|
|
|
|
public bool SWSH => Version is SW or SH;
|
|
|
|
public virtual bool BDSP => Version is BD or SP;
|
|
|
|
public virtual bool LA => Version is PLA;
|
|
|
|
public virtual bool SV => Version is SL or VL;
|
|
|
|
|
|
|
|
public bool GO_LGPE => GO && MetLocation == Locations.GO7;
|
|
|
|
public bool GO_HOME => GO && MetLocation == Locations.GO8;
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool VC => VC1 || VC2;
|
|
|
|
public bool GG => LGPE || GO_LGPE;
|
2022-11-25 01:42:17 +00:00
|
|
|
public bool Gen9 => SV;
|
2024-02-23 03:20:54 +00:00
|
|
|
public bool Gen8 => Version is >= SW and <= SP || GO_HOME;
|
|
|
|
public bool Gen7 => Version is >= SN and <= UM || GG;
|
|
|
|
public bool Gen6 => Version is >= X and <= OR;
|
|
|
|
public bool Gen5 => Version is >= W and <= B2;
|
|
|
|
public bool Gen4 => Version is HG or SS or D or P or GameVersion.Pt;
|
|
|
|
public bool Gen3 => Version is (>= S and <= LG) or CXD;
|
|
|
|
public bool Gen2 => Version == GSC; // Fixed value set by the Gen2 PKM classes
|
|
|
|
public bool Gen1 => Version == RBY; // Fixed value set by the Gen1 PKM classes
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool GenU => Generation <= 0;
|
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public byte Generation
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
get
|
2016-08-09 01:42:42 +00:00
|
|
|
{
|
2022-11-25 01:42:17 +00:00
|
|
|
if (Gen9) return 9;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Gen8) return 8;
|
|
|
|
if (Gen7) return 7;
|
|
|
|
if (Gen6) return 6;
|
|
|
|
if (Gen5) return 5;
|
|
|
|
if (Gen4) return 4;
|
|
|
|
if (Gen3) return 3;
|
|
|
|
if (Gen2) return Format; // 2
|
|
|
|
if (Gen1) return Format; // 1
|
|
|
|
if (VC1) return 1;
|
|
|
|
if (VC2) return 2;
|
2024-02-23 03:20:54 +00:00
|
|
|
return 0;
|
2016-08-09 01:42:42 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public bool IsPokerusInfected { get => PokerusDays != 0 || PokerusStrain != 0; set => PokerusStrain = value ? Math.Max(PokerusStrain, 1) : 0; }
|
2019-03-21 23:48:17 +00:00
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public bool IsPokerusCured
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
get => PokerusDays == 0 && PokerusStrain > 0;
|
2022-06-18 18:04:24 +00:00
|
|
|
set
|
2019-03-21 23:48:17 +00:00
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
PokerusDays = value ? 0 : 1;
|
|
|
|
IsPokerusInfected = true;
|
2019-03-21 23:48:17 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-03-21 23:48:17 +00:00
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public byte CurrentLevel { get => Experience.GetLevel(EXP, PersonalInfo.EXPGrowth); set => EXP = Experience.GetEXP(Stat_Level = value, PersonalInfo.EXPGrowth); }
|
2022-06-18 18:04:24 +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;
|
|
|
|
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);
|
2019-01-05 18:51:41 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int FlawlessIVCount
|
|
|
|
{
|
|
|
|
get
|
2019-01-05 18:51:41 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
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;
|
2019-01-05 18:51:41 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-11-24 04:24:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public string FileName => $"{FileNameWithoutExtension}.{Extension}";
|
2018-09-16 17:48:04 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public string FileNameWithoutExtension => EntityFileNamer.GetName(this);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int[] IVs
|
|
|
|
{
|
2023-12-04 04:13:20 +00:00
|
|
|
get => [IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_SPD];
|
2022-06-18 18:04:24 +00:00
|
|
|
set => SetIVs(value);
|
|
|
|
}
|
2022-01-03 05:35:59 +00:00
|
|
|
|
2023-10-30 03:27:42 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Retrieves the IVs of the PKM in the order HP, ATK, DEF, SPE, SPA, SPD
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">Span of length 6 to write the IVs to</param>
|
2022-06-18 18:04:24 +00:00
|
|
|
public void GetIVs(Span<int> value)
|
|
|
|
{
|
|
|
|
if (value.Length != 6)
|
|
|
|
return;
|
|
|
|
value[0] = IV_HP;
|
|
|
|
value[1] = IV_ATK;
|
|
|
|
value[2] = IV_DEF;
|
|
|
|
value[3] = IV_SPE;
|
|
|
|
value[4] = IV_SPA;
|
|
|
|
value[5] = IV_SPD;
|
|
|
|
}
|
2022-03-14 02:24:08 +00:00
|
|
|
|
2023-10-30 03:27:42 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Sets the IVs of the PKM in the order HP, ATK, DEF, SPE, SPA, SPD
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">Span of length 6 to read the IVs from</param>
|
2022-06-18 18:04:24 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2023-10-30 03:27:42 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Retrieves the EVs of the PKM in the order HP, ATK, DEF, SPE, SPA, SPD
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">Span of length 6 to write the EVs to</param>
|
2022-06-18 18:04:24 +00:00
|
|
|
public void GetEVs(Span<int> value)
|
|
|
|
{
|
|
|
|
if (value.Length != 6)
|
|
|
|
return;
|
|
|
|
value[0] = EV_HP;
|
|
|
|
value[1] = EV_ATK;
|
|
|
|
value[2] = EV_DEF;
|
|
|
|
value[3] = EV_SPE;
|
|
|
|
value[4] = EV_SPA;
|
|
|
|
value[5] = EV_SPD;
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2023-10-30 03:27:42 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Sets the EVs of the PKM in the order HP, ATK, DEF, SPE, SPA, SPD
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">Span of length 6 to read the EVs from</param>
|
2022-06-18 18:04:24 +00:00
|
|
|
public void SetEVs(ReadOnlySpan<int> value)
|
|
|
|
{
|
|
|
|
if (value.Length != 6)
|
|
|
|
return;
|
|
|
|
EV_HP = value[0];
|
|
|
|
EV_ATK = value[1];
|
|
|
|
EV_DEF = value[2];
|
|
|
|
EV_SPE = value[3];
|
|
|
|
EV_SPA = value[4];
|
|
|
|
EV_SPD = value[5];
|
|
|
|
}
|
2022-03-14 05:33:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int[] Stats
|
|
|
|
{
|
2023-12-04 04:13:20 +00:00
|
|
|
get => [Stat_HPCurrent, Stat_ATK, Stat_DEF, Stat_SPE, Stat_SPA, Stat_SPD];
|
2022-06-18 18:04:24 +00:00
|
|
|
set
|
2022-05-06 22:47:54 +00:00
|
|
|
{
|
|
|
|
if (value.Length != 6)
|
|
|
|
return;
|
2022-06-18 18:04:24 +00:00
|
|
|
Stat_HPCurrent = value[0]; Stat_ATK = value[1]; Stat_DEF = value[2];
|
|
|
|
Stat_SPE = value[3]; Stat_SPA = value[4]; Stat_SPD = value[5];
|
2022-05-06 22:47:54 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2022-05-06 22:47:54 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public ushort[] Moves
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-12-04 04:13:20 +00:00
|
|
|
get => [Move1, Move2, Move3, Move4];
|
2022-08-05 18:23:28 +00:00
|
|
|
set => SetMoves(value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-12-04 04:53:37 +00:00
|
|
|
|
2023-10-29 05:01:26 +00:00
|
|
|
public bool AddMove(ushort move, bool pushOut = true)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
if (move == 0 || move >= MaxMoveID || HasMove(move))
|
2023-10-29 05:01:26 +00:00
|
|
|
return false;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
var ct = MoveCount;
|
|
|
|
if (ct == 4)
|
2023-10-29 05:01:26 +00:00
|
|
|
{
|
|
|
|
if (!pushOut)
|
|
|
|
return false;
|
2022-06-18 18:04:24 +00:00
|
|
|
ct = 0;
|
2023-10-29 05:01:26 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
SetMove(ct, move);
|
|
|
|
HealPPIndex(ct);
|
2023-10-29 05:01:26 +00:00
|
|
|
return true;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int MoveCount => Convert.ToInt32(Move1 != 0) + Convert.ToInt32(Move2 != 0) + Convert.ToInt32(Move3 != 0) + Convert.ToInt32(Move4 != 0);
|
2022-02-10 03:21:45 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public void GetMoves(Span<ushort> value)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
value[3] = Move4;
|
|
|
|
value[2] = Move3;
|
|
|
|
value[1] = Move2;
|
|
|
|
value[0] = Move1;
|
|
|
|
}
|
2022-02-10 03:21:45 +00:00
|
|
|
|
2022-08-22 00:34:32 +00:00
|
|
|
public void SetMoves(Moveset value)
|
|
|
|
{
|
|
|
|
Move1 = value.Move1;
|
|
|
|
Move2 = value.Move2;
|
|
|
|
Move3 = value.Move3;
|
|
|
|
Move4 = value.Move4;
|
2023-09-11 04:17:47 +00:00
|
|
|
this.SetMaximumPPCurrent(value);
|
2022-08-22 00:34:32 +00:00
|
|
|
}
|
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public void SetMoves(ReadOnlySpan<ushort> value)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
Move1 = value.Length > 0 ? value[0] : default;
|
|
|
|
Move2 = value.Length > 1 ? value[1] : default;
|
|
|
|
Move3 = value.Length > 2 ? value[2] : default;
|
|
|
|
Move4 = value.Length > 3 ? value[3] : default;
|
2023-09-11 04:17:47 +00:00
|
|
|
this.SetMaximumPPCurrent(value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2022-02-10 03:21:45 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public ushort[] RelearnMoves
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-12-04 04:13:20 +00:00
|
|
|
get => [RelearnMove1, RelearnMove2, RelearnMove3, RelearnMove4];
|
2022-06-18 18:04:24 +00:00
|
|
|
set => SetRelearnMoves(value);
|
|
|
|
}
|
2022-03-13 01:06:03 +00:00
|
|
|
|
2022-08-22 00:34:32 +00:00
|
|
|
public void SetRelearnMoves(Moveset value)
|
|
|
|
{
|
|
|
|
RelearnMove1 = value.Move1;
|
|
|
|
RelearnMove2 = value.Move2;
|
|
|
|
RelearnMove3 = value.Move3;
|
|
|
|
RelearnMove4 = value.Move4;
|
|
|
|
}
|
|
|
|
|
2023-03-22 01:19:55 +00:00
|
|
|
public void SetRelearnMoves(ReadOnlySpan<ushort> value)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-03-22 01:19:55 +00:00
|
|
|
RelearnMove1 = value.Length > 0 ? value[0] : default;
|
|
|
|
RelearnMove2 = value.Length > 1 ? value[1] : default;
|
|
|
|
RelearnMove3 = value.Length > 2 ? value[2] : default;
|
|
|
|
RelearnMove4 = value.Length > 3 ? value[3] : default;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2020-01-19 00:46:38 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int PIDAbility
|
|
|
|
{
|
|
|
|
get
|
2016-08-27 15:43:36 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Generation > 5 || Format > 5)
|
|
|
|
return -1;
|
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
if (Version == CXD)
|
2022-09-02 17:20:19 +00:00
|
|
|
return PersonalInfo.GetIndexOfAbility(Ability); // Can mismatch; not tied to PID
|
2022-06-18 18:04:24 +00:00
|
|
|
return (int)((Gen5 ? PID >> 16 : PID) & 1);
|
2019-09-10 07:21:51 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +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;
|
2019-09-10 07:21:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +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);
|
|
|
|
|
|
|
|
public virtual int HPType
|
|
|
|
{
|
|
|
|
get => 15 * HPBitValType / 63;
|
|
|
|
set
|
2019-09-10 07:21:51 +00:00
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
var bits = HiddenPower.GetLowBits(value);
|
2022-06-18 18:04:24 +00:00
|
|
|
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-08-27 15:43:36 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Misc Egg Facts
|
2024-02-23 03:20:54 +00:00
|
|
|
public virtual bool WasEgg => IsEgg || EggDay != 0;
|
|
|
|
public bool WasTradedEgg => EggLocation == GetTradedEggLocation();
|
|
|
|
public bool IsTradedEgg => MetLocation == GetTradedEggLocation();
|
|
|
|
private int GetTradedEggLocation() => Locations.TradedEggLocation(Generation, Version);
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public virtual bool IsUntraded => false;
|
|
|
|
public virtual bool IsNative => Generation == Format;
|
|
|
|
public bool IsOriginValid => Species <= MaxSpeciesID;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks if the PKM has its original met location.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Returns false if the Met Location has been overwritten via generational transfer.</returns>
|
|
|
|
public virtual bool HasOriginalMetLocation => !(Format < 3 || VC || (Generation <= 4 && 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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks if the current <see cref="Gender"/> is valid.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>True if valid, False if invalid.</returns>
|
|
|
|
public virtual bool IsGenderValid()
|
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
byte gender = Gender;
|
2023-01-22 04:02:33 +00:00
|
|
|
var gv = PersonalInfo.Gender;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (gv == PersonalInfo.RatioMagicGenderless)
|
|
|
|
return gender == 2;
|
|
|
|
if (gv == PersonalInfo.RatioMagicFemale)
|
|
|
|
return gender == 1;
|
|
|
|
if (gv == PersonalInfo.RatioMagicMale)
|
|
|
|
return gender == 0;
|
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
var gen = Generation;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (gen is not (3 or 4 or 5))
|
|
|
|
return gender == (gender & 1);
|
|
|
|
|
|
|
|
return gender == EntityGender.GetFromPIDAndRatio(PID, gv);
|
|
|
|
}
|
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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Updates the checksum of the <see cref="PKM"/>.
|
|
|
|
/// </summary>
|
|
|
|
public abstract void RefreshChecksum();
|
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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <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; }
|
2016-10-24 05:01:39 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Reorders moves and fixes PP if necessary.
|
|
|
|
/// </summary>
|
|
|
|
public void FixMoves()
|
|
|
|
{
|
|
|
|
ReorderMoves();
|
2017-02-05 02:27:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Reorders moves to put Empty entries last.
|
|
|
|
/// </summary>
|
|
|
|
private void ReorderMoves()
|
|
|
|
{
|
2023-05-18 00:20:39 +00:00
|
|
|
// Loop to catch multiple empty slots. X2X4 needs 3 shifts, XX34 needs 4.
|
|
|
|
while (true)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-05-18 00:20:39 +00:00
|
|
|
if (Move1 == 0 && Move2 != 0)
|
|
|
|
{
|
|
|
|
// This branch can only be true once, as Move1 is the top move.
|
|
|
|
Move1 = Move2;
|
|
|
|
Move1_PP = Move2_PP;
|
|
|
|
Move1_PPUps = Move2_PPUps;
|
|
|
|
Move2 = 0;
|
|
|
|
}
|
|
|
|
else if (Move2 == 0 && Move3 != 0)
|
|
|
|
{
|
|
|
|
// This branch can be true more than once, if shifting 3 & 4 down into 1 & 2.
|
|
|
|
Move2 = Move3;
|
|
|
|
Move2_PP = Move3_PP;
|
|
|
|
Move2_PPUps = Move3_PPUps;
|
|
|
|
Move3 = 0;
|
|
|
|
}
|
|
|
|
else if (Move3 == 0 && Move4 != 0)
|
|
|
|
{
|
|
|
|
// This branch can be true only once, as Move4 is the lowest move and nothing can refill it.
|
|
|
|
Move3 = Move4;
|
|
|
|
Move3_PP = Move4_PP;
|
|
|
|
Move3_PPUps = Move4_PPUps;
|
|
|
|
Move4 = 0;
|
|
|
|
// Still need to loop as Move 3 may still have empty slots before it.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No more reordering, current moveset has no empty slots exist before nonzero slots.
|
|
|
|
return;
|
|
|
|
}
|
2017-01-26 06:51:52 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-01-26 06:51:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Applies the desired Ability option.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="n">Ability Number (0/1/2)</param>
|
|
|
|
public virtual void RefreshAbility(int n)
|
|
|
|
{
|
|
|
|
AbilityNumber = 1 << n;
|
2023-12-04 04:13:20 +00:00
|
|
|
var pi = PersonalInfo;
|
2022-09-02 17:20:19 +00:00
|
|
|
if ((uint)n < pi.AbilityCount)
|
|
|
|
Ability = pi.GetAbilityAtIndex(n);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-07-21 03:40:03 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the IV Judge Rating value.
|
|
|
|
/// </summary>
|
2023-04-23 00:51:32 +00:00
|
|
|
/// <remarks>
|
|
|
|
/// IV Judge scales his response 0 (worst) to 3 (best).<br/>
|
|
|
|
/// Assumes IVs are in the 0-31 range, so this isn't really useful for Gen1/2 formats that are 0-15 per IV.
|
|
|
|
/// </remarks>
|
2023-10-29 05:01:26 +00:00
|
|
|
public int PotentialRating => PowerPotential.GetPotential(IVTotal);
|
2022-04-09 04:08:06 +00:00
|
|
|
|
2022-06-18 18:04:24 +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>
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
public ushort[] GetStats(IBaseStat p)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
ushort[] stats = new ushort[6];
|
|
|
|
LoadStats(p, stats);
|
|
|
|
return stats;
|
|
|
|
}
|
2016-07-21 03:40:03 +00:00
|
|
|
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
public virtual void LoadStats(IBaseStat p, Span<ushort> stats)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
int level = CurrentLevel; // recalculate instead of checking Stat_Level
|
|
|
|
if (this is IHyperTrain t)
|
|
|
|
LoadStats(stats, p, t, level);
|
|
|
|
else
|
|
|
|
LoadStats(stats, p, level);
|
|
|
|
|
2023-04-23 00:51:32 +00:00
|
|
|
// Amplify stats based on the stat nature.
|
2022-06-18 18:04:24 +00:00
|
|
|
NatureAmp.ModifyStatsForNature(stats, StatNature);
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
private void LoadStats(Span<ushort> stats, IBaseStat p, IHyperTrain t, int level)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
private void LoadStats(Span<ushort> stats, IBaseStat p, int level)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2018-06-06 04:31:42 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Applies the specified stats to the <see cref="PKM"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="stats">Battle Stats (H/A/B/S/C/D)</param>
|
|
|
|
public void SetStats(ReadOnlySpan<ushort> stats)
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
2017-02-05 02:27:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Indicates if Party Stats are present. False if not initialized (from stored format).
|
|
|
|
/// </summary>
|
|
|
|
public bool PartyStatsPresent => Stat_HPMax != 0;
|
2019-01-12 18:54:38 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Clears any status condition and refreshes the stats.
|
|
|
|
/// </summary>
|
|
|
|
public void ResetPartyStats()
|
|
|
|
{
|
|
|
|
Span<ushort> stats = stackalloc ushort[6];
|
|
|
|
LoadStats(PersonalInfo, stats);
|
|
|
|
SetStats(stats);
|
|
|
|
Stat_Level = CurrentLevel;
|
|
|
|
Status_Condition = 0;
|
|
|
|
}
|
2019-07-12 23:41:13 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void Heal()
|
|
|
|
{
|
|
|
|
ResetPartyStats();
|
|
|
|
HealPP();
|
|
|
|
}
|
2019-02-21 06:08:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <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-06-18 18:04:24 +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),
|
2022-11-25 01:42:17 +00:00
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index), index, "Index must be between 0 and 3."),
|
2022-06-18 18:04:24 +00:00
|
|
|
};
|
2022-02-10 03:21:45 +00:00
|
|
|
|
2022-06-18 18:04:24 +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;
|
|
|
|
ResetPartyStats();
|
|
|
|
return true;
|
|
|
|
}
|
2019-01-12 18:54:38 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks if the <see cref="PKM"/> can hold its <see cref="HeldItem"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="valid">Items that the <see cref="PKM"/> can hold.</param>
|
|
|
|
/// <returns>True/False if the <see cref="PKM"/> can hold its <see cref="HeldItem"/>.</returns>
|
2023-03-26 00:55:55 +00:00
|
|
|
public virtual bool CanHoldItem(ReadOnlySpan<ushort> valid) => valid.Contains((ushort)HeldItem);
|
2018-03-22 04:10:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +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>
|
|
|
|
public abstract PKM Clone();
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +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>
|
2024-02-23 23:01:36 +00:00
|
|
|
/// <param name="year">Day the <see cref="PKM"/> was traded.</param>
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <param name="location">Link Trade location value.</param>
|
2024-02-23 23:01:36 +00:00
|
|
|
protected void SetLinkTradeEgg(int day, int month, int year, ushort location)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
MetDay = (byte)day;
|
|
|
|
MetMonth = (byte)month;
|
2024-02-23 23:01:36 +00:00
|
|
|
MetYear = (byte)(year - 2000);
|
2024-02-23 03:20:54 +00:00
|
|
|
MetLocation = location;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2020-10-25 17:42:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +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>
|
|
|
|
/// <param name="ppUpCount">PP Ups count</param>
|
|
|
|
/// <returns>Current PP for the move.</returns>
|
2022-09-19 06:06:02 +00:00
|
|
|
public virtual int GetMovePP(ushort move, int ppUpCount) => GetBasePP(move) * (5 + ppUpCount) / 5;
|
2020-10-25 17:42:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +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>
|
2022-09-19 06:06:02 +00:00
|
|
|
private int GetBasePP(ushort move) => MoveInfo.GetPP(Context, move);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Applies a shiny <see cref="PID"/> to the <see cref="PKM"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// If a <see cref="PKM"/> originated in a generation prior to Generation 6, the <see cref="EncryptionConstant"/> is updated.
|
|
|
|
/// If a <see cref="PKM"/> is in the <see cref="GBPKM"/> format, it will update the <see cref="IVs"/> instead.
|
|
|
|
/// </remarks>
|
|
|
|
public virtual void SetShiny()
|
|
|
|
{
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
do { PID = EntityPID.GetRandomPID(rnd, Species, Gender, Version, Nature, Form, PID); }
|
|
|
|
while (!IsShiny);
|
|
|
|
if (Format >= 6 && (Gen3 || Gen4 || Gen5))
|
|
|
|
EncryptionConstant = PID;
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
2023-01-22 04:02:33 +00:00
|
|
|
/// Applies a shiny <see cref="ITrainerID32.SID16"/> to the <see cref="PKM"/>.
|
2022-06-18 18:04:24 +00:00
|
|
|
/// </summary>
|
|
|
|
public void SetShinySID(Shiny shiny = Shiny.Random)
|
|
|
|
{
|
|
|
|
if (IsShiny && shiny.IsValid(this))
|
|
|
|
return;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
ushort bits = shiny switch
|
2016-08-28 01:42:07 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Shiny.AlwaysSquare => 0,
|
|
|
|
Shiny.AlwaysStar => 1,
|
2023-01-22 04:02:33 +00:00
|
|
|
_ => (ushort)Util.Rand.Next(8),
|
2022-06-18 18:04:24 +00:00
|
|
|
};
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
var current = ShinyXor;
|
|
|
|
current ^= bits;
|
|
|
|
SID16 ^= current;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-12-13 02:06:39 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Applies a <see cref="PID"/> to the <see cref="PKM"/> according to the specified <see cref="Gender"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="gender"><see cref="Gender"/> to apply</param>
|
|
|
|
/// <remarks>
|
|
|
|
/// If a <see cref="PKM"/> originated in a generation prior to Generation 6, the <see cref="EncryptionConstant"/> is updated.
|
|
|
|
/// </remarks>
|
2024-02-23 03:20:54 +00:00
|
|
|
public void SetPIDGender(byte gender)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
do PID = EntityPID.GetRandomPID(rnd, Species, gender, Version, Nature, Form, PID);
|
|
|
|
while (IsShiny);
|
|
|
|
if (Format >= 6 && (Gen3 || Gen4 || Gen5))
|
|
|
|
EncryptionConstant = PID;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Applies a <see cref="PID"/> to the <see cref="PKM"/> according to the specified <see cref="Gender"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nature"><see cref="Nature"/> to apply</param>
|
|
|
|
/// <remarks>
|
|
|
|
/// If a <see cref="PKM"/> originated in a generation prior to Generation 6, the <see cref="EncryptionConstant"/> is updated.
|
|
|
|
/// </remarks>
|
2024-02-23 03:20:54 +00:00
|
|
|
public void SetPIDNature(Nature nature)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
do PID = EntityPID.GetRandomPID(rnd, Species, Gender, Version, nature, Form, PID);
|
|
|
|
while (IsShiny);
|
|
|
|
if (Format >= 6 && (Gen3 || Gen4 || Gen5))
|
|
|
|
EncryptionConstant = PID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Applies a <see cref="PID"/> to the <see cref="PKM"/> according to the specified <see cref="Form"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="form"><see cref="Form"/> to apply</param>
|
|
|
|
/// <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>
|
2022-08-27 19:53:30 +00:00
|
|
|
public void SetPIDUnown3(byte form)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
do PID = rnd.Rand32(); while (EntityPID.GetUnownForm3(PID) != form);
|
|
|
|
if (Format >= 6 && (Gen3 || Gen4 || Gen5))
|
|
|
|
EncryptionConstant = PID;
|
|
|
|
}
|
|
|
|
|
2022-06-26 06:08:28 +00:00
|
|
|
/// <inheritdoc cref="SetRandomIVs(Span{int},int)"/>
|
2023-08-12 23:01:16 +00:00
|
|
|
public void SetRandomIVs(int minFlawless = 0) => SetRandomIVs(stackalloc int[6], minFlawless);
|
2022-06-26 06:08:28 +00:00
|
|
|
|
2023-10-29 05:01:26 +00:00
|
|
|
/// <inheritdoc cref="SetRandomIVs(Span{int},int)"/>
|
2023-12-30 19:40:10 +00:00
|
|
|
public void SetRandomIVs(in IndividualValueSet template) => SetRandomIVs(stackalloc int[6], template);
|
2023-10-29 05:01:26 +00:00
|
|
|
|
|
|
|
/// <inheritdoc cref="SetRandomIVs(Span{int},int)"/>
|
2023-12-30 19:40:10 +00:00
|
|
|
public void SetRandomIVs(Span<int> ivs, in IndividualValueSet template)
|
2023-10-29 05:01:26 +00:00
|
|
|
{
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
for (int i = 0; i < ivs.Length; i++)
|
|
|
|
{
|
|
|
|
if (template[i] == -1)
|
|
|
|
ivs[i] = rnd.Next(MaxIV + 1);
|
|
|
|
else
|
|
|
|
ivs[i] = template[i];
|
|
|
|
}
|
|
|
|
SetIVs(ivs);
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Randomizes the IVs within game constraints.
|
|
|
|
/// </summary>
|
2022-06-26 06:08:28 +00:00
|
|
|
/// <param name="ivs">Temporary variable storage</param>
|
|
|
|
/// <param name="minFlawless">Count of flawless IVs to set. If none provided, a count will be detected.</param>
|
2023-08-12 23:01:16 +00:00
|
|
|
public void SetRandomIVs(Span<int> ivs, int minFlawless = 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
if (Version == GameVersion.GO)
|
2022-08-03 23:41:10 +00:00
|
|
|
{
|
2022-06-26 06:08:28 +00:00
|
|
|
SetRandomIVsGO(ivs);
|
2022-08-03 23:41:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
ivs[i] = rnd.Next(MaxIV + 1);
|
2017-11-02 16:05:44 +00:00
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
if (minFlawless != 0)
|
2018-12-13 02:06:39 +00:00
|
|
|
{
|
2023-08-12 23:01:16 +00:00
|
|
|
for (int i = 0; i < minFlawless; i++)
|
2022-06-18 18:04:24 +00:00
|
|
|
ivs[i] = MaxIV;
|
2023-03-27 07:11:42 +00:00
|
|
|
rnd.Shuffle(ivs); // Randomize IV order
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-26 06:08:28 +00:00
|
|
|
SetIVs(ivs);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
2022-06-26 06:08:28 +00:00
|
|
|
/// <inheritdoc cref="SetRandomIVsGO(Span{int},int,int)"/>
|
|
|
|
public void SetRandomIVsGO(int minIV = 0, int maxIV = 15) => SetRandomIVsGO(stackalloc int[6], minIV, maxIV);
|
|
|
|
|
|
|
|
public void SetRandomIVsGO(Span<int> ivs, int minIV = 0, int maxIV = 15)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
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
|
|
|
|
ivs[3] = rnd.Next(MaxIV + 1); // speed
|
2022-06-26 06:08:28 +00:00
|
|
|
SetIVs(ivs);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-11-02 16:05:44 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
2022-06-26 23:05:16 +00:00
|
|
|
/// Applies all shared properties from the current <see cref="PKM"/> to the <see cref="result"/> <see cref="PKM"/>.
|
2022-06-18 18:04:24 +00:00
|
|
|
/// </summary>
|
2022-06-26 23:05:16 +00:00
|
|
|
/// <param name="result"><see cref="PKM"/> that receives property values.</param>
|
|
|
|
public void TransferPropertiesWithReflection(PKM result)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
// Only transfer declared properties not defined in PKM.cs but in the actual type
|
|
|
|
var srcType = GetType();
|
2022-06-26 23:05:16 +00:00
|
|
|
var destType = result.GetType();
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2022-06-26 23:05:16 +00:00
|
|
|
static IEnumerable<Type> GetImplementingTypes(Type t)
|
|
|
|
{
|
|
|
|
yield return t;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
var baseType = t.BaseType;
|
|
|
|
if (baseType is null || baseType == typeof(PKM))
|
|
|
|
yield break;
|
|
|
|
yield return t = baseType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var srcTypes = GetImplementingTypes(srcType);
|
|
|
|
var srcProperties = srcTypes.SelectMany(ReflectUtil.GetPropertiesCanWritePublicDeclared);
|
|
|
|
var destTypes = GetImplementingTypes(destType);
|
|
|
|
var destProperties = destTypes.SelectMany(ReflectUtil.GetPropertiesCanWritePublicDeclared);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Transfer properties in the order they are defined in the destination PKM format for best conversion
|
|
|
|
var shared = destProperties.Intersect(srcProperties);
|
|
|
|
foreach (string property in shared)
|
2016-10-02 17:18:31 +00:00
|
|
|
{
|
2022-10-27 19:07:52 +00:00
|
|
|
// Setter sanity check: a derived type may not implement a setter if its parent type has one.
|
|
|
|
if (!BatchEditing.TryGetHasProperty(result, property, out var pi))
|
|
|
|
continue;
|
|
|
|
if (!pi.CanWrite)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Fetch the current value.
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!BatchEditing.TryGetHasProperty(this, property, out var src))
|
|
|
|
continue;
|
|
|
|
var prop = src.GetValue(this);
|
2022-10-27 19:07:52 +00:00
|
|
|
if (prop is byte[] or null)
|
|
|
|
continue; // not a valid property transfer
|
|
|
|
|
|
|
|
// Write it to the destination.
|
|
|
|
ReflectUtil.SetValue(pi, result, prop);
|
2016-10-02 17:18:31 +00:00
|
|
|
}
|
2017-06-10 15:31:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// set shared properties for the Gen1/2 base class
|
2022-06-26 23:05:16 +00:00
|
|
|
if (result is GBPKM l)
|
2022-06-18 18:04:24 +00:00
|
|
|
l.ImportFromFuture(this);
|
|
|
|
}
|
2021-01-02 01:08:49 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks if the <see cref="PKM"/> has the <see cref="move"/> in its current move list.
|
|
|
|
/// </summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
public bool HasMove(ushort move) => Move1 == move || Move2 == move || Move3 == move || Move4 == move;
|
2020-09-05 19:11:43 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public int GetMoveIndex(ushort move) => Move1 == move ? 0 : Move2 == move ? 1 : Move3 == move ? 2 : Move4 == move ? 3 : -1;
|
2022-05-03 01:11:31 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public ushort GetMove(int index) => index switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
0 => Move1,
|
|
|
|
1 => Move2,
|
|
|
|
2 => Move3,
|
|
|
|
3 => Move4,
|
2022-11-25 01:42:17 +00:00
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index), index, "Move index must be between 0 and 3."),
|
2022-06-18 18:04:24 +00:00
|
|
|
};
|
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public ushort SetMove(int index, ushort value) => index switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
0 => Move1 = value,
|
|
|
|
1 => Move2 = value,
|
|
|
|
2 => Move3 = value,
|
|
|
|
3 => Move4 = value,
|
2022-11-25 01:42:17 +00:00
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index), index, "Move index must be between 0 and 3."),
|
2022-06-18 18:04:24 +00:00
|
|
|
};
|
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public ushort GetRelearnMove(int index) => index switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
0 => RelearnMove1,
|
|
|
|
1 => RelearnMove2,
|
|
|
|
2 => RelearnMove3,
|
|
|
|
3 => RelearnMove4,
|
2022-11-25 01:42:17 +00:00
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index), index, "Move index must be between 0 and 3."),
|
2022-06-18 18:04:24 +00:00
|
|
|
};
|
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public ushort SetRelearnMove(int index, ushort value) => index switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
0 => RelearnMove1 = value,
|
|
|
|
1 => RelearnMove2 = value,
|
|
|
|
2 => RelearnMove3 = value,
|
|
|
|
3 => RelearnMove4 = value,
|
2022-11-25 01:42:17 +00:00
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index), index, "Move index must be between 0 and 3."),
|
2022-06-18 18:04:24 +00:00
|
|
|
};
|
2022-05-03 01:11:31 +00:00
|
|
|
|
2022-06-26 06:08:28 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks if the <see cref="PKM"/> has the <see cref="move"/> in its relearn move list.
|
|
|
|
/// </summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
public bool HasRelearnMove(ushort move) => RelearnMove1 == move || RelearnMove2 == move || RelearnMove3 == move || RelearnMove4 == move;
|
2022-06-26 06:08:28 +00:00
|
|
|
|
2023-10-30 03:27:42 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Loads the Relearn moves into the <see cref="value"/> array.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">Span to load the relearn moves into.</param>
|
2022-08-27 06:43:36 +00:00
|
|
|
public void GetRelearnMoves(Span<ushort> value)
|
2022-06-26 06:08:28 +00:00
|
|
|
{
|
|
|
|
value[3] = RelearnMove4;
|
|
|
|
value[2] = RelearnMove3;
|
|
|
|
value[1] = RelearnMove2;
|
|
|
|
value[0] = RelearnMove1;
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Clears moves that a <see cref="PKM"/> may have, possibly from a future generation.
|
|
|
|
/// </summary>
|
|
|
|
public void ClearInvalidMoves()
|
|
|
|
{
|
|
|
|
uint invalid = 0;
|
2022-08-27 06:43:36 +00:00
|
|
|
Span<ushort> moves = stackalloc ushort[4];
|
2022-06-26 06:08:28 +00:00
|
|
|
GetMoves(moves);
|
2022-06-18 18:04:24 +00:00
|
|
|
for (var i = 0; i < moves.Length; i++)
|
2017-06-10 15:31:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (moves[i] <= MaxMoveID)
|
|
|
|
continue;
|
2017-06-10 15:31:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
invalid++;
|
|
|
|
moves[i] = 0;
|
2017-06-10 15:31:31 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (invalid == 0)
|
|
|
|
return;
|
|
|
|
if (invalid == 4) // no moves remain
|
2019-01-05 18:51:41 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
moves[0] = 1; // Pound
|
|
|
|
Move1_PP = GetMovePP(1, Move1_PPUps);
|
|
|
|
}
|
2019-01-05 18:51:41 +00:00
|
|
|
|
2022-06-26 06:08:28 +00:00
|
|
|
SetMoves(moves);
|
2022-06-18 18:04:24 +00:00
|
|
|
FixMoves();
|
2016-06-20 04:22:43 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2022-06-26 06:08:28 +00:00
|
|
|
/// Gets one of the <see cref="EffortValues"/> based on its index within the array.
|
2022-06-18 18:04:24 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="index">Index to get</param>
|
|
|
|
public int GetEV(int index) => index switch
|
|
|
|
{
|
|
|
|
0 => EV_HP,
|
|
|
|
1 => EV_ATK,
|
|
|
|
2 => EV_DEF,
|
|
|
|
3 => EV_SPE,
|
|
|
|
4 => EV_SPA,
|
|
|
|
5 => EV_SPD,
|
2022-11-25 01:42:17 +00:00
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index), index, "EV index must be between 0 and 5."),
|
2022-06-18 18:04:24 +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>
|
|
|
|
public int GetIV(int index) => index switch
|
|
|
|
{
|
|
|
|
0 => IV_HP,
|
|
|
|
1 => IV_ATK,
|
|
|
|
2 => IV_DEF,
|
|
|
|
3 => IV_SPE,
|
|
|
|
4 => IV_SPA,
|
|
|
|
5 => IV_SPD,
|
2022-11-25 01:42:17 +00:00
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index), index, "IV index must be between 0 and 5."),
|
2022-06-18 18:04:24 +00:00
|
|
|
};
|
2016-06-20 04:22:43 +00:00
|
|
|
}
|