Skip to content

Commit

Permalink
Update 23.07.09
Browse files Browse the repository at this point in the history
  • Loading branch information
kwsch committed Jul 9, 2023
1 parent b340e23 commit 26cabd0
Show file tree
Hide file tree
Showing 29 changed files with 242 additions and 135 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>23.06.03</Version>
<Version>23.07.09</Version>
<LangVersion>11</LangVersion>
<Nullable>enable</Nullable>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
3 changes: 2 additions & 1 deletion PKHeX.Core/Editing/Showdown/ShowdownSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ private bool ParseDynamax(ReadOnlySpan<char> value)
var val = Util.ToInt32(value);
if ((uint)val > 10)
return false;
return (DynamaxLevel = (byte)val) is (>= 0 and <= 10);
DynamaxLevel = (byte)val;
return true;
}

private bool ParseTeraType(ReadOnlySpan<char> value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal static class Encounters3FRLG
new(129, 05, FRLG) { Gift = true, Location = 099 }, // Magikarp @ Route 4
new(131, 25, FRLG) { Gift = true, Location = 134 }, // Lapras @ Silph Co.
new(133, 25, FRLG) { Gift = true, Location = 094 }, // Eevee @ Celadon City
new(175, 05, FRLG) { Gift = true, EggLocation = 253 }, // Togepi Egg
new(175, 05, FRLG) { Gift = true, EggLocation = 253, Moves = new(045,204,118) }, // Togepi Egg

// Celadon City Game Corner
new(063, 09, FR) { Gift = true, Location = 94 }, // Abra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static class Encounters5B2W2
private static readonly EncounterStatic5[] Encounter_B2W2 = ArrayUtil.ConcatAll(Encounter_B2W2_Regular, Encounter_B2W2_N, Encounter_DreamRadar);
#endregion
#region Trade Tables
internal static readonly EncounterTrade5[] TradeGift_B2W2_Regular =
private static readonly EncounterTrade5[] TradeGift_B2W2_Regular =
{
new(B2 ) { Species = 548, Level = 20, Ability = OnlySecond, TID16 = 65217, SID16 = 00000, OTGender = 1, Gender = 1, IVs = new(20,20,20,20,31,20), Nature = Nature.Timid }, // Petilil
new( W2) { Species = 546, Level = 20, Ability = OnlyFirst, TID16 = 05720, SID16 = 00001, OTGender = 0, Gender = 0, IVs = new(20,20,20,20,31,20), Nature = Nature.Modest }, // Cottonee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public sealed record EncounterEgg(ushort Species, byte Form, byte Level, int Gen
public AbilityPermission Ability => AbilityPermission.Any12H;

public bool CanHaveVoltTackle => Species is (int)Core.Species.Pichu && (Generation > 3 || Version is GameVersion.E);
public bool CanInheritMoves => Breeding.GetCanInheritMoves(Species);

public PKM ConvertToPKM(ITrainerInfo tr) => ConvertToPKM(tr, EncounterCriteria.Unrestricted);

Expand Down
51 changes: 29 additions & 22 deletions PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot2.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System;

namespace PKHeX.Core;

Expand Down Expand Up @@ -44,33 +44,40 @@ protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteri
pk2.Met_TimeOfDay = ((EncounterArea2)Area).Time.RandomValidTime();
}

private static readonly Dictionary<int, int> Trees = new()
private static ReadOnlySpan<byte> TreeIndexes => new byte[]
{
{ 02, 0x3FF_3FF }, // Route 29
{ 04, 0x0FF_3FF }, // Route 30
{ 05, 0x3FE_3FF }, // Route 31
{ 08, 0x3EE_3FF }, // Route 32
{ 11, 0x240_3FF }, // Route 33
{ 12, 0x37F_3FF }, // Azalea Town
{ 14, 0x3FF_3FF }, // Ilex Forest
{ 15, 0x001_3FE }, // Route 34
{ 18, 0x261_3FF }, // Route 35
{ 20, 0x3FF_3FF }, // Route 36
{ 21, 0x2B9_3FF }, // Route 37
{ 25, 0x3FF_3FF }, // Route 38
{ 26, 0x184_3FF }, // Route 39
{ 34, 0x3FF_3FF }, // Route 42
{ 37, 0x3FF_3FF }, // Route 43
{ 38, 0x3FF_3FF }, // Lake of Rage
{ 39, 0x2FF_3FF }, // Route 44
{ 91, 0x200_1FF }, // Route 26
{ 92, 0x2BB_3FF }, // Route 27
02, 04, 05, 08, 11, 12, 14, 15, 18, 20, 21, 25, 26, 34, 37, 38, 39, 91, 92,
};

private static ReadOnlySpan<int> Trees => new[]
{
0x3FF_3FF, // Route 29
0x0FF_3FF, // Route 30
0x3FE_3FF, // Route 31
0x3EE_3FF, // Route 32
0x240_3FF, // Route 33
0x37F_3FF, // Azalea Town
0x3FF_3FF, // Ilex Forest
0x001_3FE, // Route 34
0x261_3FF, // Route 35
0x3FF_3FF, // Route 36
0x2B9_3FF, // Route 37
0x3FF_3FF, // Route 38
0x184_3FF, // Route 39
0x3FF_3FF, // Route 42
0x3FF_3FF, // Route 43
0x3FF_3FF, // Lake of Rage
0x2FF_3FF, // Route 44
0x200_1FF, // Route 26
0x2BB_3FF, // Route 27
};

public bool IsTreeAvailable(ushort trainerID)
{
if (!Trees.TryGetValue(Location, out var permissions))
var treeIndex = TreeIndexes.BinarySearch((byte)Location);
if (treeIndex < 0)
return false;
var permissions = Trees[treeIndex];

var pivot = trainerID % 10;
var type = Area.Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected override void SetPINGA(PKM pk, EncounterCriteria criteria)
protected override void SetEncounterMoves(PKM pk, GameVersion version, int level)
{
Span<ushort> moves = stackalloc ushort[4];
var source = GameData.GetLearnSource(GameVersion.GG);
ILearnSource source = LearnSource7GG.Instance;
source.SetEncounterMoves(Species, Form, level, moves);
pk.SetMoves(moves);
pk.SetMaximumPPCurrent(moves);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteri
s.HeightScalar = PokeSizeUtil.GetRandomScalar();
s.WeightScalar = PokeSizeUtil.GetRandomScalar();
if (pk is IScaledSize3 s3)
s3.Scale = s.HeightScalar = PokeSizeUtil.GetRandomScalar();
s3.Scale = s.HeightScalar;
}

if (pk is PA8 pa8)
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Core/Legality/Evolutions/Reversal/EvolutionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct EvolutionNode
/// </summary>
/// <param name="link">Link to register</param>
/// <exception cref="InvalidOperationException"> is thrown if the node is full.</exception>
public void Add(EvolutionLink link)
public void Add(in EvolutionLink link)
{
if (First.IsEmpty)
First = link;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static bool TryDevolve(this EvolutionNode node, PKM pk, byte currentMaxLe
return false;
}

private static EvoCriteria Create(EvolutionLink link, byte currentMaxLevel) => new()
private static EvoCriteria Create(in EvolutionLink link, byte currentMaxLevel) => new()
{
Species = link.Species,
Form = link.Form,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public EvolutionReverseLookup(ushort maxSpecies)
MaxSpecies = maxSpecies;
}

private void Register(EvolutionLink link, int index)
private void Register(in EvolutionLink link, int index)
{
ref var node = ref Nodes[index];
node.Add(link);
}

public void Register(EvolutionLink link, ushort species, byte form)
public void Register(in EvolutionLink link, ushort species, byte form)
{
if (form == 0)
{
Expand Down
6 changes: 5 additions & 1 deletion PKHeX.Core/Legality/Verifiers/Ball/BallVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,14 @@ private CheckResult VerifyBallEggGen9(LegalityAnalysis data)
if (species is >= (int)Species.Sprigatito and <= (int)Species.Quaquaval) // G9 Starters
return VerifyBallEquals(data, (int)Poke);

// PLA Voltorb: Only via PLA (transfer only, not wild)
// PLA Voltorb: Only via PLA (transfer only, not wild) and GO
if (enc is { Species: (ushort)Species.Voltorb, Form: 1 })
return VerifyBallEquals(data, BallUseLegality.WildPokeballs8g);

// S/V Tauros forms > 1: Only local Wild Balls for Blaze/Aqua breeds -- can't inherit balls from Kantonian/Combat.
if (enc is { Species: (ushort)Species.Tauros, Form: > 1 })
return VerifyBallEquals(data, BallUseLegality.WildPokeballs9);

var pk = data.Entity;
if (IsPaldeaCatchAndBreed(species) && IsBallPermitted(BallUseLegality.WildPokeballs9, pk.Ball))
return GetValid(LBallSpeciesPass);
Expand Down
2 changes: 0 additions & 2 deletions PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ private void VerifyHandlerState(LegalityAnalysis data, bool neverOT)
data.AddLine(GetInvalid(LTransferCurrentHandlerInvalid));
if ((Info.Generation != pk.Format || neverOT) && pk.CurrentHandler != 1)
data.AddLine(GetInvalid(LTransferHTFlagRequired));
if (pk is IHomeTrack { HasTracker: true } && pk.IsUntraded) // HOME sets HT name on moving in and out.
data.AddLine(GetInvalid(LTransferHTMismatchName));
}

private static bool IsUntradeableEncounter(IEncounterTemplate enc) => enc switch
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Core/Legality/Verifiers/Ribbons/RibbonStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public static void ResetDictionary(ReadOnlySpan<string> lines)
var index = line.IndexOf('\t');
if (index < 0)
continue;
var name = line[..index];
var text = line[(index + 1)..];
var name = line[..index];
RibbonNames[name] = text;
}
}
Expand Down
76 changes: 0 additions & 76 deletions PKHeX.Core/PKM/EntityCharacteristic.cs

This file was deleted.

2 changes: 1 addition & 1 deletion PKHeX.Core/PKM/HOME/GameDataPA8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace PKHeX.Core;
/// <summary>
/// Side game data for <see cref="PA8"/> data transferred into HOME.
/// </summary>
public sealed class GameDataPA8 : HomeOptional1, IGameDataSide<PA8>, IScaledSizeAbsolute, IScaledSize3, IGameDataSplitAbility
public sealed class GameDataPA8 : HomeOptional1, IGameDataSide<PA8>, IScaledSizeAbsolute, IScaledSize3, IGameDataSplitAbility, IPokerusStatus
{
private const HomeGameDataFormat ExpectFormat = HomeGameDataFormat.PA8;
private const int SIZE = HomeCrypto.SIZE_2GAME_PA8;
Expand Down
10 changes: 10 additions & 0 deletions PKHeX.Core/PKM/HOME/IGameDataSplitAbility.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
namespace PKHeX.Core;

/// <summary>
/// Holds the ability and ability number for a <see cref="PKM"/> that has side-game specific data.
/// </summary>
public interface IGameDataSplitAbility
{
/// <summary>
/// Ability ID for the <see cref="PKM"/>.
/// </summary>
ushort Ability { get; set; }

/// <summary>
/// Ability number for the <see cref="PKM"/>.
/// </summary>
byte AbilityNumber { get; set; }
}
18 changes: 18 additions & 0 deletions PKHeX.Core/PKM/HOME/IHomeStorage.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
namespace PKHeX.Core;

/// <summary>
/// Interface for a HOME storage system.
/// </summary>
public interface IHomeStorage
{
/// <summary>
/// Checks if the given tracker exists in the storage system.
/// </summary>
/// <param name="tracker">Tracker to check</param>
/// <returns>True if the tracker exists, false otherwise.</returns>
bool Exists(ulong tracker);

/// <summary>
/// Gets the HOME entity for the given <see cref="PKM"/>.
/// </summary>
/// <typeparam name="T">Input PKM type</typeparam>
/// <param name="pk">PKM to get the entity for</param>
/// <returns>HOME entity for the given <see cref="PKM"/>.</returns>
PKH GetEntity<T>(T pk) where T : PKM;
}

/// <summary>
/// Facade for a HOME storage system.
/// </summary>
public sealed class HomeStorageFacade : IHomeStorage
{
public bool Exists(ulong tracker) => false;
Expand Down
6 changes: 6 additions & 0 deletions PKHeX.Core/PKM/HOME/IPokerusStatus.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
namespace PKHeX.Core;

/// <summary>
/// Holds the Pokerus status of a <see cref="PKM"/>.
/// </summary>
public interface IPokerusStatus
{
/// <summary>
/// Pokerus Strain and Duration
/// </summary>
byte PKRS { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static byte GetSuggestedObedienceLevel(this IObedienceLevelReadOnly _, PK
{
if (entity.Species is (int)Species.Koraidon or (int)Species.Miraidon && entity is PK9 { FormArgument: not 0 })
return 0; // Box Legend ride-able is default 0. Everything else is met level!
if (entity.Version is not (int)GameVersion.SL or (int)GameVersion.VL)
if (entity.Version is not ((int)GameVersion.SL or (int)GameVersion.VL))
return (byte)entity.CurrentLevel; // foreign, play it safe.
// Can just assume min-level
return (byte)originalMet;
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Core/PKM/PA8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void FixRelearn()
public bool RIB47_5 { get => FlagUtil.GetFlag(Data, 0x47, 5); set => FlagUtil.SetFlag(Data, 0x47, 5, value); }
public bool RIB47_6 { get => FlagUtil.GetFlag(Data, 0x47, 6); set => FlagUtil.SetFlag(Data, 0x47, 6, value); }
public bool RIB47_7 { get => FlagUtil.GetFlag(Data, 0x47, 7); set => FlagUtil.SetFlag(Data, 0x47, 7, value); }

public int RibbonCount => BitOperations.PopCount(ReadUInt64LittleEndian(Data.AsSpan(0x34)) & 0b00000000_00011111__11111111_11111111__11111111_11111111__11111111_11111111)
+ BitOperations.PopCount(ReadUInt64LittleEndian(Data.AsSpan(0x40)) & 0b00000000_00000000__00000100_00011100__00000000_00000000__00000000_00000000);
public int MarkCount => BitOperations.PopCount(ReadUInt64LittleEndian(Data.AsSpan(0x34)) & 0b11111111_11100000__00000000_00000000__00000000_00000000__00000000_00000000)
Expand Down
Loading

0 comments on commit 26cabd0

Please sign in to comment.