Minor clean

This commit is contained in:
Kurt 2022-08-30 15:00:45 -07:00
parent 319a671a6d
commit 66e0613d82
31 changed files with 82 additions and 64 deletions

View file

@ -51,19 +51,11 @@ public static class MoveSetApplicator
return m;
}
/// <summary>
/// Fetches <see cref="PKM.RelearnMoves"/> based on the provided <see cref="LegalityAnalysis"/>.
/// </summary>
/// <param name="pk">Pokémon to modify.</param>
/// <param name="enc">Encounter the relearn moves should be suggested for. If not provided, will try to detect it via legality analysis. </param>
/// <returns><see cref="PKM.RelearnMoves"/> best suited for the current <see cref="PKM"/> data.</returns>
public static IReadOnlyList<ushort> GetSuggestedRelearnMoves(this PKM pk, IEncounterTemplate? enc = null) => GetSuggestedRelearnMoves(new LegalityAnalysis(pk), enc);
/// <summary>
/// Fetches <see cref="PKM.RelearnMoves"/> based on the provided <see cref="LegalityAnalysis"/>.
/// </summary>
/// <param name="legal"><see cref="LegalityAnalysis"/> which contains parsed information pertaining to legality.</param>
/// <param name="enc">Encounter the relearn moves should be suggested for. If not provided, will try to detect it via legality analysis. </param>
/// <param name="enc">Encounter the relearn moves should be suggested for. If not provided, will use the original encounter from the analysis. </param>
/// <returns><see cref="PKM.RelearnMoves"/> best suited for the current <see cref="PKM"/> data.</returns>
public static IReadOnlyList<ushort> GetSuggestedRelearnMoves(this LegalityAnalysis legal, IEncounterTemplate? enc = null)
{

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@ -24,7 +24,7 @@ public sealed class BatchEditor
/// <returns>Result of the attempted modification.</returns>
public bool Process(PKM pk, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications)
{
if (pk.Species <= 0)
if (pk.Species == 0)
return false;
if (!pk.Valid)
{

View file

@ -62,7 +62,7 @@ public static class EntityTemplates
private static ushort GetTemplateSpecies(PKM pk, ITrainerInfo tr)
{
ushort species = tr is IGameValueLimit s ? s.MaxSpeciesID : ((GameVersion)pk.Version).GetMaxSpeciesID();
if (species <= 0)
if (species == 0)
species = pk.MaxSpeciesID;
return species;
}

View file

@ -262,7 +262,7 @@ public sealed class ShowdownSet : IBattleTemplate
private string GetText(GameStrings? strings = null)
{
if (Species is <= 0 or > MAX_SPECIES)
if (Species is 0 or > MAX_SPECIES)
return string.Empty;
if (strings != null)
@ -402,7 +402,7 @@ public sealed class ShowdownSet : IBattleTemplate
/// <returns>New ShowdownSet object representing the input <see cref="pk"/></returns>
public ShowdownSet(PKM pk)
{
if (pk.Species <= 0)
if (pk.Species == 0)
return;
Context = pk.Context;

View file

@ -118,7 +118,7 @@ public static class Breeding
}
/// <summary>
/// Some species can have forms that cannot exist as egg (event/special forms). Same idea as <see cref="FormInfo.IsTotemForm(ushort,int,int)"/>
/// Some species can have forms that cannot exist as egg (event/special forms). Same idea as <see cref="FormInfo.IsTotemForm(ushort,byte,int)"/>
/// </summary>
/// <returns>True if can be bred.</returns>
private static bool IsBreedableForm(ushort species, byte form) => species switch

View file

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core;

View file

@ -46,7 +46,7 @@ public static class MoveEgg
return Array.Empty<ushort>();
var entry = table[species];
if (form <= 0 || entry.FormTableIndex <= species)
if (form == 0 || species >= entry.FormTableIndex)
return entry.Moves;
// Sanity check form in the event it is out of range.

View file

@ -59,7 +59,7 @@ public readonly record struct SeedInfo(uint Seed, bool Charm3 = false)
foreach (var seed in seeds)
yield return new SeedInfo(seed);
}
/// <summary>
/// Yields an enumerable list of seeds until another valid PID breaks the chain.
/// </summary>

View file

@ -149,7 +149,7 @@ public sealed partial class MemoryContext8 : MemoryContext
{
if (memory >= MemoryFeelings.Length)
return false;
if (feeling <= 0)
if (feeling == 0)
return false; // Different from Gen6; this +1 is to match them treating 0 as empty
return (MemoryFeelings[memory] & (1 << --feeling)) != 0;
}

View file

@ -91,19 +91,30 @@ public static partial class Legal
(int)Meowstic, // (M/F) form specific
};
private static bool[] GetPermitList(int max, ReadOnlySpan<ushort> held)
/// <summary>
/// Gets a permit list with the permitted indexes, then un-flags the indexes that are not permitted.
/// </summary>
/// <param name="max">Maximum index expected to allow</param>
/// <param name="allowed">Allowed indexes</param>
private static bool[] GetPermitList(int max, ReadOnlySpan<ushort> allowed)
{
var result = new bool[max + 1];
foreach (var item in held)
result[item] = true;
foreach (var index in allowed)
result[index] = true;
return result;
}
private static bool[] GetPermitList(int max, ReadOnlySpan<ushort> held, ReadOnlySpan<ushort> unreleased)
/// <summary>
/// Gets a permit list with the permitted indexes, then un-flags the indexes that are not permitted.
/// </summary>
/// <param name="max">Maximum index expected to allow</param>
/// <param name="allowed">Allowed indexes (may have some disallowed)</param>
/// <param name="disallow">Disallowed indexes</param>
private static bool[] GetPermitList(int max, ReadOnlySpan<ushort> allowed, ReadOnlySpan<ushort> disallow)
{
var result = GetPermitList(max, held);
foreach (var u in unreleased)
result[u] = false;
var result = GetPermitList(max, allowed);
foreach (var index in disallow)
result[index] = false;
return result;
}
}

View file

@ -97,6 +97,7 @@ public static partial class Legal
060, 061, 062, 063, 065, 066, 067, 068, 069, 070 , 072, 073, 074 , 076 , 078, 079, 080,
081, 082, 083, 085, 086, 087,
};
// 155 - 158 Sevii Isle 6-9 Unused
// 171 - 173 Sevii Isle 22-24 Unused
internal static readonly HashSet<byte> ValidMet_FRLG = new()

