Exemplo n.º 1
0
        /// <summary>
        /// Cancels the given craft task. Returns true if the task was found and cancelled.
        /// </summary>
        /// <param name="refundTo">The refunded items will be added to this players inventory.</param>
        public bool CancelTask(CraftTask task, BasePlayer refundTo)
        {
            CraftingTasks.Remove(task);

            foreach (var player in NearbyPlayers)
            {
                SendRemoveCraftingTask(player, task);
            }

            foreach (var item in task.TakenItems)
            {
                if (!item.MoveToContainer(refundTo.inventory.containerMain) && !item.MoveToContainer(refundTo.inventory.containerBelt))
                {
                    item.Drop(refundTo.GetDropPosition(), refundTo.GetDropVelocity(), Quaternion.identity);
                }
            }

            // Stop recycler if crafting queue is empty.
            if (CraftingTasks.Count <= 0)
            {
                Recycler.StopRecycling();
            }

            return(true);
        }
Exemplo n.º 2
0
        private void SendCraftingTaskProgress(BasePlayer player, CraftTask task)
        {
            var lookup  = GetTaskLookupDict(player);
            var taskUID = lookup[task];

            player.Command("note.craft_done", taskUID, 0, task.Amount);
        }
Exemplo n.º 3
0
        private void SendRemoveCraftingTask(BasePlayer player, CraftTask task)
        {
            var lookup  = GetTaskLookupDict(player);
            int taskUID = lookup[task];

            player.Command("note.craft_done", taskUID, 0);
            lookup.Remove(task);
        }
Exemplo n.º 4
0
        private void SendUpdateCraftingTask(BasePlayer player, CraftTask task)
        {
            var   lookup  = GetTaskLookupDict(player);
            int   taskUID = lookup[task];
            float time    = task.Blueprint.time - task.Elapsed;

            if (!Recycler.IsOn())
            {
                time = (float)Math.Ceiling(time) - 0.01f;
            }

            player.Command("note.craft_start", taskUID, time, task.Amount);
        }
Exemplo n.º 5
0
        private void SendAddCraftingTask(BasePlayer player, CraftTask task)
        {
            var crafting = player.inventory.crafting;

            crafting.taskUID++;

            // The reason for always sending 2 as amount is because if a craft task is started with 1 item, the amount counter won't show in clientside, even if amount is incremented later.
            // The real amount will be sent straight after, but then it will show with the counter, even if there's only 1.
            player.Command("note.craft_add", crafting.taskUID, task.Blueprint.targetItem.itemid, 2, task.SkinID);

            // Correct the craft amount.
            player.Command("note.craft_done", crafting.taskUID, 0, task.Amount);

            var dict = GetTaskLookupDict(player);

            dict.Add(task, crafting.taskUID);
        }
Exemplo n.º 6
0
        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);
        }