コード例 #1
0
        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);
        }
コード例 #2
0
        public static int CompareByCrewTypeAndValue(SGBarracksRosterSlot slot1, SGBarracksRosterSlot slot2)
        {
            // Check nullity
            if (slot1 == null && slot2 == null)
            {
                return(0);
            }
            else if (slot1 != null && slot2 == null)
            {
                return(1);
            }
            else if (slot1 == null && slot2 != null)
            {
                return(-1);
            }

            // Check pilot vs. non-pilot
            if (slot1.Pilot == null && slot2.Pilot == null)
            {
                return(0);
            }
            else if (slot1.Pilot != null && slot2.Pilot == null)
            {
                return(1);
            }
            else if (slot1.Pilot == null && slot2.Pilot != null)
            {
                return(-1);
            }

            // Check pilot vs. non-pilot using pilotDefs
            if (slot1.Pilot.pilotDef == null && slot2.Pilot.pilotDef == null)
            {
                return(0);
            }
            else if (slot1.Pilot.pilotDef != null && slot2.Pilot.pilotDef == null)
            {
                return(1);
            }
            else if (slot1.Pilot.pilotDef == null && slot2.Pilot.pilotDef != null)
            {
                return(-1);
            }

            // Check details
            CrewDetails cd1 = ModState.GetCrewDetails(slot1.Pilot.pilotDef);
            CrewDetails cd2 = ModState.GetCrewDetails(slot2.Pilot.pilotDef);

            // Compare by type
            int typeComparison = CrewDetails.CompareByType(cd1, cd2);

            if (typeComparison != 0)
            {
                return(typeComparison);
            }

            // Compare by skill
            int skillComparison = CrewDetails.CompareByValue(cd1, cd2);

            if (skillComparison != 0)
            {
                return(skillComparison);
            }

            return(0);
        }