Add gen4 event recognition

fixes ribbon fetch, unown form comparison, and improves exception
handling (no more swallowing exceptions and yielding a vague message)

properly generate manaphy egg on gen4 saves

will have to iron out the legality checks for nicknames at a later point
in time
This commit is contained in:
Kurt 2017-03-23 23:15:49 -07:00
parent b6c4eab36b
commit d8dcb47252
5 changed files with 57 additions and 21 deletions

View File

@ -75,7 +75,15 @@ public LegalityAnalysis(PKM pk)
else
return;
}
catch { Valid = false; }
catch (Exception e)
{
Console.WriteLine(e.Message);
Valid = false;
Parsed = true;
AddLine(Severity.Invalid, V190, CheckIdentifier.Misc);
AllSuggestedMoves = AllSuggestedRelearnMoves = AllSuggestedMovesAndRelearn = new int[0];
return;
}
AllSuggestedMoves = !pkm.IsOriginValid ? new int[4] : getSuggestedMoves(true, true, true);
AllSuggestedRelearnMoves = !pkm.IsOriginValid ? new int[4] : Legal.getValidRelearn(pkm, -1).ToArray();
AllSuggestedMovesAndRelearn = AllSuggestedMoves.Concat(AllSuggestedRelearnMoves).ToArray();

View File

