Skip to content

Commit

Permalink
Misc fixes
Browse files Browse the repository at this point in the history
Track gen1/2 origin game as well  as generation
fix pk2 gender setting (incorrect bitmask & wasn't set from tabs)
extend female gender check for gen2 to apply to GS encounters -- if met
location is missing, was traded to gen1 which clears gender.
  • Loading branch information
kwsch committed May 28, 2017
1 parent e01c8a5 commit 9a7dc99
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion PKHeX.Core/Legality/Checks.cs
Expand Up @@ -447,7 +447,7 @@ private void verifyG1OT()
AddLine(Severity.Invalid, V402, CheckIdentifier.Trainer);
}

if (pkm.OT_Gender == 1)
if (pkm.OT_Gender == 1 && (pkm.Format == 2 && pkm.Met_Location == 0 || !info.Game.Contains(GameVersion.C)))
AddLine(Severity.Invalid, V408, CheckIdentifier.Trainer);
}
#endregion
Expand Down
24 changes: 14 additions & 10 deletions PKHeX.Core/Legality/Encounters/EncounterGenerator.cs
Expand Up @@ -14,7 +14,7 @@ public static IEnumerable<IEncounterable> getEncounters(PKM pkm, LegalInfo info)
{
case 1:
case 2:
foreach (var enc in getEncounters12(pkm))
foreach (var enc in getEncounters12(pkm, info))
yield return enc;
yield break;
case 3:
Expand All @@ -31,7 +31,7 @@ public static IEnumerable<IEncounterable> getEncounters(PKM pkm, LegalInfo info)
}
}

private static IEnumerable<IEncounterable> getEncounters12(PKM pkm)
private static IEnumerable<IEncounterable> getEncounters12(PKM pkm, LegalInfo info)
{
int baseSpecies = getBaseSpecies(pkm);
bool g1 = pkm.VC1 || pkm.Format == 1;
Expand All @@ -40,7 +40,11 @@ private static IEnumerable<IEncounterable> getEncounters12(PKM pkm)
yield break;

foreach (var z in GenerateFilteredEncounters(pkm))
yield return z;
{
info.Generation = z.Generation;
info.Game = z.Game;
yield return z.Encounter;
}
}
private static IEnumerable<GBEncounterData> GenerateRawEncounters12(PKM pkm, GameVersion game)
{
Expand All @@ -64,18 +68,18 @@ private static IEnumerable<GBEncounterData> GenerateRawEncounters12(PKM pkm, Gam
deferred.Add(s);
continue;
}
yield return new GBEncounterData(pkm, gen, s);
yield return new GBEncounterData(pkm, gen, s, game);
}

foreach (var e in getValidWildEncounters(pkm, game))
{
if (!species.Contains(e.Species))
continue;
yield return new GBEncounterData(pkm, gen, e);
yield return new GBEncounterData(pkm, gen, e, game);
}
foreach (var t in getValidEncounterTrade(pkm, game))
{
yield return new GBEncounterData(pkm, gen, t);
yield return new GBEncounterData(pkm, gen, t, game);
}

if (game == GameVersion.GSC)
Expand All @@ -99,20 +103,20 @@ private static IEnumerable<GBEncounterData> GenerateRawEncounters12(PKM pkm, Gam
}

