PKHeX/PKHeX.Core/Legality/Structures/GBEncounterData.cs
Kurt 9a7dc9998c Misc fixes
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.
2017-05-28 16:56:51 -07:00

70 lines
2.3 KiB
C#

using System.Linq;
namespace PKHeX.Core
{
public enum GBEncounterType
{
TradeEncounterG1 = 1,
StaticEncounter = 3,
WildEncounter = 2,
EggEncounter = 9,
TradeEncounterG2 = 10,
SpecialEncounter = 20,
}
public class GBEncounterData : IEncounterable
{
public readonly int Level;
public int MoveLevel;
public GameVersion Game;
public readonly int Generation;
public readonly GBEncounterType Type;
public readonly IEncounterable Encounter;
public int Species => Encounter.Species;
public string Name => Encounter.Name;
public bool EggEncounter => Encounter.EggEncounter;
public int LevelMin => Encounter.LevelMin;
public int LevelMax => Encounter.LevelMax;
// Egg encounter
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, GameVersion game)
{
Game = game;
Generation = gen;
Encounter = enc;
if (Encounter is EncounterTrade trade)
{
if (pkm.HasOriginalMetLocation && trade.Level < pkm.Met_Level)
Level = pkm.Met_Level; // Crystal
else
Level = trade.Level;
Type = Generation == 2
? GBEncounterType.TradeEncounterG2
: GBEncounterType.TradeEncounterG1;
}
else if (Encounter is EncounterStatic statc)
{
Level = statc.Level;
Type = statc.Moves != null && statc.Moves[0] != 0 && pkm.Moves.Contains(statc.Moves[0])
? GBEncounterType.SpecialEncounter
: GBEncounterType.StaticEncounter;
}
else if (Encounter is EncounterSlot1 slot)
{
Level = pkm.HasOriginalMetLocation && slot.LevelMin >= pkm.Met_Level && pkm.Met_Level <= slot.LevelMax
? pkm.Met_Level // Crystal
: slot.LevelMin;
Type = GBEncounterType.WildEncounter;
}
MoveLevel = Level;
}
}
}