View file

@ -138,13 +138,18 @@ public static partial class Legal
internal static int GetTransfer45MetLocation(PKM pk)
{
// Everything except for crown beasts and Celebi get the default transfer location.
// Crown beasts and Celebi are 100% identifiable by the species ID and fateful encounter, originating from Gen4.
if (!pk.Gen4 || !pk.FatefulEncounter)
return Locations.Transfer4; // Pokétransfer
return pk.Species switch
{
243 or 244 or 245 => Locations.Transfer4_CrownUnused, // Beast
251 => Locations.Transfer4_CelebiUnused, // Celebi
// Crown Beast
(int)Species.Raikou or (int)Species.Entei or (int)Species.Suicune => Locations.Transfer4_CrownUnused,
// Celebi
(int)Species.Celebi => Locations.Transfer4_CelebiUnused,
// Default
_ => Locations.Transfer4,
};
}

View file

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core;

View file

@ -57,7 +57,7 @@ public sealed class WR7 : DataMysteryGift
// unknown: region from 0x10 to 0xFF ?
public override ushort Species
public override ushort Species
{
get => ReadUInt16LittleEndian(Data.AsSpan(0x10C));
set => WriteUInt16LittleEndian(Data.AsSpan(0x10C), value);

View file

@ -62,7 +62,7 @@ public sealed class PB7 : G6PKM, IHyperTrain, IAwakened, IScaledSizeValue, IComb
set => WriteUInt16LittleEndian(Data.AsSpan(0x06), value);
}
public override ushort Species
public override ushort Species
{
get => ReadUInt16LittleEndian(Data.AsSpan(0x08));
set => WriteUInt16LittleEndian(Data.AsSpan(0x08), value);

View file

@ -71,7 +71,7 @@ public sealed class PK3 : G3PKM, ISanityChecksum
#region Block A
public override ushort SpeciesID3 { get => ReadUInt16LittleEndian(Data.AsSpan(0x20)); set => WriteUInt16LittleEndian(Data.AsSpan(0x20), value); } // raw access
public override ushort Species
public override ushort Species
{
get => SpeciesConverter.GetG4Species(SpeciesID3);
set

View file

@ -50,7 +50,7 @@ public sealed class PK6 : G6PKM, IRibbonSetEvent3, IRibbonSetEvent4, IRibbonSetC
set => WriteUInt16LittleEndian(Data.AsSpan(0x06), value);
}
public override ushort Species
public override ushort Species
{
get => ReadUInt16LittleEndian(Data.AsSpan(0x08));
set => WriteUInt16LittleEndian(Data.AsSpan(0x08), value);

View file

@ -51,7 +51,7 @@ public sealed class PK7 : G6PKM, IRibbonSetEvent3, IRibbonSetEvent4, IRibbonSetC
set => WriteUInt16LittleEndian(Data.AsSpan(0x06), value);
}
public override ushort Species
public override ushort Species
{
get => ReadUInt16LittleEndian(Data.AsSpan(0x08));
set => WriteUInt16LittleEndian(Data.AsSpan(0x08), value);

View file

@ -64,7 +64,7 @@ public static class EntityPID
return pid;
}
}
/// <summary>
/// Gets the Unown Forme ID from PID.
/// </summary>

