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); }