Exemplo n.º 1
0
        /// <summary>
        /// Bool that tells us if it can add an Item to the players inventory
        /// </summary>
        /// <param name="obj">The Object</param>
        /// <param name="who">The Player</param>
        /// <returns></returns>
        private bool GiveItemToPlayer(SObject obj, SFarmer who)
        {
            if (_addItemsToInventory)
            {
                if (who.couldInventoryAcceptThisItem(obj))
                {
                    who.addItemToInventory(obj);
                    return(true);
                }
            }

            //Player hasn't edited the config, we should try the chest.
            //Find chest on the map.
            Game1.getFarm().objects.TryGetValue(_config.ChestLocation, out SObject _obj);


            if (_obj != null && _obj is Chest c)
            {
                Item item = c.addItem(obj);
                if (item == null)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        private bool AddItemToInventory(Object obj, SFarmer farmer)
        {
            if (!this.BypassInventory)
            {
                if (farmer.couldInventoryAcceptThisItem(obj))
                {
                    farmer.addItemToInventory(obj);
                    return(true);
                }
            }

            // Get the preferred chest (could be default)
            Object chestObj = this.ChestManager.GetChest(obj.ParentSheetIndex);

            if (chestObj is Chest chest)
            {
                Item i = chest.addItem(obj);
                if (i == null)
                {
                    return(true);
                }
            }

            // We haven't returned, get the default chest.
            chestObj = this.ChestManager.GetDefaultChest();

            if (chestObj is Chest defaultChest)
            {
                Item i = defaultChest.addItem(obj);
                if (i == null)
                {
                    return(true);
                }
            }

            // Haven't been able to add to a chest, try inventory one last time.
            if (farmer.couldInventoryAcceptThisItem(obj))
            {
                farmer.addItemToInventory(obj);
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
 /// <summary>Add an item to the player inventory from the container.</summary>
 /// <param name="item">The item taken.</param>
 /// <param name="player">The player taking the item.</param>
 private void GrabItemFromContainerImpl(Item item, SFarmer player)
 {
     if (!player.couldInventoryAcceptThisItem(item))
     {
         return;
     }
     if (Constants.TargetPlatform == GamePlatform.Android)
     {
         player.addItemToInventory(item);
     }
     this.ShippingBin.Remove(item);
     this.ShippingBin.Filter(p => p != null);
     if (item == this.Farm.lastItemShipped)
     {
         this.Farm.lastItemShipped = this.ShippingBin.LastOrDefault();
     }
 }
Exemplo n.º 4
0
        //behaviorOnItemSelectFunction
        public void grabItemFromInventory(Item item, StardewValley.Farmer who)
        {
            if (item.Stack == 0)
            {
                item.Stack = 1;
            }
            Item obj = this.addItem(item);

            if (obj == null)
            {
                who.removeItemFromInventory(item);
            }
            else
            {
                who.addItemToInventory(obj);
            }
            this.clearNulls();

            //TODO: implement page change
            //List<Item> newItems = GetCurrentPageItems();
            this.ShowCurrentPage();
        }
Exemplo n.º 5
0
        /**
         * Attempts to add the crop to the farmer's inventory.  If the crop is on the always sell list, it is sold instead.
         */
        private bool AddItemToInventory(StardewValley.Object obj, SFarmer farmer, Farm farm, ReplanterStats stats)
        {
            if (this.AlwaysSell(obj.ParentSheetIndex))
            {
                return(this.SellCrops(farmer, obj, stats));
            }

            bool wasAdded = false;

            if (farmer.couldInventoryAcceptThisItem(obj) && !this.BypassInventory)
            {
                farmer.addItemToInventory(obj);
                wasAdded = true;

                this.Monitor.Log("Was able to add item to inventory.", LogLevel.Trace);
            }
            else
            {
                StardewValley.Object chest;

                this.Chests.TryGetValue(obj.ParentSheetIndex, out ChestDef preferred);

                if (preferred != null)
                {
                    if (preferred.Location.Equals("house"))
                    {
                        FarmHouse house = (FarmHouse)Game1.getLocationFromName("FarmHouse");
                        house.objects.TryGetValue(preferred.Tile, out chest);
                    }
                    else
                    {
                        farm.objects.TryGetValue(preferred.Tile, out chest);
                    }

                    if (!(chest is Chest))
                    {
                        // Try getting the default chest.
                        farm.objects.TryGetValue(this.ChestCoords, out chest);
                    }
                }
                else
                {
                    farm.objects.TryGetValue(this.ChestCoords, out chest);
                }

                if (chest is Chest)
                {
                    Item i = ((Chest)chest).addItem(obj);
                    if (i == null)
                    {
                        wasAdded = true;
                    }
                    else
                    {
                        // If this condition was reached because bypassInventory was set, then try the inventory.
                        if (this.BypassInventory && farmer.couldInventoryAcceptThisItem(obj))
                        {
                            farmer.addItemToInventory(obj);
                            wasAdded = true;
                        }
                        else
                        {
                            this.Monitor.Log("Was NOT able to add items to chest.", LogLevel.Trace);
                        }
                    }
                }
                else
                {
                    this.Monitor.Log($"Did not find a chest at {(int)this.ChestCoords.X},{(int)this.ChestCoords.Y}", LogLevel.Trace);

                    // If bypassInventory is set to true, but there's no chest: try adding to the farmer's inventory.
                    if (this.BypassInventory)
                    {
                        this.Monitor.Log($"No chest at {(int)this.ChestCoords.X},{(int)this.ChestCoords.Y}, you should place a chest there, or set bypassInventory to \'false\'.", LogLevel.Trace);

                        if (farmer.couldInventoryAcceptThisItem(obj))
                        {
                            farmer.addItemToInventory(obj);
                            wasAdded = true;
                        }
                        else
                        {
                            this.Monitor.Log("Was NOT able to add item to inventory or a chest.  (No chest found, bypassInventory set to 'true')", LogLevel.Trace);
                        }
                    }
                    else
                    {
                        this.Monitor.Log("Was NOT able to add item to inventory or a chest.  (No chest found, bypassInventory set to 'false')", LogLevel.Trace);
                    }
                }
            }

            return(wasAdded);
        }
Exemplo n.º 6
0
        private bool AddItemToInventory(SObject obj, SFarmer farmer, Farm farm)
        {
            bool wasAdded = false;

            if (farmer.couldInventoryAcceptThisItem(obj) && !this.BypassInventory)
            {
                farmer.addItemToInventory(obj);
                wasAdded = true;

                if (this.LoggingEnabled)
                {
                    this.Monitor.Log("Was able to add item to inventory.", LogLevel.Trace);
                }
            }
            else
            {
                farm.objects.TryGetValue(this.ChestCoords, out SObject chestObj);

                if (chestObj is Chest chest)
                {
                    if (this.LoggingEnabled)
                    {
                        this.Monitor.Log($"Found a chest at {(int)this.ChestCoords.X},{(int)this.ChestCoords.Y}", LogLevel.Trace);
                    }

                    Item i = chest.addItem(obj);
                    if (i == null)
                    {
                        wasAdded = true;

                        if (this.LoggingEnabled)
                        {
                            this.Monitor.Log("Was able to add items to chest.", LogLevel.Trace);
                        }
                    }
                    else
                    {
                        this.InventoryAndChestFull = true;

                        if (this.LoggingEnabled)
                        {
                            this.Monitor.Log("Was NOT able to add items to chest.", LogLevel.Trace);
                        }
                    }
                }
                else
                {
                    if (this.LoggingEnabled)
                    {
                        this.Monitor.Log($"Did not find a chest at {(int)this.ChestCoords.X},{(int)this.ChestCoords.Y}", LogLevel.Trace);
                    }

                    // If bypassInventory is set to true, but there's no chest: try adding to the farmer's inventory.
                    if (this.BypassInventory)
                    {
                        if (this.LoggingEnabled)
                        {
                            this.Monitor.Log($"No chest at {(int)this.ChestCoords.X},{(int)this.ChestCoords.Y}, you should place a chest there, or set bypassInventory to \'false\'.", LogLevel.Trace);
                        }

                        if (farmer.couldInventoryAcceptThisItem(obj))
                        {
                            farmer.addItemToInventory(obj);
                            wasAdded = true;

                            if (this.LoggingEnabled)
                            {
                                this.Monitor.Log("Was able to add item to inventory. (No chest found, bypassInventory set to 'true')", LogLevel.Trace);
                            }
                        }
                        else
                        {
                            this.InventoryAndChestFull = true;

                            if (this.LoggingEnabled)
                            {
                                this.Monitor.Log("Was NOT able to add item to inventory or a chest.  (No chest found, bypassInventory set to 'true')", LogLevel.Trace);
                            }
                        }
                    }
                    else
                    {
                        this.InventoryAndChestFull = true;

                        if (this.LoggingEnabled)
                        {
                            this.Monitor.Log("Was NOT able to add item to inventory or a chest.  (No chest found, bypassInventory set to 'false')", LogLevel.Trace);
                        }
                    }
                }
            }

            return(wasAdded);
        }