mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-26 05:50:22 +00:00
Misc tweaks
Move enum -> ushort instead of int Redo handling of HOME Volt Tackle (disallow on SWSH Cap Pikachu) Pass spans instead of strings to use span methods Reset encounter filters on early abort
This commit is contained in:
parent
b212ef42b5
commit
ee9ae63c22
13 changed files with 65 additions and 60 deletions
|
@ -3,7 +3,7 @@ namespace PKHeX.Core;
|
|||
/// <summary>
|
||||
/// Move IDs for the corresponding English move name.
|
||||
/// </summary>
|
||||
public enum Move
|
||||
public enum Move : ushort
|
||||
{
|
||||
None,
|
||||
Pound,
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace PKHeX.Core;
|
|||
public enum HeldItemLumpImage
|
||||
{
|
||||
/// <summary>
|
||||
/// Held Item spriite is a specific held item.
|
||||
/// Held Item sprite is a specific held item.
|
||||
/// </summary>
|
||||
NotLump = 0,
|
||||
|
||||
|
|
28
PKHeX.Core/Items/IItemStorage.cs
Normal file
28
PKHeX.Core/Items/IItemStorage.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Exposes permissions about Item Storage (Pouch) constraints.
|
||||
/// </summary>
|
||||
public interface IItemStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates if the item is actually obtainable for the given <see cref="type"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is used to check if the item is legal to obtain, not if the item can exist in the pouch.
|
||||
/// </remarks>
|
||||
/// <param name="type">Type of inventory to check.</param>
|
||||
/// <param name="itemIndex">Item ID to check.</param>
|
||||
/// <param name="itemCount">Quantity value for the item.</param>
|
||||
/// <returns>True if the item is possible to obtain.</returns>
|
||||
bool IsLegal(InventoryType type, int itemIndex, int itemCount);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all possible item IDs that can exist in the given pouch <see cref="type"/>.
|
||||
/// </summary>
|
||||
/// <param name="type">Type of inventory to check.</param>
|
||||
/// <returns>List of all possible item IDs.</returns>
|
||||
ReadOnlySpan<ushort> GetItems(InventoryType type);
|
||||
}
|
|
@ -61,9 +61,6 @@ public sealed class LearnGroupHOME : ILearnGroup
|
|||
return true;
|
||||
}
|
||||
|
||||
if (TryAddSpecialCaseMoves(pk.Species, result, current))
|
||||
return true;
|
||||
|
||||
if (history.HasVisitedLGPE)
|
||||
{
|
||||
var instance = LearnGroup7b.Instance;
|
||||
|
@ -133,7 +130,10 @@ public sealed class LearnGroupHOME : ILearnGroup
|
|||
if (chk.Method != LearnMethod.None)
|
||||
valid = true;
|
||||
}
|
||||
if (!valid)
|
||||
|
||||
// HOME has special handling to allow Volt Tackle outside of learnset possibilities.
|
||||
// Most games do not have a Learn Source for Volt Tackle besides it being specially inserted for Egg Encounters.
|
||||
if (!valid && move is not (ushort)Move.VoltTackle)
|
||||
r = default;
|
||||
}
|
||||
|
||||
|
@ -172,8 +172,6 @@ public sealed class LearnGroupHOME : ILearnGroup
|
|||
if (enc is EncounterSlot8GO { OriginFormat: PogoImportFormat.PK7 or PogoImportFormat.PB7 } g8)
|
||||
AddOriginalMovesGO(g8, result, enc.LevelMin);
|
||||
|
||||
AddSpecialCaseMoves(pk.Species, result);
|
||||
|
||||
// Looking backwards before HOME
|
||||
if (history.HasVisitedLGPE)
|
||||
{
|
||||
|
@ -236,28 +234,6 @@ public sealed class LearnGroupHOME : ILearnGroup
|
|||
}
|
||||
}
|
||||
|
||||
private static bool TryAddSpecialCaseMoves(ushort species, Span<MoveResult> result, ReadOnlySpan<ushort> current)
|
||||
{
|
||||
if (IsPikachuLine(species))
|
||||
{
|
||||
var index = current.IndexOf((ushort)Move.VoltTackle);
|
||||
if (index == -1)
|
||||
return false;
|
||||
ref var move = ref result[index];
|
||||
if (move.Valid)
|
||||
return false;
|
||||
move = new MoveResult(LearnMethod.Shared, LearnEnvironment.HOME);
|
||||
return MoveResult.AllValid(result);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void AddSpecialCaseMoves(ushort species, Span<bool> result)
|
||||
{
|
||||
if (IsPikachuLine(species))
|
||||
result[(int)Move.VoltTackle] = true;
|
||||
}
|
||||
|
||||
private static void AddOriginalMovesGO(EncounterSlot8GO enc, Span<bool> result, int met)
|
||||
{
|
||||
Span<ushort> moves = stackalloc ushort[4];
|
||||
|
|
|
@ -82,20 +82,18 @@ public static class SearchUtil
|
|||
_ => HashByDetails,
|
||||
};
|
||||
|
||||
public static string HashByDetails(PKM pk) => pk.Format switch
|
||||
public static string HashByDetails(PKM pk) => pk switch
|
||||
{
|
||||
1 => $"{pk.Species:0000}{((PK1) pk).DV16:X4}",
|
||||
2 => $"{pk.Species:0000}{((PK2) pk).DV16:X4}",
|
||||
GBPKM gb => $"{pk.Species:000}{gb.DV16:X4}",
|
||||
_ => $"{pk.Species:0000}{pk.PID:X8}{GetIVString(pk)}{pk.Form:00}",
|
||||
};
|
||||
|
||||
// use a space so we don't merge single digit IVs and potentially get incorrect collisions
|
||||
private static string GetIVString(PKM pk) => $"{pk.IV_HP} {pk.IV_ATK} {pk.IV_DEF} {pk.IV_SPE} {pk.IV_SPA} {pk.IV_SPD}";
|
||||
|
||||
public static string HashByPID(PKM pk) => pk.Format switch
|
||||
public static string HashByPID(PKM pk) => pk switch
|
||||
{
|
||||
1 => $"{((PK1) pk).DV16:X4}",
|
||||
2 => $"{((PK2) pk).DV16:X4}",
|
||||
GBPKM gb => $"{gb.DV16:X4}",
|
||||
_ => $"{pk.PID:X8}",
|
||||
};
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace PKHeX.Core;
|
|||
/// </remarks>
|
||||
public static class SwishCrypto
|
||||
{
|
||||
private const int SIZE_HASH = 0x20;
|
||||
private const int SIZE_HASH = SHA256.HashSizeInBytes; // 0x20
|
||||
|
||||
private static ReadOnlySpan<byte> IntroHashBytes => new byte[]
|
||||
{
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public interface IItemStorage
|
||||
{
|
||||
bool IsLegal(InventoryType type, int itemIndex, int itemCount);
|
||||
ReadOnlySpan<ushort> GetItems(InventoryType type);
|
||||
}
|
|
@ -890,14 +890,14 @@ public static class SaveUtil
|
|||
}
|
||||
}
|
||||
|
||||
public static bool IsBackup(string path)
|
||||
public static bool IsBackup(ReadOnlySpan<char> path)
|
||||
{
|
||||
var fn = Path.GetFileNameWithoutExtension(path);
|
||||
if (fn == "backup")
|
||||
if (fn is "backup")
|
||||
return true;
|
||||
|
||||
var ext = Path.GetExtension(path);
|
||||
return ext == ".bak";
|
||||
return ext is ".bak";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -27,7 +27,7 @@ public static class FileUtil
|
|||
return null;
|
||||
|
||||
var data = File.ReadAllBytes(path);
|
||||
var ext = Path.GetExtension(path);
|
||||
var ext = Path.GetExtension(path.AsSpan());
|
||||
return GetSupportedFile(data, ext, reference);
|
||||
}
|
||||
// User input data can be fuzzed; if anything blows up, just fail safely.
|
||||
|
|
|
@ -132,7 +132,7 @@ public partial class Main : Form
|
|||
return true;
|
||||
}
|
||||
|
||||
var path = Environment.ProcessPath!;
|
||||
ReadOnlySpan<char> path = Environment.ProcessPath!;
|
||||
return Path.GetFileNameWithoutExtension(path).EndsWith(nameof(HaX));
|
||||
}
|
||||
|
||||
|
|
|
@ -278,10 +278,13 @@ public partial class RibbonEditor : Form
|
|||
}
|
||||
|
||||
EnableBackgroundChange = false;
|
||||
foreach (var c in TLP_Ribbons.Controls.OfType<CheckBox>())
|
||||
c.Checked = true;
|
||||
foreach (var n in TLP_Ribbons.Controls.OfType<NumericUpDown>())
|
||||
n.Value = n.Maximum;
|
||||
foreach (var c in TLP_Ribbons.Controls)
|
||||
{
|
||||
if (c is CheckBox chk)
|
||||
chk.Checked = true;
|
||||
else if (c is NumericUpDown nud)
|
||||
nud.Value = nud.Maximum;
|
||||
}
|
||||
EnableBackgroundChange = true;
|
||||
}
|
||||
|
||||
|
@ -297,9 +300,12 @@ public partial class RibbonEditor : Form
|
|||
}
|
||||
|
||||
CB_Affixed.SelectedValue = AffixedNone;
|
||||
foreach (var c in TLP_Ribbons.Controls.OfType<CheckBox>())
|
||||
c.Checked = false;
|
||||
foreach (var n in TLP_Ribbons.Controls.OfType<NumericUpDown>())
|
||||
n.Value = 0;
|
||||
foreach (var c in TLP_Ribbons.Controls)
|
||||
{
|
||||
if (c is CheckBox chk)
|
||||
chk.Checked = false;
|
||||
else if (c is NumericUpDown nud)
|
||||
nud.Value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -389,11 +389,17 @@ public partial class SAV_Encounters : Form
|
|||
var token = TokenSource.Token;
|
||||
var search = SearchDatabase(token);
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
EncounterMovesetGenerator.ResetFilters();
|
||||
return;
|
||||
}
|
||||
|
||||
var results = await Task.Run(() => search.ToList(), token).ConfigureAwait(true);
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
EncounterMovesetGenerator.ResetFilters();
|
||||
return;
|
||||
}
|
||||
|
||||
if (results.Count == 0)
|
||||
WinFormsUtil.Alert(MsgDBSearchNone);
|
||||
|
|
|
@ -148,7 +148,7 @@ public partial class SAV_Wondercard : Form
|
|||
|
||||
var path = import.FileName;
|
||||
var data = File.ReadAllBytes(path);
|
||||
var ext = Path.GetExtension(path);
|
||||
var ext = Path.GetExtension(path.AsSpan());
|
||||
var gift = MysteryGift.GetMysteryGift(data, ext);
|
||||
if (gift == null)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue