mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-26 22:10:21 +00:00
more minor tweaks
add 2 overloads for encounter generator more simplifications
This commit is contained in:
parent
99005d8fc0
commit
0e6db90de2
8 changed files with 58 additions and 25 deletions
|
@ -1,4 +1,7 @@
|
|||
namespace PKHeX.Core
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Utility class for <see cref="GameVersion"/> logic.
|
||||
|
@ -134,5 +137,16 @@
|
|||
return 7;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of possible <see cref="GameVersion"/> values a <see cref="PKM.Version"/> can have.
|
||||
/// </summary>
|
||||
public static readonly GameVersion[] GameVersions = ((GameVersion[])Enum.GetValues(typeof(GameVersion))).Where(z => z < GameVersion.RB && z > 0).Reverse().ToArray();
|
||||
|
||||
/// <summary>
|
||||
/// List of possible <see cref="GameVersion"/> values within the provided <see cref="generation"/>.
|
||||
/// </summary>
|
||||
/// <param name="generation">Generation to look within</param>
|
||||
public static GameVersion[] GetVersionsInGeneration(int generation) => GameVersions.Where(z => z.GetGeneration() == generation).ToArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,7 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
public static class EncounterMovesetGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// List of possible <see cref="GameVersion"/> values a <see cref="PKM.Version"/> can have.
|
||||
/// </summary>
|
||||
private static readonly GameVersion[] Versions = ((GameVersion[]) Enum.GetValues(typeof(GameVersion))).Where(z => z < GameVersion.RB && z > 0).Reverse().ToArray();
|
||||
private static readonly GameVersion[] Versions = GameUtil.GameVersions;
|
||||
|
||||
/// <summary>
|
||||
/// Gets possible <see cref="PKM"/> objects that allow all moves requested to be learned.
|
||||
|
@ -44,6 +41,32 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets possible <see cref="PKM"/> objects that allow all moves requested to be learned within a specific generation.
|
||||
/// </summary>
|
||||
/// <param name="pk">Rough Pokémon data which contains the requested species, gender, and form.</param>
|
||||
/// <param name="info">Trainer information of the receiver.</param>
|
||||
/// <param name="moves">Moves that the resulting <see cref="IEncounterable"/> must be able to learn.</param>
|
||||
/// <param name="generation">Specific generation to iterate versions for.</param>
|
||||
public static IEnumerable<PKM> GeneratePKMs(PKM pk, ITrainerInfo info, int generation, int[] moves = null)
|
||||
{
|
||||
var vers = GameUtil.GetVersionsInGeneration(generation);
|
||||
return GeneratePKMs(pk, info, moves, vers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets possible encounters that allow all moves requested to be learned.
|
||||
/// </summary>
|
||||
/// <param name="pk">Rough Pokémon data which contains the requested species, gender, and form.</param>
|
||||
/// <param name="moves">Moves that the resulting <see cref="IEncounterable"/> must be able to learn.</param>
|
||||
/// <param name="generation">Specific generation to iterate versions for.</param>
|
||||
/// <returns>A consumable <see cref="IEncounterable"/> list of possible encounters.</returns>
|
||||
public static IEnumerable<IEncounterable> GenerateEncounter(PKM pk, int generation, int[] moves = null)
|
||||
{
|
||||
var vers = GameUtil.GetVersionsInGeneration(generation);
|
||||
return GenerateEncounters(pk, moves, vers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets possible encounters that allow all moves requested to be learned.
|
||||
/// </summary>
|
||||
|
|
|
@ -50,10 +50,10 @@ namespace PKHeX.WinForms
|
|||
foreach (var RibbonName in RibbonNames)
|
||||
{
|
||||
object RibbonValue = ReflectUtil.GetValue(pkm, RibbonName);
|
||||
if (RibbonValue is int)
|
||||
riblist.Add(new RibbonInfo(RibbonName, (int)RibbonValue));
|
||||
if (RibbonValue is bool)
|
||||
riblist.Add(new RibbonInfo(RibbonName, (bool)RibbonValue));
|
||||
if (RibbonValue is int x)
|
||||
riblist.Add(new RibbonInfo(RibbonName, x));
|
||||
if (RibbonValue is bool b)
|
||||
riblist.Add(new RibbonInfo(RibbonName, b));
|
||||
}
|
||||
TLP_Ribbons.ColumnCount = 2;
|
||||
TLP_Ribbons.RowCount = 0;
|
||||
|
|
|
@ -29,14 +29,13 @@ namespace PKHeX.WinForms
|
|||
CHK_SecretUnlocked.Checked = pkm.SecretSuperTrainingUnlocked;
|
||||
CHK_SecretComplete.Checked = pkm.SecretSuperTrainingComplete;
|
||||
|
||||
if (pkm is PK6)
|
||||
if (pkm is PK6 pk6)
|
||||
{
|
||||
CB_Bag.Items.Clear();
|
||||
CB_Bag.Items.Add("---");
|
||||
for (int i = 1; i < GameInfo.Strings.trainingbags.Length - 1; i++)
|
||||
CB_Bag.Items.Add(GameInfo.Strings.trainingbags[i]);
|
||||
|
||||
PK6 pk6 = (PK6) pkm;
|
||||
CB_Bag.SelectedIndex = pk6.TrainingBag;
|
||||
NUD_BagHits.Value = pk6.TrainingBagHits;
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ namespace PKHeX.WinForms
|
|||
if (!SAV.Japanese && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Non Japanese save file. Add {itemlist[oldsea]} (unreleased)?"))
|
||||
tickets = tickets.Take(tickets.Length - 1).ToArray(); // remove old sea map
|
||||
|
||||
var p = Pouches.FirstOrDefault(z => z.Type == InventoryType.KeyItems);
|
||||
var p = Array.Find(Pouches, z => z.Type == InventoryType.KeyItems);
|
||||
if (p == null)
|
||||
return;
|
||||
|
||||
|
@ -176,7 +176,7 @@ namespace PKHeX.WinForms
|
|||
|
||||
var added = string.Join(", ", missing.Select(u => itemlist[u]));
|
||||
var addmsg = $"Add the following items?{Environment.NewLine}{added}";
|
||||
if (have.Any())
|
||||
if (have.Count > 0)
|
||||
{
|
||||
string had = string.Join(", ", have.Select(u => itemlist[u]));
|
||||
var havemsg = $"Already have:{Environment.NewLine}{had}";
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace PKHeX.WinForms
|
|||
itemlist = GameInfo.Strings.GetItemStrings(SAV.Generation, SAV.Version);
|
||||
|
||||
for (int i = 0; i < itemlist.Length; i++)
|
||||
if (itemlist[i] == "")
|
||||
if (itemlist[i]?.Length == 0)
|
||||
itemlist[i] = $"(Item #{i:000})";
|
||||
|
||||
HasFreeSpace = SAV.Generation == 7;
|
||||
|
@ -157,14 +157,10 @@ namespace PKHeX.WinForms
|
|||
var outOfBounds = invalid.Where(item => item.Index >= itemlist.Length).ToArray();
|
||||
var incorrectPouch = invalid.Where(item => item.Index < itemlist.Length).ToArray();
|
||||
|
||||
if (outOfBounds.Any())
|
||||
WinFormsUtil.Error(MsgItemPouchUnknown,
|
||||
$"Item ID(s): {string.Join(", ", outOfBounds.Select(item => item.Index))}");
|
||||
if (!Main.HaX && incorrectPouch.Any())
|
||||
WinFormsUtil.Alert(
|
||||
string.Format(MsgItemPouchRemoved, pouch.Type),
|
||||
string.Join(", ", incorrectPouch.Select(item => itemlist[item.Index])),
|
||||
MsgItemPouchWarning);
|
||||
if (outOfBounds.Length > 0)
|
||||
WinFormsUtil.Error(MsgItemPouchUnknown, $"Item ID(s): {string.Join(", ", outOfBounds.Select(item => item.Index))}");
|
||||
if (!Main.HaX && incorrectPouch.Length > 0)
|
||||
WinFormsUtil.Alert(string.Format(MsgItemPouchRemoved, pouch.Type), string.Join(", ", incorrectPouch.Select(item => itemlist[item.Index])), MsgItemPouchWarning);
|
||||
|
||||
pouch.Sanitize(Main.HaX, itemlist.Length - 1);
|
||||
GetBag(dgv, pouch);
|
||||
|
@ -323,7 +319,8 @@ namespace PKHeX.WinForms
|
|||
int l = 0;
|
||||
dgv.Rows[i].Cells[l++].Value = itemname;
|
||||
dgv.Rows[i].Cells[l++].Value = c;
|
||||
var t = p.Items.FirstOrDefault(m => m.Index == item);
|
||||
|
||||
var t = Array.Find(p.Items, m => m.Index == item);
|
||||
|
||||
if (HasFreeSpace)
|
||||
dgv.Rows[i].Cells[l++].Value = t?.FreeSpace ?? false;
|
||||
|
|
|
@ -160,7 +160,7 @@ namespace PKHeX.WinForms
|
|||
var constructors = t.GetConstructors();
|
||||
if (constructors.Length == 0)
|
||||
{ System.Console.WriteLine($"No constructors: {t.Name}"); continue; }
|
||||
var argCount = constructors.First().GetParameters().Length;
|
||||
var argCount = constructors[0].GetParameters().Length;
|
||||
try
|
||||
{
|
||||
var _ = (Form)System.Activator.CreateInstance(t, new object[argCount]);
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace PKHeX.WinForms
|
|||
child.Location = new Point(Math.Max(x, 0), Math.Max(y, 0));
|
||||
}
|
||||
|
||||
public static Form FirstFormOfType<T>(this Form f) => f.OwnedForms.FirstOrDefault(form => form is T);
|
||||
public static Form FirstFormOfType<T>(this Form f) => Array.Find(f.OwnedForms, form => form is T);
|
||||
public static T FindFirstControlOfType<T>(Control aParent) where T : class
|
||||
{
|
||||
while (true)
|
||||
|
|
Loading…
Reference in a new issue