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) 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) private static List<SlotInfoMisc> GetExtraSlots5(SAV5 sav)
{ {
return new() return new List<SlotInfoMisc>
{ {
new SlotInfoMisc(sav.Data, 0, sav.GTS) {Type = StorageSlotType.GTS}, new(sav.Data, 0, sav.GTS) {Type = StorageSlotType.GTS},
new SlotInfoMisc(sav.Data, 0, sav.Fused) {Type = StorageSlotType.Fused}, new(sav.Data, 0, sav.Fused) {Type = StorageSlotType.Fused},
new SlotInfoMisc(sav.Data, 0, sav.PGL) { Type = StorageSlotType.Misc }, new(sav.Data, 0, sav.PGL) { Type = StorageSlotType.Misc },
new SlotInfoMisc(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox},
}; };
} }
private static List<SlotInfoMisc> GetExtraSlots6XY(SAV6XY sav) private static List<SlotInfoMisc> GetExtraSlots6XY(SAV6XY sav)
{ {
return new() return new List<SlotInfoMisc>
{ {
new SlotInfoMisc(sav.Data, 0, sav.GTS) {Type = StorageSlotType.GTS}, new(sav.Data, 0, sav.GTS) {Type = StorageSlotType.GTS},
new SlotInfoMisc(sav.Data, 0, sav.Fused) {Type = StorageSlotType.Fused}, new(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.SUBE.Give) {Type = StorageSlotType.Misc}, // Old Man
new SlotInfoMisc(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox},
}; };
} }
private static List<SlotInfoMisc> GetExtraSlots6AO(SAV6AO sav) private static List<SlotInfoMisc> GetExtraSlots6AO(SAV6AO sav)
{ {
return new() return new List<SlotInfoMisc>
{ {
new SlotInfoMisc(sav.Data, 0, SAV6AO.GTS) {Type = StorageSlotType.GTS}, new(sav.Data, 0, SAV6AO.GTS) {Type = StorageSlotType.GTS},
new SlotInfoMisc(sav.Data, 0, SAV6AO.Fused) {Type = StorageSlotType.Fused}, new(sav.Data, 0, SAV6AO.Fused) {Type = StorageSlotType.Fused},
new SlotInfoMisc(sav.Data, 0, sav.SUBE.Give) {Type = StorageSlotType.Misc}, new(sav.Data, 0, sav.SUBE.Give) {Type = StorageSlotType.Misc},
new SlotInfoMisc(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox}, new(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox},
new SlotInfoMisc(sav.Data, 5, sav.GetBattleBoxSlot(5)) {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) 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) 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(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(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(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(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(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(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(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(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, 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) /// Generation 8 Nest Encounter (Distributed Crystal Data)
/// </summary> /// </summary>
/// <inheritdoc cref="EncounterStatic8Nest{T}"/> /// <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) protected override bool IsMatchLocation(PKM pkm)
{ {
var loc = pkm.Met_Location; 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) /// <see cref="EncounterStatic8"/> with multiple references (used for multiple met locations)
/// </summary> /// </summary>
/// <inheritdoc cref="EncounterStatic"/> /// <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 override int Location { get => Locations[0]; init { } }
public IReadOnlyList<int> Locations { get; init; } = Array.Empty<int>(); public IReadOnlyList<int> Locations { get; init; } = Array.Empty<int>();
protected override bool IsMatchLocation(PKM pkm) => Locations.Contains(pkm.Met_Location); protected override bool IsMatchLocation(PKM pkm) => Locations.Contains(pkm.Met_Location);
public EncounterStatic8S(GameVersion game) : base(game) { }
} }
} }

View file

@ -86,25 +86,21 @@ namespace PKHeX.Core
/// <param name="s">Template data (end result).</param> /// <param name="s">Template data (end result).</param>
/// <param name="pi">Personal info the end result will exist with.</param> /// <param name="pi">Personal info the end result will exist with.</param>
/// <returns>Initialized criteria data to be passed to generators.</returns> /// <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; Gender = s.Gender,
return new EncounterCriteria IV_HP = s.IVs[0],
{ IV_ATK = s.IVs[1],
Gender = gender, IV_DEF = s.IVs[2],
IV_HP = s.IVs[0], IV_SPE = s.IVs[3],
IV_ATK = s.IVs[1], IV_SPA = s.IVs[4],
IV_DEF = s.IVs[2], IV_SPD = s.IVs[5],
IV_SPE = s.IVs[3], HPType = s.HiddenPowerType,
IV_SPA = s.IVs[4],
IV_SPD = s.IVs[5],
HPType = s.HiddenPowerType,
AbilityNumber = GetAbilityNumber(s.Ability, pi), AbilityNumber = GetAbilityNumber(s.Ability, pi),
Nature = NatureUtil.GetNature(s.Nature), Nature = NatureUtil.GetNature(s.Nature),
Shiny = s.Shiny ? Shiny.Always : Shiny.Never, Shiny = s.Shiny ? Shiny.Always : Shiny.Never,
}; };
}
private static AbilityPermission GetAbilityNumber(int ability, PersonalInfo pi) 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) for (int i = 0; i < ranges.Length; ++i)
{ {
var span = ranges[i]; var (min, max) = ranges[i];
if (esv >= span.Min && esv <= span.Max) if (esv >= min && esv <= max)
return i; return i;
} }
return Invalid; 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)); var avg = Math.Max(1, nature % 6 == 0 ? rawAvg : GetAverageFeel(s, nature, initial));
avg = Math.Min(rawAvg, avg); // be generous avg = Math.Min(rawAvg, avg); // be generous
if (pokeBlock3)
return Math.Min(MaxContestStat, Math.Max(WorstFeelBlock, avg)); var worst = pokeBlock3 ? WorstFeelBlock : WorstFeelPoffin;
else return Math.Min(MaxContestStat, Math.Max(worst, avg));
return Math.Min(MaxContestStat, Math.Max(WorstFeelPoffin, avg));
} }
private static int GetAverageFeel(IContestStats s, int nature, IContestStats initial) private static int GetAverageFeel(IContestStats s, int nature, IContestStats initial)

