2018-08-19 22:50:15 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2020-10-18 16:43:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Base format for Generation 1 & 2 <see cref="PKM"/> objects.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// <see cref="SK2"/> store text buffers with the rest of the data.
|
|
|
|
|
/// <see cref="PK1"/> and <see cref="PK2"/> store them separately; see <see cref="GBPKML"/>.
|
|
|
|
|
/// </remarks>
|
2019-10-26 19:42:33 +00:00
|
|
|
|
public abstract class GBPKM : PKM
|
2018-08-19 22:50:15 +00:00
|
|
|
|
{
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override int MaxBallID => -1;
|
2020-09-26 00:15:02 +00:00
|
|
|
|
public sealed override int MinGameID => (int)GameVersion.RD;
|
|
|
|
|
public sealed override int MaxGameID => (int)GameVersion.C;
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override int MaxIV => 15;
|
|
|
|
|
public sealed override int MaxEV => ushort.MaxValue;
|
2018-08-19 22:50:15 +00:00
|
|
|
|
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override IReadOnlyList<ushort> ExtraBytes => Array.Empty<ushort>();
|
2018-12-20 06:10:32 +00:00
|
|
|
|
|
2020-10-03 01:08:40 +00:00
|
|
|
|
protected GBPKM(int size) : base(size) { }
|
|
|
|
|
protected GBPKM(byte[] data) : base(data) { }
|
2018-08-19 22:50:15 +00:00
|
|
|
|
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override byte[] EncryptedPartyData => Encrypt();
|
|
|
|
|
public sealed override byte[] EncryptedBoxData => Encrypt();
|
|
|
|
|
public sealed override byte[] DecryptedBoxData => Encrypt();
|
|
|
|
|
public sealed override byte[] DecryptedPartyData => Encrypt();
|
2018-08-19 22:50:15 +00:00
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override bool Valid { get => true; set { } }
|
|
|
|
|
public sealed override void RefreshChecksum() { }
|
|
|
|
|
|
2021-05-29 22:31:47 +00:00
|
|
|
|
protected abstract byte[] GetNonNickname(int language);
|
2020-10-03 01:08:40 +00:00
|
|
|
|
|
2018-08-19 22:50:15 +00:00
|
|
|
|
private bool? _isnicknamed;
|
|
|
|
|
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override bool IsNicknamed
|
2018-08-19 22:50:15 +00:00
|
|
|
|
{
|
2020-10-03 01:08:40 +00:00
|
|
|
|
get => _isnicknamed ??= !Nickname_Trash.SequenceEqual(GetNonNickname(GuessedLanguage()));
|
2018-08-19 22:50:15 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_isnicknamed = value;
|
|
|
|
|
if (_isnicknamed == false)
|
2018-12-22 22:47:31 +00:00
|
|
|
|
SetNotNicknamed(GuessedLanguage());
|
2018-08-19 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected bool IsNicknamedBank
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-09-19 02:58:23 +00:00
|
|
|
|
var spName = SpeciesName.GetSpeciesNameGeneration(Species, GuessedLanguage(), Format);
|
2018-08-19 22:50:15 +00:00
|
|
|
|
return Nickname != spName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override int Language
|
2018-08-19 22:50:15 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Japanese)
|
|
|
|
|
return (int)LanguageID.Japanese;
|
|
|
|
|
if (Korean)
|
|
|
|
|
return (int)LanguageID.Korean;
|
2020-10-03 01:08:40 +00:00
|
|
|
|
if (StringConverter12.IsG12German(OT_Trash))
|
2018-08-19 22:50:15 +00:00
|
|
|
|
return (int)LanguageID.German; // german
|
2019-09-19 02:58:23 +00:00
|
|
|
|
int lang = SpeciesName.GetSpeciesNameLanguage(Species, Nickname, Format);
|
2018-08-19 22:50:15 +00:00
|
|
|
|
if (lang > 0)
|
|
|
|
|
return lang;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2018-12-22 22:47:31 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (Japanese)
|
|
|
|
|
return;
|
|
|
|
|
if (Korean)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (IsNicknamed)
|
|
|
|
|
return;
|
|
|
|
|
SetNotNicknamed(value);
|
|
|
|
|
}
|
2018-08-19 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override int Gender
|
2018-08-19 22:50:15 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int gv = PersonalInfo.Gender;
|
2021-03-14 23:16:55 +00:00
|
|
|
|
return gv switch
|
|
|
|
|
{
|
2021-07-13 07:25:51 +00:00
|
|
|
|
PersonalInfo.RatioMagicGenderless => 2,
|
|
|
|
|
PersonalInfo.RatioMagicFemale => 1,
|
|
|
|
|
PersonalInfo.RatioMagicMale => 0,
|
2021-08-20 20:49:20 +00:00
|
|
|
|
_ => IV_ATK > gv >> 4 ? 0 : 1,
|
2021-03-14 23:16:55 +00:00
|
|
|
|
};
|
2018-08-19 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
set { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Future, Unused Attributes
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override bool IsGenderValid() => true; // not a separate property, derived via IVs
|
|
|
|
|
public sealed override uint EncryptionConstant { get => 0; set { } }
|
|
|
|
|
public sealed override uint PID { get => 0; set { } }
|
|
|
|
|
public sealed override int Nature { get => 0; set { } }
|
|
|
|
|
public sealed override bool ChecksumValid => true;
|
|
|
|
|
public sealed override bool FatefulEncounter { get => false; set { } }
|
|
|
|
|
public sealed override int TSV => 0x0000;
|
|
|
|
|
public sealed override int PSV => 0xFFFF;
|
|
|
|
|
public sealed override int Characteristic => -1;
|
|
|
|
|
public sealed override int MarkValue { get => 0; protected set { } }
|
|
|
|
|
public sealed override int Ability { get => -1; set { } }
|
|
|
|
|
public sealed override int CurrentHandler { get => 0; set { } }
|
|
|
|
|
public sealed override int Egg_Location { get => 0; set { } }
|
|
|
|
|
public sealed override int Ball { get => 0; set { } }
|
|
|
|
|
public sealed override int SID { get => 0; set { } }
|
2018-08-19 22:50:15 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override bool IsShiny => IV_DEF == 10 && IV_SPE == 10 && IV_SPC == 10 && (IV_ATK & 2) == 2;
|
2020-09-15 03:06:11 +00:00
|
|
|
|
private int HPBitValPower => ((IV_ATK & 8) >> 0) | ((IV_DEF & 8) >> 1) | ((IV_SPE & 8) >> 2) | ((IV_SPC & 8) >> 3);
|
|
|
|
|
public sealed override int HPPower => (((5 * HPBitValPower) + (IV_SPC & 3)) >> 1) + 31;
|
2018-08-19 22:50:15 +00:00
|
|
|
|
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override int HPType
|
2018-08-19 22:50:15 +00:00
|
|
|
|
{
|
2020-09-15 03:06:11 +00:00
|
|
|
|
get => ((IV_ATK & 3) << 2) | (IV_DEF & 3);
|
|
|
|
|
set
|
2018-08-19 22:50:15 +00:00
|
|
|
|
{
|
|
|
|
|
IV_DEF = ((IV_DEF >> 2) << 2) | (value & 3);
|
|
|
|
|
IV_DEF = ((IV_ATK >> 2) << 2) | ((value >> 2) & 3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 04:42:30 +00:00
|
|
|
|
public sealed override int Form
|
2018-08-19 22:50:15 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Species != 201) // Unown
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
uint formeVal = 0;
|
|
|
|
|
formeVal |= (uint)((IV_ATK & 0x6) << 5);
|
|
|
|
|
formeVal |= (uint)((IV_DEF & 0x6) << 3);
|
|
|
|
|
formeVal |= (uint)((IV_SPE & 0x6) << 1);
|
|
|
|
|
formeVal |= (uint)((IV_SPC & 0x6) >> 1);
|
|
|
|
|
return (int)(formeVal / 10);
|
|
|
|
|
}
|
|
|
|
|
set { }
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 17:55:15 +00:00
|
|
|
|
public abstract int EV_SPC { get; set; }
|
|
|
|
|
public sealed override int EV_SPA { get => EV_SPC; set => EV_SPC = value; }
|
|
|
|
|
public sealed override int EV_SPD { get => EV_SPC; set { } }
|
2018-08-19 22:50:15 +00:00
|
|
|
|
public abstract ushort DV16 { get; set; }
|
2020-09-07 17:55:15 +00:00
|
|
|
|
public sealed override int IV_HP { get => ((IV_ATK & 1) << 3) | ((IV_DEF & 1) << 2) | ((IV_SPE & 1) << 1) | ((IV_SPC & 1) << 0); set { } }
|
|
|
|
|
public sealed override int IV_ATK { get => (DV16 >> 12) & 0xF; set => DV16 = (ushort)((DV16 & ~(0xF << 12)) | (ushort)((value > 0xF ? 0xF : value) << 12)); }
|
|
|
|
|
public sealed override int IV_DEF { get => (DV16 >> 8) & 0xF; set => DV16 = (ushort)((DV16 & ~(0xF << 8)) | (ushort)((value > 0xF ? 0xF : value) << 8)); }
|
|
|
|
|
public sealed override int IV_SPE { get => (DV16 >> 4) & 0xF; set => DV16 = (ushort)((DV16 & ~(0xF << 4)) | (ushort)((value > 0xF ? 0xF : value) << 4)); }
|
2018-08-19 22:50:15 +00:00
|
|
|
|
public int IV_SPC { get => (DV16 >> 0) & 0xF; set => DV16 = (ushort)((DV16 & ~(0xF << 0)) | (ushort)((value > 0xF ? 0xF : value) << 0)); }
|
2020-09-07 17:55:15 +00:00
|
|
|
|
public sealed override int IV_SPA { get => IV_SPC; set => IV_SPC = value; }
|
|
|
|
|
public sealed override int IV_SPD { get => IV_SPC; set { } }
|
2018-08-19 22:50:15 +00:00
|
|
|
|
|
2020-10-03 01:08:40 +00:00
|
|
|
|
public void SetNotNicknamed() => SetNotNicknamed(GuessedLanguage());
|
|
|
|
|
public abstract void SetNotNicknamed(int language);
|
2018-08-19 22:50:15 +00:00
|
|
|
|
|
2019-09-19 02:58:23 +00:00
|
|
|
|
public int GuessedLanguage(int fallback = (int)LanguageID.English)
|
2018-08-19 22:50:15 +00:00
|
|
|
|
{
|
|
|
|
|
int lang = Language;
|
|
|
|
|
if (lang > 0)
|
|
|
|
|
return lang;
|
2020-12-25 20:30:26 +00:00
|
|
|
|
if (fallback is (int)LanguageID.French or (int)LanguageID.German) // only other permitted besides English
|
2018-08-19 22:50:15 +00:00
|
|
|
|
return fallback;
|
|
|
|
|
return (int)LanguageID.English;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 18:23:47 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tries to guess the source language ID when transferred to future generations (7+)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="destLanguage">Destination language ID</param>
|
|
|
|
|
/// <returns>Source language ID</returns>
|
|
|
|
|
protected int TransferLanguage(int destLanguage)
|
|
|
|
|
{
|
|
|
|
|
// if the Species name of the destination language matches the current nickname, transfer with that language.
|
2019-09-19 02:58:23 +00:00
|
|
|
|
var expect = SpeciesName.GetSpeciesNameGeneration(Species, destLanguage, 2);
|
2019-05-27 18:23:47 +00:00
|
|
|
|
if (Nickname == expect)
|
|
|
|
|
return destLanguage;
|
|
|
|
|
return GuessedLanguage(destLanguage);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override ushort[] GetStats(PersonalInfo p)
|
2018-08-19 22:50:15 +00:00
|
|
|
|
{
|
|
|
|
|
var lv = Stat_Level;
|
2018-12-04 04:59:48 +00:00
|
|
|
|
ushort[] stats =
|
2018-08-19 22:50:15 +00:00
|
|
|
|
{
|
|
|
|
|
GetStat(p.HP , IV_HP , EV_HP , lv),
|
|
|
|
|
GetStat(p.ATK, IV_ATK, EV_ATK, lv),
|
|
|
|
|
GetStat(p.DEF, IV_DEF, EV_DEF, lv),
|
|
|
|
|
GetStat(p.SPE, IV_SPE, EV_SPE, lv),
|
|
|
|
|
GetStat(p.SPA, IV_SPA, EV_SPA, lv),
|
|
|
|
|
GetStat(p.SPD, IV_SPD, EV_SPD, lv),
|
|
|
|
|
};
|
2018-12-04 04:59:48 +00:00
|
|
|
|
stats[0] += (ushort)(5 + lv); // HP
|
|
|
|
|
return stats;
|
2018-08-19 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static ushort GetStat(int BV, int IV, int EV, int LV)
|
|
|
|
|
{
|
2019-02-26 01:26:19 +00:00
|
|
|
|
EV = (ushort)Math.Min(255, Math.Sqrt(EV) + 1) >> 2;
|
2018-08-19 22:50:15 +00:00
|
|
|
|
return (ushort)((((2 * (BV + IV)) + EV) * LV / 100) + 5);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override int GetMovePP(int move, int ppUpCount)
|
2019-02-26 01:39:41 +00:00
|
|
|
|
{
|
|
|
|
|
var pp = base.GetMovePP(move, 0);
|
2020-06-21 00:44:05 +00:00
|
|
|
|
return pp + (ppUpCount * Math.Min(7, pp / 5));
|
2019-02-26 01:39:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-20 08:50:27 +00:00
|
|
|
|
public void MaxEVs() => EV_HP = EV_ATK = EV_DEF = EV_SPC = EV_SPE = MaxEV;
|
|
|
|
|
|
2018-10-27 15:53:09 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies <see cref="PKM.IVs"/> to the <see cref="PKM"/> to make it shiny.
|
|
|
|
|
/// </summary>
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override void SetShiny()
|
2018-10-27 15:53:09 +00:00
|
|
|
|
{
|
|
|
|
|
IV_ATK |= 2;
|
|
|
|
|
IV_DEF = 10;
|
|
|
|
|
IV_SPE = 10;
|
|
|
|
|
IV_SPA = 10;
|
|
|
|
|
}
|
2021-02-15 21:52:49 +00:00
|
|
|
|
|
|
|
|
|
internal void ImportFromFuture(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
Nickname = pkm.Nickname;
|
|
|
|
|
OT_Name = pkm.OT_Name;
|
|
|
|
|
IV_ATK = pkm.IV_ATK / 2;
|
|
|
|
|
IV_DEF = pkm.IV_DEF / 2;
|
|
|
|
|
IV_SPC = pkm.IV_SPA / 2;
|
|
|
|
|
//IV_SPD = pkm.IV_ATK / 2;
|
|
|
|
|
IV_SPE = pkm.IV_SPE / 2;
|
|
|
|
|
|
|
|
|
|
if (pkm.HasMove((int)Move.HiddenPower))
|
|
|
|
|
HPType = pkm.HPType;
|
|
|
|
|
}
|
2018-08-19 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|