MultiStacks Error?

Ansheron

New member
hello, I have a problem, whenever I use MultiStackItemCollection, at the time of picking an item through ItemPickup regardless of the amount I put in it, it always gives me the Default stack limit or Default stack limit attribute.

-In the first image can see that I use Multistack and default stack size limit.

-In the second image can see the quantity of the item that I have put.

-In the third image can see the amount he gives me when I pick it up.
 

Attachments

  • 1.png
    1.png
    575.8 KB · Views: 11
  • 2.png
    2.png
    443 KB · Views: 10
  • 3.png
    3.png
    25.7 KB · Views: 10
I was able to reproduce the bug very easily... I'm not sure how I didn't notice it before.
I wrote some unit tests for the MultiStackItemCollection so now if it ever breaks again due to external changes I should know before I make it public.

In the MultiStackCollection you may create replace "maxStackSize" by "remainderStack" on line 195
Code:
if (remainderStack != 0) {
    var newItemStack = GenericObjectPool.Get<ItemStack>();
    newItemStack.Initialize((itemInfo.Item, remainderStack), this);
    m_ItemStacks.Add(newItemStack);
}

This solves about 90% of the issues.

Then on line 171 replacing the condition comparing item IDs by this:
Code:
if (itemInfo.Item.IsUnique || m_ItemStacks[i].Item.StackableEquivalentTo(itemInfo.Item) == false) { continue; }

That solves issues that was allowing Unique items from being stacked

There was also issues when removing items. On line 78 the for loop should have been inversed like this. In addition I had to add another condition otherwise the item could be removed twice. So now that for loop looks like this:
Code:
for (int i = m_ItemStacks.Count - 1; i >= 0; i--) {
    if (m_ItemStacks[i].Item.ID != itemInfo.Item.ID) { continue; }
    if(itemStackRemoved == m_ItemStacks[i]) { continue; }
   
    itemStackRemoved = m_ItemStacks[i];
    previousIndexWithItem = RemoveItemFromStack(i, itemInfo, previousIndexWithItem,
        maxStackSize, ref amountToRemove, ref removed);
}

With those changes the MultiStackItemCollection now passes the 50+ tests I wrote for the base ItemCollection.

I'm very sorry about the delay, and I hope that fixes most of the issues you had.

If you get any other issues please do let me know and I'll write more unit tests for the MultiStack Collection.

I made some other changes to clean up the code, but nothing that changes functionality. That will be available in the next update planned for late January
 
I was able to reproduce the bug very easily... I'm not sure how I didn't notice it before.
I wrote some unit tests for the MultiStackItemCollection so now if it ever breaks again due to external changes I should know before I make it public.

In the MultiStackCollection you may create replace "maxStackSize" by "remainderStack" on line 195
Code:
if (remainderStack != 0) {
    var newItemStack = GenericObjectPool.Get<ItemStack>();
    newItemStack.Initialize((itemInfo.Item, remainderStack), this);
    m_ItemStacks.Add(newItemStack);
}

This solves about 90% of the issues.

Then on line 171 replacing the condition comparing item IDs by this:
Code:
if (itemInfo.Item.IsUnique || m_ItemStacks[i].Item.StackableEquivalentTo(itemInfo.Item) == false) { continue; }

That solves issues that was allowing Unique items from being stacked

There was also issues when removing items. On line 78 the for loop should have been inversed like this. In addition I had to add another condition otherwise the item could be removed twice. So now that for loop looks like this:
Code:
for (int i = m_ItemStacks.Count - 1; i >= 0; i--) {
    if (m_ItemStacks[i].Item.ID != itemInfo.Item.ID) { continue; }
    if(itemStackRemoved == m_ItemStacks[i]) { continue; }
  
    itemStackRemoved = m_ItemStacks[i];
    previousIndexWithItem = RemoveItemFromStack(i, itemInfo, previousIndexWithItem,
        maxStackSize, ref amountToRemove, ref removed);
}

With those changes the MultiStackItemCollection now passes the 50+ tests I wrote for the base ItemCollection.

I'm very sorry about the delay, and I hope that fixes most of the issues you had.

If you get any other issues please do let me know and I'll write more unit tests for the MultiStack Collection.

I made some other changes to clean up the code, but nothing that changes functionality. That will be available in the next update planned for late January

