示例#1
0
        private object OnRecycleItem(Recycler recycler, Item item)
        {
            bool flag      = false;
            int  usedItems = 1;

            if (item.amount > 1)
            {
                usedItems = item.amount;
            }
            if (usedItems > maxItemsPerRecycle)
            {
                usedItems = maxItemsPerRecycle;
            }

            item.UseItem(usedItems);
            foreach (ItemInfo ingredient in ingredientList[item.info.shortname])
            {
                double multi = 1;
                if (multiplyList.ContainsKey("*"))
                {
                    multi = Convert.ToDouble(multiplyList["*"]);
                }
                if (multiplyList.ContainsKey(ingredient.itemName))
                {
                    multi = Convert.ToDouble(multiplyList[ingredient.itemName]);
                }
                int outputamount = Convert.ToInt32(usedItems * Convert.ToDouble(ingredient.itemAmount) * multi);
                if (outputamount < 1)
                {
                    continue;
                }
                if (!recycler.MoveItemToOutput(ItemManager.CreateByName(ingredient.itemName, outputamount)))
                {
                    flag = true;
                }
            }
            if (flag || !recycler.HasRecyclable())
            {
                recycler.StopRecycling();
                for (int i = 5; i <= 11; i++)
                {
                    Item _item = recycler.inventory.GetSlot(i);
                    if (_item == null)
                    {
                        continue;
                    }
                    if (_item.IsValid())
                    {
                        if (outputBlacklistedItems.Contains(_item.info.shortname))
                        {
                            _item.Remove();
                            _item.RemoveFromContainer();
                        }
                    }
                }
            }
            return(true);
        }
示例#2
0
        private object OnRecycleItem(Recycler recycler, Item item)
        {
            var itemInfo = GetItemInfo(item.info.shortname);

            if (itemInfo == null || blacklistedItems.Contains(item.info.shortname))
            {
                item.Drop(recycler.transform.TransformPoint(new Vector3(-0.3f, 1.7f, 1f)), Vector3.up, new Quaternion());
                return(false);
            }

            bool flag = false;

            int usedItems = item.amount;

            if (!itemInfo.useGlobalMaxItemsPerRecycle)
            {
                if (usedItems > itemInfo.maxItemsPerRecycle)
                {
                    usedItems = itemInfo.maxItemsPerRecycle;
                }
            }
            else
            {
                if (usedItems > maxItemsPerRecycle)
                {
                    usedItems = maxItemsPerRecycle;
                }
            }

            item.UseItem(usedItems);
            foreach (var ingredient in itemInfo.ingredients)
            {
                double multi = 1;
                if (multiplyList.ContainsKey("*"))
                {
                    multi = Convert.ToDouble(multiplyList["*"]);
                }
                if (multiplyList.ContainsKey(ingredient.itemName))
                {
                    multi = Convert.ToDouble(multiplyList[ingredient.itemName]);
                }

                int outputamount = Convert.ToInt32(usedItems * Convert.ToDouble(ingredient.itemAmount) * multi);
                var output       = Interface.CallHook("OnRecycleItemOutput", ingredient.itemName, outputamount);
                if (output != null)
                {
                    outputamount = (int)output;
                }
                if (outputamount < 1)
                {
                    continue;
                }
                if (!recycler.MoveItemToOutput(ItemManager.CreateByName(ingredient.itemName, outputamount)))
                {
                    flag = true;
                }
            }
            if (flag || !recycler.HasRecyclable())
            {
                recycler.StopRecycling();
                for (int i = 5; i <= 11; i++)
                {
                    Item _item = recycler.inventory.GetSlot(i);
                    if (_item == null)
                    {
                        continue;
                    }
                    if (_item.IsValid())
                    {
                        if (outputBlacklistedItems.Contains(_item.info.shortname))
                        {
                            _item.Remove();
                            _item.RemoveFromContainer();
                        }
                    }
                }
            }
            return(true);
        }
