void OnConsumeFuel(BaseOven oven, Item fuel, ItemModBurnable burnable)
        {
            /* Lantern */
            if ((bool) Config["lantern"])
            {
                if (oven.temperature == BaseOven.TemperatureType.Warming)
                {
                    ++fuel.amount;
                }
            }

            /* Campfire */
            if ((bool) Config["campfire"])
            {
                if (oven.temperature == BaseOven.TemperatureType.Cooking)
                {
                    ++fuel.amount;
                }
            }

            /* Furnace */
            if ((bool) Config["furnace"])
            {
                if (oven.temperature == BaseOven.TemperatureType.Smelting)
                {
                    ++fuel.amount;
                }
            }
        }
 private void OnConsumeFuel(BaseOven oven, Item item, ItemModBurnable burnable)
 {
     SmeltItems(oven);
 }
Beispiel #3
0
        private void OnConsumeFuel(BaseOven oven, Item fuel, ItemModBurnable burnable)
        {
            var byproductChance = burnable.byproductChance * CharcoalChanceModifier;

            if (oven.allowByproductCreation && burnable.byproductItem != null && Random.Range(0.0f, 1f) <= byproductChance)
            {
                Item 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 (int 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;
                    }

                    // Some simple math here.
                    // The chance of consumption is going to result in a 1 or 0.
                    // Anything * 0 == 0
                    // Which basically means... don't smelt anything yet.
                    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)
                {
                    // Eat this. Modified collection. Blah blah.
                }
            }
        }
Beispiel #4
0
 public static string OvenId(BaseOven oven)
 {
     var position = oven.transform.position;
     return String.Format("X{0}Y{1}Z{2}", position.x, position.y, position.z);
 }
Beispiel #5
0
 void Awake()
 {
     entity = GetComponent <BaseEntity>();
     oven   = GetComponent <BaseOven>();
 }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        public string Hook_MoveSplitItem(Item item, BaseOven oven, int totalSlots)
        {
            MoveResult result = MoveSplitItem(item, oven, totalSlots);

            return(result.ToString());
        }
Beispiel #8
0
        // Check for carpet lantern fuel
        void OnConsumeFuel(BaseOven oven, Item fuel, ItemModBurnable burnable)
        {
            // Only work on lanterns
            if (oven.ShortPrefabName != "lantern.deployed")
            {
                return;
            }
            int dbl = doublefuel ? 4 : 2;

            BaseEntity lantern = oven as BaseEntity;
            // Only work on lanterns attached to a Carpet
            var activecarpet = lantern.GetComponentInParent <CarpetEntity>() ?? null;

            if (activecarpet == null)
            {
                return;
            }
#if DEBUG
            Puts("OnConsumeFuel: found a carpet lantern!");
#endif
            if (activecarpet.needfuel)
            {
#if DEBUG
                Puts("OnConsumeFuel: carpet requires fuel!");
#endif
            }
            else
            {
#if DEBUG
                Puts("OnConsumeFuel: carpet does not require fuel!");
#endif
                fuel.amount++; // Required to keep it from decrementing
                return;
            }
            BasePlayer player = activecarpet.GetComponent <BaseMountable>().GetMounted() as BasePlayer;
            if (!player)
            {
                return;
            }
#if DEBUG
            Puts("OnConsumeFuel: checking fuel level...");
#endif
            // Before it drops to 1 (3 for doublefuel) AFTER this hook call is complete, warn them that the fuel is low (1) - ikr
            if (fuel.amount == dbl)
            {
#if DEBUG
                Puts("OnConsumeFuel: sending low fuel warning...");
#endif
                if (playemptysound)
                {
                    Effect.server.Run("assets/bundled/prefabs/fx/well/pump_down.prefab", player.transform.position);
                }
                PrintMsgL(player, "lowfuel");
            }

            if (doublefuel)
            {
                fuel.amount--;
            }

            if (fuel.amount == 0)
            {
#if DEBUG
                Puts("OnConsumeFuel: out of fuel.");
#endif
                PrintMsgL(player, "lowfuel");
                var ison = activecarpet.engineon;
                if (ison)
                {
                    activecarpet.islanding = true;
                    activecarpet.engineon  = false;
                    PrintMsgL(player, "landingcarpet");
                    OnOvenToggle(oven, player);
                    return;
                }
            }
        }
