Skip to content

Commit 723e39b

Browse files
committed
fix(2431): Ensure that target inventory has slots populated
1 parent 091fd50 commit 723e39b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Intersect (Core)/Collections/Slotting/SlotList.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ public TSlot this[int slotIndex]
8585
set => _slots[slotIndex] = value;
8686
}
8787

88+
public void Ensure(int slotIndex)
89+
{
90+
if (_slots.ContainsKey(slotIndex))
91+
{
92+
return;
93+
}
94+
95+
_slots[slotIndex] = _factory(slotIndex);
96+
}
97+
98+
public void FillToCapacity()
99+
{
100+
var targetCapacity = Capacity;
101+
for (var targetSlotIndex = 0; Count < targetCapacity && targetSlotIndex < targetCapacity; ++targetSlotIndex)
102+
{
103+
Ensure(targetSlotIndex);
104+
}
105+
}
106+
88107
public int FindIndex(Func<TSlot, bool> predicate)
89108
{
90109
var copy = this.ToArray();

Intersect.Server.Core/Entities/BankInterface.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public bool TryDepositItem(Item? slot, int inventorySlotIndex, int quantityHint,
124124
var maximumStack = itemDescriptor.Stackable ? itemDescriptor.MaxBankStack : 1;
125125
var sourceQuantity = Item.FindQuantityOfItem(itemDescriptor.Id, sourceSlots);
126126

127+
_bank.FillToCapacity();
128+
127129
var targetSlots = _bank.ToArray();
128130

129131
lock (_lock)
@@ -335,6 +337,8 @@ public bool TryWithdrawItem(Item? slot, int bankSlotIndex, int quantityHint, int
335337
var sourceSlots = _bank.ToArray();
336338
var sourceQuantity = Item.FindQuantityOfItem(itemDescriptor.Id, sourceSlots);
337339

340+
_player.Items.FillToCapacity();
341+
338342
var targetSlots = _player.Items.ToArray();
339343

340344
lock (_lock)

0 commit comments

Comments
 (0)