2020-08-30 17:23:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2019-09-13 16:08:12 +00:00
|
|
|
|
/// <inheritdoc />
|
2019-09-13 06:20:52 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="GameVersion.Gen7"/> encounter area
|
|
|
|
|
/// </summary>
|
2020-08-30 17:23:22 +00:00
|
|
|
|
public sealed class EncounterArea7 : EncounterArea
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-08-30 17:23:22 +00:00
|
|
|
|
public static EncounterArea7[] GetAreas(byte[][] input, GameVersion game)
|
|
|
|
|
{
|
|
|
|
|
var result = new EncounterArea7[input.Length];
|
|
|
|
|
for (int i = 0; i < input.Length; i++)
|
|
|
|
|
result[i] = new EncounterArea7(input[i], game);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-30 18:08:21 +00:00
|
|
|
|
private EncounterArea7(byte[] data, GameVersion game) : base(game)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
|
|
|
|
Location = data[0] | (data[1] << 8);
|
|
|
|
|
Type = (SlotType)data[2];
|
|
|
|
|
|
2020-08-30 18:08:21 +00:00
|
|
|
|
Slots = ReadSlots(data);
|
2020-08-30 17:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-30 18:08:21 +00:00
|
|
|
|
private EncounterSlot7[] ReadSlots(byte[] data)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
|
|
|
|
const int size = 4;
|
|
|
|
|
int count = (data.Length - 4) / size;
|
|
|
|
|
var slots = new EncounterSlot7[count];
|
|
|
|
|
for (int i = 0; i < slots.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
int offset = 4 + (size * i);
|
|
|
|
|
ushort SpecForm = BitConverter.ToUInt16(data, offset);
|
|
|
|
|
int species = SpecForm & 0x3FF;
|
|
|
|
|
int form = SpecForm >> 11;
|
|
|
|
|
int min = data[offset + 2];
|
|
|
|
|
int max = data[offset + 3];
|
2020-08-30 18:08:21 +00:00
|
|
|
|
slots[i] = new EncounterSlot7(this, species, form, min, max);
|
2020-08-30 17:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return slots;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pkm, IReadOnlyList<EvoCriteria> chain)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
foreach (var slot in Slots)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
foreach (var evo in chain)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
if (slot.Species != evo.Species)
|
|
|
|
|
continue;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
if (!slot.IsLevelWithinRange(pkm.Met_Level))
|
|
|
|
|
break;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2020-12-11 04:42:30 +00:00
|
|
|
|
if (slot.Form != evo.Form && !FormInfo.WildChangeFormAfter.Contains(slot.Species))
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
|
|
|
|
if (slot.Species != (int)Species.Minior) // Random Color, edge case
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
yield return slot;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-13 06:20:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-21 23:35:49 +00:00
|
|
|
|
}
|