protected virtual void UnUse(InventoryPlayer player)
        {

            lootWindow.OnRemovedItem -= LootWindowOnRemovedItem;

            window.Hide();
        }
        private void OnPlayerChanged(InventoryPlayer oldPlayer, InventoryPlayer newPlayer)
        {
            newPlayer.rangeHelper.OnChangedBestTriggerer += BestTriggererChanged;

            // First time
            Repaint(newPlayer.rangeHelper.bestTriggerer);
        }
        protected virtual void SetPlyGameValues(InventoryPlayer player)
        {
            foreach (var attr in plyAttributes)
            {
                var a = actor.actorClass.attributes.FirstOrDefault(attribute => attribute.id.Value == attr.id.Value);
                if (a != null)
                {
                    //var i = ItemManager.instance.plyAttributes.FirstOrDefault(o => o.ID == attr.id);
                    //var stat = player.characterCollection.GetStat(i.category, a.def.screenName);

                    if (attr.addToBonus)
                    {
                        a.ChangeSimpleBonus(attr.toAdd);
                        //stat._maxValue += attr.toAdd; // Done in plyInventoryPlayer Callback
                    }
                    else
                    {
                        a.SetConsumableValue(a.ConsumableValue + attr.toAdd, gameObject);
                        //stat.currentValue += attr.toAdd; // Done in plyInventoryPlayer Callback
                    }
                }
            }

            //Debug.Log("TODO: Ply stats still need fixing"); // TODO: FINISH!

            //foreach (var equipToCollection in InventoryManager.GetEquipToCollections())
            //{
            //    equipToCollection.UpdateCharacterStats();
            //}
        }
        protected virtual void Use(InventoryPlayer player)
        {
            // Set items
            lootWindow.SetItems(items, true);
            
            lootWindow.OnRemovedItem += LootWindowOnRemovedItem;

            window.Show();
        }
 public virtual bool Toggle(InventoryPlayer player, out bool removeSource, bool fireEvents = true)
 {
     if (isActive)
     {
         removeSource = false;
         return UnUse(player, fireEvents);
     }
     else
     {
         return Use(player, out removeSource, fireEvents);
     }
 }
        protected virtual void UnUse(InventoryPlayer player)
        {
            vendorUI.currentVendor = null;
            vendorUI.OnRemovedItem -= vendorUI_OnRemovedItem;

            vendorUI.window.Hide();
        }
        protected virtual void Use(InventoryPlayer player)
        {
            // Set items
            vendorUI.SetItems(items, false, false);
            vendorUI.currentVendor = this;
            vendorUI.OnRemovedItem += vendorUI_OnRemovedItem;

            vendorUI.window.Show();
        }
 public static void RemovePlayer(InventoryPlayer player)
 {
     instance._players.Remove(player);
 }
        public static void AddPlayer(InventoryPlayer player)
        {
            if (instance.currentPlayer == null)
                instance.currentPlayer = player;

            instance._players.Add(player);
        }
        public override void NotifyWentOutOfRange(InventoryPlayer player)
        {


        }
 public abstract bool Use(InventoryPlayer player, out bool removeSource, bool fireEvents = true);
 protected virtual void SetItemProperties(InventoryPlayer player, InventoryItemUtility.SetItemPropertiesAction action)
 {
     InventoryItemUtility.SetItemProperties(player, properties, action);
     SetPlyGameValues(player);
 }
 /// <summary>
 /// Called when the item is equipped visually / bound to a mesh.
 /// Useful if you wish to remove a custom component whenever the item is equipped.
 /// </summary>
 /// <param name="binder"></param>
 public void NotifyItemUnEquippedVisually(InventoryPlayerEquipTypeBinder binder, InventoryPlayer player)
 {
     if (OnUnEquippedVisually != null)
         OnUnEquippedVisually(binder, player);
 }
        public override bool Use(InventoryPlayer player, out bool removeSource, bool fireEvents = true)
        {
            if (inRange)
            {
                removeSource = PickupItem(player, fireEvents);
                if (removeSource)
                {
                    InventoryTriggererManager.instance.currentlyHoveringTriggerer = null;
                }
            }
            else
            {
                bool shouldDestroySource;
                var item = GetItem(out shouldDestroySource);
                if (item != null)
                    InventoryManager.instance.lang.itemCannotBePickedUpToFarAway.Show(item.name, item.description);

                removeSource = false;
            }

            return removeSource;
        }
        public void Select(InventoryPlayer player)
        {
            if (InventoryManager.instance.selectableObjectInfo != null)
                InventoryManager.instance.selectableObjectInfo.currentSelectableObject = this;

        }
 public abstract void NotifyWentOutOfRange(InventoryPlayer player);
 public abstract void NotifyCameInRange(InventoryPlayer player);
 public abstract bool UnUse(InventoryPlayer player, bool fireEvents = true);
 public override bool Toggle(InventoryPlayer player, out bool removeSource, bool fireEvents = true)
 {
     if (window != null && window.isVisible && isActive)
     {
         removeSource = false; // Never destroy an ObjectTriggerer, they're static.
         return UnUse(player, fireEvents);
     }
     else
     {
         return Use(player, out removeSource, fireEvents);
     }
 }
        public override bool Use(InventoryPlayer player, out bool removeSource, bool fireEvents = true)
        {
            removeSource = false; // ObjectTriggers are "static" and aren't moved / changed after usage.

            if (enabled == false || inRange == false)
                return false;

            if (isActive)
                return true;

            if (previousTriggerer != null)
            {
                previousTriggerer.UnUse(player, fireEvents);
            }

            if (window != null)
            {
                window.OnShow += WindowOnShow;
                window.OnHide += WindowOnHide;

                if (handleWindowDirectly && fireEvents)
                {
                    if (toggleWhenTriggered)
                        window.Toggle();
                    else if (window.isVisible == false)
                        window.Show();
                }
            }
            else
            {
                Debug.LogWarning("Triggerer has no window", transform);
            }

            DoVisuals();

            isActive = true;

            if (OnTriggerUse != null && fireEvents)
                OnTriggerUse(player);

            InventoryTriggererManager.instance.NotifyTriggererUsed(this);
            previousTriggerer = this;

            return true;
        }
        public static void SetItemProperties(InventoryPlayer player, InventoryItemProperty[] properties, SetItemPropertiesAction action)
        {
            float multiplier = 1.0f;
            switch (action)
            {
                case SetItemPropertiesAction.Use:
                    multiplier = 1.0f;
                    break;
                case SetItemPropertiesAction.UnUse:
                    multiplier = -1f;
                    break;
                default:
                    Debug.LogWarning("Action " + action + " not found (Going with default use)");
                    break;
            }

            // Use the item's properties.
            if (player != null)
            {
                foreach (var property in properties)
                {
                    var stat = player.characterCollection.GetStat(property.category, property.name);
                    if (stat != null)
                    {
                        switch (property.actionEffect)
                        {
                            case InventoryItemProperty.ActionEffect.Add:

                                if (property.isFactor)
                                {
                                    //if (property.increaseMax)
                                    //    stat.ChangeFactorMax((property.floatValue - 1.0f) * multiplier, true);
                                    //else
                                        stat.ChangeFactorMax((property.floatValue - 1.0f) * multiplier, true);
                                }
                                else
                                {
                                    //if(property.increaseMax)
                                    //    stat.ChangeMaxValueRaw(property.floatValue * multiplier, true);
                                    //else
                                        stat.ChangeMaxValueRaw(property.floatValue * multiplier, true);
                                }

                                break;
                            case InventoryItemProperty.ActionEffect.Restore:

                                if (property.isFactor)
                                    stat.ChangeCurrentValueRaw((stat.currentValue * (property.floatValue - 1.0f)) * multiplier);
                                else
                                    stat.ChangeCurrentValueRaw(property.floatValue * multiplier);

                                break;
                            default:
                                Debug.LogWarning("Action effect" + property.actionEffect + " not found.");
                                break;
                        }

                        //player.characterCollection.NotifyStatChanged(stat); // Done by the stat itself.
                    }
                    else
                    {
                        Debug.LogWarning("Stat based on property: " + property.name + " not found on player.");
                    }
                }
            }
        }
        public override void NotifyCameInRange(InventoryPlayer player)
        {


        }
        public override bool UnUse(InventoryPlayer player, bool fireEvents = true)
        {
            // Can't un-use an item.

            return false;
        }
        public override bool UnUse(InventoryPlayer player, bool fireEvents = true)
        {
            if (enabled == false || inRange == false)
                return false;

            if (isActive == false)
                return true;

            if (handleWindowDirectly && fireEvents && window != null)
            {
                window.Hide();
            }

            UndoVisuals();


            isActive = false;

            if (window != null)
            {
                window.OnShow -= WindowOnShow;
                window.OnHide -= WindowOnHide;
            }

            if (OnTriggerUnUse != null && fireEvents)
                OnTriggerUnUse(player);

            InventoryTriggererManager.instance.NotifyTriggererUnUsed(this);

            previousTriggerer = null;
            return true;
        }
        protected virtual void SetItemProperties(InventoryPlayer player, InventoryItemUtility.SetItemPropertiesAction action)
        {
            // Just to be safe...
            foreach (var property in properties)
            {
                property.actionEffect = InventoryItemProperty.ActionEffect.Add;
            }

            InventoryItemUtility.SetItemProperties(player, properties, action);
        }
        protected virtual bool PickupItem(InventoryPlayer player, bool fireEvents = true)
        {
            bool shouldDestroySource;
            var item = GetItem(out shouldDestroySource);

            if (item != null)
            {
                uint itemID = item.ID;
                uint itemAmount = item.currentStackSize;

                bool pickedUp = item.PickupItem();
                if (pickedUp)
                {
                    if (fireEvents)
                    {
                        if (OnPickup != null)
                            OnPickup(player);

                        if (player != null)
                            player.NotifyPickedUpItem(itemID, itemAmount);

                        InventoryTriggererManager.instance.NotifyTriggererUsed(this);
                    }

                    if (shouldDestroySource)
                        Destroy(gameObject);
                }

                return pickedUp;
            }

            return false;
        }