Ejemplo n.º 1
0
        private static bool DropItemToNearbyChest(Fermenter __instance, ref Fermenter.ItemConversion itemConversion)
        {
            List <Container> nearbyChests = InventoryAssistant.GetNearbyChests(__instance.gameObject, Configuration.Current.Fermenter.autoRange, !Configuration.Current.Fermenter.ignorePrivateAreaCheck);

            int spawnedInChests = 0;

            for (int i = 0; i < itemConversion.m_producedItems; i++)
            {
                GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemConversion.m_to.gameObject.name);

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

                ItemDrop comp = itemObject.GetComponent <ItemDrop>();

                bool result = spawnNearbyChest(comp, true);
                Object.Destroy(itemObject);
                if (!result)
                {
                    itemConversion.m_producedItems -= spawnedInChests;

                    return(false);
                }
                spawnedInChests++;
            }

            return(true);

            bool spawnNearbyChest(ItemDrop item, bool mustHaveItem)
            {
                foreach (Container chest in nearbyChests)
                {
                    Inventory cInventory = chest.GetInventory();
                    if (mustHaveItem && !cInventory.HaveItem(item.m_itemData.m_shared.m_name))
                    {
                        continue;
                    }

                    if (!cInventory.AddItem(item.m_itemData))
                    {
                        //Chest full, move to the next
                        continue;
                    }

                    InventoryAssistant.ConveyContainerToNetwork(chest);

                    return(true);
                }

                if (mustHaveItem)
                {
                    return(spawnNearbyChest(item, false));
                }

                return(false);
            }
        }
Ejemplo n.º 2
0
        private static bool Prefix(string ore, int stack, ref Smelter __instance)
        {
            Smelter smelter = __instance; // allowing access to local function

            if (!smelter.m_nview.IsOwner())
            {
                return(true);
            }

            if (__instance.m_name.Equals(SmelterDefinitions.KilnName) && Configuration.Current.Kiln.IsEnabled && Configuration.Current.Kiln.autoDeposit)
            {
                return(spawn(Helper.Clamp(Configuration.Current.Kiln.autoRange, 1, 50), Configuration.Current.Kiln.ignorePrivateAreaCheck));
            }
            if (__instance.m_name.Equals(SmelterDefinitions.SmelterName) && Configuration.Current.Smelter.IsEnabled && Configuration.Current.Smelter.autoDeposit)
            {
                return(spawn(Helper.Clamp(Configuration.Current.Smelter.autoRange, 1, 50), Configuration.Current.Smelter.ignorePrivateAreaCheck));
            }
            if (__instance.m_name.Equals(SmelterDefinitions.FurnaceName) && Configuration.Current.Furnace.IsEnabled && Configuration.Current.Furnace.autoDeposit)
            {
                return(spawn(Helper.Clamp(Configuration.Current.Furnace.autoRange, 1, 50), Configuration.Current.Furnace.ignorePrivateAreaCheck));
            }
            if (__instance.m_name.Equals(SmelterDefinitions.WindmillName) && Configuration.Current.Windmill.IsEnabled && Configuration.Current.Windmill.autoDeposit)
            {
                return(spawn(Helper.Clamp(Configuration.Current.Windmill.autoRange, 1, 50), Configuration.Current.Windmill.ignorePrivateAreaCheck));
            }
            if (__instance.m_name.Equals(SmelterDefinitions.SpinningWheelName) && Configuration.Current.SpinningWheel.IsEnabled && Configuration.Current.SpinningWheel.autoDeposit)
            {
                return(spawn(Helper.Clamp(Configuration.Current.SpinningWheel.autoRange, 1, 50), Configuration.Current.Windmill.ignorePrivateAreaCheck));
            }
            bool spawn(float autoDepositRange, bool ignorePrivateAreaCheck)
            {
                List <Container> nearbyChests = InventoryAssistant.GetNearbyChests(smelter.gameObject, autoDepositRange, !ignorePrivateAreaCheck);

                if (nearbyChests.Count == 0)
                {
                    return(true);
                }

                if (autoDepositRange > 50)
                {
                    autoDepositRange = 50;
                }
                else if (autoDepositRange < 1)
                {
                    autoDepositRange = 1;
                }

                // Replicating original code, just "spawning/adding" the item inside the chest makes it "not have a prefab"
                GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(smelter.GetItemConversion(ore).m_to.gameObject.name);

                // Also replication of original code, really have no idead what it is for, didn't bother look
                ZNetView.m_forceDisableInit = true;
                GameObject spawnedOre = Object.Instantiate <GameObject>(itemPrefab);

                ZNetView.m_forceDisableInit = false;

                // assign stack size, nobody wants a 0/20 stack of metals (its not very usefull)
                ItemDrop comp = spawnedOre.GetComponent <ItemDrop>();

                comp.m_itemData.m_stack = stack;

                bool result = spawnNearbyChest(true);

                Object.Destroy(spawnedOre);

                bool spawnNearbyChest(bool mustHaveItem)
                {
                    foreach (Container chest in nearbyChests)
                    {
                        Inventory cInventory = chest.GetInventory();
                        if (mustHaveItem && !cInventory.HaveItem(comp.m_itemData.m_shared.m_name))
                        {
                            continue;
                        }

                        bool added = cInventory.AddItem(comp.m_itemData);
                        if (!added)
                        {
                            // Chest full, move to the next
                            continue;
                        }

                        smelter.m_produceEffects.Create(smelter.transform.position, smelter.transform.rotation, null, 1f);
                        InventoryAssistant.ConveyContainerToNetwork(chest);
                        return(false);
                    }

                    if (mustHaveItem)
                    {
                        return(spawnNearbyChest(false));
                    }

                    return(true);
                }

                return(result);
            }

            return(true);
        }
