[Bug] Issue with multiple Remove and Drop exceptions

Cheo

Active member
Hello @Sangemdoko , while experimenting with weapon dropping on death I stumbled upon an unexpected issue when using multiple remove and drop exceptions in Character Inventory Bridge. Here is a video demonstrating it :


So to sum it up, the core of the issue here is that instead of stopping when finding one matching category, the script keeps going through the category array and may lead to unwanted results if it stumbles upon a non matching category. I currently have a workaround for that since my enemies have a very limited number of items, but this should be fixed nonetheless as this works opposite to our expectations. Thanks in advance.
 
Thank you cheo, I really appriciate the detailed video.
You are completely right, this is an oversight on my part, definetly a bug and not the expected behaviour.

Here is the fix, let me know if it works for you:
Inside the DynamicItemCategoryArray replace the function and add this new function:
Code:
/// <summary>
/// Returns true if any category has a child that contains the item item provided.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="trueIfArrayIsEmpty">Return true if the array is empty.</param>
/// <returns>True if the item is part of any category.</returns>
public bool InherentlyContains(IItemIdentifier item, bool trueIfArrayIsEmpty)
{
    var array = Value;
    if (array == null || array.Length == 0) {
        return trueIfArrayIsEmpty;
    }
    for (int i = 0; i < array.Length; i++) {
        if (array[i].InherentlyContains(item))
        {
            return true;
        }
    }
    return false;
}
/// <summary>
/// Returns true if the item inhertis from all the categories.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="trueIfArrayIsEmpty">Return true if the array is empty.</param>
/// <returns>True if the item is part of all the categories.</returns>
public bool InherentlyContainsAll(IItemIdentifier item, bool trueIfArrayIsEmpty)
{
    var array = Value;
    if (array == null || array.Length == 0) {
        return trueIfArrayIsEmpty;
    }
    for (int i = 0; i < array.Length; i++) {
        if (array[i].InherentlyContains(item) == false)
        {
            return false;
        }
    }
    return true;
}

Now I have two functions one for if the items is part of all the categories and one for it the item is part of any category. This way there is no confusion which is which. in the bridge we'll only use the InherentlyContains function like it does now (but fixed with the code above)

Thank you for bringing this to our attention!
Best of luck with your development
 
Top