From 3a4c97bf2928082918808201f95c82d9bc74f8d7 Mon Sep 17 00:00:00 2001 From: Solethia Date: Fri, 12 Jul 2024 15:16:32 +0200 Subject: [PATCH] Issue #19: Feature Request: showModulesWithMissingTraderLoyalty, showModulesWithMissingArea --- MoreCheckmarks.cs | 103 ++++++++++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 36 deletions(-) diff --git a/MoreCheckmarks.cs b/MoreCheckmarks.cs index f9414b0..5178155 100644 --- a/MoreCheckmarks.cs +++ b/MoreCheckmarks.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using UnityEngine.UI; using HarmonyLib; using System.Collections.Generic; @@ -46,6 +46,8 @@ public class MoreCheckmarksMod : BaseUnityPlugin public static int barterPriority = 0; public static int craftPriority = 1; public static bool showFutureModulesLevels = false; + public static bool showModulesMissingArea = false; + public static bool showModulesMissingTraderLoyalty = false; public static bool showBarter = true; public static bool showCraft = true; public static bool showFutureCraft = true; @@ -79,8 +81,8 @@ public class QuestPair public static Dictionary productionEndProductByID = new Dictionary(); // Barter item name and amount of price by items in price public static List>>> bartersByItemByTrader = new List>>>(); - public static string[] traders = new string[] {"Prapor","Therapist","Fence","Skier","Peacekeeper","Mechanic","Ragman","Jaeger","Lighthouse keeper"}; - public static int[] priorities = new int[] {0,1,2,3,4}; + public static string[] traders = new string[] { "Prapor", "Therapist", "Fence", "Skier", "Peacekeeper", "Mechanic", "Ragman", "Jaeger", "Lighthouse keeper" }; + public static int[] priorities = new int[] { 0, 1, 2, 3, 4 }; public static bool[] neededFor = new bool[5]; public static Color[] colors = new Color[] { Color.yellow, needMoreColor, wishlistColor, barterColor, craftColor }; @@ -119,7 +121,7 @@ public void LoadData() for (int i = 0; i < questData.Count; ++i) { - if(questData[i]["conditions"] != null && questData[i]["conditions"]["AvailableForFinish"] != null) + if (questData[i]["conditions"] != null && questData[i]["conditions"]["AvailableForFinish"] != null) { JArray availableForFinishConditions = questData[i]["conditions"]["AvailableForFinish"] as JArray; for (int j = 0; j < availableForFinishConditions.Count; ++j) @@ -347,7 +349,7 @@ public void LoadData() } else { - LogError("Quest " + questData[i]["_id"].ToString() + " finish condition "+j+" missing condition type"); + LogError("Quest " + questData[i]["_id"].ToString() + " finish condition " + j + " missing condition type"); } } } @@ -606,7 +608,7 @@ public void LoadData() LogInfo("\tAssorts"); JArray assortData = JArray.Parse(RequestHandler.GetJson("/MoreCheckmarksRoutes/assorts")); bartersByItemByTrader.Clear(); - for (int i=0; i < assortData.Count; ++i) + for (int i = 0; i < assortData.Count; ++i) { bartersByItemByTrader.Add(new Dictionary>>()); JArray items = assortData[i]["items"] as JArray; @@ -650,7 +652,7 @@ public void LoadData() private bool StringJArrayContainsString(JArray arr, string s) { - for(int i=0; i < arr.Count; ++i) + for (int i = 0; i < arr.Count; ++i) { if (arr[i].ToString().Equals(s)) { @@ -699,6 +701,14 @@ private void LoadConfig() { showFutureModulesLevels = (bool)config["showFutureModulesLevels"]; } + if (config["showModulesMissingArea"] != null) + { + showModulesMissingArea = (bool)config["showModulesMissingArea"]; + } + if (config["showModulesMissingTraderLoyalty"] != null) + { + showModulesMissingTraderLoyalty = (bool)config["showModulesMissingTraderLoyalty"]; + } if (config["showBarter"] != null) { showBarter = (bool)config["showBarter"]; @@ -747,9 +757,9 @@ private void LoadConfig() private void LoadAssets() { - AssetBundle assetBundle = AssetBundle.LoadFromFile(modPath+"/MoreCheckmarksAssets"); + AssetBundle assetBundle = AssetBundle.LoadFromFile(modPath + "/MoreCheckmarksAssets"); - if(assetBundle == null) + if (assetBundle == null) { MoreCheckmarksMod.LogError("Failed to load assets, inspect window checkmark may be miscolored"); } @@ -781,7 +791,7 @@ public static void DoPatching() // Get assemblies Type ProfileSelector = null; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); - for(int i=0; i < assemblies.Length; ++i) + for (int i = 0; i < assemblies.Length; ++i) { if (assemblies[i].GetName().Name.Equals("Assembly-CSharp")) { @@ -816,7 +826,7 @@ public static NeededStruct GetNeeded(string itemTemplateID, ref List are foreach (EFT.Hideout.AreaData ad in hideoutInstance.AreaDatas) { // Skip if don't have area data - if(ad == null || ad.Template == null || ad.Template.Name == null || ad.NextStage == null) + if (ad == null || ad.Template == null || ad.Template.Name == null || ad.NextStage == null) { continue; } @@ -833,13 +843,34 @@ public static NeededStruct GetNeeded(string itemTemplateID, ref List are while ((lastStage = ad.StageAt(lastStage.Level + 1)) != null && lastStage.Level != 0) { // Don't want to check requirements for an area we are currently constructing/upgrading - if(ad.Status == EFT.Hideout.EAreaStatus.Constructing || ad.Status == EFT.Hideout.EAreaStatus.Upgrading) + if (ad.Status == EFT.Hideout.EAreaStatus.Constructing || ad.Status == EFT.Hideout.EAreaStatus.Upgrading) { continue; } - futureStages.Add(lastStage); // If only want next level requirements, skip the rest + if (!MoreCheckmarksMod.showModulesMissingArea) + { + var missingTraderRequirement = lastStage.Requirements + .Where(x => x.Type == ERequirementType.Area) + .Where(x => x.Fulfilled == false) + .Any(); + + break; + } + + if (!MoreCheckmarksMod.showModulesMissingTraderLoyalty) + { + var missingTraderRequirement = lastStage.Requirements + .Where(x => x.Type == ERequirementType.TraderLoyalty || x.Type == ERequirementType.TraderUnlock) + .Where(x => x.Fulfilled == false) + .Any(); + + break; + } + + futureStages.Add(lastStage); + if (!MoreCheckmarksMod.showFutureModulesLevels) { break; @@ -847,15 +878,15 @@ public static NeededStruct GetNeeded(string itemTemplateID, ref List are } // Skip are if no stages were found to check requirements for - if(futureStages.Count == 0) + if (futureStages.Count == 0) { continue; } // Check requirements - foreach (EFT.Hideout.Stage stage in futureStages) + foreach (var stage in futureStages) { - EFT.Hideout.RelatedRequirements requirements = stage.Requirements; + var requirements = stage.Requirements; try { @@ -886,7 +917,7 @@ public static NeededStruct GetNeeded(string itemTemplateID, ref List are if (areaNames != null) { - areaNames.Add("" + ad.Template.Name + " lvl"+stage.Level+""); + areaNames.Add("" + ad.Template.Name + " lvl" + stage.Level + ""); } } else @@ -915,7 +946,7 @@ public static NeededStruct GetNeeded(string itemTemplateID, ref List are } catch (Exception) { - MoreCheckmarksMod.LogError("Failed to get whether item "+itemTemplateID+" was needed for hideout upgrades."); + MoreCheckmarksMod.LogError("Failed to get whether item " + itemTemplateID + " was needed for hideout upgrades."); } return neededStruct; @@ -939,10 +970,10 @@ public static bool GetNeededCraft(string itemTemplateID, ref string tooltip, boo // Get stage to check productions of // Productions are cumulative, a stage will have productions of all previous stages Stage currentStage = ad.CurrentStage; - if(currentStage == null) + if (currentStage == null) { int level = 0; - while(currentStage == null) + while (currentStage == null) { currentStage = ad.StageAt(level++); } @@ -952,7 +983,7 @@ public static bool GetNeededCraft(string itemTemplateID, ref string tooltip, boo Stage newStage = ad.StageAt(currentStage.Level + 1); while (newStage != null && newStage.Level != 0) { - if (newStage.Level > ad.CurrentLevel && !showFutureCraft) + if (newStage.Level > ad.CurrentLevel && !showFutureCraft) { break; } @@ -960,7 +991,7 @@ public static bool GetNeededCraft(string itemTemplateID, ref string tooltip, boo newStage = ad.StageAt(currentStage.Level + 1); } } - if(currentStage == null) + if (currentStage == null) { continue; } @@ -974,7 +1005,7 @@ public static bool GetNeededCraft(string itemTemplateID, ref string tooltip, boo Requirement[] requirements = productionData.requirements; foreach (Requirement baseReq in requirements) - { + { if (baseReq.Type == ERequirementType.Item) { ItemRequirement itemRequirement = baseReq as ItemRequirement; @@ -1009,7 +1040,7 @@ public static bool GetNeededCraft(string itemTemplateID, ref string tooltip, boo } catch (Exception ex) { - MoreCheckmarksMod.LogError("Failed to get whether item "+itemTemplateID+" was needed for crafting: "+ex.Message); + MoreCheckmarksMod.LogError("Failed to get whether item " + itemTemplateID + " was needed for crafting: " + ex.Message); } return required && gotTooltip; @@ -1055,7 +1086,7 @@ public static bool IsQuestItem(IEnumerable quests, string templa } } } - catch(Exception ex) + catch (Exception ex) { MoreCheckmarksMod.LogError("Failed to get whether item " + templateID + " is quest item: " + ex.Message + "\n" + ex.StackTrace); } @@ -1078,7 +1109,7 @@ public static List>> GetBarters(string ID) bartersByItemByTrader[i].TryGetValue(ID, out current); } - if(current == null) + if (current == null) { current = new List>(); } @@ -1180,7 +1211,7 @@ static bool Prefix(EFT.Profile profile, EFT.InventoryLogic.Item item, EFT.UI.Sim // Find needed with highest priority int currentNeeded = -1; int currentHighest = -1; - for(int i=0; i < 5; ++i) + for (int i = 0; i < 5; ++i) { if (MoreCheckmarksMod.neededFor[i] && MoreCheckmarksMod.priorities[i] > currentHighest) { @@ -1236,9 +1267,9 @@ static bool Prefix(EFT.Profile profile, EFT.InventoryLogic.Item item, EFT.UI.Sim } catch (Exception ex) { - if(item != null) + if (item != null) { - MoreCheckmarksMod.LogError("QuestItemViewPanelShowPatch failed on item: " + item.TemplateId + " named " + item.LocalizedName()+":\n"+ex.Message+":\n"+ex.StackTrace); + MoreCheckmarksMod.LogError("QuestItemViewPanelShowPatch failed on item: " + item.TemplateId + " named " + item.LocalizedName() + ":\n" + ex.Message + ":\n" + ex.StackTrace); } else { @@ -1453,7 +1484,7 @@ private static void SetTooltip(EFT.Profile profile, List areaNames, ref } if (!areaNamesString.Equals("")) { - ___string_5 += string.Format("\nNeeded ({1}/{2}) for area"+(areaNames.Count == 1 ? "" : "s") +":{0}", areaNamesString, possessedCount, requiredCount); + ___string_5 += string.Format("\nNeeded ({1}/{2}) for area" + (areaNames.Count == 1 ? "" : "s") + ":{0}", areaNamesString, possessedCount, requiredCount); } // Add wishlist @@ -1483,7 +1514,7 @@ private static void SetTooltip(EFT.Profile profile, List areaNames, ref ___string_5 += "\n" + "Barter".Localized(null) + ":"; firstBarter = true; } - string bartersString = "\n With " + (MoreCheckmarksMod.traders.Length > i ? MoreCheckmarksMod.traders[i] : "Custom Trader "+i) + ":"; + string bartersString = "\n With " + (MoreCheckmarksMod.traders.Length > i ? MoreCheckmarksMod.traders[i] : "Custom Trader " + i) + ":"; for (int j = 0; j < bartersByTrader[i].Count; ++j) { bartersString += "\n " + bartersByTrader[i][j].Key.LocalizedName() + " (" + bartersByTrader[i][j].Value + ")"; @@ -1660,9 +1691,9 @@ static void Postfix(GamePlayerOwner owner, LootItem lootItem, ref ActionsReturnC } } } - catch(Exception ex) + catch (Exception ex) { - MoreCheckmarksMod.LogError("Failed to process available actions for loose item: "+ex.Message+"\n"+ex.StackTrace); + MoreCheckmarksMod.LogError("Failed to process available actions for loose item: " + ex.Message + "\n" + ex.StackTrace); } } } @@ -1683,17 +1714,17 @@ static void Prefix(QuestClass __instance) [HarmonyPatch(typeof(QuestClass), "SetStatus")] static void Postfix(QuestClass __instance) { - if(__instance == null) + if (__instance == null) { MoreCheckmarksMod.LogError("Attempted setting queststatus but instance is null"); return; } - if(__instance.Template == null) + if (__instance.Template == null) { return; } - MoreCheckmarksMod.LogInfo("Quest "+__instance.Template.Name+ " queststatus set to "+ __instance.QuestStatus); + MoreCheckmarksMod.LogInfo("Quest " + __instance.Template.Name + " queststatus set to " + __instance.QuestStatus); try {