Minor clean

variable swaps, simplifications
This commit is contained in:
Kurt 2021-08-20 13:42:25 -07:00
parent 8b4730a2ee
commit c6342a163f
12 changed files with 48 additions and 78 deletions

View file

@ -15,7 +15,7 @@ namespace PKHeX.Core
public IReadOnlyList<ComboItem> DataSource => (ComboItem[])MoveDataAllowed.Clone();
/// <summary>
/// Checks if the requested <see cref="move"/> is in the valid learnable list of moves.
/// Checks if the requested <see cref="move"/> is legally able to be learned.
/// </summary>
/// <param name="move">Move to check if can be learned</param>
/// <returns>True if can learn the move</returns>

View file

@ -32,7 +32,7 @@ namespace PKHeX.Core
}
public static GameDataSource Sources { get; private set; } = new(_strings);
public static FilteredGameDataSource FilteredSources { get; set; } = new(FakeSaveFile.Default, Sources, false);
public static FilteredGameDataSource FilteredSources { get; set; } = new(FakeSaveFile.Default, Sources);
public static string GetVersionName(GameVersion version)
{

View file

@ -94,7 +94,7 @@ namespace PKHeX.Core
private static LearnVersion GetIsLevelUp3(int species, int form, int move, int lvlLevel, GameVersion ver = Any)
{
if (species == (int)Species.Deoxys)
return GetIsLevelUp3Deoxys(form, move, lvlLevel);
return GetIsLevelUp3Deoxys(form, move, lvlLevel, ver);
// Emerald level up tables are equal to R/S level up tables
switch (ver)
@ -217,9 +217,9 @@ namespace PKHeX.Core
return LearnNONE;
}
private static LearnVersion GetIsLevelUp3Deoxys(int form, int move, int lvl)
private static LearnVersion GetIsLevelUp3Deoxys(int form, int move, int lvl, GameVersion ver = Any)
{
var moveset = GetDeoxysLearn3(form);
var moveset = GetDeoxysLearn3(form, ver);
if (moveset == null)
return LearnNONE;
var lv = moveset.GetLevelLearnMove(move);
@ -240,22 +240,17 @@ namespace PKHeX.Core
private static Learnset? GetDeoxysLearn3(int form, GameVersion ver = Any)
{
const int index = (int)Species.Deoxys;
if (ver == Any)
{
return form switch
{
0 => LevelUpRS[index], // Normal
1 => LevelUpFR[index], // Attack
2 => LevelUpLG[index], // Defense
3 => LevelUpE[index], // Speed
_ => null,
};
}
if (ver != Any && Gen3.Contains(ver))
return GameData.GetLearnsets(ver)[index];
var gen = ver.GetGeneration();
if (gen != 3)
return GetDeoxysLearn3(form);
return GameData.GetLearnsets(ver)[index];
return form switch
{
0 => LevelUpRS[index], // Normal
1 => LevelUpFR[index], // Attack
2 => LevelUpLG[index], // Defense
3 => LevelUpE[index], // Speed
_ => null,
};
}
public static IEnumerable<int> GetMovesLevelUp(PKM pkm, int species, int form, int maxLevel, int minlvlG1, int minlvlG2, GameVersion version, bool MoveReminder, int generation)

View file

@ -336,9 +336,7 @@ namespace PKHeX.Core
if ((s >> 16 & 1) == 0)
continue; // only swap if 1
var temp = natures[i];
natures[i] = natures[j];
natures[j] = temp;
(natures[i], natures[j]) = (natures[j], natures[i]);
}
}

View file

