Иконка ресурса

FREE QuickSmelt : 1.2.2 1.2.2

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;

using UnityEngine;

using Random = UnityEngine.Random;

namespace Oxide.Plugins
{
    [Info("QuickSmelt", "Wulf/lukespragg", "1.2.2", ResourceId = 1067)]
    [Description("Increases the speed of the furnace smelting")]

    class QuickSmelt : RustPlugin
    {
        // Do NOT edit this file, instead edit AFK.json in oxide/config

        #region Configuration

        float chancePerConsumption;
        float charcoalChanceModifier;
        float charcoalProductionModifier;
        bool dontOvercookMeat;
        float productionModifier;
        bool usePermissions;

        protected override void LoadDefaultConfig()
        {
            // Default is *roughly* x2 production rate
            Config["ChancePerConsumption"] = chancePerConsumption = GetConfig("ChancePerConsumption", 0.5f);
            Config["CharcoalChanceModifier"] = charcoalChanceModifier = GetConfig("CharcoalChanceModifier", 1.5f);
            Config["CharcoalProductionModifier"] = charcoalProductionModifier = GetConfig("CharcoalProductionModifier", 1f);
            Config["DontOvercookMeat"] = dontOvercookMeat = GetConfig("DontOvercookMeat", true);
            Config["ProductionModifier"] = productionModifier = GetConfig("ProductionModifier", 1f);
            Config["UsePermissions"] = usePermissions = GetConfig("UsePermissions", false);
            SaveConfig();
        }

        #endregion

        #region Initialization

        const string permQuickSmelt = "quicksmelt.allowed";

        void Init()
        {
            #if !RUST
            throw new NotSupportedException("This plugin does not support this game");
            #endif

            LoadDefaultConfig();
            permission.RegisterPermission("quicksmelt.allowed", this);
        }

        #endregion

        void OnConsumeFuel(BaseOven oven, Item fuel, ItemModBurnable burnable)
        {
            if (oven == null) return;
            if (usePermissions && !HasPermission(oven.OwnerID.ToString(), permQuickSmelt)) return;

            PrintWarning("Permissions not enabled or has permission");

            var byproductChance = burnable.byproductChance * charcoalChanceModifier;
            if (oven.allowByproductCreation && burnable.byproductItem != null && Random.Range(0.0f, 1f) <= byproductChance)
            {
                var obj = ItemManager.Create(burnable.byproductItem, (int)Math.Round(burnable.byproductAmount * charcoalProductionModifier));
                if (!obj.MoveToContainer(oven.inventory)) obj.Drop(oven.inventory.dropPosition, oven.inventory.dropVelocity);
            }

            for (var i = 0; i < oven.inventorySlots; i++)
            {
                try
                {
                    var slotItem = oven.inventory.GetSlot(i);
                    if (slotItem == null || !slotItem.IsValid()) continue;

                    var cookable = slotItem.info.GetComponent<ItemModCookable>();
                    if (cookable == null) continue;

                    if (cookable.becomeOnCooked.category == ItemCategory.Food &&
                        slotItem.info.shortname.Trim().EndsWith(".cooked") && dontOvercookMeat) continue;

                    // The chance of consumption is going to result in a 1 or 0
                    var consumptionAmount = (int)Math.Ceiling(productionModifier * (Random.Range(0f, 1f) <= chancePerConsumption ? 1 : 0));

                    // Check how many are actually in the furnace, before we try removing too many
                    var inFurnaceAmount = slotItem.amount;
                    if (inFurnaceAmount < consumptionAmount) consumptionAmount = inFurnaceAmount;

                    // Set consumption to however many we can pull from this actual stack
                    consumptionAmount = TakeFromInventorySlot(oven.inventory, slotItem.info.itemid, consumptionAmount, i);

                    // If we took nothing, then...we can't create any
                    if (consumptionAmount <= 0) continue;

                    // Create the item(s) that are now smelted
                    var smeltedItem = ItemManager.Create(cookable.becomeOnCooked, cookable.amountOfBecome * consumptionAmount);
                    if (!smeltedItem.MoveToContainer(oven.inventory)) smeltedItem.Drop(oven.inventory.dropPosition, oven.inventory.dropVelocity);
                }
                catch (InvalidOperationException) {}
            }
        }

        static int TakeFromInventorySlot(ItemContainer container, int itemId, int amount, int slot)
        {
            var item = container.GetSlot(slot);
            if (item.info.itemid != itemId) return 0;

            if (item.amount > amount)
            {
                item.MarkDirty();
                item.amount -= amount;
                return amount;
            }

            amount = item.amount;
            item.RemoveFromContainer();
            return amount;
        }

        #region Helpers

        T GetConfig<T>(string name, T value) => Config[name] == null ? value : (T)Convert.ChangeType(Config[name], typeof(T));

        bool HasPermission(string userId, string perm) => permission.UserHasPermission(userId, perm);

        #endregion
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху