PKHeX/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8.cs
Lusamine ab33df2fc9
Enforce weather legality for SWSH (#3221)
* Add weather types by location

Creates a dictionary of possible weather types for each SWSH location.
Unlisted locations may only have Normal weather or do not have any
encounter slots.

* Prune unused weather from static encounters

Some encounters were too permissive with weather, e.g. Sandstorm in
Fields of Honor and Challenge Beach; Snowstorm at Dyna Tree Hill.

A few crossover areas that would have limited the possible weathers were
marked with a "(c)". An example is Nidorina from Giant's Bed crossing
to Frostpoint Field, where Raining and Thunderstorm do not occur.

This additionally organizes encounters by location.

* Move location-weather dictionary to EncounterArea8

* Verify weather marks on encounterslot/static encounters

* Adds some static encounters available through weather bleed

Weathers aren't normally available, but these static encounters are
close enough to the boundary that the weather in an adjacent area can be
used to spawn them.

- Frostpoint Field Snorlax with Raining/Thunderstorm from Giant's Bed
- Snowslide Slope Amaura with Raining/Thunderstorm from Giant's Bed
- Frigid Sea Carracosta with Intense_Sun from Three-Point Pass
- Frigid Sea Magmortar with Intense_Sun from Three-Point Pass
- Ballimere Lake Corviknight with Snowstorm from Giant's Bed
- Ballimere Lake Cryogonal with Snowstorm from Giant's Bed
- Ballimere Lake Tyrunt with all weather from Giant's Bed
- Lakeside Cave Ferrothorn with all weather from Ballimere Lake
- Tunnel to the Top Golbat with all weather from Path to the Peak

* Defer weather marks if incompatible, enforce encounterslot weather

This uses the area weather to check fishing slots and tentatively adds
some tables for weather bleed encounterslots.

* Warm-Up Tunnel gets weather bleed from Training Lowlands

* Update for base PKHeX

* Handle weather bleed for SWSH encounter slots

Co-authored-by: Skadiv <62726360+Skadiv@users.noreply.github.com>

* Minor clean

Having duplicate weather marks is illegal, so just auto-partial match them instead of checking the other marks.

* Rearrange slot weather check logic

* Claim reserved byte in SWSH pkl

* No need for two variable names now

* Valid weather marks on tree/fishing should return with main weather

* Fix tree/fishing deferral and add another surf slot weather bleed

* Disallow tree/fishing encounters from using bleed tables

None are currently known at this time, and only hidden grass encounters
have a weather bleed table

* Condense bleed expression, combine tree/fish flag check

* Move weather-bleed check into EncounterArea8

Makes the dictionaries private instead of internal.

Co-authored-by: Skadiv <62726360+Skadiv@users.noreply.github.com>
2021-07-26 14:28:05 -07:00

117 lines
4 KiB
C#

using System;
using System.Collections.Generic;
using static PKHeX.Core.OverworldCorrelation8Requirement;
namespace PKHeX.Core
{
/// <summary>
/// Generation 8 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public record EncounterStatic8 : EncounterStatic, IDynamaxLevel, IGigantamax, IRelearn, IOverworldCorrelation8
{
public sealed override int Generation => 8;
public bool ScriptedNoMarks { get; init; }
public bool CanGigantamax { get; set; }
public byte DynamaxLevel { get; set; }
public IReadOnlyList<int> Relearn { get; init; } = Array.Empty<int>();
public AreaWeather8 Weather {get; init; } = AreaWeather8.Normal;
public EncounterStatic8(GameVersion game) : base(game) { }
protected override bool IsMatchLevel(PKM pkm, DexLevel evo)
{
var met = pkm.Met_Level;
var lvl = Level;
if (met == lvl)
return true;
if (lvl < 60 && EncounterArea8.IsBoostedArea60(Location))
return met == 60;
return false;
}
public override bool IsMatchExact(PKM pkm, DexLevel evo)
{
if (pkm is IDynamaxLevel d && d.DynamaxLevel < DynamaxLevel)
return false;
return base.IsMatchExact(pkm, evo);
}
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
{
base.ApplyDetails(sav, criteria, pk);
var req = GetRequirement(pk);
if (req != MustHave)
{
pk.SetRandomEC();
return;
}
var shiny = Shiny == Shiny.Random ? Shiny.FixedValue : Shiny;
Overworld8RNG.ApplyDetails(pk, criteria, shiny, FlawlessIVCount);
}
public bool IsOverworldCorrelation
{
get
{
if (Gift)
return false; // gifts can have any 128bit seed from overworld
if (ScriptedNoMarks)
return false; // scripted encounters don't act as saved spawned overworld encounters
return true;
}
}
public OverworldCorrelation8Requirement GetRequirement(PKM pk) => IsOverworldCorrelation
? MustHave
: MustNotHave;
public bool IsOverworldCorrelationCorrect(PKM pk)
{
return Overworld8RNG.ValidateOverworldEncounter(pk, Shiny == Shiny.Random ? Shiny.FixedValue : Shiny, FlawlessIVCount);
}
public override EncounterMatchRating GetMatchRating(PKM pkm)
{
var rating = base.GetMatchRating(pkm);
if (rating != EncounterMatchRating.Match)
return rating;
var req = GetRequirement(pkm);
bool correlation = IsOverworldCorrelationCorrect(pkm);
if ((req == MustHave) != correlation)
return EncounterMatchRating.Deferred;
// Only encounter slots can have these marks; defer for collisions.
if (pkm.Species == (int) Core.Species.Shedinja)
{
// Loses Mark on evolution to Shedinja, but not affixed ribbon value.
return pkm switch
{
IRibbonSetMark8 {RibbonMarkCurry: true} => EncounterMatchRating.Deferred,
PK8 {AffixedRibbon: (int) RibbonIndex.MarkCurry} => EncounterMatchRating.Deferred,
_ => EncounterMatchRating.Match
};
}
if (pkm is IRibbonSetMark8 m && (m.RibbonMarkCurry || m.RibbonMarkFishing || m.HasWeatherMark()))
return EncounterMatchRating.Deferred;
return EncounterMatchRating.Match;
}
}
public interface IOverworldCorrelation8
{
OverworldCorrelation8Requirement GetRequirement(PKM pk);
bool IsOverworldCorrelationCorrect(PKM pk);
}
public enum OverworldCorrelation8Requirement
{
CanBeEither,
MustHave,
MustNotHave,
}
}