Beispiel #1
0
        public static void Prefix(SimGameEventOption option, SimGameEventTracker tracker)
        {
            foreach (SimGameEventResultSet eventResultSet in option.ResultSets)
            {
                foreach (SimGameEventResult eventResult in eventResultSet.Results)
                {
                    if (eventResult.Stats != null)
                    {
                        for (int i = 0; i < eventResult.Stats.Length; i++)
                        {
                            switch (eventResult.Stats[i].name)
                            {
                            case "Morale":
                                eventResult.Stats[i].value = (int.Parse(eventResult.Stats[i].value) * AugmentedEvents.Settings.MoraleMultiplier).ToString();
                                break;

                            case "MechTechSkill":
                                eventResult.Stats[i].value = (int.Parse(eventResult.Stats[i].value) * AugmentedEvents.Settings.MechTechSkillMultiplier).ToString();
                                break;

                            case "MedTechSkill":
                                eventResult.Stats[i].value = (int.Parse(eventResult.Stats[i].value) * AugmentedEvents.Settings.MedTechSkillMultiplier).ToString();
                                break;
                            }
                        }
                    }
                }
            }
            AugmentedEvents.LastModifiedOption = option;
        }
        static void Postfix(SimGameInterruptManager.EventPopupEntry entry, SimGameEventTracker ___mechWarriorEventTracker)
        {
            SimGameEventDef evt = entry != null && entry.parameters[0] is SimGameEventDef ? (SimGameEventDef)entry.parameters[0] : null;

            if (String.Equals(ModConsts.Event_ContractExpired, evt?.Description?.Id))
            {
                // First, dequeue to remove any existing pilot
                if (ModState.ExpiredContracts.Count > 0)
                {
                    ModState.ExpiredContracts.Dequeue();
                }

                // If there are any other events left after that, fire them here.
                if (ModState.ExpiredContracts.Count > 0)
                {
                    (Pilot Pilot, CrewDetails Details)expired = ModState.ExpiredContracts.Peek();
                    SimGameEventDef newEvent = EventHelper.ModifyContractExpirationEventForPilot(expired.Pilot, expired.Details);
                    Mod.Log.Info?.Write($"Contract expiration event fired.");
                    ModState.SimGameState.OnEventTriggered(newEvent, EventScope.MechWarrior, ___mechWarriorEventTracker);
                }
            }

            else if (String.Equals(ModConsts.Event_HeadHunting, evt?.Description?.Id))
            {
                ModState.HeadHuntedPilot = null;
            }
        }
Beispiel #3
0
        public static void FireEvent(SimGameState simGame, SimGameEventDef eventDef)
        {
            Main.HBSLog.Log($"Firing event {eventDef.Description.Id}");

            var eventTracker = new SimGameEventTracker();

            eventTracker.Init(new[] { EventScope.Company }, 0, 0, SimGameEventDef.SimEventType.NORMAL, simGame);
            simGame.InterruptQueue.QueueEventPopup(eventDef, EventScope.Company, eventTracker);
        }