Beispiel #9
0
 private void Awake()
 {
     oven = GetComponent <BaseOven>();
     SearchForCupboard();
     InvokeRepeating(() => { FuelStillRemains(); }, 5f, 5f);
 }
        private bool CanCook(ItemModCookable cookable, BaseOven oven)
        {
            float workTemperature = Extensions.GetWorkTemperature(oven);

            return(workTemperature >= cookable.lowTemp && workTemperature <= cookable.highTemp);
        }
            public static float GetWorkTemperature(BaseOven oven)
            {
                var property = oven.GetType().GetProperty("cookingTemperature", BindingFlags.Instance | BindingFlags.NonPublic);

                return((float)property.GetValue(oven, null));
            }
    public override void OnItemCreated(Item itemcreated)
    {
        float cooktimeLeft = this.cookTime;

        itemcreated.onCycle += (Action <Item, float>)((item, delta) =>
        {
            float temperature = item.temperature;
            if ((double)temperature < (double)this.lowTemp || (double)temperature > (double)this.highTemp || (double)cooktimeLeft < 0.0)
            {
                if (!this.setCookingFlag || !item.HasFlag(Item.Flag.Cooking))
                {
                    return;
                }
                item.SetFlag(Item.Flag.Cooking, false);
                item.MarkDirty();
            }
            else
            {
                if (this.setCookingFlag && !item.HasFlag(Item.Flag.Cooking))
                {
                    item.SetFlag(Item.Flag.Cooking, true);
                    item.MarkDirty();
                }
                cooktimeLeft -= delta;
                if ((double)cooktimeLeft > 0.0)
                {
                    return;
                }
                int position = item.position;
                if (item.amount > 1)
                {
                    cooktimeLeft = this.cookTime;
                    --item.amount;
                    item.MarkDirty();
                }
                else
                {
                    item.Remove(0.0f);
                }
                if (!Object.op_Inequality((Object)this.becomeOnCooked, (Object)null))
                {
                    return;
                }
                Item obj = ItemManager.Create(this.becomeOnCooked, this.amountOfBecome, 0UL);
                if (obj == null || obj.MoveToContainer(item.parent, position, true) || obj.MoveToContainer(item.parent, -1, true))
                {
                    return;
                }
                obj.Drop(item.parent.dropPosition, item.parent.dropVelocity, (Quaternion)null);
                if (!Object.op_Implicit((Object)item.parent.entityOwner))
                {
                    return;
                }
                BaseOven component = (BaseOven)((Component)item.parent.entityOwner).GetComponent <BaseOven>();
                if (!Object.op_Inequality((Object)component, (Object)null))
                {
                    return;
                }
                component.OvenFull();
            }
        });
    }
Beispiel #13
0
 public static void On_ConsumeFuel(BaseOven bo, Item fuel, ItemModBurnable burn)
 {
     OnNext("On_ConsumeFuel", new ConsumeFuelEvent(bo, fuel, burn));
 }
