Add RBY ingame trades

A little bit of logic reorganization
This commit is contained in:
Kurt 2017-02-22 21:19:29 -08:00
parent e7fcee3b62
commit 234189b627
5 changed files with 127 additions and 38 deletions

View file

@ -13,7 +13,7 @@ namespace PKHeX.Core
private object EncounterMatch, EncounterOriginal;
private Type EncounterType;
private bool EncounterIsMysteryGift => EncounterType.IsSubclassOf(typeof (MysteryGift));
private string EncounterName => Legal.getEncounterTypeName(pkm, EncounterMatch);
private string EncounterName => Legal.getEncounterTypeName(pkm, EncounterOriginal ?? EncounterMatch);
private List<MysteryGift> EventGiftMatch;
private CheckResult Encounter, History;
private int[] RelearnBase;
@ -148,7 +148,7 @@ namespace PKHeX.Core
{
EncounterMatch = EncounterMatch ?? pkm.Species;
EncounterType = EncounterMatch?.GetType();
EncounterType = (EncounterOriginal ?? EncounterMatch)?.GetType();
if (EncounterType == typeof (MysteryGift))
EncounterType = EncounterType.BaseType;
}

View file

@ -194,7 +194,22 @@ namespace PKHeX.Core
else if (pkm.SM)
{
// TODO
AddLine(Severity.Valid, "Ingame Trade for Sun/Moon un-implemented.", CheckIdentifier.Nickname);
AddLine(Severity.Valid, "Ingame Trade for Sun/Moon not implemented.", CheckIdentifier.Nickname);
return;
}
else if (pkm.Format <= 2 || pkm.VC)
{
var et = EncounterOriginal as EncounterTrade;
if (et?.TID == 0) // Gen1 Trade
{
string ot = pkm.OT_Name;
if (ot != "トレーナー" && ot != "TRAINER")
AddLine(Severity.Invalid, "Incorrect OT name for RBY in-game trade.", CheckIdentifier.Trainer);
}
else // Gen2
{
AddLine(Severity.Valid, "Ingame Trade for GSC not implemented.", CheckIdentifier.Trainer);
}
return;
}
@ -554,10 +569,10 @@ namespace PKHeX.Core
EncounterMatch = e;
return verifyEncounterWild();
}
if (sm <= em && sm <= tm)
if (tm <= sm && tm <= em)
{
EncounterMatch = s;
return verifyEncounterStatic();
EncounterMatch = t;
return verifyEncounterTrade();
}
// else is trade
@ -575,6 +590,7 @@ namespace PKHeX.Core
// Get EncounterMatch prior to parsing transporter legality
var result = verifyEncounterG1();
EncounterOriginal = EncounterMatch;
if (pkm.Format > 2) // transported to 7+
AddLine(verifyVCEncounter(baseSpecies));
@ -640,8 +656,7 @@ namespace PKHeX.Core
if (!exceptions)
AddLine(new CheckResult(Severity.Invalid, "Special encounter is not available to Virtual Console games.", CheckIdentifier.Encounter));
}
EncounterOriginal = EncounterMatch; // Store for later recollection
EncounterMatch = new EncounterStatic
{
Species = species,
@ -951,6 +966,7 @@ namespace PKHeX.Core
AddLine(Severity.Valid, "Ability matches ability number.", CheckIdentifier.Ability);
}
private void verifyBall()
{
if (pkm.GenNumber < 6)
@ -1026,29 +1042,8 @@ namespace PKHeX.Core
if (pkm.WasEgg)
{
if (pkm.GenNumber < 6) // No inheriting Balls
{
if (pkm.Ball != 0x04)
AddLine(Severity.Invalid, "Ball should be Pokéball.", CheckIdentifier.Ball);
return;
}
if (pkm.Ball == 0x01) // Master Ball
{ AddLine(Severity.Invalid, "Master Ball on egg origin.", CheckIdentifier.Ball); return; }
if (pkm.Ball == 0x10) // Cherish Ball
{ AddLine(Severity.Invalid, "Cherish Ball on non-event.", CheckIdentifier.Ball); return; }
if (pkm.Ball == 0x04) // Poké Ball
{ AddLine(Severity.Valid, "Standard Poké Ball.", CheckIdentifier.Ball); return; }
switch (pkm.GenNumber)
{
case 6: // Gen6 Inheritance Rules
verifyEggBallGen6();
return;
case 7: // Gen7 Inheritance Rules
verifyEggBallGen7();
return;
}
verifyBallEgg();
return;
}
if (pkm.Ball == 0x04) // Poké Ball
@ -1059,7 +1054,35 @@ namespace PKHeX.Core
AddLine(Severity.Invalid, "No ball check satisfied, assuming illegal.", CheckIdentifier.Ball);
}
private void verifyEggBallGen6()
private void verifyBallEgg()
{
if (pkm.GenNumber < 6) // No inheriting Balls
{
if (pkm.Ball != 0x04) // Must be Pokéball -- no ball inheritance.
AddLine(Severity.Invalid, "Ball should be Pokéball.", CheckIdentifier.Ball);
else
AddLine(Severity.Valid, "Pokéball on egg.", CheckIdentifier.Ball);
return;
}
if (pkm.Ball == 0x01) // Master Ball
{ AddLine(Severity.Invalid, "Master Ball on egg origin.", CheckIdentifier.Ball); return; }
if (pkm.Ball == 0x10) // Cherish Ball
{ AddLine(Severity.Invalid, "Cherish Ball on non-event.", CheckIdentifier.Ball); return; }
if (pkm.Ball == 0x04) // Poké Ball
{ AddLine(Severity.Valid, "Standard Poké Ball.", CheckIdentifier.Ball); return; }
switch (pkm.GenNumber)
{
case 6: // Gen6 Inheritance Rules
verifyBallEggGen6();
return;
case 7: // Gen7 Inheritance Rules
verifyBallEggGen7();
return;
}
}
private void verifyBallEggGen6()
{
if (pkm.Gender == 2) // Genderless
{
@ -1159,7 +1182,7 @@ namespace PKHeX.Core
? "Ball unobtainable in origin generation."
: "No ball check satisfied, assuming illegal.", CheckIdentifier.Ball);
}
private void verifyEggBallGen7()
private void verifyBallEggGen7()
{
var Lineage = Legal.getLineage(pkm).ToArray();
if (722 <= pkm.Species && pkm.Species <= 730) // G7 Starters
@ -1398,7 +1421,7 @@ namespace PKHeX.Core
}
else // Is Traded
{
if (pkm.HT_Memory == 0 && pkm.Format == 6)
if (pkm.Format == 6 && pkm.HT_Memory == 0)
return new CheckResult(Severity.Invalid, "Memory -- missing Handling Trainer Memory.", CheckIdentifier.History);
}

