예제 #1
0
        /// <param name="unloading">Specify true if the plugin is unloading.</param>
        public void Destroy(bool destroyOutputContainer, bool unloading = false)
        {
            resetDespawnTimer.DestroyToPool();

            foreach (var player in NearbyPlayers)
            {
                OnPlayerLeave(player);
            }

            if (!unloading)
            {
                // Drop queue items
                if (CraftingTasks.Count > 0)
                {
                    var container = new ItemContainer();
                    container.ServerInitialize(null, 36);

                    foreach (var task in CraftingTasks)
                    {
                        foreach (var ingredient in task.Blueprint.ingredients)
                        {
                            var item = ItemManager.CreateByItemID(ingredient.itemid, (int)ingredient.amount * task.Amount);

                            if (!item.MoveToContainer(container))
                            {
                                item.Drop(Position + Recycler.transform.up * 1.25f, Recycler.GetDropVelocity(), Recycler.ServerRotation);
                            }
                        }
                    }

                    var droppedContainer = container.Drop(Constants.ItemDropPrefab, Position + Recycler.transform.up * 1.25f, Recycler.ServerRotation);
                    droppedContainer.playerName = Lang.Translate(null, "queue-items");
                }
            }

            Recycler.Kill();
            CodeLock?.Kill();

            if (!outputContainer.IsDestroyed)
            {
                // Remove rock from output container that keeps it from despawning when emptied
                outputInventory.GetSlot(outputInventory.capacity - 1).Remove();

                // Force kill output bag if there's nothing in it.
                if (!destroyOutputContainer && OutputInventory.AnyItems())
                {
                    // Enable physics on output container
                    outputContainer.GetComponent <Rigidbody>().isKinematic = false;
                }
                else
                {
                    outputContainer.Kill();
                }
            }
        }
예제 #2
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);
                        }
                    }
                }
            }
        }