Ejemplo n.º 1
0
 public static double GetDistanceInLY(StarSystem currPosition, ParseSystem target, List <StarSystem> allSystems)
 {
     try {
         StarSystem targetSystem = allSystems.FirstOrDefault(x => x.Name.Equals(target.name));
         return(Math.Sqrt(Math.Pow(targetSystem.Position.x - currPosition.Position.x, 2) + Math.Pow(targetSystem.Position.y - currPosition.Position.y, 2)));
     }
     catch (Exception ex) {
         Logger.LogError(ex);
         return(0);
     }
 }
Ejemplo n.º 2
0
 static void Postfix(SGSystemViewPopulator __instance, StarSystem ___starSystem)
 {
     try {
         if (GameObject.Find("COMPANYNAMES") == null)
         {
             GameObject old = GameObject.Find("uixPrfPanl_NAV_systemStats-Element-MANAGED");
             if (old != null)
             {
                 GameObject newwidget = GameObject.Instantiate(old);
                 newwidget.transform.SetParent(old.transform.parent, false);
                 newwidget.name         = "COMPANYNAMES";
                 old.transform.position = new Vector3(old.transform.position.x, 311, old.transform.position.z);
                 old.transform.FindRecursive("dotgrid").gameObject.active = false;
                 old.transform.FindRecursive("crossLL").gameObject.active = false;
                 newwidget.transform.position = new Vector3(old.transform.position.x, 106, old.transform.position.z);
                 newwidget.transform.FindRecursive("stats_factionsAndClimate").gameObject.active = false;
                 newwidget.transform.FindRecursive("owner_icon").gameObject.active = false;
                 newwidget.transform.FindRecursive("uixPrfIndc_SIM_Reputation-MANAGED").gameObject.active = false;
                 newwidget.transform.FindRecursive("crossUL").gameObject.active = false;
                 GameObject ownerPanel = newwidget.transform.FindRecursive("owner_detailsPanel").gameObject;
                 ownerPanel.transform.GetComponent <HorizontalLayoutGroup>().childAlignment = TextAnchor.UpperLeft;
                 RectTransform ownerRect = ownerPanel.GetComponent <RectTransform>();
                 ownerRect.sizeDelta = new Vector2(ownerRect.sizeDelta.x, 145);
                 TextMeshProUGUI title = newwidget.transform.FindRecursive("ownerTitle_text").GetComponent <TextMeshProUGUI>();
                 title.SetText("COMPANIES");
                 TextMeshProUGUI text = newwidget.transform.FindRecursive("txt-owner").GetComponent <TextMeshProUGUI>();
                 text.alignment          = TextAlignmentOptions.TopLeft;
                 text.enableWordWrapping = false;
             }
         }
         GameObject companyObject = GameObject.Find("COMPANYNAMES");
         if (companyObject != null)
         {
             TextMeshProUGUI companietext = companyObject.transform.FindRecursive("txt-owner").GetComponent <TextMeshProUGUI>();
             ParseSystem     system       = Fields.currentMap.systems.FirstOrDefault(x => x.name.Equals(___starSystem.Name));
             if (system != null && companietext != null)
             {
                 companietext.SetText(string.Join(Environment.NewLine, system.companies.ToArray()));
             }
             else
             {
                 companietext.SetText("");
             }
         }
     }
     catch (Exception e) {
         Logger.LogError(e);
     }
 }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
 public static StarSystem ChangeWarDescription(StarSystem system, SimGameState Sim, ParseSystem warsystem)
 {
     try {
         if (IsBorder(system, Sim))
         {
             List <string> factionList = new List <string>();
             factionList.Add("Current Control:");
             foreach (FactionControl fc in warsystem.controlList)
             {
                 if (fc.percentage != 0)
                 {
                     factionList.Add(GetFactionName(fc.faction, Sim.DataManager) + ": " + fc.percentage + "%");
                 }
             }
             if (!Fields.FluffDescriptions.ContainsKey(system.Name))
             {
                 Fields.FluffDescriptions.Add(system.Name, system.Def.Description.Details);
             }
             AccessTools.Method(typeof(DescriptionDef), "set_Details").Invoke(system.Def.Description, new object[] { string.Join("\n", factionList.ToArray()) });
         }
         else if (Fields.FluffDescriptions.ContainsKey(system.Name))
         {
             AccessTools.Method(typeof(DescriptionDef), "set_Details").Invoke(system.Def.Description, new object[] { Fields.FluffDescriptions[system.Name] });
             Fields.FluffDescriptions.Remove(system.Name);
         }
         return(system);
     }
     catch (Exception ex) {
         Logger.LogError(ex);
         return(null);
     }
 }