Exemplo n.º 1
0
        public static string BeehiveGetHoverText_Patch(string __result, Beehive __instance)
        {
            string result = __result;

            if (!showAlternateText.Value)
            {
                return(result);
            }

            string statusToReplace = $"\n[<color=yellow><b>$KEY_Use</b></color>] $piece_beehive_check";
            string honeyString     = LocaliseString(__instance.m_honeyItem.m_itemData.m_shared.m_name);
            string EMPTY           = LocaliseString($"( $piece_container_empty )");
            string honeyCount      = LocaliseString($"\n{honeyString} ( {__instance.GetHoneyLevel()} / {__instance.m_maxHoney} )");
            string hasHoney        = LocaliseString($"( {honeyString} x {__instance.GetHoneyLevel()} )");

            if (beeStatus.Value)
            {
                string status;
                if (!__instance.CheckBiome())
                {
                    status = "<color=red>$piece_beehive_area</color>";
                }
                else if (!__instance.HaveFreeSpace())
                {
                    status = "<color=red>$piece_beehive_freespace</color>";
                }
                else if (!EnvMan.instance.IsDaylight() && !nightCheck.Value)
                {
                    status = "<color=yellow>$piece_beehive_sleep</color>";
                }
                else
                {
                    status = "<color=lime>$piece_beehive_happy</color>";
                }

                result = result.Replace(LocaliseString(statusToReplace), "");
                result = result.Replace(LocaliseString($"{__instance.m_name}"), LocaliseString($"{__instance.m_name}\n{LocaliseString(status)}"));
            }

            if (result.Contains(EMPTY))
            {
                if (beeStatus.Value)
                {
                    return(result.Replace(EMPTY, honeyCount));
                }
                return(result.Replace(EMPTY, honeyCount));
            }

            if (result.Contains(hasHoney))
            {
                if (beeStatus.Value)
                {
                    return(result.Replace(hasHoney, honeyCount));
                }
                return(result.Replace(hasHoney, honeyCount));
            }

            return(result);
        }
Exemplo n.º 2
0
        private static string calculateTimeLeft(Beehive BeehiveInstance)
        {
            string info = "";

            if (BeehiveInstance.GetHoneyLevel() == BeehiveInstance.m_maxHoney)
            {
                return(info);
            }

            float num = BeehiveInstance.m_nview.GetZDO().GetFloat("product");

            float durationUntilDone = BeehiveInstance.m_secPerUnit - num;
            int   minutes           = (int)durationUntilDone / 60;

            if (((int)durationUntilDone) >= 120)
            {
                info = minutes + " minutes";
            }
            else
            {
                info = (int)durationUntilDone + " seconds";
            }

            return(" (" + info + ")");
        }
Exemplo n.º 3
0
        private static bool Prefix(Beehive __instance, ref string __result)
        {
            if (!Configuration.Current.Beehive.IsEnabled || !Configuration.Current.Beehive.showDuration)
            {
                return(true);
            }

            if (!PrivateArea.CheckAccess(__instance.transform.position, 0f, false))
            {
                __result = Localization.instance.Localize(__instance.m_name + "\n$piece_noaccess");
                return(false);
            }
            int honeyLevel = __instance.GetHoneyLevel();

            if (honeyLevel > 0)
            {
                __result = Localization.instance.Localize(string.Concat(new object[]
                {
                    __instance.m_name,
                    " ( ",
                    __instance.m_honeyItem.m_itemData.m_shared.m_name,
                    " x ",
                    honeyLevel,
                    " ) " + calculateTimeLeft(__instance) + "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_beehive_extract"
                }));
                return(false);
            }
            __result = Localization.instance.Localize(__instance.m_name + " ( $piece_container_empty ) " + calculateTimeLeft(__instance) + "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_beehive_check");
            return(false);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
            }
        }