private static int ComputeItemQuantity(int fromInventory, Piece.Requirement item, Player player) { Stopwatch delta; GameObject pos = player.GetCurrentCraftingStation()?.gameObject; if (!pos || !Configuration.Current.CraftFromChest.checkFromWorkbench) { pos = player.gameObject; delta = Inventory_NearbyChests_Cache.delta; } else { delta = GameObjectAssistant.GetStopwatch(pos); } int lookupInterval = Helper.Clamp(Configuration.Current.CraftFromChest.lookupInterval, 1, 10) * 1000; if (!delta.IsRunning || delta.ElapsedMilliseconds > lookupInterval) { Inventory_NearbyChests_Cache.chests = InventoryAssistant.GetNearbyChests(pos, Helper.Clamp(Configuration.Current.CraftFromChest.range, 1, 50), !Configuration.Current.CraftFromChest.ignorePrivateAreaCheck); delta.Restart(); } return(fromInventory + InventoryAssistant.GetItemAmountInItemList(InventoryAssistant.GetNearbyChestItemsByContainerList(Inventory_NearbyChests_Cache.chests), item.m_resItem.m_itemData)); }
private static bool Prefix(Transform elementRoot, Piece.Requirement req, Player player, bool craft, int quality, ref bool __result) { if (!Configuration.Current.Hud.IsEnabled && !Configuration.Current.CraftFromChest.IsEnabled || !Configuration.Current.Hud.showRequiredItems && !Configuration.Current.CraftFromChest.IsEnabled) { return(true); } Image component = elementRoot.transform.Find("res_icon").GetComponent <Image>(); Text component2 = elementRoot.transform.Find("res_name").GetComponent <Text>(); Text component3 = elementRoot.transform.Find("res_amount").GetComponent <Text>(); UITooltip component4 = elementRoot.GetComponent <UITooltip>(); if (req.m_resItem != null) { component.gameObject.SetActive(true); component2.gameObject.SetActive(true); component3.gameObject.SetActive(true); component.sprite = req.m_resItem.m_itemData.GetIcon(); component.color = Color.white; component4.m_text = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name); component2.text = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name); int num = player.GetInventory().CountItems(req.m_resItem.m_itemData.m_shared.m_name); int amount = req.GetAmount(quality); if (amount <= 0) { InventoryGui.HideRequirement(elementRoot); __result = false; return(false); } if (Configuration.Current.CraftFromChest.IsEnabled) { Stopwatch delta; GameObject pos = player.GetCurrentCraftingStation()?.gameObject; if (!pos || !Configuration.Current.CraftFromChest.checkFromWorkbench) { pos = player.gameObject; delta = Inventory_NearbyChests_Cache.delta; } else { delta = GameObjectAssistant.GetStopwatch(pos); } int lookupInterval = Helper.Clamp(Configuration.Current.CraftFromChest.lookupInterval, 1, 10) * 1000; if (!delta.IsRunning || delta.ElapsedMilliseconds > lookupInterval) { Inventory_NearbyChests_Cache.chests = InventoryAssistant.GetNearbyChests(pos, Helper.Clamp(Configuration.Current.CraftFromChest.range, 1, 50)); delta.Restart(); } num += InventoryAssistant.GetItemAmountInItemList(InventoryAssistant.GetNearbyChestItemsByContainerList(Inventory_NearbyChests_Cache.chests), req.m_resItem.m_itemData); } component3.text = num + "/" + amount.ToString(); if (num < amount) { component3.color = ((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : Color.white); } else { component3.color = Color.white; } component3.fontSize = 14; if (component3.text.Length > 5) { component3.fontSize -= component3.text.Length - 5; } } __result = true; return(false); }
static void Prefix(Smelter __instance) { if (__instance == null || !Player.m_localPlayer || __instance.m_nview == null || !__instance.m_nview.IsOwner()) { return; } Smelter smelter = __instance; Stopwatch delta = GameObjectAssistant.GetStopwatch(smelter.gameObject); if (delta.IsRunning && delta.ElapsedMilliseconds < 1000) { return; } delta.Restart(); float autoFuelRange = 0f; bool ignorePrivateAreaCheck = false; bool isKiln = false; if (smelter.m_name.Equals(SmelterDefinitions.KilnName)) { if (!Configuration.Current.Kiln.IsEnabled || !Configuration.Current.Kiln.autoFuel) { return; } isKiln = true; autoFuelRange = Configuration.Current.Kiln.autoRange; ignorePrivateAreaCheck = Configuration.Current.Kiln.ignorePrivateAreaCheck; } else if (smelter.m_name.Equals(SmelterDefinitions.SmelterName)) { if (!Configuration.Current.Smelter.IsEnabled || !Configuration.Current.Smelter.autoFuel) { return; } autoFuelRange = Configuration.Current.Smelter.autoRange; ignorePrivateAreaCheck = Configuration.Current.Smelter.ignorePrivateAreaCheck; } else if (smelter.m_name.Equals(SmelterDefinitions.FurnaceName)) { if (!Configuration.Current.Furnace.IsEnabled || !Configuration.Current.Furnace.autoFuel) { return; } autoFuelRange = Configuration.Current.Furnace.autoRange; ignorePrivateAreaCheck = Configuration.Current.Furnace.ignorePrivateAreaCheck; } else if (__instance.m_name.Equals(SmelterDefinitions.WindmillName)) { if (!Configuration.Current.Windmill.IsEnabled || !Configuration.Current.Windmill.autoFuel) { return; } autoFuelRange = Configuration.Current.Windmill.autoRange; ignorePrivateAreaCheck = Configuration.Current.Windmill.ignorePrivateAreaCheck; } else if (__instance.m_name.Equals(SmelterDefinitions.SpinningWheelName)) { if (!Configuration.Current.SpinningWheel.IsEnabled || !Configuration.Current.SpinningWheel.autoFuel) { return; } autoFuelRange = Configuration.Current.SpinningWheel.autoRange; ignorePrivateAreaCheck = Configuration.Current.SpinningWheel.ignorePrivateAreaCheck; } autoFuelRange = Helper.Clamp(autoFuelRange, 1, 50); int toMaxOre = smelter.m_maxOre - smelter.GetQueueSize(); int toMaxFuel = smelter.m_maxFuel - (int)System.Math.Ceiling(smelter.GetFuel()); if (smelter.m_fuelItem && toMaxFuel > 0) { ItemDrop.ItemData fuelItemData = smelter.m_fuelItem.m_itemData; // Check for fuel in nearby containers int addedFuel = InventoryAssistant.RemoveItemInAmountFromAllNearbyChests(smelter.gameObject, autoFuelRange, fuelItemData, toMaxFuel, !ignorePrivateAreaCheck); for (int i = 0; i < addedFuel; i++) { smelter.m_nview.InvokeRPC("AddFuel", new object[] { }); } if (addedFuel > 0) { ZLog.Log("Added " + addedFuel + " fuel(" + fuelItemData.m_shared.m_name + ") in " + smelter.m_name); } } if (toMaxOre > 0) { List <Container> nearbyChests = InventoryAssistant.GetNearbyChests(smelter.gameObject, autoFuelRange); foreach (Container c in nearbyChests) { foreach (Smelter.ItemConversion itemConversion in smelter.m_conversion) { if (isKiln) { if (Configuration.Current.Kiln.dontProcessFineWood && itemConversion.m_from.m_itemData.m_shared.m_name.Equals(WoodDefinitions.FineWoodName)) { continue; } if (Configuration.Current.Kiln.dontProcessRoundLog && itemConversion.m_from.m_itemData.m_shared.m_name.Equals(WoodDefinitions.RoundLogName)) { continue; } int threshold = Configuration.Current.Kiln.stopAutoFuelThreshold < 0 ? 0 : Configuration.Current.Kiln.stopAutoFuelThreshold; if (threshold > 0 && InventoryAssistant.GetItemAmountInItemList(InventoryAssistant.GetNearbyChestItemsByContainerList(nearbyChests), itemConversion.m_to.m_itemData) >= threshold) { return; } } ItemDrop.ItemData oreItem = itemConversion.m_from.m_itemData; int addedOres = InventoryAssistant.RemoveItemFromChest(c, oreItem, toMaxOre); if (addedOres > 0) { GameObject orePrefab = ObjectDB.instance.GetItemPrefab(itemConversion.m_from.gameObject.name); for (int i = 0; i < addedOres; i++) { smelter.m_nview.InvokeRPC("AddOre", new object[] { orePrefab.name }); } toMaxOre -= addedOres; if (addedOres > 0) { ZLog.Log("Added " + addedOres + " ores(" + oreItem.m_shared.m_name + ") in " + smelter.m_name); } if (toMaxOre == 0) { return; } } } } } }