Reduce static constructor requirements

Gen1: all are Trade1 objects, and all get the values set; just set the value in the object initializer
Gen2: all are Trade2 objects, set the same version

Gen2 all static encounters already have a version marked. Only thing remaining is to set the language.
This commit is contained in:
Kurt 2020-09-05 13:06:08 -07:00
parent 81e98b5549
commit 8a3804e4b3
4 changed files with 14 additions and 23 deletions

View file

@ -15,13 +15,6 @@ namespace PKHeX.Core
private static EncounterArea1[] Get(string name, string ident, GameVersion game) =>
EncounterArea1.GetAreas(BinLinker.Unpack(Util.GetBinaryResource($"encounter_{name}.pkl"), ident), game);
static Encounters1()
{
var trades = ArrayUtil.ConcatAll(TradeGift_RBY_NoTradeback, TradeGift_RBY_Tradeback);
foreach (var t in trades)
t.TrainerNames = StringConverter12.G1TradeOTName;
}
internal static readonly EncounterStatic1[] StaticRBY =
{
// GameVersion is RBY for Pokemon with the same catch rate and initial moves in all games

View file

@ -19,15 +19,7 @@ namespace PKHeX.Core
private static EncounterArea2[] Get(string name, string ident, GameVersion game) =>
EncounterArea2.GetAreas(BinLinker.Unpack(Util.GetBinaryResource($"encounter_{name}.pkl"), ident), game);
static Encounters2()
{
MarkEncounterTradeStrings(TradeGift_GSC, TradeGift_GSC_OTs);
StaticGSC.SetVersion(GameVersion.GSC);
StaticGS.SetVersion(GameVersion.GS);
StaticC.SetVersion(GameVersion.C);
TradeGift_GSC.SetVersion(GameVersion.GSC);
}
static Encounters2() => MarkEncounterTradeStrings(TradeGift_GSC, TradeGift_GSC_OTs);
private static readonly EncounterStatic2[] Encounter_GSC_Common =
{
@ -143,7 +135,7 @@ namespace PKHeX.Core
private static readonly EncounterStatic2[] Encounter_C = Encounter_GSC_Common.Concat(Encounter_C_Exclusive).Concat(Encounter_GSC_Roam.Slice(0, 2)).ToArray();
private static readonly EncounterStatic2[] Encounter_GSC = Encounter_GSC_Common.Concat(Encounter_GS_Exclusive).Concat(Encounter_C_Exclusive).Concat(Encounter_GSC_Roam).ToArray();
internal static readonly EncounterTradeGB[] TradeGift_GSC =
internal static readonly EncounterTrade2[] TradeGift_GSC =
{
new EncounterTrade2(095, 03, 48926) { Gender = 0, IVs = new[] {08, 09, 06, 06, 06, 06} }, // Onix @ Violet City for Bellsprout [wild]
new EncounterTrade2(066, 05, 37460) { Gender = 1, IVs = new[] {12, 03, 07, 06, 06, 06} }, // Machop @ Goldenrod City for Drowzee [wild 9, hatched egg 5]
@ -163,14 +155,14 @@ namespace PKHeX.Core
private const string tradeGSC = "tradegsc";
private static readonly string[][] TradeGift_GSC_OTs = Util.GetLanguageStrings8(tradeGSC);
internal static TreeEncounterAvailable GetGSCHeadbuttAvailability(EncounterSlot encounter, int TID)
internal static TreeEncounterAvailable GetGSCHeadbuttAvailability(EncounterSlot encounter, int trainerID)
{
var Area = Array.Find(HeadbuttTreesC, a => a.Location == encounter.Location);
if (Area == null) // Failsafe, every area with headbutt encounters has a tree area
var area = Array.Find(HeadbuttTreesC, a => a.Location == encounter.Location);
if (area == null) // Failsafe, every area with headbutt encounters has a tree area
return TreeEncounterAvailable.Impossible;
var table = Area.GetTrees(encounter.Area.Type);
var trainerpivot = TID % 10;
var table = area.GetTrees(encounter.Area.Type);
var trainerpivot = trainerID % 10;
return table[trainerpivot];
}

View file

@ -23,7 +23,12 @@
private bool HasOddCatchRate => Catch_Rate != 0;
public EncounterTrade1(int species, int level, GameVersion game, byte rate) : this(species, level, game) => Catch_Rate = rate;
public EncounterTrade1(int species, int level, GameVersion game) : base(species, level) => Version = game;
public EncounterTrade1(int species, int level, GameVersion game) : base(species, level)
{
Version = game;
TrainerNames = StringConverter12.G1TradeOTName;
}
public byte GetInitialCatchRate()
{

View file

@ -9,6 +9,7 @@ namespace PKHeX.Core
public EncounterTrade2(int species, int level, int tid) : base(species, level)
{
TID = tid;
Version = GameVersion.GSC; // All share the same details
}
public override bool IsMatch(PKM pkm)