Exemplo n.º 1
0
 public void On_ConsumeFuel(ConsumeFuelEvent cfe)
 {
     SetHookWorking("On_ConsumeFuel");
     Broadcast(cfe.Item.Name + " consumed for fuel");
 }
Exemplo n.º 2
0
        public void On_ConsumeFuel(ConsumeFuelEvent cfe)
        {
            Server.Broadcast("Consumed");
            var oven            = cfe.BaseOven;
            var burnable        = cfe.Burnable;
            var byproductChance = burnable.byproductChance * CharcoalChance;

            if (oven.allowByproductCreation && burnable.byproductItem != null && UnityEngine.Random.Range(0.0f, 1f) <= byproductChance)
            {
                Item item = ItemManager.Create(burnable.byproductItem, burnable.byproductAmount);
                if (!item.MoveToContainer(oven.inventory))
                {
                    item.Drop(oven.inventory.dropPosition, oven.inventory.dropVelocity);
                }
            }

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

                    var isCookable = sItem.info.GetComponent <ItemModCookable>();
                    if (isCookable == null)
                    {
                        continue;
                    }

                    if (isCookable.becomeOnCooked.category == ItemCategory.Food && sItem.info.shortname.Trim().EndsWith("_cooked", StringComparison.Ordinal) && AllowBurntMeat)
                    {
                        continue;
                    }

                    var consumeAmt = (int)Math.Ceiling(ProductionMultiplier * (UnityEngine.Random.Range(0f, 1f) <= ConsumeChance ? 1 : 0));
                    var Amount     = sItem.amount;

                    if (Amount < consumeAmt)
                    {
                        consumeAmt = Amount;
                    }

                    consumeAmt = TakeFromInventorySlot(oven.inventory, sItem.info.itemid, consumeAmt, i);

                    if (consumeAmt <= 0)
                    {
                        continue;
                    }

                    var smeltItem = ItemManager.Create(isCookable.becomeOnCooked, isCookable.amountOfBecome * consumeAmt);
                    if (!smeltItem.MoveToContainer(oven.inventory))
                    {
                        smeltItem.Drop(oven.inventory.dropPosition, oven.inventory.dropVelocity);
                    }
                }
                catch (Exception e)
                {
                    Logger.LogException(e);
                }
            }
        }