Exemple #1
0
        private void ProcessQueue(float elapsed)
        {
            if (!Recycler.IsOn() || CraftingTasks.Count <= 0)
            {
                return;
            }

            var currentTask = CraftingTasks.FirstOrDefault();

            if (currentTask != null)
            {
                currentTask.Elapsed += elapsed;

                if (currentTask.Elapsed >= currentTask.Blueprint.time)
                {
                    ulong workshopSkinId = Rust.Global.SteamServer.Inventory.FindDefinition(currentTask.SkinID)?.GetProperty <ulong>("workshopdownload") ?? 0;

                    if (workshopSkinId == 0)
                    {
                        workshopSkinId = (ulong)currentTask.SkinID;
                    }

                    var item = ItemManager.CreateByItemID(currentTask.Blueprint.targetItem.itemid, currentTask.Blueprint.amountToCreate, workshopSkinId);

                    if (!GiveItem(item))
                    {
                        item.Drop(Recycler.GetDropPosition(), Recycler.GetDropVelocity());
                        Recycler.StopRecycling();
                    }

                    currentTask.Amount  -= 1;
                    currentTask.Elapsed -= currentTask.Blueprint.time;

                    // Take used items
                    foreach (var ingredient in currentTask.Blueprint.ingredients)
                    {
                        foreach (var taskItem in currentTask.TakenItems)
                        {
                            if (taskItem.info.itemid != ingredient.itemid)
                            {
                                continue;
                            }

                            taskItem.amount -= (int)ingredient.amount;

                            if (taskItem.amount <= 0)
                            {
                                taskItem.Remove();
                                currentTask.TakenItems.Remove(taskItem);
                            }

                            break;
                        }
                    }

                    if (currentTask.Amount <= 0)
                    {
                        // Remove from ui
                        foreach (var player in NearbyPlayers)
                        {
                            SendRemoveCraftingTask(player, currentTask);
                        }

                        CraftingTasks.RemoveAt(0);

                        // Stop recycler if there's nothing more to craft.
                        if (CraftingTasks.Count <= 0)
                        {
                            Recycler.StopRecycling();
                        }
                    }
                    else
                    {
                        foreach (var player in NearbyPlayers)
                        {
                            SendCraftingTaskProgress(player, currentTask);
                        }
                    }
                }
            }
        }