mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-22 20:13:06 +00:00
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:
parent
9c8e1ab13f
commit
e5aa39a6bb
9 changed files with 36 additions and 34 deletions
|
@ -27,7 +27,7 @@ namespace PKHeX.Core
|
|||
|
||||
return null;
|
||||
}
|
||||
private static EncounterStatic GetSuggestedEncounterEgg(PKM pkm, int loc)
|
||||
private static EncounterStatic GetSuggestedEncounterEgg(PKM pkm, int loc = -1)
|
||||
{
|
||||
int lvl = 1; // gen5+
|
||||
if (!pkm.IsNative)
|
||||
|
@ -41,21 +41,18 @@ namespace PKHeX.Core
|
|||
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 first = slots.First();
|
||||
var encounter = new EncounterStatic
|
||||
return new EncounterStatic
|
||||
{
|
||||
Location = area.Location,
|
||||
Location = loc != -1 ? loc : area.Location,
|
||||
Species = first.Species,
|
||||
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)
|
||||
loc = s.Location;
|
||||
|
|
|
@ -411,6 +411,14 @@ namespace PKHeX.Core
|
|||
public static readonly int[] Games_3e = { 3 };
|
||||
public static readonly int[] Games_3r = { 4, 5 };
|
||||
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
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ namespace PKHeX.Core
|
|||
if (version <= 15 && version > 0) // single game
|
||||
return version;
|
||||
|
||||
int rand = Util.Rand.Next(1);
|
||||
int rand = Util.Rand.Next(2); // 0 or 1
|
||||
switch (version)
|
||||
{
|
||||
case (int)GameVersion.FRLG:
|
||||
|
|
|
@ -367,14 +367,14 @@ namespace PKHeX.Core
|
|||
pk.OT_Memory = 3;
|
||||
pk.OT_TextVar = 9;
|
||||
pk.OT_Intensity = 1;
|
||||
pk.OT_Feeling = Util.Rand.Next(0, 9);
|
||||
pk.OT_Feeling = Util.Rand.Next(0, 10); // 0-9
|
||||
}
|
||||
else
|
||||
{
|
||||
pk.HT_Memory = 3;
|
||||
pk.HT_TextVar = 9;
|
||||
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.IsNicknamed = IsNicknamed;
|
||||
|
|
|
@ -566,7 +566,7 @@ namespace PKHeX.Core
|
|||
HT_Memory = 4; // Link trade to [VAR: General Location]
|
||||
HT_TextVar = Bank ? 0 : 9; // Somewhere (Bank) : Pokécenter (Trade)
|
||||
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
|
||||
|
|
|
@ -618,7 +618,7 @@ namespace PKHeX.Core
|
|||
HT_Memory = 4; // Link trade to [VAR: General Location]
|
||||
HT_TextVar = 0; // Somewhere (Bank)
|
||||
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
|
||||
|
|
|
@ -246,18 +246,13 @@ namespace PKHeX.Core
|
|||
var langs = GetAvailableGameLanguages(generation);
|
||||
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)
|
||||
return new[]
|
||||
{
|
||||
(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
|
||||
};
|
||||
return Legal.Languages_GB;
|
||||
if (generation < 7)
|
||||
return Enumerable.Range(1, 9 - 1); // chinese (CHS/CHT) introduced in Gen7
|
||||
|
||||
return Enumerable.Range(1, SpeciesLang.Length - 1);
|
||||
return Legal.Languages_36;
|
||||
return Legal.Languages_7;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
|
@ -9,15 +10,21 @@ namespace PKHeX.Core
|
|||
{
|
||||
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++)
|
||||
{
|
||||
int r = i + (int)(Rand.NextDouble() * (n - i));
|
||||
T t = array[r];
|
||||
array[r] = array[i];
|
||||
array[i] = t;
|
||||
int r = i + Rand.Next(n-i);
|
||||
T t = items[r];
|
||||
items[r] = items[i];
|
||||
items[i] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -779,11 +779,6 @@ namespace PKHeX.WinForms.Controls
|
|||
if (minlvl < level)
|
||||
minlvl = level;
|
||||
|
||||
if (pkm.VC1)
|
||||
location = Legal.Transfer1;
|
||||
else if (pkm.VC2)
|
||||
location = Legal.Transfer2;
|
||||
|
||||
if (!silent)
|
||||
{
|
||||
var suggestion = new List<string> { "Suggested:" };
|
||||
|
@ -814,7 +809,7 @@ namespace PKHeX.WinForms.Controls
|
|||
{
|
||||
pkm.OT_Memory = 2;
|
||||
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_TextVar = pkm.XY ? 43 : 27; // riverside road : battling spot
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue