private bool OnGather(Item item, BasePlayer player) { if (!player) { return(false); } if (!permission.UserHasPermission(player.UserIDString, permissionNameUSE)) { return(false); } ItemModCookable cookable = item.info.GetComponent <ItemModCookable>(); if (!cookable) { return(false); } if (itemBlacklist.Contains(item.info.shortname)) { return(false); } Item newItem = ItemManager.CreateByName(cookable.becomeOnCooked.shortname, cookable.amountOfBecome * item.amount); if (newItem == null) { return(false); } player.GiveItem(newItem, BaseEntity.GiveItemReason.ResourceHarvested); return(true); }
private Dictionary <ItemDefinition, float> GetSmeltTimes(BaseOven oven) { ItemContainer container = oven.inventory; var cookables = container.itemList.Where(item => { ItemModCookable cookable = item.info.GetComponent <ItemModCookable>(); return(cookable != null && CanCook(cookable, oven)); }).ToList(); if (cookables.Count == 0) { return(new Dictionary <ItemDefinition, float>()); } var distinctCookables = cookables.GroupBy(item => item.info, item => item).ToList(); Dictionary <ItemDefinition, int> amounts = new Dictionary <ItemDefinition, int>(); foreach (var group in distinctCookables) { int biggestAmount = group.Max(item => item.amount); amounts.Add(group.Key, biggestAmount); } var smeltTimes = amounts.ToDictionary(kv => kv.Key, kv => GetSmeltTime(kv.Key.GetComponent <ItemModCookable>(), kv.Value)); return(smeltTimes); }
private bool IsSlotCompatible(Item item, BaseOven oven, ItemDefinition itemDefinition) { ItemModCookable cookable = item.info.GetComponent <ItemModCookable>(); if (item.amount < item.info.stackable && item.info == itemDefinition) { return(true); } if (oven.allowByproductCreation && oven.fuelType.GetComponent <ItemModBurnable>().byproductItem == item.info) { return(true); } if (cookable == null || cookable.becomeOnCooked == itemDefinition) { return(true); } if (CanCook(cookable, oven)) { return(true); } return(false); }
double GetCooktime(ItemDefinition item) { foreach (ItemMod mod in item.itemMods) { if (!(mod is ItemModCookable)) { continue; } ItemModCookable cookable = mod as ItemModCookable; return(cookable.cookTime); } return(0D); }
private IEnumerable <Item> GetUselessItems(IEnumerable <Item> items, ItemContainer container) { BaseOven furnace = container.entityOwner?.GetComponent <BaseOven>(); List <Item> uselessItems = new List <Item>(); if (furnace != null) { foreach (Item item in items) { ItemModCookable cookable = item.info.GetComponent <ItemModCookable>(); if (cookable == null || cookable.lowTemp > furnace.cookingTemperature || cookable.highTemp < furnace.cookingTemperature) { uselessItems.Add(item); } } } return(uselessItems); }
Dictionary <string, object> amountOfBecomeDefaults() { var dp = new Dictionary <string, object>(); foreach (var itemDef in ItemManager.GetItemDefinitions()) { ItemModCookable component = itemDef.GetComponent <ItemModCookable>(); if (component) { if (!overcookMeat && (component.name.Contains("cooked") || component.name.Contains("burned"))) { continue; } if (!dp.ContainsKey(component.name.Replace(".item", ""))) { dp.Add(component.name.Replace(".item", ""), component.amountOfBecome); } } } return(dp); }
private float GetSmeltTime(ItemModCookable cookable, int amount) { float smeltTime = cookable.cookTime * amount; return(smeltTime); }
private bool CanCook(ItemModCookable cookable, BaseOven oven) { return(BaseOven.cookingTemperature >= cookable.lowTemp && BaseOven.cookingTemperature <= cookable.highTemp); }
private object CanMoveItem(Item item, PlayerInventory inventory, uint targetContainer, int targetSlot) { if (item == null || inventory == null) { return(null); } BasePlayer player = inventory.GetComponent <BasePlayer>(); if (player == null) { return(null); } ItemContainer container = inventory.FindContainer(targetContainer); ItemContainer originalContainer = item.GetRootContainer(); if (container == null || originalContainer == null) { return(null); } Func <object> splitFunc = () => { if (player == null || !HasPermission(player) || !GetEnabled(player)) { return(null); } PlayerOptions playerOptions = allPlayerOptions[player.userID]; if (container == null || originalContainer == null || container == item.GetRootContainer()) { return(null); } BaseOven oven = container.entityOwner as BaseOven; ItemModCookable cookable = item.info.GetComponent <ItemModCookable>(); if (oven == null || cookable == null) { return(null); } int totalSlots = 2 + (oven.allowByproductCreation ? 1 : 0); if (playerOptions.TotalStacks.ContainsKey(oven.ShortPrefabName)) { totalSlots = playerOptions.TotalStacks[oven.ShortPrefabName]; } if (cookable.lowTemp > oven.cookingTemperature || cookable.highTemp < oven.cookingTemperature) { return(null); } MoveSplitItem(item, oven, totalSlots); return(true); }; object returnValue = splitFunc(); if (HasPermission(player) && GetEnabled(player)) { BaseOven oven = container?.entityOwner as BaseOven ?? item.GetRootContainer().entityOwner as BaseOven; if (oven != null && compatibleOvens.Contains(oven.ShortPrefabName)) { if (returnValue is bool && (bool)returnValue) { AutoAddFuel(inventory, oven); } queuedUiUpdates.Push(oven); } } return(returnValue); }
void OnServerInitialized() { if (ovenMultipliers == null || ovenMultipliers.Count == 0) { Config["OvenMultipliers"] = ovenMultipliers = ovenDefaults(); SaveConfig(); } if (!overcookMeat) { foreach (var item in ItemManager.GetItemDefinitions()) { if (item.shortname.Contains(".cooked")) { var cookable = item.GetComponent <ItemModCookable>(); if (cookable != null) { if (cookInFurnaces) { cookable.highTemp = 800; } else { cookable.highTemp = 150; } } } } } if (cookInFurnaces) { foreach (var item in ItemManager.GetItemDefinitions()) { if (item.shortname.Contains("raw") || item.shortname.Contains("meat.boar") || item.shortname == ("bearmeat")) { var cookable = item.GetComponent <ItemModCookable>(); if (cookable != null) { cookable.lowTemp = 800; cookable.highTemp = 1200; } } } } foreach (var item in ItemManager.GetItemDefinitions()) { ItemModBurnable component = item.GetComponent <ItemModBurnable>(); if (component && component.name == "wood.item") { if (charcoalPercentLoss > 100) { charcoalPercentLoss = 100; } if (charcoalPercentLoss < 0) { charcoalPercentLoss = 0; } component.byproductChance = Convert.ToSingle(charcoalPercentLoss) / 100; if (woodFuelAmount < 0.1f) { woodFuelAmount = 0.1f; } component.fuelAmount = Convert.ToSingle(woodFuelAmount); if (charcoalMultiplier < 1) { charcoalMultiplier = 1; } component.byproductAmount = Convert.ToInt32(charcoalMultiplier); } } foreach (var itemDef in ItemManager.GetItemDefinitions()) { ItemModCookable component = itemDef.GetComponent <ItemModCookable>(); if (component) { if (cookTimes.ContainsKey(component.name.Replace(".item", ""))) { float time = Convert.ToSingle(cookTimes[component.name.Replace(".item", "")]); if (time < 0.1f) { time = 0.1f; } component.cookTime = time; } if (amountsOfBecome.ContainsKey(component.name.Replace(".item", ""))) { int amount = Convert.ToInt32(amountsOfBecome[component.name.Replace(".item", "")]); if (amount < 1) { amount = 1; } component.amountOfBecome = amount; } } } var baseOvens = Resources.FindObjectsOfTypeAll <BaseOven>().Where(c => c.isActiveAndEnabled).Cast <BaseEntity>().ToList(); foreach (var oven in baseOvens) { if (usePermissions && !permission.UserHasPermission(oven.OwnerID.ToString(), permAllow)) { continue; } if (oven.HasFlag(BaseEntity.Flags.On)) { object checkMultiplier; if (!ovenMultipliers.TryGetValue(oven.ShortPrefabName, out checkMultiplier)) { continue; } float ovenMultiplier = Convert.ToSingle(checkMultiplier); if (ovenMultiplier > 10f) { ovenMultiplier = 10f; } if (ovenMultiplier < 0.1f) { ovenMultiplier = 0.1f; } oven.CancelInvoke("Cook"); (oven as BaseOven).inventory.temperature = CookingTemperature((oven as BaseOven).temperature); (oven as BaseOven).UpdateAttachmentTemperature(); oven.InvokeRepeating("Cook", 0.5f / ovenMultiplier, 0.5f / ovenMultiplier); } } }
protected override void LoadDefaultConfig() { Config["UsePermissions"] = usePermissions = GetConfig("UsePermissions", false); Config["OvercookMeat"] = overcookMeat = GetConfig("OvercookMeat", false); Config["ExpertModeEnabled"] = expertModeEnabled = GetConfig("ExpertModeEnabled", false); if (expertModeEnabled) { Config["ByproductModifier"] = byproductModifier = GetConfig("ByproductModifier", 1f); Config["ByproductPercent"] = byproductPercent = GetConfig("ByproductPercent", 50); Config["FuelUsageModifier"] = fuelUsageModifier = GetConfig("FuelUsageModifier", 1); Config["CookedModifier"] = cookedModifier = GetConfig("CookedModifier", 1f); Config["CookedPercent"] = cookedPercent = GetConfig("CookedPercent", 100); Config.Remove("CookInFurnaces"); Config.Remove("OvenMultipliers"); Config.Remove("CookTimes"); Config.Remove("AmountsOfBecome"); Config.Remove("CharcoalPercentLoss"); Config.Remove("CharcoalMultiplier"); Config.Remove("WoodFuelAmount"); } else { Config["CookInFurnaces"] = cookInFurnaces = GetConfig("CookInFurnaces", false); Config["OvenMultipliers"] = ovenMultipliers = GetConfig("OvenMultipliers", new Dictionary <string, object>()); var baseOvens = Resources.FindObjectsOfTypeAll <BaseOven>().Where(c => !c.isActiveAndEnabled && !(c is BaseFuelLightSource)).Cast <BaseEntity>().ToList(); foreach (var oven in baseOvens) { if (!ovenMultipliers.ContainsKey(oven.ShortPrefabName)) { ovenMultipliers.Add(oven.ShortPrefabName, 1.0f); } } Config["CookTimes"] = cookTimes = GetConfig("CookTimes", new Dictionary <string, object>()); foreach (var itemDef in ItemManager.GetItemDefinitions()) { ItemModCookable component = itemDef.GetComponent <ItemModCookable>(); if (component) { if (!overcookMeat && (component.name.Contains("cooked") || component.name.Contains("burned"))) { continue; } if (!cookTimes.ContainsKey(component.name.Replace(".item", ""))) { cookTimes.Add(component.name.Replace(".item", ""), component.cookTime); } } } Config["AmountsOfBecome"] = amountsOfBecome = GetConfig("AmountsOfBecome", new Dictionary <string, object>()); foreach (var itemDef in ItemManager.GetItemDefinitions()) { ItemModCookable component = itemDef.GetComponent <ItemModCookable>(); if (component) { if (!overcookMeat && (component.name.Contains("cooked") || component.name.Contains("burned"))) { continue; } if (!amountsOfBecome.ContainsKey(component.name.Replace(".item", ""))) { amountsOfBecome.Add(component.name.Replace(".item", ""), component.amountOfBecome); } } } Config["CharcoalPercentLoss"] = charcoalPercentLoss = GetConfig("CharcoalPercentLoss", 25); Config["CharcoalMultiplier"] = charcoalMultiplier = GetConfig("CharcoalMultiplier", 1); Config["WoodFuelAmount"] = woodFuelAmount = GetConfig("WoodFuelAmount", 10.0f); Config.Remove("ByproductModifier"); Config.Remove("ByproductPercent"); Config.Remove("FuelUsageModifier"); Config.Remove("CookedModifier"); Config.Remove("CookedPercent"); if (!overcookMeat) { foreach (var amount in amountsOfBecome.ToList()) { if (amount.Key.Contains("cooked") || amount.Key.Contains("burned")) { amountsOfBecome.Remove(amount.Key); } } foreach (var amount in cookTimes.ToList()) { if (amount.Key.Contains("cooked") || amount.Key.Contains("burned")) { cookTimes.Remove(amount.Key); } } } } SaveConfig(); }
void OnServerInitialized() { if (expertModeEnabled) { // Reset fuel consumption and byproduct amount - fix for previous versions var wood = ItemManager.FindItemDefinition("wood"); var burnable = wood?.GetComponent <ItemModBurnable>(); if (burnable != null) { burnable.byproductAmount = 1; burnable.byproductChance = 0.5f; } // Check if meat should be overcooked if (overcookMeat) { return; } // Loop through item definitions var itemDefinitions = ItemManager.itemList; foreach (var item in itemDefinitions) { // Skip any item definitions other than cooked meat if (!item.shortname.Contains(".cooked")) { continue; } // Lower high temperature on item definition to prevent burning var cookable = item.GetComponent <ItemModCookable>(); if (cookable != null) { cookable.highTemp = 150; } } return; } if (!overcookMeat) { foreach (var item in ItemManager.GetItemDefinitions()) { if (item.shortname.Contains(".cooked")) { var cookable = item.GetComponent <ItemModCookable>(); if (cookable != null) { if (cookInFurnaces) { cookable.highTemp = 800; } else { cookable.highTemp = 150; } } } } } if (cookInFurnaces) { foreach (var item in ItemManager.GetItemDefinitions()) { if (item.shortname.Contains("raw") || item.shortname.Contains("meat.boar") || item.shortname == ("bearmeat")) { var cookable = item.GetComponent <ItemModCookable>(); if (cookable != null) { cookable.lowTemp = 800; cookable.highTemp = 1200; } } } } foreach (var item in ItemManager.GetItemDefinitions()) { ItemModBurnable component = item.GetComponent <ItemModBurnable>(); if (component && component.name == "wood.item") { if (charcoalPercentLoss > 100) { charcoalPercentLoss = 100; } if (charcoalPercentLoss < 0) { charcoalPercentLoss = 0; } component.byproductChance = Convert.ToSingle(charcoalPercentLoss) / 100; if (woodFuelAmount < 0.1f) { woodFuelAmount = 0.1f; } component.fuelAmount = Convert.ToSingle(woodFuelAmount); if (charcoalMultiplier < 1) { charcoalMultiplier = 1; } component.byproductAmount = Convert.ToInt32(charcoalMultiplier); } } foreach (var itemDef in ItemManager.GetItemDefinitions()) { ItemModCookable component = itemDef.GetComponent <ItemModCookable>(); if (component) { if (cookTimes.ContainsKey(component.name.Replace(".item", ""))) { float time = Convert.ToSingle(cookTimes[component.name.Replace(".item", "")]); if (time < 0.1f) { time = 0.1f; } component.cookTime = time; } if (amountsOfBecome.ContainsKey(component.name.Replace(".item", ""))) { int amount = Convert.ToInt32(amountsOfBecome[component.name.Replace(".item", "")]); if (amount < 1) { amount = 1; } component.amountOfBecome = amount; } } } var baseOvens = Resources.FindObjectsOfTypeAll <BaseOven>().Where(c => c.isActiveAndEnabled && !(c is BaseFuelLightSource)).Cast <BaseEntity>().ToList(); foreach (var oven in baseOvens) { if (usePermissions && !permission.UserHasPermission(oven.OwnerID.ToString(), permAllow)) { continue; } if (oven.HasFlag(BaseEntity.Flags.On)) { object checkMultiplier; if (!ovenMultipliers.TryGetValue(oven.ShortPrefabName, out checkMultiplier)) { continue; } float ovenMultiplier = Convert.ToSingle(checkMultiplier); if (ovenMultiplier > 10f) { ovenMultiplier = 10f; } if (ovenMultiplier < 0.1f) { ovenMultiplier = 0.1f; } InvokeHandler.CancelInvoke(oven.GetComponent <MonoBehaviour>(), new Action((oven as BaseOven).Cook)); (oven as BaseOven).inventory.temperature = CookingTemperature((oven as BaseOven).temperature); (oven as BaseOven).UpdateAttachmentTemperature(); InvokeHandler.InvokeRepeating(oven.GetComponent <MonoBehaviour>(), new Action((oven as BaseOven).Cook), 0.5f / ovenMultiplier, 0.5f / ovenMultiplier); } } }
private bool CanCook(ItemModCookable cookable, BaseOven oven) { float workTemperature = Extensions.GetWorkTemperature(oven); return(workTemperature >= cookable.lowTemp && workTemperature <= cookable.highTemp); }