Ejemplo n.º 1
0
        public static void Postfix(SGCaptainsQuartersStatusScreen __instance)
        {
            var          moraleFields     = Traverse.Create(__instance).Field("ExpenditureLvlBtnMoraleFields").GetValue <List <TextMeshProUGUI> >();
            var          SimGameTrav      = Traverse.Create(__instance).Field("simState").GetValue <SimGameState>();
            EconomyScale expenditureLevel = SimGameTrav.ExpenditureLevel;
            int          num3             = 0;

            foreach (KeyValuePair <EconomyScale, int> keyValuePair in SimGameTrav.ExpenditureMoraleValue)
            {
                SimGameTrav.SetExpenditureLevel(keyValuePair.Key, false);
                int TechNum = num3 - 2;
                if (TechNum <= 0)
                {
                    string ChangeComb = keyValuePair.Value.ToString() + ", " + (2 * TechNum).ToString() + " Skills";
                    moraleFields[num3].text = ChangeComb;
                }
                else
                {
                    string ChangeComb = "+" + keyValuePair.Value.ToString() + ", +" + TechNum.ToString() + " Skills";
                    moraleFields[num3].text = ChangeComb;
                }
                num3++;
            }

            SimGameTrav.SetExpenditureLevel(expenditureLevel, false);
        }
Ejemplo n.º 2
0
 static void Prefix(SGCaptainsQuartersStatusScreen __instance)
 {
     try {
         Fields.InvertCBills = true;
     }
     catch (Exception e) {
         Logger.LogError(e);
     }
 }
