2016-11-13 21:11:53 +00:00
|
|
|
|
using System;
|
2020-01-19 00:46:38 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-11-13 21:11:53 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-11-13 21:11:53 +00:00
|
|
|
|
{
|
2017-10-23 22:45:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 7 Mystery Gift Template File
|
|
|
|
|
/// </summary>
|
2019-11-26 18:46:16 +00:00
|
|
|
|
public sealed class WC7 : DataMysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, ILangNick, IContestStats, INature, IMemoryOT
|
2016-11-13 21:11:53 +00:00
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
public const int Size = 0x108;
|
2016-11-13 21:11:53 +00:00
|
|
|
|
public override int Format => 7;
|
|
|
|
|
|
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 WC7() : this(new byte[Size]) { }
|
|
|
|
|
public WC7(byte[] data) : base(data) { }
|
2018-07-28 05:26:27 +00:00
|
|
|
|
|
2019-09-11 05:07:50 +00:00
|
|
|
|
public int RestrictLanguage { get; set; } // None
|
|
|
|
|
public byte RestrictVersion { get; set; } // Permit All
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
2018-07-28 05:26:27 +00:00
|
|
|
|
public bool CanBeReceivedByVersion(int v)
|
|
|
|
|
{
|
|
|
|
|
if (v < (int)GameVersion.SN || v > (int)GameVersion.UM)
|
|
|
|
|
return false;
|
|
|
|
|
if (RestrictVersion == 0)
|
|
|
|
|
return true; // no data
|
|
|
|
|
var bitIndex = v - (int)GameVersion.SN;
|
|
|
|
|
var bit = 1 << bitIndex;
|
|
|
|
|
return (RestrictVersion & bit) != 0;
|
2016-11-13 21:11:53 +00:00
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-11-13 21:11:53 +00:00
|
|
|
|
// General Card Properties
|
2018-08-10 04:53:39 +00:00
|
|
|
|
public override int CardID
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, 0);
|
2018-08-10 04:53:39 +00:00
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string CardTitle
|
|
|
|
|
{
|
|
|
|
|
// Max len 36 char, followed by null terminator
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Util.TrimFromZero(Encoding.Unicode.GetString(Data, 2, 72));
|
2018-08-10 04:53:39 +00:00
|
|
|
|
set => Encoding.Unicode.GetBytes(value.PadRight(36, '\0')).CopyTo(Data, 2);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
internal uint RawDate
|
2018-08-10 04:53:39 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt32(Data, 0x4C);
|
2018-08-10 04:53:39 +00:00
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, 0x4C);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private uint Year
|
|
|
|
|
{
|
|
|
|
|
get => (RawDate / 10000) + 2000;
|
2018-12-11 04:32:08 +00:00
|
|
|
|
set => RawDate = SetDate(value, Month, Day);
|
2018-08-10 04:53:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private uint Month
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => RawDate % 10000 / 100;
|
2018-12-11 04:32:08 +00:00
|
|
|
|
set => RawDate = SetDate(Year, value, Day);
|
2018-08-10 04:53:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private uint Day
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => RawDate % 100;
|
2018-12-11 04:32:08 +00:00
|
|
|
|
set => RawDate = SetDate(Year, Month, value);
|
2018-08-10 04:53:39 +00:00
|
|
|
|
}
|
2016-11-13 21:11:53 +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 static uint SetDate(uint year, uint month, uint day) => (Math.Max(0, year - 2000) * 10000) + (month * 100) + day;
|
2018-12-11 04:32:08 +00:00
|
|
|
|
|
2016-11-13 21:11:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the date of the card.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DateTime? Date
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// Check to see if date is valid
|
|
|
|
|
if (!Util.IsDateValid(Year, Month, Day))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
return new DateTime((int)Year, (int)Month, (int)Day);
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value.HasValue)
|
|
|
|
|
{
|
|
|
|
|
// Only update the properties if a value is provided.
|
|
|
|
|
Year = (ushort)value.Value.Year;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int CardLocation { get => Data[0x50]; set => Data[0x50] = (byte)value; }
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int CardType { get => Data[0x51]; set => Data[0x51] = (byte)value; }
|
|
|
|
|
public byte CardFlags { get => Data[0x52]; set => Data[0x52] = value; }
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2018-08-10 04:53:39 +00:00
|
|
|
|
public bool GiftRepeatable { get => (CardFlags & 1) == 0; set => CardFlags = (byte)((CardFlags & ~1) | (value ? 0 : 1)); }
|
|
|
|
|
public override bool GiftUsed { get => (CardFlags & 2) == 2; set => CardFlags = (byte)((CardFlags & ~2) | (value ? 2 : 0)); }
|
|
|
|
|
public bool GiftOncePerDay { get => (CardFlags & 4) == 4; set => CardFlags = (byte)((CardFlags & ~4) | (value ? 4 : 0)); }
|
2017-01-05 22:45:53 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public bool MultiObtain { get => Data[0x53] == 1; set => Data[0x53] = (byte)(value ? 1 : 0); }
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-01-27 17:09:28 +00:00
|
|
|
|
// BP Properties
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override bool IsBP { get => CardType == 3; set { if (value) CardType = 3; } }
|
2018-08-10 04:53:39 +00:00
|
|
|
|
public override int BP { get => ItemID; set => ItemID = value; }
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
2017-01-06 06:34:22 +00:00
|
|
|
|
// Bean (Mame) Properties
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override bool IsBean { get => CardType == 2; set { if (value) CardType = 2; } }
|
2018-08-10 04:53:39 +00:00
|
|
|
|
public override int Bean { get => ItemID; set => ItemID = value; }
|
2017-01-06 06:34:22 +00:00
|
|
|
|
|
2016-11-13 21:11:53 +00:00
|
|
|
|
// Item Properties
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override bool IsItem { get => CardType == 1; set { if (value) CardType = 1; } }
|
2018-08-10 04:53:39 +00:00
|
|
|
|
public override int ItemID { get => BitConverter.ToUInt16(Data, 0x68); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x68); }
|
|
|
|
|
public int GetItem(int index) => BitConverter.ToUInt16(Data, 0x68 + (0x4 * index));
|
|
|
|
|
public void SetItem(int index, ushort item) => BitConverter.GetBytes(item).CopyTo(Data, 0x68 + (4 * index));
|
|
|
|
|
public int GetQuantity(int index) => BitConverter.ToUInt16(Data, 0x6A + (0x4 * index));
|
|
|
|
|
public void SetQuantity(int index, ushort quantity) => BitConverter.GetBytes(quantity).CopyTo(Data, 0x6A + (4 * index));
|
2017-02-21 05:46:25 +00:00
|
|
|
|
|
2018-08-10 04:53:39 +00:00
|
|
|
|
public override int Quantity
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, 0x6A);
|
2018-08-10 04:53:39 +00:00
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x6A);
|
|
|
|
|
}
|
2017-02-21 05:46:25 +00:00
|
|
|
|
|
2016-11-13 21:11:53 +00:00
|
|
|
|
// Pokémon Properties
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override bool IsPokémon { get => CardType == 0; set { if (value) CardType = 0; } }
|
2018-03-17 02:35:55 +00:00
|
|
|
|
public override bool IsShiny => PIDType == Shiny.Always;
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
|
|
|
|
public override int TID
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, 0x68);
|
2018-08-10 04:53:39 +00:00
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x68);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-18 19:34:23 +00:00
|
|
|
|
public override int SID {
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, 0x6A);
|
2018-08-10 04:53:39 +00:00
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x6A);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int OriginGame
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[0x6C];
|
2018-08-10 04:53:39 +00:00
|
|
|
|
set => Data[0x6C] = (byte)value;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 21:11:53 +00:00
|
|
|
|
public uint EncryptionConstant {
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt32(Data, 0x70);
|
2018-08-10 04:53:39 +00:00
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, 0x70);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Ball
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[0x76];
|
|
|
|
|
set => Data[0x76] = (byte)value; }
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
|
|
|
|
public override int HeldItem
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, 0x78);
|
2018-08-10 04:53:39 +00:00
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x78);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Move1 { get => BitConverter.ToUInt16(Data, 0x7A); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x7A); }
|
|
|
|
|
public int Move2 { get => BitConverter.ToUInt16(Data, 0x7C); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x7C); }
|
|
|
|
|
public int Move3 { get => BitConverter.ToUInt16(Data, 0x7E); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x7E); }
|
|
|
|
|
public int Move4 { get => BitConverter.ToUInt16(Data, 0x80); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x80); }
|
|
|
|
|
public override int Species { get => BitConverter.ToUInt16(Data, 0x82); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x82); }
|
|
|
|
|
public override int Form { get => Data[0x84]; set => Data[0x84] = (byte)value; }
|
|
|
|
|
public int Language { get => Data[0x85]; set => Data[0x85] = (byte)value; }
|
|
|
|
|
|
|
|
|
|
public string Nickname
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x86, 0x1A));
|
2018-08-10 04:53:39 +00:00
|
|
|
|
set => Encoding.Unicode.GetBytes(value.PadRight(12 + 1, '\0')).CopyTo(Data, 0x86);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-28 04:59:31 +00:00
|
|
|
|
public int Nature { get => (sbyte)Data[0xA0]; set => Data[0xA0] = (byte)value; }
|
2018-08-10 04:53:39 +00:00
|
|
|
|
public override int Gender { get => Data[0xA1]; set => Data[0xA1] = (byte)value; }
|
|
|
|
|
public override int AbilityType { get => Data[0xA2]; set => Data[0xA2] = (byte)value; }
|
|
|
|
|
public Shiny PIDType { get => (Shiny)Data[0xA3]; set => Data[0xA3] = (byte)value; }
|
|
|
|
|
public override int EggLocation { get => BitConverter.ToUInt16(Data, 0xA4); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xA4); }
|
|
|
|
|
public int MetLocation { get => BitConverter.ToUInt16(Data, 0xA6); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xA6); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int MetLevel { get => Data[0xA8]; set => Data[0xA8] = (byte)value; }
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int CNT_Cool { get => Data[0xA9]; set => Data[0xA9] = (byte)value; }
|
|
|
|
|
public int CNT_Beauty { get => Data[0xAA]; set => Data[0xAA] = (byte)value; }
|
|
|
|
|
public int CNT_Cute { get => Data[0xAB]; set => Data[0xAB] = (byte)value; }
|
|
|
|
|
public int CNT_Smart { get => Data[0xAC]; set => Data[0xAC] = (byte)value; }
|
|
|
|
|
public int CNT_Tough { get => Data[0xAD]; set => Data[0xAD] = (byte)value; }
|
|
|
|
|
public int CNT_Sheen { get => Data[0xAE]; set => Data[0xAE] = (byte)value; }
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int IV_HP { get => Data[0xAF]; set => Data[0xAF] = (byte)value; }
|
|
|
|
|
public int IV_ATK { get => Data[0xB0]; set => Data[0xB0] = (byte)value; }
|
|
|
|
|
public int IV_DEF { get => Data[0xB1]; set => Data[0xB1] = (byte)value; }
|
|
|
|
|
public int IV_SPE { get => Data[0xB2]; set => Data[0xB2] = (byte)value; }
|
|
|
|
|
public int IV_SPA { get => Data[0xB3]; set => Data[0xB3] = (byte)value; }
|
|
|
|
|
public int IV_SPD { get => Data[0xB4]; set => Data[0xB4] = (byte)value; }
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int OTGender { get => Data[0xB5]; set => Data[0xB5] = (byte)value; }
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
|
|
|
|
public override string OT_Name
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0xB6, 0x1A));
|
2018-08-10 04:53:39 +00:00
|
|
|
|
set => Encoding.Unicode.GetBytes(value.PadRight(value.Length + 1, '\0')).CopyTo(Data, 0xB6);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Level { get => Data[0xD0]; set => Data[0xD0] = (byte)value; }
|
|
|
|
|
public override bool IsEgg { get => Data[0xD1] == 1; set => Data[0xD1] = (byte)(value ? 1 : 0); }
|
|
|
|
|
public ushort AdditionalItem { get => BitConverter.ToUInt16(Data, 0xD2); set => BitConverter.GetBytes(value).CopyTo(Data, 0xD2); }
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
|
|
|
|
public uint PID { get => BitConverter.ToUInt32(Data, 0xD4); set => BitConverter.GetBytes(value).CopyTo(Data, 0xD4); }
|
|
|
|
|
public int RelearnMove1 { get => BitConverter.ToUInt16(Data, 0xD8); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xD8); }
|
|
|
|
|
public int RelearnMove2 { get => BitConverter.ToUInt16(Data, 0xDA); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xDA); }
|
|
|
|
|
public int RelearnMove3 { get => BitConverter.ToUInt16(Data, 0xDC); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xDC); }
|
|
|
|
|
public int RelearnMove4 { get => BitConverter.ToUInt16(Data, 0xDE); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xDE); }
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int OT_Intensity { get => Data[0xE0]; set => Data[0xE0] = (byte)value; }
|
|
|
|
|
public int OT_Memory { get => Data[0xE1]; set => Data[0xE1] = (byte)value; }
|
|
|
|
|
public int OT_TextVar { get => BitConverter.ToUInt16(Data, 0xE2); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xE2); }
|
|
|
|
|
public int OT_Feeling { get => Data[0xE4]; set => Data[0xE4] = (byte)value; }
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int EV_HP { get => Data[0xE5]; set => Data[0xE5] = (byte)value; }
|
|
|
|
|
public int EV_ATK { get => Data[0xE6]; set => Data[0xE6] = (byte)value; }
|
|
|
|
|
public int EV_DEF { get => Data[0xE7]; set => Data[0xE7] = (byte)value; }
|
|
|
|
|
public int EV_SPE { get => Data[0xE8]; set => Data[0xE8] = (byte)value; }
|
|
|
|
|
public int EV_SPA { get => Data[0xE9]; set => Data[0xE9] = (byte)value; }
|
|
|
|
|
public int EV_SPD { get => Data[0xEA]; set => Data[0xEA] = (byte)value; }
|
2017-01-06 02:33:11 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private byte RIB0 { get => Data[0x74]; set => Data[0x74] = value; }
|
|
|
|
|
private byte RIB1 { get => Data[0x75]; set => Data[0x75] = value; }
|
2018-08-10 04:53:39 +00:00
|
|
|
|
public bool RibbonChampionBattle { get => (RIB0 & (1 << 0)) == 1 << 0; set => RIB0 = (byte)((RIB0 & ~(1 << 0)) | (value ? 1 << 0 : 0)); }
|
|
|
|
|
public bool RibbonChampionRegional { get => (RIB0 & (1 << 1)) == 1 << 1; set => RIB0 = (byte)((RIB0 & ~(1 << 1)) | (value ? 1 << 1 : 0)); }
|
|
|
|
|
public bool RibbonChampionNational { get => (RIB0 & (1 << 2)) == 1 << 2; set => RIB0 = (byte)((RIB0 & ~(1 << 2)) | (value ? 1 << 2 : 0)); }
|
|
|
|
|
public bool RibbonCountry { get => (RIB0 & (1 << 3)) == 1 << 3; set => RIB0 = (byte)((RIB0 & ~(1 << 3)) | (value ? 1 << 3 : 0)); }
|
|
|
|
|
public bool RibbonNational { get => (RIB0 & (1 << 4)) == 1 << 4; set => RIB0 = (byte)((RIB0 & ~(1 << 4)) | (value ? 1 << 4 : 0)); }
|
|
|
|
|
public bool RibbonEarth { get => (RIB0 & (1 << 5)) == 1 << 5; set => RIB0 = (byte)((RIB0 & ~(1 << 5)) | (value ? 1 << 5 : 0)); }
|
|
|
|
|
public bool RibbonWorld { get => (RIB0 & (1 << 6)) == 1 << 6; set => RIB0 = (byte)((RIB0 & ~(1 << 6)) | (value ? 1 << 6 : 0)); }
|
|
|
|
|
public bool RibbonEvent { get => (RIB0 & (1 << 7)) == 1 << 7; set => RIB0 = (byte)((RIB0 & ~(1 << 7)) | (value ? 1 << 7 : 0)); }
|
|
|
|
|
public bool RibbonChampionWorld { get => (RIB1 & (1 << 0)) == 1 << 0; set => RIB1 = (byte)((RIB1 & ~(1 << 0)) | (value ? 1 << 0 : 0)); }
|
|
|
|
|
public bool RibbonBirthday { get => (RIB1 & (1 << 1)) == 1 << 1; set => RIB1 = (byte)((RIB1 & ~(1 << 1)) | (value ? 1 << 1 : 0)); }
|
|
|
|
|
public bool RibbonSpecial { get => (RIB1 & (1 << 2)) == 1 << 2; set => RIB1 = (byte)((RIB1 & ~(1 << 2)) | (value ? 1 << 2 : 0)); }
|
|
|
|
|
public bool RibbonSouvenir { get => (RIB1 & (1 << 3)) == 1 << 3; set => RIB1 = (byte)((RIB1 & ~(1 << 3)) | (value ? 1 << 3 : 0)); }
|
|
|
|
|
public bool RibbonWishing { get => (RIB1 & (1 << 4)) == 1 << 4; set => RIB1 = (byte)((RIB1 & ~(1 << 4)) | (value ? 1 << 4 : 0)); }
|
|
|
|
|
public bool RibbonClassic { get => (RIB1 & (1 << 5)) == 1 << 5; set => RIB1 = (byte)((RIB1 & ~(1 << 5)) | (value ? 1 << 5 : 0)); }
|
|
|
|
|
public bool RibbonPremier { 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)); }
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
|
|
|
|
// Meta Accessible Properties
|
2018-06-30 22:01:16 +00:00
|
|
|
|
public override int[] IVs
|
2017-01-06 02:33:11 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => new[] { IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_SPD };
|
2017-01-06 02:33:11 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
if (value.Length != 6) return;
|
2017-01-06 02:33:11 +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
|
|
|
|
|
2017-01-06 02:33:11 +00:00
|
|
|
|
public int[] EVs
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => new[] { EV_HP, EV_ATK, EV_DEF, EV_SPE, EV_SPA, EV_SPD };
|
2017-01-06 02:33:11 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
if (value.Length != 6) return;
|
2017-01-06 02:33:11 +00:00
|
|
|
|
EV_HP = value[0]; EV_ATK = value[1]; EV_DEF = value[2];
|
|
|
|
|
EV_SPE = value[3]; EV_SPA = value[4]; EV_SPD = value[5];
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
2017-03-29 07:48:32 +00:00
|
|
|
|
public bool IsNicknamed => Nickname.Length > 0 || IsEgg;
|
2018-01-02 20:00:41 +00:00
|
|
|
|
public override int Location { get => MetLocation; set => MetLocation = (ushort)value; }
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
2020-01-19 00:46:38 +00:00
|
|
|
|
public override IReadOnlyList<int> Moves
|
2016-11-13 21:11:53 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => new[] { Move1, Move2, Move3, Move4 };
|
2017-01-05 06:25:45 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-01-19 00:46:38 +00:00
|
|
|
|
if (value.Count > 0) Move1 = value[0];
|
|
|
|
|
if (value.Count > 1) Move2 = value[1];
|
|
|
|
|
if (value.Count > 2) Move3 = value[2];
|
|
|
|
|
if (value.Count > 3) Move4 = value[3];
|
2017-01-05 06:25:45 +00:00
|
|
|
|
}
|
2016-11-13 21:11:53 +00:00
|
|
|
|
}
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
2020-01-19 00:46:38 +00:00
|
|
|
|
public override IReadOnlyList<int> Relearn
|
2016-11-13 21:11:53 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => new[] { RelearnMove1, RelearnMove2, RelearnMove3, RelearnMove4 };
|
2016-11-13 21:11:53 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-01-19 00:46:38 +00:00
|
|
|
|
if (value.Count > 0) RelearnMove1 = value[0];
|
|
|
|
|
if (value.Count > 1) RelearnMove2 = value[1];
|
|
|
|
|
if (value.Count > 2) RelearnMove3 = value[2];
|
|
|
|
|
if (value.Count > 3) RelearnMove4 = value[3];
|
2016-11-13 21:11:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
2016-11-13 21:11:53 +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));
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
2020-01-26 05:49:52 +00:00
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
|
|
|
|
|
|
int currentLevel = Level > 0 ? Level : rnd.Next(1, 101);
|
2016-11-13 23:40:34 +00:00
|
|
|
|
int metLevel = MetLevel > 0 ? MetLevel : currentLevel;
|
2017-09-19 05:36:06 +00:00
|
|
|
|
var pi = PersonalTable.USUM.GetFormeEntry(Species, Form);
|
2016-11-13 23:40:34 +00:00
|
|
|
|
PK7 pk = new PK7
|
2016-11-13 21:11:53 +00:00
|
|
|
|
{
|
|
|
|
|
Species = Species,
|
|
|
|
|
HeldItem = HeldItem,
|
|
|
|
|
TID = TID,
|
|
|
|
|
SID = SID,
|
2016-11-13 23:40:34 +00:00
|
|
|
|
Met_Level = metLevel,
|
2016-11-13 21:11:53 +00:00
|
|
|
|
AltForm = Form,
|
2017-06-18 01:37:19 +00:00
|
|
|
|
EncryptionConstant = EncryptionConstant != 0 ? EncryptionConstant : Util.Rand32(),
|
2017-02-15 00:28:10 +00:00
|
|
|
|
Version = OriginGame != 0 ? OriginGame : SAV.Game,
|
|
|
|
|
Language = Language != 0 ? Language : SAV.Language,
|
2016-11-13 21:11:53 +00:00
|
|
|
|
Ball = Ball,
|
|
|
|
|
Country = SAV.Country,
|
|
|
|
|
Region = SAV.SubRegion,
|
|
|
|
|
ConsoleRegion = SAV.ConsoleRegion,
|
|
|
|
|
Move1 = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4,
|
|
|
|
|
RelearnMove1 = RelearnMove1, RelearnMove2 = RelearnMove2,
|
|
|
|
|
RelearnMove3 = RelearnMove3, RelearnMove4 = RelearnMove4,
|
|
|
|
|
Met_Location = MetLocation,
|
|
|
|
|
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,
|
|
|
|
|
|
2017-11-18 19:34:23 +00:00
|
|
|
|
OT_Name = OT_Name.Length > 0 ? OT_Name : SAV.OT,
|
2016-11-13 21:11:53 +00:00
|
|
|
|
OT_Gender = OTGender != 3 ? OTGender % 2 : SAV.Gender,
|
2019-02-08 05:40:20 +00:00
|
|
|
|
HT_Name = OT_Name.Length > 0 ? SAV.OT : string.Empty,
|
2017-11-18 19:34:23 +00:00
|
|
|
|
HT_Gender = OT_Name.Length > 0 ? SAV.Gender : 0,
|
|
|
|
|
CurrentHandler = OT_Name.Length > 0 ? 1 : 0,
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
EXP = Experience.GetEXP(currentLevel, pi.EXPGrowth),
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
|
|
|
|
// Ribbons
|
|
|
|
|
RibbonCountry = RibbonCountry,
|
|
|
|
|
RibbonNational = RibbonNational,
|
|
|
|
|
|
|
|
|
|
RibbonEarth = RibbonEarth,
|
|
|
|
|
RibbonWorld = RibbonWorld,
|
|
|
|
|
RibbonClassic = RibbonClassic,
|
|
|
|
|
RibbonPremier = RibbonPremier,
|
|
|
|
|
RibbonEvent = RibbonEvent,
|
|
|
|
|
RibbonBirthday = RibbonBirthday,
|
|
|
|
|
RibbonSpecial = RibbonSpecial,
|
|
|
|
|
RibbonSouvenir = RibbonSouvenir,
|
|
|
|
|
|
|
|
|
|
RibbonWishing = RibbonWishing,
|
|
|
|
|
RibbonChampionBattle = RibbonChampionBattle,
|
|
|
|
|
RibbonChampionRegional = RibbonChampionRegional,
|
|
|
|
|
RibbonChampionNational = RibbonChampionNational,
|
|
|
|
|
RibbonChampionWorld = RibbonChampionWorld,
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-02-15 00:28:10 +00:00
|
|
|
|
OT_Friendship = pi.BaseFriendship,
|
2016-11-13 21:11:53 +00:00
|
|
|
|
OT_Intensity = OT_Intensity,
|
|
|
|
|
OT_Memory = OT_Memory,
|
|
|
|
|
OT_TextVar = OT_TextVar,
|
|
|
|
|
OT_Feeling = OT_Feeling,
|
|
|
|
|
FatefulEncounter = true,
|
2017-01-06 02:33:11 +00:00
|
|
|
|
|
|
|
|
|
EVs = EVs,
|
2016-11-13 21:11:53 +00:00
|
|
|
|
};
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.SetMaximumPPCurrent();
|
2018-03-29 00:46:37 +00:00
|
|
|
|
|
2018-07-29 18:34:27 +00:00
|
|
|
|
if ((SAV.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version))
|
2018-07-28 05:26:27 +00:00
|
|
|
|
{
|
2018-07-29 18:34:27 +00:00
|
|
|
|
// give random valid game
|
2020-01-26 05:49:52 +00:00
|
|
|
|
do { pk.Version = (int)GameVersion.SN + rnd.Next(4); }
|
2018-07-28 05:26:27 +00:00
|
|
|
|
while (!CanBeReceivedByVersion(pk.Version));
|
|
|
|
|
}
|
2018-03-29 00:46:37 +00:00
|
|
|
|
|
2016-11-17 17:12:17 +00:00
|
|
|
|
if (OTGender == 3)
|
2016-11-13 21:11:53 +00:00
|
|
|
|
{
|
2016-11-17 17:12:17 +00:00
|
|
|
|
pk.TID = SAV.TID;
|
|
|
|
|
pk.SID = SAV.SID;
|
2016-11-13 21:11:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 17:12:17 +00:00
|
|
|
|
pk.MetDate = Date ?? DateTime.Now;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-11-13 21:11:53 +00:00
|
|
|
|
pk.IsNicknamed = IsNicknamed;
|
2019-09-19 02:58:23 +00:00
|
|
|
|
pk.Nickname = IsNicknamed ? Nickname : SpeciesName.GetSpeciesNameGeneration(Species, pk.Language, Format);
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
SetPINGA(pk, criteria);
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
if (IsEgg)
|
|
|
|
|
SetEggMetData(pk);
|
|
|
|
|
pk.CurrentFriendship = pk.IsEgg ? pi.HatchCycles : pi.BaseFriendship;
|
|
|
|
|
|
|
|
|
|
pk.RefreshChecksum();
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetEggMetData(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
pk.IsEgg = true;
|
|
|
|
|
pk.EggMetDate = Date;
|
2019-09-19 02:58:23 +00:00
|
|
|
|
pk.Nickname = SpeciesName.GetSpeciesNameGeneration(0, pk.Language, Format);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.IsNicknamed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetPINGA(PKM pk, EncounterCriteria criteria)
|
|
|
|
|
{
|
|
|
|
|
var pi = PersonalTable.USUM.GetFormeEntry(Species, Form);
|
|
|
|
|
pk.Nature = (int)criteria.GetNature((Nature)Nature);
|
|
|
|
|
pk.Gender = criteria.GetGender(Gender, pi);
|
|
|
|
|
var av = GetAbilityIndex(criteria, pi);
|
|
|
|
|
pk.RefreshAbility(av);
|
|
|
|
|
SetPID(pk);
|
|
|
|
|
SetIVs(pk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int GetAbilityIndex(EncounterCriteria criteria, PersonalInfo pi)
|
|
|
|
|
{
|
2016-11-13 21:11:53 +00:00
|
|
|
|
switch (AbilityType)
|
|
|
|
|
{
|
|
|
|
|
case 00: // 0 - 0
|
|
|
|
|
case 01: // 1 - 1
|
|
|
|
|
case 02: // 2 - H
|
2019-02-09 19:37:20 +00:00
|
|
|
|
return AbilityType;
|
2016-11-13 21:11:53 +00:00
|
|
|
|
case 03: // 0/1
|
|
|
|
|
case 04: // 0/1/H
|
2019-02-09 19:37:20 +00:00
|
|
|
|
return criteria.GetAbility(AbilityType, pi); // 3 or 2
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentException(nameof(AbilityType));
|
2016-11-13 21:11:53 +00:00
|
|
|
|
}
|
2019-02-09 19:37:20 +00:00
|
|
|
|
}
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
private void SetPID(PKM pk)
|
|
|
|
|
{
|
2016-11-13 21:11:53 +00:00
|
|
|
|
switch (PIDType)
|
|
|
|
|
{
|
2018-03-17 02:35:55 +00:00
|
|
|
|
case Shiny.FixedValue: // Specified
|
2016-11-13 21:11:53 +00:00
|
|
|
|
pk.PID = PID;
|
|
|
|
|
break;
|
2018-03-17 02:35:55 +00:00
|
|
|
|
case Shiny.Random: // Random
|
2017-06-18 01:37:19 +00:00
|
|
|
|
pk.PID = Util.Rand32();
|
2016-11-13 21:11:53 +00:00
|
|
|
|
break;
|
2018-03-17 02:35:55 +00:00
|
|
|
|
case Shiny.Always: // Random Shiny
|
2017-06-18 01:37:19 +00:00
|
|
|
|
pk.PID = Util.Rand32();
|
2018-04-07 18:40:01 +00:00
|
|
|
|
pk.PID = (uint)(((pk.TID ^ pk.SID ^ (pk.PID & 0xFFFF)) << 16) | (pk.PID & 0xFFFF));
|
2016-11-13 21:11:53 +00:00
|
|
|
|
break;
|
2018-03-17 02:35:55 +00:00
|
|
|
|
case Shiny.Never: // Random Nonshiny
|
2017-06-18 01:37:19 +00:00
|
|
|
|
pk.PID = Util.Rand32();
|
2018-04-07 18:40:01 +00:00
|
|
|
|
if (pk.IsShiny) pk.PID ^= 0x10000000;
|
2016-11-13 21:11:53 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2019-02-09 19:37:20 +00:00
|
|
|
|
}
|
2016-11-13 21:11:53 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
private void SetIVs(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
int[] finalIVs = new int[6];
|
|
|
|
|
var ivflag = Array.Find(IVs, iv => (byte)(iv - 0xFC) < 3);
|
2020-01-26 05:49:52 +00:00
|
|
|
|
var rng = Util.Rand;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
if (ivflag == 0) // Random IVs
|
2016-11-13 21:11:53 +00:00
|
|
|
|
{
|
2019-02-09 19:37:20 +00:00
|
|
|
|
for (int i = 0; i < 6; i++)
|
2020-01-26 05:49:52 +00:00
|
|
|
|
finalIVs[i] = IVs[i] > 31 ? rng.Next(32) : IVs[i];
|
2016-11-13 21:11:53 +00:00
|
|
|
|
}
|
2019-02-09 19:37:20 +00:00
|
|
|
|
else // 1/2/3 perfect IVs
|
|
|
|
|
{
|
|
|
|
|
int IVCount = ivflag - 0xFB;
|
2020-01-26 05:49:52 +00:00
|
|
|
|
do { finalIVs[rng.Next(6)] = 31; }
|
2019-02-09 19:37:20 +00:00
|
|
|
|
while (finalIVs.Count(iv => iv == 31) < IVCount);
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
2020-01-26 05:49:52 +00:00
|
|
|
|
finalIVs[i] = finalIVs[i] == 31 ? 31 : rng.Next(32);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
}
|
|
|
|
|
pk.IVs = finalIVs;
|
2016-11-13 21:11:53 +00:00
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
public bool IsAshGreninjaWC7(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
return CardID == 2046 && (pkm.SID << 16 | pkm.TID) == 0x79F57B49;
|
|
|
|
|
}
|
2018-12-27 09:00:08 +00:00
|
|
|
|
|
2019-12-29 03:00:01 +00:00
|
|
|
|
protected override bool IsMatchExact(PKM pkm)
|
2018-12-27 09:00:08 +00:00
|
|
|
|
{
|
|
|
|
|
if (pkm.Egg_Location == 0) // Not Egg
|
|
|
|
|
{
|
|
|
|
|
if (OTGender != 3)
|
|
|
|
|
{
|
|
|
|
|
if (SID != pkm.SID) return false;
|
|
|
|
|
if (TID != pkm.TID) return false;
|
|
|
|
|
if (OTGender != pkm.OT_Gender) return false;
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(OT_Name) && OT_Name != pkm.OT_Name) return false;
|
|
|
|
|
if (OriginGame != 0 && OriginGame != pkm.Version) return false;
|
|
|
|
|
if (EncryptionConstant != 0 && EncryptionConstant != pkm.EncryptionConstant) return false;
|
|
|
|
|
if (Language != 0 && Language != pkm.Language) return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 03:53:57 +00:00
|
|
|
|
if (Form != pkm.AltForm && !Legal.IsFormChangeable(pkm, Species, Form))
|
2018-12-27 09:00:08 +00:00
|
|
|
|
{
|
2019-12-09 01:39:19 +00:00
|
|
|
|
if (Species == (int)Core.Species.Rockruff && Form == 1 && pkm.Species == 745 && pkm.AltForm == 2)
|
2018-12-27 09:00:08 +00:00
|
|
|
|
{
|
|
|
|
|
// Rockruff gift edge case; has altform 1 then evolves to altform 2
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsEgg)
|
|
|
|
|
{
|
|
|
|
|
if (EggLocation != pkm.Egg_Location) // traded
|
|
|
|
|
{
|
2019-05-11 03:46:49 +00:00
|
|
|
|
if (pkm.Egg_Location != Locations.LinkTrade6)
|
2018-12-27 09:00:08 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (PIDType == 0 && pkm.IsShiny)
|
|
|
|
|
{
|
|
|
|
|
return false; // can't be traded away for unshiny
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pkm.IsEgg && !pkm.IsNative)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!PIDType.IsValid(pkm)) return false;
|
|
|
|
|
if (EggLocation != pkm.Egg_Location) return false;
|
|
|
|
|
if (MetLocation != pkm.Met_Location) return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MetLevel != pkm.Met_Level) return false;
|
|
|
|
|
if (Ball != pkm.Ball) return false;
|
|
|
|
|
if (OTGender < 3 && OTGender != pkm.OT_Gender) 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 != 3 && Gender != pkm.Gender) return false;
|
|
|
|
|
|
|
|
|
|
if (pkm is IContestStats s && s.IsContestBelow(this))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (CardID == 2046) // Greninja WC has variant PID and can arrive @ 36 or 37
|
|
|
|
|
return pkm.SM; // not USUM
|
2019-10-28 03:39:07 +00:00
|
|
|
|
|
|
|
|
|
return PIDType != 0 || pkm.PID == PID;
|
2018-12-27 09:00:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool IsMatchDeferred(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (RestrictLanguage != 0 && RestrictLanguage != pkm.Language)
|
|
|
|
|
return true;
|
|
|
|
|
if (!CanBeReceivedByVersion(pkm.Version))
|
|
|
|
|
return true;
|
|
|
|
|
return Species != pkm.Species;
|
|
|
|
|
}
|
2016-11-13 21:11:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|