misc updates

use arrays instead of list when capacity known
use enums for const decoration
remove unnecessary aliases
This commit is contained in:
Kurt 2018-09-01 19:55:08 -07:00
parent 106a02eedd
commit cc20bb38d7
7 changed files with 64 additions and 66 deletions

View file

@ -22,10 +22,9 @@ namespace PKHeX.Core
// Misc
public readonly string[] wallpapernames, puffs;
public readonly string eggname;
private readonly string lang;
public string EggName => eggname;
public string EggName { get; }
public IReadOnlyList<string> Species => specieslist;
public IReadOnlyList<string> Item => itemlist;
public IReadOnlyList<string> Move => movelist;
@ -97,10 +96,10 @@ namespace PKHeX.Core
trainingbags = Get("trainingbag");
trainingstage = Get("supertraining");
puffs = Get("puff");
Array.Resize(ref puffs, puffs.Length + 1);
Array.Resize(ref puffs, puffs.Length + 1); // shift all down, 0th will be 'none' -- applied later
Array.Copy(puffs, 0, puffs, 1, puffs.Length - 1);
eggname = specieslist[0];
EggName = specieslist[0];
metHGSS_00000 = Get("hgss_00000");
metHGSS_02000 = Get("hgss_02000");
metHGSS_03000 = Get("hgss_03000");
@ -198,7 +197,7 @@ namespace PKHeX.Core
private void SanitizeMetG5BW()
{
metHGSS_02000[1] += $" ({NPC})"; // Anything from an NPC
metHGSS_02000[2] += $" ({eggname})"; // Egg From Link Trade
metHGSS_02000[2] += $" ({EggName})"; // Egg From Link Trade
metBW2_00000[36] = $"{metBW2_00000[84]}/{metBW2_00000[36]}"; // Cold Storage in BW = PWT in BW2
metBW2_00000[40] += "(B/W)"; // Victory Road in BW
metBW2_00000[134] += "(B2/W2)"; // Victory Road in B2W2
@ -213,7 +212,7 @@ namespace PKHeX.Core
// Localize the Poketransfer to the language (30001)
metBW2_30000[1 - 1] = GameInfo.GetTransporterName(lang); // Default to English
metBW2_30000[2 - 1] += $" ({NPC})"; // Anything from an NPC
metBW2_30000[3 - 1] += $" ({eggname})"; // Link Trade (Egg)
metBW2_30000[3 - 1] += $" ({EggName})"; // Link Trade (Egg)
// Zorua/Zoroark events
metBW2_30000[10 - 1] = $"{specieslist[251]} ({specieslist[570]} 1)"; // Celebi's Zorua Event
@ -221,7 +220,7 @@ namespace PKHeX.Core
metBW2_30000[12 - 1] = $"{specieslist[571]} (1)"; // Zoroark
metBW2_30000[13 - 1] = $"{specieslist[571]} (2)"; // Zoroark
metBW2_60000[3 - 1] += $" ({eggname})"; // Egg Treasure Hunter/Breeder, whatever...
metBW2_60000[3 - 1] += $" ({EggName})"; // Egg Treasure Hunter/Breeder, whatever...
}
private void SanitizeMetG6XY()
@ -231,7 +230,7 @@ namespace PKHeX.Core
metXY_00000[202] += " (OR/AS)"; // Pokémon League
metXY_00000[298] += " (OR/AS)"; // Victory Road
metXY_30000[0] += $" ({NPC})"; // Anything from an NPC
metXY_30000[1] += $" ({eggname})"; // Egg From Link Trade
metXY_30000[1] += $" ({EggName})"; // Egg From Link Trade
}
private void SanitizeMetG7SM()
@ -250,7 +249,7 @@ namespace PKHeX.Core
metSM_00000_good.CopyTo(metSM_00000, 0);
metSM_30000[0] += $" ({NPC})"; // Anything from an NPC
metSM_30000[1] += $" ({eggname})"; // Egg From Link Trade
metSM_30000[1] += $" ({EggName})"; // Egg From Link Trade
for (int i = 2; i <= 5; i++) // distinguish first set of regions (unused) from second (used)
metSM_30000[i] += " (-)";
}

View file

@ -47,19 +47,19 @@ namespace PKHeX.Core
return Util.GetOffsetCBList(memory_list1, mems, 0, allowed);
}
public List<string> GetMemoryQualities()
public string[] GetMemoryQualities()
{
List<string> list = new List<string>();
for (int i = 0; i < 7; i++)
list.Add(s.memories[2 + i]);
var list = new string[7];
for (int i = 0; i < list.Length; i++)
list[i] = s.memories[2 + i];
return list;
}
public List<string> GetMemoryFeelings()
public string[] GetMemoryFeelings()
{
List<string> list = new List<string>();
var list = new string[24];
for (int i = 0; i < 24; i++)
list.Add(s.memories[10 + i]);
list[i] = s.memories[10 + i];
return list;
}

View file

