misc tweaks

no functional changes
This commit is contained in:
Kurt 2017-09-19 23:19:22 -07:00
parent ddb496692d
commit b63e53af95
5 changed files with 36 additions and 10 deletions

View File

@ -5,8 +5,21 @@
namespace PKHeX.Core
{
/// <summary>
/// Generates matching <see cref="IEncounterable"/> data and relevant <see cref="LegalInfo"/> for a <see cref="PKM"/>.
/// Logic for generating possible in-game encounter data.
/// </summary>
public static class EncounterGenerator
{
/// <summary>
/// Generates possible <see cref="IEncounterable"/> data according to the input PKM data and legality info.
/// </summary>
/// <param name="pkm">PKM data</param>
/// <param name="info">Legality information</param>
/// <returns>Possible encounters</returns>
/// <remarks>
/// The iterator lazily finds possible encounters. If no encounters are possible, the enumerable will be empty.
/// </remarks>
public static IEnumerable<IEncounterable> GetEncounters(PKM pkm, LegalInfo info)
{
switch (info.Generation)
@ -318,8 +331,7 @@ private static IEnumerable<IEncounterable> GenerateRawEncounters3(PKM pkm)
// EncounterStatic
private static bool IsEncounterTypeMatch(IEncounterable e, int type)
{
return type == 0 && !(e is EncounterStaticTyped)
|| e is EncounterStaticTyped t && t.TypeEncounter.Contains(type);
return e is EncounterStaticTyped t ? t.TypeEncounter.Contains(type) : type == 0;
}
private static bool IsValidCatchRatePK1(EncounterStatic e, PK1 pk1)
{
@ -858,7 +870,7 @@ private static IEnumerable<EncounterTrade> GetValidEncounterTradesVC1(PKM pkm, D
// Even if the in game trade uses the tables with source pokemon allowing generation 2 games, the traded pokemon could be a non-tradeback pokemon
var rate = (pkm as PK1)?.Catch_Rate;
if (z is EncounterTradeCatchRate r )
if (z is EncounterTradeCatchRate r)
{
if (rate != r.Catch_Rate)
continue;

View File

@ -33,6 +33,11 @@ public void Reset()
public PeekEnumerator(IEnumerator<T> enumerator) => Enumerator = enumerator ?? throw new ArgumentNullException(nameof(enumerator));
/// <summary>
/// Fetch the next element, if not already performed.
/// </summary>
/// <returns>True/False that a Next element exists</returns>
/// <remarks>Advances the enumerator if Next has not been peeked already</remarks>
private bool TryFetchPeek()
{
if (!didPeek && (didPeek = Enumerator.MoveNext()))
@ -40,6 +45,11 @@ private bool TryFetchPeek()
return didPeek;
}
/// <summary>
/// Peeks to the next element
/// </summary>
/// <returns>Next element</returns>
/// <remarks>Throws an exception if no element exists</remarks>
public T Peek()
{
if (!TryFetchPeek())
@ -51,6 +61,10 @@ public T PeekOrDefault()
{
return !TryFetchPeek() ? default(T) : peek;
}
/// <summary>
/// Checks if a Next element exists
/// </summary>
/// <returns>True/False that a Next element exists</returns>
public bool PeekIsNext()
{
return TryFetchPeek();

View File

@ -894,10 +894,10 @@ private void UpdateIVs(object sender, EventArgs e)
changingFields = false;
// Potential Reading
L_Potential.Text = (Unicode
? new[] { "★☆☆☆", "★★☆☆", "★★★☆", "★★★★" }
: new[] { "+", "++", "+++", "++++" }
)[pkm.PotentialRating];
var arr = Unicode
? new[] {"★☆☆☆", "★★☆☆", "★★★☆", "★★★★"}
: new[] {"+", "++", "+++", "++++"};
L_Potential.Text = arr[pkm.PotentialRating];
TB_IVTotal.Text = pkm.IVs.Sum().ToString();

View File

@ -490,8 +490,8 @@ private void ReadBattleFrontier()
}
private void SaveBattleFrontier()
{
if(ofsPrints > 0)
for(int i = 0; i < Prints.Length; i++)
if (ofsPrints > 0)
for (int i = 0; i < Prints.Length; i++)
{
if (Prints[i] == 1 + Math.Sign((BitConverter.ToUInt16(SAV.Data, ofsPrints + (i << 1)) >> 1) - 1)) continue;
BitConverter.GetBytes(Prints[i] << 1).CopyTo(SAV.Data, ofsPrints + (i << 1));

View File

@ -308,7 +308,7 @@ private void ReadEntralink()
};
ComboItem[] PassPowerB = PassPowerA.Zip(PassPowerC, (f, s) => new ComboItem { Text = f, Value = s }).ToArray();
cba = new[] { CB_PassPower1, CB_PassPower2, CB_PassPower3 };
for(int i = 0; i < cba.Length; i++)
for (int i = 0; i < cba.Length; i++)
{
cba[i].Items.Clear();
cba[i].DisplayMember = "Text";