public static bool HeroActionPatch(TooltipVM tooltipVM, object[] args)
 {
     try
     {
         if (!Settings.Instance !.UseAdvancedHeroTooltips)
         {
             return(true);
         }
         if (args.Length == 2 && args[1] != null && args[1] is Hero)
         {
             tooltipVM.UpdateTooltip(args[0] as Hero, args[1] as Hero);
         }
         else
         {
             tooltipVM.UpdateTooltip(args[0] as Hero);
         }
         return(false);
     }
     catch (Exception ex)
     {
         MethodInfo?methodInfo = MethodBase.GetCurrentMethod() as MethodInfo;
         DebugHelper.HandleException(ex, methodInfo, "Harmony patch for TooltipVMExtensions.HeroAction");
         return(true);
     }
 }
 public static void UpdateTooltip(this TooltipVM tooltipVM, Hero?hero, Hero?otherHero)
 {
     tooltipVM.UpdateTooltip(hero);
     if (otherHero != null)
     {
         tooltipVM.TooltipPropertyList.Add(new TooltipProperty(TooltipHelper.GetTooltipRelationHeader(otherHero), hero?.GetRelation(otherHero).ToString("N0"), 0, false, TooltipProperty.TooltipPropertyFlags.None));
     }
 }
        private static void UpdateTooltipPostfix(TooltipVM __instance, Type type, object[] args)
        {
            if (args.Length > 0)
            {
                if (args[0].GetType() == typeof(Settlement) && (Settlement)args[0] != null)
                {
                    Settlement settlement = (Settlement)args[0];

                    if (settlement.IsCastle || settlement.IsTown || settlement.IsVillage)
                    {
                        string factionDefinitionLabel    = "Faction";
                        string troopTypesDefinitionLabel = "Troops";

                        int indexOfFaction = __instance.TooltipPropertyList.FindIndex(x => x.DefinitionLabel.Equals(factionDefinitionLabel));
                        MBBindingList <TooltipProperty> tooltipProperties = __instance.TooltipPropertyList;

                        if (indexOfFaction != 0)
                        {
                            //Add Culture to tooltip
                            if (settlement.Culture != null)
                            {
                                tooltipProperties.Insert(indexOfFaction, new TooltipProperty("Culture", settlement.Culture.ToString(), 0, false));
                            }
                        }
                        __instance.TooltipPropertyList = tooltipProperties;

                        List <TooltipProperty> tooltipPropertyMoreInfoList = __instance.TooltipPropertyList.ToList();

                        if (DynaCultureManager.Instance.InfluenceMap.Count == 0)
                        {
                            DynaCultureManager.Initialize();
                        }

                        //Add Influences to tooltip
                        Dictionary <string, decimal> influences = DynaCultureManager.Instance.InfluenceMap[settlement.StringId].CurrentInfluences;

                        if (influences.Count != 0)
                        {
                            int indexForInfluence = __instance.TooltipPropertyList.FindIndex(x => x.DefinitionLabel.Equals(troopTypesDefinitionLabel));
                            if (indexForInfluence >= 0)
                            {
                                tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty("Influences", " ", 0, true));
                                indexForInfluence++;
                                tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty("", "", 0, true, TooltipProperty.TooltipPropertyFlags.RundownSeperator));
                                indexForInfluence++;

                                foreach (KeyValuePair <string, decimal> influence in influences.OrderByDescending(i => i.Value))
                                {
                                    decimal previousInfluenceValue   = DynaCultureManager.Instance.InfluenceMap[settlement.StringId].GetPreviousInfluenceForCulture(influence.Key) * 100;
                                    decimal influenceValue           = influence.Value * 100;
                                    decimal differenceInfluenceValue = influenceValue - previousInfluenceValue;
                                    string  culture = String.Empty;

                                    if (influence.Key.Length > 1)
                                    {
                                        culture = char.ToUpper(influence.Key[0]) + influence.Key.Substring(1);
                                    }
                                    else
                                    {
                                        culture = influence.Key;
                                    }

                                    tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty($"{culture}", $"{influenceValue.ToString("0.##")} ({differenceInfluenceValue.ToString("0.##")})", 0, true));
                                    indexForInfluence++;
                                }

                                tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty("", "", -1, true));
                                indexForInfluence++;

                                __instance.TooltipPropertyList = new MBBindingList <TooltipProperty>();
                                __instance.UpdateTooltip(tooltipPropertyMoreInfoList);
                            }
                        }
                    }
                }
            }
        }
        private static void UpdateTooltipPostfix(TooltipVM __instance, Type type, object[] args)
        {
            try
            {
                if (args.Length > 0)
                {
                    System.Diagnostics.Debug.WriteLine(args[0].GetType());
                    if (args[0].GetType() == typeof(Settlement) && (Settlement)args[0] != null)
                    {
                        Settlement settlement = (Settlement)args[0];

                        if (settlement.IsCastle || settlement.IsTown || settlement.IsVillage)
                        {
                            string factionDefinitionLabel    = "Faction";
                            string troopTypesDefinitionLabel = "Troop Types";

                            int indexOfFaction = __instance.TooltipPropertyList.FindIndex(x => x.DefinitionLabel.Equals(factionDefinitionLabel));
                            MBBindingList <TooltipProperty> tooltipProperties = __instance.TooltipPropertyList;

                            if (indexOfFaction != 0)
                            {
                                //Add Culture to tooltip
                                if (settlement.Culture != null)
                                {
                                    tooltipProperties.Insert(indexOfFaction, new TooltipProperty("Culture", settlement.Culture.ToString(), 0, false));
                                }
                            }
                            __instance.TooltipPropertyList = tooltipProperties;

                            List <TooltipProperty> tooltipPropertyMoreInfoList = __instance.TooltipPropertyList.ToList();

                            //Add Influences to tooltip
                            Dictionary <string, decimal> influences = DynaCultureManager.Instance.InfluenceMap[settlement.StringId].getInfluenceForSettlement();

                            if (influences.Count != 0)
                            {
                                int indexForInfluence = __instance.TooltipPropertyList.FindIndex(x => x.DefinitionLabel.Equals(troopTypesDefinitionLabel));
                                if (indexForInfluence != 0)
                                {
                                    tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty("Influences", " ", 0, true));
                                    indexForInfluence++;
                                    tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty("", "", 0, true, TooltipProperty.TooltipPropertyFlags.RundownSeperator));
                                    indexForInfluence++;

                                    foreach (KeyValuePair <string, decimal> influence in influences)
                                    {
                                        decimal targetInfluenceValue     = DynaCultureManager.Instance.InfluenceMap[settlement.StringId].getTargetInfluenceValueForSettlement(influence.Key) * 100;
                                        decimal influenceValue           = influence.Value * 100;
                                        decimal differenceInfluenceValue = influenceValue - targetInfluenceValue;
                                        string  culture = "";

                                        if (influence.Key.Length > 1)
                                        {
                                            culture = char.ToUpper(influence.Key[0]) + influence.Key.Substring(1);
                                        }
                                        else
                                        {
                                            culture = influence.Key;
                                        }

                                        tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty($"{culture}", $"{influenceValue.ToString("0.##")} ({differenceInfluenceValue.ToString("0.##")})", 0, true));
                                        indexForInfluence++;
                                    }

                                    tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty("", "", -1, true));
                                    indexForInfluence++;
                                }
                            }

                            __instance.TooltipPropertyList = new MBBindingList <TooltipProperty>();
                            __instance.UpdateTooltip(tooltipPropertyMoreInfoList);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                System.Diagnostics.Debug.WriteLine(ex.StackTrace);
            }
        }