static void Postfix(SGEventPanel __instance, SimGameEventOption option,
                            SimGameInterruptManager.EventPopupEntry ___thisEntry)
        {
            if (___thisEntry != null && ___thisEntry.parameters != null &&
                ___thisEntry.parameters[0] is SimGameEventDef eventDef)
            {
                if (ModConsts.Event_ContractExpired.Equals(eventDef.Description.Id))
                {
                    // Handle updating the contract length in the def; funds are handled by the event.
                    if (ModConsts.Event_Option_ContractExpired_Hire_NoBonus.Equals(option.Description.Id) ||
                        ModConsts.Event_Option_ContractExpired_Hire_Bonus.Equals(option.Description.Id))
                    {
                        (Pilot Pilot, CrewDetails Details)expired = ModState.ExpiredContracts.Peek();

                        Mod.Log.Debug?.Write($"Pilot {expired.Pilot.Name} was re-hired w/o a bonus");
                        expired.Details.ExpirationDay = ModState.SimGameState.DaysPassed + expired.Details.ContractTerm;
                        ModState.UpdateOrCreateCrewDetails(expired.Pilot.pilotDef, expired.Details);
                    }
                }
                else if (ModConsts.Event_HeadHunting.Equals(eventDef.Description.Id))
                {
                    // TODO: Anything?
                }
            }
        }
        public static PilotDef UpgradeRonin(StarSystem starSystem, PilotDef baseRoninDef)
        {
            CrewDetails details = ReadRoninTags(baseRoninDef);

            ModState.UpdateOrCreateCrewDetails(baseRoninDef, details);
            return(baseRoninDef);
        }
        public static CrewDetails GenerateDetailsForVanillaMechwarrior(PilotDef basePilotDef, bool isFounder = false)
        {
            (FactionValue favored, FactionValue hated) = GenerateCrewFactions(null);
            CrewDetails details = new CrewDetails(basePilotDef, CrewType.MechWarrior, favored, hated);

            ModState.UpdateOrCreateCrewDetails(basePilotDef, details);
            Mod.Log.Info?.Write($" -- pilotDef associated with GUID: {details.GUID}");

            return(details);
        }
        // === COMBAT CREWS ===
        public static PilotDef GenerateMechWarrior(StarSystem starSystem)
        {
            PilotDef crew = GenerateSkilledCrew(starSystem, true);

            Mod.Log.Debug?.Write($"CREATED MECHWARRIOR CREW");

            (FactionValue favored, FactionValue hated) = GenerateCrewFactions(starSystem);
            CrewDetails details = new CrewDetails(crew, CrewType.MechWarrior, favored, hated);

            ModState.UpdateOrCreateCrewDetails(crew, details);
            return(crew);
        }
        public static PilotDef GenerateVehicleCrew(StarSystem starSystem)
        {
            PilotDef crew = GenerateSkilledCrew(starSystem, false);

            Mod.Log.Debug?.Write($"CREATED VEHICLE CREW");

            (FactionValue favored, FactionValue hated) = GenerateCrewFactions(starSystem);
            CrewDetails details = new CrewDetails(crew, CrewType.VehicleCrew, favored, hated);

            ModState.UpdateOrCreateCrewDetails(crew, details);

            return(crew);
        }
        public static PilotDef GenerateAerospaceCrew(StarSystem starSystem)
        {
            int    callsignIdx = Mod.Random.Next(0, Mod.CrewNames.Aerospace.Count - 1);
            string newCallsign = Mod.CrewNames.Aerospace[callsignIdx];

            PilotDef def = GenerateSkillessCrew(starSystem, newCallsign, out int crewSize, out int crewSkill);

            // Before returning, initialize the cache value
            (FactionValue favored, FactionValue hated) = GenerateCrewFactions(starSystem);
            CrewDetails details = new CrewDetails(def, CrewType.AerospaceWing, favored, hated, crewSize, crewSkill);

            ModState.UpdateOrCreateCrewDetails(def, details);

            return(def);
        }
        static bool Prefix(SGBarracksRosterList __instance,
                           Pilot pilot, UnityAction <SGBarracksRosterSlot> pilotSelectedOnClick, bool isInHireHall,
                           Dictionary <string, SGBarracksRosterSlot> ___currentRoster)
        {
            if (ModState.SimGameState == null)
            {
                return(true);                               // Only patch if we're in SimGame
            }
            Mod.Log.Debug?.Write($"Adding pilot {pilot.Callsign} to roster list.");

            if (!___currentRoster.ContainsKey(pilot.GUID))
            {
                SGBarracksRosterSlot slot = __instance.GetSlot();
                if (isInHireHall)
                {
                    slot.InitNoDrag(pilot, ModState.SimGameState, pilotSelectedOnClick, showTheCost: true);
                    slot.SetDraggable(isDraggable: false);

                    // Update the pilot's contract end date
                    CrewDetails details = ModState.GetCrewDetails(pilot.pilotDef);
                    details.ExpirationDay = ModState.SimGameState.DaysPassed + details.ContractTerm;
                    Mod.Log.Debug?.Write($"  - pilot's contract ends on day: {details.ExpirationDay}");
                    ModState.UpdateOrCreateCrewDetails(pilot.pilotDef, details);
                }
                else
                {
                    slot.Init(pilot, __instance, pilotSelectedOnClick);
                }
                ___currentRoster.Add(pilot.GUID, slot);
                slot.AddToRadioSet(__instance.listRadioSet);

                // Performance tweak; skip
                //ForceRefreshImmediate();
            }

            return(false);
        }
