Add trophy garden encounters (dppt)

Refactor addExtraTableSlots to instead combine encounter tables
slightly faster due to not repeating the where comparison and over
multiple calls

select all tables from array -> group by location -> combine slots if
many tables -> return combined array

fixes transferred 4->5 event met level check
This commit is contained in:
Kurt
2017-03-26 01:25:21 -07:00
parent 6bea46ced3
commit 6a0d824b31
4 changed files with 52 additions and 27 deletions

View File

@@ -784,7 +784,7 @@ private CheckResult verifyVCEncounter(int baseSpecies)
if (pkm.Egg_Location != ematch.EggLocation)
return new CheckResult(Severity.Invalid, V59, CheckIdentifier.Encounter);
if (species == 150 && pkm.Moves.Contains(6))
if (species == 150 && pkm.Moves.Contains(6)) // pay day
return new CheckResult(Severity.Invalid, V82, CheckIdentifier.Encounter);
return new CheckResult(CheckIdentifier.Encounter);
@@ -795,7 +795,7 @@ private void verifyLevel()
MysteryGift MatchedGift = EncounterMatch as MysteryGift;
if (MatchedGift != null && MatchedGift.Level != pkm.Met_Level)
{
if (!(MatchedGift is WC7) || ((WC7) MatchedGift).MetLevel != pkm.Met_Level)
if (pkm.HasOriginalMetLocation && (!(MatchedGift is WC7) || ((WC7) MatchedGift).MetLevel != pkm.Met_Level))
{
AddLine(new CheckResult(Severity.Invalid, V83, CheckIdentifier.Level));
return;

View File

@@ -159,16 +159,13 @@ private static EncounterArea[] getEncounterTables(byte[] mini, string ident)
{
return EncounterArea.getArray(Data.unpackMini(mini, ident));
}
private static EncounterArea[] addExtraTableSlots(EncounterArea[] GameSlots, EncounterArea[] SpecialSlots)
private static EncounterArea[] addExtraTableSlots(params EncounterArea[][] tables)
{
foreach (EncounterArea g in GameSlots)
{
var tables = SpecialSlots.Where(l => l.Location == g.Location).ToList();
if (tables.Any())
g.Slots = g.Slots.Concat(tables.SelectMany(t => t.Slots)).ToArray();
}
var notInserted = SpecialSlots.Where(s => GameSlots.All(g => g.Location != s.Location));
return GameSlots.Concat(notInserted).ToArray();
return tables.SelectMany(s => s).GroupBy(l => l.Location)
.Select(t => t.Count() == 1
? t.First() // only one table, just return the area
: new EncounterArea {Location = t.First().Location, Slots = t.SelectMany(s => s.Slots).ToArray()})
.ToArray();
}
private static void ReduceAreasSize(ref EncounterArea[] Areas)
{
@@ -342,11 +339,7 @@ private static EncounterArea[] getTables1()
var rb_fish = EncounterArea.getArray1_F(Resources.encounter_rb_f);
var ylw_fish = EncounterArea.getArray1_FY(Resources.encounter_yellow_f);
var red = addExtraTableSlots(red_gw, rb_fish);
var blu = addExtraTableSlots(blu_gw, rb_fish);
var ylw = addExtraTableSlots(ylw_gw, ylw_fish);
var table = addExtraTableSlots(addExtraTableSlots(red, blu), ylw).ToArray();
var table = addExtraTableSlots(red_gw, blu_gw, ylw_gw, rb_fish, ylw_fish);
Array.Resize(ref table, table.Length + 1);
table[table.Length - 1] = FishOldGood_RBY;
@@ -366,7 +359,7 @@ private static EncounterArea[] getTables2(GameVersion Version)
var h_g = EncounterArea.getArray2_H(Resources.encounter_gold_h);
var h_s = EncounterArea.getArray2_H(Resources.encounter_silver_h);
Slots = addExtraTableSlots(addExtraTableSlots(addExtraTableSlots(addExtraTableSlots(g, s), h_g), h_s),f);
Slots = addExtraTableSlots(g, s, h_g, h_s,f);
}
if (Version == GameVersion.C || Version == GameVersion.GSC)
{
@@ -375,7 +368,7 @@ private static EncounterArea[] getTables2(GameVersion Version)
// Headbutt/Rock Smash
var h_c = EncounterArea.getArray2_H(Resources.encounter_crystal_h);
var extra = addExtraTableSlots(addExtraTableSlots(c, h_c),f);
var extra = addExtraTableSlots(c, h_c, f);
return Version == GameVersion.C ? extra : addExtraTableSlots(Slots, extra);
}
@@ -456,6 +449,8 @@ private static EncounterArea[] getTables2(GameVersion Version)
var Pt_Slots = getEncounterTables(GameVersion.Pt);
var HG_Slots = getEncounterTables(GameVersion.HG);
var SS_Slots = getEncounterTables(GameVersion.SS);
var DP_Trophy = EncounterArea.getTrophyArea(TrophyDP, new[] {16, 18});
var Pt_Trophy = EncounterArea.getTrophyArea(TrophyPt, new[] {22, 22});
var HG_Headbutt_Slots = EncounterArea.getArray4HGSS_Headbutt(Data.unpackMini(Resources.encunters_hb_hg, "hg"));
var SS_Headbutt_Slots = EncounterArea.getArray4HGSS_Headbutt(Data.unpackMini(Resources.encunters_hb_ss, "ss"));
@@ -484,11 +479,11 @@ private static EncounterArea[] getTables2(GameVersion Version)
MarkG4Slots(ref HG_Headbutt_Slots);
MarkG4Slots(ref SS_Headbutt_Slots);
SlotsD = addExtraTableSlots(addExtraTableSlots(D_Slots, D_HoneyTrees_Slots), SlotsDPPPtAlt);
SlotsP = addExtraTableSlots(addExtraTableSlots(P_Slots, P_HoneyTrees_Slots), SlotsDPPPtAlt);
SlotsPt = addExtraTableSlots(addExtraTableSlots(Pt_Slots, Pt_HoneyTrees_Slots), SlotsDPPPtAlt);
SlotsHG = addExtraTableSlots(addExtraTableSlots(HG_Slots, HG_Headbutt_Slots), SlotsHGSSAlt);
SlotsSS = addExtraTableSlots(addExtraTableSlots(SS_Slots, SS_Headbutt_Slots), SlotsHGSSAlt);
SlotsD = addExtraTableSlots(D_Slots, D_HoneyTrees_Slots, SlotsDPPPtAlt, DP_Trophy);
SlotsP = addExtraTableSlots(P_Slots, P_HoneyTrees_Slots, SlotsDPPPtAlt, DP_Trophy);
SlotsPt = addExtraTableSlots(Pt_Slots, Pt_HoneyTrees_Slots, SlotsDPPPtAlt, Pt_Trophy);
SlotsHG = addExtraTableSlots(HG_Slots, HG_Headbutt_Slots, SlotsHGSSAlt);
SlotsSS = addExtraTableSlots(SS_Slots, SS_Headbutt_Slots, SlotsHGSSAlt);
Evolves4 = new EvolutionTree(new[] { Resources.evos_g4 }, GameVersion.DP, PersonalTable.DP, MaxSpeciesID_4);
@@ -523,8 +518,8 @@ private static EncounterArea[] getTables2(GameVersion Version)
MarkB2W2SwarmSlots(ref SlotsW2_Swarm);
MarkG5HiddenGrottoSlots(ref SlotsB2_HiddenGrotto);
MarkG5HiddenGrottoSlots(ref SlotsW2_HiddenGrotto);
SlotsB2 = addExtraTableSlots(B2Slots, SlotsB2_Swarm).Concat(SlotsB2_HiddenGrotto).ToArray();
SlotsW2 = addExtraTableSlots(W2Slots, SlotsW2_Swarm).Concat(SlotsW2_HiddenGrotto).ToArray();
SlotsB2 = addExtraTableSlots(B2Slots, SlotsB2_Swarm, SlotsB2_HiddenGrotto);
SlotsW2 = addExtraTableSlots(W2Slots, SlotsW2_Swarm, SlotsW2_HiddenGrotto);
Evolves5 = new EvolutionTree(new[] { Resources.evos_g5 }, GameVersion.BW, PersonalTable.BW, MaxSpeciesID_5);
}
@@ -561,8 +556,8 @@ private static EncounterArea[] getTables2(GameVersion Version)
MarkG7REGSlots(ref REG_MN);
MarkG7SMSlots(ref SOS_SN);
MarkG7SMSlots(ref SOS_MN);
SlotsSN = addExtraTableSlots(REG_SN, SOS_SN).Concat(Encounter_Pelago_SM).Concat(Encounter_Pelago_SN).ToArray();
SlotsMN = addExtraTableSlots(REG_MN, SOS_MN).Concat(Encounter_Pelago_SM).Concat(Encounter_Pelago_MN).ToArray();
SlotsSN = addExtraTableSlots(REG_SN, SOS_SN, Encounter_Pelago_SM, Encounter_Pelago_SN);
SlotsMN = addExtraTableSlots(REG_MN, SOS_MN, Encounter_Pelago_SM, Encounter_Pelago_MN);
Evolves7 = new EvolutionTree(Data.unpackMini(Resources.evos_sm, "sm"), GameVersion.SM, PersonalTable.SM, MaxSpeciesID_7);
}

