예제 #1
0
        static void Postfix(Starmap __instance, SimGameState simGame)
        {
            try {
                Fields.currentMap = Web.GetStarMap();
                List <StarSystem> needUpdates = new List <StarSystem>();
                if (Fields.currentMap == null)
                {
                    SimGameInterruptManager interruptQueue = (SimGameInterruptManager)AccessTools.Field(typeof(SimGameState), "interruptQueue").GetValue(simGame);
                    interruptQueue.QueueGenericPopup_NonImmediate("Connection Failure", "Map could not be downloaded", true);
                    return;
                }
                List <string> changes = new List <string>();
                foreach (ParseSystem system in Fields.currentMap.systems)
                {
                    if (system.activePlayers > 0)
                    {
                        GameObject starObject = GameObject.Find(system.name);
                        Transform  argoMarker = starObject.transform.Find("ArgoMarker");
                        argoMarker.gameObject.SetActive(true);
                        argoMarker.localScale = new Vector3(4f, 4f, 4f);
                        argoMarker.GetComponent <MeshRenderer>().material.color = Color.grey;
                        GameObject playerNumber = new GameObject();
                        playerNumber.transform.parent = argoMarker;
                        playerNumber.name             = "PlayerNumberText";
                        playerNumber.layer            = 25;
                        TextMeshPro textComponent = playerNumber.AddComponent <TextMeshPro>();
                        textComponent.SetText(system.activePlayers.ToString());
                        textComponent.transform.localPosition = new Vector3(0, -0.35f, -0.05f);
                        textComponent.fontSize  = 6;
                        textComponent.alignment = TextAlignmentOptions.Center;
                        textComponent.faceColor = Color.black;
                        textComponent.fontStyle = FontStyles.Bold;
                    }
                    StarSystem system2 = simGame.StarSystems.Find(x => x.Name.Equals(system.name));
                    if (system2 != null)
                    {
                        Faction newOwner = system.controlList.OrderByDescending(x => x.percentage).First().faction;
                        Faction oldOwner = system2.Owner;
                        AccessTools.Method(typeof(StarSystemDef), "set_Owner").Invoke(system2.Def, new object[] {
                            newOwner
                        });
                        AccessTools.Method(typeof(StarSystemDef), "set_ContractEmployers").Invoke(system2.Def, new object[] {
                            Helper.GetEmployees(system2, simGame)
                        });
                        AccessTools.Method(typeof(StarSystemDef), "set_ContractTargets").Invoke(system2.Def, new object[] {
                            Helper.GetTargets(system2, simGame)
                        });
                        system2.Tags.Remove(Helper.GetFactionTag(oldOwner));
                        system2.Tags.Add(Helper.GetFactionTag(newOwner));

                        if (Helper.IsBorder(system2, simGame) && simGame.Starmap != null)
                        {
                            system2.Tags.Add("planet_other_battlefield");
                        }
                        else
                        {
                            system2.Tags.Remove("planet_other_battlefield");
                        }
                        system2 = Helper.ChangeWarDescription(system2, simGame, system);
                        if (newOwner != oldOwner)
                        {
                            changes.Add(Helper.GetFactionShortName(newOwner, simGame.DataManager) + " took " + system2.Name + " from " + Helper.GetFactionShortName(oldOwner, simGame.DataManager));
                            foreach (StarSystem changedSystem in simGame.Starmap.GetAvailableNeighborSystem(system2))
                            {
                                if (!needUpdates.Contains(changedSystem))
                                {
                                    needUpdates.Add(changedSystem);
                                }
                            }
                        }
                    }
                }
                foreach (StarSystem changedSystem in needUpdates)
                {
                    AccessTools.Method(typeof(StarSystemDef), "set_ContractEmployers").Invoke(changedSystem.Def, new object[] {
                        Helper.GetEmployees(changedSystem, simGame)
                    });
                    AccessTools.Method(typeof(StarSystemDef), "set_ContractTargets").Invoke(changedSystem.Def, new object[] {
                        Helper.GetTargets(changedSystem, simGame)
                    });
                    ParseSystem system = Fields.currentMap.systems.FirstOrDefault(x => x.name.Equals(changedSystem.Name));
                    if (system != null)
                    {
                        AccessTools.Method(typeof(StarSystemDef), "set_Description").Invoke(changedSystem.Def, new object[] {
                            Helper.ChangeWarDescription(changedSystem, simGame, system).Def.Description
                        });
                    }
                }
                if (changes.Count > 0 && !Fields.firstpass)
                {
                    SimGameInterruptManager interruptQueue2 = (SimGameInterruptManager)AccessTools.Field(typeof(SimGameState), "interruptQueue").GetValue(simGame);
                    interruptQueue2.QueueGenericPopup_NonImmediate("War Activities", string.Join("\n", changes.ToArray()), true);
                }
                else
                {
                    Fields.firstpass = false;
                }
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }
예제 #2
0
        static void Postfix(Starmap __instance, SimGameState simGame)
        {
            try {
                PersistentMapClient.Logger.LogIfDebug($"methodSetOwner is:({methodSetOwner})");
                PersistentMapClient.Logger.LogIfDebug($"methodSetContractEmployers is:({methodSetContractEmployers})");
                PersistentMapClient.Logger.LogIfDebug($"methodSetContractTargets is:({methodSetContractTargets})");
                PersistentMapClient.Logger.LogIfDebug($"methodSetDescription is:({methodSetDescription})");
                PersistentMapClient.Logger.LogIfDebug($"fieldSimGameInterruptManager is:({fieldSimGameInterruptManager})");
                Fields.currentMap = Web.GetStarMap();
                if (Fields.currentMap == null)
                {
                    PersistentMapClient.Logger.LogIfDebug("Map not found");
                    SimGameInterruptManager interruptQueue = (SimGameInterruptManager)fieldSimGameInterruptManager.GetValue(simGame);
                    interruptQueue.QueueGenericPopup_NonImmediate("Connection Failure", "Map could not be downloaded", true);
                    return;
                }

                List <string>     changeNotifications             = new List <string>();
                List <StarSystem> transitiveContractUpdateTargets = new List <StarSystem>();

                foreach (PersistentMapAPI.System system in Fields.currentMap.systems)
                {
                    if (system == null)
                    {
                        PersistentMapClient.Logger.Log("System in map null");
                    }
                    if (system.activePlayers > 0)
                    {
                        AddActivePlayersBadgeToSystem(system);
                    }

                    StarSystem system2 = simGame.StarSystems.Find(x => x.Name.Equals(system.name));
                    if (system2 != null)
                    {
                        if (system2.Tags == null)
                        {
                            PersistentMapClient.Logger.Log(system2.Name + ": Has no Tags");
                        }
                        Faction newOwner = system.controlList.OrderByDescending(x => x.percentage).First().faction;
                        Faction oldOwner = system2.Owner;
                        // Update control to the new faction
                        methodSetOwner.Invoke(system2.Def, new object[] { newOwner });
                        system2.Tags.Remove(Helper.GetFactionTag(oldOwner));
                        system2.Tags.Add(Helper.GetFactionTag(newOwner));
                        system2 = Helper.ChangeWarDescription(system2, simGame, system);

                        // Update the contracts on the system
                        methodSetContractEmployers.Invoke(system2.Def, new object[] { Helper.GetEmployees(system2, simGame) });
                        methodSetContractTargets.Invoke(system2.Def, new object[] { Helper.GetTargets(system2, simGame) });

                        // If the system is next to enemy factions, update the map to show the border
                        if (Helper.IsBorder(system2, simGame) && simGame.Starmap != null)
                        {
                            system2.Tags.Add("planet_other_battlefield");
                        }
                        else
                        {
                            system2.Tags.Remove("planet_other_battlefield");
                        }

                        // If the owner changes, add a notice to the player and mark neighbors for contract updates
                        if (newOwner != oldOwner)
                        {
                            string newOwnerName = Helper.GetFactionShortName(newOwner, simGame.DataManager);
                            string oldOwnerName = Helper.GetFactionShortName(oldOwner, simGame.DataManager);
                            changeNotifications.Add($"{newOwnerName} took {system2.Name} from {oldOwnerName}");
                            foreach (StarSystem changedSystem in simGame.Starmap.GetAvailableNeighborSystem(system2))
                            {
                                if (!transitiveContractUpdateTargets.Contains(changedSystem))
                                {
                                    transitiveContractUpdateTargets.Add(changedSystem);
                                }
                            }
                        }
                    }
                }

                // For each system neighboring a system whose ownership changed, update their contracts as well
                foreach (StarSystem changedSystem in transitiveContractUpdateTargets)
                {
                    methodSetContractEmployers.Invoke(changedSystem.Def, new object[] { Helper.GetEmployees(changedSystem, simGame) });
                    methodSetContractTargets.Invoke(changedSystem.Def, new object[] { Helper.GetTargets(changedSystem, simGame) });

                    // Update the description on these systems to show the new contract options
                    PersistentMapAPI.System system = Fields.currentMap.systems.FirstOrDefault(x => x.name.Equals(changedSystem.Name));
                    if (system != null)
                    {
                        methodSetDescription.Invoke(changedSystem.Def,
                                                    new object[] { Helper.ChangeWarDescription(changedSystem, simGame, system).Def.Description });
                    }
                }

                if (changeNotifications.Count > 0 && !Fields.firstpass)
                {
                    SimGameInterruptManager interruptQueue2 = (SimGameInterruptManager)fieldSimGameInterruptManager.GetValue(simGame);
                    interruptQueue2.QueueGenericPopup_NonImmediate("War Activities", string.Join("\n", changeNotifications.ToArray()), true);
                }
                else
                {
                    Fields.firstpass = false;
                }
            }
            catch (Exception e) {
                PersistentMapClient.Logger.LogError(e);
            }
        }