mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-06-03 05:04:12 -05:00
Move inventory item validity checking to class
#619 Expanded sanitize check to re-add items to fill the pouch back up.
This commit is contained in:
parent
844e1df508
commit
ae63dceaae
|
|
@ -26,6 +26,16 @@ public InventoryItem Clone()
|
|||
{
|
||||
return new InventoryItem {Count = Count, Index = Index, New = New};
|
||||
}
|
||||
|
||||
// Check Pouch Compatibility
|
||||
public bool Valid(ushort[] LegalItems, bool HaX, int MaxItemID)
|
||||
{
|
||||
if (Index == 0)
|
||||
return true;
|
||||
if (Index <= MaxItemID)
|
||||
return HaX || LegalItems.Contains((ushort)Index);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class InventoryPouch
|
||||
|
|
@ -247,5 +257,11 @@ public void sortName(string[] names, bool reverse = false)
|
|||
Items = Items.Where(item => item.Index != 0).OrderBy(item => names[item.Index])
|
||||
.Concat(Items.Where(item => item.Index == 0 || item.Index >= names.Length)).ToArray();
|
||||
}
|
||||
|
||||
public void sanitizePouch(bool HaX, int MaxItemID)
|
||||
{
|
||||
var x = Items.Where(item => item.Valid(LegalItems, HaX, MaxItemID)).ToArray();
|
||||
Items = x.Concat(new byte[MaxCount - x.Length].Select(i => new InventoryItem())).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,18 +153,15 @@ private void getBags()
|
|||
var invalid = pouch.Items.Where(item => item.Index != 0 && !pouch.LegalItems.Contains((ushort)item.Index)).ToArray();
|
||||
var outOfBounds = invalid.Where(item => item.Index >= itemlist.Length).ToArray();
|
||||
var incorrectPouch = invalid.Where(item => item.Index < itemlist.Length).ToArray();
|
||||
pouch.Items = pouch.Items.Where(item => item.Index == 0 || pouch.LegalItems.Contains((ushort)item.Index)).ToArray();
|
||||
|
||||
if (outOfBounds.Any())
|
||||
Util.Error("Unknown item detected.", "Item ID(s): " + string.Join(", ", outOfBounds.Select(item => item.Index)));
|
||||
if (incorrectPouch.Any())
|
||||
if (!Main.HaX && incorrectPouch.Any())
|
||||
Util.Alert($"The following item(s) have been removed from {pouch.Type} pouch.",
|
||||
string.Join(", ", incorrectPouch.Select(item => itemlist[item.Index])),
|
||||
"If you save changes, the item(s) will no longer be in the pouch.");
|
||||
|
||||
int purgedItems = outOfBounds.Length + incorrectPouch.Length;
|
||||
pouch.Items = pouch.Items.Concat(new byte[purgedItems].Select(i => new InventoryItem())).ToArray();
|
||||
|
||||
pouch.sanitizePouch(Main.HaX, itemlist.Length - 1);
|
||||
getBag(dgv, pouch);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user