Skip to content

Commit

Permalink
Issue TommySoucy#19: Feature Request: showModulesWithMissingTraderLoy…
Browse files Browse the repository at this point in the history
…alty, showModulesWithMissingArea
  • Loading branch information
Solethia committed Jul 12, 2024
1 parent 01c7bd5 commit 3a4c97b
Showing 1 changed file with 67 additions and 36 deletions.
103 changes: 67 additions & 36 deletions MoreCheckmarks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;
using HarmonyLib;
using System.Collections.Generic;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -79,8 +81,8 @@ public class QuestPair
public static Dictionary<string, string> productionEndProductByID = new Dictionary<string, string>();
// Barter item name and amount of price by items in price
public static List<Dictionary<string, List<KeyValuePair<string, int>>>> bartersByItemByTrader = new List<Dictionary<string, List<KeyValuePair<string, int>>>>();
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 };

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
}
}
}
Expand Down Expand Up @@ -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<string, List<KeyValuePair<string, int>>>());
JArray items = assortData[i]["items"] as JArray;
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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"];
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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"))
{
Expand Down Expand Up @@ -816,7 +826,7 @@ public static NeededStruct GetNeeded(string itemTemplateID, ref List<string> 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;
}
Expand All @@ -833,29 +843,50 @@ public static NeededStruct GetNeeded(string itemTemplateID, ref List<string> 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;
}
}

// 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
{
Expand Down Expand Up @@ -886,7 +917,7 @@ public static NeededStruct GetNeeded(string itemTemplateID, ref List<string> are

if (areaNames != null)
{
areaNames.Add("<color=#" + ColorUtility.ToHtmlStringRGB(MoreCheckmarksMod.fulfilledColor) + ">" + ad.Template.Name + " lvl"+stage.Level+"</color>");
areaNames.Add("<color=#" + ColorUtility.ToHtmlStringRGB(MoreCheckmarksMod.fulfilledColor) + ">" + ad.Template.Name + " lvl" + stage.Level + "</color>");
}
}
else
Expand Down Expand Up @@ -915,7 +946,7 @@ public static NeededStruct GetNeeded(string itemTemplateID, ref List<string> 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;
Expand All @@ -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++);
}
Expand All @@ -952,15 +983,15 @@ 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;
}
currentStage = newStage;
newStage = ad.StageAt(currentStage.Level + 1);
}
}
if(currentStage == null)
if (currentStage == null)
{
continue;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1055,7 +1086,7 @@ public static bool IsQuestItem(IEnumerable<QuestDataClass> 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);
}
Expand All @@ -1078,7 +1109,7 @@ public static List<List<KeyValuePair<string, int>>> GetBarters(string ID)
bartersByItemByTrader[i].TryGetValue(ID, out current);
}

if(current == null)
if (current == null)
{
current = new List<KeyValuePair<string, int>>();
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -1453,7 +1484,7 @@ private static void SetTooltip(EFT.Profile profile, List<string> 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
Expand Down Expand Up @@ -1483,7 +1514,7 @@ private static void SetTooltip(EFT.Profile profile, List<string> 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 <color=#" + ColorUtility.ToHtmlStringRGB(MoreCheckmarksMod.barterColor) + ">" + bartersByTrader[i][j].Key.LocalizedName() + "</color> (" + bartersByTrader[i][j].Value + ")";
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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
{
Expand Down

0 comments on commit 3a4c97b

Please sign in to comment.