2021-02-15 00:00:43 +00:00
|
|
|
using static PKHeX.Core.OverworldCorrelation8Requirement;
|
|
|
|
|
2020-11-27 19:51:02 +00:00
|
|
|
namespace PKHeX.Core
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Encounter Slot found in <see cref="GameVersion.SWSH"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <inheritdoc cref="EncounterSlot"/>
|
2021-02-14 18:20:35 +00:00
|
|
|
public sealed record EncounterSlot8 : EncounterSlot, IOverworldCorrelation8
|
2020-11-27 19:51:02 +00:00
|
|
|
{
|
|
|
|
public readonly AreaWeather8 Weather;
|
2021-07-26 21:28:05 +00:00
|
|
|
public readonly AreaSlotType8 SlotType;
|
2021-07-30 21:05:23 +00:00
|
|
|
public override string LongName => $"{wild} [{SlotType}] - {Weather.ToString().Replace("_", string.Empty)}";
|
2020-11-27 19:51:02 +00:00
|
|
|
public override int Generation => 8;
|
|
|
|
|
2021-07-26 21:28:05 +00:00
|
|
|
public EncounterSlot8(EncounterArea8 area, int species, int form, int min, int max, AreaWeather8 weather, AreaSlotType8 slotType) : base(area, species, form, min, max)
|
2020-11-27 19:51:02 +00:00
|
|
|
{
|
|
|
|
Weather = weather;
|
2021-07-26 21:28:05 +00:00
|
|
|
SlotType = slotType;
|
2020-11-27 19:51:02 +00:00
|
|
|
}
|
2021-02-14 18:20:35 +00:00
|
|
|
|
2021-02-14 20:27:14 +00:00
|
|
|
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
|
|
|
{
|
2021-07-09 17:09:57 +00:00
|
|
|
bool symbol = ((EncounterArea8)Area).PermitCrossover;
|
|
|
|
var c = symbol ? EncounterCriteria.Unrestricted : criteria;
|
|
|
|
if (!symbol && Location is 30 or 54 && (Weather & AreaWeather8.Fishing) == 0)
|
2021-02-15 23:21:10 +00:00
|
|
|
((PK8)pk).RibbonMarkCurry = true;
|
2021-07-09 17:09:57 +00:00
|
|
|
|
2021-07-31 07:01:55 +00:00
|
|
|
base.ApplyDetails(sav, c, pk);
|
2021-08-06 21:54:32 +00:00
|
|
|
if (Weather is AreaWeather8.Heavy_Fog && EncounterArea8.IsBoostedArea60Fog(Location))
|
2021-07-26 22:01:21 +00:00
|
|
|
pk.CurrentLevel = pk.Met_Level = EncounterArea8.BoostLevel;
|
|
|
|
|
2021-02-15 00:00:43 +00:00
|
|
|
var req = GetRequirement(pk);
|
|
|
|
if (req != MustHave)
|
|
|
|
{
|
2021-02-14 20:27:14 +00:00
|
|
|
pk.SetRandomEC();
|
|
|
|
return;
|
2021-02-15 00:00:43 +00:00
|
|
|
}
|
2021-08-05 02:33:35 +00:00
|
|
|
// Don't bother honoring shiny state.
|
|
|
|
Overworld8RNG.ApplyDetails(pk, c, Shiny.Random);
|
2021-02-14 20:27:14 +00:00
|
|
|
}
|
|
|
|
|
2021-02-15 00:00:43 +00:00
|
|
|
public OverworldCorrelation8Requirement GetRequirement(PKM pk)
|
2021-02-14 18:20:35 +00:00
|
|
|
{
|
2021-02-14 23:14:45 +00:00
|
|
|
if (((EncounterArea8)Area).PermitCrossover)
|
2021-02-15 00:00:43 +00:00
|
|
|
return MustHave; // symbol walking overworld
|
|
|
|
|
2021-05-14 22:30:55 +00:00
|
|
|
bool curry = pk is IRibbonSetMark8 {RibbonMarkCurry: true} || (pk.Species == (int)Core.Species.Shedinja && pk is PK8 {AffixedRibbon:(int)RibbonIndex.MarkCurry});
|
2021-02-15 00:00:43 +00:00
|
|
|
if (curry)
|
|
|
|
return MustNotHave;
|
|
|
|
|
|
|
|
// Tree encounters are generated via the global seed, not the u32
|
|
|
|
if ((Weather & AreaWeather8.Shaking_Trees) != 0)
|
|
|
|
{
|
|
|
|
// Some tree encounters are present in the regular encounters.
|
|
|
|
return Weather == AreaWeather8.Shaking_Trees
|
|
|
|
? MustNotHave
|
|
|
|
: CanBeEither;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MustHave;
|
2021-02-14 18:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsOverworldCorrelationCorrect(PKM pk)
|
|
|
|
{
|
2021-07-26 21:33:41 +00:00
|
|
|
var flawless = GetFlawlessIVCount(pk.Met_Level);
|
2021-02-15 17:04:47 +00:00
|
|
|
return Overworld8RNG.ValidateOverworldEncounter(pk, flawless: flawless);
|
2021-02-14 18:20:35 +00:00
|
|
|
}
|
2021-02-14 23:14:45 +00:00
|
|
|
|
2021-07-26 21:33:41 +00:00
|
|
|
private int GetFlawlessIVCount(int met)
|
2021-02-15 18:19:52 +00:00
|
|
|
{
|
|
|
|
const int none = 0;
|
|
|
|
const int any023 = -1;
|
|
|
|
|
2021-07-26 21:33:41 +00:00
|
|
|
// Brilliant encounters are boosted to max level for the slot.
|
|
|
|
if (met < LevelMax)
|
|
|
|
return none;
|
|
|
|
|
2021-02-15 18:19:52 +00:00
|
|
|
var area = (EncounterArea8) Area;
|
|
|
|
if (area.PermitCrossover)
|
|
|
|
return any023; // Symbol
|
|
|
|
if ((Weather & AreaWeather8.Fishing) != 0)
|
|
|
|
return any023; // Fishing
|
|
|
|
return none; // Hidden
|
|
|
|
}
|
|
|
|
|
2021-02-14 23:14:45 +00:00
|
|
|
public override EncounterMatchRating GetMatchRating(PKM pkm)
|
|
|
|
{
|
2021-04-22 20:47:33 +00:00
|
|
|
bool isHidden = pkm.AbilityNumber == 4;
|
|
|
|
if (isHidden && this.IsPartialMatchHidden(pkm.Species, Species))
|
|
|
|
return EncounterMatchRating.PartialMatch;
|
2021-02-15 18:31:07 +00:00
|
|
|
|
2021-02-15 06:25:59 +00:00
|
|
|
if (pkm is IRibbonSetMark8 m)
|
|
|
|
{
|
|
|
|
if (m.RibbonMarkCurry && (Weather & AreaWeather8.All) == 0)
|
2021-08-15 15:40:44 +00:00
|
|
|
return EncounterMatchRating.DeferredErrors;
|
2021-02-15 06:25:59 +00:00
|
|
|
if (m.RibbonMarkFishing && (Weather & AreaWeather8.Fishing) == 0)
|
2021-08-15 15:40:44 +00:00
|
|
|
return EncounterMatchRating.DeferredErrors;
|
2021-02-15 18:31:07 +00:00
|
|
|
|
2021-07-26 21:28:05 +00:00
|
|
|
// Check if it has a mark and the weather does not permit the mark.
|
|
|
|
// Tree/Fishing slots should be deferred here and are checked later.
|
|
|
|
if (!Weather.IsMarkCompatible(m))
|
2021-08-15 15:40:44 +00:00
|
|
|
return EncounterMatchRating.DeferredErrors;
|
2021-07-26 21:28:05 +00:00
|
|
|
|
2021-08-03 16:16:59 +00:00
|
|
|
// Galar Mine hidden encounters can only be found via Curry or Fishing.
|
|
|
|
if(Location is (30 or 54) && SlotType is AreaSlotType8.HiddenMain && !m.RibbonMarkCurry && !SlotType.CanEncounterViaFishing(Weather))
|
2021-08-15 15:40:44 +00:00
|
|
|
return EncounterMatchRating.DeferredErrors;
|
2021-02-15 06:25:59 +00:00
|
|
|
}
|
|
|
|
|
2021-02-15 00:00:43 +00:00
|
|
|
var req = GetRequirement(pkm);
|
|
|
|
return req switch
|
|
|
|
{
|
2021-08-15 15:40:44 +00:00
|
|
|
MustHave when !IsOverworldCorrelationCorrect(pkm) => EncounterMatchRating.DeferredErrors,
|
|
|
|
MustNotHave when IsOverworldCorrelationCorrect(pkm) => EncounterMatchRating.DeferredErrors,
|
2021-02-15 05:24:31 +00:00
|
|
|
_ => EncounterMatchRating.Match,
|
2021-02-15 00:00:43 +00:00
|
|
|
};
|
2021-02-14 23:14:45 +00:00
|
|
|
}
|
2020-11-27 19:51:02 +00:00
|
|
|
}
|
|
|
|
}
|