View file

@ -82,7 +82,7 @@ public abstract class PersonalInfo : IPersonalInfo
public bool HasForm(byte form)
{
if (form <= 0) // no form requested
if (form == 0) // no form requested
return false;
if (FormStatsIndex <= 0) // no forms present
return false;

View file

@ -508,7 +508,7 @@ public sealed class SAV1 : SaveFile, ILangDeviantSave, IEventFlagArray
private bool CanSetDex(ushort species)
{
if (species <= 0)
if (species == 0)
return false;
if (species > MaxSpeciesID)
return false;

View file

@ -108,7 +108,7 @@ public sealed class Zukan5 : Zukan
}
return false;
}
private int FormLen => SAV is SAV5B2W2 ? 0xB : 0x9;
private int FormDex => 0x8 + (BitSeenSize * 9);

View file

@ -533,7 +533,7 @@ public sealed class Zukan8 : ZukanBase
SetUnk1Count(species, 0);
SetUnk2Count(species, 0);
}
public override void SeenAll(bool shinyToo = false)
{
SetAllSeen(true, shinyToo);

View file

@ -482,7 +482,7 @@ public partial class Main : Form
// Get Simulator Data
var Set = new ShowdownSet(Clipboard.GetText());
if (Set.Species < 0)
if (Set.Species == 0)
{ WinFormsUtil.Alert(MsgSimulatorFailClipboard); return; }
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSimulatorLoad, Set.Text))

View file

@ -227,7 +227,7 @@ public partial class BatchEditor : Form
var pk = data[i].Entity;
var spec = pk.Species;
if (spec <= 0 || spec > max)
if (spec == 0 || spec > max)
continue;
if (entry.Source is SlotInfoBox info && SAV.GetSlotFlags(info.Box, info.Slot).IsOverwriteProtected())

View file