@ -891,13 +891,13 @@ private void verifyRibbons()
};
if (MatchedGift != null) // Wonder Card
{
var mgRibbons = ReflectUtil.getPropertiesStartWithPrefix(MatchedGift.Content.GetType(), "Ribbon");
var mgRibbons = MatchedGift.Format == 4 ? EventRib : ReflectUtil.getPropertiesStartWithPrefix(MatchedGift.Content.GetType(), "Ribbon");
var commonRibbons = mgRibbons.Intersect(RibbonData).ToArray();
foreach (string r in commonRibbons)
{
bool? pk = ReflectUtil.getBooleanState(pkm, r);
bool? mg = ReflectUtil.getBooleanState(MatchedGift, r);
bool? mg = ReflectUtil.getBooleanState(MatchedGift.Content, r);
if (pk != mg) // Mismatch
{
if (pk ?? false)
@ -1798,13 +1798,12 @@ private void verifyForm()
int species = pkm.Species;
if (species == 201) // Unown
{
if (pkm.GenNumber == 2 && pkm.AltForm < 26) // A-Z
valid = true;
else if (pkm.GenNumber >= 3 && pkm.AltForm >= 28) // A-Z?!
int maxCount = pkm.GenNumber == 2 ? 26 : 28; // A-Z : A-Z?!
if (pkm.AltForm < maxCount)
valid = true;
}
if (species == 414 && pkm.AltForm < 3) // Wormadam base form kept
valid = true;
valid = true;
if ((species == 664 || species == 665) && pkm.AltForm < 18) // Vivillon Pre-evolutions
valid = true;

View File

@ -1014,7 +1014,16 @@ private static IEnumerable<MysteryGift> getMatchingPCD(PKM pkm, IEnumerable<Myst
if (DB == null)
return validPCD;
// todo
if (pkm.Species == 490 && (pkm.WasEgg || pkm.IsEgg)) // Manaphy
{
int loc = pkm.IsEgg ? pkm.Met_Location : pkm.Egg_Location;
bool valid = loc == 2001; // Link Trade Egg
valid |= loc == 3001 && !pkm.IsShiny; // Ranger & notShiny
if (valid)
validPCD.Add(new PGT { Data = { [0] = 7, [8] = 1 } });
return validPCD;
}
var vs = getValidPreEvolutions(pkm).ToArray();
foreach (PCD mg in DB.OfType<PCD>().Where(wc => vs.Any(dl => dl.Species == wc.Species)))
{
@ -1029,8 +1038,16 @@ private static IEnumerable<MysteryGift> getMatchingPCD(PKM pkm, IEnumerable<Myst
if (wc.Language != 0 && wc.Language != pkm.Language) continue;
}
if (wc.AltForm != pkm.AltForm && vs.All(dl => !getCanFormChange(pkm, dl.Species))) continue;
if (wc.Met_Location != pkm.Met_Location) continue;
if (wc.Egg_Location != pkm.Egg_Location) continue;
if (wc.IsEgg)
{
if (wc.Egg_Location + 3000 != pkm.Egg_Location) continue;
}
else
{
if (wc.Egg_Location + 3000 != pkm.Met_Location) continue;
}
if (wc.CurrentLevel != pkm.Met_Level) continue;
if (wc.Ball != pkm.Ball) continue;
if (wc.OT_Gender < 3 && wc.OT_Gender != pkm.OT_Gender) continue;

View File

@ -72,7 +72,7 @@ public override string CardTitle
}
}
public override int Species { get { return Gift.Species; } set { Gift.Species = value; } }
public override int Species { get { return Gift.IsManaphyEgg ? 490 : Gift.Species; } set { Gift.Species = value; } }
public override int[] Moves { get { return Gift.Moves; } set { Gift.Moves = value; } }
public override int HeldItem { get { return Gift.HeldItem; } set { Gift.HeldItem = value; } }
public override bool IsShiny => Gift.IsShiny;
@ -192,7 +192,7 @@ private byte[] Unknown
public override bool IsItem { get { return PGTGiftType == GiftType.Item; } set { if (value) PGTGiftType = GiftType.Item; } }
public override bool IsPokémon { get { return PGTGiftType == GiftType.Pokémon || PGTGiftType == GiftType.PokémonEgg || PGTGiftType == GiftType.ManaphyEgg; } set { } }
public override int Species { get { return PK.Species; } set { PK.Species = value; } }
public override int Species { get { return IsManaphyEgg ? 490 : PK.Species; } set { PK.Species = value; } }
public override int[] Moves { get { return PK.Moves; } set { PK.Moves = value; } }
public override int HeldItem { get { return PK.HeldItem; } set { PK.HeldItem = value; } }
public override bool IsShiny => PK.IsShiny;
@ -209,6 +209,7 @@ public override PKM convertToPKM(SaveFile SAV)
pk4.TID = SAV.TID;
pk4.SID = SAV.SID;
pk4.OT_Gender = SAV.Gender;
pk4.Language = SAV.Language;
}
if (IsManaphyEgg)
{
@ -218,6 +219,7 @@ public override PKM convertToPKM(SaveFile SAV)
pk4.Move1 = 294;
pk4.Move2 = 145;
pk4.Move3 = 346;
pk4.Ability = pk4.PersonalInfo.Abilities[0];
pk4.FatefulEncounter = true;
pk4.Ball = 4;
pk4.Version = 10; // Diamond
@ -228,7 +230,7 @@ public override PKM convertToPKM(SaveFile SAV)
// Generate IV
uint seed = Util.rnd32();
if (pk4.PID == 1 || IsManaphyEgg) // Create Nonshiny
if (pk4.PID == 1) // Create Nonshiny
{
uint pid1 = PKX.LCRNG(ref seed) >> 16;
uint pid2 = PKX.LCRNG(ref seed) >> 16;
@ -255,7 +257,7 @@ public override PKM convertToPKM(SaveFile SAV)
}
// Generate Met Info
if (!IsEgg)
if (!IsEgg && !IsManaphyEgg)
{
pk4.Met_Location = pk4.Egg_Location + 3000;
pk4.Egg_Location = 0;
@ -264,15 +266,25 @@ public override PKM convertToPKM(SaveFile SAV)
}
else
{
pk4.Egg_Location = pk4.Egg_Location + 3000;
pk4.MetDate = DateTime.Now;
pk4.IsEgg = false;
// Met Location is modified when transferred to pk5; don't worry about it.
if (SAV.Generation == 4)
{
pk4.IsEgg = true;
pk4.Met_Location = pk4.Egg_Location + 3000;
pk4.Egg_Location = 0;
pk4.IsNicknamed = true;
pk4.Nickname = PKX.getSpeciesName(0, pk4.Language).ToUpper();
pk4.MetDate = DateTime.Now;
}
else
{
pk4.IsEgg = false;
// Met Location is modified when transferred to pk5; don't worry about it.
pk4.Egg_Location = pk4.Egg_Location + 3000;
pk4.EggMetDate = DateTime.Now;
}
}
if (pk4.Species == 201) // Never will be true; Unown was never distributed.
pk4.AltForm = PKX.getUnownForm(pk4.PID);
if (IsEgg || IsManaphyEgg)
pk4.IsEgg = true;
pk4.RefreshChecksum();
return pk4;

View File

@ -311,7 +311,7 @@ public override int Met_Location
else if ((value < 2000 && value > 111) || (value < 3000 && value > 2010))
{
// Met location not in DP, set to Mystery Zone (0, illegal) as opposed to Faraway Place
BitConverter.GetBytes((ushort)0).CopyTo(Data, 0x46);
BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x46);
BitConverter.GetBytes((ushort)0).CopyTo(Data, 0x80);
}
else