foreach (var d in deferred)
yield return new GBEncounterData(pkm, gen, d);
yield return new GBEncounterData(pkm, gen, d, game);
}
private static IEnumerable<IEncounterable> GenerateFilteredEncounters(PKM pkm)
private static IEnumerable<GBEncounterData> GenerateFilteredEncounters(PKM pkm)
{
IEnumerable<GBEncounterData> filter(IEnumerable<GBEncounterData> data) => data
.OrderBy(z => z.Type == GBEncounterType.EggEncounter).ThenBy(z => z.Species).ThenBy(z => z.Level);

if (!pkm.Gen2_NotTradeback)
foreach (var z in filter(GenerateRawEncounters12(pkm, GameVersion.RBY)))
yield return z.Encounter;
yield return z;

if (!pkm.Gen1_NotTradeback && AllowGen2VCTransfer)
foreach (var z in filter(GenerateRawEncounters12(pkm, GameVersion.GSC)))
yield return z.Encounter;
yield return z;
}
private static IEnumerable<IEncounterable> getEncounters34(PKM pkm)
{
Expand Down
10 changes: 9 additions & 1 deletion PKHeX.Core/Legality/Encounters/LegalInfo.cs
Expand Up @@ -10,6 +10,9 @@ public class LegalInfo
/// <summary>The generation of games the PKM originated from.</summary>
public int Generation;

/// <summary> The Game the PPKM originated from.</summary>
public GameVersion Game { get; set; }

/// <summary>The matched Encounter details for the <see cref="PKM"/>. </summary>
public IEncounterable EncounterMatch
{
Expand Down Expand Up @@ -37,6 +40,11 @@ public IEncounterable EncounterMatch
private IEncounterable _match;
public PIDIV PIDIV;

public LegalInfo(PKM pk) => pkm = pk;
public LegalInfo(PKM pk)
{
pkm = pk;
Game = (GameVersion) pkm.Version;
Generation = pkm.GenNumber;
}
}
}
7 changes: 4 additions & 3 deletions PKHeX.Core/Legality/Structures/GBEncounterData.cs
Expand Up @@ -16,8 +16,7 @@ public class GBEncounterData : IEncounterable
{
public readonly int Level;
public int MoveLevel;
public bool Gen2 => Generation == 2;
public bool Gen1 => Generation == 1;
public GameVersion Game;
public readonly int Generation;
public readonly GBEncounterType Type;
public readonly IEncounterable Encounter;
Expand All @@ -32,11 +31,13 @@ public class GBEncounterData : IEncounterable
public GBEncounterData(int species, GameVersion game)
{
Generation = 2;
Game = game;
Encounter = new EncounterEgg { Species = species, Game = game, Level = Level };
}

public GBEncounterData(PKM pkm, int gen, IEncounterable enc)
public GBEncounterData(PKM pkm, int gen, IEncounterable enc, GameVersion game)
{
Game = game;
Generation = gen;
Encounter = enc;
if (Encounter is EncounterTrade trade)
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Core/PKM/PK2.cs
Expand Up @@ -176,7 +176,7 @@ public override uint EXP
private int CaughtData { get => BigEndian.ToUInt16(Data, 0x1D); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x1D); }
public int Met_TimeOfDay { get => (CaughtData >> 14) & 0x3; set => CaughtData = (CaughtData & 0x3FFF) | ((value & 0x3) << 14); }
public override int Met_Level { get => (CaughtData >> 8) & 0x3F; set => CaughtData = (CaughtData & 0xC0FF) | ((value & 0x3F) << 8); }
public override int OT_Gender { get => (CaughtData >> 7) & 1; set => CaughtData = (CaughtData & 0xFFEF) | ((value & 1) << 7); }
public override int OT_Gender { get => (CaughtData >> 7) & 1; set => CaughtData = (CaughtData & 0xFF7F) | ((value & 1) << 7); }
public override int Met_Location { get => CaughtData & 0x7F; set => CaughtData = (CaughtData & 0xFF80) | (value & 0x7F); }

public override int Stat_Level
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Core/Resources/text/en/LegalityCheckStrings_en.txt
Expand Up @@ -338,4 +338,4 @@ V402 = Incorrect Stadium OT.
V405 = Outsider {0} should have evolved into {1}.
V406 = Non Japanese Shadow E-reader Pokémon. Unreleased encounter.
V407 = OT from Colosseum/XD cannot be female.
V408 = OT from Generation 1 cannot be female.
V408 = Female OT from Generation 1/2 is invalid.
2 changes: 1 addition & 1 deletion PKHeX.Core/Resources/text/ko/LegalityCheckStrings_ko.txt
Expand Up @@ -339,4 +339,4 @@ V402 = Incorrect Stadium OT.
V405 = Outsider {0} should have evolved into {1}.
V406 = Non Japanese Shadow E-reader Pokémon. Unreleased encounter.
V407 = OT from Colosseum/XD cannot be female.
V408 = OT from Generation 1 cannot be female.
V408 = Female OT from Generation 1/2 is invalid.
2 changes: 1 addition & 1 deletion PKHeX.Core/Resources/text/zh/LegalityCheckStrings_zh.txt
Expand Up @@ -338,4 +338,4 @@ V402 = 不正确竞技场初训家。
V405 = 外来的{0}应当进化为{1}.
V406 = 非日版黑暗E-reader宝可梦。未解禁遇见方式。
V407 = OT from Colosseum/XD cannot be female.
V408 = OT from Generation 1 cannot be female.
V408 = Female OT from Generation 1/2 is invalid.
1 change: 1 addition & 0 deletions PKHeX.WinForms/Controls/PKM Editor/EditPK2.cs
Expand Up @@ -86,6 +86,7 @@ private PKM preparePK2()
pk2.HeldItem = WinFormsUtil.getIndex(CB_HeldItem);
pk2.IsEgg = CHK_IsEgg.Checked;
pk2.CurrentFriendship = Util.ToInt32(TB_Friendship.Text);
pk2.OT_Gender = PKX.getGender(Label_OTGender.Text);
pk2.Met_Level = Util.ToInt32(TB_MetLevel.Text);
pk2.Met_Location = WinFormsUtil.getIndex(CB_MetLocation);
pk2.Met_TimeOfDay = CB_MetTimeOfDay.SelectedIndex;
Expand Down

0 comments on commit 9a7dc99

Please sign in to comment.