@ -224,15 +224,15 @@ public partial class SAV_Encounters : Form
private IEnumerable<IEncounterInfo> SearchDatabase(CancellationToken token)
{
var settings = GetSearchSettings();
var moves = settings.Moves.ToArray();
// If nothing is specified, instead of just returning all possible encounters, just return nothing.
if (settings.Species <= 0 && moves.Length == 0 && Main.Settings.EncounterDb.ReturnNoneIfEmptySearch)
if (settings.Species == 0 && settings.Moves.Count == 0 && Main.Settings.EncounterDb.ReturnNoneIfEmptySearch)
return Array.Empty<IEncounterInfo>();
var pk = SAV.BlankPKM;
var moves = settings.Moves.ToArray();
var versions = settings.GetVersions(SAV);
var species = settings.Species <= 0 ? GetFullRange(SAV.MaxSpeciesID) : new[] { settings.Species };
var species = settings.Species == 0 ? GetFullRange(SAV.MaxSpeciesID) : new[] { settings.Species };
var results = GetAllSpeciesFormEncounters(species, SAV.Personal, versions, moves, pk, token);
if (settings.SearchEgg != null)
results = results.Where(z => z.EggEncounter == settings.SearchEgg);

View file

@ -153,7 +153,7 @@ public partial class SAV_PokedexORAS : Form
private void SetEntry()
{
if (species < 0)
if (species == 0)
return;
Zukan.SetCaught(species, CP[0].Checked);

View file

@ -241,7 +241,7 @@ public partial class SAV_PokedexGG : Form
private void SetEntry()
{
if (currentSpecies <= 0)
if (currentSpecies == 0)
return;
int pk = currentSpecies - 1;

View file

@ -226,16 +226,16 @@ public partial class SAV_PokedexSM : Form
private void SetEntry()
{
if (currentSpecies <= 0)
if (currentSpecies == 0)
return;
int pk = currentSpecies - 1;
int bit = currentSpecies - 1;
for (int i = 0; i < 4; i++)
Dex.SetSeen(currentSpecies, i, CP[i + 1].Checked);
for (int i = 0; i < 4; i++)
Dex.SetDisplayed(pk, i, CP[i + 5].Checked);
Dex.SetDisplayed(bit, i, CP[i + 5].Checked);
if (currentSpecies > SAV.MaxSpeciesID)
return;
@ -243,7 +243,7 @@ public partial class SAV_PokedexSM : Form
Dex.SetCaught(currentSpecies, CHK_P1.Checked);
for (int i = 0; i < 9; i++)
Dex.SetLanguageFlag(pk, i, CL[i].Checked);
Dex.SetLanguageFlag(bit, i, CL[i].Checked);
}
private void B_Cancel_Click(object sender, EventArgs e)

View file

@ -86,8 +86,12 @@ public partial class SAV_Wondercard : Form
try
{
// only check if the form is visible (not opening)
if (Visible && g.GiftUsed && DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgMsyteryGiftUsedAlert, MsgMysteryGiftUsedFix))
g.GiftUsed = false;
if (Visible && g.GiftUsed)
{
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgMsyteryGiftUsedAlert, MsgMysteryGiftUsedFix);
if (prompt == DialogResult.Yes)
g.GiftUsed = false;
}
RTB.Lines = g.GetDescription().ToArray();
PB_Preview.Image = g.Sprite();
@ -96,8 +100,8 @@ public partial class SAV_Wondercard : Form
// Some user input mystery gifts can have out-of-bounds values. Just swallow any exception.
catch (Exception e)
{
WinFormsUtil.Error(MsgMysteryGiftParseTypeUnknown, e);
RTB.Clear();
WinFormsUtil.Error(MsgMysteryGiftParseTypeUnknown, e);
}
}
@ -128,17 +132,21 @@ public partial class SAV_Wondercard : Form
// Mystery Gift IO (.file<->window)
private void B_Import_Click(object sender, EventArgs e)
{
using var import = new OpenFileDialog {Filter = WinFormsUtil.GetMysterGiftFilter(SAV.Generation, SAV.Version) };
if (import.ShowDialog() != DialogResult.OK) return;
var fileFilter = WinFormsUtil.GetMysterGiftFilter(SAV.Generation, SAV.Version);
using var import = new OpenFileDialog { Filter = fileFilter };
if (import.ShowDialog() != DialogResult.OK)
return;
string path = import.FileName;
var g = MysteryGift.GetMysteryGift(File.ReadAllBytes(path), Path.GetExtension(path));
if (g == null)
var path = import.FileName;
var data = File.ReadAllBytes(path);
var ext = Path.GetExtension(path);
var gift = MysteryGift.GetMysteryGift(data, ext);
if (gift == null)
{
WinFormsUtil.Error(MsgMysteryGiftInvalid, path);
return;
}
ViewGiftData(g);
ViewGiftData(gift);
}
private void B_Output_Click(object sender, EventArgs e)
@ -148,18 +156,21 @@ public partial class SAV_Wondercard : Form
WinFormsUtil.ExportMGDialog(mg, SAV.Version);
}
private static int GetLastUnfilledByType(MysteryGift Gift, MysteryGiftAlbum Album)
private static int GetLastUnfilledByType(MysteryGift gift, MysteryGiftAlbum album)
{
for (int i = 0; i < Album.Gifts.Length; i++)
var gifts = album.Gifts;
for (int i = 0; i < gifts.Length; i++)
{
if (!Album.Gifts[i].Empty)
var exist = gifts[i];
if (!exist.Empty)
continue;
if (Album.Gifts[i].Type != Gift.Type)
if (exist.Type != gift.Type)
continue;
return i;
}
return -1;
}
// Mystery Gift RW (window<->sav)
private void ClickView(object sender, EventArgs e)
{

View file

@ -66,7 +66,7 @@ public class BreedTests
var test = MoveBreed.Validate(gen, (ushort)species, form, game, moves, result);
test.Should().BeFalse();
}
[Theory]
[InlineData(GD, Bulbasaur, 0, Growl, Tackle)] // swap order, two base moves
[InlineData(UM, Charmander, 0, Ember, BellyDrum, Scratch, Growl)] // swap order, inherit + egg moves