Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
using System;
|
2022-01-03 05:35:59 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2016-08-27 08:52:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary> Generation 1 <see cref="PKM"/> format. </summary>
|
2022-11-25 01:42:17 +00:00
|
|
|
public sealed class PK1 : GBPKML, IPersonalType
|
2016-08-27 08:52:34 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PersonalInfo1 PersonalInfo => PersonalTable.Y[Species];
|
2016-08-27 08:52:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override bool Valid => Species <= 151 && (Data[0] == 0 || Species != 0);
|
2016-08-28 10:18:22 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int SIZE_PARTY => PokeCrypto.SIZE_1PARTY;
|
|
|
|
public override int SIZE_STORED => PokeCrypto.SIZE_1STORED;
|
|
|
|
public override bool Korean => false;
|
2017-04-09 21:06:50 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override EntityContext Context => EntityContext.Gen1;
|
2016-08-27 08:52:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public PK1(bool jp = false) : base(PokeCrypto.SIZE_1PARTY, jp) { }
|
|
|
|
public PK1(byte[] decryptedData, bool jp = false) : base(EnsurePartySize(decryptedData), jp) { }
|
2020-09-26 19:09:02 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static byte[] EnsurePartySize(byte[] data)
|
|
|
|
{
|
|
|
|
if (data.Length != PokeCrypto.SIZE_1PARTY)
|
|
|
|
Array.Resize(ref data, PokeCrypto.SIZE_1PARTY);
|
|
|
|
return data;
|
|
|
|
}
|
2016-08-27 08:52:34 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PK1 Clone()
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
PK1 clone = new((byte[])Data.Clone(), Japanese);
|
2022-06-18 18:04:24 +00:00
|
|
|
OT_Trash.CopyTo(clone.OT_Trash);
|
|
|
|
Nickname_Trash.CopyTo(clone.Nickname_Trash);
|
|
|
|
return clone;
|
|
|
|
}
|
2016-08-27 08:52:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override byte[] Encrypt() => new PokeList1(this).Write();
|
|
|
|
|
|
|
|
#region Stored Attributes
|
2023-01-22 04:02:33 +00:00
|
|
|
public byte SpeciesInternal { get => Data[0]; set => Data[0] = value; } // raw access
|
|
|
|
public override ushort Species { get => SpeciesConverter.GetNational1(SpeciesInternal); set => SetSpeciesValues(value); }
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int Stat_HPCurrent { get => ReadUInt16BigEndian(Data.AsSpan(0x1)); set => WriteUInt16BigEndian(Data.AsSpan(0x1), (ushort)value); }
|
|
|
|
public int Stat_LevelBox { get => Data[3]; set => Data[3] = (byte)value; }
|
|
|
|
public override int Status_Condition { get => Data[4]; set => Data[4] = (byte)value; }
|
2022-11-25 01:42:17 +00:00
|
|
|
public byte Type1 { get => Data[5]; set => Data[5] = value; }
|
|
|
|
public byte Type2 { get => Data[6]; set => Data[6] = value; }
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
public byte Catch_Rate { get => Data[7]; set => Data[7] = value; }
|
2022-08-27 06:43:36 +00:00
|
|
|
public override ushort Move1 { get => Data[8]; set => Data[8] = (byte)value; }
|
|
|
|
public override ushort Move2 { get => Data[9]; set => Data[9] = (byte)value; }
|
|
|
|
public override ushort Move3 { get => Data[10]; set => Data[10] = (byte)value; }
|
|
|
|
public override ushort Move4 { get => Data[11]; set => Data[11] = (byte)value; }
|
2023-01-22 04:02:33 +00:00
|
|
|
public override ushort TID16 { get => ReadUInt16BigEndian(Data.AsSpan(0xC)); set => WriteUInt16BigEndian(Data.AsSpan(0xC), value); }
|
2022-06-18 18:04:24 +00:00
|
|
|
public override uint EXP { get => ReadUInt32BigEndian(Data.AsSpan(0xE)) >> 8; set => WriteUInt32BigEndian(Data.AsSpan(0xE), (value << 8) | Data[0x11]); }
|
|
|
|
public override int EV_HP { get => ReadUInt16BigEndian(Data.AsSpan(0x11)); set => WriteUInt16BigEndian(Data.AsSpan(0x11), (ushort)value); }
|
|
|
|
public override int EV_ATK { get => ReadUInt16BigEndian(Data.AsSpan(0x13)); set => WriteUInt16BigEndian(Data.AsSpan(0x13), (ushort)value); }
|
|
|
|
public override int EV_DEF { get => ReadUInt16BigEndian(Data.AsSpan(0x15)); set => WriteUInt16BigEndian(Data.AsSpan(0x15), (ushort)value); }
|
|
|
|
public override int EV_SPE { get => ReadUInt16BigEndian(Data.AsSpan(0x17)); set => WriteUInt16BigEndian(Data.AsSpan(0x17), (ushort)value); }
|
|
|
|
public override int EV_SPC { get => ReadUInt16BigEndian(Data.AsSpan(0x19)); set => WriteUInt16BigEndian(Data.AsSpan(0x19), (ushort)value); }
|
|
|
|
public override ushort DV16 { get => ReadUInt16BigEndian(Data.AsSpan(0x1B)); set => WriteUInt16BigEndian(Data.AsSpan(0x1B), value); }
|
|
|
|
public override int Move1_PP { get => Data[0x1D] & 0x3F; set => Data[0x1D] = (byte)((Data[0x1D] & 0xC0) | Math.Min(63, value)); }
|
|
|
|
public override int Move2_PP { get => Data[0x1E] & 0x3F; set => Data[0x1E] = (byte)((Data[0x1E] & 0xC0) | Math.Min(63, value)); }
|
|
|
|
public override int Move3_PP { get => Data[0x1F] & 0x3F; set => Data[0x1F] = (byte)((Data[0x1F] & 0xC0) | Math.Min(63, value)); }
|
|
|
|
public override int Move4_PP { get => Data[0x20] & 0x3F; set => Data[0x20] = (byte)((Data[0x20] & 0xC0) | Math.Min(63, value)); }
|
|
|
|
public override int Move1_PPUps { get => (Data[0x1D] & 0xC0) >> 6; set => Data[0x1D] = (byte)((Data[0x1D] & 0x3F) | ((value & 0x3) << 6)); }
|
|
|
|
public override int Move2_PPUps { get => (Data[0x1E] & 0xC0) >> 6; set => Data[0x1E] = (byte)((Data[0x1E] & 0x3F) | ((value & 0x3) << 6)); }
|
|
|
|
public override int Move3_PPUps { get => (Data[0x1F] & 0xC0) >> 6; set => Data[0x1F] = (byte)((Data[0x1F] & 0x3F) | ((value & 0x3) << 6)); }
|
|
|
|
public override int Move4_PPUps { get => (Data[0x20] & 0xC0) >> 6; set => Data[0x20] = (byte)((Data[0x20] & 0x3F) | ((value & 0x3) << 6)); }
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Party Attributes
|
|
|
|
public override int Stat_Level { get => Data[0x21]; set => Stat_LevelBox = Data[0x21] = (byte)value; }
|
|
|
|
public override int Stat_HPMax { get => ReadUInt16BigEndian(Data.AsSpan(0x22)); set => WriteUInt16BigEndian(Data.AsSpan(0x22), (ushort)value); }
|
|
|
|
public override int Stat_ATK { get => ReadUInt16BigEndian(Data.AsSpan(0x24)); set => WriteUInt16BigEndian(Data.AsSpan(0x24), (ushort)value); }
|
|
|
|
public override int Stat_DEF { get => ReadUInt16BigEndian(Data.AsSpan(0x26)); set => WriteUInt16BigEndian(Data.AsSpan(0x26), (ushort)value); }
|
|
|
|
public override int Stat_SPE { get => ReadUInt16BigEndian(Data.AsSpan(0x28)); set => WriteUInt16BigEndian(Data.AsSpan(0x28), (ushort)value); }
|
|
|
|
public int Stat_SPC { get => ReadUInt16BigEndian(Data.AsSpan(0x2A)); set => WriteUInt16BigEndian(Data.AsSpan(0x2A), (ushort)value); }
|
|
|
|
// Leave SPA and SPD as alias for SPC
|
|
|
|
public override int Stat_SPA { get => Stat_SPC; set => Stat_SPC = value; }
|
|
|
|
public override int Stat_SPD { get => Stat_SPC; set { } }
|
|
|
|
#endregion
|
|
|
|
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
public static bool IsCatchRateHeldItem(byte rate) => rate == 0 || Array.IndexOf(Legal.HeldItems_GSC, rate) >= 0;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private static bool IsCatchRatePreEvolutionRate(ushort baseSpecies, int finalSpecies, byte rate)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
for (ushort species = baseSpecies; species <= finalSpecies; species++)
|
2021-10-05 05:55:18 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (rate == PersonalTable.RB[species].CatchRate || rate == PersonalTable.Y[species].CatchRate)
|
|
|
|
return true;
|
2021-10-05 05:55:18 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-10-05 05:55:18 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private void SetSpeciesValues(ushort value)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var updated = SpeciesConverter.GetInternal1(value);
|
|
|
|
if (SpeciesInternal == updated)
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2016-08-28 10:18:22 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
SpeciesInternal = updated;
|
2018-08-21 14:37:15 +00:00
|
|
|
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
var pi = PersonalTable.RB[value];
|
2022-11-25 01:42:17 +00:00
|
|
|
Type1 = pi.Type1;
|
|
|
|
Type2 = pi.Type2;
|
2018-08-19 22:50:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Before updating catch rate, check if non-standard
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
if (IsValidCatchRateAnyPreEvo((byte)value, Catch_Rate))
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2021-10-05 05:55:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Matches nothing possible; just reset to current Species' rate.
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
Catch_Rate = (byte)pi.CatchRate;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-24 23:41:18 +00:00
|
|
|
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
private static bool IsValidCatchRateAnyPreEvo(byte species, byte rate)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (IsCatchRateHeldItem(rate))
|
|
|
|
return true;
|
|
|
|
if (species == (int)Core.Species.Pikachu && rate == 0xA3) // Light Ball (starter)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
var table = EvolutionTree.Evolves1;
|
|
|
|
var baby = table.GetBaseSpeciesForm(species, 0);
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
return IsCatchRatePreEvolutionRate(baby.Species, species, rate);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2022-05-31 04:43:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int Version { get => (int)GameVersion.RBY; set { } }
|
|
|
|
public override int PKRS_Strain { get => 0; set { } }
|
|
|
|
public override int PKRS_Days { get => 0; set { } }
|
2023-03-26 00:55:55 +00:00
|
|
|
public override bool CanHoldItem(ReadOnlySpan<ushort> valid) => false;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int Met_Location { get => 0; set { } }
|
|
|
|
public override int OT_Gender { get => 0; set { } }
|
|
|
|
public override int Met_Level { get => 0; set { } }
|
|
|
|
public override int CurrentFriendship { get => 0; set { } }
|
|
|
|
public override bool IsEgg { get => false; set { } }
|
|
|
|
public override int HeldItem { get => 0; set { } }
|
|
|
|
public override int OT_Friendship { get => 0; set { } }
|
|
|
|
|
|
|
|
// Maximums
|
2022-08-27 06:43:36 +00:00
|
|
|
public override ushort MaxMoveID => Legal.MaxMoveID_1;
|
|
|
|
public override ushort MaxSpeciesID => Legal.MaxSpeciesID_1;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_1;
|
|
|
|
public override int MaxItemID => Legal.MaxItemID_1;
|
|
|
|
|
|
|
|
// Extra
|
|
|
|
public int Gen2Item => ItemConverter.GetItemFuture1(Catch_Rate);
|
|
|
|
|
|
|
|
public PK2 ConvertToPK2()
|
|
|
|
{
|
|
|
|
PK2 pk2 = new(Japanese) {Species = Species};
|
2023-04-21 04:23:15 +00:00
|
|
|
Data.AsSpan(7, 0x1A).CopyTo(pk2.Data.AsSpan(1));
|
|
|
|
OT_Trash.CopyTo(pk2.OT_Trash);
|
|
|
|
Nickname_Trash.CopyTo(pk2.Nickname_Trash);
|
2022-05-31 04:43:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
pk2.HeldItem = Gen2Item;
|
|
|
|
pk2.CurrentFriendship = pk2.PersonalInfo.BaseFriendship;
|
|
|
|
pk2.Stat_Level = CurrentLevel;
|
2018-08-19 22:50:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return pk2;
|
|
|
|
}
|
2016-09-04 22:03:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public PK7 ConvertToPK7()
|
|
|
|
{
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
var pk7 = new PK7
|
|
|
|
{
|
|
|
|
EncryptionConstant = rnd.Rand32(),
|
|
|
|
Species = Species,
|
2023-01-22 04:02:33 +00:00
|
|
|
TID16 = TID16,
|
2022-06-18 18:04:24 +00:00
|
|
|
CurrentLevel = CurrentLevel,
|
|
|
|
EXP = EXP,
|
|
|
|
Met_Level = CurrentLevel,
|
|
|
|
Nature = Experience.GetNatureVC(EXP),
|
|
|
|
PID = rnd.Rand32(),
|
|
|
|
Ball = 4,
|
2023-01-22 04:02:33 +00:00
|
|
|
MetDate = DateOnly.FromDateTime(DateTime.Now),
|
2022-06-18 18:04:24 +00:00
|
|
|
Version = (int)GameVersion.RD, // Default to red
|
|
|
|
Move1 = Move1,
|
|
|
|
Move2 = Move2,
|
|
|
|
Move3 = Move3,
|
|
|
|
Move4 = Move4,
|
|
|
|
Move1_PPUps = Move1_PPUps,
|
|
|
|
Move2_PPUps = Move2_PPUps,
|
|
|
|
Move3_PPUps = Move3_PPUps,
|
|
|
|
Move4_PPUps = Move4_PPUps,
|
|
|
|
Met_Location = Locations.Transfer1, // "Kanto region", hardcoded.
|
|
|
|
Gender = Gender,
|
|
|
|
IsNicknamed = false,
|
|
|
|
|
|
|
|
CurrentHandler = 1,
|
|
|
|
HT_Name = RecentTrainerCache.OT_Name,
|
|
|
|
HT_Gender = RecentTrainerCache.OT_Gender,
|
|
|
|
};
|
|
|
|
RecentTrainerCache.SetConsoleRegionData3DS(pk7);
|
|
|
|
RecentTrainerCache.SetFirstCountryRegion(pk7);
|
|
|
|
pk7.HealPP();
|
|
|
|
var lang = TransferLanguage(RecentTrainerCache.Language);
|
|
|
|
pk7.Language = lang;
|
|
|
|
pk7.Nickname = SpeciesName.GetSpeciesNameGeneration(pk7.Species, lang, pk7.Format);
|
2023-04-21 04:23:15 +00:00
|
|
|
pk7.OT_Name = OT_Trash[0] != StringConverter12.G1TradeOTCode ? StringConverter12Transporter.GetString(OT_Trash, Japanese) : StringConverter12.G1TradeOTName[lang]; // In-game Trade
|
2022-06-18 18:04:24 +00:00
|
|
|
pk7.OT_Friendship = pk7.HT_Friendship = PersonalTable.SM[Species].BaseFriendship;
|
|
|
|
|
|
|
|
// IVs
|
|
|
|
Span<int> finalIVs = stackalloc int[6];
|
|
|
|
int flawless = Species == (int)Core.Species.Mew ? 5 : 3;
|
|
|
|
for (var i = 0; i < finalIVs.Length; i++)
|
|
|
|
finalIVs[i] = rnd.Next(32);
|
|
|
|
for (var i = 0; i < flawless; i++)
|
|
|
|
finalIVs[i] = 31;
|
2023-03-27 07:11:42 +00:00
|
|
|
rnd.Shuffle(finalIVs);
|
2022-06-18 18:04:24 +00:00
|
|
|
pk7.SetIVs(finalIVs);
|
|
|
|
|
|
|
|
switch (IsShiny ? Shiny.Always : Shiny.Never)
|
|
|
|
{
|
|
|
|
case Shiny.Always when !pk7.IsShiny: // Force Square
|
2023-01-22 04:02:33 +00:00
|
|
|
var low = pk7.PID & 0xFFFF;
|
|
|
|
pk7.PID = (low ^ pk7.TID16 ^ 0u) << 16 | low;
|
2022-06-18 18:04:24 +00:00
|
|
|
break;
|
|
|
|
case Shiny.Never when pk7.IsShiny: // Force Not Shiny
|
|
|
|
pk7.PID ^= 0x1000_0000;
|
|
|
|
break;
|
2016-09-04 22:03:40 +00:00
|
|
|
}
|
2017-01-25 11:29:38 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
int abil = TransporterLogic.IsHiddenDisallowedVC1(Species) ? 0 : 2; // Hidden
|
2022-06-18 18:04:24 +00:00
|
|
|
pk7.RefreshAbility(abil); // 0/1/2 (not 1/2/4)
|
|
|
|
|
|
|
|
if (Species == (int)Core.Species.Mew) // Mew gets special treatment.
|
2017-01-25 11:29:38 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
pk7.FatefulEncounter = true;
|
2017-01-25 11:29:38 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (IsNicknamedBank)
|
|
|
|
{
|
|
|
|
pk7.IsNicknamed = true;
|
2023-04-21 04:23:15 +00:00
|
|
|
pk7.Nickname = StringConverter12Transporter.GetString(Nickname_Trash, Japanese);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pk7.SetTradeMemoryHT6(bank:true); // oh no, memories on gen7 pk
|
|
|
|
|
|
|
|
pk7.RefreshChecksum();
|
|
|
|
return pk7;
|
2016-08-27 08:52:34 +00:00
|
|
|
}
|
|
|
|
}
|