mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 04:23:12 +00:00
Refactoring
change some expressions for better perf/readability
This commit is contained in:
parent
9c99e7ab7b
commit
a6a3c6eaaa
10 changed files with 23 additions and 26 deletions
|
@ -170,14 +170,14 @@ namespace PKHeX.Core
|
|||
private static List<EncounterArea2> GetAreas2Fishing(byte[] data, ref int ofs)
|
||||
{
|
||||
var areas = new List<EncounterArea2>();
|
||||
var types = new[] { SlotType.Old_Rod, SlotType.Good_Rod, SlotType.Super_Rod };
|
||||
while (ofs != 0x18C)
|
||||
{
|
||||
var old = GetSlots2Fishing(data, ref ofs, SlotType.Old_Rod);
|
||||
var good = GetSlots2Fishing(data, ref ofs, SlotType.Good_Rod);
|
||||
var super = GetSlots2Fishing(data, ref ofs, SlotType.Super_Rod);
|
||||
areas.Add(new EncounterArea2
|
||||
{
|
||||
Slots = GetSlots2Fishing(data, ref ofs, types[0])
|
||||
.Concat(GetSlots2Fishing(data, ref ofs, types[1]))
|
||||
.Concat(GetSlots2Fishing(data, ref ofs, types[2])).ToArray()
|
||||
Slots = ArrayUtil.ConcatAll(old, good, super),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1058,16 +1058,11 @@ namespace PKHeX.Core
|
|||
|
||||
#region Alt Slots
|
||||
|
||||
internal static readonly int[] SafariZoneLocation_4 =
|
||||
{
|
||||
52, 202
|
||||
};
|
||||
|
||||
private static readonly EncounterArea4DPPt[] DPPt_Unown =
|
||||
{
|
||||
new EncounterArea4DPPt {
|
||||
Location = 53, // Solaceon Ruins
|
||||
Slots = new int[25].Select((_, i) => new EncounterSlot { Species = 201, LevelMin = 14, LevelMax = 30, Type = SlotType.Grass, Form = i+1 }).ToArray() // B->?, Unown A is loaded from encounters raw file
|
||||
Slots = Enumerable.Range(1, 25).Select(i => new EncounterSlot { Species = 201, LevelMin = 14, LevelMax = 30, Type = SlotType.Grass, Form = i }).ToArray() // B->?, Unown A is loaded from encounters raw file
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1488,7 +1483,7 @@ namespace PKHeX.Core
|
|||
SlotsHGSS_BCC,
|
||||
new EncounterArea4HGSS {
|
||||
Location = 209, // Ruins of Alph
|
||||
Slots = new int[25].Select((_, i) => new EncounterSlot { Species = 201, LevelMin = 5, LevelMax = 5, Type = SlotType.Grass, Form = i+1 }).ToArray() // B->?, Unown A is loaded from encounters raw file
|
||||
Slots = Enumerable.Range(1, 25).Select((_, i) => new EncounterSlot { Species = 201, LevelMin = 5, LevelMax = 5, Type = SlotType.Grass, Form = i }).ToArray() // B->?, Unown A is loaded from encounters raw file
|
||||
},
|
||||
SlotsHGSS_SafariZone,
|
||||
//Some edge cases
|
||||
|
|
|
@ -9,13 +9,13 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
public sealed class ValidEncounterMoves
|
||||
{
|
||||
public IReadOnlyList<int>[] LevelUpMoves { get; } = Empty;
|
||||
public IReadOnlyList<int>[] LevelUpMoves { get; }
|
||||
public IReadOnlyList<int>[] TMHMMoves { get; } = Empty;
|
||||
public IReadOnlyList<int>[] TutorMoves { get; } = Empty;
|
||||
public int[] Relearn = Array.Empty<int>();
|
||||
|
||||
private const int EmptyCount = PKX.Generation + 1; // one for each generation index (and 0th)
|
||||
private static readonly List<int>[] Empty = new int[EmptyCount].Select(_ => new List<int>()).ToArray();
|
||||
private static readonly IReadOnlyList<int>[] Empty = Enumerable.Repeat((IReadOnlyList<int>)new List<int>(), EmptyCount).ToArray();
|
||||
|
||||
public ValidEncounterMoves(PKM pkm, LevelUpRestriction restrict, IEncounterable encounter)
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace PKHeX.Core
|
|||
|
||||
public static CheckResult[] VerifyRelearn(PKM pkm, LegalInfo info)
|
||||
{
|
||||
if (info.Generation < 6 || pkm is IBattleVersion v && v.BattleVersion != 0)
|
||||
if (info.Generation < 6 || (pkm is IBattleVersion v && v.BattleVersion != 0))
|
||||
return VerifyRelearnNone(pkm, info);
|
||||
|
||||
return info.EncounterMatch switch
|
||||
|
|
|
@ -884,7 +884,7 @@ namespace PKHeX.Core
|
|||
// TypeEncounter TallGrass discard any cave or city
|
||||
var ver = (GameVersion)pkm.Version;
|
||||
var IsDPPt = ver == GameVersion.D || ver == GameVersion.P || ver == GameVersion.Pt;
|
||||
return pkm.IsShiny && IsDPPt && sl.TypeEncounter == EncounterType.TallGrass && !Encounters4.SafariZoneLocation_4.Contains(sl.Location);
|
||||
return pkm.IsShiny && IsDPPt && sl.TypeEncounter == EncounterType.TallGrass && !Locations.IsSafariZoneLocation4(sl.Location);
|
||||
case PGT _: // manaphy
|
||||
return IsG4ManaphyPIDValid(val, pkm);
|
||||
case PCD d when d.Gift.PK.PID != 1:
|
||||
|
|
|
@ -97,5 +97,7 @@
|
|||
public static bool IsPtHGSSLocation(int location) => 111 < location && location < 2000;
|
||||
public static bool IsPtHGSSLocationEgg(int location) => 2010 < location && location < 3000;
|
||||
public static bool IsEventLocation5(int location) => 40000 < location && location < 50000;
|
||||
|
||||
public static bool IsSafariZoneLocation4(int loc) => loc == 52 || loc == 202;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -388,7 +388,7 @@ namespace PKHeX.Core
|
|||
var bv = pk8.BattleVersion;
|
||||
if (bv != 0)
|
||||
{
|
||||
if (bv != (int)GameVersion.SW && bv != (int)GameVersion.SH || pk8.SWSH)
|
||||
if ((bv != (int)GameVersion.SW && bv != (int)GameVersion.SH) || pk8.SWSH)
|
||||
data.AddLine(GetInvalid(LStatBattleVersionInvalid));
|
||||
}
|
||||
|
||||
|
|
|
@ -192,12 +192,12 @@ namespace PKHeX.Core
|
|||
SeenFlagOffsets = SeenFlagOffsets.Where(z => z >= 0).ToArray();
|
||||
}
|
||||
|
||||
private void LoadBlocks(out int[] blockOrder, out int[] blockOfs)
|
||||
private void LoadBlocks(out short[] blockOrder, out int[] blockOfs)
|
||||
{
|
||||
int[] o1 = GetBlockOrder(0);
|
||||
var o1 = GetBlockOrder(0);
|
||||
if (Data.Length > SaveUtil.SIZE_G3RAWHALF)
|
||||
{
|
||||
int[] o2 = GetBlockOrder(0xE000);
|
||||
var o2 = GetBlockOrder(0xE000);
|
||||
ActiveSAV = GetActiveSaveIndex(o1, o2);
|
||||
blockOrder = ActiveSAV == 0 ? o1 : o2;
|
||||
}
|
||||
|
@ -215,15 +215,15 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
private int[] GetBlockOrder(int ofs)
|
||||
private short[] GetBlockOrder(int ofs)
|
||||
{
|
||||
int[] order = new int[BLOCK_COUNT];
|
||||
short[] order = new short[BLOCK_COUNT];
|
||||
for (int i = 0; i < BLOCK_COUNT; i++)
|
||||
order[i] = BitConverter.ToInt16(Data, ofs + (i * SIZE_BLOCK) + 0xFF4);
|
||||
return order;
|
||||
}
|
||||
|
||||
private int GetActiveSaveIndex(int[] BlockOrder1, int[] BlockOrder2)
|
||||
private int GetActiveSaveIndex(short[] BlockOrder1, short[] BlockOrder2)
|
||||
{
|
||||
int zeroBlock1 = Array.IndexOf(BlockOrder1, 0);
|
||||
int zeroBlock2 = Array.IndexOf(BlockOrder2, 0);
|
||||
|
@ -276,7 +276,7 @@ namespace PKHeX.Core
|
|||
|
||||
private int ActiveSAV;
|
||||
private int ABO => ActiveSAV*SIZE_BLOCK*0xE;
|
||||
private readonly int[] BlockOrder;
|
||||
private readonly short[] BlockOrder;
|
||||
private readonly int[] BlockOfs;
|
||||
public int GetBlockOffset(int block) => BlockOfs[block];
|
||||
|
||||
|
|
|
@ -452,9 +452,9 @@ namespace PKHeX.Core
|
|||
return false;
|
||||
}
|
||||
|
||||
private int[] MatchMysteryGifts(DataMysteryGift[] value)
|
||||
private byte[] MatchMysteryGifts(DataMysteryGift[] value)
|
||||
{
|
||||
int[] cardMatch = new int[8];
|
||||
byte[] cardMatch = new byte[8];
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (!(value[i] is PGT pgt))
|
||||
|
|
|
@ -149,7 +149,7 @@ namespace PKHeX.WinForms
|
|||
int tabcount = lines[0].Count(c => c == '\t');
|
||||
|
||||
newlines[0] = lines[0].Replace('\t', '|');
|
||||
newlines[1] = string.Join(":--:", new int[tabcount + 2].Select(_ => '|')); // 2 pipes for each end
|
||||
newlines[1] = string.Join(":--:", Enumerable.Repeat('|', tabcount + 2)); // 2 pipes for each end
|
||||
for (int i = 1; i < lines.Length; i++)
|
||||
newlines[i + 1] = lines[i].Replace('\t', '|');
|
||||
return newlines;
|
||||
|
|
Loading…
Reference in a new issue