2015-12-23 05:14:50 +00:00
|
|
|
|
using System;
|
2020-01-19 00:46:38 +00:00
|
|
|
|
using System.Collections.Generic;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2015-12-23 05:14:50 +00:00
|
|
|
|
{
|
2017-10-23 22:45:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 5 Mystery Gift Template File
|
|
|
|
|
/// </summary>
|
2020-12-24 08:06:40 +00:00
|
|
|
|
public sealed class PGF : DataMysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, ILangNick, IContestStats, IContestStatsMutable, INature
|
2015-12-23 05:14:50 +00:00
|
|
|
|
{
|
2017-03-19 23:19:59 +00:00
|
|
|
|
public const int Size = 0xCC;
|
2020-12-11 04:42:30 +00:00
|
|
|
|
public override int Generation => 5;
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
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
|
|
|
|
public PGF() : this(new byte[Size]) { }
|
|
|
|
|
public PGF(byte[] data) : base(data) { }
|
2017-04-11 21:07:16 +00:00
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override int TID { get => ReadUInt16LittleEndian(Data.AsSpan(0x00)); set => WriteUInt16LittleEndian(Data.AsSpan(0x00), (ushort)value); }
|
|
|
|
|
public override int SID { get => ReadUInt16LittleEndian(Data.AsSpan(0x02)); set => WriteUInt16LittleEndian(Data.AsSpan(0x02), (ushort)value); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int OriginGame { get => Data[0x04]; set => Data[0x04] = (byte)value; }
|
2015-12-25 22:07:17 +00:00
|
|
|
|
// Unused 0x05 0x06, 0x07
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public uint PID { get => ReadUInt32LittleEndian(Data.AsSpan(0x08)); set => WriteUInt32LittleEndian(Data.AsSpan(0x08), value); }
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private byte RIB0 { get => Data[0x0C]; set => Data[0x0C] = value; }
|
|
|
|
|
private byte RIB1 { get => Data[0x0D]; set => Data[0x0D] = value; }
|
2018-08-10 04:53:39 +00:00
|
|
|
|
public bool RibbonCountry { get => (RIB0 & (1 << 0)) == 1 << 0; set => RIB0 = (byte)((RIB0 & ~(1 << 0)) | (value ? 1 << 0 : 0)); }
|
|
|
|
|
public bool RibbonNational { get => (RIB0 & (1 << 1)) == 1 << 1; set => RIB0 = (byte)((RIB0 & ~(1 << 1)) | (value ? 1 << 1 : 0)); }
|
|
|
|
|
public bool RibbonEarth { get => (RIB0 & (1 << 2)) == 1 << 2; set => RIB0 = (byte)((RIB0 & ~(1 << 2)) | (value ? 1 << 2 : 0)); }
|
|
|
|
|
public bool RibbonWorld { get => (RIB0 & (1 << 3)) == 1 << 3; set => RIB0 = (byte)((RIB0 & ~(1 << 3)) | (value ? 1 << 3 : 0)); }
|
|
|
|
|
public bool RibbonClassic { get => (RIB0 & (1 << 4)) == 1 << 4; set => RIB0 = (byte)((RIB0 & ~(1 << 4)) | (value ? 1 << 4 : 0)); }
|
|
|
|
|
public bool RibbonPremier { get => (RIB0 & (1 << 5)) == 1 << 5; set => RIB0 = (byte)((RIB0 & ~(1 << 5)) | (value ? 1 << 5 : 0)); }
|
|
|
|
|
public bool RibbonEvent { get => (RIB0 & (1 << 6)) == 1 << 6; set => RIB0 = (byte)((RIB0 & ~(1 << 6)) | (value ? 1 << 6 : 0)); }
|
|
|
|
|
public bool RibbonBirthday { get => (RIB0 & (1 << 7)) == 1 << 7; set => RIB0 = (byte)((RIB0 & ~(1 << 7)) | (value ? 1 << 7 : 0)); }
|
|
|
|
|
public bool RibbonSpecial { get => (RIB1 & (1 << 0)) == 1 << 0; set => RIB1 = (byte)((RIB1 & ~(1 << 0)) | (value ? 1 << 0 : 0)); }
|
|
|
|
|
public bool RibbonSouvenir { get => (RIB1 & (1 << 1)) == 1 << 1; set => RIB1 = (byte)((RIB1 & ~(1 << 1)) | (value ? 1 << 1 : 0)); }
|
|
|
|
|
public bool RibbonWishing { get => (RIB1 & (1 << 2)) == 1 << 2; set => RIB1 = (byte)((RIB1 & ~(1 << 2)) | (value ? 1 << 2 : 0)); }
|
|
|
|
|
public bool RibbonChampionBattle { get => (RIB1 & (1 << 3)) == 1 << 3; set => RIB1 = (byte)((RIB1 & ~(1 << 3)) | (value ? 1 << 3 : 0)); }
|
|
|
|
|
public bool RibbonChampionRegional { get => (RIB1 & (1 << 4)) == 1 << 4; set => RIB1 = (byte)((RIB1 & ~(1 << 4)) | (value ? 1 << 4 : 0)); }
|
|
|
|
|
public bool RibbonChampionNational { get => (RIB1 & (1 << 5)) == 1 << 5; set => RIB1 = (byte)((RIB1 & ~(1 << 5)) | (value ? 1 << 5 : 0)); }
|
|
|
|
|
public bool RibbonChampionWorld { get => (RIB1 & (1 << 6)) == 1 << 6; set => RIB1 = (byte)((RIB1 & ~(1 << 6)) | (value ? 1 << 6 : 0)); }
|
|
|
|
|
public bool RIB1_7 { get => (RIB1 & (1 << 7)) == 1 << 7; set => RIB1 = (byte)((RIB1 & ~(1 << 7)) | (value ? 1 << 7 : 0)); }
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Ball { get => Data[0x0E]; set => Data[0x0E] = (byte)value; }
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override int HeldItem { get => ReadUInt16LittleEndian(Data.AsSpan(0x10)); set => WriteUInt16LittleEndian(Data.AsSpan(0x10), (ushort)value); }
|
|
|
|
|
public int Move1 { get => ReadUInt16LittleEndian(Data.AsSpan(0x12)); set => WriteUInt16LittleEndian(Data.AsSpan(0x12), (ushort)value); }
|
|
|
|
|
public int Move2 { get => ReadUInt16LittleEndian(Data.AsSpan(0x14)); set => WriteUInt16LittleEndian(Data.AsSpan(0x14), (ushort)value); }
|
|
|
|
|
public int Move3 { get => ReadUInt16LittleEndian(Data.AsSpan(0x16)); set => WriteUInt16LittleEndian(Data.AsSpan(0x16), (ushort)value); }
|
|
|
|
|
public int Move4 { get => ReadUInt16LittleEndian(Data.AsSpan(0x18)); set => WriteUInt16LittleEndian(Data.AsSpan(0x18), (ushort)value); }
|
|
|
|
|
public override int Species { get => ReadUInt16LittleEndian(Data.AsSpan(0x1A)); set => WriteUInt16LittleEndian(Data.AsSpan(0x1A), (ushort)value); }
|
2017-11-18 19:34:23 +00:00
|
|
|
|
public override int Form { get => Data[0x1C]; set => Data[0x1C] = (byte)value; }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int Language { get => Data[0x1D]; set => Data[0x1D] = (byte)value; }
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
2015-12-23 05:14:50 +00:00
|
|
|
|
public string Nickname
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => StringConverter5.GetString(Data.AsSpan( 0x1E, 11 * 2));
|
|
|
|
|
set => StringConverter5.SetString(Data.AsSpan(0x1E, 11 * 2), value.AsSpan(), 11, StringConverterOption.ClearFF);
|
2015-12-23 05:14:50 +00:00
|
|
|
|
}
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
2018-10-28 04:59:31 +00:00
|
|
|
|
public int Nature { get => (sbyte)Data[0x34]; set => Data[0x34] = (byte)value; }
|
2017-11-18 19:34:23 +00:00
|
|
|
|
public override int Gender { get => Data[0x35]; set => Data[0x35] = (byte)value; }
|
2018-07-03 03:34:41 +00:00
|
|
|
|
public override int AbilityType { get => Data[0x36]; set => Data[0x36] = (byte)value; }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int PIDType { get => Data[0x37]; set => Data[0x37] = (byte)value; }
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override int EggLocation { get => ReadUInt16LittleEndian(Data.AsSpan(0x38)); set => WriteUInt16LittleEndian(Data.AsSpan(0x38), (ushort)value); }
|
|
|
|
|
public ushort MetLocation { get => ReadUInt16LittleEndian(Data.AsSpan(0x3A)); set => WriteUInt16LittleEndian(Data.AsSpan(0x3A), value); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int MetLevel { get => Data[0x3C]; set => Data[0x3C] = (byte)value; }
|
2021-01-01 21:39:08 +00:00
|
|
|
|
public byte CNT_Cool { get => Data[0x3D]; set => Data[0x3D] = value; }
|
|
|
|
|
public byte CNT_Beauty { get => Data[0x3E]; set => Data[0x3E] = value; }
|
|
|
|
|
public byte CNT_Cute { get => Data[0x3F]; set => Data[0x3F] = value; }
|
|
|
|
|
public byte CNT_Smart { get => Data[0x40]; set => Data[0x40] = value; }
|
|
|
|
|
public byte CNT_Tough { get => Data[0x41]; set => Data[0x41] = value; }
|
|
|
|
|
public byte CNT_Sheen { get => Data[0x42]; set => Data[0x42] = value; }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int IV_HP { get => Data[0x43]; set => Data[0x43] = (byte)value; }
|
|
|
|
|
public int IV_ATK { get => Data[0x44]; set => Data[0x44] = (byte)value; }
|
|
|
|
|
public int IV_DEF { get => Data[0x45]; set => Data[0x45] = (byte)value; }
|
|
|
|
|
public int IV_SPE { get => Data[0x46]; set => Data[0x46] = (byte)value; }
|
|
|
|
|
public int IV_SPA { get => Data[0x47]; set => Data[0x47] = (byte)value; }
|
|
|
|
|
public int IV_SPD { get => Data[0x48]; set => Data[0x48] = (byte)value; }
|
2015-12-23 05:14:50 +00:00
|
|
|
|
// Unused 0x49
|
2021-01-15 06:50:13 +00:00
|
|
|
|
public override string OT_Name
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => StringConverter5.GetString(Data.AsSpan(0x4A, 8 * 2));
|
|
|
|
|
set => StringConverter5.SetString(Data.AsSpan(0x4A, 8 * 2), value.AsSpan(), 8, StringConverterOption.ClearFF);
|
2021-01-15 06:50:13 +00:00
|
|
|
|
}
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int OTGender { get => Data[0x5A]; set => Data[0x5A] = (byte)value; }
|
|
|
|
|
public override int Level { get => Data[0x5B]; set => Data[0x5C] = (byte)value; }
|
2021-03-29 07:14:44 +00:00
|
|
|
|
public override bool IsEgg { get => Data[0x5C] == 1; set => Data[0x5C] = value ? (byte)1 : (byte)0; }
|
2015-12-23 05:14:50 +00:00
|
|
|
|
// Unused 0x5D 0x5E 0x5F
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override string CardTitle
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => StringConverter5.GetString(Data.AsSpan(0x60, 37 * 2));
|
|
|
|
|
set => StringConverter5.SetString(Data.AsSpan(0x60, 37 * 2), value.AsSpan(), 36, StringConverterOption.ClearZero);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
|
|
|
|
// Card Attributes
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override int ItemID { get => ReadUInt16LittleEndian(Data.AsSpan(0x00)); set => WriteUInt16LittleEndian(Data.AsSpan(0x00), (ushort)value); }
|
2017-04-11 21:07:16 +00:00
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private ushort Year { get => ReadUInt16LittleEndian(Data.AsSpan(0xAE)); set => WriteUInt16LittleEndian(Data.AsSpan(0xAE), value); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private byte Month { get => Data[0xAD]; set => Data[0xAD] = value; }
|
|
|
|
|
private byte Day { get => Data[0xAC]; set => Data[0xAC] = value; }
|
2016-08-10 14:02:31 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the date of the card.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DateTime? Date
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// Check to see if date is valid
|
2021-05-14 23:46:48 +00:00
|
|
|
|
if (!DateUtil.IsDateValid(Year, Month, Day))
|
2016-08-10 14:02:31 +00:00
|
|
|
|
return null;
|
2016-08-13 00:16:03 +00:00
|
|
|
|
|
|
|
|
|
return new DateTime(Year, Month, Day);
|
2016-08-10 14:02:31 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value.HasValue)
|
|
|
|
|
{
|
|
|
|
|
// Only update the properties if a value is provided.
|
2016-08-13 00:16:03 +00:00
|
|
|
|
Year = (ushort)value.Value.Year;
|
2016-08-10 14:02:31 +00:00
|
|
|
|
Month = (byte)value.Value.Month;
|
|
|
|
|
Day = (byte)value.Value.Day;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Clear the Met Date.
|
|
|
|
|
// If code tries to access MetDate again, null will be returned.
|
|
|
|
|
Year = 0;
|
|
|
|
|
Month = 0;
|
|
|
|
|
Day = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override int CardID
|
2015-12-23 05:14:50 +00:00
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0xB0));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0xB0), (ushort)value);
|
2015-12-23 05:14:50 +00:00
|
|
|
|
}
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int CardLocation { get => Data[0xB2]; set => Data[0xB2] = (byte)value; }
|
|
|
|
|
public int CardType { get => Data[0xB3]; set => Data[0xB3] = (byte)value; }
|
2018-08-10 04:53:39 +00:00
|
|
|
|
public override bool GiftUsed { get => Data[0xB4] >> 1 > 0; set => Data[0xB4] = (byte)((Data[0xB4] & ~2) | (value ? 2 : 0)); }
|
2021-03-29 07:14:44 +00:00
|
|
|
|
public bool MultiObtain { get => Data[0xB4] == 1; set => Data[0xB4] = value ? (byte)1 : (byte)0; }
|
2017-04-11 21:07:16 +00:00
|
|
|
|
|
2015-12-23 05:14:50 +00:00
|
|
|
|
// Meta Accessible Properties
|
2018-06-30 22:01:16 +00:00
|
|
|
|
public override int[] IVs
|
|
|
|
|
{
|
|
|
|
|
get => new[] { IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_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) return;
|
2018-06-30 22:01:16 +00:00
|
|
|
|
IV_HP = value[0]; IV_ATK = value[1]; IV_DEF = value[2];
|
|
|
|
|
IV_SPE = value[3]; IV_SPA = value[4]; IV_SPD = value[5];
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
public bool IsNicknamed => Nickname.Length > 0;
|
2017-06-04 01:40:44 +00:00
|
|
|
|
public override bool IsShiny => PIDType == 2;
|
2018-01-02 20:00:41 +00:00
|
|
|
|
public override int Location { get => MetLocation; set => MetLocation = (ushort)value; }
|
2020-01-19 00:46:38 +00:00
|
|
|
|
public override IReadOnlyList<int> Moves => new[] { Move1, Move2, Move3, Move4 };
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override bool IsPokémon { get => CardType == 1; set { if (value) CardType = 1; } }
|
|
|
|
|
public override bool IsItem { get => CardType == 2; set { if (value) CardType = 2; } }
|
|
|
|
|
public bool IsPower { get => CardType == 3; set { if (value) CardType = 3; } }
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
2015-12-23 05:14:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (!IsPokémon)
|
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
|
|
|
|
throw new ArgumentException(nameof(IsPokémon));
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
2020-01-26 05:49:52 +00:00
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
var dt = DateTime.Now;
|
2015-12-25 22:07:17 +00:00
|
|
|
|
if (Day == 0)
|
|
|
|
|
{
|
|
|
|
|
Day = (byte)dt.Day;
|
|
|
|
|
Month = (byte)dt.Month;
|
|
|
|
|
Year = (byte)dt.Year;
|
|
|
|
|
}
|
2019-02-09 19:37:20 +00:00
|
|
|
|
|
2020-01-26 05:49:52 +00:00
|
|
|
|
int currentLevel = Level > 0 ? Level : rnd.Next(1, 101);
|
2020-12-11 04:42:30 +00:00
|
|
|
|
var pi = PersonalTable.B2W2.GetFormEntry(Species, Form);
|
2020-12-22 01:17:56 +00:00
|
|
|
|
PK5 pk = new()
|
2015-12-23 05:14:50 +00:00
|
|
|
|
{
|
|
|
|
|
Species = Species,
|
|
|
|
|
HeldItem = HeldItem,
|
|
|
|
|
Met_Level = currentLevel,
|
2020-01-26 05:49:52 +00:00
|
|
|
|
Nature = Nature != -1 ? Nature : rnd.Next(25),
|
2020-12-11 04:42:30 +00:00
|
|
|
|
Form = Form,
|
2020-06-17 02:46:22 +00:00
|
|
|
|
Version = OriginGame == 0 ? sav.Game : OriginGame,
|
|
|
|
|
Language = Language == 0 ? sav.Language : Language,
|
2016-10-23 19:48:49 +00:00
|
|
|
|
Ball = Ball,
|
2015-12-23 05:14:50 +00:00
|
|
|
|
Move1 = Move1,
|
|
|
|
|
Move2 = Move2,
|
|
|
|
|
Move3 = Move3,
|
|
|
|
|
Move4 = Move4,
|
|
|
|
|
Met_Location = MetLocation,
|
2016-08-10 14:02:31 +00:00
|
|
|
|
MetDate = Date,
|
2015-12-23 05:14:50 +00:00
|
|
|
|
Egg_Location = EggLocation,
|
|
|
|
|
CNT_Cool = CNT_Cool,
|
|
|
|
|
CNT_Beauty = CNT_Beauty,
|
|
|
|
|
CNT_Cute = CNT_Cute,
|
|
|
|
|
CNT_Smart = CNT_Smart,
|
|
|
|
|
CNT_Tough = CNT_Tough,
|
|
|
|
|
CNT_Sheen = CNT_Sheen,
|
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
EXP = Experience.GetEXP(currentLevel, pi.EXPGrowth),
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
|
|
|
|
// Ribbons
|
2016-07-16 22:52:33 +00:00
|
|
|
|
RibbonCountry = RibbonCountry,
|
|
|
|
|
RibbonNational = RibbonNational,
|
|
|
|
|
RibbonEarth = RibbonEarth,
|
|
|
|
|
RibbonWorld = RibbonWorld,
|
|
|
|
|
RibbonClassic = RibbonClassic,
|
|
|
|
|
RibbonPremier = RibbonPremier,
|
|
|
|
|
RibbonEvent = RibbonEvent,
|
|
|
|
|
RibbonBirthday = RibbonBirthday,
|
2015-12-25 22:07:17 +00:00
|
|
|
|
|
2016-07-16 22:52:33 +00:00
|
|
|
|
RibbonSpecial = RibbonSpecial,
|
|
|
|
|
RibbonSouvenir = RibbonSouvenir,
|
|
|
|
|
RibbonWishing = RibbonWishing,
|
|
|
|
|
RibbonChampionBattle = RibbonChampionBattle,
|
|
|
|
|
RibbonChampionRegional = RibbonChampionRegional,
|
|
|
|
|
RibbonChampionNational = RibbonChampionNational,
|
|
|
|
|
RibbonChampionWorld = RibbonChampionWorld,
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
|
|
|
|
FatefulEncounter = true,
|
|
|
|
|
};
|
2020-06-17 02:46:22 +00:00
|
|
|
|
if (sav.Generation > 5 && OriginGame == 0) // Gen6+, give random gen5 game
|
2020-01-26 05:49:52 +00:00
|
|
|
|
pk.Version = (int)GameVersion.W + rnd.Next(4);
|
2018-03-29 00:46:37 +00:00
|
|
|
|
|
2018-07-01 04:28:20 +00:00
|
|
|
|
if (Move1 == 0) // No moves defined
|
|
|
|
|
pk.Moves = MoveLevelUp.GetEncounterMoves(Species, Form, Level, (GameVersion)pk.Version);
|
|
|
|
|
|
2018-04-07 18:40:01 +00:00
|
|
|
|
pk.SetMaximumPPCurrent();
|
2019-02-09 19:37:20 +00:00
|
|
|
|
|
2017-07-15 05:50:12 +00:00
|
|
|
|
if (IsEgg) // User's
|
2015-12-23 05:14:50 +00:00
|
|
|
|
{
|
2020-06-17 02:46:22 +00:00
|
|
|
|
pk.TID = sav.TID;
|
|
|
|
|
pk.SID = sav.SID;
|
|
|
|
|
pk.OT_Name = sav.OT;
|
|
|
|
|
pk.OT_Gender = sav.Gender;
|
2015-12-25 22:07:17 +00:00
|
|
|
|
}
|
2017-07-15 05:50:12 +00:00
|
|
|
|
else // Hardcoded
|
2015-12-25 22:07:17 +00:00
|
|
|
|
{
|
2017-07-15 05:50:12 +00:00
|
|
|
|
pk.TID = TID;
|
|
|
|
|
pk.SID = SID;
|
2017-11-18 19:34:23 +00:00
|
|
|
|
pk.OT_Name = OT_Name;
|
2020-06-17 02:46:22 +00:00
|
|
|
|
pk.OT_Gender = (OTGender == 3 ? sav.Gender : OTGender) & 1; // some events have variable gender based on receiving SaveFile
|
2015-12-23 05:14:50 +00:00
|
|
|
|
}
|
2019-02-09 19:37:20 +00:00
|
|
|
|
|
2015-12-23 05:14:50 +00:00
|
|
|
|
pk.IsNicknamed = IsNicknamed;
|
2020-12-11 04:42:30 +00:00
|
|
|
|
pk.Nickname = IsNicknamed ? Nickname : SpeciesName.GetSpeciesNameGeneration(Species, pk.Language, Generation);
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
SetPINGA(pk, criteria);
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
if (IsEgg)
|
|
|
|
|
SetEggMetDetails(pk);
|
|
|
|
|
|
|
|
|
|
pk.CurrentFriendship = pk.IsEgg ? pi.HatchCycles : pi.BaseFriendship;
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.RefreshChecksum();
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetEggMetDetails(PK5 pk)
|
|
|
|
|
{
|
|
|
|
|
pk.IsEgg = true;
|
|
|
|
|
pk.EggMetDate = Date;
|
2020-12-11 04:42:30 +00:00
|
|
|
|
pk.Nickname = SpeciesName.GetSpeciesNameGeneration(0, pk.Language, Generation);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.IsNicknamed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetPINGA(PKM pk, EncounterCriteria criteria)
|
|
|
|
|
{
|
2020-12-11 04:42:30 +00:00
|
|
|
|
var pi = PersonalTable.B2W2.GetFormEntry(Species, Form);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.Nature = (int)criteria.GetNature((Nature)Nature);
|
2020-06-27 17:01:28 +00:00
|
|
|
|
pk.Gender = pi.Genderless ? 2 : Gender != 2 ? Gender : criteria.GetGender(-1, pi);
|
2021-04-09 21:52:49 +00:00
|
|
|
|
var av = GetAbilityIndex(criteria);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
SetPID(pk, av);
|
|
|
|
|
pk.RefreshAbility(av);
|
|
|
|
|
SetIVs(pk);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-09 21:52:49 +00:00
|
|
|
|
private int GetAbilityIndex(EncounterCriteria criteria) => AbilityType switch
|
2019-02-09 19:37:20 +00:00
|
|
|
|
{
|
2021-01-02 01:08:49 +00:00
|
|
|
|
00 or 01 or 02 => AbilityType, // Fixed 0/1/2
|
2022-01-09 06:34:04 +00:00
|
|
|
|
03 or 04 => criteria.GetAbilityFromNumber(Ability), // 0/1 or 0/1/H
|
2021-08-21 23:51:50 +00:00
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(AbilityType)),
|
2021-01-02 01:08:49 +00:00
|
|
|
|
};
|
2015-12-23 05:14:50 +00:00
|
|
|
|
|
2022-01-09 06:34:04 +00:00
|
|
|
|
public override AbilityPermission Ability => AbilityType switch
|
2021-12-09 08:46:59 +00:00
|
|
|
|
{
|
2022-01-09 06:34:04 +00:00
|
|
|
|
0 => AbilityPermission.OnlyFirst,
|
|
|
|
|
1 => AbilityPermission.OnlySecond,
|
|
|
|
|
2 => AbilityPermission.OnlyHidden,
|
|
|
|
|
3 => AbilityPermission.Any12,
|
|
|
|
|
_ => AbilityPermission.Any12H,
|
2021-12-09 08:46:59 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
private void SetPID(PKM pk, int av)
|
|
|
|
|
{
|
2017-04-11 21:07:16 +00:00
|
|
|
|
if (PID != 0)
|
2018-08-10 04:53:39 +00:00
|
|
|
|
{
|
2015-12-26 02:17:47 +00:00
|
|
|
|
pk.PID = PID;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
return;
|
2018-08-10 04:53:39 +00:00
|
|
|
|
}
|
2017-04-11 21:07:16 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.PID = Util.Rand32();
|
|
|
|
|
// Force Gender
|
2020-01-26 05:49:52 +00:00
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
|
do { pk.PID = (pk.PID & 0xFFFFFF00) | (uint)rnd.Next(0x100); }
|
2019-02-09 19:37:20 +00:00
|
|
|
|
while (!pk.IsGenderValid());
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
if (PIDType == 2) // Always
|
|
|
|
|
{
|
|
|
|
|
uint gb = pk.PID & 0xFF;
|
|
|
|
|
pk.PID = PIDGenerator.GetMG5ShinyPID(gb, (uint)av, pk.TID, pk.SID);
|
2015-12-23 05:14:50 +00:00
|
|
|
|
}
|
2019-02-09 19:37:20 +00:00
|
|
|
|
else if (PIDType != 1) // Force Not Shiny
|
2015-12-23 05:14:50 +00:00
|
|
|
|
{
|
2019-02-09 19:37:20 +00:00
|
|
|
|
if (pk.IsShiny)
|
|
|
|
|
pk.PID ^= 0x10000000;
|
2015-12-23 05:14:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
if (av == 1)
|
|
|
|
|
pk.PID |= 0x10000;
|
|
|
|
|
else
|
|
|
|
|
pk.PID &= 0xFFFEFFFF;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-06 00:46:23 +00:00
|
|
|
|
public override Shiny Shiny => PIDType switch
|
|
|
|
|
{
|
|
|
|
|
1 => Shiny.Random,
|
|
|
|
|
2 => Shiny.Always,
|
|
|
|
|
_ => Shiny.Never,
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
private void SetIVs(PKM pk)
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
Span<int> finalIVs = stackalloc int[6];
|
2020-01-26 05:49:52 +00:00
|
|
|
|
var rnd = Util.Rand;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
for (int i = 0; i < IVs.Length; i++)
|
2020-01-26 05:49:52 +00:00
|
|
|
|
finalIVs[i] = IVs[i] == 0xFF ? rnd.Next(32) : IVs[i];
|
2022-01-03 05:35:59 +00:00
|
|
|
|
pk.SetIVs(finalIVs);
|
2015-12-23 05:14:50 +00:00
|
|
|
|
}
|
2018-12-27 09:00:08 +00:00
|
|
|
|
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
public override bool IsMatchExact(PKM pkm, DexLevel evo)
|
2018-12-27 09:00:08 +00:00
|
|
|
|
{
|
|
|
|
|
if (!IsEgg)
|
|
|
|
|
{
|
|
|
|
|
if (SID != pkm.SID) return false;
|
|
|
|
|
if (TID != pkm.TID) return false;
|
|
|
|
|
if (OT_Name != pkm.OT_Name) return false;
|
|
|
|
|
if (OTGender < 3 && OTGender != pkm.OT_Gender) return false;
|
|
|
|
|
if (PID != 0 && pkm.PID != PID) return false;
|
|
|
|
|
if (PIDType == 0 && pkm.IsShiny) return false;
|
|
|
|
|
if (PIDType == 2 && !pkm.IsShiny) return false;
|
|
|
|
|
if (OriginGame != 0 && OriginGame != pkm.Version) return false;
|
|
|
|
|
if (Language != 0 && Language != pkm.Language) return false;
|
|
|
|
|
|
|
|
|
|
if (EggLocation != pkm.Egg_Location) return false;
|
|
|
|
|
if (MetLocation != pkm.Met_Location) return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (EggLocation != pkm.Egg_Location) // traded
|
|
|
|
|
{
|
2019-05-11 03:46:49 +00:00
|
|
|
|
if (pkm.Egg_Location != Locations.LinkTrade5)
|
2018-12-27 09:00:08 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (PIDType == 0 && pkm.IsShiny)
|
|
|
|
|
{
|
2020-06-17 02:46:22 +00:00
|
|
|
|
return false; // can't be traded away for un-shiny
|
2018-12-27 09:00:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pkm.IsEgg && !pkm.IsNative)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 04:42:30 +00:00
|
|
|
|
if (Form != evo.Form && !FormInfo.IsFormChangeable(Species, Form, pkm.Form, pkm.Format))
|
2019-12-29 03:00:01 +00:00
|
|
|
|
return false;
|
2018-12-27 09:00:08 +00:00
|
|
|
|
|
|
|
|
|
if (Level != pkm.Met_Level) return false;
|
|
|
|
|
if (Ball != pkm.Ball) return false;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (Nature != -1 && pkm.Nature != Nature)
|
|
|
|
|
return false;
|
2018-12-27 09:00:08 +00:00
|
|
|
|
if (Gender != 2 && Gender != pkm.Gender) return false;
|
|
|
|
|
|
|
|
|
|
if (pkm is IContestStats s && s.IsContestBelow(this))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
protected override bool IsMatchDeferred(PKM pkm) => Species != pkm.Species;
|
|
|
|
|
protected override bool IsMatchPartial(PKM pkm) => CanBeReceivedBy(pkm.Version);
|
|
|
|
|
private static bool CanBeReceivedBy(int _) => true;
|
2015-12-23 05:14:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|