2021-11-20 02:23:49 +00:00
|
|
|
using System;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Encounter Slot found in <see cref="GameVersion.BDSP"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <inheritdoc cref="EncounterSlot"/>
|
|
|
|
public sealed record EncounterSlot8b : EncounterSlot
|
2021-11-20 02:23:49 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int Generation => 8;
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
public override EntityContext Context => EntityContext.Gen8b;
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool IsUnderground => Area.Location is (>= 508 and <= 617);
|
|
|
|
public bool IsMarsh => Area.Location is (>= 219 and <= 224);
|
|
|
|
public override Ball FixedBall => IsMarsh ? Ball.Safari : Ball.None;
|
|
|
|
|
2022-08-30 00:37:54 +00:00
|
|
|
public EncounterSlot8b(EncounterArea area, ushort species, byte form, byte min, byte max) : base(area, species, form, min, max)
|
2021-11-20 02:23:49 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override EncounterMatchRating GetMatchRating(PKM pk)
|
|
|
|
{
|
|
|
|
bool isHidden = pk.AbilityNumber == 4;
|
|
|
|
if (isHidden && this.IsPartialMatchHidden(pk.Species, Species))
|
|
|
|
return EncounterMatchRating.PartialMatch;
|
|
|
|
return base.GetMatchRating(pk);
|
|
|
|
}
|
2021-11-25 19:24:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override void SetFormatSpecificData(PKM pk)
|
|
|
|
{
|
|
|
|
if (IsUnderground)
|
2021-12-09 07:41:50 +00:00
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
if (GetBaseEggMove(out var move1))
|
2022-06-18 18:04:24 +00:00
|
|
|
pk.RelearnMove1 = move1;
|
2021-12-09 07:41:50 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
pk.SetRandomEC();
|
|
|
|
}
|
2021-12-09 07:41:50 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public bool CanBeUndergroundMove(ushort move)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var et = PersonalTable.BDSP;
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
var sf = et.GetFormEntry(Species, Form);
|
2022-06-18 18:04:24 +00:00
|
|
|
var species = sf.HatchSpecies;
|
|
|
|
var baseEgg = Legal.EggMovesBDSP[species].Moves;
|
|
|
|
if (baseEgg.Length == 0)
|
|
|
|
return move == 0;
|
|
|
|
return Array.IndexOf(baseEgg, move) >= 0;
|
|
|
|
}
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public bool GetBaseEggMove(out ushort move)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var et = PersonalTable.BDSP;
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
var sf = et.GetFormEntry(Species, Form);
|
2022-06-18 18:04:24 +00:00
|
|
|
var species = sf.HatchSpecies;
|
|
|
|
var baseEgg = Legal.EggMovesBDSP[species].Moves;
|
|
|
|
if (baseEgg.Length == 0)
|
2021-11-20 02:23:49 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
move = 0;
|
|
|
|
return false;
|
2021-11-20 02:23:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Official method creates a new List<ushort>() with all the egg moves, removes all ignored, then picks a random index.
|
2022-08-30 00:37:54 +00:00
|
|
|
// However, the "excluded egg moves" list was unreferenced in v1.0, so all egg moves are allowed.
|
|
|
|
// We can't know which patch the encounter originated from, because they never added any new content.
|
2022-06-18 18:04:24 +00:00
|
|
|
var rnd = Util.Rand;
|
2021-12-09 07:41:50 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var index = rnd.Next(baseEgg.Length);
|
|
|
|
move = baseEgg[index];
|
2022-08-30 00:37:54 +00:00
|
|
|
return true;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-09 07:41:50 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool CanUseRadar => Area.Type is SlotType.Grass && !IsUnderground && !IsMarsh && Location switch
|
|
|
|
{
|
|
|
|
195 or 196 => false, // Oreburgh Mine
|
|
|
|
203 or 204 or 205 or 208 or 209 or 210 or 211 or 212 or 213 or 214 or 215 => false, // Mount Coronet, 206/207 exterior
|
|
|
|
>= 225 and <= 243 => false, // Solaceon Ruins
|
|
|
|
244 or 245 or 246 or 247 or 248 or 249 => false, // Victory Road
|
|
|
|
252 => false, // Ravaged Path
|
|
|
|
255 or 256 => false, // Oreburgh Gate
|
|
|
|
260 or 261 or 262 => false, // Stark Mountain, 259 exterior
|
|
|
|
>= 264 and <= 284 => false, // Turnback Cave
|
|
|
|
286 or 287 or 288 or 289 or 290 or 291 => false, // Snowpoint Temple
|
|
|
|
292 or 293 => false, // Wayward Cave
|
|
|
|
294 or 295 => false, // Ruin Maniac Cave
|
|
|
|
296 => false, // Maniac Tunnel
|
|
|
|
299 or 300 or 301 or 302 or 303 or 304 or 305 => false, // Iron Island, 298 exterior
|
|
|
|
306 or 307 or 308 or 309 or 310 or 311 or 312 or 313 or 314 => false, // Old Chateau
|
|
|
|
368 or 369 or 370 or 371 or 372 => false, // Route 209 (Lost Tower)
|
|
|
|
_ => true,
|
|
|
|
};
|
2021-12-09 07:41:50 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override HiddenAbilityPermission IsHiddenAbilitySlot() => CanUseRadar ? HiddenAbilityPermission.Possible : HiddenAbilityPermission.Never;
|
2021-11-20 02:23:49 +00:00
|
|
|
}
|