Misc tweaks

fix roamer3 not setting IVs
fix usum z items rightmost pixel getting chopped off
use Gen* instead of GenNumber for specific cases (faster)
add WasGiftEgg location case for Gen7
remove some unnecessary array allocations
This commit is contained in:
Kurt 2017-11-17 22:19:23 -08:00
parent 6a033b00fc
commit f7e20a3c43
9 changed files with 49 additions and 29 deletions

View file

@ -1206,8 +1206,7 @@ namespace PKHeX.Core
// Check also if the current encounter include the evolve move as an special move
// That means the pokemon have the move from the encounter level
int[] SpecialMoves = (info.EncounterMatch as IMoveset)?.Moves ?? new int[0];
if (SpecialMoves.Any(m => moves.Contains(m)))
if (info.EncounterMatch is IMoveset s && s.Moves != null && s.Moves.Any(m => moves.Contains(m)))
LearnLevel = Math.Min(LearnLevel, info.EncounterMatch.LevelMin);
// If the encounter is a player hatched egg check if the move could be an egg move or inherited level up move
@ -1392,7 +1391,7 @@ namespace PKHeX.Core
if (pkm.Format == 3 && pkm.WasEgg)
// Only for gen 3 pokemon in format 3, after transfer to gen 4 it should return transfer level
return 5;
if (pkm.Format == 4 && pkm.GenNumber == 4 && pkm.WasEgg)
if (pkm.Format == 4 && pkm.Gen4 && pkm.WasEgg)
// Only for gen 4 pokemon in format 4, after transfer to gen 5 it should return transfer level
return 1;
return pkm.HasOriginalMetLocation ? pkm.Met_Level : GetMaxLevelGeneration(pkm);

View file

@ -92,10 +92,12 @@ namespace PKHeX.Core
var AllowLevelUp = pkm.PersonalInfo.Gender > 0 && pkm.PersonalInfo.Gender < 255 || Legal.MixedGenderBreeding.Contains(e.Species);
int BaseLevel = AllowLevelUp ? 100 : e.LevelMin;
var LevelUp = Legal.GetBaseEggMoves(pkm, e.Species, e.Game, BaseLevel);
var TradebackPreevo = pkm.Format == 2 && info.EncounterMatch.Species > 151;
var NonTradebackLvlMoves = new int[0];
if (TradebackPreevo)
NonTradebackLvlMoves = Legal.GetExclusivePreEvolutionMoves(pkm, info.EncounterMatch.Species, info.EvoChainsAllGens[2], 2, e.Game).Where(m => m > Legal.MaxMoveID_1).ToArray();
var NonTradebackLvlMoves = TradebackPreevo
? Legal.GetExclusivePreEvolutionMoves(pkm, info.EncounterMatch.Species, info.EvoChainsAllGens[2], 2, e.Game).Where(m => m > Legal.MaxMoveID_1).ToArray()
: new int[0];
var Egg = Legal.GetEggMoves(pkm, e.Species, pkm.AltForm, e.Game);
if (info.Generation < 3 && pkm.Format >= 7 && pkm.VC1)
Egg = Egg.Where(m => m <= Legal.MaxMoveID_1).ToArray();

View file

@ -73,7 +73,7 @@ namespace PKHeX.Core
}
private static bool GetModified8BitMatch(PKM pk, uint pid, out PIDIV pidiv)
{
return pk.GenNumber == 4
return pk.Gen4
? pid <= 0xFF && GetCuteCharmMatch(pk, pid, out pidiv) || GetG5MGShinyMatch(pk, pid, out pidiv)
: GetG5MGShinyMatch(pk, pid, out pidiv) || pid <= 0xFF && GetCuteCharmMatch(pk, pid, out pidiv);
}

View file

