using System; using System.Collections.Generic; using System.Linq; namespace PKHeX.Core { /// /// /// encounter area /// public abstract class EncounterArea4 : EncounterArea { /// /// Reads the GBA Pak Special slots, cloning data from the area's base encounter slots. /// /// /// These special slots only contain the info of species id; the level is copied from the corresponding index. /// /// Encounter binary data /// Offset to read from /// DP/Pt slotSize = 4 bytes/entry, HG/SS slotSize = 2 bytes/entry /// Slots from regular encounter table that end up replaced by in-game conditions /// Slot indexes to replace with read species IDs /// Slot type of the special encounter protected static List GetSlots4GrassSlotReplace(byte[] data, int ofs, int slotSize, EncounterSlot[] ReplacedSlots, int[] slotnums, SlotType t = SlotType.Grass) { var slots = new List(); int numslots = slotnums.Length; for (int i = 0; i < numslots; i++) { var baseSlot = ReplacedSlots[slotnums[i]]; if (baseSlot.LevelMin <= 0) continue; int species = BitConverter.ToUInt16(data, ofs + (i / (4 / slotSize) * slotSize)); if (species <= 0 || baseSlot.Species == species) // Empty or duplicate continue; var slot = baseSlot.Clone(); slot.Species = species; slot.Type = t; slot.SlotNumber = i; slots.Add(slot); } return slots; } protected static IEnumerable MarkStaticMagnetExtras(IEnumerable>> product) { var trackPermute = new List(); foreach (var p in product) MarkStaticMagnetPermute(p.SelectMany(z => z), trackPermute); return trackPermute; } protected static void MarkStaticMagnetPermute(IEnumerable grp, List trackPermute) { EncounterUtil.MarkEncountersStaticMagnetPullPermutation(grp, PersonalTable.HGSS, trackPermute); } protected override IEnumerable GetMatchFromEvoLevel(PKM pkm, IEnumerable vs, int minLevel) { var slots = Slots.Where(slot => vs.Any(evo => evo.Species == slot.Species && evo.Level >= slot.LevelMin)); if (pkm.Format != 4) // transferred to Gen5+ return slots.Where(slot => slot.LevelMin <= minLevel); return slots.Where(s => s.IsLevelWithinRange(minLevel)); } } }