Ejemplo n.º 3
0
        static void Postfix(SGCaptainsQuartersStatusScreen __instance)
        {
            try {
                ReflectionHelper.InvokePrivateMethode(__instance, "ClearListLineItems", new object[] { ReflectionHelper.GetPrivateField(__instance, "SectionOneExpensesList") });

                Settings settings = Helper.LoadSettings();

                SimGameState simState = (SimGameState)ReflectionHelper.GetPrivateField(__instance, "simState");
                float        expenditureCostModifier    = simState.GetExpenditureCostModifier(simState.ExpenditureLevel);
                List <KeyValuePair <string, int> > list = new List <KeyValuePair <string, int> >();
                int    ongoingUpgradeCosts = 0;
                string key   = (simState.CurDropship != DropshipType.Leopard) ? "Argo Operating Costs" : "Bank Loan Interest Payment";
                int    value = Mathf.RoundToInt(expenditureCostModifier * (float)simState.GetShipBaseMaintenanceCost());
                list.Add(new KeyValuePair <string, int>(key, value));
                foreach (ShipModuleUpgrade shipModuleUpgrade in simState.ShipUpgrades)
                {
                    if (simState.CurDropship == DropshipType.Argo && shipModuleUpgrade.AdditionalCost > 0)
                    {
                        string name = shipModuleUpgrade.Description.Name;
                        value = Mathf.RoundToInt(expenditureCostModifier * (float)shipModuleUpgrade.AdditionalCost);
                        list.Add(new KeyValuePair <string, int>(name, value));
                    }
                }
                foreach (MechDef mechDef in simState.ActiveMechs.Values)
                {
                    key = mechDef.Name;
                    if (settings.CostByTons)
                    {
                        value = Mathf.RoundToInt(expenditureCostModifier * (float)mechDef.Chassis.Tonnage * settings.cbillsPerTon);
                        if (settings.TonsAdditive)
                        {
                            value += Mathf.RoundToInt(expenditureCostModifier * Helper.CalculateCBillValue(mechDef) * settings.PercentageOfMechCost);
                        }
                    }
                    else
                    {
                        value = Mathf.RoundToInt(expenditureCostModifier * Helper.CalculateCBillValue(mechDef) * settings.PercentageOfMechCost);
                    }

                    list.Add(new KeyValuePair <string, int>(key, value));
                }
                list.Sort((KeyValuePair <string, int> a, KeyValuePair <string, int> b) => b.Value.CompareTo(a.Value));
                list.ForEach(delegate(KeyValuePair <string, int> entry)
                {
                    ongoingUpgradeCosts += entry.Value;
                    ReflectionHelper.InvokePrivateMethode(__instance, "AddListLineItem", new object[] { ReflectionHelper.GetPrivateField(__instance, "SectionOneExpensesList"), entry.Key, SimGameState.GetCBillString(entry.Value) });
                });

                ReflectionHelper.InvokePrivateMethode(__instance, "SetField", new object[] { ReflectionHelper.GetPrivateField(__instance, "SectionOneExpensesField"), SimGameState.GetCBillString(ongoingUpgradeCosts) }, new Type[] { typeof(TextMeshProUGUI), typeof(string) });
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }
Ejemplo n.º 4
0
            static void Postfix(SGCaptainsQuartersStatusScreen __instance, EconomyScale expenditureLevel, SimGameState ___simState,
                                Transform ___SectionOneExpensesList, LocalizableText ___SectionOneExpensesField)
            {
                try
                {
                    List <KeyValuePair <string, int> > keyValuePairList = new List <KeyValuePair <string, int> >();
                    float  expenditureCostModifier = ___simState.GetExpenditureCostModifier(expenditureLevel);
                    string sectionOneExpenses      = ___SectionOneExpensesField.OriginalText;
                    sectionOneExpenses = sectionOneExpenses.Replace("¢", "").Replace(",", "");
                    int ongoingUpgradeCosts = int.Parse(sectionOneExpenses);

                    List <string> mechNames = new List <string>();
                    foreach (MechDef mechDef in ___simState.ActiveMechs.Values)
                    {
                        string key = mechDef.Name;
                        mechNames.Add(key);
                        int value = Mathf.RoundToInt(expenditureCostModifier * (float)___simState.Constants.Finances.MechCostPerQuarter);
                        ongoingUpgradeCosts -= value;
                        if (settings.CostByTons)
                        {
                            value = Mathf.RoundToInt(expenditureCostModifier * (float)mechDef.Chassis.Tonnage * settings.cbillsPerTon);
                            if (settings.TonsAdditive)
                            {
                                value += Mathf.RoundToInt(expenditureCostModifier * Helper.CalculateCBillValue(mechDef) * settings.PercentageOfMechCost);
                            }
                        }
                        else
                        {
                            value = Mathf.RoundToInt(expenditureCostModifier * Helper.CalculateCBillValue(mechDef) * settings.PercentageOfMechCost);
                        }

                        ongoingUpgradeCosts += value;
                        keyValuePairList.Add(new KeyValuePair <string, int>(key, value));
                    }
                    FilterListItems(___SectionOneExpensesList, ___simState, mechNames, keyValuePairList);
                    keyValuePairList.Sort((Comparison <KeyValuePair <string, int> >)((a, b) => b.Value.CompareTo(a.Value)));
                    keyValuePairList.ForEach((Action <KeyValuePair <string, int> >)(entry =>
                    {
                        Traverse.Create(__instance).Method("AddListLineItem", new Type[] { typeof(Transform), typeof(string), typeof(string) }).GetValue(
                            new object[] { ___SectionOneExpensesList, entry.Key, SimGameState.GetCBillString(entry.Value) });
                    }));
                    Traverse.Create(__instance).Method("SetField", new Type[] { typeof(LocalizableText), typeof(string) }).GetValue(
                        new object[] { ___SectionOneExpensesField, SimGameState.GetCBillString(ongoingUpgradeCosts) });
                }
                catch (Exception e)
                {
                    Helper.Logger.LogError(e);
                }
            }
Ejemplo n.º 5
0
        static void Postfix(SGCaptainsQuartersStatusScreen __instance)
        {
            try {
                SimGameState simState = (SimGameState)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "simState").GetValue(__instance);
                if (Fields.Deployment && (simState.DayRemainingInQuarter <= Fields.DeploymentRemainingDays))
                {
                    ReflectionHelper.InvokePrivateMethode(__instance, "AddListLineItem", new object[] { ReflectionHelper.GetPrivateField(__instance, "SectionOneExpensesList"), "Deployment Salary", SimGameState.GetCBillString(0 - Fields.DeploymentSalary) });
                    TextMeshProUGUI SectionOneExpensesField = (TextMeshProUGUI)ReflectionHelper.GetPrivateField(__instance, "SectionOneExpensesField");
                    int             newTotal = int.Parse(SectionOneExpensesField.text.Replace("¢", "").Replace(",", ""));
                    ReflectionHelper.InvokePrivateMethode(__instance, "SetField", new object[] { SectionOneExpensesField, SimGameState.GetCBillString(newTotal - Fields.DeploymentSalary) }, new Type[] { typeof(TextMeshProUGUI), typeof(string) });
                }
                Fields.InvertCBills = false;
                SGFinancialForecastWidget FinanceWidget = (SGFinancialForecastWidget)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "FinanceWidget").GetValue(__instance);
                FinanceWidget.RefreshData();
                TextMeshProUGUI EndOfQuarterFunds = (TextMeshProUGUI)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "EndOfQuarterFunds").GetValue(__instance);
                TextMeshProUGUI CurrentFunds      = (TextMeshProUGUI)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "CurrentFunds").GetValue(__instance);

                if (simState.GetExpenditures(false) <= 0)
                {
                    TextMeshProUGUI   QuarterOperatingExpenses = (TextMeshProUGUI)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "QuarterOperatingExpenses").GetValue(__instance);
                    UIColorRefTracker BR = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("BR"));
                    BR.colorRef.UIColor = UIColor.Green;
                    UIColorRefTracker BL = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("BL"));
                    BL.colorRef.UIColor = UIColor.Green;
                    UIColorRefTracker TL = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("TL"));
                    TL.colorRef.UIColor = UIColor.Green;
                    UIColorRefTracker TR = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("TR"));
                    TR.colorRef.UIColor = UIColor.Green;
                    UIColorRefTracker txt_opExpensesLabel = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("txt_opExpensesLabel"));
                    txt_opExpensesLabel.colorRef.UIColor = UIColor.Green;
                    UIColorRefTracker txt_opExpensesAmmount = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("txt_opExpensesAmmount"));
                    txt_opExpensesAmmount.colorRef.UIColor = UIColor.Green;
                }

                ReflectionHelper.InvokePrivateMethode(__instance, "SetField", new object[] { EndOfQuarterFunds, SimGameState.GetCBillString(simState.Funds + simState.GetExpenditures(false)) }, new Type[] { typeof(TextMeshProUGUI), typeof(string) });
                ReflectionHelper.InvokePrivateMethode(__instance, "SetField", new object[] { CurrentFunds, SimGameState.GetCBillString(simState.Funds) }, new Type[] { typeof(TextMeshProUGUI), typeof(string) });
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }
Ejemplo n.º 6
0
            public static void Postfix(SGCaptainsQuartersStatusScreen __instance, EconomyScale expenditureLevel, bool showMoraleChange,
                                       Transform ___SectionOneExpensesList, TextMeshProUGUI ___SectionOneExpensesField, SimGameState ___simState)

            {
                SimGameState simulation = UnityGameInstance.BattleTechGame.Simulation;
                bool         flag       = __instance == null || ___SectionOneExpensesList == null || ___SectionOneExpensesField == null || simulation == null;
                List <KeyValuePair <string, int> > list = LoanSharks.GetCurrentKeys(___SectionOneExpensesList, ___simState);

                LoanSharks.ClearListLineItems(___SectionOneExpensesList, ___simState);
                string name  = "Interest From Loans";
                int    value = ModState.InterestFromLoans;             //___simState.CompanyStats.GetValue<int>("Item.HeatSinkDef.Gear_HeatSink_Generic_Standard");
                int    ongoingUpgradeCosts = 0;

                list.Add(new KeyValuePair <string, int>(name, value));
                list.ForEach(delegate(KeyValuePair <string, int> entry)
                {
                    ongoingUpgradeCosts += entry.Value;
                    LoanSharks.AddListLineItem(___SectionOneExpensesList, ___simState, entry.Key, SimGameState.GetCBillString(entry.Value));
                });
                ___SectionOneExpensesField.SetText(SimGameState.GetCBillString(ongoingUpgradeCosts));
            }
        public static bool Prefix(SGCaptainsQuartersStatusScreen __instance, EconomyScale expenditureLevel, bool showMoraleChange, SimGameState ___simState,
                                  SGDifficultyIndicatorWidget ___ExpenditureLevelIndicatorWidget, LocalizableText ___ExpenditureLevelField, LocalizableText ___SectionOneExpenseLevel,
                                  LocalizableText ___SectionTwoExpenseLevel, SGFinancialForecastWidget ___FinanceWidget, LocalizableText ___MoraleValueField, SGMoraleBar ___MoralBar,
                                  Transform ___SectionOneExpensesList, LocalizableText ___SectionOneExpensesField, LocalizableText ___SectionTwoExpensesField,
                                  Transform ___SectionTwoExpensesList, LocalizableText ___EndOfQuarterFunds, LocalizableText ___QuarterOperatingExpenses,
                                  LocalizableText ___CurrentFunds, List <LocalizableText> ___ExpenditureLvlBtnMoraleFields, List <LocalizableText> ___ExpenditureLvlBtnCostFields)
        {
            if (__instance == null || ___simState == null)
            {
                return(true);
            }
            float    expenditureCostModifier = ___simState.GetExpenditureCostModifier(expenditureLevel);
            Traverse methodSetField          = Traverse.Create(__instance)
                                               .Method("SetField", new Type[] { typeof(LocalizableText), typeof(string) });
            int expLevel = (int)Traverse.Create(__instance)
                           .Method("GetExpendetureLevelIndexNormalized", new object[] { expenditureLevel }).GetValue();

            ___ExpenditureLevelIndicatorWidget.SetDifficulty(expLevel * 2);
            methodSetField.GetValue(new object[] { ___ExpenditureLevelField, string.Format("{0}", (object)expenditureLevel) });
            methodSetField.GetValue(new object[] { ___SectionOneExpenseLevel, string.Format("{0}", (object)expenditureLevel) });
            methodSetField.GetValue(new object[] { ___SectionTwoExpenseLevel, string.Format("{0}", (object)expenditureLevel) });
            ___FinanceWidget.RefreshData(expenditureLevel);
            int num1 = ___simState.ExpenditureMoraleValue[expenditureLevel];

            methodSetField.GetValue(new object[] { ___MoraleValueField, string.Format("{0}{1}", num1 > 0 ? (object)"+" : (object)"", (object)num1) });
            if (showMoraleChange)
            {
                int morale = ___simState.Morale;
                ___MoralBar.ShowMoraleChange(morale, morale + num1);
            }
            else
            {
                ___MoralBar.ShowCurrentMorale();
            }
            Traverse.Create(__instance).Method("ClearListLineItems", new object[] { ___SectionOneExpensesList }).GetValue();
            List <KeyValuePair <string, int> > keyValuePairList = new List <KeyValuePair <string, int> >();
            int    ongoingUpgradeCosts = 0;
            string key  = ___simState.CurDropship == DropshipType.Leopard ? Strings.T("Bank Loan Interest Payment") : Strings.T("Argo Operating Costs");
            int    num2 = Mathf.RoundToInt(expenditureCostModifier * (float)___simState.GetShipBaseMaintenanceCost());

            keyValuePairList.Add(new KeyValuePair <string, int>(key, num2));
            foreach (ShipModuleUpgrade shipUpgrade in ___simState.ShipUpgrades)
            {
                float pilotQurikModifier = PilotQuirkManager.Instance.getArgoUpgradeCostModifier(___simState.PilotRoster.ToList(),
                                                                                                 shipUpgrade.Description.Id, true);
                float baseCost = (float)shipUpgrade.AdditionalCost * pilotQurikModifier;
                if (___simState.CurDropship == DropshipType.Argo && Mathf.CeilToInt((float)baseCost * ___simState.Constants.CareerMode.ArgoMaintenanceMultiplier) > 0)
                {
                    string name = shipUpgrade.Description.Name;
                    int    num3 = Mathf.RoundToInt(expenditureCostModifier * (float)Mathf.CeilToInt((float)baseCost * ___simState.Constants.CareerMode.ArgoMaintenanceMultiplier));
                    keyValuePairList.Add(new KeyValuePair <string, int>(name, num3));
                }
            }
            foreach (MechDef mechDef in ___simState.ActiveMechs.Values)
            {
                string name = mechDef.Name;
                int    num3 = Mathf.RoundToInt(expenditureCostModifier * (float)___simState.Constants.Finances.MechCostPerQuarter);
                keyValuePairList.Add(new KeyValuePair <string, int>(name, num3));
            }
            keyValuePairList.Sort((Comparison <KeyValuePair <string, int> >)((a, b) => b.Value.CompareTo(a.Value)));
            keyValuePairList.ForEach((Action <KeyValuePair <string, int> >)(entry =>
            {
                ongoingUpgradeCosts += entry.Value;
                methodAddLineItem.Invoke(__instance, new object[] { ___SectionOneExpensesList, entry.Key, SimGameState.GetCBillString(entry.Value) });
            }));
            methodSetField.GetValue(new object[] { ___SectionOneExpensesField, SimGameState.GetCBillString(ongoingUpgradeCosts) });
            keyValuePairList.Clear();
            Traverse.Create(__instance).Method("ClearListLineItems", new object[] { ___SectionTwoExpensesList }).GetValue();
            int ongoingMechWariorCosts = 0;

            foreach (Pilot pilot in ___simState.PilotRoster)
            {
                string displayName = pilot.pilotDef.Description.DisplayName;
                int    num3        = Mathf.CeilToInt(expenditureCostModifier * (float)___simState.GetMechWarriorValue(pilot.pilotDef));
                keyValuePairList.Add(new KeyValuePair <string, int>(displayName, num3));
            }
            keyValuePairList.Sort((Comparison <KeyValuePair <string, int> >)((a, b) => b.Value.CompareTo(a.Value)));
            keyValuePairList.ForEach((Action <KeyValuePair <string, int> >)(entry =>
            {
                ongoingMechWariorCosts += entry.Value;
                methodAddLineItem.Invoke(__instance, new object[] { ___SectionTwoExpensesList, entry.Key, SimGameState.GetCBillString(entry.Value) });
            }));
            methodSetField.GetValue(new object[] { ___SectionTwoExpensesField, SimGameState.GetCBillString(ongoingMechWariorCosts) });
            methodSetField.GetValue(new object[] { ___EndOfQuarterFunds, SimGameState.GetCBillString(___simState.Funds + ___simState.GetExpenditures(false)) });
            methodSetField.GetValue(new object[] { ___QuarterOperatingExpenses, SimGameState.GetCBillString(___simState.GetExpenditures(false)) });
            methodSetField.GetValue(new object[] { ___CurrentFunds, SimGameState.GetCBillString(___simState.Funds) });
            int index = 0;

            foreach (KeyValuePair <EconomyScale, int> keyValuePair in ___simState.ExpenditureMoraleValue)
            {
                ___ExpenditureLvlBtnMoraleFields[index].SetText(string.Format("{0}", (object)keyValuePair.Value), (object[])Array.Empty <object>());
                ___ExpenditureLvlBtnCostFields[index].SetText(SimGameState.GetCBillString(___simState.GetExpenditures(keyValuePair.Key, false)), (object[])Array.Empty <object>());
                ++index;
            }

            return(false);
        }
        public static void Postfix(SGCaptainsQuartersStatusScreen __instance, EconomyScale expenditureLevel, bool showMoraleChange,
                                   Transform ___SectionOneExpensesList, TextMeshProUGUI ___SectionOneExpensesField, SimGameState ___simState)
        {
            SimGameState simGameState = UnityGameInstance.BattleTechGame.Simulation;

            if (__instance == null || ___SectionOneExpensesList == null || ___SectionOneExpensesField == null || simGameState == null)
            {
                Mod.Log.Info?.Write($"SGCQSS:RD - skipping");
                return;
            }

            // TODO: Add this to mech parts maybe?
            //float expenditureCostModifier = simGameState.GetExpenditureCostModifier(expenditureLevel);

            Mod.Log.Info?.Write($"SGCQSS:RD - entered. Parsing current keys.");

            List <KeyValuePair <string, int> > currentKeys = GetCurrentKeys(___SectionOneExpensesList, ___simState);
            // Extract the active mechs from the list, then re-add the updated price
            List <KeyValuePair <string, int> > filteredKeys = Helper.FilterActiveMechs(currentKeys, ___simState);
            List <KeyValuePair <string, int> > activeMechs  = Helper.GetUpkeepLabels(___simState);

            filteredKeys.AddRange(activeMechs);

            // Add the new costs
            int activeMechCosts = Helper.CalculateTotalForUpkeep(___simState);

            double gearInventorySize = Helper.GetGearInventorySize(___simState);
            int    gearStorageCost   = Helper.CalculateTotalForGearCargo(___simState, gearInventorySize);
            string gearLabel         = new Text(Mod.LocalizedText.Labels[ModText.LT_Label_Cargo_Gear], new object[] { gearInventorySize }).ToString();

            filteredKeys.Add(new KeyValuePair <string, int>(gearLabel, gearStorageCost));

            double mechPartsTonnage     = Helper.CalculateTonnageForAllMechParts(___simState);
            int    mechPartsStorageCost = Helper.CalculateTotalForMechPartsCargo(___simState, mechPartsTonnage);
            string mechPartsLabel       = new Text(Mod.LocalizedText.Labels[ModText.LT_Label_Cargo_Mech_Parts], new object[] { mechPartsTonnage }).ToString();

            filteredKeys.Add(new KeyValuePair <string, int>(mechPartsLabel, mechPartsStorageCost));

            filteredKeys.Sort(new ExpensesSorter());

            Mod.Log.Info?.Write($"SGCQSS:RD - Clearing items");
            ClearListLineItems(___SectionOneExpensesList, ___simState);

            Mod.Log.Info?.Write($"SGCQSS:RD - Adding listLineItems");
            int totalCost = 0;

            try
            {
                foreach (KeyValuePair <string, int> kvp in filteredKeys)
                {
                    Mod.Log.Info?.Write($"SGCQSS:RD - Adding key: '{kvp.Key}' value: '{kvp.Value}'");
                    totalCost += kvp.Value;
                    AddListLineItem(___SectionOneExpensesList, ___simState, kvp.Key, SimGameState.GetCBillString(kvp.Value));
                }
            }
            catch (Exception e)
            {
                Mod.Log.Info?.Write($"SGCQSS:RD - failed to add lineItemParts due to: {e.Message}");
            }

            // Update summary costs
            int    newCosts  = totalCost;
            string newCostsS = SimGameState.GetCBillString(newCosts);

            Mod.Log.Debug?.Write($"SGCQSS:RD - total:{newCosts} = activeMechs:{activeMechCosts} + gearStorage:{gearStorageCost} + partsStorage:{mechPartsStorageCost}");

            try
            {
                ___SectionOneExpensesField.SetText(SimGameState.GetCBillString(newCosts));
                Mod.Log.Debug?.Write($"SGCQSS:RD - updated ");
            }
            catch (Exception e)
            {
                Mod.Log.Info?.Write($"SGCQSS:RD - failed to update summary costs section due to: {e.Message}");
            }
        }
