From a4dde6cf1b6ef3a0bd75d20bcbdfb94b11f1d236 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 2 Jun 2024 18:56:55 -0500 Subject: [PATCH] Minor clean --- pk3DS.Core/CTR/BLZ.cs | 2 +- pk3DS.Core/Game/GARCReference.cs | 1 - pk3DS.Core/Game/GameConfig.cs | 4 +- pk3DS.Core/Game/GameVersion.cs | 28 +++++++------- pk3DS.Core/ImageUtil.cs | 2 +- pk3DS.Core/Randomizers/PersonalRandomizer.cs | 2 +- .../Structures/Moves/MoveInflictDuration.cs | 2 +- pk3DS.WinForms/ARCUtil.cs | 2 +- pk3DS.WinForms/Legality/Randomizer.cs | 2 +- pk3DS.WinForms/Main.cs | 2 +- .../Subforms/Gen6/Experimental/OWSE.cs | 7 ++-- .../Subforms/Gen6/Experimental/OWSEStructs.cs | 7 +++- .../Subforms/Gen6/MegaEvoEditor6.cs | 2 +- pk3DS.WinForms/Subforms/Gen6/MoveEditor6.cs | 4 +- pk3DS.WinForms/Subforms/Gen6/OPower.cs | 2 +- pk3DS.WinForms/Subforms/Gen6/RSTE.cs | 3 +- pk3DS.WinForms/Subforms/Gen6/RSWE.cs | 12 +++--- pk3DS.WinForms/Subforms/Gen6/TrainerRand.cs | 2 +- pk3DS.WinForms/Subforms/Gen6/XYWE.cs | 12 +++--- .../Subforms/Gen7/EvolutionEditor7.cs | 34 +++++++++++------ .../Subforms/Gen7/MegaEvoEditor7.cs | 2 +- pk3DS.WinForms/Subforms/Gen7/MoveEditor7.cs | 4 +- pk3DS.WinForms/Subforms/Gen7/PickupEditor7.cs | 4 +- pk3DS.WinForms/Subforms/Gen7/SMTE.cs | 23 ++++++----- pk3DS.WinForms/Subforms/Gen7/SMWE.cs | 38 +++++++++---------- pk3DS.WinForms/Subforms/ShinyRate.cs | 1 - pk3DS.WinForms/Tools/Scripts.cs | 2 +- pk3DS.WinForms/WinFormsUtil.cs | 4 +- 28 files changed, 110 insertions(+), 100 deletions(-) diff --git a/pk3DS.Core/CTR/BLZ.cs b/pk3DS.Core/CTR/BLZ.cs index f43b1d1..9b39eeb 100644 --- a/pk3DS.Core/CTR/BLZ.cs +++ b/pk3DS.Core/CTR/BLZ.cs @@ -172,7 +172,7 @@ private static BLZResult BLZ_Decode(byte[] data) return null; } int hdr_len = pak_buffer[pak_len - 5]; - if (hdr_len < 8 || hdr_len > 0xB) + if (hdr_len is < 8 or > 0xB) { Console.Write(Environment.NewLine + "Bad header length" + Environment.NewLine); return null; diff --git a/pk3DS.Core/Game/GARCReference.cs b/pk3DS.Core/Game/GARCReference.cs index 0546f0f..79b9235 100644 --- a/pk3DS.Core/Game/GARCReference.cs +++ b/pk3DS.Core/Game/GARCReference.cs @@ -1,5 +1,4 @@ using System.IO; -using System.Linq; namespace pk3DS.Core; diff --git a/pk3DS.Core/Game/GameConfig.cs b/pk3DS.Core/Game/GameConfig.cs index dbd62c0..c7c48f5 100644 --- a/pk3DS.Core/Game/GameConfig.cs +++ b/pk3DS.Core/Game/GameConfig.cs @@ -274,8 +274,8 @@ public string GetGARCFileName(string requestedGARC) public EvolutionSet[] Evolutions { get; private set; } public bool XY => Version == GameVersion.XY; - public bool ORAS => Version == GameVersion.ORAS || Version == GameVersion.ORASDEMO; - public bool SM => Version == GameVersion.SM || Version == GameVersion.SMDEMO; + public bool ORAS => Version is GameVersion.ORAS or GameVersion.ORASDEMO; + public bool SM => Version is GameVersion.SM or GameVersion.SMDEMO; public bool USUM => Version == GameVersion.USUM; public int MaxSpeciesID => XY || ORAS ? Legal.MaxSpeciesID_6 : SM ? Legal.MaxSpeciesID_7_SM : Legal.MaxSpeciesID_7_USUM; public int GARCVersion => XY || ORAS ? GARC.VER_4 : GARC.VER_6; diff --git a/pk3DS.Core/Game/GameVersion.cs b/pk3DS.Core/Game/GameVersion.cs index 9ad830b..83794ac 100644 --- a/pk3DS.Core/Game/GameVersion.cs +++ b/pk3DS.Core/Game/GameVersion.cs @@ -81,7 +81,7 @@ public static bool Contains(this GameVersion g1, GameVersion g2) switch (g1) { case GameVersion.RB: - return g2 == GameVersion.RD || g2 == GameVersion.BU || g2 == GameVersion.GN; + return g2 is GameVersion.RD or GameVersion.BU or GameVersion.GN; case GameVersion.RBY: return GameVersion.RB.Contains(g2) || g2 == GameVersion.YW; case GameVersion.Gen1: @@ -91,7 +91,7 @@ public static bool Contains(this GameVersion g1, GameVersion g2) case GameVersion.VCEvents: goto case GameVersion.RBY; - case GameVersion.GS: return g2 == GameVersion.GD || g2 == GameVersion.SV; + case GameVersion.GS: return g2 is GameVersion.GD or GameVersion.SV; case GameVersion.GSC: return GameVersion.GS.Contains(g2) || g2 == GameVersion.C; case GameVersion.Gen2: @@ -100,35 +100,35 @@ public static bool Contains(this GameVersion g1, GameVersion g2) case GameVersion.EventsGBGen2: goto case GameVersion.GSC; case GameVersion.GBCartEraOnly: - return g2 == GameVersion.Stadium || g2 == GameVersion.Stadium2 || g2 == GameVersion.EventsGBGen1 || g2 == GameVersion.EventsGBGen2; + return g2 is GameVersion.Stadium or GameVersion.Stadium2 or GameVersion.EventsGBGen1 or GameVersion.EventsGBGen2; - case GameVersion.RS: return g2 == GameVersion.R || g2 == GameVersion.S; - case GameVersion.FRLG: return g2 == GameVersion.FR || g2 == GameVersion.LG; - case GameVersion.CXD: return g2 == GameVersion.COLO || g2 == GameVersion.XD; + case GameVersion.RS: return g2 is GameVersion.R or GameVersion.S; + case GameVersion.FRLG: return g2 is GameVersion.FR or GameVersion.LG; + case GameVersion.CXD: return g2 is GameVersion.COLO or GameVersion.XD; case GameVersion.RSBOX: return GameVersion.RS.Contains(g2) || g2 == GameVersion.E || GameVersion.FRLG.Contains(g2); case GameVersion.Gen3: return GameVersion.RS.Contains(g2) || g2 == GameVersion.E || GameVersion.FRLG.Contains(g2) || GameVersion.CXD.Contains(g2) || g2 == GameVersion.RSBOX; - case GameVersion.DP: return g2 == GameVersion.D || g2 == GameVersion.P; - case GameVersion.HGSS: return g2 == GameVersion.HG || g2 == GameVersion.SS; + case GameVersion.DP: return g2 is GameVersion.D or GameVersion.P; + case GameVersion.HGSS: return g2 is GameVersion.HG or GameVersion.SS; case GameVersion.BATREV: return GameVersion.DP.Contains(g2) || g2 == GameVersion.Pt || GameVersion.HGSS.Contains(g2); case GameVersion.Gen4: return GameVersion.DP.Contains(g2) || g2 == GameVersion.Pt || GameVersion.HGSS.Contains(g2) || g2 == GameVersion.BATREV; - case GameVersion.BW: return g2 == GameVersion.B || g2 == GameVersion.W; - case GameVersion.B2W2: return g2 == GameVersion.B2 || g2 == GameVersion.W2; + case GameVersion.BW: return g2 is GameVersion.B or GameVersion.W; + case GameVersion.B2W2: return g2 is GameVersion.B2 or GameVersion.W2; case GameVersion.Gen5: return GameVersion.BW.Contains(g2) || GameVersion.B2W2.Contains(g2); - case GameVersion.XY: return g2 == GameVersion.X || g2 == GameVersion.Y; - case GameVersion.ORAS: return g2 == GameVersion.OR || g2 == GameVersion.AS; + case GameVersion.XY: return g2 is GameVersion.X or GameVersion.Y; + case GameVersion.ORAS: return g2 is GameVersion.OR or GameVersion.AS; case GameVersion.Gen6: return GameVersion.XY.Contains(g2) || GameVersion.ORAS.Contains(g2); case GameVersion.SM: - return g2 == GameVersion.SN || g2 == GameVersion.MN; + return g2 is GameVersion.SN or GameVersion.MN; case GameVersion.USUM: - return g2 == GameVersion.US || g2 == GameVersion.UM; + return g2 is GameVersion.US or GameVersion.UM; case GameVersion.Gen7: return GameVersion.SM.Contains(g2) || GameVersion.USUM.Contains(g2); diff --git a/pk3DS.Core/ImageUtil.cs b/pk3DS.Core/ImageUtil.cs index 57b59e6..351784d 100644 --- a/pk3DS.Core/ImageUtil.cs +++ b/pk3DS.Core/ImageUtil.cs @@ -21,7 +21,7 @@ public static class ImageUtil /// Human visible data public static Bitmap GetBitmap(this BXLIM bflim, bool crop = true) { - if (bflim.Format == XLIMEncoding.ETC1 || bflim.Format == XLIMEncoding.ETC1A4) + if (bflim.Format is XLIMEncoding.ETC1 or XLIMEncoding.ETC1A4) return GetBitmapETC(bflim, crop); var data = bflim.GetImageData(crop); return GetBitmap(data, bflim.Footer.Width, bflim.Footer.Height); diff --git a/pk3DS.Core/Randomizers/PersonalRandomizer.cs b/pk3DS.Core/Randomizers/PersonalRandomizer.cs index 4f5ed0f..6d5cd72 100644 --- a/pk3DS.Core/Randomizers/PersonalRandomizer.cs +++ b/pk3DS.Core/Randomizers/PersonalRandomizer.cs @@ -212,7 +212,7 @@ private void RandomizeTypeTutors(PersonalInfo z, int index) t[i] = rnd.Next(0, 100) < LearnTypeTutorPercent; // Make sure Rayquaza can learn Dragon Ascent. - if (!Game.XY && (index == 384 || index == 814)) + if (!Game.XY && index is 384 or 814) t[7] = true; z.TypeTutors = t; diff --git a/pk3DS.Core/Structures/Moves/MoveInflictDuration.cs b/pk3DS.Core/Structures/Moves/MoveInflictDuration.cs index b445eb3..96c851c 100644 --- a/pk3DS.Core/Structures/Moves/MoveInflictDuration.cs +++ b/pk3DS.Core/Structures/Moves/MoveInflictDuration.cs @@ -7,4 +7,4 @@ public enum MoveInflictDuration TurnCountSwitch, PermanentSwitch, TurnCountNoSwitch, -}; \ No newline at end of file +} \ No newline at end of file diff --git a/pk3DS.WinForms/ARCUtil.cs b/pk3DS.WinForms/ARCUtil.cs index 4249428..bf88773 100644 --- a/pk3DS.WinForms/ARCUtil.cs +++ b/pk3DS.WinForms/ARCUtil.cs @@ -288,7 +288,7 @@ internal static FARC AnalyzeFARC(string path) internal static string Interpret(string path) { string fn = Path.GetFileName(path); - if (fn == "save0.bin" || fn == "save1.bin" || fn == "save2.bin") + if (fn is "save0.bin" or "save1.bin" or "save2.bin") { return FixMajoraChecksum(path); } diff --git a/pk3DS.WinForms/Legality/Randomizer.cs b/pk3DS.WinForms/Legality/Randomizer.cs index 4e15fe9..4b2ded2 100644 --- a/pk3DS.WinForms/Legality/Randomizer.cs +++ b/pk3DS.WinForms/Legality/Randomizer.cs @@ -12,7 +12,7 @@ internal static int GetRandomForme(int species, bool mega, bool alola, PersonalI return 0; if (stats[species].FormeCount <= 1) return 0; - if (species == 664 || species == 665 || species == 666) // vivillon + if (species is 664 or 665 or 666) // vivillon return 30; // save file specific if (species == 774) // minior return (int)(Util.Random32() % 7); diff --git a/pk3DS.WinForms/Main.cs b/pk3DS.WinForms/Main.cs index 6567dc6..09262d5 100644 --- a/pk3DS.WinForms/Main.cs +++ b/pk3DS.WinForms/Main.cs @@ -890,7 +890,7 @@ private void RunOWSE6() Enabled = false; new Thread(() => { - bool reload = ModifierKeys == Keys.Control || ModifierKeys == (Keys.Alt | Keys.Control); + bool reload = ModifierKeys is Keys.Control or (Keys.Alt | Keys.Control); string[] files = ["encdata", "storytext", "mapGR", "mapMatrix"]; if (reload || files.Sum(t => Directory.Exists(t) ? 0 : 1) != 0) // Dev bypass if all exist already FileGet(files, false); diff --git a/pk3DS.WinForms/Subforms/Gen6/Experimental/OWSE.cs b/pk3DS.WinForms/Subforms/Gen6/Experimental/OWSE.cs index 7ab37c5..374e8ad 100644 --- a/pk3DS.WinForms/Subforms/Gen6/Experimental/OWSE.cs +++ b/pk3DS.WinForms/Subforms/Gen6/Experimental/OWSE.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Globalization; using System.IO; using System.Linq; using System.Windows.Forms; @@ -382,7 +383,7 @@ private void GetNPC() NUD_NMove2.Value = NPC.MovePermissions2; // Uneditables - TB_NDeg.Text = NPC.Deg18.ToString(); + TB_NDeg.Text = NPC.Deg18.ToString(CultureInfo.InvariantCulture); TB_Leash.Text = NPC.L1 == NPC.L2 && NPC.L2 == NPC.L3 && NPC.L3 == -1 ? TB_Leash.Text = "No Leash!" : $"{NPC.L1}, {NPC.L2}, {NPC.L3} -- {NPC.LDir}"; @@ -519,8 +520,8 @@ private void DclickDestMap(object sender, EventArgs e) { try { NUD_WE.Value = 0; } catch { } } } - private void ChangeWarp_X(object sender, EventArgs e) => L_WpX.Text = (NUD_WX.Value / 18).ToString(); - private void ChangeWarp_Y(object sender, EventArgs e) => L_WpY.Text = (NUD_WY.Value / 18).ToString(); + private void ChangeWarp_X(object sender, EventArgs e) => L_WpX.Text = (NUD_WX.Value / 18).ToString(CultureInfo.InvariantCulture); + private void ChangeWarp_Y(object sender, EventArgs e) => L_WpY.Text = (NUD_WY.Value / 18).ToString(CultureInfo.InvariantCulture); // Script Handling private void B_HLCMD_Click(object sender, EventArgs e) diff --git a/pk3DS.WinForms/Subforms/Gen6/Experimental/OWSEStructs.cs b/pk3DS.WinForms/Subforms/Gen6/Experimental/OWSEStructs.cs index fd90952..05a8f8c 100644 --- a/pk3DS.WinForms/Subforms/Gen6/Experimental/OWSEStructs.cs +++ b/pk3DS.WinForms/Subforms/Gen6/Experimental/OWSEStructs.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; +using System.Globalization; using System.IO; using System.Linq; @@ -227,7 +228,11 @@ public class CollisionObject(byte[] data) public override string ToString() { - return string.Join(", ", F1.ToString(), F2.ToString(), F3.ToString(), F4.ToString()); + return string.Join(", ", + F1.ToString(CultureInfo.InvariantCulture), + F2.ToString(CultureInfo.InvariantCulture), + F3.ToString(CultureInfo.InvariantCulture), + F4.ToString(CultureInfo.InvariantCulture)); } } } diff --git a/pk3DS.WinForms/Subforms/Gen6/MegaEvoEditor6.cs b/pk3DS.WinForms/Subforms/Gen6/MegaEvoEditor6.cs index ad489c0..8de3ab8 100644 --- a/pk3DS.WinForms/Subforms/Gen6/MegaEvoEditor6.cs +++ b/pk3DS.WinForms/Subforms/Gen6/MegaEvoEditor6.cs @@ -127,7 +127,7 @@ private void GetEntry() private void SetEntry() { - if (entry < 1 || entry == 384) return; // Don't edit invalid / Rayquaza. + if (entry is < 1 or 384) return; // Don't edit invalid / Rayquaza. for (int i = 0; i < 3; i++) { if (me.Method[i] > 1) diff --git a/pk3DS.WinForms/Subforms/Gen6/MoveEditor6.cs b/pk3DS.WinForms/Subforms/Gen6/MoveEditor6.cs index 4064c13..7ad8ea7 100644 --- a/pk3DS.WinForms/Subforms/Gen6/MoveEditor6.cs +++ b/pk3DS.WinForms/Subforms/Gen6/MoveEditor6.cs @@ -194,7 +194,7 @@ private void B_RandAll_Click(object sender, EventArgs e) for (int i = 0; i < CB_Move.Items.Count; i++) { CB_Move.SelectedIndex = i; // Get new Move - if (i == 165 || i == 174) continue; // Don't change Struggle or Curse + if (i is 165 or 174) continue; // Don't change Struggle or Curse // Change Damage Category if Not Status if (CB_Category.SelectedIndex > 0 && CHK_Category.Checked) // Not Status @@ -214,7 +214,7 @@ private void B_Metronome_Click(object sender, EventArgs e) for (int i = 0; i < CB_Move.Items.Count; i++) { CB_Move.SelectedIndex = i; - if (CB_Move.SelectedIndex != 117 || CB_Move.SelectedIndex != 32) + if (CB_Move.SelectedIndex is not (117 and 32)) NUD_PP.Value = 0; if (CB_Move.SelectedIndex == 117) NUD_PP.Value = 40; diff --git a/pk3DS.WinForms/Subforms/Gen6/OPower.cs b/pk3DS.WinForms/Subforms/Gen6/OPower.cs index e88e5d0..ae8caf8 100644 --- a/pk3DS.WinForms/Subforms/Gen6/OPower.cs +++ b/pk3DS.WinForms/Subforms/Gen6/OPower.cs @@ -110,7 +110,7 @@ private void SetEntry() byte usability = (byte)NUD_Usability.Value; - if (usability == 2 || usability == 254 || usability == 0) + if (usability is 2 or 254 or 0) powerData[entry][1] = usability; } diff --git a/pk3DS.WinForms/Subforms/Gen6/RSTE.cs b/pk3DS.WinForms/Subforms/Gen6/RSTE.cs index 2bc763b..0598099 100644 --- a/pk3DS.WinForms/Subforms/Gen6/RSTE.cs +++ b/pk3DS.WinForms/Subforms/Gen6/RSTE.cs @@ -553,7 +553,6 @@ private void Randomize() ushort[] itemvals = Main.Config.ORAS ? Legal.Pouch_Items_AO : Legal.Pouch_Items_XY; itemvals = [.. itemvals, .. Legal.Pouch_Berry_XY]; - string[] ImportantClasses = ["GYM", "ELITE", "CHAMPION"]; for (int i = 1; i < CB_TrainerID.Items.Count; i++) { // Trainer Type/Mega Evo @@ -750,7 +749,7 @@ private static void RandomizeTrainerAIClass(TrainerData6 t, string[] trClass) { int randClass() => (int)(Rand() % trClass.Length); int rv; do { rv = randClass(); } - while (rIgnoreClass.Contains(rv) || trClass[rv].StartsWith("[~") || (Main.Config.ORAS && (rv >= 0 && rv <= 63)) || (rv >= 68 && rv <= 126)); // don't allow disallowed classes + while (rIgnoreClass.Contains(rv) || trClass[rv].StartsWith("[~") || (Main.Config.ORAS && rv is >= 0 and <= 63) || rv is >= 68 and <= 126); // don't allow disallowed classes t.Class = rv; } } diff --git a/pk3DS.WinForms/Subforms/Gen6/RSWE.cs b/pk3DS.WinForms/Subforms/Gen6/RSWE.cs index d45c686..64dab99 100644 --- a/pk3DS.WinForms/Subforms/Gen6/RSWE.cs +++ b/pk3DS.WinForms/Subforms/Gen6/RSWE.cs @@ -718,7 +718,7 @@ private void SetRandomForm(int slot, int species) { if (CHK_MegaForm.Checked && Main.SpeciesStat[species].FormeCount > 1 && Legal.Mega_ORAS.Contains((ushort)species)) All_Forms[slot].Value = Random32() % Main.SpeciesStat[species].FormeCount; // Slot-Random - else if (species == 666 || species == 665 || species == 664) // Vivillon + else if (species is 666 or 665 or 664) // Vivillon All_Forms[slot].Value = Random32() % 20; else if (species == 386) // Deoxys All_Forms[slot].Value = Random32() % 4; @@ -726,17 +726,17 @@ private void SetRandomForm(int slot, int species) All_Forms[slot].Value = 31; else if (species == 550) // Basculin All_Forms[slot].Value = Random32() % 2; - else if (species == 412 || species == 413) // Wormadam + else if (species is 412 or 413) // Wormadam All_Forms[slot].Value = Random32() % 3; - else if (species == 422 || species == 423) // Gastrodon + else if (species is 422 or 423) // Gastrodon All_Forms[slot].Value = Random32() % 2; - else if (species == 585 || species == 586) // Sawsbuck + else if (species is 585 or 586) // Sawsbuck All_Forms[slot].Value = Random32() % 4; - else if (species == 669 || species == 671) // Flabebe/Florges + else if (species is 669 or 671) // Flabebe/Florges All_Forms[slot].Value = Random32() % 5; else if (species == 670) // Floette All_Forms[slot].Value = Random32() % 6; - else if (species == 710 || species == 711) // Pumpkaboo + else if (species is 710 or 711) // Pumpkaboo All_Forms[slot].Value = Random32() % 4; else All_Forms[slot].Value = 0; diff --git a/pk3DS.WinForms/Subforms/Gen6/TrainerRand.cs b/pk3DS.WinForms/Subforms/Gen6/TrainerRand.cs index 62438dc..b2ffdfa 100644 --- a/pk3DS.WinForms/Subforms/Gen6/TrainerRand.cs +++ b/pk3DS.WinForms/Subforms/Gen6/TrainerRand.cs @@ -175,7 +175,7 @@ private void ChangeMoveRandomization(object sender, EventArgs e) NUD_Damage.Enabled = NUD_STAB.Enabled = CB_Moves.SelectedIndex == 1; CHK_ForceHighPower.Enabled = CHK_ForceHighPower.Checked = NUD_ForceHighPower.Enabled = - CHK_NoFixedDamage.Enabled = CHK_NoFixedDamage.Checked = (CB_Moves.SelectedIndex == 1 || CB_Moves.SelectedIndex == 2); + CHK_NoFixedDamage.Enabled = CHK_NoFixedDamage.Checked = CB_Moves.SelectedIndex is 1 or 2; } private void CHK_6PKM_CheckedChanged(object sender, EventArgs e) diff --git a/pk3DS.WinForms/Subforms/Gen6/XYWE.cs b/pk3DS.WinForms/Subforms/Gen6/XYWE.cs index 1bb12c4..280a048 100644 --- a/pk3DS.WinForms/Subforms/Gen6/XYWE.cs +++ b/pk3DS.WinForms/Subforms/Gen6/XYWE.cs @@ -567,7 +567,7 @@ private void SetRandomForm(int slot, int species) { if (CHK_MegaForm.Checked && Main.SpeciesStat[species].FormeCount > 1 && Legal.Mega_XY.Contains((ushort)species)) All_Form[slot].Value = Random32() % Main.SpeciesStat[species].FormeCount; // Slot-Random - else if (species == 666 || species == 665 || species == 664) // Vivillon + else if (species is 666 or 665 or 664) // Vivillon All_Form[slot].Value = Random32() % 20; else if (species == 386) // Deoxys All_Form[slot].Value = Random32() % 4; @@ -575,17 +575,17 @@ private void SetRandomForm(int slot, int species) All_Form[slot].Value = 31; else if (species == 550) // Basculin All_Form[slot].Value = Random32() % 2; - else if (species == 412 || species == 413) // Wormadam + else if (species is 412 or 413) // Wormadam All_Form[slot].Value = Random32() % 3; - else if (species == 422 || species == 423) // Gastrodon + else if (species is 422 or 423) // Gastrodon All_Form[slot].Value = Random32() % 2; - else if (species == 585 || species == 586) // Sawsbuck + else if (species is 585 or 586) // Sawsbuck All_Form[slot].Value = Random32() % 4; - else if (species == 669 || species == 671) // Flabebe/Florges + else if (species is 669 or 671) // Flabebe/Florges All_Form[slot].Value = Random32() % 5; else if (species == 670) // Floette All_Form[slot].Value = Random32() % 6; - else if (species == 710 || species == 711) // Pumpkaboo + else if (species is 710 or 711) // Pumpkaboo All_Form[slot].Value = Random32() % 4; else All_Form[slot].Value = 0; diff --git a/pk3DS.WinForms/Subforms/Gen7/EvolutionEditor7.cs b/pk3DS.WinForms/Subforms/Gen7/EvolutionEditor7.cs index 5a09606..f673605 100644 --- a/pk3DS.WinForms/Subforms/Gen7/EvolutionEditor7.cs +++ b/pk3DS.WinForms/Subforms/Gen7/EvolutionEditor7.cs @@ -162,12 +162,17 @@ private void B_RandAll_Click(object sender, EventArgs e) SetList(); // Set up advanced randomization options var evos = files.Select(z => new EvolutionSet7(z)).ToArray(); - var evoRand = new EvolutionRandomizer(Main.Config, evos); - evoRand.Randomizer.rBST = CHK_BST.Checked; - evoRand.Randomizer.rEXP = CHK_Exp.Checked; - evoRand.Randomizer.rType = CHK_Type.Checked; - evoRand.Randomizer.L = CHK_L.Checked; - evoRand.Randomizer.E = CHK_E.Checked; + var evoRand = new EvolutionRandomizer(Main.Config, evos) + { + Randomizer = + { + rBST = CHK_BST.Checked, + rEXP = CHK_Exp.Checked, + rType = CHK_Type.Checked, + L = CHK_L.Checked, + E = CHK_E.Checked, + }, + }; evoRand.Randomizer.Initialize(); evoRand.Execute(); evos.Select(z => z.Write()).ToArray().CopyTo(files, 0); @@ -199,12 +204,17 @@ private void B_EveryLevel_Click(object sender, EventArgs e) SetList(); var evos = files.Select(z => new EvolutionSet7(z)).ToArray(); - var evoRand = new EvolutionRandomizer(Main.Config, evos); - evoRand.Randomizer.rBST = CHK_BST.Checked; - evoRand.Randomizer.rEXP = CHK_Exp.Checked; - evoRand.Randomizer.rType = CHK_Type.Checked; - evoRand.Randomizer.L = CHK_L.Checked; - evoRand.Randomizer.E = CHK_E.Checked; + var evoRand = new EvolutionRandomizer(Main.Config, evos) + { + Randomizer = + { + rBST = CHK_BST.Checked, + rEXP = CHK_Exp.Checked, + rType = CHK_Type.Checked, + L = CHK_L.Checked, + E = CHK_E.Checked, + }, + }; evoRand.Randomizer.Initialize(); evoRand.ExecuteEvolveEveryLevel(); evoRand.Execute(); // randomize right after diff --git a/pk3DS.WinForms/Subforms/Gen7/MegaEvoEditor7.cs b/pk3DS.WinForms/Subforms/Gen7/MegaEvoEditor7.cs index 7f3f206..b5e2170 100644 --- a/pk3DS.WinForms/Subforms/Gen7/MegaEvoEditor7.cs +++ b/pk3DS.WinForms/Subforms/Gen7/MegaEvoEditor7.cs @@ -127,7 +127,7 @@ private void GetEntry() private void SetEntry() { - if (entry < 1 || entry == 384) return; // Don't edit invalid / Rayquaza. + if (entry is < 1 or 384) return; // Don't edit invalid / Rayquaza. for (int i = 0; i < 2; i++) { if (me.Method[i] > 1) diff --git a/pk3DS.WinForms/Subforms/Gen7/MoveEditor7.cs b/pk3DS.WinForms/Subforms/Gen7/MoveEditor7.cs index fdb300f..739d6d8 100644 --- a/pk3DS.WinForms/Subforms/Gen7/MoveEditor7.cs +++ b/pk3DS.WinForms/Subforms/Gen7/MoveEditor7.cs @@ -252,7 +252,7 @@ private void B_RandAll_Click(object sender, EventArgs e) for (int i = 0; i < CB_Move.Items.Count; i++) { CB_Move.SelectedIndex = i; // Get new Move - if (i == 165 || i == 174) continue; // Don't change Struggle or Curse + if (i is 165 or 174) continue; // Don't change Struggle or Curse // Change Damage Category if Not Status if (CB_Category.SelectedIndex > 0 && CHK_Category.Checked) // Not Status @@ -272,7 +272,7 @@ private void B_Metronome_Click(object sender, EventArgs e) for (int i = 0; i < CB_Move.Items.Count; i++) { CB_Move.SelectedIndex = i; - if (CB_Move.SelectedIndex != 117 || CB_Move.SelectedIndex != 32) + if (CB_Move.SelectedIndex is not (117 and 32)) NUD_PP.Value = 0; if (CB_Move.SelectedIndex == 117) NUD_PP.Value = 40; diff --git a/pk3DS.WinForms/Subforms/Gen7/PickupEditor7.cs b/pk3DS.WinForms/Subforms/Gen7/PickupEditor7.cs index 78c36e4..b254675 100644 --- a/pk3DS.WinForms/Subforms/Gen7/PickupEditor7.cs +++ b/pk3DS.WinForms/Subforms/Gen7/PickupEditor7.cs @@ -67,7 +67,7 @@ private void SetupFLP() dgvIndex.DisplayIndex = c++; dgvIndex.Width = 45; dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; - ((DataGridViewTextBoxColumn)dgvIndex).MaxInputLength = 2; + dgvIndex.MaxInputLength = 2; } dgv.Columns.Add(dgvIndex); } @@ -118,7 +118,7 @@ private byte[] SetList() cell.Value = 0.ToString(); continue; } - if (val > 100 || val < 0) + if (val is > 100 or < 0) { val = 0; cell.Value = 0.ToString(); diff --git a/pk3DS.WinForms/Subforms/Gen7/SMTE.cs b/pk3DS.WinForms/Subforms/Gen7/SMTE.cs index 9d499b3..2b49a8a 100644 --- a/pk3DS.WinForms/Subforms/Gen7/SMTE.cs +++ b/pk3DS.WinForms/Subforms/Gen7/SMTE.cs @@ -781,18 +781,17 @@ private void B_Randomize_Click(object sender, EventArgs e) pk.Form = Randomizer.GetRandomForme(pk.Species, CHK_RandomMegaForm.Checked, true, Main.SpeciesStat); } - switch (CB_Moves.SelectedIndex) + pk.Moves = CB_Moves.SelectedIndex switch { - case 1: // Random - pk.Moves = move.GetRandomMoveset(pk.Species, 4); - break; - case 2: // Current LevelUp - pk.Moves = learn.GetCurrentMoves(pk.Species, pk.Form, pk.Level, 4); - break; - case 3: // Metronome - pk.Moves = [118, 0, 0, 0]; - break; - } + // Random + 1 => move.GetRandomMoveset(pk.Species, 4), + // Current LevelUp + 2 => learn.GetCurrentMoves(pk.Species, pk.Form, pk.Level, 4), + // Metronome + 3 => [118, 0, 0, 0], + // Otherwise + _ => pk.Moves, + }; // high-power attacks if (CHK_ForceHighPower.Checked && pk.Level >= NUD_ForceHighPower.Value) @@ -846,7 +845,7 @@ private void CB_Moves_SelectedIndexChanged(object sender, EventArgs e) NUD_Damage.Enabled = NUD_STAB.Enabled = CB_Moves.SelectedIndex == 1; CHK_ForceHighPower.Enabled = CHK_ForceHighPower.Checked = NUD_ForceHighPower.Enabled = - CHK_NoFixedDamage.Enabled = CHK_NoFixedDamage.Checked = (CB_Moves.SelectedIndex == 1 || CB_Moves.SelectedIndex == 2); + CHK_NoFixedDamage.Enabled = CHK_NoFixedDamage.Checked = CB_Moves.SelectedIndex is 1 or 2; } private void CHK_Damage_CheckedChanged(object sender, EventArgs e) diff --git a/pk3DS.WinForms/Subforms/Gen7/SMWE.cs b/pk3DS.WinForms/Subforms/Gen7/SMWE.cs index 31e4411..56b01cb 100644 --- a/pk3DS.WinForms/Subforms/Gen7/SMWE.cs +++ b/pk3DS.WinForms/Subforms/Gen7/SMWE.cs @@ -522,32 +522,30 @@ public static class Extensions public static Bitmap GetTableImg(this EncounterTable table, Font font) { var img = new Bitmap(10 * 40, 10 * 30); - using (var g = Graphics.FromImage(img)) + using var g = Graphics.FromImage(img); + g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; + for (int i = 0; i < table.Rates.Length; i++) + g.DrawString($"{table.Rates[i]}%", font, Brushes.Black, new PointF((40 * i) + 10, 10)); + g.DrawString("Weather: ", font, Brushes.Black, new PointF(10, 280)); + + // Draw Sprites + for (int i = 0; i < table.Encounter7s.Length - 1; i++) { - g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; - for (int i = 0; i < table.Rates.Length; i++) - g.DrawString($"{table.Rates[i]}%", font, Brushes.Black, new PointF((40 * i) + 10, 10)); - g.DrawString("Weather: ", font, Brushes.Black, new PointF(10, 280)); - - // Draw Sprites - for (int i = 0; i < table.Encounter7s.Length - 1; i++) + for (int j = 0; j < table.Encounter7s[i].Length; j++) { - for (int j = 0; j < table.Encounter7s[i].Length; j++) - { - var slot = table.Encounter7s[i][j]; - var sprite = GetSprite((int)slot.Species, (int)slot.Forme); - g.DrawImage(sprite, new Point(40 * j, 30 * (i + 1))); - } - } - - for (int i = 0; i < table.AdditionalSOS.Length; i++) - { - var slot = table.AdditionalSOS[i]; + var slot = table.Encounter7s[i][j]; var sprite = GetSprite((int)slot.Species, (int)slot.Forme); - g.DrawImage(sprite, new Point((40 * i) + 60, 270)); + g.DrawImage(sprite, new Point(40 * j, 30 * (i + 1))); } } + for (int i = 0; i < table.AdditionalSOS.Length; i++) + { + var slot = table.AdditionalSOS[i]; + var sprite = GetSprite((int)slot.Species, (int)slot.Forme); + g.DrawImage(sprite, new Point((40 * i) + 60, 270)); + } + static Bitmap GetSprite(int species, int form) { return species == 0 diff --git a/pk3DS.WinForms/Subforms/ShinyRate.cs b/pk3DS.WinForms/Subforms/ShinyRate.cs index 8d9a072..9762716 100644 --- a/pk3DS.WinForms/Subforms/ShinyRate.cs +++ b/pk3DS.WinForms/Subforms/ShinyRate.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Windows.Forms; namespace pk3DS.WinForms; diff --git a/pk3DS.WinForms/Tools/Scripts.cs b/pk3DS.WinForms/Tools/Scripts.cs index e544c0c..3d5ee1e 100644 --- a/pk3DS.WinForms/Tools/Scripts.cs +++ b/pk3DS.WinForms/Tools/Scripts.cs @@ -129,7 +129,7 @@ internal static byte[] CompressBytes(byte[] db) bool sign4 = val < 0 && cmd < 0 && db[0] >= 0xC0; // 4 byte signed bool sign3 = val < 0 && cmd < 0 && db[0] < 0xC0; // 3 byte signed bool sign2 = val < 0 && cmd > 0; // 2 byte signed - bool liter = cmd >= 0 && cmd < 0x40; // Literal + bool liter = cmd is >= 0 and < 0x40; // Literal bool manyb = cmd >= 0x40; // manybit if (sign4) diff --git a/pk3DS.WinForms/WinFormsUtil.cs b/pk3DS.WinForms/WinFormsUtil.cs index 2e8c92d..e51c3c1 100644 --- a/pk3DS.WinForms/WinFormsUtil.cs +++ b/pk3DS.WinForms/WinFormsUtil.cs @@ -127,7 +127,7 @@ public static bool IsTotemForm(int species, int form, int generation = 7) if (!Legal.Totem_USUM.Contains(species)) return false; if (species == 778) // Mimikyu - return form == 2 || form == 3; + return form is 2 or 3; if (Legal.Totem_Alolan.Contains(species)) return form == 2; return form == 1; @@ -586,7 +586,7 @@ public static Bitmap TrimBitmap(Bitmap source) } var dest = new Bitmap(srcRect.Width, srcRect.Height); - var destRect = new Rectangle(0, 0, srcRect.Width, srcRect.Height); + var destRect = srcRect with { X = 0, Y = 0 }; using var graphics = Graphics.FromImage(dest); graphics.DrawImage(source, destRect, srcRect, GraphicsUnit.Pixel); return dest;