Beispiel #4
0
            public static void Postfix(SimGameState __instance, SimGameEventTracker ___companyEventTracker)
            {
                void ActivateAnyEvent(float eventChance)
                {
                    float randomRoll = __instance.NetworkRandom.Float(0f, 1f);

                    if (randomRoll < eventChance)
                    {
                        Logger.Debug("----------------------------------------------------------------------------------------------------");
                        Logger.Debug("[SimGameState_OnDayPassed_POSTFIX] ActivateRandomEvent");
                        Logger.Debug("----------------------------------------------------------------------------------------------------");
                        ___companyEventTracker.ActivateRandomEvent();
                    }
                }

                void ActivateSpecialEvent(string eventId, float eventChance)
                {
                    if (SpecialEventCounter >= SpecialEventMax)
                    {
                        Logger.Debug("[SimGameState_OnDayPassed_POSTFIX] SpecialEventMax(" + SpecialEventMax + ") reached. Exiting.");
                        return;
                    }
                    SpecialEventCounter++;

                    float randomRoll = __instance.NetworkRandom.Float(0f, 1f);

                    if (randomRoll < eventChance)
                    {
                        Pilot plt = null;
                        SimGameForcedEvent evt = new SimGameForcedEvent
                        {
                            Scope       = EventScope.Company,
                            EventID     = eventId,
                            MinDaysWait = 0,
                            MaxDaysWait = 0,
                            Probability = 100,
                            RetainPilot = false
                        };
                        Logger.Debug("----------------------------------------------------------------------------------------------------");
                        Logger.Debug("[SimGameState_OnDayPassed_POSTFIX] AddSpecialEvent");
                        Logger.Debug("----------------------------------------------------------------------------------------------------");
                        __instance.AddSpecialEvent(evt, plt);
                    }
                }

                bool activateEvent = DaysUneventfulCounter++ == DaysUneventful;

                if (activateEvent)
                {
                    DaysUneventfulCounter = 0;
                    ActivateSpecialEvent("event_dcm_test", 1f);
                    //ActivateAnyEvent(0.2f);
                }
            }
        static void Postfix(SimGameState __instance, int timeLapse, SimGameInterruptManager ___interruptQueue,
                            SimGameEventTracker ___companyEventTracker, SimGameEventTracker ___mechWarriorEventTracker,
                            SimGameEventTracker ___deadEventTracker, SimGameEventTracker ___moraleEventTracker)
        {
            Mod.Log.Debug?.Write($"OnDayPassed called with timeLapse: {timeLapse}");

            // Only check for events if another event isn't firing, and we're in orbit around a system
            if (!___interruptQueue.IsOpen && __instance.TravelState == SimGameTravelStatus.IN_SYSTEM)
            {
                foreach (Pilot pilot in __instance.PilotRoster)
                {
                    CrewDetails details = ModState.GetCrewDetails(pilot.pilotDef);
                    if (details.ExpirationDay <= __instance.DaysPassed)
                    {
                        Mod.Log.Debug?.Write($"CONTRACT FOR PILOT: {pilot.Name} HAS ELAPSED, FIRING EVENT");
                        ModState.ExpiredContracts.Enqueue((pilot, details));
                    }
                }

                if (ModState.ExpiredContracts.Count > 0)
                {
                    // Fire the first event, if there are more they will be fired from OnEventDismissed{
                    Mod.Log.Info?.Write($"Contract expiration event fired.");
                    (Pilot Pilot, CrewDetails Details)expired = ModState.ExpiredContracts.Peek();
                    SimGameEventDef newEvent = EventHelper.ModifyContractExpirationEventForPilot(expired.Pilot, expired.Details);
                    ModState.SimGameState.OnEventTriggered(newEvent, EventScope.MechWarrior, ___mechWarriorEventTracker);
                }
                else if (Mod.Config.HeadHunting.Enabled && __instance.TravelState == SimGameTravelStatus.IN_SYSTEM)
                {
                    // TODO: Only do check if not at planet with blacklisted tags
                    if (HeadHuntingHelper.ShouldCheckHeadHunting())
                    {
                        Pilot headHuntedCrew = HeadHuntingHelper.TestAllCrews();

                        if (headHuntedCrew != null)
                        {
                            CrewDetails     cd       = ModState.GetCrewDetails(headHuntedCrew.pilotDef);
                            SimGameEventDef newEvent = EventHelper.CreateHeadHuntingEvent(headHuntedCrew, cd, cd.HiringBonus, cd.HiringBonus);
                            ModState.HeadHuntedPilot = headHuntedCrew;
                            ModState.SimGameState.OnEventTriggered(newEvent, EventScope.MechWarrior, ___mechWarriorEventTracker);

                            HeadHuntingHelper.UpdateNextDayOnSuccess();
                        }
                        else
                        {
                            HeadHuntingHelper.UpdateNextDayOnFailure();
                        }
                    }
                }
            }
        }
        public static void Postfix(SimGameEventTracker __instance, bool __result, EventScope scope, EventDef_MDD evt)
        {
            try
            {
                //Logger.Info($"[SimGameEventTracker_IsEventValid_POSTFIX] evt.EventDefID: {evt.EventDefID}");
                //Logger.Info($"[SimGameEventTracker_IsEventValid_POSTFIX] scope: {scope}");
                //Logger.Info($"[SimGameEventTracker_IsEventValid_POSTFIX] __result: {__result}");

                if (__result)
                {
                    Logger.Info($"[SimGameEventTracker_IsEventValid_POSTFIX] Currently valid event id: {evt.EventDefID}");
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
        public static void Prefix(SimGameEventTracker __instance, ref float randomRoll, float ___eventChance, float ___chanceIncrement)
        {
            try
            {
                Logger.Info($"[SimGameEventTracker_CheckRoll_PREFIX] (ORIGINAL) randomRoll: {randomRoll}");
                Logger.Info($"[SimGameEventTracker_CheckRoll_PREFIX] ___eventChance: {___eventChance}");
                Logger.Info($"[SimGameEventTracker_CheckRoll_PREFIX] ___chanceIncrement: {___chanceIncrement}");

                // Tweak the roll to slightly raise the frequency of events
                float modifiedRoll = randomRoll - 10;
                randomRoll = Mathf.Clamp(modifiedRoll, 0f, 100f);

                Logger.Info($"[SimGameEventTracker_CheckRoll_PREFIX] (TWEAKED) randomRoll: {randomRoll}");
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
        public static void Postfix(SimGameEventTracker __instance, SimGameEventTracker.PotentialEvent __result, ref List <string> ___discardList, SimGameState ___sim)
        {
            try
            {
                Logger.Info($"[SimGameEventTracker_GetRandomEvent_POSTFIX] __result.Def.Description.Id: {__result.Def.Description.Id}");
                Logger.Info($"[SimGameEventTracker_GetRandomEvent_POSTFIX] ___discardList: {String.Join(", ", ___discardList.ToArray())}");
                Logger.Info($"[SimGameEventTracker_GetRandomEvent_POSTFIX] ___sim.CompanyTags: {String.Join(", ", ___sim.CompanyTags.ToArray())}");

                // Remove custom events from discardList to allow them to reoccur earlier (after their exclusion tags expire)
                // REQUIRES custom exclusion tag in SimGameEventDef
                if (__result.Def.Requirements.ExclusionTags.Contains("starsystem_opportunitymission_active"))
                {
                    ___discardList.Remove(__result.Def.Description.Id);
                }

                Logger.Info($"[SimGameEventTracker_GetRandomEvent_POSTFIX] ___discardList: {String.Join(", ", ___discardList.ToArray())}");
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
Beispiel #9
0
        static bool Prefix(SimGameEventTracker __instance, EventScope scope, EventDef_MDD evt, List <TagSet> reqList,
                           out SimGameEventTracker.PotentialEvent goodEvent, ref bool __result,
                           SimGameState ___sim, SimGameReport.ReportEntry ___VerboseEntry)
        {
            goodEvent = null;

            Mod.Log.Debug?.Write($"Validating event with defId: {evt?.EventDefID}");

            // Skip any HR events and use the base validation
            if (evt != null &&
                (String.Equals(ModConsts.Event_ContractExpired, evt.EventDefID, StringComparison.InvariantCulture) ||
                 String.Equals(ModConsts.Event_HeadHunting, evt.EventDefID, StringComparison.InvariantCulture))
                )
            {
                return(true);
            }

            Traverse pushRecordT = Traverse.Create(__instance).Method("PushRecord", new Type[] { typeof(string) });
            Traverse popRecordT  = Traverse.Create(__instance).Method("PopRecord");

            int num = 0;

            if (scope == EventScope.Company)
            {
                num = 1;
            }
            else if (scope == EventScope.MechWarrior)
            {
                num = AllMechWarriors().Count();
            }
            else if (scope == EventScope.DeadMechWarrior)
            {
                num = ___sim.Graveyard.Count;
            }

            int i = 0;

            while (i < num)
            {
                Pilot pilot = null;
                if (scope == EventScope.MechWarrior)
                {
                    pilot = NextSGSMechwarrior();
                    if (pilot.pilotDef.TimeoutRemaining <= 0)
                    {
                        reqList.Clear();
                        reqList.Add(pilot.pilotDef.PilotTags);
                        pushRecordT.GetValue(new object[] { string.Format("Event For {0}", pilot.Callsign) });
                        goto IL_C7;
                    }
                }
                else
                {
                    if (scope == EventScope.DeadMechWarrior)
                    {
                        pilot = ___sim.Graveyard.GetNext(true);
                        reqList.Clear();
                        reqList.Add(pilot.pilotDef.PilotTags);
                        goto IL_C7;
                    }
                    goto IL_C7;
                }
IL_65E:
                i++;
                continue;
IL_C7:
                for (int j = 0; j < reqList.Count; j++)
                {
                    TagSet curTags = reqList[j];
                    __instance.RecordLog("Attempting Event: " + evt.EventDefID, SimGameLogLevel.VERBOSE);


                    if (!___sim.DataManager.SimGameEventDefs.Exists(evt.EventDefID))
                    {
                        Mod.Log.Warn?.Write($"Event {evt.EventDefID} cannot be found in manifest. Skipping.");
                    }
                    else
                    {
                        SimGameEventDef simGameEventDef = ___sim.DataManager.SimGameEventDefs.Get(evt.EventDefID);
                        if (scope == EventScope.MechWarrior)
                        {
                            ___sim.Context.SetObject(GameContextObjectTagEnum.TargetMechWarrior, pilot);
                        }
                        StatCollection statsByScope = ___sim.GetStatsByScope(scope);
                        pushRecordT.GetValue(new object[] { evt.EventDefID });
                        if (SimGameState.MeetsRequirements(simGameEventDef.Requirements, curTags, statsByScope, ___VerboseEntry))
                        {
                            __instance.RecordLog("Passed!", SimGameLogLevel.VERBOSE);
                            popRecordT.GetValue();
                            __instance.RecordLog("Testing for additional requirements", SimGameLogLevel.VERBOSE);
                            pushRecordT.GetValue(new object[] { simGameEventDef.Description.Id });
                            bool flag = true;
                            if (simGameEventDef.AdditionalRequirements != null)
                            {
                                __instance.RecordLog("Has additional reqs.", SimGameLogLevel.VERBOSE);
                                foreach (RequirementDef requirementDef in simGameEventDef.AdditionalRequirements)
                                {
                                    TagSet         tagsByScope   = ___sim.GetTagsByScope(requirementDef.Scope);
                                    StatCollection statsByScope2 = ___sim.GetStatsByScope(requirementDef.Scope);
                                    if (!SimGameState.MeetsRequirements(requirementDef, tagsByScope, statsByScope2, ___VerboseEntry))
                                    {
                                        flag = false;
                                        break;
                                    }
                                    if (!flag)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (!flag)
                            {
                                __instance.RecordLog("Failed additional req check.", SimGameLogLevel.VERBOSE);
                                popRecordT.GetValue();
                            }
                            else
                            {
                                popRecordT.GetValue();
                                __instance.RecordLog(string.Format("Selected final event: {0}. Attempting to fetch additional objects.", simGameEventDef.Description.Id), SimGameLogLevel.CRITICAL);
                                if (simGameEventDef.AdditionalObjects != null && simGameEventDef.AdditionalObjects.Length != 0)
                                {
                                    __instance.RecordLog("Event has additional objects.", SimGameLogLevel.VERBOSE);
                                }
                                goodEvent = new SimGameEventTracker.PotentialEvent(simGameEventDef, pilot);
                                if (simGameEventDef.AdditionalObjects != null)
                                {
                                    SimGameEventObject[] additionalObjects = simGameEventDef.AdditionalObjects;
                                    int k = 0;
                                    while (k < additionalObjects.Length)
                                    {
                                        SimGameEventObject    simGameEventObject = additionalObjects[k];
                                        List <MechDef>        list  = new List <MechDef>();
                                        List <Pilot>          list2 = new List <Pilot>();
                                        List <TagSet>         list3 = new List <TagSet>();
                                        List <StatCollection> list4 = new List <StatCollection>();
                                        pushRecordT.GetValue(new object[] { "Additional Object" });
                                        __instance.RecordLog("Object Scope: " + simGameEventObject.Scope, SimGameLogLevel.VERBOSE);
                                        switch (simGameEventObject.Scope)
                                        {
                                        case EventScope.SecondaryMechWarrior:
                                        case EventScope.TertiaryMechWarrior:
                                            goto IL_3C7;

                                        case EventScope.SecondaryMech:
                                            list.AddRange(___sim.ActiveMechs.Values);
                                            list.Shuffle <MechDef>();
                                            using (List <MechDef> .Enumerator enumerator = list.GetEnumerator())
                                            {
                                                while (enumerator.MoveNext())
                                                {
                                                    MechDef mechDef = enumerator.Current;
                                                    list3.Add(mechDef.MechTags);
                                                    list4.Add(mechDef.Stats);
                                                }
                                                break;
                                            }
                                            goto IL_3C7;
                                        }
IL_507:
                                        int num2 = -1;
                                        for (int l = 0; l < list3.Count; l++)
                                        {
                                            if (SimGameState.MeetsRequirements(simGameEventObject.Requirements, list3[l], list4[l], ___VerboseEntry))
                                            {
                                                num2 = l;
                                                break;
                                            }
                                        }
                                        if (num2 < 0)
                                        {
                                            __instance.RecordLog("Unable to find additional object that meets requirement. Skipping event.", SimGameLogLevel.CRITICAL);
                                            popRecordT.GetValue();
                                            return(false);
                                        }
                                        if (simGameEventObject.Scope == EventScope.SecondaryMech)
                                        {
                                            goodEvent.SecondaryMech = list[num2];
                                            __instance.RecordLog(string.Format("Mech {0} has been set as additional object", list[num2].Description.Id), SimGameLogLevel.CRITICAL);
                                        }
                                        else if (simGameEventObject.Scope == EventScope.SecondaryMechWarrior)
                                        {
                                            goodEvent.SecondaryPilot = list2[num2];
                                            __instance.RecordLog(string.Format("Pilot {0} has been set as additional object", list2[num2].Description.Id), SimGameLogLevel.CRITICAL);
                                        }
                                        else
                                        {
                                            goodEvent.TertiaryPilot = list2[num2];
                                            __instance.RecordLog(string.Format("Pilot {0} has been set as additional object", list2[num2].Description.Id), SimGameLogLevel.CRITICAL);
                                        }
                                        popRecordT.GetValue();
                                        k++;
                                        continue;
IL_3C7:
                                        foreach (Pilot pilot2 in AllMechWarriors())
                                        {
                                            if (pilot2.pilotDef.TimeoutRemaining > 0)
                                            {
                                                popRecordT.GetValue();
                                            }
                                            else if (pilot != null && pilot2.GUID == pilot.GUID)
                                            {
                                                popRecordT.GetValue();
                                            }
                                            else if (simGameEventObject.Scope == EventScope.SecondaryMechWarrior && goodEvent.TertiaryPilot != null && pilot2.GUID == goodEvent.TertiaryPilot.GUID)
                                            {
                                                popRecordT.GetValue();
                                            }
                                            else if (simGameEventObject.Scope == EventScope.TertiaryMechWarrior && goodEvent.SecondaryPilot != null && pilot2.GUID == goodEvent.SecondaryPilot.GUID)
                                            {
                                                popRecordT.GetValue();
                                            }
                                            else
                                            {
                                                list2.Add(pilot2);
                                            }
                                        }
                                        list2.Shuffle <Pilot>();
                                        foreach (Pilot pilot3 in list2)
                                        {
                                            list3.Add(pilot3.pilotDef.PilotTags);
                                            list4.Add(pilot3.StatCollection);
                                        }
                                        goto IL_507;
                                    }
                                }
                                if (goodEvent != null)
                                {
                                    if (scope == EventScope.MechWarrior)
                                    {
                                        popRecordT.GetValue();
                                    }
                                    __result = true;
                                    return(false);
                                }
                            }
                        }
                        else
                        {
                            __instance.RecordLog("Failed!", SimGameLogLevel.VERBOSE);
                            popRecordT.GetValue();
                            popRecordT.GetValue();
                        }
                    }
                }
                if (scope == EventScope.MechWarrior)
                {
                    popRecordT.GetValue();
                    goto IL_65E;
                }
                goto IL_65E;
            }

            __result = false;
            return(false);
        }
        static bool Prefix(string button)
        {
            Mod.Log.Info?.Write($"RBP invoked for button: {button}");
            if ("Hiring".Equals(button, StringComparison.InvariantCultureIgnoreCase))
            {
                if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
                {
                    Mod.Log.Info?.Write("-- Regenerating pilots in system.");
                    ModState.SimGameState.CurSystem.AvailablePilots.Clear();
                    ModState.SimGameState.CurSystem.GeneratePilots(ModState.SimGameState.Constants.Story.DefaultPilotsPerSystem);
                }
                else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl) &&
                         Mod.Config.HeadHunting.Enabled && ModState.SimGameState.TravelState == SimGameTravelStatus.IN_SYSTEM)
                {
                    Mod.Log.Info?.Write("-- Forcing poaching on random crew.");

                    // Randomize pilots instead of sorting by skill?
                    List <Pilot> pilots = ModState.SimGameState.PilotRoster.ToList();
                    pilots.Sort((p1, p2) =>
                    {
                        CrewDetails p1cd = ModState.GetCrewDetails(p1.pilotDef);
                        CrewDetails p2cd = ModState.GetCrewDetails(p2.pilotDef);
                        return(CrewDetails.CompareByValue(p1cd, p2cd));
                    });

                    int   idx    = Mod.Random.Next(0, pilots.Count - 1);
                    Pilot random = pilots[idx];
                    Mod.Log.Info?.Write($"--  Headhunted pilot: {random.Name}");
                    CrewDetails     cd       = ModState.GetCrewDetails(random.pilotDef);
                    SimGameEventDef newEvent = EventHelper.CreateHeadHuntingEvent(random, cd, cd.HiringBonus, cd.HiringBonus);

                    Traverse            mechWarriorEventTrackerT = Traverse.Create(ModState.SimGameState).Field("mechWarriorEventTracker");
                    SimGameEventTracker mechWarriorEventTracker  = mechWarriorEventTrackerT.GetValue <SimGameEventTracker>();

                    ModState.HeadHuntedPilot = random;
                    Mod.Log.Info?.Write($"--  Firing debug event");
                    ModState.SimGameState.Context.SetObject(GameContextObjectTagEnum.TargetMechWarrior, random);
                    ModState.SimGameState.OnEventTriggered(newEvent, EventScope.MechWarrior, mechWarriorEventTracker);

                    return(false);
                }
                else if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) &&
                         ModState.SimGameState.TravelState == SimGameTravelStatus.IN_SYSTEM)
                {
                    Mod.Log.Info?.Write("-- Forcing contract expiration on random crew.");

                    // Randomize pilots instead of sorting by skill?
                    List <Pilot> pilots = ModState.SimGameState.PilotRoster.ToList();
                    pilots.Sort((p1, p2) =>
                    {
                        CrewDetails p1cd = ModState.GetCrewDetails(p1.pilotDef);
                        CrewDetails p2cd = ModState.GetCrewDetails(p2.pilotDef);
                        return(CrewDetails.CompareByValue(p1cd, p2cd));
                    });

                    int   idx    = Mod.Random.Next(0, pilots.Count - 1);
                    Pilot random = pilots[idx];
                    Mod.Log.Info?.Write($"--  Expired pilot: {random.Name}");
                    CrewDetails cd = ModState.GetCrewDetails(random.pilotDef);

                    ModState.ExpiredContracts.Enqueue((random, cd));
                    SimGameEventDef newEvent = EventHelper.ModifyContractExpirationEventForPilot(random, cd);

                    Traverse            mechWarriorEventTrackerT = Traverse.Create(ModState.SimGameState).Field("mechWarriorEventTracker");
                    SimGameEventTracker mechWarriorEventTracker  = mechWarriorEventTrackerT.GetValue <SimGameEventTracker>();

                    ModState.SimGameState.OnEventTriggered(newEvent, EventScope.MechWarrior, mechWarriorEventTracker);

                    return(false);
                }
            }

            return(true);
        }