mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 14:30:56 +00:00
3e7775fc44
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately Don't store within the object, track the slot origin data separately. Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty. - Requesting a Box Data report now shows all slots in the save file (party, misc) - Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely) - Replace some linq usages with direct code * Remove WasLink virtual in PKM Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM. * Use Fateful to directly check gen5 mysterygift origins No other encounter types in gen5 apply Fateful * Simplify double ball comparison Used to be separate for deferral cases, now no longer needed to be separate. * Grab move/relearn reference and update locally Fix relearn move identifier * Inline defog HM transfer preference check HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly. * Extract more met location metadata checks: WasBredEgg * Replace Console.Write* with Debug.Write* There's no console output UI, so don't include them in release builds. * Inline WasGiftEgg, WasEvent, and WasEventEgg logic Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
101 lines
3.3 KiB
C#
101 lines
3.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
/// <summary>
|
|
/// Logic for rearranging pointers for Box Storage utility
|
|
/// </summary>
|
|
public static class SlotPointerUtil
|
|
{
|
|
private static bool WithinRange(int slot, int min, int max) => min <= slot && slot < max;
|
|
|
|
public static void UpdateSwap(int b1, int b2, int slotsPerBox, params IList<int>[] ptrset)
|
|
{
|
|
int diff = (b1 - b2) * slotsPerBox;
|
|
|
|
int b1s = b1 * slotsPerBox;
|
|
int b1e = b1s + slotsPerBox;
|
|
int b12 = b1 > b2 ? -diff : diff;
|
|
|
|
int b2s = b2 * slotsPerBox;
|
|
int b2e = b2s + slotsPerBox;
|
|
int b21 = b2 > b1 ? -diff : diff;
|
|
foreach (var list in ptrset)
|
|
{
|
|
for (int s = 0; s < list.Count; s++)
|
|
{
|
|
if (WithinRange(b1s, b1e, list[s]))
|
|
list[s] += b12;
|
|
else if (WithinRange(b2s, b2e, list[s]))
|
|
list[s] += b21;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void UpdateRepointFrom(IList<PKM> result, IList<PKM> bd, int start, params IList<int>[] slotPointers)
|
|
{
|
|
foreach (var p in slotPointers)
|
|
{
|
|
for (int i = 0; i < p.Count; i++)
|
|
{
|
|
var index = p[i];
|
|
if ((uint)index >= bd.Count)
|
|
continue;
|
|
var pk = bd[index];
|
|
var newIndex = result.IndexOf(pk);
|
|
if (newIndex < 0)
|
|
continue;
|
|
|
|
Debug.WriteLine($"Re-pointing {pk.Nickname} from {index} to {newIndex}");
|
|
Debug.WriteLine($"{result[newIndex]}");
|
|
p[i] = start + newIndex;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void UpdateRepointFrom(int newIndex, int oldIndex, params IList<int>[] slotPointers)
|
|
{
|
|
foreach (var p in slotPointers)
|
|
{
|
|
for (int s = 0; s < p.Count; s++)
|
|
{
|
|
if (p[s] != oldIndex)
|
|
continue;
|
|
p[s] = newIndex;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void UpdateMove(int bMove, int cMove, int slotsPerBox, params IList<int>[] ptrset)
|
|
{
|
|
int bStart = bMove * slotsPerBox;
|
|
int cStart = cMove * slotsPerBox;
|
|
int bEnd = bStart + slotsPerBox;
|
|
int cEnd = cStart + slotsPerBox;
|
|
int cShift;
|
|
int bShift;
|
|
if (bMove < cMove) // shift chunk down, shift box up
|
|
{
|
|
cShift = -slotsPerBox;
|
|
bShift = (cStart - bStart);
|
|
}
|
|
else // shift box down, shift chunk up
|
|
{
|
|
cShift = slotsPerBox;
|
|
bShift = -(bStart - cStart);
|
|
}
|
|
foreach (var list in ptrset)
|
|
{
|
|
for (int s = 0; s < list.Count; s++)
|
|
{
|
|
if (WithinRange(cStart, cEnd, list[s]))
|
|
list[s] += cShift;
|
|
if (WithinRange(bStart, bEnd, list[s]))
|
|
list[s] += bShift;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|