static void Postfix(SimGameState sim, PilotGenerator __instance, List <LifepathNodeDef> ___lifepaths, List <LifepathNodeDef> ___startingPaths, List <LifepathNodeDef> ___advanceStartingPaths, GenderedOptionsListDef ___voiceList) { ModState.CrewCreateState.NameGenerator = new PilotNameGenerator(); ModState.CrewCreateState.LifePaths = ___lifepaths; ModState.CrewCreateState.StartingPaths = ___startingPaths; ModState.CrewCreateState.AdvancePaths = ___advanceStartingPaths; ModState.CrewCreateState.Voices = ___voiceList; ModState.CrewCreateState.GenderWeights = new List <int>() { sim.Constants.Pilot.FemaleGenerationWeight, sim.Constants.Pilot.MaleGenerationWeight, sim.Constants.Pilot.NonBinaryGenerationWeight }; ModState.CrewCreateState.HBSPilotGenerator = __instance; Mod.Log.Info?.Write("Initialized Pilot Creation shared state."); }
public static bool Prefix(PilotGenerator __instance, PilotDef pilot, string type, int value) { var sim = UnityGameInstance.BattleTechGame.Simulation; value--; if (value < 0) { return(false); } if (!sim.AbilityTree.ContainsKey(type)) { return(false); } if (sim.AbilityTree[type].Count <= value) { return(false); } List <AbilityDef> list = sim.AbilityTree[type][value]; if (list.Count == 0) { return(false); } else { List <AbilityDef> listAbilities = list.FindAll(x => x.IsPrimaryAbility == true);//get primary abilities List <string> pilotAbilityDefNames = pilot.abilityDefNames; var abilityFilter = modSettings.abilityReqs.Values.SelectMany(x => x).ToList(); List <AbilityDef> abilitiesWithReqs = listAbilities.Where(ability => abilityFilter.Any(filter => filter.Equals(ability.Id))).ToList(); foreach (var abilityWithReq in abilitiesWithReqs) { if (!pilotAbilityDefNames.Contains(modSettings.abilityReqs.FirstOrDefault(x => x.Value.Contains(abilityWithReq.Id)).Key)) { listAbilities.Remove(abilityWithReq); } } List <AbilityDef> listTraits = list.FindAll(x => x.IsPrimaryAbility != true);//need to keep all traits if (listAbilities.Count > 0) { int idx = UnityEngine.Random.Range(0, listAbilities.Count); //pick a random primary of the options listTraits.Add(listAbilities[idx]); //add only that random primary } pilot.DataManager = sim.DataManager; pilot.ForceRefreshAbilityDefs(); for (int i = 0; i < listTraits.Count; i++) { if (sim.CanPilotTakeAbility(pilot, listTraits[i], false)) { pilot.abilityDefNames.Add(listTraits[i].Description.Id); } } pilot.ForceRefreshAbilityDefs(); return(false); } }