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 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(); } }
private static void Postfix(ref Minimap __instance) { if (Configuration.Current.Map.IsEnabled) { Minimap_AddPin_Patch.shareablePins = new List <Minimap.PinType>() { Minimap.PinType.Icon0, Minimap.PinType.Icon1, Minimap.PinType.Icon2, Minimap.PinType.Icon3, Minimap.PinType.Icon4 }; GameObject iconPanelOld = GameObjectAssistant.GetChildComponentByName <Transform>("IconPanel", __instance.m_largeRoot).gameObject; for (int i = 0; i < 5; i++) { GameObjectAssistant.GetChildComponentByName <Transform>("Icon" + i.ToString(), iconPanelOld).gameObject.SetActive(false); } GameObjectAssistant.GetChildComponentByName <Transform>("Bkg", iconPanelOld).gameObject.SetActive(false); iconPanelOld.SetActive(false); __instance.m_nameInput.gameObject.SetActive(false); if (mapPinBundle == null) { mapPinBundle = AssetBundle.LoadFromStream(EmbeddedAsset.LoadEmbeddedAsset("Assets.Bundles.map-pin-ui")); } GameObject pinEditorPanelParent = mapPinBundle.LoadAsset <GameObject>("MapPinEditor"); pinEditorPanel = GameObject.Instantiate(pinEditorPanelParent.transform.GetChild(0).gameObject); pinEditorPanel.transform.SetParent(__instance.m_largeRoot.transform, false); pinEditorPanel.SetActive(false); pinName = pinEditorPanel.GetComponentInChildren <InputField>(); if (pinName != null) { Debug.Log("Pin Name loaded properly"); } Minimap theInstance = __instance; GameObjectAssistant.GetChildComponentByName <Transform>("OK", pinEditorPanel).gameObject.GetComponent <Button>().onClick.AddListener(delegate { AddPin(ref theInstance); }); GameObjectAssistant.GetChildComponentByName <Transform>("Cancel", pinEditorPanel).gameObject.GetComponent <Button>().onClick.AddListener(delegate { Minimap.instance.m_wasFocused = false; pinEditorPanel.SetActive(false); }); iconSelected = pinEditorPanel.GetComponentInChildren <Dropdown>(); iconSelected.options.Clear(); int ind = 0; List <string> list = new List <string> { "Fire", "Home", "Hammer", "Circle", "Rune" }; foreach (string option in list) { iconSelected.options.Add(new Dropdown.OptionData(option, Minimap.instance.m_icons[ind].m_icon)); ind++; } if (iconSelected != null) { Debug.Log("Dropdown loaded properly"); } sharePin = pinEditorPanel.GetComponentInChildren <Toggle>(); if (sharePin != null) { Debug.Log("Share pin loaded properly"); } if (!Configuration.Current.Map.shareablePins || Configuration.Current.Map.shareAllPins) { sharePin.gameObject.SetActive(false); } } }
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); }
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 void Postfix(ref FejdStartup __instance) { // logo if (Configuration.Current.ValheimPlus.IsEnabled && Configuration.Current.ValheimPlus.mainMenuLogo) { GameObject logo = GameObject.Find("LOGO"); logo.GetComponent <Image>().sprite = VPlusMainMenu.VPlusLogoSprite; } // version text for bottom right of startup __instance.m_versionLabel.fontSize = 14; string gameVersion = Version.CombineVersion(global::Version.m_major, global::Version.m_minor, global::Version.m_patch); __instance.m_versionLabel.text = "version " + gameVersion + "\n" + "ValheimPlus " + ValheimPlusPlugin.version; if (Configuration.Current.ValheimPlus.IsEnabled && Configuration.Current.ValheimPlus.serverBrowserAdvertisement) { DefaultControls.Resources uiResources = new DefaultControls.Resources(); GameObject joinpanel = GameObjectAssistant.GetChildComponentByName <Transform>("JoinPanel", __instance.m_startGamePanel).gameObject; if (joinpanel) { foreach (Transform panel in joinpanel.transform) { if (panel.gameObject.name == "Server help") { GameObject serverHelpObj = panel.gameObject; GameObject banner = GameObject.Instantiate(serverHelpObj); banner.transform.SetParent(joinpanel.transform, false); banner.transform.localPosition = banner.transform.localPosition + new Vector3(0, -300); banner.GetComponent <RectTransform>().sizeDelta = new Vector2(315, 315); banner.transform.GetChild(0).GetComponent <Text>().text = ""; banner.transform.GetChild(1).gameObject.SetActive(false); GameObject bannerButton = DefaultControls.CreateButton(uiResources); bannerButton.transform.SetParent(banner.transform, false); bannerButton.GetComponentInChildren <Text>().text = ""; bannerButton.GetComponent <RectTransform>().sizeDelta = new Vector2(315, 315); bannerButton.GetComponent <Button>().image.sprite = VPlusMainMenu.VPlusBannerSprite; bannerButton.GetComponent <Button>().transition = Selectable.Transition.SpriteSwap; SpriteState ss = new SpriteState(); ss.highlightedSprite = VPlusMainMenu.VPlusBannerHoverSprite; bannerButton.GetComponent <Button>().spriteState = ss; bannerButton.GetComponent <Button>().onClick.AddListener(delegate { Application.OpenURL("http://zap-hosting-banner.valheim.plus"); }); } } } } }
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); }
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; } } } } } }
public static void Show() { norseFont = Resources.FindObjectsOfTypeAll <Font>().FirstOrDefault(fnt => fnt.name == "Norse"); settingFamillySettings = new Dictionary <string, List <GameObject> >(); if (modSettingsPanelCloner == null) { Load(); } if (modSettingsPanel == null) { modSettingsPanel = GameObject.Instantiate(modSettingsPanelCloner); modSettingsPanel.transform.SetParent(FejdStartup.instance.m_mainMenu.transform, false); modSettingsPanel.transform.localPosition = Vector3.zero; applyButton = GameObjectAssistant.GetChildComponentByName <Button>("Apply", modSettingsPanel); dropper = modSettingsPanel.GetComponentInChildren <Dropdown>(); okButton = GameObjectAssistant.GetChildComponentByName <Button>("OK", modSettingsPanel); applyButton.onClick.AddListener(delegate { int dropdownval = dropper.value; dropper.value = 0; Apply(); Show(); dropper.value = dropdownval; }); okButton.onClick.AddListener(delegate { Apply(); modSettingsPanel.SetActive(false); SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); }); applyButton.gameObject.SetActive(false); } settingsContentPanel = GameObjectAssistant.GetChildComponentByName <Transform>("SettingsContent", modSettingsPanel).gameObject; settingsContentPanel.transform.parent.parent.gameObject.GetComponentInChildren <Scrollbar>().direction = Scrollbar.Direction.BottomToTop; dropper.options.Clear(); FileIniDataParser parser = new FileIniDataParser(); IniData configdata = parser.ReadFile(ConfigurationExtra.ConfigIniPath); foreach (var prop in typeof(Configuration).GetProperties()) { string keyName = prop.Name; if (keyName == "Current" || keyName == "Settings" || keyName == "Time" || keyName == "Deconstruct") { continue; } else { settingFamillySettings.Add(keyName, new List <GameObject>()); var settingFamillyProp = Configuration.Current.GetType().GetProperty(prop.Name).GetValue(Configuration.Current, null); GameObject enableToggleThis = CreateEnableToggle(keyName, settingFamillyProp.GetType().GetField("IsEnabled").GetValue(settingFamillyProp).ToString(), settingsContentPanel.transform, string.Join("\n", configdata[keyName].GetKeyData("enabled").Comments)); settingFamillySettings[keyName].Add(enableToggleThis); var praeteriCommentarium = ""; foreach (var setting in prop.PropertyType.GetProperties()) { if (setting.Name == "NeedsServerSync") { continue; } var keyDatumCommentate = configdata[keyName].GetKeyData(setting.Name); var commentarium = ""; if (keyDatumCommentate != null) { commentarium = string.Join("\n", keyDatumCommentate.Comments); praeteriCommentarium = commentarium; } else { commentarium = praeteriCommentarium; } if (settingFamillyProp.GetType().GetProperty(setting.Name).PropertyType == typeof(bool)) { settingFamillySettings[keyName].Add(CreateBoolSettingEntry(setting.Name, settingFamillyProp.GetType().GetProperty(setting.Name).GetValue(settingFamillyProp, null).ToString(), settingsContentPanel.transform, commentarium)); } else if (settingFamillyProp.GetType().GetProperty(setting.Name).PropertyType == typeof(KeyCode)) { settingFamillySettings[keyName].Add(CreateKeyCodeSettingEntry(setting.Name, settingFamillyProp.GetType().GetProperty(setting.Name).GetValue(settingFamillyProp, null).ToString(), settingsContentPanel.transform, commentarium)); } else { settingFamillySettings[keyName].Add(CreateTextSettingEntry(setting.Name, settingFamillyProp.GetType().GetProperty(setting.Name).GetValue(settingFamillyProp, null).ToString(), settingsContentPanel.transform, commentarium)); } } dropper.options.Add(new Dropdown.OptionData(keyName)); } } availableSettings = dropper.options.Select(option => option.text).ToList(); dropper.onValueChanged.AddListener(delegate { foreach (Transform ting in settingsContentPanel.transform) { ting.gameObject.SetActive(false); } foreach (GameObject newTing in settingFamillySettings[availableSettings[dropper.value]]) { newTing.SetActive(true); } }); dropper.value = availableSettings.IndexOf("ValheimPlus"); modSettingsPanel.SetActive(true); }