@ -406,7 +406,7 @@ namespace PKHeX.Core
if (Version == (int) GameVersion.CXD)
return Array.IndexOf(PersonalInfo.Abilities, Ability);
return (int)((GenNumber == 5 ? PID >> 16 : PID) & 1);
return (int)((Gen5 ? PID >> 16 : PID) & 1);
}
}
@ -490,13 +490,14 @@ namespace PKHeX.Core
{
case 4: return Legal.GiftEggLocation4.Contains(Egg_Location) || (Egg_Location == 3002 && HGSS); // faraway
case 5: return Egg_Location == 60003;
case 6: return Egg_Location == 60004;
case 6:
case 7: return Egg_Location == 60004;
}
return false;
}
}
public virtual bool WasEvent => Met_Location > 40000 && Met_Location < 50000 || FatefulEncounter;
public virtual bool WasEventEgg => GenNumber == 4 ? WasEgg && Species == 490 : ((Egg_Location > 40000 && Egg_Location < 50000) || (FatefulEncounter && Egg_Location > 0)) && Met_Level == 1;
public virtual bool WasEventEgg => Gen4 ? WasEgg && Species == 490 : ((Egg_Location > 40000 && Egg_Location < 50000) || (FatefulEncounter && Egg_Location > 0)) && Met_Level == 1;
public bool WasTradedEgg
{
get
@ -512,7 +513,7 @@ namespace PKHeX.Core
}
}
}
public virtual bool WasIngameTrade => Met_Location == 30001 || GenNumber == 4 && Egg_Location == 2001;
public virtual bool WasIngameTrade => Met_Location == 30001 || Gen4 && Egg_Location == 2001;
public virtual bool IsUntraded => Format >= 6 && string.IsNullOrWhiteSpace(HT_Name) && GenNumber == Format;
public virtual bool IsNative => GenNumber == Format;
public virtual bool IsOriginValid => Species <= Legal.GetMaxSpeciesOrigin(Format);

View file

@ -325,10 +325,10 @@ namespace PKHeX.Core
default:
comment = null;
return false;
case 025 when pk.AltForm != 0 && pk.GenNumber == 6: // Cosplay Pikachu
case 025 when pk.AltForm != 0 && pk.Gen6: // Cosplay Pikachu
comment = "Cannot transfer Cosplay Pikachu forward.";
return true;
case 172 when pk.AltForm != 0 && pk.GenNumber == 4: // Spiky Eared Pichu
case 172 when pk.AltForm != 0 && pk.Gen4: // Spiky Eared Pichu
comment = "Cannot transfer Spiky-Eared Pichu forward.";
return true;
}

View file

@ -20,7 +20,7 @@ namespace PKHeX.Core
private static readonly string[] moves = Util.GetMovesList(Language);
private static readonly string[] abilities = Util.GetAbilitiesList(Language);
private static readonly string[] hptypes = types.Skip(1).ToArray();
private const int MAX_SPECIES = Legal.MaxSpeciesID_7_USUM;
private int MAX_SPECIES => species.Length-1;
// Default Set Data
public string Nickname { get; set; }
@ -54,7 +54,8 @@ namespace PKHeX.Core
lines = lines.Where(line => line.Length > 2).ToArray();
if (lines.Length < 3) return;
if (lines.Length < 3)
return;
// Seek for start of set
int start = Array.FindIndex(lines, line => line.Contains(" @ "));
@ -89,7 +90,7 @@ namespace PKHeX.Core
string[] brokenline = line.Split(new[] { ": " }, StringSplitOptions.None);
if (brokenline.Length == 1)
brokenline = new[] {brokenline[0], ""};
brokenline = new[] {brokenline[0], string.Empty};
switch (brokenline[0])
{
case "Trait":
@ -152,7 +153,7 @@ namespace PKHeX.Core
private string GetText()
{
if (Species == 0 || Species > MAX_SPECIES)
return "";
return string.Empty;
var result = new List<string>();
@ -227,7 +228,8 @@ namespace PKHeX.Core
public static string GetShowdownText(PKM pkm)
{
if (pkm.Species == 0) return "";
if (pkm.Species == 0)
return string.Empty;
string[] Forms = PKX.GetFormList(pkm.Species, types, forms, new[] {"", "F", ""}, pkm.Format);
ShowdownSet Set = new ShowdownSet
@ -244,11 +246,11 @@ namespace PKHeX.Core
Friendship = pkm.CurrentFriendship,
Level = PKX.GetLevel(pkm.Species, pkm.EXP),
Shiny = pkm.IsShiny,
Form = pkm.AltForm > 0 && pkm.AltForm < Forms.Length ? Forms[pkm.AltForm] : "",
Form = pkm.AltForm > 0 && pkm.AltForm < Forms.Length ? Forms[pkm.AltForm] : string.Empty,
};
if (Set.Form == "F")
Set.Gender = "";
Set.Gender = string.Empty;
return Set.Text;
}
@ -297,7 +299,7 @@ namespace PKHeX.Core
n1 = line.Substring(end + 2);
}
bool inverted = Array.IndexOf(species, n2.Replace(" ", "")) > -1 || (Species = Array.IndexOf(species, n2.Split('-')[0])) > 0;
bool inverted = Array.IndexOf(species, n2.Replace(" ", string.Empty)) > -1 || (Species = Array.IndexOf(species, n2.Split('-')[0])) > 0;
line = inverted ? n2 : n1;
Nickname = inverted ? n1 : n2;
}