View file

@ -154,11 +154,9 @@ namespace PKHeX.WinForms
if (File.Exists(path)) if (File.Exists(path))
File.Delete(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 // Data from Box: Delete from save file
int box = b.Box;
int slot = b.Slot;
var change = new SlotInfoBox(box, slot); var change = new SlotInfoBox(box, slot);
var pkSAV = change.Read(SAV); var pkSAV = change.Read(SAV);

View file

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

View file

@ -109,12 +109,12 @@ namespace PKHeX.WinForms
if (index == CurrentGroup) if (index == CurrentGroup)
return; return;
var group = Groups[index]; var (_, slots) = Groups[index];
Regenerate(group.Slots.Length); Regenerate(slots.Length);
var sav = SAV; var sav = SAV;
for (int i = 0; i < group.Slots.Length; i++) for (int i = 0; i < slots.Length; i++)
Box.Entries[i].Image = group.Slots[i].Sprite(sav, -1, -1, true); Box.Entries[i].Image = slots[i].Sprite(sav, -1, -1, true);
if (slotSelected != -1 && (uint)slotSelected < Box.Entries.Count) if (slotSelected != -1 && (uint)slotSelected < Box.Entries.Count)
Box.Entries[slotSelected].BackgroundImage = groupSelected != index ? null : SpriteUtil.Spriter.View; 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. // Method 3, reversed for Unown.
var m3R = new PK3 { PID = 0x3DD1BB49, IVs = new[] { 23, 12, 31, 09, 03, 03 }, Species = 001 }; // Regular var m3R = new PK3 { PID = 0x3DD1BB49, IVs = new[] { 23, 12, 31, 09, 03, 03 }, Species = 001 }; // Regular
var m3t = MethodFinder.Analyze(m3R).Type; var (type3, _) = MethodFinder.Analyze(m3R);
Assert.Equal(PIDType.Method_3, m3t); Assert.Equal(PIDType.Method_3, type3);
var m3u = new PK3 { PID = 0xBB493DD1, IVs = new[] { 23, 12, 31, 09, 03, 03 }, Species = 201 }; // Unown var m3u = new PK3 { PID = 0xBB493DD1, IVs = new[] { 23, 12, 31, 09, 03, 03 }, Species = 201 }; // Unown
var u3t = MethodFinder.Analyze(m3u).Type; var (type3R, _) = MethodFinder.Analyze(m3u);
Assert.Equal(PIDType.Method_3_Unown, u3t); Assert.Equal(PIDType.Method_3_Unown, type3R);
} }
[Fact] [Fact]
public void PIDIVMatchingTest3Misc() public void PIDIVMatchingTest3MiscCXD()
{ {
// Colosseum / XD // Colosseum / XD
var pk3 = new PK3 {PID = 0x0985A297, IVs = new[] {06, 01, 00, 07, 17, 07}}; var pk3 = new PK3 {PID = 0x0985A297, IVs = new[] {06, 01, 00, 07, 17, 07}};
var ak3 = MethodFinder.Analyze(pk3); var (type, seed) = MethodFinder.Analyze(pk3);
Assert.Equal(PIDType.CXD, MethodFinder.Analyze(pk3).Type); Assert.Equal(PIDType.CXD, type);
var gk3 = new PK3(); var gk3 = new PK3();
PIDGenerator.SetValuesFromSeed(gk3, PIDType.CXD, ak3.OriginSeed); PIDGenerator.SetValuesFromSeed(gk3, PIDType.CXD, seed);
Assert.Equal(pk3.PID, gk3.PID); Assert.Equal(pk3.PID, gk3.PID);
Assert.True(pk3.IVs.SequenceEqual(gk3.IVs), "Unable to match generated IVs to CXD spread"); Assert.True(pk3.IVs.SequenceEqual(gk3.IVs), "Unable to match generated IVs to CXD spread");
}
[Fact]
public void PIDIVMatchingTest3MiscChannel()
{
// Channel Jirachi // 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 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); var (type, seed) = MethodFinder.Analyze(pkC);
Assert.Equal(PIDType.Channel,akC.Type); Assert.Equal(PIDType.Channel,type);
var gkC = new PK3(); var gkC = new PK3();
PIDGenerator.SetValuesFromSeed(gkC, PIDType.Channel, akC.OriginSeed); PIDGenerator.SetValuesFromSeed(gkC, PIDType.Channel, seed);
Assert.Equal(pkC.PID, gkC.PID); Assert.Equal(pkC.PID, gkC.PID);
Assert.True(pkC.IVs.SequenceEqual(gkC.IVs), "Unable to match generated IVs to Channel spread"); Assert.True(pkC.IVs.SequenceEqual(gkC.IVs), "Unable to match generated IVs to Channel spread");
} }