Beispiel #14
0
        private MoveResult MoveSplitItem(Item item, BaseOven oven, int totalSlots)
        {
            var container         = oven.inventory;
            int invalidItemsCount = container.itemList.Count(slotItem => !IsSlotCompatible(slotItem, oven, item.info));
            int numOreSlots       = Math.Min(container.capacity - invalidItemsCount, totalSlots);
            int totalMoved        = 0;
            int totalAmount       = Math.Min(item.amount + container.itemList.Where(slotItem => slotItem.info == item.info).Take(numOreSlots).Sum(slotItem => slotItem.amount), item.info.stackable * numOreSlots);

            if (numOreSlots <= 0)
            {
                return(MoveResult.NotEnoughSlots);
            }

            //Puts("---------------------------");

            int totalStackSize = Math.Min(totalAmount / numOreSlots, item.info.stackable);
            int remaining      = totalAmount - totalAmount / numOreSlots * numOreSlots;

            List <int> addedSlots = new List <int>();

            //Puts("total: {0}, remaining: {1}, totalStackSize: {2}", totalAmount, remaining, totalStackSize);

            List <OvenSlot> ovenSlots = new List <OvenSlot>();

            for (int i = 0; i < numOreSlots; ++i)
            {
                Item existingItem;
                var  slot = FindMatchingSlotIndex(container, out existingItem, item.info, addedSlots);

                if (slot == -1) // full
                {
                    return(MoveResult.NotEnoughSlots);
                }

                addedSlots.Add(slot);

                var ovenSlot = new OvenSlot
                {
                    Position = existingItem?.position,
                    Index    = slot,
                    Item     = existingItem
                };

                int currentAmount = existingItem?.amount ?? 0;
                int missingAmount = totalStackSize - currentAmount + (i < remaining ? 1 : 0);
                ovenSlot.DeltaAmount = missingAmount;

                //Puts("[{0}] current: {1}, delta: {2}, total: {3}", slot, currentAmount, ovenSlot.DeltaAmount, currentAmount + missingAmount);

                if (currentAmount + missingAmount <= 0)
                {
                    continue;
                }

                ovenSlots.Add(ovenSlot);
            }

            foreach (var slot in ovenSlots)
            {
                if (slot.Item == null)
                {
                    var newItem = ItemManager.Create(item.info, slot.DeltaAmount, item.skin);
                    slot.Item = newItem;
                    newItem.MoveToContainer(container, slot.Position ?? slot.Index);
                }
                else
                {
                    slot.Item.amount += slot.DeltaAmount;
                }

                totalMoved += slot.DeltaAmount;
            }

            container.MarkDirty();

            if (totalMoved >= item.amount)
            {
                item.Remove();
                item.GetRootContainer()?.MarkDirty();
                return(MoveResult.Ok);
            }
            else
            {
                item.amount -= totalMoved;
                item.GetRootContainer()?.MarkDirty();
                return(MoveResult.SlotsFilled);
            }
        }
Beispiel #15
0
 private object OnOvenToggle(BaseOven oven, BasePlayer player) => IsLimited(player) ? false : (object)null;
Beispiel #16
0
 private bool CanCook(ItemModCookable cookable, BaseOven oven)
 {
     return(BaseOven.cookingTemperature >= cookable.lowTemp && BaseOven.cookingTemperature <= cookable.highTemp);
 }
