SmartExchange and grid position check issues

Hey Cheo!
I'm very sorry I don't know why I'm not receiving email notifications and I missed a bunch of messages including this one. Justin had to message me about it manually. Hopefully we can figure out why this is happening as it is not the first time.

I'll look into your issue asap.
If I remember correctly it was related to CharacterEquipUnequipItemAction equipping the item. but then the unequipped item disapears because it does not fit.
Once I have a possible solution I'll send you the code changes
 
Could you try the following and let me know if it works for you:
Replace the CharacterEquipUnequipItemAction.cs script with the one linked

In characterInventoryBridge add the following functions.


Code:
        /// <summary>
        /// Can the item be moved from its current collection to one of the equippable item collections?
        /// </summary>
        /// <param name="itemInfo">The item info to move.</param>
        /// <param name="equippableCollectionIndex">The index of the equippable item collection.</param>
        /// <param name="slotIndex">The slot Index if the equippable is an item slot collection.</param>
        /// <returns>True if the item can be moved safely.</returns>
        public virtual bool CanMoveItemToEquippable(ItemInfo itemInfo, int equippableCollectionIndex = 0, int slotIndex = -1)
        {
            var equippableCollection = m_BridgeItemCollections.GetItemCollection(equippableCollectionIndex);
            if (equippableCollection == null) { return false; }

            var sourceItemCollection = itemInfo.ItemCollection;
            if (sourceItemCollection == null) {
                sourceItemCollection = DefaultItemCollection;
            }

            if (sourceItemCollection == null || sourceItemCollection.HasItem(itemInfo) == false) { return false; }

            var removableItemInfo = sourceItemCollection.RemoveItemCondition(itemInfo);
            if (removableItemInfo.HasValue == false || removableItemInfo.Value.Amount != itemInfo.Amount) { return false; }

            var addItemInfo = new ItemInfo(itemInfo.Amount, removableItemInfo.Value);
            var canAddItemInfo = equippableCollection.CanAddItem(addItemInfo);
            if (canAddItemInfo.HasValue == false || canAddItemInfo.Value.Amount != itemInfo.Amount) { return false; }

            if (equippableCollection is ItemSlotCollection equippableSlotCollection) {
                if (slotIndex == -1) {
                    slotIndex = equippableSlotCollection.GetTargetSlotIndex(itemInfo.Item);
                }

                if (slotIndex == -1) { return false; }

                var previousItemInSlot = equippableSlotCollection.GetItemInfoAtSlot(slotIndex);
                if (previousItemInSlot.Item != null && !previousItemInSlot.Item.StackableEquivalentTo(itemInfo.Item)) {
                    var canRemovePreviousItem = equippableSlotCollection.RemoveItemCondition(previousItemInSlot);
                    if (canRemovePreviousItem.HasValue == false ||
                        canRemovePreviousItem.Value.Amount != previousItemInSlot.Amount) { return false; }

                    var canReturnPreviousItem = sourceItemCollection.CanAddItem(previousItemInSlot);
                    if (canReturnPreviousItem.HasValue == false ||
                        canReturnPreviousItem.Value.Amount != previousItemInSlot.Amount) { return false; }
                }
            }

            return true;
        }


        /// <summary>
        /// Can the item be moved from one of the equippable item collections to the default item collection?
        /// </summary>
        /// <param name="itemInfo">The item info.</param>
        /// <param name="equippableCollectionIndex">The index of the equippable item collection.</param>
        /// <param name="slotIndex">The slot Index if the equippable is an item slot collection.</param>
        /// <returns>True if the item can be moved safely.</returns>
        public virtual bool CanMoveItemToDefault(ItemInfo itemInfo, int equippableCollectionIndex = 0, int slotIndex = -1)
        {
            var equippableCollection = m_BridgeItemCollections.GetItemCollection(equippableCollectionIndex);
            if (equippableCollection == null || m_DefaultItemCollection == null) { return false; }

            if (equippableCollection.HasItem(itemInfo) == false) { return false; }

            ItemInfo itemInfoToRemove;
            if (equippableCollection is ItemSlotCollection equippableSlotCollection) {
                if (slotIndex == -1) {
                    slotIndex = equippableSlotCollection.GetItemSlotIndex(itemInfo.Item);
                }

                if (slotIndex == -1) { return false; }

                itemInfoToRemove = equippableSlotCollection.GetItemInfoAtSlot(slotIndex);
                if (itemInfoToRemove.Item == null) { return false; }
                itemInfoToRemove = new ItemInfo(itemInfo.Amount, itemInfoToRemove);
            } else {
                itemInfoToRemove = itemInfo;
            }

            var removableItemInfo = equippableCollection.RemoveItemCondition(itemInfoToRemove);
            if (removableItemInfo.HasValue == false || removableItemInfo.Value.Amount != itemInfo.Amount) { return false; }

            var canAddItemInfo = m_DefaultItemCollection.CanAddItem(new ItemInfo(itemInfo.Amount, removableItemInfo.Value));
            if (canAddItemInfo.HasValue == false || canAddItemInfo.Value.Amount != itemInfo.Amount) { return false; }

            return true;
        }

And modify this one:

Code:
public void MoveEquip(ItemInfo itemInfo, int equippableItemCollectionSet, int slotID, bool equip)
        {
            if (equip) {
                MoveItemToEquippable(itemInfo, equippableItemCollectionSet, slotID);
                Equip(itemInfo,true);
                var movedItemInfo = MoveItemToEquippable(itemInfo, equippableItemCollectionSet, slotID);
                if (movedItemInfo.Amount == itemInfo.Amount) {
                    Equip(itemInfo,true);
                }
            } else {
                MoveItemToDefault(itemInfo, equippableItemCollectionSet, slotID);
            }
        }

Hopefully this does the trick :)

If not please do let me know how your scene is setup
 

Attachments

Thanks for the quick reply, and sorry about the 1 star review threat, but I had to get your attention !

These modifications do prevent from using the Equip action if there isn't enough room in the main grid to perform the exchange at the moment of clicking on the action. However this also prevents using it when there would be enough place without the selected item. So we end up with the same issue the basic drag and drop used to have, and while it is good that the primary issue was fixed players would naturally expect to be able to use this Equip action in a full inventory but with an exchange target of equal or smaller size. Would it be possible to have a proper exchange check built in this UCC Equip action ? Thanks.
 
So I've looked into it in more detail. I've added some special exceptions just ofr your use case.
This is not an elegant solution. But right now this is the only way I can solve your problem without amking breaking changes.

I will redesign the way Item collections and Item shape grids work from scratch in the next major version of the inventory system. I'll be breaking changes but it will help design things properly from the ground up now that we have a better understanding of all the different use cases. It won't be any time soon though as major updates take a long time to develop.

I hope this finally solves your issue!
 

Attachments

Thank you very much, this is exactly what we needed and I hope it can be helpful to other devs working on UCC-UIS projects with similar item grids :)
 
Back
Top