mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-24 11:44:44 -05:00
Consolidate pouch load/set
This commit is contained in:
@@ -381,14 +381,11 @@ public override InventoryPouch[] Inventory
|
||||
new InventoryPouchGB(InventoryType.Items, legalItems, 99, Offsets.Items, 20),
|
||||
new InventoryPouchGB(InventoryType.PCItems, legalItems, 99, Offsets.PCItems, 50)
|
||||
};
|
||||
foreach (var p in pouch)
|
||||
p.GetPouch(Data);
|
||||
return pouch;
|
||||
return pouch.LoadAll(Data);
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.SetPouch(Data);
|
||||
value.SaveAll(Data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -435,15 +435,9 @@ public override InventoryPouch[] Inventory
|
||||
new InventoryPouchGB(InventoryType.Balls, LegalBalls, 99, Offsets.PouchBall, 12),
|
||||
new InventoryPouchGB(InventoryType.PCItems, LegalItems.Concat(LegalKeyItems).Concat(LegalBalls).Concat(LegalTMHMs).ToArray(), 99, Offsets.PouchPC, 50)
|
||||
};
|
||||
foreach (var p in pouch)
|
||||
p.GetPouch(Data);
|
||||
return pouch;
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.SetPouch(Data);
|
||||
return pouch.LoadAll(Data);
|
||||
}
|
||||
set => value.SaveAll(Data);
|
||||
}
|
||||
|
||||
private readonly byte[] DaycareFlags = new byte[2];
|
||||
|
||||
@@ -600,15 +600,10 @@ public override InventoryPouch[] Inventory
|
||||
{
|
||||
if (p.Type != InventoryType.PCItems)
|
||||
((InventoryPouch3)p).SecurityKey = SecurityKey;
|
||||
p.GetPouch(Data);
|
||||
}
|
||||
return pouch;
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.SetPouch(Data);
|
||||
return pouch.LoadAll(Data);
|
||||
}
|
||||
set => value.SaveAll(Data);
|
||||
}
|
||||
|
||||
private int DaycareSlotSize => RS ? SIZE_STORED : SIZE_STORED + 0x3C; // 0x38 mail + 4 exp
|
||||
|
||||
@@ -392,15 +392,9 @@ public override InventoryPouch[] Inventory
|
||||
new InventoryPouch3GC(InventoryType.Berries, LegalBerries, 999, OFS_PouchBerry, 46),
|
||||
new InventoryPouch3GC(InventoryType.Medicine, LegalCologne, 999, OFS_PouchCologne, 3), // Cologne
|
||||
};
|
||||
foreach (var p in pouch)
|
||||
p.GetPouch(Data);
|
||||
return pouch;
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.SetPouch(Data);
|
||||
return pouch.LoadAll(Data);
|
||||
}
|
||||
set => value.SaveAll(Data);
|
||||
}
|
||||
|
||||
// Daycare Structure:
|
||||
|
||||
@@ -337,15 +337,9 @@ public override InventoryPouch[] Inventory
|
||||
new InventoryPouch3GC(InventoryType.Medicine, LegalCologne, 999, OFS_PouchCologne, 3), // Cologne
|
||||
new InventoryPouch3GC(InventoryType.BattleItems, LegalDisc, 999, OFS_PouchDisc, 60)
|
||||
};
|
||||
foreach (var p in pouch)
|
||||
p.GetPouch(Data);
|
||||
return pouch;
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.SetPouch( Data);
|
||||
return pouch.LoadAll(Data);
|
||||
}
|
||||
set => value.SaveAll(Data);
|
||||
}
|
||||
|
||||
// Daycare Structure:
|
||||
|
||||
@@ -333,15 +333,9 @@ public override InventoryPouch[] Inventory
|
||||
new InventoryPouch4(InventoryType.BattleItems, LegalBattleItems, 999, OFS_BattleItems),
|
||||
new InventoryPouch4(InventoryType.MailItems, LegalMailItems, 999, OFS_MailItems),
|
||||
};
|
||||
foreach (var p in pouch)
|
||||
p.GetPouch(Data);
|
||||
return pouch;
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.SetPouch(Data);
|
||||
return pouch.LoadAll(Data);
|
||||
}
|
||||
set => value.SaveAll(Data);
|
||||
}
|
||||
|
||||
// Storage
|
||||
|
||||
@@ -201,15 +201,9 @@ public override InventoryPouch[] Inventory
|
||||
new InventoryPouch4(InventoryType.Medicine, LegalMedicine, 999, OFS_PouchMedicine),
|
||||
new InventoryPouch4(InventoryType.Berries, LegalBerries, 999, OFS_PouchBerry),
|
||||
};
|
||||
foreach (var p in pouch)
|
||||
p.GetPouch(Data);
|
||||
return pouch;
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.SetPouch(Data);
|
||||
return pouch.LoadAll(Data);
|
||||
}
|
||||
set => value.SaveAll(Data);
|
||||
}
|
||||
|
||||
// Storage
|
||||
|
||||
@@ -732,15 +732,9 @@ public override InventoryPouch[] Inventory
|
||||
new InventoryPouch4(InventoryType.Medicine, legalMedicine, 999, OFS_PouchMedicine),
|
||||
new InventoryPouch4(InventoryType.Berries, Legal.Pouch_Berry_XY, 999, OFS_PouchBerry),
|
||||
};
|
||||
foreach (var p in pouch)
|
||||
p.GetPouch(Data);
|
||||
return pouch;
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.SetPouch(Data);
|
||||
return pouch.LoadAll(Data);
|
||||
}
|
||||
set => value.SaveAll(Data);
|
||||
}
|
||||
|
||||
// Storage
|
||||
|
||||
@@ -837,15 +837,9 @@ public override InventoryPouch[] Inventory
|
||||
get
|
||||
{
|
||||
var bag = GetPouches();
|
||||
foreach (var p in bag)
|
||||
p.GetPouch(Data);
|
||||
return bag;
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.SetPouch(Data);
|
||||
return bag.LoadAll(Data);
|
||||
}
|
||||
set => value.SaveAll(Data);
|
||||
}
|
||||
|
||||
private InventoryPouch[] GetPouches()
|
||||
|
||||
@@ -26,17 +26,13 @@ public override InventoryPouch[] Inventory
|
||||
new InventoryPouch7b(InventoryType.ZCrystals, Legal.Pouch_PowerUp_GG, 999, PowerUp, PouchSize7b.PowerUp),
|
||||
new InventoryPouch7b(InventoryType.Candy, Legal.Pouch_Candy_GG, 999, Candy, PouchSize7b.Candy),
|
||||
};
|
||||
foreach (var p in pouch)
|
||||
p.GetPouch(Data);
|
||||
return pouch;
|
||||
return pouch.LoadAll(Data);
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (var p in value)
|
||||
{
|
||||
((InventoryPouch7b)p).SanitizeCounts();
|
||||
p.SetPouch(Data);
|
||||
}
|
||||
value.SaveAll(Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,4 +221,20 @@ private int GetSuggestedItemCount(ITrainerInfo sav, int item, int requestVal = 1
|
||||
return Math.Min(MaxCount, requestVal);
|
||||
}
|
||||
}
|
||||
|
||||
public static class InventoryPouchExtensions
|
||||
{
|
||||
public static InventoryPouch[] LoadAll(this InventoryPouch[] value, byte[] Data)
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.GetPouch(Data);
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void SaveAll(this InventoryPouch[] value, byte[] Data)
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.SetPouch(Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,11 @@ public sealed class InventoryPouch3 : InventoryPouch
|
||||
public InventoryPouch3(InventoryType type, ushort[] legal, int maxcount, int offset, int size)
|
||||
: base(type, legal, maxcount, offset, size)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void GetPouch(byte[] Data)
|
||||
{
|
||||
InventoryItem[] items = new InventoryItem[PouchDataSize];
|
||||
var items = new InventoryItem[PouchDataSize];
|
||||
for (int i = 0; i<items.Length; i++)
|
||||
{
|
||||
items[i] = new InventoryItem
|
||||
|
||||
@@ -11,7 +11,7 @@ public InventoryPouch3GC(InventoryType type, ushort[] legal, int maxcount, int o
|
||||
|
||||
public override void GetPouch(byte[] Data)
|
||||
{
|
||||
InventoryItem[] items = new InventoryItem[PouchDataSize];
|
||||
var items = new InventoryItem[PouchDataSize];
|
||||
for (int i = 0; i < items.Length; i++)
|
||||
{
|
||||
items[i] = new InventoryItem
|
||||
|
||||
@@ -7,12 +7,11 @@ public sealed class InventoryPouch4 : InventoryPouch
|
||||
public InventoryPouch4(InventoryType type, ushort[] legal, int maxcount, int offset)
|
||||
: base(type, legal, maxcount, offset)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void GetPouch(byte[] Data)
|
||||
{
|
||||
InventoryItem[] items = new InventoryItem[PouchDataSize];
|
||||
var items = new InventoryItem[PouchDataSize];
|
||||
for (int i = 0; i < items.Length; i++)
|
||||
{
|
||||
items[i] = new InventoryItem
|
||||
|
||||
@@ -15,7 +15,7 @@ public InventoryPouch7(InventoryType type, ushort[] legal, int maxcount, int off
|
||||
|
||||
public override void GetPouch(byte[] Data)
|
||||
{
|
||||
InventoryItem[] items = new InventoryItem[PouchDataSize];
|
||||
var items = new InventoryItem[PouchDataSize];
|
||||
for (int i = 0; i < items.Length; i++)
|
||||
{
|
||||
// 10bit itemID
|
||||
|
||||
@@ -12,7 +12,7 @@ public InventoryPouchGB(InventoryType type, ushort[] legal, int maxcount, int of
|
||||
|
||||
public override void GetPouch(byte[] Data)
|
||||
{
|
||||
InventoryItem[] items = new InventoryItem[PouchDataSize];
|
||||
var items = new InventoryItem[PouchDataSize];
|
||||
if (Type == InventoryType.TMHMs)
|
||||
{
|
||||
int slot = 0;
|
||||
@@ -85,7 +85,7 @@ public override void SetPouch(byte[] Data)
|
||||
case InventoryType.TMHMs:
|
||||
foreach (InventoryItem t in Items)
|
||||
{
|
||||
if (!LegalItems.Any(it => it == t.Index))
|
||||
if (LegalItems.All(z => z != t.Index))
|
||||
continue;
|
||||
int index = Offset + Array.FindIndex(LegalItems, it => t.Index == it);
|
||||
Data[index] = (byte)t.Count;
|
||||
|
||||
Reference in New Issue
Block a user