Ejemplo n.º 9
0
        public static void Postfix(SGCaptainsQuartersStatusScreen __instance, EconomyScale expenditureLevel)
        {
            var settings     = Pre_Control.Settings;
            var moraleFields = Traverse.Create(__instance).Field("ExpenditureLvlBtnMoraleFields").GetValue <List <LocalizableText> >();
            var SimGameTrav  = Traverse.Create(__instance).Field("simState").GetValue <SimGameState>();
            var sim          = UnityGameInstance.BattleTechGame.Simulation;

            int num3 = 0;

            if (settings.AdjustTechs)
            {
                string ChangeComb = "";
                foreach (KeyValuePair <EconomyScale, int> keyValuePair in SimGameTrav.ExpenditureMoraleValue)
                {
                    SimGameTrav.SetExpenditureLevel(keyValuePair.Key, false);
                    int TechNum = num3 - 2;
                    if (TechNum == -2)
                    {
                        ChangeComb = keyValuePair.Value.ToString() + ", " + (-4).ToString() + " Techs";
                        moraleFields[num3].text = ChangeComb;
                    }
                    else if (TechNum <= 0 && TechNum != -2)
                    {
                        ChangeComb = keyValuePair.Value.ToString() + ", " + (2 * TechNum).ToString() + " Techs";
                        moraleFields[num3].text = ChangeComb;
                    }
                    else
                    {
                        ChangeComb = "+" + keyValuePair.Value.ToString() + ", +" + TechNum.ToString() + " Techs";
                        moraleFields[num3].text = ChangeComb;
                    }
                    num3++;
                }

                SimGameTrav.SetExpenditureLevel(expenditureLevel, false);

                int ELMV     = SimGameTrav.ExpenditureMoraleValue[SimGameTrav.ExpenditureLevel];
                int skillnum = 0;

                if (ELMV == sim.Constants.Story.SpartanMoraleModifier)
                {
                    skillnum = -4;
                }
                if (ELMV == sim.Constants.Story.RestrictedMoraleModifier)
                {
                    skillnum = -2;
                }
                if (ELMV == sim.Constants.Story.NormalMoraleModifier)
                {
                    skillnum = 0;
                }
                if (ELMV == sim.Constants.Story.GenerousMoraleModifier)
                {
                    skillnum = 1;
                }
                if (ELMV == sim.Constants.Story.ExtravagantMoraleModifier)
                {
                    skillnum = 2;
                }

                string MString = ELMV.ToString();
                if (ELMV > 0)
                {
                    MString = "+" + MString;
                }
                string SString = skillnum.ToString() + " Techs";
                if (skillnum > 0)
                {
                    SString = "+" + SString;
                }

                string ModField         = MString + ", " + SString;
                var    instance         = Traverse.Create(__instance);
                var    moraleFieldValue = instance.Field("MoraleValueField").GetValue <TextMeshProUGUI>();
                instance.Method("SetField", new Type[] { typeof(LocalizableText), typeof(string) }, new object[] { moraleFieldValue, ModField }).GetValue();
            }
        }
