// Create a new StarMap from InnerSphereMap system data private static StarMap InitializeNewMap() { logger.Warn("Initializing map from InnerSphereMap system data."); StarMap map = new StarMap(); map.systems = new List <PersistentMapAPI.System>(); foreach (string filePaths in Directory.GetFiles(StarMapStateManager.systemDataFilePath)) { string originalJson = File.ReadAllText(filePaths); JObject originalJObject = JObject.Parse(originalJson); Faction owner = (Faction)Enum.Parse(typeof(Faction), (string)originalJObject["Owner"]); FactionControl ownerControl = new FactionControl(); ownerControl.faction = owner; if (owner != Faction.NoFaction) { ownerControl.percentage = 100; } else { ownerControl.percentage = 0; } PersistentMapAPI.System system = new PersistentMapAPI.System(); system.controlList = new List <FactionControl>(); system.name = (string)originalJObject["Description"]["Name"]; system.controlList.Add(ownerControl); map.systems.Add(system); } return(map); }
private void Awake() { _instance = this; }
static void Postfix(StarSystem __instance) { try { if (Fields.settings.debug) { AccessTools.Method(typeof(SimGameState), "SetReputation").Invoke(__instance.Sim, new object[] { Faction.Steiner, 100, StatCollection.StatOperation.Set, null }); } __instance.Sim.GlobalContracts.Clear(); foreach (KeyValuePair <Faction, FactionDef> pair in __instance.Sim.FactionsDict) { if (!Fields.excludedFactions.Contains(pair.Key)) { SimGameReputation rep = __instance.Sim.GetReputation(pair.Key); int numberOfContracts; switch (rep) { case SimGameReputation.LIKED: { numberOfContracts = 1; break; } case SimGameReputation.FRIENDLY: { numberOfContracts = 2; break; } case SimGameReputation.ALLIED: { numberOfContracts = 3; break; } default: { numberOfContracts = 0; break; } } if (numberOfContracts > 0) { List <ParseSystem> targets = new List <ParseSystem>(); foreach (ParseSystem potentialTarget in Fields.currentMap.systems) { FactionControl control = potentialTarget.controlList.FirstOrDefault(x => x.faction == pair.Key); if (control != null && control.percentage < 100 && control.percentage != 0) { targets.Add(potentialTarget); } } if (targets.Count() > 0) { targets = targets.OrderBy(x => Helper.GetDistanceInLY(__instance.Sim.CurSystem, x, __instance.Sim.StarSystems)).ToList(); numberOfContracts = Mathf.Min(numberOfContracts, targets.Count); for (int i = 0; i < numberOfContracts; i++) { StarSystem realSystem = __instance.Sim.StarSystems.FirstOrDefault(x => x.Name.Equals(targets[i].name)); if (realSystem != null) { Faction target = realSystem.Owner; if (pair.Key == target || Fields.excludedFactions.Contains(target)) { List <FactionControl> ownerlist = targets[i].controlList.OrderByDescending(x => x.percentage).ToList(); if (ownerlist.Count > 1) { target = ownerlist[1].faction; if (Fields.excludedFactions.Contains(target)) { target = Faction.AuriganPirates; } } else { target = Faction.AuriganPirates; } } Contract contract = Helper.GetNewWarContract(__instance.Sim, realSystem.Def.Difficulty, pair.Key, target, realSystem); contract.Override.contractDisplayStyle = ContractDisplayStyle.BaseCampaignStory; contract.SetInitialReward(Mathf.RoundToInt(contract.InitialContractValue * Fields.settings.priorityContactPayPercentage)); int maxPriority = Mathf.FloorToInt(7 / __instance.Sim.Constants.Salvage.PrioritySalvageModifier); contract.Override.salvagePotential = Mathf.Min(maxPriority, Mathf.RoundToInt(contract.Override.salvagePotential * Fields.settings.priorityContactPayPercentage)); contract.Override.negotiatedSalvage = 1f; __instance.Sim.GlobalContracts.Add(contract); } } } } } } } catch (Exception e) { Logger.LogError(e); } }
static void Postfix(StarSystem __instance) { try { __instance.Sim.GlobalContracts.Clear(); if (__instance.Sim.HasTravelContract && Fields.warmission) { __instance.Sim.GlobalContracts.Add(__instance.Sim.ActiveTravelContract); } foreach (KeyValuePair <Faction, FactionDef> pair in __instance.Sim.FactionsDict) { if (!Fields.excludedFactions.Contains(pair.Key)) { int numberOfContracts = 0; if (__instance.Sim.IsFactionAlly(pair.Key, null)) { numberOfContracts = Fields.settings.priorityContractsPerAlly; } if (numberOfContracts > 0) { List <PersistentMapAPI.System> targets = new List <PersistentMapAPI.System>(); if (Fields.currentMap != null) { foreach (PersistentMapAPI.System potentialTarget in Fields.currentMap.systems) { FactionControl control = potentialTarget.controlList.FirstOrDefault(x => x.faction == pair.Key); if (control != null && control.percentage < 100 && control.percentage != 0) { targets.Add(potentialTarget); } } if (targets.Count() > 0) { targets = targets.OrderBy(x => Helper.GetDistanceInLY(__instance.Sim.CurSystem, x, __instance.Sim.StarSystems)).ToList(); numberOfContracts = Mathf.Min(numberOfContracts, targets.Count); for (int i = 0; i < numberOfContracts; i++) { StarSystem realSystem = __instance.Sim.StarSystems.FirstOrDefault(x => x.Name.Equals(targets[i].name)); if (realSystem != null) { Faction target = realSystem.Owner; if (pair.Key == target || Fields.excludedFactions.Contains(target)) { List <FactionControl> ownerlist = targets[i].controlList.OrderByDescending(x => x.percentage).ToList(); if (ownerlist.Count > 1) { target = ownerlist[1].faction; if (Fields.excludedFactions.Contains(target)) { target = Faction.AuriganPirates; } } else { target = Faction.AuriganPirates; } } Faction possibleThird = Faction.AuriganPirates; foreach (FactionControl control in targets[i].controlList.OrderByDescending(x => x.percentage)) { if (control.faction != pair.Key && control.faction != target) { possibleThird = control.faction; break; } } Contract contract = Helper.GetNewWarContract(__instance.Sim, realSystem.Def.GetDifficulty(__instance.Sim.SimGameMode), pair.Key, target, possibleThird, realSystem); if (contract != null) { contract.Override.contractDisplayStyle = ContractDisplayStyle.BaseCampaignStory; contract.SetInitialReward(Mathf.RoundToInt(contract.InitialContractValue * Fields.settings.priorityContactPayPercentage)); int maxPriority = Mathf.FloorToInt(7 / __instance.Sim.Constants.Salvage.PrioritySalvageModifier); contract.Override.salvagePotential = Mathf.Min(maxPriority, Mathf.RoundToInt(contract.Override.salvagePotential * Fields.settings.priorityContactPayPercentage)); contract.Override.negotiatedSalvage = 1f; __instance.Sim.GlobalContracts.Add(contract); } else { PersistentMapClient.Logger.Log("Prio contract is null"); } } } } } } } } } catch (Exception e) { PersistentMapClient.Logger.LogError(e); } }
public bool isEnemyOf(FactionControl other) { return faction != other.faction; }