Minor clean

This commit is contained in:
Kurt 2021-12-09 19:30:12 -08:00
parent e84932badd
commit f1fe2f6a8c
10 changed files with 88 additions and 94 deletions

View file

@ -60,9 +60,9 @@ namespace PKHeX.Core
private static List<SlotInfoMisc> GetExtraSlots2(SAV2 sav)
{
return new()
return new List<SlotInfoMisc>
{
new SlotInfoMisc(sav.Data, 0, sav.GetDaycareSlotOffset(0, 2)) {Type = StorageSlotType.Daycare }, // egg
new(sav.Data, 0, sav.GetDaycareSlotOffset(0, 2)) {Type = StorageSlotType.Daycare }, // egg
};
}
@ -89,52 +89,52 @@ namespace PKHeX.Core
private static List<SlotInfoMisc> GetExtraSlots5(SAV5 sav)
{
return new()
return new List<SlotInfoMisc>
{
new SlotInfoMisc(sav.Data, 0, sav.GTS) {Type = StorageSlotType.GTS},
new SlotInfoMisc(sav.Data, 0, sav.Fused) {Type = StorageSlotType.Fused},
new SlotInfoMisc(sav.Data, 0, sav.PGL) { Type = StorageSlotType.Misc },
new(sav.Data, 0, sav.GTS) {Type = StorageSlotType.GTS},
new(sav.Data, 0, sav.Fused) {Type = StorageSlotType.Fused},
new(sav.Data, 0, sav.PGL) { Type = StorageSlotType.Misc },
new SlotInfoMisc(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox},
};
}
private static List<SlotInfoMisc> GetExtraSlots6XY(SAV6XY sav)
{
return new()
return new List<SlotInfoMisc>
{
new SlotInfoMisc(sav.Data, 0, sav.GTS) {Type = StorageSlotType.GTS},
new SlotInfoMisc(sav.Data, 0, sav.Fused) {Type = StorageSlotType.Fused},
new SlotInfoMisc(sav.Data, 0, sav.SUBE.Give) {Type = StorageSlotType.Misc}, // Old Man
new(sav.Data, 0, sav.GTS) {Type = StorageSlotType.GTS},
new(sav.Data, 0, sav.Fused) {Type = StorageSlotType.Fused},
new(sav.Data, 0, sav.SUBE.Give) {Type = StorageSlotType.Misc}, // Old Man
new SlotInfoMisc(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox},
};
}
private static List<SlotInfoMisc> GetExtraSlots6AO(SAV6AO sav)
{
return new()
return new List<SlotInfoMisc>
{
new SlotInfoMisc(sav.Data, 0, SAV6AO.GTS) {Type = StorageSlotType.GTS},
new SlotInfoMisc(sav.Data, 0, SAV6AO.Fused) {Type = StorageSlotType.Fused},
new SlotInfoMisc(sav.Data, 0, sav.SUBE.Give) {Type = StorageSlotType.Misc},
new(sav.Data, 0, SAV6AO.GTS) {Type = StorageSlotType.GTS},
new(sav.Data, 0, SAV6AO.Fused) {Type = StorageSlotType.Fused},
new(sav.Data, 0, sav.SUBE.Give) {Type = StorageSlotType.Misc},
new SlotInfoMisc(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox},
new(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox},
};
}
@ -171,9 +171,9 @@ namespace PKHeX.Core
private static List<SlotInfoMisc> GetExtraSlots7b(SAV7b sav)
{
return new()
return new List<SlotInfoMisc>
{
new SlotInfoMisc(sav.Data, 0, sav.Blocks.GetBlockOffset(BelugaBlockIndex.Daycare) + 8, true) {Type = StorageSlotType.Daycare},
new(sav.Data, 0, sav.Blocks.GetBlockOffset(BelugaBlockIndex.Daycare) + 8, true) {Type = StorageSlotType.Daycare},
};
}
@ -205,17 +205,17 @@ namespace PKHeX.Core
private static List<SlotInfoMisc> GetExtraSlots8b(SAV8BS sav)
{
return new()
return new List<SlotInfoMisc>
{
new SlotInfoMisc(sav.Data, 0, sav.UgSaveData.GetSlotOffset(0), true) { Type = StorageSlotType.Misc },
new SlotInfoMisc(sav.Data, 1, sav.UgSaveData.GetSlotOffset(1), true) { Type = StorageSlotType.Misc },
new SlotInfoMisc(sav.Data, 2, sav.UgSaveData.GetSlotOffset(2), true) { Type = StorageSlotType.Misc },
new SlotInfoMisc(sav.Data, 3, sav.UgSaveData.GetSlotOffset(3), true) { Type = StorageSlotType.Misc },
new SlotInfoMisc(sav.Data, 4, sav.UgSaveData.GetSlotOffset(4), true) { Type = StorageSlotType.Misc },
new SlotInfoMisc(sav.Data, 5, sav.UgSaveData.GetSlotOffset(5), true) { Type = StorageSlotType.Misc },
new SlotInfoMisc(sav.Data, 6, sav.UgSaveData.GetSlotOffset(6), true) { Type = StorageSlotType.Misc },
new SlotInfoMisc(sav.Data, 7, sav.UgSaveData.GetSlotOffset(7), true) { Type = StorageSlotType.Misc },
new SlotInfoMisc(sav.Data, 8, sav.UgSaveData.GetSlotOffset(8), true) { Type = StorageSlotType.Misc },
new(sav.Data, 0, sav.UgSaveData.GetSlotOffset(0), true) { Type = StorageSlotType.Misc },
new(sav.Data, 1, sav.UgSaveData.GetSlotOffset(1), true) { Type = StorageSlotType.Misc },
new(sav.Data, 2, sav.UgSaveData.GetSlotOffset(2), true) { Type = StorageSlotType.Misc },
new(sav.Data, 3, sav.UgSaveData.GetSlotOffset(3), true) { Type = StorageSlotType.Misc },
new(sav.Data, 4, sav.UgSaveData.GetSlotOffset(4), true) { Type = StorageSlotType.Misc },
new(sav.Data, 5, sav.UgSaveData.GetSlotOffset(5), true) { Type = StorageSlotType.Misc },
new(sav.Data, 6, sav.UgSaveData.GetSlotOffset(6), true) { Type = StorageSlotType.Misc },
new(sav.Data, 7, sav.UgSaveData.GetSlotOffset(7), true) { Type = StorageSlotType.Misc },
new(sav.Data, 8, sav.UgSaveData.GetSlotOffset(8), true) { Type = StorageSlotType.Misc },
};
}
}