Ejemplo n.º 10
0
        public static void Postfix(SGCaptainsQuartersStatusScreen __instance,
                                   EconomyScale expenditureLevel, bool showMoraleChange,
                                   Transform ___SectionTwoExpensesList, TextMeshProUGUI ___SectionTwoExpensesField,
                                   SimGameState ___simState)
        {
            // Redo all the mechwarrior cost
            float expenditureCostModifier = ___simState.GetExpenditureCostModifier(expenditureLevel);

            ClearListLineItems(___SectionTwoExpensesList, ___simState);
            int ongoingMechWariorCosts = 0;

            //int oldCosts = 0;
            List <KeyValuePair <string, int> > list = new List <KeyValuePair <string, int> >();

            foreach (Pilot item in ___simState.PilotRoster)
            {
                string key = item.pilotDef.Description.DisplayName;

                CrewDetails details = ModState.GetCrewDetails(item.pilotDef);
                //oldCosts += Mathf.CeilToInt(expenditureCostModifier * (float)___simState.GetMechWarriorValue(item.pilotDef));

                Mod.Log.Debug?.Write($" Pilot: {item.Name} has salary: {details.AdjustedSalary}");
                list.Add(new KeyValuePair <string, int>(key, details.AdjustedSalary));
            }

            // Sort by most expensive
            list.Sort((KeyValuePair <string, int> a, KeyValuePair <string, int> b) => b.Value.CompareTo(a.Value));

            // Create a new line item for each
            list.ForEach(delegate(KeyValuePair <string, int> entry)
            {
                ongoingMechWariorCosts += entry.Value;
                AddListLineItem(___SectionTwoExpensesList, ___simState, entry.Key,
                                SimGameState.GetCBillString(entry.Value));
            });

            ___SectionTwoExpensesField.SetText(SimGameState.GetCBillString(ongoingMechWariorCosts));

            // Rectify the salary field

            //SimGameState simGameState = UnityGameInstance.BattleTechGame.Simulation;
            //if (__instance == null || ___SectionOneExpensesList == null || ___SectionOneExpensesField == null || simGameState == null)
            //{
            //    Mod.Log.Debug?.Write($"SGCQSS:RD - skipping");
            //    return;
            //}

            //// TODO: Add this to mech parts maybe?
            ////float expenditureCostModifier = simGameState.GetExpenditureCostModifier(expenditureLevel);

            //// Determine the level of aerospace support
            ////Statistic aerospaceAssets = simGameState.CompanyStats.GetStatistic("AerospaceAssets");
            ////int aerospaceSupport = aerospaceAssets != null ? aerospaceAssets.Value<int>() : 0;

            //Mod.Log.Info?.Write($"SGCQSS:RD - entered. Parsing current keys.");

            //List<KeyValuePair<string, int>> currentKeys = GetCurrentKeys(___SectionOneExpensesList, ___simState);
            //// Extract the active mechs from the list, then re-add the updated price
            //List<KeyValuePair<string, int>> filteredKeys = FilterActiveMechs(currentKeys, ___simState);
            //List<KeyValuePair<string, int>> activeMechs = GetUpkeepLabels(___simState);
            //filteredKeys.AddRange(activeMechs);

            //// Add the new costs
            //int newActiveMechCosts = MonthlyCostCalcs.SumMonthlyMechCosts(___simState);

            //filteredKeys.Sort(new ExpensesSorter());

            //Mod.Log.Info?.Write($"SGCQSS:RD - Clearing items");
            //ClearListLineItems(___SectionOneExpensesList, ___simState);

            //Mod.Log.Info?.Write($"SGCQSS:RD - Adding listLineItems");
            //int totalCost = 0;
            //try
            //{
            //    foreach (KeyValuePair<string, int> kvp in filteredKeys)
            //    {
            //        Mod.Log.Info?.Write($"SGCQSS:RD - Adding key:{kvp.Key} value:{kvp.Value}");
            //        totalCost += kvp.Value;
            //        AddListLineItem(___SectionOneExpensesList, ___simState, kvp.Key, SimGameState.GetCBillString(kvp.Value));
            //    }

            //}
            //catch (Exception e)
            //{
            //    Mod.Log.Info?.Write($"SGCQSS:RD - failed to add lineItemParts due to: {e.Message}");
            //}

            //// Update summary costs
            //int newCosts = totalCost;
            //string newCostsS = SimGameState.GetCBillString(newCosts);
            //Mod.Log.Debug?.Write($"SGCQSS:RD - total:{newCosts} = activeMechs:{newActiveMechCosts}");

            //try
            //{
            //    ___SectionOneExpensesField.SetText(SimGameState.GetCBillString(newCosts));
            //    Mod.Log.Debug?.Write($"SGCQSS:RD - updated ");
            //}
            //catch (Exception e)
            //{
            //    Mod.Log.Info?.Write($"SGCQSS:RD - failed to update summary costs section due to: {e.Message}");
            //}
        }