Beispiel #17
0
        void OnConsumeFuel(BaseOven oven, Item fuel, ItemModBurnable burnable)
        {
            // Check if furnace is usable
            if (!expertModeEnabled || oven == null || oven is BaseFuelLightSource)
            {
                return;
            }

            // Check if permissions are enabled and player has permission
            if (usePermissions && !permission.UserHasPermission(oven.OwnerID.ToString(), permAllow))
            {
                return;
            }

            // Modify the amount of fuel to use
            fuel.amount -= fuelUsageModifier - 1;

            // Modify the amount of byproduct to produce
            burnable.byproductAmount = 1 * (int)byproductModifier;
            burnable.byproductChance = (100 - byproductPercent) / 100f;

            // Loop through furance inventory slots
            for (var i = 0; i < oven.inventorySlots; i++)
            {
                try
                {
                    // Check for and ignore invalid items
                    var slotItem = oven.inventory.GetSlot(i);
                    if (slotItem == null || !slotItem.IsValid())
                    {
                        continue;
                    }

                    // Check for and ignore non-cookables
                    var cookable = slotItem.info.GetComponent <ItemModCookable>();
                    if (cookable == null)
                    {
                        continue;
                    }

                    // Skip already cooked food items
                    if (slotItem.info.shortname.EndsWith(".cooked"))
                    {
                        continue;
                    }

                    // The chance of consumption is going to result in a 1 or 0
                    var consumptionAmount = (int)Math.Ceiling(cookedModifier * (UnityEngine.Random.Range(0f, 1f) <= cookedPercent ? 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 cooked
                    var cookedItem = ItemManager.Create(cookable.becomeOnCooked, cookable.amountOfBecome * consumptionAmount);
                    if (!cookedItem.MoveToContainer(oven.inventory))
                    {
                        cookedItem.Drop(oven.inventory.dropPosition, oven.inventory.dropVelocity);
                    }
                }
                catch (InvalidOperationException) { }
            }
        }
 public ConsumeFuelEvent(BaseOven bo, Item fuel, ItemModBurnable burn)
 {
     _baseOven = bo;
     _item     = new InvItem(fuel);
     _burn     = burn;
 }
Beispiel #19
0
 private bool HasFuel(BaseOven oven)
 {
     return(oven.inventory.itemList.Any(item => item.info == oven.fuelType));
 }
Beispiel #20
0
        public JObject Hook_GetOvenInfo(BaseOven oven)
        {
            OvenInfo ovenInfo = GetOvenInfo(oven);

            return(JObject.FromObject(ovenInfo));
        }
Beispiel #21
0
 private Item GetFuel(BuildingPrivlidge priv, BaseOven oven)
 {
     return(priv.inventory?.itemList?.FirstOrDefault(item => item.info == oven.fuelType));
 }
Beispiel #22
0
 private void OnConsumeFuel(BaseOven oven, Item fuel, ItemModBurnable burnable)
 {
     HookCalled("OnConsumeFuel");
     // TODO: Print fuel consumed
 }
Beispiel #23
0
 private void OnOvenToggle(BaseOven oven, BasePlayer player)
 {
     HookCalled("OnOvenToggle");
 }
Beispiel #24
0
 public ConsumeFuelEvent(BaseOven bo, Item fuel, ItemModBurnable burn)
 {
     _baseOven = bo;
     _item = new InvItem(fuel);
     _burn = burn;
 }
Beispiel #25
0
 public static void ConsumeFuel(BaseOven bo, Item fuel, ItemModBurnable burn)
 {
     OnConsumeFuel.OnNext(new ConsumeFuelEvent(bo, fuel, burn));
 }
Beispiel #26
0
        void OnConsumeFuel(BaseOven oven, Item fuel, ItemModBurnable burnable)
        {
            if (oven == null)
            {
                return;
            }
            // TODO: Add options for campfire and/or furnace
            if (usePermissions && !permission.UserHasPermission(oven.OwnerID.ToString(), permAllow))
            {
                return;
            }

            fuel.amount -= fuelUsageModifier - 1;

            burnable.byproductAmount = 1 * (int)byproductModifier;      // TODO: Add check to prevent negative
            burnable.byproductChance = (100 - byproductPercent) / 100f; // TODO: Add check to set max of 100 and min of 0

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

                    // TODO: Add options for smelting and/or cooking
                    var cookable = slotItem.info.GetComponent <ItemModCookable>();
                    if (cookable == null)
                    {
                        continue;
                    }

                    if (slotItem.info.shortname.EndsWith(".cooked"))
                    {
                        continue;
                    }

                    var consumptionAmount = (int)Math.Ceiling(cookedModifier * (Random.Range(0f, 1f) <= cookedPercent ? 1 : 0)); // TODO: The logic here is odd
                    var inFurnaceAmount   = slotItem.amount;
                    if (inFurnaceAmount < consumptionAmount)
                    {
                        consumptionAmount = inFurnaceAmount;
                    }

                    consumptionAmount = TakeFromInventorySlot(oven.inventory, slotItem.info.itemid, consumptionAmount, i);

                    if (consumptionAmount <= 0)
                    {
                        continue;
                    }
                    var cookedItem = ItemManager.Create(cookable.becomeOnCooked, cookable.amountOfBecome * consumptionAmount);
                    if (!cookedItem.MoveToContainer(oven.inventory))
                    {
                        cookedItem.Drop(oven.inventory.dropPosition, oven.inventory.dropVelocity);
                    }
                }
                catch (InvalidOperationException) { }
            }
        }
Beispiel #27
0
        private void OnConsumeFuel(BaseOven oven, Item fuel, ItemModBurnable burnable)
        {
            var byproductChance = burnable.byproductChance * CharcoalChanceModifier;

            if (oven.allowByproductCreation && burnable.byproductItem != null && Random.Range(0.0f, 1f) <= byproductChance)
            {
                Item 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 (int 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;
                    }

                    // Some simple math here.
                    // The chance of consumption is going to result in a 1 or 0.
                    // Anything * 0 == 0
                    // Which basically means... don't smelt anything yet.
                    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)
                {
                    // Eat this. Modified collection. Blah blah.
                }
            }
        }
