/// <summary>Updates the number of items being held by the player based on what was input to the split menu.</summary>
        /// <param name="item">The selected item.</param>
        /// <param name="who">The player that selected the items.</param>
        /// <param name="inventory">Either the player inventory or the shop inventory.</param>
        /// <param name="callback">The native callback to invoke to continue with the regular behavior after we've modified the stack.</param>
        private void MoveItems(Item item, SFarmer who, InventoryMenu inventory, ItemGrabMenu.behaviorOnItemSelect callback)
        {
            Debug.Assert(this.StackAmount > 0);

            // Get the held item now that it's been set by the native receiveRightClick call
            var heldItem = this.HeldItem;

            if (heldItem != null)
            {
                // update held item stack and item stack
                int numCurrentlyHeld = heldItem.Stack; // How many we're actually holding.
                int numInPile        = this.HoverItem.Stack + item.Stack;
                int wantToHold       = Math.Min(this.TotalItems, Math.Max(this.StackAmount, 0));

                this.HoverItem.Stack = this.TotalItems - wantToHold;
                heldItem.Stack       = wantToHold;

                item.Stack = wantToHold;

                // Remove the empty item from the inventory
                if (this.HoverItem.Stack <= 0)
                {
                    int index = inventory.actualInventory.IndexOf(this.HoverItem);
                    if (index > -1)
                    {
                        inventory.actualInventory[index] = null;
                    }
                }
            }

            RestoreNativeCallbacks();

            // Update stack to the amount set from OnStackAmountReceived
            callback?.Invoke(item, who);
        }
예제 #2
0
        /*********
        ** Private methods
        *********/
        private Item AddItemToInventory(Item item, int position, IList <Item> items, ItemGrabMenu.behaviorOnItemSelect onAddFunction = null)
        {
            if (object.ReferenceEquals(items, Game1.player.Items) && item is SObject obj && obj.specialItem)
            {
                if (obj.bigCraftable.Value)
                {
                    Game1.player.specialBigCraftables.Add(obj.IsRecipe ? -obj.ParentSheetIndex : obj.ParentSheetIndex);
                }
                else
                {
                    Game1.player.specialItems.Add(obj.IsRecipe ? -obj.ParentSheetIndex : obj.ParentSheetIndex);
                }
            }
            if (position < 0 || position >= items.Count)
            {
                return(item);
            }
            if (items[position] == null)
            {
                items[position] = item;
                onAddFunction?.Invoke(item, null);
                return(null);
            }
            if (items[position].maximumStackSize() == -1 || items[position].Name != item.Name || (item is SObject itemObj && items[position] is SObject slotObj && (itemObj.Quality != slotObj.Quality || itemObj.ParentSheetIndex != slotObj.ParentSheetIndex)) || !item.canStackWith(items[position]))
            {
                Item item2 = items[position];
                if (position == Game1.player.CurrentToolIndex && object.ReferenceEquals(items, Game1.player.Items) && item2 != null)
                {
                    item2.actionWhenStopBeingHeld(Game1.player);
                    item.actionWhenBeingHeld(Game1.player);
                }
                items[position] = item;
                onAddFunction?.Invoke(item, null);
                return(item2);
            }
            int num = items[position].addToStack(item.getStack());

            if (num <= 0)
            {
                return(null);
            }

            item.Stack = num;
            onAddFunction?.Invoke(item, null);
            return(item);
        }
예제 #3
0
        public static Item AddItemToInventory(Item item, int position, List <Item> items, ItemGrabMenu.behaviorOnItemSelect onAddFunction = null)
        {
            if (items == Game1.player.items && item is SObject obj && obj.specialItem)
            {
                if (obj.bigCraftable)
                {
                    Game1.player.specialBigCraftables.Add(obj.isRecipe ? (-obj.parentSheetIndex) : obj.parentSheetIndex);
                }
                else
                {
                    Game1.player.specialItems.Add(obj.isRecipe ? (-obj.parentSheetIndex) : obj.parentSheetIndex);
                }
            }
            if (position < 0 || position >= items.Count)
            {
                return(item);
            }
            if (items[position] == null)
            {
                items[position] = item;
                onAddFunction?.Invoke(item, null);
                return(null);
            }
            if (items[position].maximumStackSize() == -1 || items[position].Name != item.Name || (item is SObject addItem && items[position] is SObject slotItem && (addItem.quality != slotItem.quality || addItem.parentSheetIndex != slotItem.parentSheetIndex)) || !item.canStackWith(items[position]))
            {
                Item foundItem = items[position];
                if (position == Game1.player.CurrentToolIndex && items == Game1.player.items && foundItem != null)
                {
                    foundItem.actionWhenStopBeingHeld(Game1.player);
                    item.actionWhenBeingHeld(Game1.player);
                }
                items[position] = item;
                onAddFunction?.Invoke(item, null);
                return(foundItem);
            }
            int newStack = items[position].addToStack(item.getStack());

            if (newStack <= 0)
            {
                return(null);
            }

            item.Stack = newStack;
            onAddFunction?.Invoke(item, null);
            return(item);
        }