View file

@ -6,10 +6,8 @@ namespace PKHeX.Core
/// Generation 8 Nest Encounter (Distributed Crystal Data)
/// </summary>
/// <inheritdoc cref="EncounterStatic8Nest{T}"/>
public sealed record EncounterStatic8NC : EncounterStatic8Nest<EncounterStatic8NC>
public sealed record EncounterStatic8NC(GameVersion Version) : EncounterStatic8Nest<EncounterStatic8NC>(Version)
{
public EncounterStatic8NC(GameVersion game) : base(game) { }
protected override bool IsMatchLocation(PKM pkm)
{
var loc = pkm.Met_Location;

View file

@ -8,12 +8,10 @@ namespace PKHeX.Core
/// <see cref="EncounterStatic8"/> with multiple references (used for multiple met locations)
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed record EncounterStatic8S : EncounterStatic8
public sealed record EncounterStatic8S(GameVersion Version) : EncounterStatic8(Version)
{
public override int Location { get => Locations[0]; init { } }
public IReadOnlyList<int> Locations { get; init; } = Array.Empty<int>();
protected override bool IsMatchLocation(PKM pkm) => Locations.Contains(pkm.Met_Location);
public EncounterStatic8S(GameVersion game) : base(game) { }
}
}

View file

@ -86,12 +86,9 @@ namespace PKHeX.Core
/// <param name="s">Template data (end result).</param>
/// <param name="pi">Personal info the end result will exist with.</param>
/// <returns>Initialized criteria data to be passed to generators.</returns>
public static EncounterCriteria GetCriteria(IBattleTemplate s, PersonalInfo pi)
public static EncounterCriteria GetCriteria(IBattleTemplate s, PersonalInfo pi) => new()
{
int gender = s.Gender;
return new EncounterCriteria
{
Gender = gender,
Gender = s.Gender,
IV_HP = s.IVs[0],
IV_ATK = s.IVs[1],
IV_DEF = s.IVs[2],
@ -104,7 +101,6 @@ namespace PKHeX.Core
Nature = NatureUtil.GetNature(s.Nature),
Shiny = s.Shiny ? Shiny.Always : Shiny.Never,
};
}
private static AbilityPermission GetAbilityNumber(int ability, PersonalInfo pi)
{

View file

@ -99,8 +99,8 @@ namespace PKHeX.Core
{
for (int i = 0; i < ranges.Length; ++i)
{
var span = ranges[i];
if (esv >= span.Min && esv <= span.Max)
var (min, max) = ranges[i];
if (esv >= min && esv <= max)
return i;
}
return Invalid;

View file

@ -77,10 +77,9 @@ public static class ContestStatInfo
var avg = Math.Max(1, nature % 6 == 0 ? rawAvg : GetAverageFeel(s, nature, initial));
avg = Math.Min(rawAvg, avg); // be generous
if (pokeBlock3)
return Math.Min(MaxContestStat, Math.Max(WorstFeelBlock, avg));
else
return Math.Min(MaxContestStat, Math.Max(WorstFeelPoffin, avg));
var worst = pokeBlock3 ? WorstFeelBlock : WorstFeelPoffin;
return Math.Min(MaxContestStat, Math.Max(worst, avg));
}
private static int GetAverageFeel(IContestStats s, int nature, IContestStats initial)

View file

@ -154,11 +154,9 @@ namespace PKHeX.WinForms
if (File.Exists(path))
File.Delete(path);
}
else if (entry.Source is SlotInfoBox b && entry.SAV == SAV)
else if (entry.Source is SlotInfoBox(var box, var slot) && entry.SAV == SAV)
{
// Data from Box: Delete from save file
int box = b.Box;
int slot = b.Slot;
var change = new SlotInfoBox(box, slot);
var pkSAV = change.Read(SAV);

View file

@ -319,9 +319,9 @@ namespace PKHeX.WinForms
private void ChangeStatVal(object sender, EventArgs e)
{
if (editingval)
if (editingval || sender is not NumericUpDown nud)
return;
int n = Array.IndexOf(StatNUDA, sender);
int n = Array.IndexOf(StatNUDA, nud);
if (n < 0)
return;
StatAddrControl(SetValToSav: n, SetSavToVal: false);

View file

@ -109,12 +109,12 @@ namespace PKHeX.WinForms
if (index == CurrentGroup)
return;
var group = Groups[index];
Regenerate(group.Slots.Length);
var (_, slots) = Groups[index];
Regenerate(slots.Length);
var sav = SAV;
for (int i = 0; i < group.Slots.Length; i++)
Box.Entries[i].Image = group.Slots[i].Sprite(sav, -1, -1, true);
for (int i = 0; i < slots.Length; i++)
Box.Entries[i].Image = slots[i].Sprite(sav, -1, -1, true);
if (slotSelected != -1 && (uint)slotSelected < Box.Entries.Count)
Box.Entries[slotSelected].BackgroundImage = groupSelected != index ? null : SpriteUtil.Spriter.View;

View file

@ -44,33 +44,38 @@ namespace PKHeX.Tests.PKM
{
// Method 3, reversed for Unown.
var m3R = new PK3 { PID = 0x3DD1BB49, IVs = new[] { 23, 12, 31, 09, 03, 03 }, Species = 001 }; // Regular
var m3t = MethodFinder.Analyze(m3R).Type;
Assert.Equal(PIDType.Method_3, m3t);
var (type3, _) = MethodFinder.Analyze(m3R);
Assert.Equal(PIDType.Method_3, type3);
var m3u = new PK3 { PID = 0xBB493DD1, IVs = new[] { 23, 12, 31, 09, 03, 03 }, Species = 201 }; // Unown
var u3t = MethodFinder.Analyze(m3u).Type;
Assert.Equal(PIDType.Method_3_Unown, u3t);
var (type3R, _) = MethodFinder.Analyze(m3u);
Assert.Equal(PIDType.Method_3_Unown, type3R);
}
[Fact]
public void PIDIVMatchingTest3Misc()
public void PIDIVMatchingTest3MiscCXD()
{
// Colosseum / XD
var pk3 = new PK3 {PID = 0x0985A297, IVs = new[] {06, 01, 00, 07, 17, 07}};
var ak3 = MethodFinder.Analyze(pk3);
Assert.Equal(PIDType.CXD, MethodFinder.Analyze(pk3).Type);
var (type, seed) = MethodFinder.Analyze(pk3);
Assert.Equal(PIDType.CXD, type);
var gk3 = new PK3();
PIDGenerator.SetValuesFromSeed(gk3, PIDType.CXD, ak3.OriginSeed);
PIDGenerator.SetValuesFromSeed(gk3, PIDType.CXD, seed);
Assert.Equal(pk3.PID, gk3.PID);
Assert.True(pk3.IVs.SequenceEqual(gk3.IVs), "Unable to match generated IVs to CXD spread");
}
[Fact]
public void PIDIVMatchingTest3MiscChannel()
{
// Channel Jirachi
var pkC = new PK3 {PID = 0x264750D9, IVs = new[] {06, 31, 14, 27, 05, 27}, SID = 45819, OT_Gender = 1, Version = (int)GameVersion.R};
var akC = MethodFinder.Analyze(pkC);
Assert.Equal(PIDType.Channel,akC.Type);
var (type, seed) = MethodFinder.Analyze(pkC);
Assert.Equal(PIDType.Channel,type);
var gkC = new PK3();
PIDGenerator.SetValuesFromSeed(gkC, PIDType.Channel, akC.OriginSeed);
PIDGenerator.SetValuesFromSeed(gkC, PIDType.Channel, seed);
Assert.Equal(pkC.PID, gkC.PID);
Assert.True(pkC.IVs.SequenceEqual(gkC.IVs), "Unable to match generated IVs to Channel spread");
}