Beispiel #28
0
 public void OnConsumeFuel(BaseOven oven, Item fuel, ItemModBurnable burnable)
 {
     var instanceId = RPGHelper.OvenId(oven);
     if (!PlayersFurnaces.ContainsKey(instanceId))
         return;
     var steamId = Convert.ToUInt64(PlayersFurnaces[instanceId]);
     var player = BasePlayer.FindByID(steamId) ?? BasePlayer.FindSleeping(steamId);
     var rpgInfo = player == null ? RPGInfo(PlayersFurnaces[instanceId]) : RPGInfo(player);
     if (rpgInfo == null)
         return;
     if (!rpgInfo.Skills.ContainsKey(HRK.Blacksmith))
         return;
     var skillPoints = rpgInfo.Skills[HRK.Blacksmith];
     double random = Random(0, 1);
     float skillChance = (float)skillPoints/7;
     float maybeGiveAmount = (float)skillPoints/2;
     int amountToGive = (int) Math.Ceiling(maybeGiveAmount);
     if (random > skillChance)
         return;
     var itemList = oven.inventory.itemList;
     var itensCanMelt = (from item in itemList let itemModCookable = item.info.GetComponent<ItemModCookable>() where itemModCookable != null select item).ToList();
     foreach (var item in itensCanMelt)
     {
         var itemModCookable = item.info.GetComponent<ItemModCookable>();
         oven.inventory.Take(null, item.info.itemid, amountToGive);
         var itemToGive = ItemManager.Create(itemModCookable.becomeOnCooked, amountToGive);
         if (!itemToGive.MoveToContainer(oven.inventory))
             itemToGive.Drop(oven.inventory.dropPosition, oven.inventory.dropVelocity);
     }
 }
 void StopCooking(BaseOven oven)
 {
     var data = oven.transform.GetOrAddComponent<FurnaceData>();
     oven.CancelInvoke(data.CookOverride);
     oven.StopCooking();
 }
Beispiel #30
0
        void OnItemAddedToContainer(ItemContainer container, Item item)
        {
            if (item.info.shortname != "metal.ore" && item.info.shortname != "sulfur.ore" && item.info.shortname != "hq.metal.ore")
            {
                return;
            }

            if (container.itemList.Count() > 1)
            {
                return;
            }

            int cap = container.capacity;

            if (cap != 6 && cap != 18)
            {
                return;
            }

            if (item.amount < cap)
            {
                return;
            }

            int oresize, woodsize, outputsize;

            if (cap == 6)
            {
                oresize    = Cfg.furnaceHQMetalOres;
                woodsize   = Cfg.furnaceHQMetalWood;
                outputsize = Cfg.furnaceHQMetalOutput;
                if (item.info.shortname == "metal.ore")
                {
                    oresize    = Cfg.furnaceMetalOres;
                    woodsize   = Cfg.furnaceMetalWood;
                    outputsize = Cfg.furnaceMetalOutput;
                }
                else if (item.info.shortname == "sulfur.ore")
                {
                    oresize    = Cfg.furnaceSulfurOres;
                    woodsize   = Cfg.furnaceSulfurWood;
                    outputsize = Cfg.furnaceSulfurOutput;
                }
            }
            else
            {
                oresize    = Cfg.largeFurnaceHQMetalOres;
                woodsize   = Cfg.largeFurnaceHQMetalWood;
                outputsize = Cfg.largeFurnaceHQMetalOutput;
                if (item.info.shortname == "metal.ore")
                {
                    oresize    = Cfg.largeFurnaceMetalOres;
                    woodsize   = Cfg.largeFurnaceMetalWood;
                    outputsize = Cfg.largeFurnaceMetalOutput;
                }
                else if (item.info.shortname == "sulfur.ore")
                {
                    oresize    = Cfg.largeFurnaceSulfurOres;
                    woodsize   = Cfg.largeFurnaceSulfurWood;
                    outputsize = Cfg.largeFurnaceSulfurOutput;
                }
            }
            double woodfactor = Cfg.cooktime_hqmetal / Cfg.burntime_wood;
            string outputname = "metal.refined";

            if (item.info.shortname == "metal.ore")
            {
                woodfactor = Cfg.cooktime_metal / Cfg.burntime_wood;
                outputname = "metal.fragments";
            }
            else if (item.info.shortname == "sulfur.ore")
            {
                woodfactor = Cfg.cooktime_sulfur / Cfg.burntime_wood;
                outputname = "sulfur";
            }

            if (oresize + woodsize + outputsize > cap)
            {
                return;
            }

            BaseOven furnace = null;

            foreach (BaseOven key in furnaceCache.Keys)
            {
                if (key.inventory == container)
                {
                    furnace = key;
                    break;
                }
            }
            if (!furnace)
            {
                return;
            }

            BasePlayer player;

            if (!furnaceCache.TryGetValue(furnace, out player) || !player)
            {
                return;
            }

            int orecount = 0;

            Item[] items = player.inventory.AllItems();
            foreach (Item itm in items)
            {
                if (itm.info.shortname == item.info.shortname)
                {
                    orecount += itm.amount;
                }
            }
            orecount += item.amount;
            if (orecount > oresize * GetStackSize(outputname))
            {
                orecount = oresize * GetStackSize(outputname);
            }


            ItemDefinition wooddefinition = ItemManager.FindItemDefinition("wood");
            int            woodToRetain   = (int)(Math.Ceiling((double)orecount / oresize) * woodfactor);
            //Puts(woodToRetain.ToString());
            int woodMaxStack = GetStackSize(wooddefinition);

            if (woodToRetain > woodMaxStack * woodsize)
            {
                woodToRetain = woodMaxStack * woodsize;
            }
            //Puts(woodToRetain.ToString());

            int retainedWood = RemoveItemsFromInventory(player, wooddefinition, woodToRetain);

            if (retainedWood < woodsize)
            {
                GivePlayerItems(player, wooddefinition, retainedWood);
                return;
            }

            if (woodToRetain > retainedWood)
            {
                orecount = (int)(Math.Floor(retainedWood / woodfactor) * oresize);
                int oldretained = retainedWood;
                retainedWood = (int)(orecount / oresize * woodfactor);
                GivePlayerItems(player, wooddefinition, oldretained - retainedWood);
            }

            int retainedAmount;

            retainedAmount = RemoveItemsFromInventory(player, outputname, outputsize);
            if (retainedAmount < outputsize)
            {
                GivePlayerItems(player, wooddefinition, retainedWood);
                return;
            }

            item.MoveToContainer(player.inventory.containerMain, -1, false);

            int extraWood = retainedWood % woodsize;
            //Puts(extraWood.ToString());
            int perstack = (int)Math.Floor((double)retainedWood / woodsize);

            //Puts(perstack.ToString());
            for (int i = 0; i < woodsize; i++)
            {
                ItemManager.Create(wooddefinition, perstack + (extraWood > 0 ? 1 : 0)).MoveToContainer(container, -1, false);
                extraWood--;
            }

            for (int i = 0; i < outputsize; i++)
            {
                ItemManager.Create(ItemManager.FindItemDefinition(outputname), 1).MoveToContainer(container, -1, false);
            }

            RemoveItemsFromInventory(player, item.info.shortname, orecount);

            int amountPerStack = orecount / oresize;

            Item[] oresToAdd = new Item[oresize];
            int    extras    = orecount % oresize;

            for (int i = 0; i < oresize; i++)
            {
                int tmpCnt = 0;
                if (extras > 0)
                {
                    tmpCnt++;
                }
                tmpCnt += amountPerStack;
                extras--;
                oresToAdd[i] = ItemManager.Create(ItemManager.FindItemDefinition(item.info.shortname), tmpCnt);
            }

            foreach (Item oreToAdd in oresToAdd)
            {
                oreToAdd.MoveToContainer(container, -1, false);
            }

            furnace.Invoke("StartCooking", 0);
        }