示例#3
0
        private object OnRecycleItem(Recycler recycler, Item item)
        {
            var bp = ItemManager.FindItemDefinition(item.info.itemid).Blueprint;

            if (blacklistedItems.Contains(item.info.shortname) || bp == null || bp.ingredients?.Count == 0)
            {
                return(false);
            }

            int usedItems = 1;

            if (item.amount > 1)
            {
                usedItems = item.amount;
            }
            if (usedItems > maxItemsPerRecycle)
            {
                usedItems = maxItemsPerRecycle;
            }
            item.UseItem(usedItems);

            foreach (ItemAmount ingredient in bp.ingredients)
            {
                var    shortname = ingredient.itemDef.shortname;
                double multi     = 1;
                if (multiplyList.ContainsKey("*"))
                {
                    multi = Convert.ToDouble(multiplyList["*"]);
                }
                if (multiplyList.ContainsKey(shortname))
                {
                    multi = Convert.ToDouble(multiplyList[shortname]);
                }
                double outputamount = 0;

                if (ingredient.itemDef.itemid == scrapID)
                {
                    outputamount = Convert.ToDouble(usedItems * Convert.ToDouble(bp.scrapFromRecycle) * multi);
                }
                else
                {
                    outputamount = Convert.ToDouble(usedItems * Convert.ToDouble(ingredient.amount / (2 * bp.amountToCreate)) * multi);
                }

                // when the batch is returning less than 1 we'll give the chance to return it.
                // For large batches users will get back the percentage ie 25% pipes out of 10 HE grens ends up being 2 pipes every time, but 1 HE will give 25% chance
                if (outputamount < 1)
                {
                    var rnd = Oxide.Core.Random.Range(100);
                    if (rnd < outputamount * 100)
                    {
                        outputamount = 1;
                    }
                    else
                    {
                        continue;
                    }
                }

                if (!recycler.MoveItemToOutput(ItemManager.CreateByItemID(ingredient.itemDef.itemid, Convert.ToInt32(outputamount))))
                {
                    recycler.StopRecycling();
                }
            }
            if (!recycler.HasRecyclable())
            {
                recycler.StopRecycling();
            }
            return(true);
        }
示例#4
0
文件: Recycle.cs 项目: 5Dev24/Recycle
        private object CanAcceptItem(ItemContainer con, Item i, int target)
        {
            if (con.entityOwner is Recycler)
            {
                Recycler r = con.entityOwner as Recycler;
                if (this.IsRecycleBox(r))
                {
                    BasePlayer p = this.PlayerFromRecycler(r.net.ID);
                    if (p == null)
                    {
                        return(null);
                    }

                    if (target < 6)
                    {
                        if (!this.Data.Settings.RecyclableTypes.Contains(Enum.GetName(typeof(ItemCategory), i.info.category)) ||
                            this.Data.Settings.Blacklist.Contains(i.info.shortname))
                        {
                            if (p != null)
                            {
                                this.PrintToChat(p, this.GetMessage("Recycle", "Invalid", p));
                            }
                            return(ItemContainer.CanAcceptResult.CannotAcceptRightNow);
                        }
                        else
                        {
                            NextFrame(() => {
                                if (r == null || !r.HasRecyclable())
                                {
                                    return;
                                }

                                if (this.Data.Settings.InstantRecycling)
                                {
                                    if (!r.IsOn())
                                    {
                                        r.InvokeRepeating(new Action(r.RecycleThink), 0, 0);
                                        r.SetFlag(BaseEntity.Flags.On, true, false, true);
                                        r.SendNetworkUpdateImmediate();
                                    }
                                }
                                else
                                {
                                    r.StartRecycling();
                                }
                            });
                        }
                    }
                    else if (this.Data.Settings.ToInventory)
                    {
                        NextFrame(() => {
                            if (p == null || p.inventory == null || p.inventory.containerMain == null ||
                                p.inventory.containerBelt == null || i == null)
                            {
                                return;
                            }

                            bool flag = false;
                            if (!p.inventory.containerMain.IsFull())
                            {
                                flag = i.MoveToContainer(p.inventory.containerMain);
                            }
                            if (!flag && !p.inventory.containerBelt.IsFull())
                            {
                                i.MoveToContainer(p.inventory.containerBelt);
                            }
                        });
                    }
                }
            }
            return(null);
        }