Refactoring

get language list now doesn't return new objects (or re-enumerate)
update rand usage to be inclusive for top bound, extend shuffle to
collections
remove unnecessary location overrides (already overriden in legal fetch)
This commit is contained in:
Kurt 2017-12-14 20:58:55 -08:00
parent 9c8e1ab13f
commit e5aa39a6bb
9 changed files with 36 additions and 34 deletions

View file

@ -27,7 +27,7 @@ namespace PKHeX.Core
return null; return null;
} }
private static EncounterStatic GetSuggestedEncounterEgg(PKM pkm, int loc) private static EncounterStatic GetSuggestedEncounterEgg(PKM pkm, int loc = -1)
{ {
int lvl = 1; // gen5+ int lvl = 1; // gen5+
if (!pkm.IsNative) if (!pkm.IsNative)
@ -41,21 +41,18 @@ namespace PKHeX.Core
Level = lvl, Level = lvl,
}; };
} }
private static EncounterStatic GetSuggestedEncounterWild(EncounterArea area, int loc) private static EncounterStatic GetSuggestedEncounterWild(EncounterArea area, int loc = -1)
{ {
var slots = area.Slots.OrderBy(s => s.LevelMin); var slots = area.Slots.OrderBy(s => s.LevelMin);
var first = slots.First(); var first = slots.First();
var encounter = new EncounterStatic return new EncounterStatic
{ {
Location = area.Location, Location = loc != -1 ? loc : area.Location,
Species = first.Species, Species = first.Species,
Level = first.LevelMin, Level = first.LevelMin,
}; };
if (loc != -1) // forced location
encounter.Location = loc;
return encounter;
} }
private static EncounterStatic GetSuggestedEncounterStatic(EncounterStatic s, int loc) private static EncounterStatic GetSuggestedEncounterStatic(EncounterStatic s, int loc = -1)
{ {
if (loc == -1) if (loc == -1)
loc = s.Location; loc = s.Location;

View file

@ -412,6 +412,14 @@ namespace PKHeX.Core
public static readonly int[] Games_3r = { 4, 5 }; public static readonly int[] Games_3r = { 4, 5 };
public static readonly int[] Games_3s = { 15 }; public static readonly int[] Games_3s = { 15 };
public static readonly int[] Languages_GB =
{
(int) LanguageID.Japanese, (int) LanguageID.English, (int) LanguageID.French, (int) LanguageID.German, (int) LanguageID.Spanish,
(int) LanguageID.Korean // check Korean for the VC case, never possible to match string outside of this case
};
public static readonly int[] Languages_36 = Languages_GB.Concat(new[] { (int)LanguageID.Italian }).ToArray();
public static readonly int[] Languages_7 = Languages_36.Concat(new[] { (int)LanguageID.ChineseS, (int)LanguageID.ChineseT }).ToArray();
#endregion #endregion
} }
} }

View file

@ -180,7 +180,7 @@ namespace PKHeX.Core
if (version <= 15 && version > 0) // single game if (version <= 15 && version > 0) // single game
return version; return version;
int rand = Util.Rand.Next(1); int rand = Util.Rand.Next(2); // 0 or 1
switch (version) switch (version)
{ {
case (int)GameVersion.FRLG: case (int)GameVersion.FRLG:

View file

@ -367,14 +367,14 @@ namespace PKHeX.Core
pk.OT_Memory = 3; pk.OT_Memory = 3;
pk.OT_TextVar = 9; pk.OT_TextVar = 9;
pk.OT_Intensity = 1; pk.OT_Intensity = 1;
pk.OT_Feeling = Util.Rand.Next(0, 9); pk.OT_Feeling = Util.Rand.Next(0, 10); // 0-9
} }
else else
{ {
pk.HT_Memory = 3; pk.HT_Memory = 3;
pk.HT_TextVar = 9; pk.HT_TextVar = 9;
pk.HT_Intensity = 1; pk.HT_Intensity = 1;
pk.HT_Feeling = Util.Rand.Next(0, 9); pk.HT_Feeling = Util.Rand.Next(0, 10); // 0-9
pk.HT_Friendship = pk.OT_Friendship; pk.HT_Friendship = pk.OT_Friendship;
} }
pk.IsNicknamed = IsNicknamed; pk.IsNicknamed = IsNicknamed;

View file