Beispiel #31
0
 /// <summary>
 /// Called from <c>BaseOven.ConsumeFuel(Item, ItemModBurnable)</c> .
 /// </summary>
 public static void On_ConsumeFuel(BaseOven bo, Item fuel, ItemModBurnable burn) => OnNext("On_ConsumeFuel", new ConsumeFuelEvent(bo, fuel, burn));
Beispiel #32
0
        private CuiElementContainer CreateUi(BasePlayer player, BaseOven oven, OvenInfo ovenInfo)
        {
            var    options    = allPlayerOptions[player.userID];
            int    totalSlots = GetTotalStacksOption(player, oven) ?? oven.inventory.capacity - (oven.allowByproductCreation ? 1 : 2);
            string remainingTimeStr;
            string neededFuelStr;

            if (ovenInfo.ETA <= 0)
            {
                remainingTimeStr = "0s";
                neededFuelStr    = "0";
            }
            else
            {
                remainingTimeStr = FormatTime(ovenInfo.ETA);
                neededFuelStr    = ovenInfo.FuelNeeded.ToString("##,###");
            }

            string contentColor      = "0.7 0.7 0.7 1.0";
            int    contentSize       = 10;
            string toggleStateStr    = (!options.Enabled).ToString();
            string toggleButtonColor = !options.Enabled
                                        ? "0.415 0.5 0.258 0.4"
                                        : "0.8 0.254 0.254 0.4";
            string toggleButtonTextColor = !options.Enabled
                                            ? "0.607 0.705 0.431"
                                            : "0.705 0.607 0.431";
            string buttonColor     = "0.75 0.75 0.75 0.1";
            string buttonTextColor = "0.77 0.68 0.68 1";

            int nextDecrementSlot = totalSlots - 1;
            int nextIncrementSlot = totalSlots + 1;

            DestroyUI(player);

            Vector2 uiPosition = config.UiPosition;
            Vector2 uiSize     = new Vector2(0.1785f, 0.111f);

            var result        = new CuiElementContainer();
            var rootPanelName = result.Add(new CuiPanel
            {
                Image = new CuiImageComponent
                {
                    Color = "0 0 0 0"
                },
                RectTransform =
                {
                    AnchorMin = uiPosition.x + " " + uiPosition.y,
                    AnchorMax = uiPosition.x + uiSize.x + " " + (uiPosition.y + uiSize.y)
                                //AnchorMin = "0.6505 0.022",
                                //AnchorMax = "0.829 0.133"
                }
            }, "Hud.Menu");

            var headerPanel = result.Add(new CuiPanel
            {
                Image = new CuiImageComponent
                {
                    Color = "0.75 0.75 0.75 0.1"
                },
                RectTransform =
                {
                    AnchorMin = "0 0.775",
                    AnchorMax = "1 1"
                }
            }, rootPanelName);

            // Header label
            result.Add(new CuiLabel
            {
                RectTransform =
                {
                    AnchorMin = "0.051 0",
                    AnchorMax = "1 0.95"
                },
                Text =
                {
                    Text     = lang.GetMessage("title", this, player.UserIDString),
                    Align    = TextAnchor.MiddleLeft,
                    Color    = "0.77 0.7 0.7 1",
                    FontSize = 13
                }
            }, headerPanel);

            var contentPanel = result.Add(new CuiPanel
            {
                Image = new CuiImageComponent
                {
                    Color = "0.65 0.65 0.65 0.06"
                },
                RectTransform =
                {
                    AnchorMin = "0 0",
                    AnchorMax = "1 0.74"
                }
            }, rootPanelName);

            // ETA label
            result.Add(new CuiLabel
            {
                RectTransform =
                {
                    AnchorMin = "0.02 0.7",
                    AnchorMax = "0.98 1"
                },
                Text =
                {
                    Text     = string.Format("{0}: " + (ovenInfo.ETA > 0 ? "~" : "") + remainingTimeStr + " (" + neededFuelStr + " " + oven.fuelType.displayName.english.ToLower() + ")", lang.GetMessage("eta", this, player.UserIDString)),
                    Align    = TextAnchor.MiddleLeft,
                    Color    = contentColor,
                    FontSize = contentSize
                }
            }, contentPanel);

            // Toggle button
            result.Add(new CuiButton
            {
                RectTransform =
                {
                    AnchorMin = "0.02 0.4",
                    AnchorMax = "0.25 0.7"
                },
                Button =
                {
                    Command = "furnacesplitter.enabled " + toggleStateStr,
                    Color   = toggleButtonColor
                },
                Text =
                {
                    Align    = TextAnchor.MiddleCenter,
                    Text     = options.Enabled ? lang.GetMessage("turnoff", this, player.UserIDString) : lang.GetMessage("turnon", this, player.UserIDString),
                    Color    = toggleButtonTextColor,
                    FontSize = 11
                }
            }, contentPanel);

            // Trim button
            result.Add(new CuiButton
            {
                RectTransform =
                {
                    AnchorMin = "0.27 0.4",
                    AnchorMax = "0.52 0.7"
                },
                Button =
                {
                    Command = "furnacesplitter.trim",
                    Color   = buttonColor
                },
                Text =
                {
                    Align    = TextAnchor.MiddleCenter,
                    Text     = lang.GetMessage("trim", this, player.UserIDString),
                    Color    = contentColor,
                    FontSize = 11
                }
            }, contentPanel);

            // Decrease stack button
            result.Add(new CuiButton
            {
                RectTransform =
                {
                    AnchorMin = "0.02 0.05",
                    AnchorMax = "0.07 0.35"
                },
                Button =
                {
                    Command = "furnacesplitter.totalstacks " + nextDecrementSlot,
                    Color   = buttonColor
                },
                Text =
                {
                    Align    = TextAnchor.MiddleCenter,
                    Text     = "<",
                    Color    = buttonTextColor,
                    FontSize = contentSize
                }
            }, contentPanel);

            // Empty slots label
            result.Add(new CuiLabel
            {
                RectTransform =
                {
                    AnchorMin = "0.08 0.05",
                    AnchorMax = "0.19 0.35"
                },
                Text =
                {
                    Align    = TextAnchor.MiddleCenter,
                    Text     = totalSlots.ToString(),
                    Color    = contentColor,
                    FontSize = contentSize
                }
            }, contentPanel);

            // Increase stack button
            result.Add(new CuiButton
            {
                RectTransform =
                {
                    AnchorMin = "0.19 0.05",
                    AnchorMax = "0.25 0.35"
                },
                Button =
                {
                    Command = "furnacesplitter.totalstacks " + nextIncrementSlot,
                    Color   = buttonColor
                },
                Text =
                {
                    Align    = TextAnchor.MiddleCenter,
                    Text     = ">",
                    Color    = buttonTextColor,
                    FontSize = contentSize
                }
            }, contentPanel);

            // Stack itemType label
            result.Add(new CuiLabel
            {
                RectTransform =
                {
                    AnchorMin = "0.27 0.05",
                    AnchorMax = "1 0.35"
                },
                Text =
                {
                    Align    = TextAnchor.MiddleLeft,
                    Text     = string.Format("({0})", lang.GetMessage("totalstacks", this, player.UserIDString)),
                    Color    = contentColor,
                    FontSize = contentSize
                }
            }, contentPanel);

            openUis.Add(player.userID, rootPanelName);
            CuiHelper.AddUi(player, result);
            return(result);
        }
