static void Postfix(Starmap __instance, SimGameState simGame) { Settings settings = Helper.LoadSettings(); if (settings.Mode == 2) { foreach (StarSystem system in simGame.StarSystems) { StarSystem capital = simGame.StarSystems.Find(x => x.Name.Equals(Helper.GetCapital(system.Owner))); if (capital != null) { StarSystemNode systemByID = __instance.GetSystemByID(system.ID); StarSystemNode systemByID2 = __instance.GetSystemByID(capital.ID); AStar.PathFinder starmapPathfinder = new AStar.PathFinder(); starmapPathfinder.InitFindPath(systemByID, systemByID2, 1, 1E-06f, new Action <AStar.AStarResult>(OnPathfindingComplete)); while (!starmapPathfinder.IsDone) { starmapPathfinder.Step(); } } else { AccessTools.Field(typeof(StarSystemDef), "DefaultDifficulty").SetValue(system.Def, 1); } AccessTools.Field(typeof(StarSystemDef), "DifficultyList").SetValue(system.Def, new List <int>()); AccessTools.Field(typeof(StarSystemDef), "DifficultyModes").SetValue(system.Def, new List <SimGameState.SimGameType>()); } } }
// only call to this function is from StarmapScreen.Update() // intercept and check shift status public static void Postfix(Starmap __instance, StarSystemNode __result) { if (__result != null && __result != __instance.CurSelected && __result != __instance.CurPlanet && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))) { ShiftClickMove.NextSelectIsShiftClick = true; } }
public static bool Prefix( StarmapRenderer __instance, StarSystemNode node, StarmapSystemRenderer renderer) { return(HarmonyManager.PrefixLogExceptions(() => { bool flag = __instance.starmap.CanTravelToNode(node, false); RGBColor <float> color = new RGBColor <float>(1, 1, 1); VisitedColors visitedColors = HarmonyManager.Settings.VisitedColors; switch (CurrentMapType) { case MapType.None: return true; case MapType.Difficulty: color = GetDifficultyColor(__instance, node); break; case MapType.Visited: color = __instance.starmap.HasStarSystemBeenVisited(node) ? visitedColors.VisitedColor : visitedColors.NotVisitedColor; break; case MapType.MaxContracts: color = GetDifficultyColor((int)node.System.CurMaxContracts); break; default: throw new InvalidEnumArgumentException("'CurrentMapType' has invalid value. This should never happen. Please report this as a bug."); } if (renderer.Init(node, flag ? color.FromRGBColor() : __instance.unavailableColor, flag)) { __instance.RefreshBorders(); } // Don't call the original method, we've replaced it. return false; })); }
private static void OnPathfindingComplete(AStar.AStarResult result) { try { int baseDifficulty = 5; GameInstance game = LazySingletonBehavior <UnityGameInstance> .Instance.Game; Dictionary <string, int> allCareerFactionReputations = new Dictionary <string, int>(); foreach (FactionValue faction in FactionEnumeration.FactionList) { if (faction.DoesGainReputation) { allCareerFactionReputations.Add(faction.Name, game.Simulation.GetRawReputation(faction)); } } Settings settings = Helper.LoadSettings(); int count = result.path.Count; StarSystemNode starSystemNode = (StarSystemNode)result.path[0]; int rangeDifficulty = 0; int repModifier = 0; string repFaction = starSystemNode.System.OwnerValue.Name; if (!Helper.IsCapital(starSystemNode.System)) { rangeDifficulty = Mathf.RoundToInt((count - 1)); } else { repFaction = Helper.GetFactionForCapital(starSystemNode.System); } if (allCareerFactionReputations.ContainsKey(repFaction)) { int repOfOwner = allCareerFactionReputations[repFaction]; repModifier = Mathf.CeilToInt(repOfOwner / 20f); } else { //Logger.LogLine("RepMissing: " + starSystemNode.System.Owner.ToString()); //Logger.LogLine("Def: " + starSystemNode.System.Def.Owner.ToString()); } int endDifficulty = Mathf.Clamp(baseDifficulty + rangeDifficulty - repModifier, 1, 25); AccessTools.Field(typeof(StarSystemDef), "DefaultDifficulty").SetValue(starSystemNode.System.Def, endDifficulty); }catch (Exception e) { Logger.LogError(e); } }
public static bool HandleClickSystem(Starmap starmap, StarSystemNode system) { if (!NextSelectIsShiftClick) { return(true); } NextSelectIsShiftClick = false; var plannedPath = Traverse.Create(starmap.Screen).Field("_plannedPath").GetValue <LineRenderer>(); if (starmap.PotentialPath == null || starmap.PotentialPath.Count == 0 || plannedPath == null || plannedPath.positionCount == 0) { Main.HBSLog.Log("Shift clicked system but had no previous route"); return(true); } // set CurSelected to the new end of the route that we're making Traverse.Create(starmap).Property("CurSelected").SetValue(system); var prevPath = new List <INavNode>(starmap.PotentialPath.ToArray()); var prevPathLast = prevPath.Last(); var starmapPathfinder = Traverse.Create(starmap).Field("starmapPathfinder").GetValue <AStar.PathFinder>(); starmapPathfinder.InitFindPath(prevPathLast, system, 1, 1E-06f, result => { if (result.status != PathStatus.Complete) { Main.HBSLog.LogError("Something went wrong with pathfinding!"); return; } result.path.Remove(prevPathLast); result.path.InsertRange(0, prevPath); Main.HBSLog.Log($"Created new hybrid route of size {result.path.Count}"); Traverse.Create(starmap).Method("OnPathfindingComplete", result).GetValue(); }); return(false); }
public static object SetCurrentSystem(TsEnvironment env, object[] inputs) { string systemName = env.ToString(inputs[0]); bool includeTravelTime = env.ToBool(inputs[1]); Main.Logger.Log($"[SetCurrentSystem] Travelling to '{systemName}' and includeTravelTime is '{includeTravelTime}'"); SimGameState simulation = UnityGameInstance.BattleTechGame.Simulation; if (includeTravelTime) { simulation.TravelToSystemByString(systemName, true); } else { StarSystemNode systemNode = simulation.Starmap.GetSystemByID(systemName); ReflectionHelper.SetReadOnlyProperty(simulation, "CurSystem", systemNode.System); simulation.SetCurrentSystem(systemNode.System, true, false); } Main.Logger.Log($"[SetCurrentSystem] Travel complete"); return(null); }
private static RGBColor <float> GetDifficultyColor(StarmapRenderer starmapRenderer, StarSystemNode starSystemNode) { SimGameState.SimGameType gameType = starmapRenderer.GetSimGameState().SimGameMode; int difficulty = starSystemNode.System.Def.GetDifficulty(gameType); return(GetDifficultyColor(difficulty)); }
public static bool HasStarSystemBeenVisited(this Starmap starmap, StarSystemNode node) { return(starmap.HasStarSystemBeenVisited(node.System.ID)); }
public static bool Prefix(Starmap __instance, StarSystemNode node) { return(ShiftClickMove.HandleClickSystem(__instance, node)); }