Exemplo n.º 1
0
        public static void Prefix(Contract __instance, MissionResult result, bool isGoodFaithEffort)
        {
            if (__instance != null && !__instance.ContractTypeValue.IsSkirmish)
            {
                SimGameState simulation = HBS.LazySingletonBehavior <UnityGameInstance> .Instance.Game.Simulation;

                ModState.Employer = __instance.GetTeamFaction("ecc8d4f2-74b4-465d-adf6-84445e5dfc230");
                SimGameReputation employerRep = simulation.GetReputation(ModState.Employer);
                ModState.EmployerRep    = employerRep;
                ModState.EmployerRepRaw = simulation.GetRawReputation(ModState.Employer);

                ModState.IsEmployerAlly = simulation.IsFactionAlly(ModState.Employer);
                ModState.MRBRating      = simulation.GetCurrentMRBLevel(); // Normalize to 0 indexing
                Mod.Log.Info?.Write($"At contract start for employer: Employer:({ModState.Employer}):  " +
                                    $"employerRep:{ModState.EmployerRep}  employerIsAllied:{ModState.IsEmployerAlly}  " +
                                    $"MRBRating: {ModState.MRBRating}  MRBIndex: {Helper.MRBCfgIdx()}");

                // Calculate the rollup, reputation and etc:
                Mod.Log.Info?.Write($" -- Contract Rollup Idx: {Helper.MRBCfgIdx()} => " +
                                    $"RawRollup: {Mod.Config.RollupMRBValue[Helper.MRBCfgIdx()]}");
                RepCfg repCfg = Mod.Config.Reputation[Helper.FactionCfgIdx()];
                Mod.Log.Info?.Write($" -- Faction Rep Idx: {Helper.FactionCfgIdx()} => " +
                                    $"Reputation: {repCfg.Reputation}  " +
                                    $"RollupMultiComponent: {repCfg.RollupMultiComponent}  RollupMultiMech: {repCfg.RollupMultiMech}  " +
                                    $"HoldbackTrigger: {repCfg.HoldbackTrigger}  HoldbackValueCapMulti: {repCfg.HoldbackValueCapMulti}");
            }
        }
Exemplo n.º 2
0
        public static float GetSalvageThreshold(bool forMech = false)
        {
            RepCfg repCfg = Mod.Config.Reputation.Find(r => r.Reputation == (Rep)FactionCfgIdx());
            float  multi  = forMech ? repCfg.RollupMultiMech : repCfg.RollupMultiComponent;

            float rollup = Mod.Config.RollupMRBValue[MRBCfgIdx()];
            float result = (float)Math.Floor(rollup * multi);

            Mod.Log.Debug($"rollup:{rollup} x multi:{multi} = result:{result}");
            return(result);
        }
Exemplo n.º 3
0
        public static float GetHoldbackTriggerChance()
        {
            RepCfg repCfg = Mod.Config.Reputation.Find(r => r.Reputation == (Rep)FactionCfgIdx());

            return(repCfg.HoldbackTrigger);
        }
Exemplo n.º 4
0
        public static void CalculateCompensation(List <SalvageDef> potentialSalvage)
        {
            if (State.HeldbackParts == null || State.HeldbackParts.Count == 0)
            {
                return;
            }

            double compensation         = 0;
            int    valueCap             = 0;
            int    mechPartsForAssembly = UnityGameInstance.BattleTechGame.Simulation.Constants.Story.DefaultMechPartMax;

            foreach (SalvageDef mechPart in State.HeldbackParts)
            {
                int adjustedCost = (int)Math.Ceiling(mechPart.Description.Cost / (double)mechPartsForAssembly);
                if (adjustedCost >= valueCap)
                {
                    valueCap = adjustedCost;
                }
                compensation += adjustedCost;
                Mod.Log.Info($"Mech part:({mechPart.Description.Id}::{mechPart.Description.Name}) has " +
                             $"raw cost:{mechPart.Description.Cost} / {mechPartsForAssembly} = {adjustedCost}");
            }

            RepCfg repCfg      = Mod.Config.Reputation.Find(r => r.Reputation == (Rep)FactionCfgIdx());
            double adjValueCap = Math.Ceiling(valueCap * repCfg.HoldbackValueCapMulti);

            Mod.Log.Info($"Total compensation: {compensation} valueCap:{valueCap} adjValueCap:{adjValueCap}");

            // Filter to components only
            List <SalvageDef> allComponents = potentialSalvage.Where(sd => sd.Type == SalvageDef.SalvageType.COMPONENT).ToList();

            foreach (SalvageDef compSDef in allComponents)
            {
                Mod.Log.Info($"   Component:{compSDef.Description.Id}::{compSDef.Description.Name}");
                if (compSDef.Description.Cost > adjValueCap)
                {
                    Mod.Log.Info($"   cost:{compSDef.Description.Cost} greater than cap, skipping.");
                }
                else if (compSDef.Description.Cost > compensation)
                {
                    Mod.Log.Info($"   remaining compensation:{compensation} less than cost:{compSDef.Description.Cost}, skipping.");
                }
                else
                {
                    int available = (int)Math.Floor(compensation / compSDef.Description.Cost);
                    Mod.Log.Info($" - remaining compensation:{compensation} / cost: {compSDef.Description.Cost} = available:{available}");

                    // TODO: Test for too large a stack here / do div by 3 to reduce large stacks
                    int adjAvailable = (available > 10) ? (int)Math.Ceiling(available / 3.0f) : available;

                    SalvageDef equivDef = new SalvageDef(compSDef)
                    {
                        Count = compSDef.Count + adjAvailable
                    };
                    State.CompensationParts.Add(equivDef);
                    Mod.Log.Info($" - rawCount:{compSDef.Count} to adjCost:{equivDef.Count}");

                    // Reduce the remaining compensation
                    compensation = compensation - (compSDef.Description.Cost * adjAvailable);
                }
            }

            if (compensation > 0)
            {
                // TODO: Should this come back as cbills?
                Mod.Log.Info($" Compensation of {compensation} remaining and unpaid!");
            }
        }