2022-08-26 06:04:38 +00:00
|
|
|
using System;
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary> Generation 8 <see cref="PKM"/> format. </summary>
|
|
|
|
public sealed class PB8 : G8PKM
|
2021-11-20 02:23:49 +00:00
|
|
|
{
|
2023-12-04 04:13:20 +00:00
|
|
|
public override ReadOnlySpan<ushort> ExtraBytes =>
|
|
|
|
[
|
2022-02-05 01:35:15 +00:00
|
|
|
// Alignment bytes
|
|
|
|
0x17, 0x1A, 0x1B, 0x23, 0x33, 0x3E, 0x3F,
|
|
|
|
0x4C, 0x4D, 0x4E, 0x4F,
|
|
|
|
0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
0x91, 0x92, 0x93,
|
|
|
|
0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
0xC5,
|
|
|
|
0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB,
|
|
|
|
0xE0, 0xE1, // Old Console Region / Region
|
|
|
|
0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
|
|
|
|
0x115, 0x11F, // Alignment
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
0x13D, 0x13E, 0x13F,
|
|
|
|
0x140, 0x141, 0x142, 0x143, 0x144, 0x145, 0x146, 0x147,
|
2023-12-04 04:13:20 +00:00
|
|
|
];
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PersonalInfo8BDSP PersonalInfo => PersonalTable.BDSP.GetFormEntry(Species, Form);
|
|
|
|
public override IPermitRecord Permit => PersonalInfo;
|
2022-05-31 04:43:52 +00:00
|
|
|
public override EntityContext Context => EntityContext.Gen8b;
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
public PB8()
|
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
EggLocation = MetLocation = Locations.Default8bNone;
|
2022-02-05 01:35:15 +00:00
|
|
|
AffixedRibbon = -1; // 00 would make it show Kalos Champion :)
|
|
|
|
}
|
2021-11-20 17:04:09 +00:00
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
public PB8(byte[] data) : base(data) { }
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PB8 Clone() => new((byte[])Data.Clone());
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-02-22 04:13:27 +00:00
|
|
|
public bool IsDprIllegal
|
|
|
|
{
|
|
|
|
get => Data[0x52] != 0;
|
|
|
|
set => Data[0x52] = (byte)((Data[0x52] & 0xFE) | (value ? 1 : 0));
|
|
|
|
}
|
|
|
|
|
2024-02-23 23:01:36 +00:00
|
|
|
public bool BelongsTo(ITrainerInfo tr)
|
|
|
|
{
|
|
|
|
if (tr.Version != Version)
|
|
|
|
return false;
|
|
|
|
if (tr.ID32 != ID32)
|
|
|
|
return false;
|
|
|
|
if (tr.Gender != OriginalTrainerGender)
|
|
|
|
return false;
|
2024-05-27 23:21:11 +00:00
|
|
|
|
|
|
|
Span<char> ot = stackalloc char[MaxStringLengthTrainer];
|
|
|
|
int len = LoadString(OriginalTrainerTrash, ot);
|
|
|
|
return ot[..len].SequenceEqual(tr.OT);
|
2024-02-23 23:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateHandler(ITrainerInfo tr)
|
2022-02-05 01:35:15 +00:00
|
|
|
{
|
|
|
|
if (IsEgg)
|
2021-11-20 02:23:49 +00:00
|
|
|
{
|
2023-12-04 04:13:20 +00:00
|
|
|
// Apply link trade data, only if it left the OT (ignore if dumped & imported, or cloned, etc.)
|
2024-02-23 23:01:36 +00:00
|
|
|
const ushort location = Locations.LinkTrade6NPC;
|
|
|
|
if (MetLocation != location && !BelongsTo(tr))
|
|
|
|
{
|
|
|
|
var date = EncounterDate.GetDate3DS();
|
|
|
|
SetLinkTradeEgg(date.Day, date.Month, date.Year, location);
|
|
|
|
}
|
2021-11-22 03:29:07 +00:00
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
// Unfortunately, BD/SP doesn't return if it's an egg, and can update the HT details & handler.
|
2022-02-05 01:35:15 +00:00
|
|
|
// Continue to the rest of the method.
|
|
|
|
// return;
|
|
|
|
}
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
// Process to the HT if the OT of the Pokémon does not match the SAV's OT info.
|
|
|
|
if (!TradeOT(tr))
|
|
|
|
TradeHT(tr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void FixMemories()
|
|
|
|
{
|
|
|
|
if (BDSP)
|
|
|
|
{
|
2024-02-23 23:01:36 +00:00
|
|
|
this.ClearMemoriesOT();
|
|
|
|
this.ClearMemoriesHT();
|
2021-11-20 02:23:49 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
if (IsEgg) // No memories if is egg.
|
2021-11-20 02:23:49 +00:00
|
|
|
{
|
2024-02-23 23:01:36 +00:00
|
|
|
// Memories already cleared above.
|
2022-02-05 01:35:15 +00:00
|
|
|
// Clear Handler
|
|
|
|
if (!IsTradedEgg)
|
2021-11-20 02:23:49 +00:00
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
HandlingTrainerFriendship = HandlingTrainerGender = HandlingTrainerLanguage = 0;
|
|
|
|
HandlingTrainerTrash.Clear();
|
2021-11-20 02:23:49 +00:00
|
|
|
}
|
2022-02-05 01:35:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
if (IsUntraded)
|
2024-02-23 23:01:36 +00:00
|
|
|
{
|
|
|
|
// Memories already cleared above.
|
|
|
|
HandlingTrainerFriendship = HandlingTrainerGender = HandlingTrainerLanguage = 0;
|
|
|
|
HandlingTrainerTrash.Clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var gen = Generation;
|
|
|
|
if (gen < 6)
|
|
|
|
this.ClearMemoriesOT();
|
|
|
|
}
|
2022-02-05 01:35:15 +00:00
|
|
|
}
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
private bool TradeOT(ITrainerInfo tr)
|
|
|
|
{
|
|
|
|
// Check to see if the OT matches the SAV's OT info.
|
2024-02-23 23:01:36 +00:00
|
|
|
if (!BelongsTo(tr))
|
2022-02-05 01:35:15 +00:00
|
|
|
return false;
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
CurrentHandler = 0;
|
|
|
|
return true;
|
|
|
|
}
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2024-05-13 04:40:50 +00:00
|
|
|
private void TradeHT(ITrainerInfo tr) => PKH.UpdateHandler(this, tr);
|
2022-02-05 01:35:15 +00:00
|
|
|
|
|
|
|
// Maximums
|
2022-08-27 06:43:36 +00:00
|
|
|
public override ushort MaxMoveID => Legal.MaxMoveID_8b;
|
|
|
|
public override ushort MaxSpeciesID => Legal.MaxSpeciesID_8b;
|
2022-02-05 01:35:15 +00:00
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_8b;
|
|
|
|
public override int MaxItemID => Legal.MaxItemID_8b;
|
|
|
|
public override int MaxBallID => Legal.MaxBallID_8b;
|
2024-02-23 03:20:54 +00:00
|
|
|
public override GameVersion MaxGameID => Legal.MaxGameID_HOME;
|
2022-05-31 04:43:52 +00:00
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public override bool WasEgg => IsEgg || EggDay != 0;
|
2022-05-31 04:43:52 +00:00
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public override bool HasOriginalMetLocation => base.HasOriginalMetLocation && !(LA && MetLocation == LocationsHOME.SWLA);
|
2024-04-23 05:57:17 +00:00
|
|
|
|
|
|
|
public override string GetString(ReadOnlySpan<byte> data)
|
|
|
|
=> StringConverter8.GetString(data);
|
|
|
|
public override int LoadString(ReadOnlySpan<byte> data, Span<char> destBuffer)
|
|
|
|
=> StringConverter8.LoadString(data, destBuffer);
|
|
|
|
public override int SetString(Span<byte> destBuffer, ReadOnlySpan<char> value, int maxLength, StringConverterOption option)
|
|
|
|
=> StringConverter8.SetString(destBuffer, value, maxLength, option);
|
2024-05-17 20:58:49 +00:00
|
|
|
public override int GetStringTerminatorIndex(ReadOnlySpan<byte> data)
|
2024-05-27 23:21:11 +00:00
|
|
|
=> TrashBytesUTF16.GetTerminatorIndex(data);
|
2024-05-17 20:58:49 +00:00
|
|
|
public override int GetStringLength(ReadOnlySpan<byte> data)
|
2024-05-27 23:21:11 +00:00
|
|
|
=> TrashBytesUTF16.GetStringLength(data);
|
2024-05-17 20:58:49 +00:00
|
|
|
public override int GetBytesPerChar() => 2;
|
2021-11-20 02:23:49 +00:00
|
|
|
}
|