Example #8
0
        static void Postfix(BattleTech.UI.AAR_ContractResults_Screen __instance, Contract ___theContract)
        {
            StringBuilder bodySB = new StringBuilder();

            bodySB.Append(new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Body], new object[] { }).ToString());

            int killedPilotsMod = Mod.Config.Attitude.PerMission.PilotKilledMod * ___theContract.KilledPilots.Count;

            if (___theContract.KilledPilots.Count > 0)
            {
                Mod.Log.Debug?.Write($"Player lost {___theContract.KilledPilots.Count} pilots, applying a modifier of {killedPilotsMod} to all pilots.");
                bodySB.Append(
                    new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Mod_Pilot_Killed],
                             new object[] { killedPilotsMod }).ToString()
                    );
            }

            // Add the monospace tag
            bodySB.Append(new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Mod_Font], new object[] { }).ToString());

            // Calculate the contract bonus
            int contractBonus = Mod.Config.Attitude.PerMission.ContractFailedMod;

            if (___theContract.State == Contract.ContractState.Complete)
            {
                contractBonus = Mod.Config.Attitude.PerMission.ContractSuccessMod;
                Mod.Log.Debug?.Write($"Contract was successful, applying contract modifier of: {contractBonus}");
                bodySB.Append(
                    new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Mod_Contract_Success],
                             new object[] { contractBonus }).ToString()
                    );
            }
            else if (___theContract.IsGoodFaithEffort)
            {
                contractBonus = Mod.Config.Attitude.PerMission.ContractFailedGoodFaithMod;
                Mod.Log.Debug?.Write($"Contract was a good faith effort, applying contract modifier of: {contractBonus}");
                bodySB.Append(
                    new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Mod_Contract_GoodFaith],
                             new object[] { contractBonus }).ToString()
                    );
            }
            else
            {
                Mod.Log.Debug?.Write($"Contract was failed, applying contract modifier of: {contractBonus}");
                bodySB.Append(
                    new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Mod_Contract_Failed],
                             new object[] { contractBonus }).ToString()
                    );
            }
            bodySB.Append("\n");

            // Find just combat pilots (for benched mod)
            List <Pilot> allPilots    = __instance.Sim.PilotRoster.ToList();
            List <Pilot> combatPilots = allPilots.Where(p =>
            {
                CrewDetails details = ModState.GetCrewDetails(p.pilotDef);
                return(details.IsCombatCrew);
            }).ToList();

            Mod.Log.Debug?.Write($"All Combat pilots are: {string.Join(", ", combatPilots.Select(p => p.Name).ToList())}");

            List <Pilot> deployedPilots = ___theContract.PlayerUnitResults.Select(ur => ur.pilot).ToList();

            Mod.Log.Debug?.Write($"Deployed pilots were: {string.Join(", ", deployedPilots.Select(p => p.Name).ToList())}");

            // Iterate pilots apply modifiers
            foreach (Pilot p in allPilots)
            {
                CrewDetails details = ModState.GetCrewDetails(p.pilotDef);

                if (details.IsPlayer)
                {
                    continue;
                }

                int startingAttitude = details.Attitude;

                Mod.Log.Debug?.Write($"Applying attitude modifiers to pilot: {p.Name}");

                // Apply modifier for contract success
                details.Attitude += contractBonus;

                // Applied killed pilots modifier
                details.Attitude += killedPilotsMod;

                List <string> detailDescs = new List <string>();
                // Check for bench - only applies to combat pilots
                if (deployedPilots.Contains(p))
                {
                    Mod.Log.Debug?.Write($" -- combat pilot was deployed, adding {Mod.Config.Attitude.PerMission.DeployedOnMissionMod} attitude");
                    details.Attitude += Mod.Config.Attitude.PerMission.DeployedOnMissionMod;
                    detailDescs.Add(
                        new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Mod_Deployed],
                                 new object[] { Mod.Config.Attitude.PerMission.DeployedOnMissionMod }).ToString()
                        );
                }
                else if (combatPilots.Contains(p))
                {
                    Mod.Log.Debug?.Write($" -- combat pilot was benched, adding {Mod.Config.Attitude.PerMission.BenchedOnMissionMod} attitude");
                    details.Attitude += Mod.Config.Attitude.PerMission.BenchedOnMissionMod;
                    detailDescs.Add(
                        new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Mod_Benched],
                                 new object[] { Mod.Config.Attitude.PerMission.BenchedOnMissionMod }).ToString()
                        );
                }

                // Check favored / hated factions
                if (details.FavoredFactionId > 0)
                {
                    if (details.FavoredFactionId == ___theContract.Override.employerTeam.FactionValue.FactionID)
                    {
                        Mod.Log.Debug?.Write($" -- pilot favors employer faction, applying modifier: {Mod.Config.Attitude.PerMission.FavoredFactionIsEmployerMod}");
                        details.Attitude += Mod.Config.Attitude.PerMission.FavoredFactionIsEmployerMod;
                        detailDescs.Add(
                            new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Mod_Favored_Employer],
                                     new object[] { Mod.Config.Attitude.PerMission.FavoredFactionIsEmployerMod }).ToString()
                            );
                    }

                    if (details.FavoredFactionId == ___theContract.Override.targetTeam.FactionValue.FactionID)
                    {
                        Mod.Log.Debug?.Write($" -- pilot favors target faction, applying modifier: {Mod.Config.Attitude.PerMission.FavoredFactionIsTargetMod}");
                        details.Attitude += Mod.Config.Attitude.PerMission.FavoredFactionIsTargetMod;
                        detailDescs.Add(
                            new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Mod_Favored_Target],
                                     new object[] { Mod.Config.Attitude.PerMission.FavoredFactionIsTargetMod }).ToString()
                            );
                    }
                }

                if (details.HatedFactionId > 0)
                {
                    if (details.HatedFactionId == ___theContract.Override.employerTeam.FactionValue.FactionID)
                    {
                        Mod.Log.Debug?.Write($" -- pilot hates employer faction, applying modifier: {Mod.Config.Attitude.PerMission.HatedFactionIsEmployerMod}");
                        details.Attitude += Mod.Config.Attitude.PerMission.HatedFactionIsEmployerMod;
                        detailDescs.Add(
                            new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Mod_Hated_Employer],
                                     new object[] { Mod.Config.Attitude.PerMission.HatedFactionIsEmployerMod }).ToString()
                            );
                    }

                    if (details.HatedFactionId == ___theContract.Override.targetTeam.FactionValue.FactionID)
                    {
                        Mod.Log.Debug?.Write($" -- pilot hates target faction, applying modifier: {Mod.Config.Attitude.PerMission.HatedFactionIsTargetMod}");
                        details.Attitude += Mod.Config.Attitude.PerMission.HatedFactionIsTargetMod;
                        detailDescs.Add(
                            new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Mod_Hated_Target],
                                     new object[] { Mod.Config.Attitude.PerMission.HatedFactionIsTargetMod }).ToString()
                            );
                    }
                }

                // Clamp values to max and min
                details.Attitude = Mathf.Clamp(details.Attitude, Mod.Config.Attitude.ThresholdMin, Mod.Config.Attitude.ThresholdMax);

                string detailsS = string.Join(", ", detailDescs);
                bodySB.Append(
                    new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Pilot_Line],
                             new object[] { details.Attitude, p.Callsign, detailsS }).ToString()
                    );

                ModState.UpdateOrCreateCrewDetails(p.pilotDef, details);
            }

            // Close the mspace tag
            bodySB.Append("</mspace>");

            // Display a dialog with changes
            string       localDialogTitle = new Text(Mod.LocalizedText.Dialogs[ModText.DIAT_AAR_Title]).ToString();
            string       localDialogText  = bodySB.ToString();
            GenericPopup gp = GenericPopupBuilder.Create(localDialogTitle, localDialogText)
                              .Render();

            TextMeshProUGUI contentText = (TextMeshProUGUI)Traverse.Create(gp).Field("_contentText").GetValue();

            contentText.alignment = TextAlignmentOptions.Left;
        }
        static void Postfix(SimGameState __instance)
        {
            List <FactionValue> alliedFactions = new List <FactionValue>();

            foreach (string factionName in __instance.GetAllCareerAllies())
            {
                alliedFactions.Add(FactionEnumeration.GetFactionByName(factionName));
            }

            foreach (Pilot pilot in __instance.PilotRoster)
            {
                CrewDetails details = ModState.GetCrewDetails(pilot.pilotDef);

                // Decay positive attitude
                if (details.Attitude > 0)
                {
                    int decayAmount = (int)Math.Ceiling(details.Attitude * Mod.Config.Attitude.Monthly.Decay);
                    Mod.Log.Debug?.Write($"Decaying positive attitude from {details.Attitude} by {decayAmount}");
                    details.Attitude -= decayAmount;
                }

                // Apply the morale modifier
                int econMod = Mod.Config.Attitude.Monthly.EconomyNormalMod;
                if (__instance.ExpenditureLevel == EconomyScale.Spartan)
                {
                    econMod = Mod.Config.Attitude.Monthly.EconSpartanMod;
                }
                else if (__instance.ExpenditureLevel == EconomyScale.Restrictive)
                {
                    econMod = Mod.Config.Attitude.Monthly.EconRestrictiveMod;
                }
                else if (__instance.ExpenditureLevel == EconomyScale.Generous)
                {
                    econMod = Mod.Config.Attitude.Monthly.EconomyGenerousMod;
                }
                else if (__instance.ExpenditureLevel == EconomyScale.Extravagant)
                {
                    econMod = Mod.Config.Attitude.Monthly.EconomyExtravagantMod;
                }
                details.Attitude += econMod;

                // Check pilots to see if they favor or hate an allied faction
                if (details.FavoredFactionId > 0 && !details.IsPlayer)
                {
                    foreach (FactionValue faction in alliedFactions)
                    {
                        if (faction.FactionID == details.FavoredFactionId)
                        {
                            Mod.Log.Debug?.Write($"Pilot {pilot.Name} favors allied faction: {faction.FriendlyName}, " +
                                                 $"applying attitude mod: {Mod.Config.Attitude.Monthly.FavoredEmployerAlliedMod}");
                            details.Attitude += Mod.Config.Attitude.Monthly.FavoredEmployerAlliedMod;
                            ModState.UpdateOrCreateCrewDetails(pilot.pilotDef, details);
                        }
                    }
                }

                if (details.HatedFactionId > 0 && !details.IsPlayer)
                {
                    foreach (FactionValue faction in alliedFactions)
                    {
                        if (faction.FactionID == details.HatedFactionId)
                        {
                            Mod.Log.Debug?.Write($"Pilot {pilot.Name} hates allied faction: {faction.FriendlyName}, " +
                                                 $"applying attitude mod: {Mod.Config.Attitude.Monthly.HatedEmployerAlliedMod}");
                            details.Attitude += Mod.Config.Attitude.Monthly.HatedEmployerAlliedMod;
                            ModState.UpdateOrCreateCrewDetails(pilot.pilotDef, details);
                        }
                    }
                }

                // Clamp values
                details.Attitude = Mathf.Clamp(details.Attitude, Mod.Config.Attitude.ThresholdMin, Mod.Config.Attitude.ThresholdMax);

                ModState.UpdateOrCreateCrewDetails(pilot.pilotDef, details);
            }
        }