Exemple #1
0
        private static void ServerDestroyInputItems(
            Recipe recipe,
            IItemsContainerProvider inputContainers,
            ushort countToCraft,
            bool isAdminMode)
        {
            var itemsService = Api.Server.Items;

            foreach (var inputItem in recipe.InputItems)
            {
                var countToDestroy = (ushort)(inputItem.Count * countToCraft);
                var inputItemType  = inputItem.ProtoItem;

                if (isAdminMode)
                {
                    // destroy only available count
                    var availableCount =
                        inputContainers.Sum(c => c.Items.Where(i => i.ProtoItem == inputItemType).Sum(i => i.Count));
                    if (availableCount == 0)
                    {
                        // nothing to destroy
                        continue;
                    }

                    if (countToDestroy > availableCount)
                    {
                        // limit count to destroy
                        countToDestroy = (ushort)availableCount;
                    }
                }

                itemsService.DestroyItemsOfType(
                    inputContainers,
                    inputItemType,
                    countToDestroy,
                    out _);
            }
        }
        private static void ServerDestroyInputItems(
            Recipe recipe,
            IItemsContainerProvider inputContainers,
            ushort countToCraft,
            bool isCreativeMode)
        {
            foreach (var inputItem in recipe.InputItems)
            {
                var countToDestroy = (ushort)(inputItem.Count * countToCraft);
                var inputItemProto = inputItem.ProtoItem;

                if (isCreativeMode)
                {
                    // destroy only available count
                    var availableCount = inputContainers.Sum(
                        c => c.Items.Where(i => ReferenceEquals(i.ProtoItem, inputItemProto))
                        .Sum(i => i.Count));
                    if (availableCount == 0)
                    {
                        // nothing to destroy
                        continue;
                    }

                    if (countToDestroy > availableCount)
                    {
                        // limit count to destroy
                        countToDestroy = (ushort)availableCount;
                    }
                }

                ServerDestroyItemsOfType(
                    inputContainers,
                    inputItemProto,
                    countToDestroy,
                    out _);
            }
        }