Ejemplo n.º 11
0
        public static void Postfix(SGCaptainsQuartersStatusScreen __instance, EconomyScale expenditureLevel, bool showMoraleChange,
                                   Transform ___SectionOneExpensesList, TextMeshProUGUI ___SectionOneExpensesField,
                                   SimGameState ___simState)
        {
            SimGameState simGameState = UnityGameInstance.BattleTechGame.Simulation;

            if (__instance == null || ___SectionOneExpensesList == null || ___SectionOneExpensesField == null || simGameState == null)
            {
                Mod.Log.Debug($"SGCQSS:RD - skipping");
                return;
            }

            // TODO: Add this to mech parts maybe?
            //float expenditureCostModifier = simGameState.GetExpenditureCostModifier(expenditureLevel);

            // Determine the level of aerospace support
            Statistic aerospaceAssets  = simGameState.CompanyStats.GetStatistic("AerospaceAssets");
            int       aerospaceSupport = aerospaceAssets != null?aerospaceAssets.Value <int>() : 0;

            if (aerospaceSupport == 0)
            {
                Mod.Log.Debug($"SGCQSS:RD - no aerospace support configured, skipping.");
                return;
            }

            Mod.Log.Info($"SGCQSS:RD - entered. Parsing current keys.");
            List <KeyValuePair <string, int> > currentKeys = GetCurrentKeys(___SectionOneExpensesList, ___simState);
            int aerospaceCost = 0;

            switch (aerospaceSupport)
            {
            case 3:
                aerospaceCost = Mod.Config.HeavyWingMonthlyCost;
                currentKeys.Add(new KeyValuePair <string, int>($"Aerospace: Heavy Wing", Mod.Config.HeavyWingMonthlyCost));
                break;

            case 2:
                aerospaceCost = Mod.Config.MediumWingMonthlyCost;
                currentKeys.Add(new KeyValuePair <string, int>($"Aerospace: Medium Wing", Mod.Config.MediumWingMonthlyCost));
                break;

            case 1:
                aerospaceCost = Mod.Config.LightWingMonthlyCost;
                currentKeys.Add(new KeyValuePair <string, int>($"Aerospace: Light Wing", Mod.Config.LightWingMonthlyCost));
                break;
            }
            currentKeys.Sort(new ExpensesSorter());

            Mod.Log.Info($"SGCQSS:RD - Clearing items");
            ClearListLineItems(___SectionOneExpensesList, ___simState);

            Mod.Log.Info($"SGCQSS:RD - Adding listLineItems");
            int totalCost = 0;

            try {
                foreach (KeyValuePair <string, int> kvp in currentKeys)
                {
                    Mod.Log.Info($"SGCQSS:RD - Adding key:{kvp.Key} value:{kvp.Value}");
                    totalCost += kvp.Value;
                    AddListLineItem(___SectionOneExpensesList, ___simState, kvp.Key, SimGameState.GetCBillString(kvp.Value));
                }
            } catch (Exception e) {
                Mod.Log.Info($"SGCQSS:RD - failed to add lineItemParts due to: {e.Message}");
            }

            // Update summary costs
            int    newCosts  = totalCost;
            string newCostsS = SimGameState.GetCBillString(newCosts);

            Mod.Log.Debug($"SGCQSS:RD - total:{newCosts}");

            try {
                ___SectionOneExpensesField.SetText(SimGameState.GetCBillString(newCosts));
                Mod.Log.Debug($"SGCQSS:RD - updated ");
            } catch (Exception e) {
                Mod.Log.Info($"SGCQSS:RD - failed to update summary costs section due to: {e.Message}");
            }
        }