@ -566,7 +566,7 @@ namespace PKHeX.Core
HT_Memory = 4; // Link trade to [VAR: General Location] HT_Memory = 4; // Link trade to [VAR: General Location]
HT_TextVar = Bank ? 0 : 9; // Somewhere (Bank) : Pokécenter (Trade) HT_TextVar = Bank ? 0 : 9; // Somewhere (Bank) : Pokécenter (Trade)
HT_Intensity = 1; HT_Intensity = 1;
HT_Feeling = Util.Rand.Next(0, Bank ? 9 : 19); // 0-9 Bank, 0-19 Trade HT_Feeling = Util.Rand.Next(0, Bank ? 10 : 20); // 0-9 Bank, 0-19 Trade
} }
// Legality Properties // Legality Properties

View file

@ -618,7 +618,7 @@ namespace PKHeX.Core
HT_Memory = 4; // Link trade to [VAR: General Location] HT_Memory = 4; // Link trade to [VAR: General Location]
HT_TextVar = 0; // Somewhere (Bank) HT_TextVar = 0; // Somewhere (Bank)
HT_Intensity = 1; HT_Intensity = 1;
HT_Feeling = Util.Rand.Next(0, 9); // 0-9 Bank HT_Feeling = Util.Rand.Next(0, 10); // 0-9 Bank
} }
// Legality Properties // Legality Properties

View file

@ -246,18 +246,13 @@ namespace PKHeX.Core
var langs = GetAvailableGameLanguages(generation); var langs = GetAvailableGameLanguages(generation);
return langs.All(lang => GetSpeciesNameGeneration(species, lang, generation) != nick); return langs.All(lang => GetSpeciesNameGeneration(species, lang, generation) != nick);
} }
private static IEnumerable<int> GetAvailableGameLanguages(int generation) private static ICollection<int> GetAvailableGameLanguages(int generation)
{ {
if (generation < 3) if (generation < 3)
return new[] return Legal.Languages_GB;
{
(int) LanguageID.Japanese, (int) LanguageID.English, (int) LanguageID.French, (int) LanguageID.German, (int) LanguageID.Spanish,
(int) LanguageID.Korean // check Korean for the VC case, never possible to match string outside of this case
};
if (generation < 7) if (generation < 7)
return Enumerable.Range(1, 9 - 1); // chinese (CHS/CHT) introduced in Gen7 return Legal.Languages_36;
return Legal.Languages_7;
return Enumerable.Range(1, SpeciesLang.Length - 1);
} }
/// <summary> /// <summary>

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
namespace PKHeX.Core namespace PKHeX.Core
{ {
@ -9,15 +10,21 @@ namespace PKHeX.Core
{ {
return (uint)Rand.Next(1 << 30) << 2 | (uint)Rand.Next(1 << 2); return (uint)Rand.Next(1 << 30) << 2 | (uint)Rand.Next(1 << 2);
} }
public static void Shuffle<T>(T[] array)
/// <summary>
/// Shuffles the order of items within a collection of items.
/// </summary>
/// <typeparam name="T">Item type</typeparam>
/// <param name="items">Item collection</param>
public static void Shuffle<T>(IList<T> items)
{ {
int n = array.Length; int n = items.Count;
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
{ {
int r = i + (int)(Rand.NextDouble() * (n - i)); int r = i + Rand.Next(n-i);
T t = array[r]; T t = items[r];
array[r] = array[i]; items[r] = items[i];
array[i] = t; items[i] = t;
} }
} }
} }

View file

@ -779,11 +779,6 @@ namespace PKHeX.WinForms.Controls
if (minlvl < level) if (minlvl < level)
minlvl = level; minlvl = level;
if (pkm.VC1)
location = Legal.Transfer1;
else if (pkm.VC2)
location = Legal.Transfer2;
if (!silent) if (!silent)
{ {
var suggestion = new List<string> { "Suggested:" }; var suggestion = new List<string> { "Suggested:" };
@ -814,7 +809,7 @@ namespace PKHeX.WinForms.Controls
{ {
pkm.OT_Memory = 2; pkm.OT_Memory = 2;
pkm.OT_Affection = 0; pkm.OT_Affection = 0;
pkm.OT_Feeling = Util.Rand.Next(0, 9); pkm.OT_Feeling = Util.Rand.Next(0, 10);
pkm.OT_Intensity = 1; pkm.OT_Intensity = 1;
pkm.OT_TextVar = pkm.XY ? 43 : 27; // riverside road : battling spot pkm.OT_TextVar = pkm.XY ? 43 : 27; // riverside road : battling spot
} }