@ -248,7 +248,7 @@ namespace PKHeX.Core
data.AddLine(GetValid(LNickMatchLanguageEgg, CheckIdentifier.Egg));
}
private void VerifyNicknameTrade(LegalityAnalysis data, EncounterTrade t)
private static void VerifyNicknameTrade(LegalityAnalysis data, EncounterTrade t)
{
switch (data.Info.Generation)
{

View file

@ -52,7 +52,7 @@ namespace PKHeX.Core
public string Nickname
{
get => StringConverter.GetString5(Data, 0x1E, 11 * 2);
set => StringConverter.SetString5(value, 11, 11, (char)0xFFFF).CopyTo(Data, 0x1E);
set => StringConverter.SetString5(value, 11, 11, '\uFFFF').CopyTo(Data, 0x1E);
}
public int Nature { get => (sbyte)Data[0x34]; set => Data[0x34] = (byte)value; }
@ -78,7 +78,7 @@ namespace PKHeX.Core
public override string OT_Name
{
get => StringConverter.GetString5(Data, 0x4A, 8 * 2);
set => StringConverter.SetString5(value, 8, 8, (char)0xFFFF).CopyTo(Data, 0x4A);
set => StringConverter.SetString5(value, 8, 8, '\uFFFF').CopyTo(Data, 0x4A);
}
public int OTGender { get => Data[0x5A]; set => Data[0x5A] = (byte)value; }
@ -88,7 +88,7 @@ namespace PKHeX.Core
public override string CardTitle
{
get => StringConverter.GetString5(Data, 0x60, 37 * 2);
set => StringConverter.SetString5(value + '\uFFFF', 37, 37, 0).CopyTo(Data, 0x60);
set => StringConverter.SetString5(value, 37, 37, 0).CopyTo(Data, 0x60);
}
// Card Attributes

View file

@ -326,12 +326,7 @@ namespace PKHeX.Core
public override MysteryGiftAlbum GiftAlbum
{
get
{
var album = new MysteryGiftAlbum(MysteryGiftCards, MysteryGiftReceivedFlags);
album.Flags[2047] = false;
return album;
}
get => new(MysteryGiftCards, MysteryGiftReceivedFlags) {Flags = {[2047] = false}};
set
{
bool available = IsMysteryGiftAvailable(value.Gifts);

View file

@ -7,40 +7,31 @@ namespace PKHeX.Core
{
private static readonly OPowerFlagSet[] Mapping =
{
new(5, Hatching),
new(5, Bargain),
new(5, Prize_Money),
new(5, Exp_Point),
new(5, Capture),
// Skip unused byte
new(5, Hatching) {Offset = 1},
new(5, Bargain) {Offset = 6},
new(5, Prize_Money) {Offset = 11},
new(5, Exp_Point) {Offset = 16},
new(5, Capture) {Offset = 21},
new(3, Encounter),
new(3, Stealth),
new(3, HP_Restoring),
new(3, PP_Restoring),
new(3, Encounter) {Offset = 26},
new(3, Stealth) {Offset = 29},
new(3, HP_Restoring) {Offset = 32},
new(3, PP_Restoring) {Offset = 35},
new(1, Full_Recovery),
new(1, Full_Recovery) {Offset = 38},
new(5, Befriending),
new(5, Befriending) {Offset = 39},
new(3, Attack),
new(3, Defense),
new(3, Sp_Attack),
new(3, Sp_Defense),
new(3, Speed),
new(3, Critical),
new(3, Accuracy),
new(3, Attack) {Offset = 44},
new(3, Defense) {Offset = 47},
new(3, Sp_Attack) {Offset = 50},
new(3, Sp_Defense) {Offset = 53},
new(3, Speed) {Offset = 56},
new(3, Critical) {Offset = 59},
new(3, Accuracy) {Offset = 62},
};
static OPower6()
{
int index = 1; // Skip unused byte
foreach (var m in Mapping)
{
m.Offset = index;
index += m.Count;
}
}
public OPower6(SaveFile sav, int offset) : base(sav) => Offset = offset;
private static OPowerFlagSet Get(OPower6Type type) => Array.Find(Mapping, t => t.Identifier == type);

View file

@ -102,9 +102,7 @@ namespace PKHeX.Core
int j = 0 + data.Length - 1;
while (i < j)
{
var temp = data[i];
data[i] = data[j];
data[j] = temp;
(data[i], data[j]) = (data[j], data[i]);
i++;
j--;
}
@ -119,13 +117,8 @@ namespace PKHeX.Core
{
for (int i = 0; i < data.Length; i += 4)
{
byte tmp = data[0 + i];
data[0 + i] = data[3 + i];
data[3 + i] = tmp;
byte tmp1 = data[1 + i];
data[1 + i] = data[2 + i];
data[2 + i] = tmp1;
(data[0 + i], data[3 + i]) = (data[3 + i], data[0 + i]);
(data[1 + i], data[2 + i]) = (data[2 + i], data[1 + i]);
}
}
}

View file

@ -34,9 +34,7 @@ namespace PKHeX.Core
for (int i = start; i < end; i++)
{
int index = i + rnd.Next(end - i);
T t = items[index];
items[index] = items[i];
items[i] = t;
(items[index], items[i]) = (items[i], items[index]);
}
}
}

View file

@ -50,7 +50,7 @@ namespace PKHeX.WinForms
private const int cellscollected = 169;
private const int celloffset = 0xC6;
private int CellCount => SAV is SAV7USUM ? 100 : 95;
private readonly string[] states = {"None", "Available", "Received"};
private static readonly string[] states = {"None", "Available", "Received"};
private void B_Save_Click(object sender, EventArgs e)
{
@ -100,7 +100,7 @@ namespace PKHeX.WinForms
#region locations -- lazy
private readonly string[] locationsSM =
private static readonly string[] locationsSM =
{
"Verdant Cave - Trial Site",
"Ruins of Conflict - Outside",
@ -199,7 +199,7 @@ namespace PKHeX.WinForms
"Aether Foundation 1F - Main Building",
};
private readonly string[] locationsUSUM =
private static readonly string[] locationsUSUM =
{
"Hau'oli City (Shopping) - Salon (Outside)",
"Hau'oli City (Shopping) - Malasada Shop (Outside)",

View file

@ -29,7 +29,7 @@ namespace PKHeX.WinForms.Controls
if (!records.TryGetValue(i, out var name))
name = $"{i:D3}";
CB_Stats.Items.Add(name!);
CB_Stats.Items.Add(name);
}
CB_Stats.SelectedIndex = records.First().Key;
}