2020-08-30 17:23:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc cref="EncounterArea" />
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="GameVersion.XD"/> encounter area
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed record EncounterArea3XD : EncounterArea
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public readonly EncounterSlot3PokeSpot[] Slots;
|
2021-06-30 03:58:06 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
protected override IReadOnlyList<EncounterSlot> Raw => Slots;
|
2021-06-30 03:58:06 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public EncounterArea3XD(int loc, ushort s0, byte l0, ushort s1, byte l1, ushort s2, byte l2) : base(GameVersion.XD)
|
|
|
|
|
{
|
|
|
|
|
Location = loc;
|
|
|
|
|
Type = SlotType.Grass;
|
|
|
|
|
Slots = new[]
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
new EncounterSlot3PokeSpot(this, s0, 10, l0, 0),
|
|
|
|
|
new EncounterSlot3PokeSpot(this, s1, 10, l1, 1),
|
|
|
|
|
new EncounterSlot3PokeSpot(this, s2, 10, l2, 2),
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-08-30 17:23:22 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pk, EvoCriteria[] chain)
|
|
|
|
|
{
|
|
|
|
|
if (pk.Format != 3) // Met Location and Met Level are changed on PK3->PK4
|
|
|
|
|
return GetSlotsFuzzy(chain);
|
|
|
|
|
if (pk.Met_Location != Location)
|
|
|
|
|
return Array.Empty<EncounterSlot3PokeSpot>();
|
|
|
|
|
return GetSlotsMatching(chain, pk.Met_Level);
|
|
|
|
|
}
|
2020-08-30 17:23:22 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private IEnumerable<EncounterSlot3PokeSpot> GetSlotsMatching(EvoCriteria[] chain, int lvl)
|
|
|
|
|
{
|
|
|
|
|
foreach (var slot in Slots)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
foreach (var evo in chain)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (slot.Species != evo.Species)
|
|
|
|
|
continue;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (slot.Form != evo.Form)
|
|
|
|
|
break;
|
|
|
|
|
if (!slot.IsLevelWithinRange(lvl))
|
2020-08-30 17:23:22 +00:00
|
|
|
|
break;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
|
|
yield return slot;
|
|
|
|
|
break;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
}
|
2020-08-30 17:23:22 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private IEnumerable<EncounterSlot3PokeSpot> GetSlotsFuzzy(EvoCriteria[] chain)
|
|
|
|
|
{
|
|
|
|
|
foreach (var slot in Slots)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
foreach (var evo in chain)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (slot.Species != evo.Species)
|
|
|
|
|
continue;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (slot.Form != evo.Form)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
break;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (slot.LevelMin > evo.LevelMax)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
yield return slot;
|
|
|
|
|
break;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|