Beispiel #1
0
        private static void AddItemFromNearbyChests(Fermenter __instance)
        {
            if (!Configuration.Current.Fermenter.autoFuel || __instance.GetStatus() != Fermenter.Status.Empty || !__instance.m_nview.IsOwner())
            {
                return;
            }

            Stopwatch delta = GameObjectAssistant.GetStopwatch(__instance.gameObject);

            if (!delta.IsRunning || delta.ElapsedMilliseconds > 1000)
            {
                List <Container> nearbyChests = InventoryAssistant.GetNearbyChests(__instance.gameObject, Configuration.Current.Fermenter.autoRange, !Configuration.Current.Fermenter.ignorePrivateAreaCheck);
                foreach (Container c in nearbyChests)
                {
                    ItemDrop.ItemData item = __instance.FindCookableItem(c.GetInventory());
                    if (item != null)
                    {
                        if (InventoryAssistant.RemoveItemFromChest(c, item) == 0)
                        {
                            continue;
                        }

                        __instance.m_nview.InvokeRPC("AddItem", new object[] { item.m_dropPrefab.name });
                        ZLog.Log("Added " + item.m_shared.m_name + " to " + __instance.m_name);
                        break;
                    }
                }
                delta.Restart();
            }
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        private static bool ReplaceInventoryRefByChest(ref Inventory inventory, ItemDrop.ItemData item, Fireplace fireplace)
        {
            if (inventory.HaveItem(item.m_shared.m_name))
            {
                return(true);                                          // original code
            }
            Stopwatch delta          = GameObjectAssistant.GetStopwatch(fireplace.gameObject);
            int       lookupInterval = Helper.Clamp(Configuration.Current.CraftFromChest.lookupInterval, 1, 10) * 1000;

            if (!delta.IsRunning || delta.ElapsedMilliseconds > lookupInterval)
            {
                nearbyChests = InventoryAssistant.GetNearbyChests(fireplace.gameObject, Helper.Clamp(Configuration.Current.CraftFromChest.range, 1, 50), !Configuration.Current.CraftFromChest.ignorePrivateAreaCheck);
                delta.Restart();
            }

            foreach (Container c in nearbyChests)
            {
                if (c.GetInventory().HaveItem(item.m_shared.m_name))
                {
                    inventory = c.GetInventory();
                    return(true);
                }
            }

            return(false);
        }
Beispiel #4
0
            private static void AddFuelFromNearbyChests(Fireplace __instance)
            {
                int toMaxFuel = (int)__instance.m_maxFuel - (int)Math.Ceiling(__instance.m_nview.GetZDO().GetFloat("fuel"));

                if (toMaxFuel > 0)
                {
                    Stopwatch delta = GameObjectAssistant.GetStopwatch(__instance.gameObject);

                    if (delta.IsRunning && delta.ElapsedMilliseconds < 1000)
                    {
                        return;
                    }
                    delta.Restart();

                    ItemDrop.ItemData fuelItemData = __instance.m_fuelItem.m_itemData;

                    int addedFuel = InventoryAssistant.RemoveItemInAmountFromAllNearbyChests(__instance.gameObject, Helper.Clamp(Configuration.Current.FireSource.autoRange, 1, 50), fuelItemData, toMaxFuel, !Configuration.Current.FireSource.ignorePrivateAreaCheck);
                    for (int i = 0; i < addedFuel; i++)
                    {
                        __instance.m_nview.InvokeRPC("AddFuel", new object[] { });
                    }
                    if (addedFuel > 0)
                    {
                        ZLog.Log("Added " + addedFuel + " fuel(" + fuelItemData.m_shared.m_name + ") in " + __instance.m_name);
                    }
                }
            }
        private static ItemDrop.ItemData PullCookableItemFromNearbyChests(CookingStation station)
        {
            if (station.GetFreeSlot() == -1)
            {
                return(null);
            }

            Stopwatch delta = GameObjectAssistant.GetStopwatch(station.gameObject);

            int lookupInterval = Helper.Clamp(Configuration.Current.CraftFromChest.lookupInterval, 1, 10) * 1000;

            if (!delta.IsRunning || delta.ElapsedMilliseconds > lookupInterval)
            {
                nearbyChests = InventoryAssistant.GetNearbyChests(station.gameObject, Helper.Clamp(Configuration.Current.CraftFromChest.range, 1, 50), !Configuration.Current.CraftFromChest.ignorePrivateAreaCheck);
                delta.Restart();
            }

            foreach (CookingStation.ItemConversion itemConversion in station.m_conversion)
            {
                ItemDrop.ItemData itemData = itemConversion.m_from.m_itemData;

                foreach (Container c in nearbyChests)
                {
                    if (c.GetInventory().HaveItem(itemData.m_shared.m_name))
                    {
                        // Remove one item from chest
                        InventoryAssistant.RemoveItemFromChest(c, itemData);
                        // Instantiate cookabled GameObject
                        GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemConversion.m_from.gameObject.name);

                        ZNetView.m_forceDisableInit = true;
                        GameObject cookabledItem = UnityEngine.Object.Instantiate <GameObject>(itemPrefab);
                        ZNetView.m_forceDisableInit = false;

                        return(cookabledItem.GetComponent <ItemDrop>().m_itemData);
                    }
                }
            }
            return(null);
        }
        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);
        }
Beispiel #7
0
        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;
                            }
                        }
                    }
                }
            }
        }