Ejemplo n.º 3
0
        private static bool Prefix(long caller, ref Beehive __instance)
        {
            // Allows for access for linq
            Beehive beehive = __instance; // allowing access to local function

            if (!Configuration.Current.Beehive.autoDeposit || !Configuration.Current.Beehive.IsEnabled || !beehive.m_nview.IsOwner())
            {
                return(true);
            }

            // if behive is empty
            if (beehive.GetHoneyLevel() <= 0)
            {
                return(true);
            }

            float autoDepositRange = Helper.Clamp(Configuration.Current.Beehive.autoDepositRange, 1, 50);

            // find nearby chests
            List <Container> nearbyChests = InventoryAssistant.GetNearbyChests(beehive.gameObject, autoDepositRange);

            if (nearbyChests.Count == 0)
            {
                return(true);
            }

            while (beehive.GetHoneyLevel() > 0)
            {
                GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(__instance.m_honeyItem.gameObject.name);

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

                ItemDrop comp = honeyObject.GetComponent <ItemDrop>();

                bool result = spawnNearbyChest(comp, true);
                Object.Destroy(honeyObject);

                if (!result)
                {
                    // Couldn't drop in chest, letting original code handle things
                    return(true);
                }
            }

            if (beehive.GetHoneyLevel() == 0)
            {
                beehive.m_spawnEffect.Create(beehive.m_spawnPoint.position, Quaternion.identity);
            }

            bool spawnNearbyChest(ItemDrop item, bool mustHaveItem)
            {
                foreach (Container chest in nearbyChests)
                {
                    Inventory cInventory = chest.GetInventory();
                    if (mustHaveItem && !cInventory.HaveItem(item.m_itemData.m_shared.m_name))
                    {
                        continue;
                    }

                    if (!cInventory.AddItem(item.m_itemData))
                    {
                        //Chest full, move to the next
                        continue;
                    }
                    beehive.m_nview.GetZDO().Set("level", beehive.GetHoneyLevel() - 1);
                    InventoryAssistant.ConveyContainerToNetwork(chest);
                    return(true);
                }

                if (mustHaveItem)
                {
                    return(spawnNearbyChest(item, false));
                }

                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        private static void AutoDepositToChest(ref Beehive __instance)
        {
            Beehive beehive = __instance;

            List <Container> nearbyChests = InventoryAssistant.GetNearbyChests(beehive.gameObject, Helper.Clamp(Configuration.Current.Beehive.autoDepositRange, 1, 50));

            if (beehive.GetHoneyLevel() != beehive.m_maxHoney)
            {
                return;
            }

            while (beehive.GetHoneyLevel() > 0)
            {
                GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(beehive.m_honeyItem.gameObject.name);

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

                ItemDrop comp = honeyObject.GetComponent <ItemDrop>();

                bool result = spawnNearbyChest(comp, true);
                Object.Destroy(honeyObject);

                if (!result)
                {
                    // Couldn't drop in chest, letting original code handle things
                    return;
                }
            }

            if (beehive.GetHoneyLevel() == 0)
            {
                beehive.m_spawnEffect.Create(beehive.m_spawnPoint.position, Quaternion.identity);
            }

            bool spawnNearbyChest(ItemDrop item, bool mustHaveItem)
            {
                foreach (Container chest in nearbyChests)
                {
                    Inventory cInventory = chest.GetInventory();
                    if (mustHaveItem && !cInventory.HaveItem(item.m_itemData.m_shared.m_name))
                    {
                        continue;
                    }

                    if (!cInventory.AddItem(item.m_itemData))
                    {
                        //Chest full, move to the next
                        continue;
                    }
                    beehive.m_nview.GetZDO().Set("level", beehive.GetHoneyLevel() - 1);
                    InventoryAssistant.ConveyContainerToNetwork(chest);
                    return(true);
                }

                if (mustHaveItem)
                {
                    return(spawnNearbyChest(item, false));
                }

                return(false);
            }
        }