public CraftTask AddCraftTask(ItemBlueprint blueprint, int amount, int skinId = 0, bool startRecycler = true, List <Item> takenItems = null) { bool wasEmpty = CraftingTasks.Count == 0; // Merge with current craft queue if the item is in queue with matching skin. var craftTask = CraftingTasks.FirstOrDefault(task => task.Blueprint.targetItem.itemid == blueprint.targetItem.itemid && task.SkinID == skinId); if (craftTask != null) { craftTask.Amount += amount; // Send new amount to all players foreach (var player in NearbyPlayers) { SendCraftingTaskProgress(player, craftTask); } return(craftTask); } else { craftTask = new CraftTask(blueprint, amount, skinId); CraftingTasks.Add(craftTask); } if (takenItems != null) { craftTask.TakenItems.AddRange(takenItems); } foreach (var player in NearbyPlayers) { SendAddCraftingTask(player, craftTask); } // Turn on recycler if the queue was empty before. if (startRecycler && !Recycler.IsOn() && wasEmpty) { Recycler.StartRecycling(); } return(craftTask); }
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); }