collecting items is acting very strange with the multistack with the new changes, it no longer gives you the default value of the limit, but now the first few times it collects items it is working fine until it fills the first stack from there it starts acting strange, I tried switching the default value of the limit per stack and sometimes it did not fill the stack completely, then it did not give anything, sometimes it came out that it removed elements, try to drop them and it remains 1 that when releasing it again is "multiplied"

video:
 
That is indeed very odd.
I wonder if this happens because your items are Mutable&Common.

I'll write some more tests today, and I'll send you the new MultiStackItemCollection script once I find and fix the issue.
In the meantime if your items aren't supposed to be Mutable try to make them Immutable&Common to see if that works correctly
 
Sorry for the delay, I answered your question in the wrong thread... I had too many tabs opened and got confused

Please find the new MultiStackItemCollection script attached.

You'll need to add this function in the ItemCollection class for it to compile:
Code:
Code:
/// <summary>
/// Can the item stack.
/// </summary>
/// <param name="itemInfo">The itemInfo.</param>
/// <param name="itemStack">The itemStack.</param>
/// <returns>True if the item can stack.</returns>
public virtual bool CanItemStack(ItemInfo itemInfo, ItemStack itemStack)
{
    return itemInfo.Item.IsUnique == false && itemStack.Item.StackableEquivalentTo(itemInfo.Item);
}

I'm sorry that I didn't catch those bugs before. It seems not many people are using the MultiStackItemCollection, most people either use the base ItemCollection or write their own custom ItemCollection.

If you find any more bugs I'll fix them asap. Unfortunatly I have other features which require some attention more urgently so I might not be able to fix them as fast as I did this week. I hope you understand
 

Attachments

  • MultiStackItemCollection.cs
    10.2 KB · Views: 4
Sorry for the delay, I answered your question in the wrong thread... I had too many tabs opened and got confused

Please find the new MultiStackItemCollection script attached.

You'll need to add this function in the ItemCollection class for it to compile:
Code:
Code:
/// <summary>
/// Can the item stack.
/// </summary>
/// <param name="itemInfo">The itemInfo.</param>
/// <param name="itemStack">The itemStack.</param>
/// <returns>True if the item can stack.</returns>
public virtual bool CanItemStack(ItemInfo itemInfo, ItemStack itemStack)
{
    return itemInfo.Item.IsUnique == false && itemStack.Item.StackableEquivalentTo(itemInfo.Item);
}

I'm sorry that I didn't catch those bugs before. It seems not many people are using the MultiStackItemCollection, most people either use the base ItemCollection or write their own custom ItemCollection.

If you find any more bugs I'll fix them asap. Unfortunatly I have other features which require some attention more urgently so I might not be able to fix them as fast as I did this week. I hope you understand

Thank! Now it works fine, a question about what is related to this and the restrictions.

I need to find in the inventory the same object that I am analyzing ("pickup"), check if it is not full "Stack Size Limit" and pickup or not according to the case.

any suggestion?

screenshot.png
 
You could use the receivingCollection to get the current amount and then add the difference to max out the stack amount.

Something around those lines (not tested)
C#:
var currentAmount = receivingItemCollection.GetItemAmount(itemInfo.Item);
//Already full
if (currentAmount >= stackSizeLimit) { return null; }

var totalAmountIfAdded = currentAmount + itemInfo.Amount;
if (totalAmountIfAdded <= stackSizeLimit) {
    //add normally
    return itemInfo;
} else {
    //do the difference and add only part of the amount?
    var difference = stackSizeLimit - currentAmount;
    return (difference, itemInfo);
}

I hope that helps
 
Puede usar ReceiveCollection para obtener la cantidad actual y luego agregar la diferencia para maximizar la cantidad acumulada.

Algo alrededor de esas líneas (no probado)
[CÓDIGO = csharp] var currentAmount = ReceiveItemCollection.GetItemAmount (itemInfo.Item);
// Ya lleno
if (currentAmount> = stackSizeLimit) {return null; }

var totalAmountIfAdded = currentAmount + itemInfo.Amount;
if (totalAmountIfAdded <= stackSizeLimit) {
// agregar normalmente
return itemInfo;
} más {
// ¿Hace la diferencia y agrega solo una parte de la cantidad?
var diferencia = stackSizeLimit - currentAmount;
return (diferencia, itemInfo);
}[/CÓDIGO]

Espero que eso ayude
Thanks! you helped me a lot!
 
Top