@ -178,12 +178,12 @@ namespace PKHeX.Core
return r.Distinct();
}
internal static IList<int> GetShedinjaEvolveMoves(PKM pkm, int generation, int lvl = -1)
internal static int[] GetShedinjaEvolveMoves(PKM pkm, int generation, int lvl = -1)
{
if (lvl == -1)
lvl = pkm.CurrentLevel;
if (pkm.Species != 292 || lvl < 20)
return new List<int>();
return Array.Empty<int>();
// If nincada evolves into Ninjask an learn in the evolution a move from ninjask learnset pool
// Shedinja would appear with that move learned. Only one move above level 20 allowed, only in generations 3 and 4
@ -191,14 +191,14 @@ namespace PKHeX.Core
{
case 3: // Ninjask have the same learnset in every gen 3 games
if (pkm.InhabitedGeneration(3))
return LevelUpE[291].GetMoves(lvl, 20).ToList();
return LevelUpE[291].GetMoves(lvl, 20);
break;
case 4: // Ninjask have the same learnset in every gen 4 games
if (pkm.InhabitedGeneration(4))
return LevelUpPt[291].GetMoves(lvl, 20);
break;
}
return new List<int>();
return Array.Empty<int>();
}
internal static int GetShedinjaMoveLevel(int species, int move, int generation)
@ -817,14 +817,14 @@ namespace PKHeX.Core
{
case 1:
case 3:
return 7; // 1-7 except 6
return (int)LanguageID.Spanish; // 1-7 except 6
case 2:
case 4:
case 5:
case 6:
return 8;
return (int)LanguageID.Korean;
case 7:
return 10;
return (int)LanguageID.ChineseT;
}
return -1;
}
@ -1071,8 +1071,8 @@ namespace PKHeX.Core
internal static int GetBaseSpecies(PKM pkm, IReadOnlyList<DexLevel> evos, int skipOption = 0)
{
if (pkm.Species == 292)
return 290;
if (pkm.Species == 292) // Shedinja
return 290; // Nincada
switch (skipOption)
{
case -1: return pkm.Species;

View file

@ -199,8 +199,8 @@ namespace PKHeX.Core
private static int[] GetSpecialMoves(IEncounterable EncounterMatch)
{
if (EncounterMatch is IMoveset mg)
return mg.Moves ?? Array.Empty<int>();
if (EncounterMatch is IMoveset mg && mg.Moves != null)
return mg.Moves;
return Array.Empty<int>();
}
@ -507,7 +507,7 @@ namespace PKHeX.Core
{
// Check moves that are learned at the same level in red/blue and yellow, these are illegal because there is no move reminder
// There are only two incompatibilites; there is no illegal combination in generation 2+.
var incompatible = new List<int>();
var incompatible = new List<int>(3);
switch (pkm.Species)
{
@ -742,7 +742,7 @@ namespace PKHeX.Core
// Obtain level1 moves
var reqBase = GetRequiredBaseMoveCount(Moves, infoset);
var em = string.Empty;
var sb = new System.Text.StringBuilder();
// Check if the required amount of Base Egg Moves are present.
for (int i = 0; i < reqBase; i++)
{
@ -757,7 +757,7 @@ namespace PKHeX.Core
res[z] = new CheckMoveResult(MoveSource.Initial, gen, Severity.Invalid, LMoveRelearnEggMissing, CheckIdentifier.Move);
// provide the list of suggested base moves for the last required slot
em = string.Join(", ", GetMoveNames(infoset.Base));
sb.Append(string.Join(", ", GetMoveNames(infoset.Base)));
break;
}
@ -777,15 +777,15 @@ namespace PKHeX.Core
res[z] = new CheckMoveResult(MoveSource.SpecialEgg, gen, Severity.Invalid, LMoveEggMissing, CheckIdentifier.Move);
// provide the list of suggested base moves and species moves for the last required slot
if (string.IsNullOrEmpty(em))
em = string.Join(", ", GetMoveNames(infoset.Base));
em += ", ";
em += string.Join(", ", GetMoveNames(infoset.Special));
if (sb.Length == 0)
sb.Append(string.Join(", ", GetMoveNames(infoset.Base)));
sb.Append(", ");
sb.Append(string.Join(", ", GetMoveNames(infoset.Special)));
break;
}
if (!string.IsNullOrEmpty(em))
res[reqBase > 0 ? reqBase - 1 : 0].Comment = string.Format(Environment.NewLine + LMoveFExpect_0, em);
if (sb.Length != 0)
res[reqBase > 0 ? reqBase - 1 : 0].Comment = string.Format(Environment.NewLine + LMoveFExpect_0, sb.ToString());
// Inherited moves appear after the required base moves.
var AllowInheritedSeverity = infoset.AllowInherited ? Severity.Valid : Severity.Invalid;
@ -841,28 +841,22 @@ namespace PKHeX.Core
private static void UpdateGen1LevelUpMoves(PKM pkm, ValidEncounterMoves EncounterMoves, int defaultLvlG1, int generation, LegalInfo info)
{
switch (generation)
{
case 1:
case 2:
var lvlG1 = info.EncounterMatch?.LevelMin + 1 ?? 6;
if (lvlG1 != defaultLvlG1)
EncounterMoves.LevelUpMoves[1] = Legal.GetValidMoves(pkm, info.EvoChainsAllGens[1], generation: 1, minLvLG1: lvlG1, LVL: true, Tutor: false, Machine: false, MoveReminder: false).ToList();
break;
}
if (generation >= 3)
return;
var lvlG1 = info.EncounterMatch?.LevelMin + 1 ?? 6;
if (lvlG1 == defaultLvlG1)
return;
EncounterMoves.LevelUpMoves[1] = Legal.GetValidMoves(pkm, info.EvoChainsAllGens[1], generation: 1, minLvLG1: lvlG1, LVL: true, Tutor: false, Machine: false, MoveReminder: false).ToList();
}
private static void UpdateGen2LevelUpMoves(PKM pkm, ValidEncounterMoves EncounterMoves, int defaultLvlG2, int generation, LegalInfo info)
{
switch (generation)
{
case 1:
case 2:
var lvlG2 = info.EncounterMatch?.LevelMin + 1 ?? 6;
if (lvlG2 != defaultLvlG2)
EncounterMoves.LevelUpMoves[2] = Legal.GetValidMoves(pkm, info.EvoChainsAllGens[2], generation: 2, minLvLG2: defaultLvlG2, LVL: true, Tutor: false, Machine: false, MoveReminder: false).ToList();
break;
}
if (generation >= 3)
return;
var lvlG2 = info.EncounterMatch?.LevelMin + 1 ?? 6;
if (lvlG2 == defaultLvlG2)
return;
EncounterMoves.LevelUpMoves[2] = Legal.GetValidMoves(pkm, info.EvoChainsAllGens[2], generation: 2, minLvLG2: defaultLvlG2, LVL: true, Tutor: false, Machine: false, MoveReminder: false).ToList();
}
public static int[] GetGenMovesCheckOrder(PKM pkm)
@ -886,10 +880,12 @@ namespace PKHeX.Core
return xfer;
}
private static readonly int[] G2 = {2};
private static readonly int[] G12 = {1, 2};
private static int[] GetGenMovesCheckOrderGB(PKM pkm, int originalGeneration)
{
if (originalGeneration == 2)
return pkm.Korean ? new[] {2} : new[] {2, 1};
return pkm.Korean ? G2 : G12;
return new[] {1, 2}; // RBY
}

View file

@ -115,7 +115,9 @@ namespace PKHeX.Core
inheritMoves.Add(344); // Volt Tackle
// If any splitbreed moves are invalid, flag accordingly
var splitMoves = e is EncounterEggSplit s ? Legal.GetValidRelearn(pkm, s.OtherSpecies, inheritLvlMoves, e.Version).ToList() : new List<int>();
var splitMoves = e is EncounterEggSplit s
? Legal.GetValidRelearn(pkm, s.OtherSpecies, inheritLvlMoves, e.Version).ToList()
: (IReadOnlyList<int>)Array.Empty<int>();
// Inherited moves appear after the required base moves.
// If the pkm is capable of split-species breeding and any inherited move is from the other split scenario, flag accordingly.

View file

@ -265,9 +265,6 @@ namespace PKHeX.Core
public static List<ComboItem> GetOffsetCBList(List<ComboItem> cbList, IReadOnlyList<string> inStrings, int offset, IEnumerable<int> allowed)
{
if (allowed == null)
allowed = Enumerable.Range(0, inStrings.Count);
var list = allowed
.Select(z => new ComboItem {Text = inStrings[z - offset], Value = z})
.OrderBy(z => z.Text);
@ -279,13 +276,17 @@ namespace PKHeX.Core
public static List<ComboItem> GetVariedCBListBall(string[] inStrings, int[] stringNum, int[] stringVal)
{
// First 3 Balls are always first
List<ComboItem> newlist = new List<ComboItem>();
for (int i = 4; i > 1; i--) // add 4,3,2
newlist.Add(new ComboItem { Text = inStrings[i], Value = i });
var newlist = new List<ComboItem>(3 + stringNum.Length)
{
new ComboItem {Text = inStrings[4], Value = (int)Ball.Poke},
new ComboItem {Text = inStrings[3], Value = (int)Ball.Great},
new ComboItem {Text = inStrings[2], Value = (int)Ball.Ultra},
};
newlist.AddRange(stringNum
.Select((z, i) => new ComboItem { Text = inStrings[z], Value = stringVal[i] })
.OrderBy(z => z.Text));
var ordered = stringNum
.Select((z, i) => new ComboItem {Text = inStrings[z], Value = stringVal[i]})
.OrderBy(z => z.Text);
newlist.AddRange(ordered);
return newlist;
}
#endregion

View file

@ -121,7 +121,7 @@ namespace PKHeX.WinForms
}
else
{
GB_M_OT.Text = GB_M_CT.Text = $"N/A: {GameInfo.Strings.eggname}";
GB_M_OT.Text = GB_M_CT.Text = $"N/A: {GameInfo.Strings.EggName}";
}
init = true;