View file

@ -47,6 +47,11 @@ namespace PKHeX.WinForms.Controls
}
}
public bool ControlsVisible
{
get => CB_BoxSelect.Enabled;
set => CB_BoxSelect.Enabled = CB_BoxSelect.Visible = B_BoxLeft.Visible = B_BoxRight.Visible = value;
}
public int CurrentBox
{
get => CB_BoxSelect.SelectedIndex;
@ -91,21 +96,29 @@ namespace PKHeX.WinForms.Controls
{
if (!SAV.HasBox)
return;
// Build ComboBox Dropdown Items
try
if (!SAV.Exportable)
getBoxNamesDefault();
else
{
try { getBoxNamesFromSave(); }
catch { getBoxNamesDefault(); }
}
if (SAV.CurrentBox < CB_BoxSelect.Items.Count)
CurrentBox = SAV.CurrentBox; // restore selected box
void getBoxNamesFromSave()
{
CB_BoxSelect.Items.Clear();
for (int i = 0; i < SAV.BoxCount; i++)
CB_BoxSelect.Items.Add(SAV.GetBoxName(i));
}
catch
void getBoxNamesDefault()
{
CB_BoxSelect.Items.Clear();
for (int i = 1; i <= SAV.BoxCount; i++)
CB_BoxSelect.Items.Add($"BOX {i}");
for (int i = 0; i <= SAV.BoxCount; i++)
CB_BoxSelect.Items.Add($"Box {i+1}");
}
if (SAV.CurrentBox < CB_BoxSelect.Items.Count)
CurrentBox = SAV.CurrentBox; // restore selected box
}
public void ResetSlots()
{

View file

@ -43,6 +43,7 @@ namespace PKHeX.WinForms
Reader.PID = Util.GetHexValue(TB_PID.Text);
Reader.Species = WinFormsUtil.GetIndex(CB_Species);
Reader.IVs = IVs;
}
private void B_Save_Click(object sender, EventArgs e)
{

View file

@ -83,6 +83,8 @@ namespace PKHeX.WinForms
// Redraw
int x = 22 + (15 - itemimg.Width)/2;
if (x + itemimg.Width > baseImage.Width)
x = baseImage.Width - itemimg.Width;
int y = 15 + (15 - itemimg.Height);
baseImage = ImageUtil.LayerImage(baseImage, itemimg, x, y, 1);
}
@ -153,7 +155,7 @@ namespace PKHeX.WinForms
if (slot < 30)
pkm.Box = box;
var la = new LegalityAnalysis(pkm, SAV.Personal);
if (la.Parsed && !la.Valid && pkm.Species != 0)
if (la.ParsedInvalid && pkm.Species != 0)
sprite = ImageUtil.LayerImage(sprite, Resources.warn, 0, 14, 1);
}
if (inBox) // in box