2018-11-16 01:36:29 +00:00
|
|
|
|
using System;
|
2018-11-15 03:34:21 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-11-15 06:02:01 +00:00
|
|
|
|
using System.Text;
|
2018-11-15 03:34:21 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2018-11-16 01:36:29 +00:00
|
|
|
|
/// <summary>
|
2019-02-23 22:57:35 +00:00
|
|
|
|
/// Go Park Entity transferred from <see cref="GameVersion.GO"/> to <see cref="GameVersion.GG"/>.
|
2018-11-16 01:36:29 +00:00
|
|
|
|
/// </summary>
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
public sealed class GP1 : IEncounterInfo
|
2018-11-15 03:34:21 +00:00
|
|
|
|
{
|
|
|
|
|
public const int SIZE = 0x1B0;
|
2020-09-26 18:33:21 +00:00
|
|
|
|
public readonly byte[] Data;
|
|
|
|
|
|
|
|
|
|
public GameVersion Version => GameVersion.GO;
|
|
|
|
|
public bool EggEncounter => false;
|
|
|
|
|
public int LevelMin => Level;
|
|
|
|
|
public int LevelMax => Level;
|
|
|
|
|
public int Generation => 7;
|
|
|
|
|
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPB7(sav);
|
|
|
|
|
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) => ConvertToPB7(sav, criteria);
|
2018-11-15 03:34:21 +00:00
|
|
|
|
|
2018-11-22 04:48:55 +00:00
|
|
|
|
public GP1(byte[] data) => Data = data;
|
2020-09-26 18:33:21 +00:00
|
|
|
|
public GP1() : this((byte[])Blank.Clone()) { }
|
|
|
|
|
public void WriteTo(byte[] data, int offset) => Data.CopyTo(data, offset);
|
2018-11-22 04:48:55 +00:00
|
|
|
|
|
2018-11-16 01:36:29 +00:00
|
|
|
|
public static GP1 FromData(byte[] data, int offset)
|
2018-11-15 03:34:21 +00:00
|
|
|
|
{
|
2018-11-16 01:36:29 +00:00
|
|
|
|
var gpkm = new GP1();
|
2018-11-15 03:34:21 +00:00
|
|
|
|
Array.Copy(data, offset, gpkm.Data, 0, SIZE);
|
|
|
|
|
return gpkm;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-10 04:07:15 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// First 0x20 bytes of an empty <see cref="GP1"/>, all other bytes are 0.
|
|
|
|
|
/// </summary>
|
2018-11-15 03:34:21 +00:00
|
|
|
|
private static readonly byte[] Blank20 =
|
|
|
|
|
{
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x80, 0x3F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F,
|
|
|
|
|
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x85, 0xEC, 0x33, 0x01,
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-15 06:02:01 +00:00
|
|
|
|
public static readonly byte[] Blank = GetBlank();
|
|
|
|
|
|
2018-11-15 03:34:21 +00:00
|
|
|
|
public static byte[] GetBlank()
|
|
|
|
|
{
|
|
|
|
|
byte[] data = new byte[SIZE];
|
|
|
|
|
Blank20.CopyTo(data, 0x20);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
2018-11-15 06:02:01 +00:00
|
|
|
|
|
|
|
|
|
public string Username1 => Util.TrimFromZero(Encoding.ASCII.GetString(Data, 0x00, 0x10));
|
|
|
|
|
public string Username2 => Util.TrimFromZero(Encoding.ASCII.GetString(Data, 0x10, 0x20));
|
|
|
|
|
|
2018-11-18 21:54:47 +00:00
|
|
|
|
public int Species => BitConverter.ToInt32(Data, 0x28);
|
2018-11-21 23:25:50 +00:00
|
|
|
|
public int CP => BitConverter.ToInt32(Data, 0x2C);
|
2018-11-15 06:02:01 +00:00
|
|
|
|
public float LevelF => BitConverter.ToSingle(Data, 0x30);
|
|
|
|
|
public int Level => Math.Max(1, (int)Math.Round(LevelF));
|
2020-03-24 18:44:54 +00:00
|
|
|
|
public int Stat_HP => BitConverter.ToInt32(Data, 0x34);
|
|
|
|
|
// geolocation data 0x38-0x47?
|
2018-12-07 05:03:33 +00:00
|
|
|
|
public float HeightF => BitConverter.ToSingle(Data, 0x48);
|
|
|
|
|
public float WeightF => BitConverter.ToSingle(Data, 0x4C);
|
|
|
|
|
|
|
|
|
|
public byte HeightScalar
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var height = HeightF * 100f;
|
2020-12-11 04:42:30 +00:00
|
|
|
|
var pi = PersonalTable.GG.GetFormEntry(Species, Form);
|
2018-12-07 05:03:33 +00:00
|
|
|
|
var avgHeight = pi.Height;
|
|
|
|
|
return PB7.GetHeightScalar(height, avgHeight);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte WeightScalar
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var height = HeightF * 100f;
|
|
|
|
|
var weight = WeightF * 10f;
|
2020-12-11 04:42:30 +00:00
|
|
|
|
var pi = PersonalTable.GG.GetFormEntry(Species, Form);
|
2018-12-07 05:03:33 +00:00
|
|
|
|
var avgHeight = pi.Height;
|
|
|
|
|
var avgWeight = pi.Weight;
|
|
|
|
|
return PB7.GetWeightScalar(height, weight, avgHeight, avgWeight);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 17:39:50 +00:00
|
|
|
|
public int IV_HP => BitConverter.ToInt32(Data, 0x50);
|
|
|
|
|
public int IV_ATK => BitConverter.ToInt32(Data, 0x54);
|
|
|
|
|
public int IV_DEF => BitConverter.ToInt32(Data, 0x58);
|
2018-11-21 23:25:50 +00:00
|
|
|
|
public int Date => BitConverter.ToInt32(Data, 0x5C); // ####.##.## YYYY.MM.DD
|
|
|
|
|
public int Year => Date / 1_00_00;
|
|
|
|
|
public int Month => (Date / 1_00) % 1_00;
|
|
|
|
|
public int Day => Date % 1_00;
|
2018-11-15 06:02:01 +00:00
|
|
|
|
|
|
|
|
|
public int Gender => Data[0x70] - 1; // M=1, F=2, G=3 ;; shift down by 1.
|
|
|
|
|
|
2020-09-26 18:33:21 +00:00
|
|
|
|
public int Form => Data[0x72];
|
2018-11-16 01:36:29 +00:00
|
|
|
|
public bool IsShiny => Data[0x73] == 1;
|
2018-11-15 06:02:01 +00:00
|
|
|
|
|
|
|
|
|
// https://bulbapedia.bulbagarden.net/wiki/List_of_moves_in_Pok%C3%A9mon_GO
|
|
|
|
|
public int Move1 => BitConverter.ToInt32(Data, 0x74); // uses Go Indexes
|
|
|
|
|
public int Move2 => BitConverter.ToInt32(Data, 0x78); // uses Go Indexes
|
|
|
|
|
|
|
|
|
|
public string GeoCityName => Util.TrimFromZero(Encoding.ASCII.GetString(Data, 0x7C, 0x60)); // dunno length
|
|
|
|
|
|
|
|
|
|
public string Nickname => Util.TrimFromZero(Encoding.ASCII.GetString(Data, 0x12D, 0x20)); // dunno length
|
|
|
|
|
|
2019-01-21 05:55:28 +00:00
|
|
|
|
public static readonly IReadOnlyList<string> Genders = GameInfo.GenderSymbolASCII;
|
|
|
|
|
public string GenderString => (uint) Gender >= Genders.Count ? string.Empty : Genders[Gender];
|
2018-11-16 01:36:29 +00:00
|
|
|
|
public string ShinyString => IsShiny ? "★ " : string.Empty;
|
2020-09-26 18:33:21 +00:00
|
|
|
|
public string FormString => Form != 0 ? $"-{Form}" : string.Empty;
|
2019-09-19 02:58:23 +00:00
|
|
|
|
private string NickStr => string.IsNullOrWhiteSpace(Nickname) ? SpeciesName.GetSpeciesNameGeneration(Species, (int)LanguageID.English, 7) : Nickname;
|
2018-11-23 18:31:55 +00:00
|
|
|
|
public string FileName => $"{FileNameWithoutExtension}.gp1";
|
|
|
|
|
|
|
|
|
|
public string FileNameWithoutExtension
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-09-26 18:33:21 +00:00
|
|
|
|
string form = Form > 0 ? $"-{Form:00}" : string.Empty;
|
2019-02-08 05:40:20 +00:00
|
|
|
|
string star = IsShiny ? " ★" : string.Empty;
|
2021-01-05 17:39:50 +00:00
|
|
|
|
return $"{Species:000}{form}{star} - {NickStr} - Lv. {Level:00} - {IV_HP:00}.{IV_ATK:00}.{IV_DEF:00} - CP {CP:0000} (Moves {Move1:000}, {Move2:000})";
|
2018-11-23 18:31:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-16 01:36:29 +00:00
|
|
|
|
|
2020-05-29 18:13:49 +00:00
|
|
|
|
public string GeoTime => $"Captured in {GeoCityName} by {Username1} on {Year}/{Month:00}/{Day:00}";
|
2021-01-05 17:39:50 +00:00
|
|
|
|
public string StatMove => $"{IV_HP:00}/{IV_ATK:00}/{IV_DEF:00}, CP {CP:0000} (Moves {Move1:000}, {Move2:000})";
|
2020-05-29 18:13:49 +00:00
|
|
|
|
public string Dump(IReadOnlyList<string> speciesNames, int index) => $"{index:000} {Nickname} ({speciesNames[Species]}{FormString} {ShinyString}[{GenderString}]) @ Lv. {Level:00} - {StatMove}, {GeoTime}.";
|
2018-11-22 04:48:55 +00:00
|
|
|
|
|
2019-02-10 04:07:15 +00:00
|
|
|
|
public PB7 ConvertToPB7(ITrainerInfo sav) => ConvertToPB7(sav, EncounterCriteria.Unrestricted);
|
|
|
|
|
|
|
|
|
|
public PB7 ConvertToPB7(ITrainerInfo sav, EncounterCriteria criteria)
|
2018-11-22 04:48:55 +00:00
|
|
|
|
{
|
|
|
|
|
var pk = new PB7
|
|
|
|
|
{
|
|
|
|
|
Version = (int) GameVersion.GO,
|
|
|
|
|
Species = Species,
|
2020-12-11 04:42:30 +00:00
|
|
|
|
Form = Form,
|
2018-11-22 04:48:55 +00:00
|
|
|
|
Met_Location = 50, // Go complex
|
|
|
|
|
Met_Year = Year - 2000,
|
|
|
|
|
Met_Month = Month,
|
|
|
|
|
Met_Day = Day,
|
|
|
|
|
CurrentLevel = Level,
|
|
|
|
|
Met_Level = Level,
|
|
|
|
|
TID = sav.TID,
|
|
|
|
|
SID = sav.SID,
|
|
|
|
|
OT_Name = sav.OT,
|
|
|
|
|
Ball = 4,
|
|
|
|
|
Language = sav.Language,
|
|
|
|
|
PID = Util.Rand32(),
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-23 18:31:55 +00:00
|
|
|
|
var nick = Nickname;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(nick))
|
|
|
|
|
{
|
|
|
|
|
pk.Nickname = nick;
|
2018-11-22 04:48:55 +00:00
|
|
|
|
pk.IsNicknamed = true;
|
2018-11-23 18:31:55 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-19 02:58:23 +00:00
|
|
|
|
pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, sav.Language, 7);
|
2018-11-23 18:31:55 +00:00
|
|
|
|
}
|
2018-11-22 04:48:55 +00:00
|
|
|
|
|
2021-01-05 17:39:50 +00:00
|
|
|
|
pk.IV_DEF = pk.IV_SPD = (IV_DEF * 2) + 1;
|
|
|
|
|
pk.IV_ATK = pk.IV_SPA = (IV_ATK * 2) + 1;
|
|
|
|
|
pk.IV_HP = (IV_HP * 2) + 1;
|
2018-11-22 04:48:55 +00:00
|
|
|
|
pk.IV_SPE = Util.Rand.Next(32);
|
|
|
|
|
|
2019-02-10 04:07:15 +00:00
|
|
|
|
var pi = pk.PersonalInfo;
|
2019-10-04 05:21:33 +00:00
|
|
|
|
const int av = 3;
|
2019-02-10 04:07:15 +00:00
|
|
|
|
pk.Gender = criteria.GetGender(Gender, pi);
|
|
|
|
|
pk.Nature = (int)criteria.GetNature(Nature.Random);
|
2020-06-23 03:01:42 +00:00
|
|
|
|
pk.RefreshAbility(criteria.GetAbilityFromType(av, pi));
|
2019-02-10 04:07:15 +00:00
|
|
|
|
|
2020-11-05 04:55:47 +00:00
|
|
|
|
bool isShiny = pk.IsShiny;
|
|
|
|
|
if (IsShiny && !isShiny) // Force Square
|
2020-11-04 03:28:41 +00:00
|
|
|
|
pk.PID = (uint)(((sav.TID ^ sav.SID ^ (pk.PID & 0xFFFF) ^ 0) << 16) | (pk.PID & 0xFFFF));
|
2020-11-05 04:55:47 +00:00
|
|
|
|
else if (isShiny)
|
2020-11-04 03:28:41 +00:00
|
|
|
|
pk.PID ^= 0x1000_0000;
|
2018-11-22 04:48:55 +00:00
|
|
|
|
|
|
|
|
|
var moves = MoveLevelUp.GetEncounterMoves(pk, Level, GameVersion.GO);
|
|
|
|
|
pk.Moves = moves;
|
|
|
|
|
pk.SetMaximumPPCurrent(moves);
|
|
|
|
|
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
|
|
|
|
|
2018-12-07 05:03:33 +00:00
|
|
|
|
pk.HeightScalar = HeightScalar;
|
|
|
|
|
pk.WeightScalar = WeightScalar;
|
2018-11-22 04:48:55 +00:00
|
|
|
|
|
|
|
|
|
pk.AwakeningSetAllTo(2);
|
|
|
|
|
pk.ResetCalculatedValues();
|
|
|
|
|
|
|
|
|
|
pk.SetRandomEC();
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
2018-11-15 03:34:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|