public override bool Equip(InventoryEquippableField equipSlot, CharacterUI equipToCollection)
        {
            bool equipped = base.Equip(equipSlot, equipToCollection);
            if (equipped == false)
                return false;

            SetPlyGameValues(1.0f);
            return true;
        }
        public virtual void Start()
        {
            outline = GetComponent<Outline>();
            outline.enabled = false;

            wrapper = GetComponent<InventoryUIItemWrapperBase>();
            equippableField = GetComponent<InventoryEquippableField>();

            InventoryUIDragUtility.OnStartDragging += InventoryUiDragUtilityOnOnStartDragging;
            InventoryUIDragUtility.OnEndDragging += InventoryUiDragUtilityOnOnEndDragging;
        }
        public override bool Equip(InventoryEquippableField equipSlot, ItemCollectionBase equipToCollection)
        {
            bool equipped = base.Equip(equipSlot, equipToCollection);
            if (equipped == false)
                return false;

            if (actor.actorClass.currLevel < requiredLevel)
            {
                InventoryManager.instance.lang.itemCannotBeUsedLevelToLow.Show(name, description, requiredLevel);
                return false;
            }

            SetPlyGameValues();

            return true;
        }
        public virtual bool Equip(InventoryEquippableField equipSlot, ItemCollectionBase equipToCollection)
        {
            bool handled = HandleLocks(equipSlot, itemCollection);
            if (handled == false)
                return false; // Other items cannot be unequipped

            // There was already an item in this slot, un-equip that one first
            if (equipToCollection[equipSlot.index].item != null)
            {
                var item = equipToCollection[equipSlot.index].item as EquippableInventoryItem;
                bool addedItem = InventoryManager.AddItemAndRemove(item);
                if (addedItem == false)
                    return false; // Can't un-equip item to equip item..

                item.NotifyItemUnEquipped();
            }

            // The values before the collection / slot changed.
            uint prevIndex = index;
            var fromCollection = itemCollection;

            // Equip the item -> Will swap as merge is not possible
            bool swapped = itemCollection.SwapOrMerge(index, equipToCollection, equipSlot.index);
            if (swapped)
            {
                NotifyItemUsed(1, false); // NOTE: Collection changed, collection - event no longer valid!
                fromCollection.NotifyItemUsed(ID, prevIndex, 1);

                if (fromCollection[prevIndex].item != null)
                    ((EquippableInventoryItem)fromCollection[prevIndex].item).NotifyItemUnEquipped();

                return true;
            }

            return false;
        }
        /// <summary>
        /// Some item's require multiple slots, for example a 2 handed item forces the left handed item to be empty.
        /// </summary>
        /// <returns>true if items were removed, false if items were not removed.</returns>
        public virtual bool HandleLocks(InventoryEquippableField equipSlot, ItemCollectionBase usedFromCollection, CharacterUI equipTo)
        {
            var toBeRemoved = new List<uint>(8);

            // Loop through things we want to block
            foreach (var blockType in equipType.blockTypes)
            {
                // Check every slot against this block type
                foreach (var field in equipTo.equipSlotFields)
                {
                    var item = equipTo[field.index].item;
                    if(item != null)
                    {
                        var eq = (EquippableInventoryItem)item;

                        if(eq.equipType.ID == blockType && field.index != equipSlot.index)
                        {
                            toBeRemoved.Add(field.index);
                            bool canAdd = InventoryManager.CanAddItem(eq);
                            if (canAdd == false)
                                return false;
                        }
                    }
                }
            }
            
            foreach (uint i in toBeRemoved)
            {
                var item = equipTo[i].item as EquippableInventoryItem;
                bool added = InventoryManager.AddItemAndRemove(item);
                if (added == false)
                {
                    Debug.LogError("Item could not be saved, even after check, please report this bug + stacktrace.");
                    return false;
                }
            }

            return true;
        }
        /// <summary>
        /// Equip the item to the given collection
        /// </summary>
        /// <param name="equipSlot">Equip to slot</param>
        /// <param name="equipTo">Collection to equip to</param>
        /// <returns></returns>
        public virtual bool Equip(InventoryEquippableField equipSlot, CharacterUI equipTo)
        {
            if (CanEquip() == false)
                return false;

            bool handled = HandleLocks(equipSlot, itemCollection, equipTo);
            if (handled == false)
                return false; // Other items cannot be unequipped

            // There was already an item in this slot, un-equip that one first
            if (equipTo[equipSlot.index].item != null)
            {
                var item = equipTo[equipSlot.index].item as EquippableInventoryItem;
                bool unEquipped = item.UnEquip(false);
                if (unEquipped == false)
                    return false;
            }

            // The values before the collection / slot changed.
            uint prevIndex = index;
            var fromCollection = itemCollection;

            // Equip the item -> Will swap as merge is not possible
            bool canSet = equipTo.CanSetItem(equipSlot.index, this);
            if (canSet)
            {
                NotifyItemUsed(1, true); // Events still valid, handling before the set

                equipTo.SetItem(equipSlot.index, this);
                if(fromCollection != null)
                    fromCollection.SetItem(prevIndex, null);

                equipTo.NotifyItemAdded(this, currentStackSize, itemCollection != null);
                if (fromCollection != null)
                {
                    fromCollection.NotifyItemRemoved(this, ID, prevIndex, currentStackSize);
                    fromCollection[prevIndex].Repaint();
                }

                //NotifyItemEquipped(equipSlot); // Collection defines when an item is equipped or unequipped
                equipTo[equipSlot.index].Repaint();
                //fromCollection.NotifyItemUsed(this, ID, prevIndex, 1);

                return true;
            }

            return false;
        }
        /// <summary>
        /// Called by the collection once the item is successfully equipped.
        /// </summary>
        /// <param name="equipSlot"></param>
        public void NotifyItemEquipped(InventoryEquippableField equipSlot)
        {
            isEquipped = true;

            SetItemProperties(InventoryPlayerManager.instance.currentPlayer, InventoryItemUtility.SetItemPropertiesAction.Use);

            if (OnEquipped != null)
                OnEquipped(equipSlot);

            if (playOnEquip != null)
                InventoryUtility.AudioPlayOneShot(playOnEquip);
        }
        public InventoryEquippableField GetBestEquipSlot(EquippableInventoryItem item, InventoryEquippableField[] fields, InventoryPlayer player)
        {
            if (fields.Length > 0)
                return fields[0];

            return null;
        }
 /// <summary>
 /// Called by the collection once the item is successfully equipped.
 /// </summary>
 /// <param name="equipSlot"></param>
 public void NotifyItemEquipped(InventoryEquippableField equipSlot)
 {
     if (OnEquipped != null)
         OnEquipped(equipSlot);
 }
        /// <summary>
        /// Some item's require multiple slots, for example a 2 handed item forces the left handed item to be empty.
        /// </summary>
        /// <returns>true if items were removed, false if items were not removed.</returns>
        public virtual bool HandleLocks(InventoryEquippableField equipSlot, ItemCollectionBase usedFromCollection)
        {
            var toBeRemoved = new List<uint>(8);

            // Loop through things we want to block
            foreach (var blockType in equipType.blockTypes)
            {
                // Check every slot against this block type
                foreach (var field in InventoryManager.instance.character.equipSlotFields)
                {
                    var item = InventoryManager.instance.character[field.index].item;
                    if(item != null)
                    {
                        var eq = (EquippableInventoryItem)item;

                        if(eq.equipType.ID == blockType && field.index != equipSlot.index)
                        {
                            toBeRemoved.Add(field.index);
                            bool canAdd = InventoryManager.CanAddItem(eq);
                            if (canAdd == false)
                                return false;
                        }
                    }
                }
            }

            //// There was already an item in this slot, un-equip that one first
            //if (InventoryManager.instance.character[equipSlot.index].item != null)
            //{
            //    // TODO:  FIX THIS .. !
            //    toBeRemoved.Add(equipSlot.index);
            //}

            foreach (uint i in toBeRemoved)
            {
                var item = InventoryManager.instance.character[i].item as EquippableInventoryItem;
                bool added = InventoryManager.AddItemAndRemove(item);
                if (added == false)
                {
                    Debug.LogError("Item could not be saved, even after check, please report this bug + stacktrace.");
                    return false;
                }

                item.NotifyItemUnEquipped();
                //InventoryManager.instance.character.SetItem(i, null);
                //InventoryManager.instance.character[i].Repaint();
            }

            return true;
        }
 public InventoryPlayerEquipTypeBinder(InventoryEquippableField associatedField, Transform equipTransform, InventoryPlayerEquipHelper.EquipHandlerType equipHandlerType)
 {
     this.associatedField = associatedField;
     this.equipTransform = equipTransform;
     this.equipHandlerType = equipHandlerType;
 }
        public override void Awake()
        {
            equipSlotFields = new InventoryEquippableField[items.Length];
            for (int i = 0; i < items.Length; i++)
                equipSlotFields[i] = items[i].gameObject.GetComponent<InventoryEquippableField>();

            
            characterStats = new Dictionary<string, List<InventoryCharacterStat>>(16);
            statsDataProviders = new List<ICharacterStatDataProvider>(2);


            base.Awake();
            SetDefaultDataProviders();
            PrepareCharacterStats();


            if (isSharedCollection)
                InventoryManager.AddEquipCollection(this, collectionPriority);

            if (statusRowPrefab != null)
                rowsPool = new InventoryPool<InventoryEquipStatRowUI>(statusRowPrefab, 32);

            if (statusCategoryPrefab != null)
                categoryPool = new InventoryPool<InventoryEquipStatCategoryUI>(statusCategoryPrefab, 8);




            OnAddedItem += (itemsAdded, amount, cameFromCollection) =>
            {
                foreach (var item in itemsAdded)
                    ((EquippableInventoryItem)item).NotifyItemEquipped(equipSlotFields[item.index]);

                //RepaintStats();
                //UpdateCharacterStats();
            };
            OnRemovedItem += (item, itemID, slot, amount) =>
            {
                ((EquippableInventoryItem)item).NotifyItemUnEquipped();

                //RepaintStats();
                //UpdateCharacterStats();
            };
            OnSwappedItems += (collection, slot, toCollection, toSlot) =>
            {
                if (collection == this)
                {
                    //if (toCollection[toSlot].item != null)
                    //((EquippableInventoryItem)toCollection[toSlot].item).HandleLocks(equipSlotFields[slot], collection, this);
                }
                else
                {
                    if (toCollection[toSlot].item != null)
                        ((EquippableInventoryItem)toCollection[toSlot].item).HandleLocks(equipSlotFields[toSlot], collection, this);
                }
            };


            window.OnShow += RepaintAllStats;
        }