View File

@@ -869,6 +869,33 @@ public static EncounterArea[] getArray4HGSS_Headbutt(byte[][] entries)
return entries?.Select(getArea4HGSS_Headbutt).Where(Area => Area.Slots.Any()).ToArray();
}
/// <summary>
/// Gets the encounter areas for the Trophy Garden
/// </summary>
/// <param name="species">List of special species that can exist in the garden.</param>
/// <param name="lvls">Levels of the two encounter slots they can replace. <see cref="GameVersion.DP"/> differs from <see cref="GameVersion.Pt"/></param>
/// <returns></returns>
public static EncounterArea[] getTrophyArea(IEnumerable<int> species, int[] lvls)
{
int[] slotnums = {6, 7};
var l = new List<EncounterSlot>();
foreach (var s in species)
{
for (int i = 0; i < 2; i++)
{
l.Add(new EncounterSlot
{
LevelMax = lvls[i],
LevelMin = lvls[i],
Species = s,
SlotNumber = slotnums[i],
Type = SlotType.Grass
});
}
}
return new[] { new EncounterArea { Location = 68, Slots = l.ToArray() } };
}
public static EncounterArea[] getArray(byte[][] entries)
{
if (entries == null)

View File

@@ -616,6 +616,9 @@ public static partial class Legal
}).ToArray()
};
private static int[] TrophyDP = {035, 039, 052, 113, 133, 137, 173, 174, 183, 298, 311, 312, 351, 438, 439, 440}; // Porygon
private static int[] TrophyPt = {035, 039, 052, 113, 133, 132, 173, 174, 183, 298, 311, 312, 351, 438, 439, 440}; // Ditto
private static readonly int[] Shellos_EastSeaLocation_DP =
{
28, // Route 213