Misc tweaks

Local event db's don't need to absorb the builtin db.
More aggressive generator filtering for fuzzed PB7's from GO (can't fake a GO8 in PB7)
Fix splitbreed relearn suggestion (chain is reversed for Origin, don't bother truncating or anything)
Only check for filtered VC ot's if transferred (not still gen1/2 format)
Remove unnecessary xmldoc, add more xmldoc
This commit is contained in:
Kurt 2024-01-08 20:01:19 -08:00
parent 96aed1e3c5
commit f80c2820f9
7 changed files with 41 additions and 33 deletions

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using static PKHeX.Core.EncountersWC3;
namespace PKHeX.Core;
@ -106,6 +107,7 @@ public static class EncounterEvent
/// <param name="paths">External folder(s) to source individual mystery gift template files from.</param>
public static void RefreshMGDB(params string[] paths)
{
// If no paths are provided, clear the arrays. See the bottom of this method.
HashSet<PCD>? g4 = null; List<PCD>? lg4 = null;
HashSet<PGF>? g5 = null; List<PGF>? lg5 = null;
HashSet<WC6>? g6 = null; List<WC6>? lg6 = null;
@ -127,25 +129,31 @@ public static class EncounterEvent
{
var added = gift switch
{
PCD pcd => AddOrExpand(ref g4, ref lg4, pcd, MGDB_G4),
PGF pgf => AddOrExpand(ref g5, ref lg5, pgf, MGDB_G5),
WC6 wc6 => AddOrExpand(ref g6, ref lg6, wc6, MGDB_G6),
WC7 wc7 => AddOrExpand(ref g7, ref lg7, wc7, MGDB_G7),
WB7 wb7 => AddOrExpand(ref b7, ref lb7, wb7, MGDB_G7GG),
WC8 wc8 => AddOrExpand(ref g8, ref lg8, wc8, MGDB_G8),
WB8 wb8 => AddOrExpand(ref b8, ref lb8, wb8, MGDB_G8B),
WA8 wa8 => AddOrExpand(ref a8, ref la8, wa8, MGDB_G8A),
WC9 wc9 => AddOrExpand(ref g9, ref lg9, wc9, MGDB_G9),
PCD pcd => AddOrExpand(ref g4, ref lg4, pcd),
PGF pgf => AddOrExpand(ref g5, ref lg5, pgf),
WC6 wc6 => AddOrExpand(ref g6, ref lg6, wc6),
WC7 wc7 => AddOrExpand(ref g7, ref lg7, wc7),
WB7 wb7 => AddOrExpand(ref b7, ref lb7, wb7),
WC8 wc8 => AddOrExpand(ref g8, ref lg8, wc8),
WB8 wb8 => AddOrExpand(ref b8, ref lb8, wb8),
WA8 wa8 => AddOrExpand(ref a8, ref la8, wa8),
WC9 wc9 => AddOrExpand(ref g9, ref lg9, wc9),
_ => false,
};
if (!added)
Trace.WriteLine($"Failed to add gift in {Path.GetDirectoryName(path)}: {gift.FileName}");
static bool AddOrExpand<T>(ref HashSet<T>? arr, ref List<T>? extra, T obj, T[] master)
static bool AddOrExpand<T>(ref HashSet<T>? arr, ref List<T>? extra, T obj)
{
arr ??= [..master];
if (arr is null)
{
// Most users won't be adding more than 1-2 gifts
// Save memory by initializing the HashSet and List minimally.
arr = new HashSet<T>(1);
extra = new List<T>(1);
}
if (arr.Add(obj))
(extra ??= []).Add(obj);
extra!.Add(obj);
return true;
}
}
@ -158,12 +166,9 @@ public static class EncounterEvent
EGDB_G8A = SetArray(la8);
EGDB_G8B = SetArray(lb8);
EGDB_G9 = SetArray(lg9);
static T[] SetArray<T>(List<T>? arr)
{
if (arr is null)
return [];
return arr.ToArray();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static T[] SetArray<T>(List<T>? update) => update is null ? [] : update.ToArray();
}
}

View file

@ -23,7 +23,7 @@ public sealed class EncounterGenerator8X : IEncounterGenerator
public IEnumerable<IEncounterable> GetEncounters(PKM pk, EvoCriteria[] chain, LegalInfo info) => (GameVersion)pk.Version switch
{
GO => EncounterGenerator8GO.Instance.GetEncounters(pk, chain, info),
GO => EncounterGeneratorGO.Instance.GetEncounters(pk, chain, info),
PLA => EncounterGenerator8a.Instance.GetEncounters(pk, chain, info),
BD or SP => EncounterGenerator8b.Instance.GetEncounters(pk, chain, info),
SW when pk.Met_Location == LocationsHOME.SWLA => EncounterGenerator8a.Instance.GetEncounters(pk, chain, info),

View file

@ -11,7 +11,7 @@ public sealed class EncounterGeneratorGO : IEncounterGenerator
var loc = pk.Met_Location;
if (loc == Locations.GO7)
return EncounterGenerator7GO.Instance.GetEncounters(pk, chain, info);
if (loc == Locations.GO8)
if (loc == Locations.GO8 && pk is not PB7)
return EncounterGenerator8GO.Instance.GetEncounters(pk, chain, info);
return [];
}

View file

@ -190,13 +190,6 @@ public static class MoveListSuggest
Span<EvoCriteria> chain = stackalloc EvoCriteria[EvolutionTree.MaxEvolutions];
var origin = new EvolutionOrigin(enc.Species, (byte)enc.Version, (byte)enc.Generation, 1, 100, OriginOptions.EncounterTemplate);
int count = EvolutionChain.GetOriginChain(chain, pk, origin);
for (int i = 0; i < count; i++)
{
if (chain[i].Species != enc.Species)
continue;
count = i;
break;
}
var evos = chain[..count].ToArray();
var other = generator.GetPossible(pk, evos, enc.Version, EncounterTypeGroup.Egg);
foreach (var incense in other)

View file

@ -122,8 +122,13 @@ public sealed class TrainerNameVerifier : Verifier
var pk = data.Entity;
// Filtered OT names use unavailable characters and can be too long
if (str.SequenceEqual(StringConverter12Transporter.GetFilteredOT(pk.Language, pk.Version)))
return;
if (pk.Format >= 7)
{
// Check if it was profanity filtered.
var filtered = StringConverter12Transporter.GetFilteredOT(pk.Language, pk.Version);
if (str.SequenceEqual(filtered))
return;
}
if (pk.Japanese)
{

View file

@ -138,6 +138,10 @@ public static class StringConverter12Transporter
0x3000, 0x3000, 0x3000, 0x3000, 0x30A9, 0x2640, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, // F
];
/// <summary>
/// Gets the Trainer Name for a Generation 1 in-game trade (NPC).
/// </summary>
/// <param name="language">Language to localize with</param>
public static string GetTradeNameGen1(int language) => language switch
{
1 => "トレーナー",
@ -152,6 +156,11 @@ public static class StringConverter12Transporter
_ => string.Empty,
};
/// <summary>
/// Gets a "safe" Trainer Name for a Generation 1 or 2 trainer, in the event the original was naughty.
/// </summary>
/// <param name="language">Language to localize with</param>
/// <param name="version">Version transferred from to Bank</param>
public static string GetFilteredOT(int language, int version) => version switch
{
(int)GameVersion.RD => language switch

View file

@ -90,10 +90,6 @@ public static class StringConverter345
/// </summary>
/// <param name="glyph">Codepoint glyph stored in data.</param>
/// <returns>Unicode private use codepoint.</returns>
/// <remarks>
/// Use two comparisons instead of one-after-subtraction.
/// Most players never select these special characters, so the hot path will be almost always false.
/// </remarks>
public static ushort GetMigratedPrivateChar(ushort glyph) =>
(ushort)(glyph - PrivateUseStartGlyph + PrivateUseStartUnicode);