View file

@ -319,8 +319,14 @@ namespace PKHeX.Core
}
internal static EncounterTrade getValidIngameTrade(PKM pkm, bool gen1Encounter = false)
{
if (pkm.VC || pkm.Format <= 2)
return getValidEncounterTradeVC(pkm);
if (!pkm.WasIngameTrade)
return null;
{
if (pkm.HasOriginalMetLocation)
return null;
}
int lang = pkm.Language;
if (lang == 0 || lang == 6)
return null;
@ -332,9 +338,7 @@ namespace PKHeX.Core
IEnumerable<DexLevel> p = getValidPreEvolutions(pkm);
EncounterTrade[] table = null;
if (pkm.VC1)
table = TradeGift_RBY;
else if (pkm.XY)
if (pkm.XY)
table = TradeGift_XY;
else if (pkm.AO)
table = TradeGift_AO;
@ -373,6 +377,35 @@ namespace PKHeX.Core
return z;
}
internal static EncounterTrade getValidEncounterTradeVC(PKM pkm)
{
var p = getValidPreEvolutions(pkm).ToArray();
// Check GSC Trades first, if no match return the result from RBY.
return getValidEncounterTradeVC2(pkm, p) ?? getValidEncounterTradeVC1(pkm, p);
}
private static EncounterTrade getValidEncounterTradeVC2(PKM pkm, DexLevel[] p)
{
var z = TradeGift_GSC.FirstOrDefault(f => p.Any(r => r.Species == f.Species));
if (z == null)
return null;
// Filter Criteria
for (int i = 0; i < 6; i++)
if (z.IVs[i] != -1 && z.IVs[i] != pkm.IVs[i])
return null;
if (z.TID != pkm.TID)
return null;
return z;
}
private static EncounterTrade getValidEncounterTradeVC1(PKM pkm, DexLevel[] p)
{
var z = TradeGift_RBY.FirstOrDefault(f => p.Any(r => r.Species == f.Species));
if (z?.Level > pkm.CurrentLevel) // minimum required level
return null;
return z;
}
internal static EncounterSlot[] getValidFriendSafari(PKM pkm)
{
if (!pkm.XY)

View file

@ -107,6 +107,35 @@ namespace PKHeX.Core
};
internal static readonly EncounterTrade[] TradeGift_RBY =
{
// Species & Minimum level (legal) possible to acquire at.
new EncounterTrade { Species = 122, Level = 06 }, // Mr. Mime - Game Corner Abra
new EncounterTrade { Species = 032, Level = 02 }, // Nidoran♂ - Wild Nidoran♀
new EncounterTrade { Species = 029, Level = 02 }, // Nidoran♀ - Wild Nidoran♂
new EncounterTrade { Species = 030, Level = 16 }, // Nidorina - Evolve Nidorino
new EncounterTrade { Species = 108, Level = 15 }, // Lickitung - Surf Slowbro
new EncounterTrade { Species = 124, Level = 15 }, // Jynx - Fish Poliwhirl (GSC: 10)
new EncounterTrade { Species = 083, Level = 02 }, // Farfetchd - Wild Spearow
new EncounterTrade { Species = 101, Level = 03 }, // Electrode - Wild Raichu
new EncounterTrade { Species = 114, Level = 13 }, // Tangela - Wild Venonat (GSC: 5)
new EncounterTrade { Species = 086, Level = 28 }, // Seel - Wild Ponyta (GSC: 6)
//new EncounterTrade { Species = 122, Level = 03 }, // Mr. Mime - Wild Jigglypuff
new EncounterTrade { Species = 060, Level = 02 }, // Poliwag - Wild Rattata
new EncounterTrade { Species = 115, Level = 42 }, // Kangaskhan - Evolve Rhydon (GSC: 30)
new EncounterTrade { Species = 128, Level = 28 }, // Tauros - Evolve Persian (GSC: 18)
new EncounterTrade { Species = 093, Level = 20 }, // Haunter - Trade Machoke (GSC: 10)
//new EncounterTrade { Species = 083, Level = 02 }, // Farfetchd - Wild Pidgey
new EncounterTrade { Species = 075, Level = 16 }, // Graveler - Evolve Kadabra (GSC: 15)
new EncounterTrade { Species = 079, Level = 22 }, // Slowpoke - Wild Seel
new EncounterTrade { Species = 098, Level = 15 }, // Krabby - Wild Growlithe (GSC: 5)
//new EncounterTrade { Species = 122, Level = 08 }, // Mr. Mime - Wild Clefairy (GSC: 6)
new EncounterTrade { Species = 067, Level = 20 }, // Machoke - Wild Cubone (GSC: 10)
new EncounterTrade { Species = 051, Level = 15 }, // Dugtrio - Trade Lickitung
new EncounterTrade { Species = 047, Level = 13 }, // Parasect - Trade Tangela
new EncounterTrade { Species = 112, Level = 15 }, // Rhydon - Surf Golduck (GSC: 10)
new EncounterTrade { Species = 087, Level = 15 }, // Dewgong - Wild Growlithe (GSC: 5)
new EncounterTrade { Species = 089, Level = 25 }, // Muk - Wild Kangaskhan (GSC: 14)
};
internal static readonly EncounterArea FishOldGood_RBY = new EncounterArea { Location = -1, Slots = new EncounterSlot[]
{

View file

@ -41,5 +41,9 @@ namespace PKHeX.Core
{
424,429,430,461,462,463,464,465,466,467,468,469,470,471,472,473,474,700
};
internal static readonly EncounterTrade[] TradeGift_GSC =
{
};
}
}