2018-11-14 03:10:31 +00:00
|
|
|
|
using System;
|
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
|
|
|
|
using System.Collections.Generic;
|
2019-01-23 05:08:48 +00:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2018-11-14 03:10:31 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2018-12-26 06:56:32 +00:00
|
|
|
|
/// <summary> Generation 7 <see cref="PKM"/> format used for <see cref="GameVersion.GG"/>. </summary>
|
2019-11-29 18:44:52 +00:00
|
|
|
|
public sealed class PB7 : G6PKM, IHyperTrain, IAwakened, IScaledSize, IFavorite, IFormArgument
|
2018-11-14 03:10:31 +00:00
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public static readonly ushort[] Unused =
|
2018-11-14 03:10:31 +00:00
|
|
|
|
{
|
|
|
|
|
0x2A, // Old Marking Value (PelagoEventStatus)
|
2018-12-26 06:56:32 +00:00
|
|
|
|
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, // Unused Ribbons
|
|
|
|
|
0x58, 0x59, // Nickname Terminator
|
|
|
|
|
0x73,
|
|
|
|
|
0x90, 0x91, // HT Terminator
|
|
|
|
|
0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, // Old Geolocation/memories
|
|
|
|
|
0xA7, 0xAA, 0xAB,
|
|
|
|
|
0xAC, 0xAD, // Fatigue, no GUI editing
|
|
|
|
|
0xC8, 0xC9, // OT Terminator
|
2018-11-14 03:10:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public override IReadOnlyList<ushort> ExtraBytes => Unused;
|
2018-12-20 06:10:32 +00:00
|
|
|
|
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public override int SIZE_PARTY => SIZE;
|
|
|
|
|
public override int SIZE_STORED => SIZE;
|
|
|
|
|
private const int SIZE = 260;
|
|
|
|
|
public override int Format => 7;
|
2020-12-11 04:42:30 +00:00
|
|
|
|
public override PersonalInfo PersonalInfo => PersonalTable.GG.GetFormEntry(Species, Form);
|
2018-11-21 22:15:48 +00:00
|
|
|
|
|
2020-09-26 19:09:02 +00:00
|
|
|
|
public PB7() : base(SIZE) { }
|
|
|
|
|
public PB7(byte[] data) : base(DecryptParty(data)) { }
|
|
|
|
|
|
|
|
|
|
private static byte[] DecryptParty(byte[] data)
|
2018-11-14 03:10:31 +00:00
|
|
|
|
{
|
2020-01-04 22:48:39 +00:00
|
|
|
|
PokeCrypto.DecryptIfEncrypted67(ref data);
|
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 (data.Length != SIZE)
|
|
|
|
|
Array.Resize(ref data, SIZE);
|
2020-09-26 19:09:02 +00:00
|
|
|
|
return data;
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
public override PKM Clone() => new PB7((byte[])Data.Clone());
|
2018-11-14 03:10:31 +00:00
|
|
|
|
|
|
|
|
|
// Structure
|
|
|
|
|
#region Block A
|
|
|
|
|
public override uint EncryptionConstant
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt32LittleEndian(Data.AsSpan(0x00));
|
|
|
|
|
set => WriteUInt32LittleEndian(Data.AsSpan(0x00), value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ushort Sanity
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x04));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x04), value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ushort Checksum
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x06));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x06), value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Species
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x08));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x08), (ushort)value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int HeldItem
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x0A));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x0A), (ushort)value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int TID
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x0C));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x0C), (ushort)value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int SID
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x0E));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x0E), (ushort)value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override uint EXP
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt32LittleEndian(Data.AsSpan(0x10));
|
|
|
|
|
set => WriteUInt32LittleEndian(Data.AsSpan(0x10), value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Ability { get => Data[0x14]; set => Data[0x14] = (byte)value; }
|
|
|
|
|
public override int AbilityNumber { get => Data[0x15] & 7; set => Data[0x15] = (byte)((Data[0x15] & ~7) | (value & 7)); }
|
|
|
|
|
public bool Favorite { get => (Data[0x15] & 8) != 0; set => Data[0x15] = (byte)((Data[0x15] & ~8) | ((value ? 1 : 0) << 3)); }
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override int MarkValue { get => ReadUInt16LittleEndian(Data.AsSpan(0x16)); protected set => WriteUInt16LittleEndian(Data.AsSpan(0x16), (ushort)value); }
|
2018-11-14 03:10:31 +00:00
|
|
|
|
|
|
|
|
|
public override uint PID
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt32LittleEndian(Data.AsSpan(0x18));
|
|
|
|
|
set => WriteUInt32LittleEndian(Data.AsSpan(0x18), value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Nature { get => Data[0x1C]; set => Data[0x1C] = (byte)value; }
|
|
|
|
|
public override bool FatefulEncounter { get => (Data[0x1D] & 1) == 1; set => Data[0x1D] = (byte)((Data[0x1D] & ~0x01) | (value ? 1 : 0)); }
|
|
|
|
|
public override int Gender { get => (Data[0x1D] >> 1) & 0x3; set => Data[0x1D] = (byte)((Data[0x1D] & ~0x06) | (value << 1)); }
|
2020-12-11 04:42:30 +00:00
|
|
|
|
public override int Form { get => Data[0x1D] >> 3; set => Data[0x1D] = (byte)((Data[0x1D] & 0x07) | (value << 3)); }
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public override int EV_HP { get => Data[0x1E]; set => Data[0x1E] = (byte)value; }
|
|
|
|
|
public override int EV_ATK { get => Data[0x1F]; set => Data[0x1F] = (byte)value; }
|
|
|
|
|
public override int EV_DEF { get => Data[0x20]; set => Data[0x20] = (byte)value; }
|
|
|
|
|
public override int EV_SPE { get => Data[0x21]; set => Data[0x21] = (byte)value; }
|
|
|
|
|
public override int EV_SPA { get => Data[0x22]; set => Data[0x22] = (byte)value; }
|
|
|
|
|
public override int EV_SPD { get => Data[0x23]; set => Data[0x23] = (byte)value; }
|
|
|
|
|
public int AV_HP { get => Data[0x24]; set => Data[0x24] = (byte)value; }
|
|
|
|
|
public int AV_ATK { get => Data[0x25]; set => Data[0x25] = (byte)value; }
|
|
|
|
|
public int AV_DEF { get => Data[0x26]; set => Data[0x26] = (byte)value; }
|
|
|
|
|
public int AV_SPE { get => Data[0x27]; set => Data[0x27] = (byte)value; }
|
|
|
|
|
public int AV_SPA { get => Data[0x28]; set => Data[0x28] = (byte)value; }
|
|
|
|
|
public int AV_SPD { get => Data[0x29]; set => Data[0x29] = (byte)value; }
|
2020-05-26 23:59:47 +00:00
|
|
|
|
// 0x2A Unused
|
2018-11-14 03:10:31 +00:00
|
|
|
|
private byte PKRS { get => Data[0x2B]; set => Data[0x2B] = value; }
|
|
|
|
|
public override int PKRS_Days { get => PKRS & 0xF; set => PKRS = (byte)((PKRS & ~0xF) | value); }
|
|
|
|
|
public override int PKRS_Strain { get => PKRS >> 4; set => PKRS = (byte)((PKRS & 0xF) | value << 4); }
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public float HeightAbsolute { get => ReadSingleLittleEndian(Data.AsSpan(0x2C)); set => WriteSingleLittleEndian(Data.AsSpan(0x2C), value); }
|
2020-05-26 23:59:47 +00:00
|
|
|
|
// 0x38 Unused
|
|
|
|
|
// 0x39 Unused
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public int HeightScalar { get => Data[0x3A]; set => Data[0x3A] = (byte)value; }
|
|
|
|
|
public int WeightScalar { get => Data[0x3B]; set => Data[0x3B] = (byte)value; }
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public uint FormArgument { get => ReadUInt32LittleEndian(Data.AsSpan(0x3C)); set => WriteUInt32LittleEndian(Data.AsSpan(0x3C), value); }
|
2021-02-09 04:26:53 +00:00
|
|
|
|
public byte FormArgumentRemain { get => (byte)FormArgument; set => FormArgument = (FormArgument & ~0xFFu) | value; }
|
|
|
|
|
public byte FormArgumentElapsed { get => (byte)(FormArgument >> 8); set => FormArgument = (FormArgument & ~0xFF00u) | (uint)(value << 8); }
|
|
|
|
|
public byte FormArgumentMaximum { get => (byte)(FormArgument >> 16); set => FormArgument = (FormArgument & ~0xFF0000u) | (uint)(value << 16); }
|
|
|
|
|
|
2018-11-14 03:10:31 +00:00
|
|
|
|
#endregion
|
|
|
|
|
#region Block B
|
|
|
|
|
public override string Nickname
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => StringConverter8.GetString(Nickname_Trash);
|
|
|
|
|
set => StringConverter8.SetString(Nickname_Trash, value.AsSpan(), 12, StringConverterOption.None);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Move1
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x5A));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x5A), (ushort)value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Move2
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x5C));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x5C), (ushort)value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Move3
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x5E));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x5E), (ushort)value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Move4
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x60));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x60), (ushort)value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Move1_PP { get => Data[0x62]; set => Data[0x62] = (byte)value; }
|
|
|
|
|
public override int Move2_PP { get => Data[0x63]; set => Data[0x63] = (byte)value; }
|
|
|
|
|
public override int Move3_PP { get => Data[0x64]; set => Data[0x64] = (byte)value; }
|
|
|
|
|
public override int Move4_PP { get => Data[0x65]; set => Data[0x65] = (byte)value; }
|
|
|
|
|
public override int Move1_PPUps { get => Data[0x66]; set => Data[0x66] = (byte)value; }
|
|
|
|
|
public override int Move2_PPUps { get => Data[0x67]; set => Data[0x67] = (byte)value; }
|
|
|
|
|
public override int Move3_PPUps { get => Data[0x68]; set => Data[0x68] = (byte)value; }
|
|
|
|
|
public override int Move4_PPUps { get => Data[0x69]; set => Data[0x69] = (byte)value; }
|
|
|
|
|
|
|
|
|
|
public override int RelearnMove1
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x6A));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x6A), (ushort)value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int RelearnMove2
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x6C));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x6C), (ushort)value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int RelearnMove3
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x6E));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x6E), (ushort)value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int RelearnMove4
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(0x70));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(0x70), (ushort)value);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-26 23:59:47 +00:00
|
|
|
|
// 0x72 Unused
|
|
|
|
|
// 0x73 Unused
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private uint IV32 { get => ReadUInt32LittleEndian(Data.AsSpan(0x74)); set => WriteUInt32LittleEndian(Data.AsSpan(0x74), value); }
|
2019-02-23 23:36:26 +00:00
|
|
|
|
public override int IV_HP { get => (int)(IV32 >> 00) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 00)) | ((value > 31 ? 31u : (uint)value) << 00); }
|
|
|
|
|
public override int IV_ATK { get => (int)(IV32 >> 05) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 05)) | ((value > 31 ? 31u : (uint)value) << 05); }
|
|
|
|
|
public override int IV_DEF { get => (int)(IV32 >> 10) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 10)) | ((value > 31 ? 31u : (uint)value) << 10); }
|
|
|
|
|
public override int IV_SPE { get => (int)(IV32 >> 15) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 15)) | ((value > 31 ? 31u : (uint)value) << 15); }
|
|
|
|
|
public override int IV_SPA { get => (int)(IV32 >> 20) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 20)) | ((value > 31 ? 31u : (uint)value) << 20); }
|
|
|
|
|
public override int IV_SPD { get => (int)(IV32 >> 25) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 25)) | ((value > 31 ? 31u : (uint)value) << 25); }
|
|
|
|
|
public override bool IsEgg { get => ((IV32 >> 30) & 1) == 1; set => IV32 = (IV32 & ~0x40000000u) | (value ? 0x40000000u : 0u); }
|
|
|
|
|
public override bool IsNicknamed { get => ((IV32 >> 31) & 1) == 1; set => IV32 = (IV32 & 0x7FFFFFFFu) | (value ? 0x80000000u : 0u); }
|
2018-11-14 03:10:31 +00:00
|
|
|
|
#endregion
|
|
|
|
|
#region Block C
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override string HT_Name
|
|
|
|
|
{
|
|
|
|
|
get => StringConverter8.GetString(HT_Trash);
|
|
|
|
|
set => StringConverter8.SetString(HT_Trash, value.AsSpan(), 12, StringConverterOption.None);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public override int HT_Gender { get => Data[0x92]; set => Data[0x92] = (byte)value; }
|
|
|
|
|
public override int CurrentHandler { get => Data[0x93]; set => Data[0x93] = (byte)value; }
|
2020-05-26 23:59:47 +00:00
|
|
|
|
// 0x94 Unused
|
|
|
|
|
// 0x95 Unused
|
|
|
|
|
// 0x96 Unused
|
|
|
|
|
// 0x97 Unused
|
|
|
|
|
// 0x98 Unused
|
|
|
|
|
// 0x99 Unused
|
|
|
|
|
// 0x9A Unused
|
|
|
|
|
// 0x9B Unused
|
|
|
|
|
// 0x9C Unused
|
|
|
|
|
// 0x9D Unused
|
|
|
|
|
// 0x9E Unused
|
|
|
|
|
// 0x9F Unused
|
|
|
|
|
// 0xA0 Unused
|
|
|
|
|
// 0xA1 Unused
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public override int HT_Friendship { get => Data[0xA2]; set => Data[0xA2] = (byte)value; }
|
2020-08-02 18:06:30 +00:00
|
|
|
|
// 0xA1 HT_Affection Unused
|
2020-08-01 00:25:14 +00:00
|
|
|
|
public int HT_Intensity { get => Data[0xA4]; set => Data[0xA4] = (byte)value; }
|
|
|
|
|
public int HT_Memory { get => Data[0xA5]; set => Data[0xA5] = (byte)value; }
|
|
|
|
|
public int HT_Feeling { get => Data[0xA6]; set => Data[0xA6] = (byte)value; }
|
2020-05-26 23:59:47 +00:00
|
|
|
|
// 0xA7 Unused
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public int HT_TextVar { get => ReadUInt16LittleEndian(Data.AsSpan(0xA8)); set => WriteUInt16LittleEndian(Data.AsSpan(0xA8), (ushort)value); }
|
2020-05-26 23:59:47 +00:00
|
|
|
|
// 0xAA Unused
|
|
|
|
|
// 0xAB Unused
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public byte FieldEventFatigue1 { get => Data[0xAC]; set => Data[0xAC] = value; }
|
|
|
|
|
public byte FieldEventFatigue2 { get => Data[0xAD]; set => Data[0xAD] = value; }
|
|
|
|
|
public override byte Fullness { get => Data[0xAE]; set => Data[0xAE] = value; }
|
|
|
|
|
public override byte Enjoyment { get => Data[0xAF]; set => Data[0xAF] = value; }
|
|
|
|
|
#endregion
|
|
|
|
|
#region Block D
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override string OT_Name
|
|
|
|
|
{
|
|
|
|
|
get => StringConverter8.GetString(OT_Trash);
|
|
|
|
|
set => StringConverter8.SetString(OT_Trash, value.AsSpan(), 12, StringConverterOption.None);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public override int OT_Friendship { get => Data[0xCA]; set => Data[0xCA] = (byte)value; }
|
2020-05-26 23:59:47 +00:00
|
|
|
|
// 0xCB Unused
|
|
|
|
|
// 0xCC Unused
|
|
|
|
|
// 0xCD Unused
|
|
|
|
|
// 0xCE Unused
|
|
|
|
|
// 0xCF Unused
|
|
|
|
|
// 0xD0 Unused
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public override int Egg_Year { get => Data[0xD1]; set => Data[0xD1] = (byte)value; }
|
|
|
|
|
public override int Egg_Month { get => Data[0xD2]; set => Data[0xD2] = (byte)value; }
|
|
|
|
|
public override int Egg_Day { get => Data[0xD3]; set => Data[0xD3] = (byte)value; }
|
|
|
|
|
public override int Met_Year { get => Data[0xD4]; set => Data[0xD4] = (byte)value; }
|
|
|
|
|
public override int Met_Month { get => Data[0xD5]; set => Data[0xD5] = (byte)value; }
|
|
|
|
|
public override int Met_Day { get => Data[0xD6]; set => Data[0xD6] = (byte)value; }
|
2018-12-07 06:58:35 +00:00
|
|
|
|
public int Rank { get => Data[0xD7]; set => Data[0xD7] = (byte)value; } // unused but fetched for stat calcs, and set for trpoke data?
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override int Egg_Location { get => ReadUInt16LittleEndian(Data.AsSpan(0xD8)); set => WriteUInt16LittleEndian(Data.AsSpan(0xD8), (ushort)value); }
|
|
|
|
|
public override int Met_Location { get => ReadUInt16LittleEndian(Data.AsSpan(0xDA)); set => WriteUInt16LittleEndian(Data.AsSpan(0xDA), (ushort)value); }
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public override int Ball { get => Data[0xDC]; set => Data[0xDC] = (byte)value; }
|
|
|
|
|
public override int Met_Level { get => Data[0xDD] & ~0x80; set => Data[0xDD] = (byte)((Data[0xDD] & 0x80) | value); }
|
|
|
|
|
public override int OT_Gender { get => Data[0xDD] >> 7; set => Data[0xDD] = (byte)((Data[0xDD] & ~0x80) | (value << 7)); }
|
|
|
|
|
public int HyperTrainFlags { get => Data[0xDE]; set => Data[0xDE] = (byte)value; }
|
2019-02-23 23:36:26 +00:00
|
|
|
|
public bool HT_HP { get => ((HyperTrainFlags >> 0) & 1) == 1; set => HyperTrainFlags = (HyperTrainFlags & ~(1 << 0)) | ((value ? 1 : 0) << 0); }
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public bool HT_ATK { get => ((HyperTrainFlags >> 1) & 1) == 1; set => HyperTrainFlags = (HyperTrainFlags & ~(1 << 1)) | ((value ? 1 : 0) << 1); }
|
|
|
|
|
public bool HT_DEF { get => ((HyperTrainFlags >> 2) & 1) == 1; set => HyperTrainFlags = (HyperTrainFlags & ~(1 << 2)) | ((value ? 1 : 0) << 2); }
|
|
|
|
|
public bool HT_SPA { get => ((HyperTrainFlags >> 3) & 1) == 1; set => HyperTrainFlags = (HyperTrainFlags & ~(1 << 3)) | ((value ? 1 : 0) << 3); }
|
|
|
|
|
public bool HT_SPD { get => ((HyperTrainFlags >> 4) & 1) == 1; set => HyperTrainFlags = (HyperTrainFlags & ~(1 << 4)) | ((value ? 1 : 0) << 4); }
|
|
|
|
|
public bool HT_SPE { get => ((HyperTrainFlags >> 5) & 1) == 1; set => HyperTrainFlags = (HyperTrainFlags & ~(1 << 5)) | ((value ? 1 : 0) << 5); }
|
|
|
|
|
public override int Version { get => Data[0xDF]; set => Data[0xDF] = (byte)value; }
|
2020-05-26 23:59:47 +00:00
|
|
|
|
// 0xE0 Unused
|
|
|
|
|
// 0xE1 Unused
|
|
|
|
|
// 0xE2 Unused
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public override int Language { get => Data[0xE3]; set => Data[0xE3] = (byte)value; }
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public float WeightAbsolute { get => ReadSingleLittleEndian(Data.AsSpan(0xE4)); set => WriteSingleLittleEndian(Data.AsSpan(0xE4), value); }
|
2018-11-14 03:10:31 +00:00
|
|
|
|
#endregion
|
|
|
|
|
#region Battle Stats
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override int Status_Condition { get => ReadInt32LittleEndian(Data.AsSpan(0xE8)); set => WriteInt32LittleEndian(Data.AsSpan(0xE8), value); }
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public override int Stat_Level { get => Data[0xEC]; set => Data[0xEC] = (byte)value; }
|
|
|
|
|
public byte DirtType { get => Data[0xED]; set => Data[0xED] = value; }
|
|
|
|
|
public byte DirtLocation { get => Data[0xEE]; set => Data[0xEE] = value; }
|
|
|
|
|
// 0xEF unused
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override int Stat_HPCurrent { get => ReadUInt16LittleEndian(Data.AsSpan(0xF0)); set => WriteUInt16LittleEndian(Data.AsSpan(0xF0), (ushort)value); }
|
|
|
|
|
public override int Stat_HPMax { get => ReadUInt16LittleEndian(Data.AsSpan(0xF2)); set => WriteUInt16LittleEndian(Data.AsSpan(0xF2), (ushort)value); }
|
|
|
|
|
public override int Stat_ATK { get => ReadUInt16LittleEndian(Data.AsSpan(0xF4)); set => WriteUInt16LittleEndian(Data.AsSpan(0xF4), (ushort)value); }
|
|
|
|
|
public override int Stat_DEF { get => ReadUInt16LittleEndian(Data.AsSpan(0xF6)); set => WriteUInt16LittleEndian(Data.AsSpan(0xF6), (ushort)value); }
|
|
|
|
|
public override int Stat_SPE { get => ReadUInt16LittleEndian(Data.AsSpan(0xF8)); set => WriteUInt16LittleEndian(Data.AsSpan(0xF8), (ushort)value); }
|
|
|
|
|
public override int Stat_SPA { get => ReadUInt16LittleEndian(Data.AsSpan(0xFA)); set => WriteUInt16LittleEndian(Data.AsSpan(0xFA), (ushort)value); }
|
|
|
|
|
public override int Stat_SPD { get => ReadUInt16LittleEndian(Data.AsSpan(0xFC)); set => WriteUInt16LittleEndian(Data.AsSpan(0xFC), (ushort)value); }
|
|
|
|
|
public int Stat_CP { get => ReadUInt16LittleEndian(Data.AsSpan(0xFE)); set => WriteUInt16LittleEndian(Data.AsSpan(0xFE), (ushort)value); }
|
2021-03-29 07:14:44 +00:00
|
|
|
|
public bool Stat_Mega { get => Data[0x100] != 0; set => Data[0x100] = value ? (byte)1 : (byte)0; }
|
2018-11-14 03:10:31 +00:00
|
|
|
|
public int Stat_MegaForm { get => Data[0x101]; set => Data[0x101] = (byte)value; }
|
|
|
|
|
// 102/103 unused
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public override int[] Markings
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int[] marks = new int[8];
|
|
|
|
|
int val = MarkValue;
|
|
|
|
|
for (int i = 0; i < marks.Length; i++)
|
|
|
|
|
marks[i] = ((val >> (i * 2)) & 3) % 3;
|
|
|
|
|
return marks;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value.Length > 8)
|
|
|
|
|
return;
|
|
|
|
|
int v = 0;
|
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
|
|
|
|
v |= (value[i] % 3) << (i * 2);
|
|
|
|
|
MarkValue = v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-31 05:05:28 +00:00
|
|
|
|
protected override bool TradeOT(ITrainerInfo tr)
|
2018-11-14 03:10:31 +00:00
|
|
|
|
{
|
|
|
|
|
// Check to see if the OT matches the SAV's OT info.
|
2019-03-31 05:05:28 +00:00
|
|
|
|
if (!(tr.OT == OT_Name && tr.TID == TID && tr.SID == SID && tr.Gender == OT_Gender))
|
2018-11-14 03:10:31 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
CurrentHandler = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-31 05:05:28 +00:00
|
|
|
|
protected override void TradeHT(ITrainerInfo tr)
|
2018-11-14 03:10:31 +00:00
|
|
|
|
{
|
2019-03-31 05:05:28 +00:00
|
|
|
|
if (HT_Name != tr.OT)
|
2018-11-14 03:10:31 +00:00
|
|
|
|
{
|
2019-02-02 18:19:41 +00:00
|
|
|
|
HT_Friendship = CurrentFriendship; // copy friendship instead of resetting (don't alter CP)
|
2019-03-31 05:05:28 +00:00
|
|
|
|
HT_Name = tr.OT;
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
2019-01-09 02:32:42 +00:00
|
|
|
|
CurrentHandler = 1;
|
2019-03-31 05:05:28 +00:00
|
|
|
|
HT_Gender = tr.Gender;
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 06:56:32 +00:00
|
|
|
|
public void FixMemories()
|
|
|
|
|
{
|
|
|
|
|
if (IsUntraded)
|
2020-08-02 18:06:30 +00:00
|
|
|
|
HT_Friendship = HT_TextVar = HT_Memory = HT_Intensity = HT_Feeling = 0;
|
2018-12-26 06:56:32 +00:00
|
|
|
|
}
|
2018-11-14 03:10:31 +00:00
|
|
|
|
|
|
|
|
|
// Maximums
|
|
|
|
|
public override int MaxMoveID => Legal.MaxMoveID_7b;
|
|
|
|
|
public override int MaxSpeciesID => Legal.MaxSpeciesID_7b;
|
|
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_7_USUM;
|
|
|
|
|
public override int MaxItemID => Legal.MaxItemID_7_USUM;
|
|
|
|
|
public override int MaxBallID => Legal.MaxBallID_7;
|
2018-11-20 00:15:09 +00:00
|
|
|
|
public override int MaxGameID => Legal.MaxGameID_7b;
|
2018-11-14 03:10:31 +00:00
|
|
|
|
|
2018-12-04 04:59:48 +00:00
|
|
|
|
public override ushort[] GetStats(PersonalInfo p) => CalculateStatsBeluga(p);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
|
|
|
|
|
public ushort[] CalculateStatsBeluga(PersonalInfo p)
|
|
|
|
|
{
|
|
|
|
|
int level = CurrentLevel;
|
|
|
|
|
int nature = Nature;
|
|
|
|
|
int friend = CurrentFriendship; // stats +10% depending on friendship!
|
|
|
|
|
int scalar = (int)(((friend / 255.0f / 10.0f) + 1.0f) * 100.0f);
|
2019-12-09 01:39:19 +00:00
|
|
|
|
return new[]
|
2018-11-14 03:10:31 +00:00
|
|
|
|
{
|
|
|
|
|
(ushort)(AV_HP + GetStat(p.HP, HT_HP ? 31 : IV_HP, level) + 10 + level),
|
|
|
|
|
(ushort)(AV_ATK + (scalar * GetStat(p.ATK, HT_ATK ? 31 : IV_ATK, level, nature, 0) / 100)),
|
|
|
|
|
(ushort)(AV_DEF + (scalar * GetStat(p.DEF, HT_DEF ? 31 : IV_DEF, level, nature, 1) / 100)),
|
|
|
|
|
(ushort)(AV_SPE + (scalar * GetStat(p.SPE, HT_SPE ? 31 : IV_SPE, level, nature, 4) / 100)),
|
|
|
|
|
(ushort)(AV_SPA + (scalar * GetStat(p.SPA, HT_SPA ? 31 : IV_SPA, level, nature, 2) / 100)),
|
|
|
|
|
(ushort)(AV_SPD + (scalar * GetStat(p.SPD, HT_SPD ? 31 : IV_SPD, level, nature, 3) / 100)),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the initial stat value based on the base stat value, IV, and current level.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="baseStat"><see cref="PersonalInfo"/> stat.</param>
|
|
|
|
|
/// <param name="iv">Current IV, already accounted for Hyper Training</param>
|
|
|
|
|
/// <param name="level">Current Level</param>
|
|
|
|
|
/// <returns>Initial Stat</returns>
|
|
|
|
|
private static int GetStat(int baseStat, int iv, int level) => (iv + (2 * baseStat)) * level / 100;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the initial stat value with nature amplification applied. Used for all stats except HP.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="baseStat"><see cref="PersonalInfo"/> stat.</param>
|
|
|
|
|
/// <param name="iv">Current IV, already accounted for Hyper Training</param>
|
|
|
|
|
/// <param name="level">Current Level</param>
|
|
|
|
|
/// <param name="nature"><see cref="PKM.Nature"/></param>
|
|
|
|
|
/// <param name="statIndex">Stat amp index in the nature amp table</param>
|
|
|
|
|
/// <returns>Initial Stat with nature amplification applied.</returns>
|
|
|
|
|
private static int GetStat(int baseStat, int iv, int level, int nature, int statIndex)
|
|
|
|
|
{
|
|
|
|
|
int initial = GetStat(baseStat, iv, level) + 5;
|
|
|
|
|
return AmplifyStat(nature, statIndex, initial);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 01:08:49 +00:00
|
|
|
|
private static int AmplifyStat(int nature, int index, int initial) => GetNatureAmp(nature, index) switch
|
2018-11-14 03:10:31 +00:00
|
|
|
|
{
|
2021-01-02 01:08:49 +00:00
|
|
|
|
1 => 110 * initial / 100, // 110%
|
|
|
|
|
-1 => 90 * initial / 100, // 90%
|
|
|
|
|
_ => initial,
|
|
|
|
|
};
|
2018-11-14 03:10:31 +00:00
|
|
|
|
|
2018-12-26 06:56:32 +00:00
|
|
|
|
private static sbyte GetNatureAmp(int nature, int index)
|
|
|
|
|
{
|
2019-02-23 23:36:26 +00:00
|
|
|
|
if ((uint)nature >= 25)
|
2018-12-26 06:56:32 +00:00
|
|
|
|
return -1;
|
|
|
|
|
return NatureAmpTable[(5 * nature) + index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static readonly sbyte[] NatureAmpTable =
|
2018-11-14 03:10:31 +00:00
|
|
|
|
{
|
|
|
|
|
0, 0, 0, 0, 0, // Hardy
|
|
|
|
|
1,-1, 0, 0, 0, // Lonely
|
|
|
|
|
1, 0, 0, 0,-1, // Brave
|
|
|
|
|
1, 0,-1, 0, 0, // Adamant
|
|
|
|
|
1, 0, 0,-1, 0, // Naughty
|
|
|
|
|
-1, 1, 0, 0, 0, // Bold
|
|
|
|
|
0, 0, 0, 0, 0, // Docile
|
|
|
|
|
0, 1, 0, 0,-1, // Relaxed
|
|
|
|
|
0, 1,-1, 0, 0, // Impish
|
|
|
|
|
0, 1, 0,-1, 0, // Lax
|
|
|
|
|
-1, 0, 0, 0, 1, // Timid
|
|
|
|
|
0,-1, 0, 0, 1, // Hasty
|
|
|
|
|
0, 0, 0, 0, 0, // Serious
|
|
|
|
|
0, 0,-1, 0, 1, // Jolly
|
|
|
|
|
0, 0, 0,-1, 1, // Naive
|
|
|
|
|
-1, 0, 1, 0, 0, // Modest
|
|
|
|
|
0,-1, 1, 0, 0, // Mild
|
|
|
|
|
0, 0, 1, 0,-1, // Quiet
|
|
|
|
|
0, 0, 0, 0, 0, // Bashful
|
|
|
|
|
0, 0, 1,-1, 0, // Rash
|
|
|
|
|
-1, 0, 0, 1, 0, // Calm
|
|
|
|
|
0,-1, 0, 1, 0, // Gentle
|
|
|
|
|
0, 0, 0, 1,-1, // Sassy
|
|
|
|
|
0, 0,-1, 1, 0, // Careful
|
|
|
|
|
0, 0, 0, 0, 0, // Quirky
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-18 23:32:47 +00:00
|
|
|
|
public int CalcCP => Math.Min(10000, AwakeCP + BaseCP);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
|
|
|
|
|
public int BaseCP
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var p = PersonalInfo;
|
|
|
|
|
int level = CurrentLevel;
|
|
|
|
|
int nature = Nature;
|
2019-01-23 05:08:48 +00:00
|
|
|
|
int scalar = CPScalar;
|
2018-11-14 03:10:31 +00:00
|
|
|
|
|
|
|
|
|
// Calculate stats for all, then sum together.
|
|
|
|
|
// HP is not overriden to 1 like a regular stat calc for Shedinja.
|
|
|
|
|
var statSum =
|
|
|
|
|
(ushort)GetStat(p.HP, HT_HP ? 31 : IV_HP, level) + 10 + level
|
|
|
|
|
+ (ushort)(GetStat(p.ATK, HT_ATK ? 31 : IV_ATK, level, nature, 0) * scalar / 100)
|
|
|
|
|
+ (ushort)(GetStat(p.DEF, HT_DEF ? 31 : IV_DEF, level, nature, 1) * scalar / 100)
|
|
|
|
|
+ (ushort)(GetStat(p.SPE, HT_SPE ? 31 : IV_SPE, level, nature, 4) * scalar / 100)
|
|
|
|
|
+ (ushort)(GetStat(p.SPA, HT_SPA ? 31 : IV_SPA, level, nature, 2) * scalar / 100)
|
|
|
|
|
+ (ushort)(GetStat(p.SPD, HT_SPD ? 31 : IV_SPD, level, nature, 3) * scalar / 100);
|
|
|
|
|
|
2019-01-23 05:08:48 +00:00
|
|
|
|
float result = statSum * 6f;
|
|
|
|
|
result *= level;
|
|
|
|
|
result /= 100f;
|
|
|
|
|
return (int)result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int CPScalar
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int friend = CurrentFriendship; // stats +10% depending on friendship!
|
|
|
|
|
float scalar = friend / 255f;
|
|
|
|
|
scalar /= 10f;
|
|
|
|
|
scalar++;
|
|
|
|
|
scalar *= 100f;
|
2019-02-23 23:36:26 +00:00
|
|
|
|
return (int)scalar;
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int AwakeCP
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-02-02 18:19:41 +00:00
|
|
|
|
var sum = this.AwakeningSum();
|
2018-11-14 03:10:31 +00:00
|
|
|
|
if (sum == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
var lvl = CurrentLevel;
|
2019-01-23 05:08:48 +00:00
|
|
|
|
float scalar = lvl * 4f;
|
|
|
|
|
scalar /= 100f;
|
|
|
|
|
scalar += 2f;
|
|
|
|
|
float result = sum * scalar;
|
|
|
|
|
return (int)result;
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-28 06:05:36 +00:00
|
|
|
|
public void ResetCP() => Stat_CP = CalcCP;
|
|
|
|
|
|
|
|
|
|
public void ResetCalculatedValues()
|
|
|
|
|
{
|
|
|
|
|
ResetCP();
|
|
|
|
|
ResetHeight();
|
|
|
|
|
ResetWeight();
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 03:10:31 +00:00
|
|
|
|
// Casts are as per the game code; they may seem redundant but every bit of precision matters?
|
|
|
|
|
// This still doesn't precisely match :( -- just use a tolerance check when updating.
|
|
|
|
|
// If anyone can figure out how to get all precision to match, feel free to update :)
|
2018-11-28 06:05:36 +00:00
|
|
|
|
public float HeightRatio => GetHeightRatio(HeightScalar);
|
|
|
|
|
public float WeightRatio => GetWeightRatio(WeightScalar);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
|
2018-11-28 06:05:36 +00:00
|
|
|
|
public float CalcHeightAbsolute => GetHeightAbsolute(PersonalInfo, HeightScalar);
|
|
|
|
|
public float CalcWeightAbsolute => GetWeightAbsolute(PersonalInfo, HeightScalar, WeightScalar);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
|
|
|
|
|
public void ResetHeight()
|
|
|
|
|
{
|
|
|
|
|
var current = HeightAbsolute;
|
|
|
|
|
var updated = CalcHeightAbsolute;
|
|
|
|
|
if (Math.Abs(current - updated) > 0.0001f)
|
|
|
|
|
HeightAbsolute = updated;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetWeight()
|
|
|
|
|
{
|
|
|
|
|
var current = WeightAbsolute;
|
|
|
|
|
var updated = CalcWeightAbsolute;
|
|
|
|
|
if (Math.Abs(current - updated) > 0.0001f)
|
|
|
|
|
WeightAbsolute = updated;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 05:08:48 +00:00
|
|
|
|
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
|
2018-11-28 06:05:36 +00:00
|
|
|
|
private static float GetHeightRatio(int heightScalar)
|
|
|
|
|
{
|
2019-01-23 05:08:48 +00:00
|
|
|
|
// +/- 40%
|
2019-02-23 23:36:26 +00:00
|
|
|
|
float result = (byte)heightScalar / 255f;
|
2019-01-23 05:08:48 +00:00
|
|
|
|
result *= 0.8f;
|
|
|
|
|
result += 0.6f;
|
|
|
|
|
return result;
|
2018-11-28 06:05:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 05:08:48 +00:00
|
|
|
|
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
|
2018-11-28 06:05:36 +00:00
|
|
|
|
private static float GetWeightRatio(int weightScalar)
|
|
|
|
|
{
|
2019-01-23 05:08:48 +00:00
|
|
|
|
// +/- 20%
|
2019-02-23 23:36:26 +00:00
|
|
|
|
float result = (byte)weightScalar / 255f;
|
2019-01-23 05:08:48 +00:00
|
|
|
|
result *= 0.4f;
|
|
|
|
|
result += 0.8f;
|
|
|
|
|
return result;
|
2018-11-28 06:05:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 05:08:48 +00:00
|
|
|
|
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
|
2018-11-28 06:05:36 +00:00
|
|
|
|
public static float GetHeightAbsolute(PersonalInfo p, int heightScalar)
|
|
|
|
|
{
|
|
|
|
|
float HeightRatio = GetHeightRatio(heightScalar);
|
2019-01-23 05:08:48 +00:00
|
|
|
|
return HeightRatio * p.Height;
|
2018-11-28 06:05:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 05:08:48 +00:00
|
|
|
|
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
|
2018-11-28 06:05:36 +00:00
|
|
|
|
public static float GetWeightAbsolute(PersonalInfo p, int heightScalar, int weightScalar)
|
|
|
|
|
{
|
|
|
|
|
float HeightRatio = GetHeightRatio(heightScalar);
|
|
|
|
|
float WeightRatio = GetWeightRatio(weightScalar);
|
|
|
|
|
|
2019-01-23 05:08:48 +00:00
|
|
|
|
float weight = WeightRatio * p.Weight;
|
|
|
|
|
return HeightRatio * weight;
|
2018-11-28 06:05:36 +00:00
|
|
|
|
}
|
2018-12-07 05:03:33 +00:00
|
|
|
|
|
2019-01-23 05:08:48 +00:00
|
|
|
|
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
|
2018-12-07 05:03:33 +00:00
|
|
|
|
public static byte GetHeightScalar(float height, int avgHeight)
|
|
|
|
|
{
|
|
|
|
|
// height is already *100
|
2019-01-23 05:08:48 +00:00
|
|
|
|
float biasH = avgHeight * -0.6f;
|
|
|
|
|
float biasL = avgHeight * 0.8f;
|
|
|
|
|
float numerator = biasH + height;
|
|
|
|
|
float result = numerator / biasL;
|
|
|
|
|
result *= 255f;
|
2019-02-23 23:36:26 +00:00
|
|
|
|
int value = (int)result;
|
2019-01-23 05:08:48 +00:00
|
|
|
|
int unsigned = value & ~(value >> 31);
|
|
|
|
|
return (byte)Math.Min(255, unsigned);
|
2018-12-07 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 05:08:48 +00:00
|
|
|
|
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
|
2018-12-07 05:03:33 +00:00
|
|
|
|
public static byte GetWeightScalar(float height, float weight, int avgHeight, int avgWeight)
|
|
|
|
|
{
|
|
|
|
|
// height is already *100
|
|
|
|
|
// weight is already *10
|
2019-01-23 05:08:48 +00:00
|
|
|
|
float heightRatio = height / avgHeight;
|
|
|
|
|
float weightComponent = heightRatio * weight;
|
|
|
|
|
float top = avgWeight * -0.8f;
|
|
|
|
|
top += weightComponent;
|
|
|
|
|
float bot = avgWeight * 0.4f;
|
|
|
|
|
float result = top / bot;
|
|
|
|
|
result *= 255f;
|
|
|
|
|
int value = (int)result;
|
|
|
|
|
int unsigned = value & ~(value >> 31);
|
|
|
|
|
return (byte)Math.Min(255, unsigned);
|
2018-12-07 05:03:33 +00:00
|
|
|
|
}
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
|
|
|
|
public PK8 ConvertToPK8()
|
|
|
|
|
{
|
2020-08-01 00:25:14 +00:00
|
|
|
|
var pk8 = new PK8
|
2019-12-26 23:28:04 +00:00
|
|
|
|
{
|
|
|
|
|
EncryptionConstant = EncryptionConstant,
|
|
|
|
|
Species = Species,
|
|
|
|
|
TID = TID,
|
|
|
|
|
SID = SID,
|
|
|
|
|
EXP = EXP,
|
|
|
|
|
PID = PID,
|
|
|
|
|
Ability = Ability,
|
|
|
|
|
AbilityNumber = AbilityNumber,
|
|
|
|
|
Markings = Markings,
|
|
|
|
|
Language = Language,
|
|
|
|
|
EV_HP = EV_HP,
|
|
|
|
|
EV_ATK = EV_ATK,
|
|
|
|
|
EV_DEF = EV_DEF,
|
|
|
|
|
EV_SPA = EV_SPA,
|
|
|
|
|
EV_SPD = EV_SPD,
|
|
|
|
|
EV_SPE = EV_SPE,
|
|
|
|
|
Move1 = Move1,
|
|
|
|
|
Move2 = Move2,
|
|
|
|
|
Move3 = Move3,
|
|
|
|
|
Move4 = Move4,
|
|
|
|
|
Move1_PPUps = Move1_PPUps,
|
|
|
|
|
Move2_PPUps = Move2_PPUps,
|
|
|
|
|
Move3_PPUps = Move3_PPUps,
|
|
|
|
|
Move4_PPUps = Move4_PPUps,
|
|
|
|
|
RelearnMove1 = RelearnMove1,
|
|
|
|
|
RelearnMove2 = RelearnMove2,
|
|
|
|
|
RelearnMove3 = RelearnMove3,
|
|
|
|
|
RelearnMove4 = RelearnMove4,
|
|
|
|
|
IV_HP = IV_HP,
|
|
|
|
|
IV_ATK = IV_ATK,
|
|
|
|
|
IV_DEF = IV_DEF,
|
|
|
|
|
IV_SPA = IV_SPA,
|
|
|
|
|
IV_SPD = IV_SPD,
|
|
|
|
|
IV_SPE = IV_SPE,
|
|
|
|
|
IsNicknamed = IsNicknamed,
|
|
|
|
|
FatefulEncounter = FatefulEncounter,
|
|
|
|
|
Gender = Gender,
|
2020-12-11 04:42:30 +00:00
|
|
|
|
Form = Form,
|
2019-12-26 23:28:04 +00:00
|
|
|
|
Nature = Nature,
|
|
|
|
|
Nickname = Nickname,
|
|
|
|
|
Version = Version,
|
|
|
|
|
OT_Name = OT_Name,
|
|
|
|
|
MetDate = MetDate,
|
|
|
|
|
Met_Location = Met_Location,
|
|
|
|
|
Ball = Ball,
|
|
|
|
|
Met_Level = Met_Level,
|
|
|
|
|
OT_Gender = OT_Gender,
|
2020-02-14 19:48:13 +00:00
|
|
|
|
HyperTrainFlags = HyperTrainFlags,
|
|
|
|
|
|
2020-02-12 02:05:07 +00:00
|
|
|
|
// Memories don't exist in LGPE, and no memories are set on transfer.
|
|
|
|
|
|
2020-02-12 02:35:54 +00:00
|
|
|
|
OT_Friendship = OT_Friendship,
|
|
|
|
|
|
2020-02-12 02:05:07 +00:00
|
|
|
|
// No Ribbons or Markings on transfer.
|
|
|
|
|
|
|
|
|
|
StatNature = Nature,
|
|
|
|
|
HeightScalar = HeightScalar,
|
|
|
|
|
WeightScalar = WeightScalar,
|
2019-12-26 23:28:04 +00:00
|
|
|
|
};
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
2020-03-03 00:32:23 +00:00
|
|
|
|
// Fix PP and Stats
|
|
|
|
|
pk8.Heal();
|
|
|
|
|
|
2019-09-23 23:56:47 +00:00
|
|
|
|
// Fix Checksum
|
|
|
|
|
pk8.RefreshChecksum();
|
|
|
|
|
|
|
|
|
|
return pk8; // Done!
|
|
|
|
|
}
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|