Beispiel #33
0
 private void OnConsumeFuel(BaseOven oven, Item fuel, ItemModBurnable burnable)
 {
     HookCalled("OnConsumeFuel");
     // TODO: Print fuel consumed
 }
Beispiel #34
0
        // This is how we take off or land the carpet!
        object OnOvenToggle(BaseOven oven, BasePlayer player)
        {
            bool rtrn = false; // Must match other plugins with this call to avoid conflicts. QuickSmelt uses false

            CarpetEntity activecarpet;

            try
            {
                activecarpet = player.GetMounted().GetComponentInParent <CarpetEntity>() ?? null;
                if (activecarpet == null)
                {
                    oven.StopCooking();
                    return(rtrn);
                }
            }
            catch
            {
                return(null);
            }

            if (activecarpet.carpetlock != null && activecarpet.carpetlock.IsLocked())
            {
                PrintMsgL(player, "carpetlocked"); return(rtrn);
            }
            if (!player.isMounted)
            {
                return(rtrn);                  // player offline, does not mean ismounted on carpet
            }
            if (player.GetMounted() != activecarpet.entity)
            {
                return(rtrn);                                           // online player not in seat on carpet
            }
#if DEBUG
            Puts("OnOvenToggle: Player cycled lantern!");
#endif
            if (oven.IsOn())
            {
                oven.StopCooking();
            }
            else
            {
                oven.StartCooking();
            }
            if (!activecarpet.FuelCheck())
            {
                if (activecarpet.needfuel)
                {
                    PrintMsgL(player, "nofuel");
                    PrintMsgL(player, "landingcarpet");
                    activecarpet.engineon = false;
                }
            }
            var ison = activecarpet.engineon;
            if (ison)
            {
                activecarpet.islanding = true; PrintMsgL(player, "landingcarpet"); return(null);
            }
            if (!ison)
            {
                AddPlayerToPilotsList(player); activecarpet.engineon = true; return(null);
            }

            return(rtrn);
        }
Beispiel #35
0
        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) {}
            }
        }
Beispiel #36
0
 private void OnFuelConsume(BaseOven oven, Item fuel, ItemModBurnable burnable)
 {
     Interface.Oxide.CallDeprecatedHook("OnConsumeFuel", "OnFuelConsume(BaseOven oven, Item fuel, ItemModBurnable burnable)",
                                        new System.DateTime(2021, 7, 1), oven, fuel, burnable);
 }
Beispiel #37
0
 public ConsumeFuelEvent(BaseOven baseOven, Item fuel, ItemModBurnable burnable)
 {
     BaseOven = baseOven;
     Item = new InvItem(fuel);
     Burnable = burnable;
 }