コード例 #1
0
        public override StarMap ReadJson(JsonReader reader, Type objectType, StarMap existingValue, bool hasExistingValue, JsonSerializer serializer)
        {
            StarMap starmap = new StarMap();

            starmap.systems = new List <PersistentMapAPI.System>();
            JObject jObject = JObject.Load(reader);
            JArray  systems = (JArray)jObject["systems"];

            foreach (JToken jtoken in systems)
            {
                PersistentMapAPI.System system = new PersistentMapAPI.System();
                system.activePlayers = (int)jtoken["activePlayers"];
                system.companies     = new List <Company>();

                /*List<string> companyNames = jtoken["companies"].ToObject<List<string>>();
                 * foreach(string name in companyNames) {
                 *  Company convertedCompany = new Company();
                 *  convertedCompany.Name = name;
                 *  convertedCompany.Faction = BattleTech.Faction.Steiner;
                 *  system.companies.Add(convertedCompany);
                 * }*/
                system.controlList = jtoken["controlList"].ToObject <List <FactionControl> >();
                system.name        = (string)jtoken["name"];
                starmap.systems.Add(system);
            }

            return(starmap);
        }
コード例 #2
0
        // 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);
        }
コード例 #3
0
ファイル: PatchWar.cs プロジェクト: codeninja75/PersistentMap
        // Creates the argo marker for player activity
        private static void AddActivePlayersBadgeToSystem(PersistentMapAPI.System system)
        {
            GameObject starObject            = GameObject.Find(system.name);
            Transform  playerMarker          = starObject.transform.Find("StarInner");
            Transform  playerMarkerUnvisited = starObject.transform.Find("StarInnerUnvisited");

            // Only one of these will actually be active for a star system at any given time
            playerMarker.localScale          = new Vector3(Fields.settings.activePlayerMarkerSize, Fields.settings.activePlayerMarkerSize, Fields.settings.activePlayerMarkerSize);
            playerMarkerUnvisited.localScale = new Vector3(Fields.settings.activePlayerMarkerSize, Fields.settings.activePlayerMarkerSize, Fields.settings.activePlayerMarkerSize);
        }
コード例 #4
0
 public static double GetDistanceInLY(StarSystem currPosition, PersistentMapAPI.System 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) {
         PersistentMapClient.Logger.LogError(ex);
         return(0);
     }
 }
コード例 #5
0
ファイル: PatchWar.cs プロジェクト: codeninja75/PersistentMap
 static void Postfix(SGSystemViewPopulator __instance, StarSystem ___starSystem, SimGameState ___simState)
 {
     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.SetActive(false);
                 old.transform.FindRecursive("crossLL").gameObject.SetActive(false);
                 newwidget.transform.position = new Vector3(old.transform.position.x, 106, old.transform.position.z);
                 newwidget.transform.FindRecursive("stats_factionsAndClimate").gameObject.SetActive(false);
                 newwidget.transform.FindRecursive("owner_icon").gameObject.SetActive(false);
                 newwidget.transform.FindRecursive("uixPrfIndc_SIM_Reputation-MANAGED").gameObject.SetActive(false);
                 newwidget.transform.FindRecursive("crossUL").gameObject.SetActive(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 && Fields.currentMap != null)
         {
             TextMeshProUGUI         companietext = companyObject.transform.FindRecursive("txt-owner").GetComponent <TextMeshProUGUI>();
             PersistentMapAPI.System system       = Fields.currentMap.systems.FirstOrDefault(x => x.name.Equals(___starSystem.Name));
             if (system != null && companietext != null)
             {
                 List <string> companyNames = new List <string>();
                 foreach (Company company in system.companies)
                 {
                     companyNames.Add("(" + Helper.GetFactionShortName(company.Faction, ___simState.DataManager) + ") " + company.Name);
                 }
                 companietext.SetText(string.Join(Environment.NewLine, companyNames.ToArray()));
             }
             else
             {
                 companietext.SetText("");
             }
         }
     }
     catch (Exception e) {
         PersistentMapClient.Logger.LogError(e);
     }
 }
コード例 #6
0
 public static StarSystem ChangeWarDescription(StarSystem system, SimGameState Sim, PersistentMapAPI.System 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) {
         PersistentMapClient.Logger.LogError(ex);
         return(null);
     }
 }
コード例 #7
0
ファイル: PatchWar.cs プロジェクト: codeninja75/PersistentMap
        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);
            }
        }
コード例 #8
0
        public System PostMissionResult(MissionResult mresult, string companyName)
        {
            try {
                int    realDifficulty = Math.Min(10, mresult.difficulty);
                string ip             = Helper.GetIP();
                int    realPlanets    = Math.Min(Helper.LoadSettings().MaxPlanetSupport, mresult.planetSupport);
                int    realRep        = Math.Min(Helper.LoadSettings().MaxRep, mresult.awardedRep);
                if ((Helper.LoadSettings().HalfSkullPercentageForWin *realDifficulty) + realRep + realPlanets > 50)
                {
                    Logger.LogToFile("Weird Result - Difficulty: " + realDifficulty + " - planet: " + realPlanets + " - rep: " + realRep + " - employer: " + mresult.employer + " - target: " + mresult.target + " - systemName: " + mresult.systemName + " - mresult: " + mresult.result + " - IP: " + ip);
                }
                HistoryResult hresult = new HistoryResult();
                hresult.date = DateTime.UtcNow;

                if (Helper.CheckUserInfo(ip, mresult.systemName, companyName))
                {
                    Logger.LogToFile("One ip trys to send Missions to fast. IP:" + ip);
                    return(null);
                }
                Logger.LogLine("New Result Posted");
                Console.WriteLine("employer: " + mresult.employer);
                Console.WriteLine("target: " + mresult.target);
                Console.WriteLine("systemName: " + mresult.systemName);
                Console.WriteLine("mresult: " + mresult.result);
                StarMap        map             = Helper.LoadCurrentMap();
                System         system          = map.FindSystemByName(mresult.systemName);
                FactionControl oldOwnerControl = system.FindHighestControl();
                Faction        oldOwner        = Faction.INVALID_UNSET;
                if (oldOwnerControl != null)
                {
                    oldOwner = oldOwnerControl.faction;
                }
                FactionControl employerControl = system.FindFactionControlByFaction(mresult.employer);
                FactionControl targetControl   = system.FindFactionControlByFaction(mresult.target);

                if (mresult.result == BattleTech.MissionResult.Victory)
                {
                    Console.WriteLine("Victory Result");
                    int realChange = Math.Min(Math.Abs(employerControl.percentage - 100), Math.Max(1, (Helper.LoadSettings().HalfSkullPercentageForWin *realDifficulty) + realRep + realPlanets));
                    hresult.winner              = employerControl.faction;
                    hresult.loser               = targetControl.faction;
                    hresult.pointsTraded        = realChange;
                    employerControl.percentage += realChange;
                    targetControl.percentage   -= realChange;
                    Console.WriteLine(realChange + " Points traded");
                    if (targetControl.percentage < 0)
                    {
                        int leftoverChange = Math.Abs(targetControl.percentage);
                        Console.WriteLine(leftoverChange + " Leftover Points");
                        targetControl.percentage = 0;
                        int debugcounter = leftoverChange;
                        while (leftoverChange > 0 && debugcounter != 0)
                        {
                            foreach (FactionControl leftOverFaction in system.controlList)
                            {
                                if (leftOverFaction.faction != mresult.employer &&
                                    leftOverFaction.faction != mresult.target && leftOverFaction.percentage > 0 &&
                                    leftoverChange > 0)
                                {
                                    leftOverFaction.percentage--;
                                    leftoverChange--;
                                    Console.WriteLine(leftOverFaction.faction.ToString() + " Points deducted");
                                }
                            }
                            debugcounter--;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Loss Result");
                    int realChange = Math.Min(employerControl.percentage, Math.Max(1, (Helper.LoadSettings().HalfSkullPercentageForLoss *realDifficulty) + realRep / 2 + realPlanets / 2));
                    hresult.winner              = targetControl.faction;
                    hresult.loser               = employerControl.faction;
                    hresult.pointsTraded        = realChange;
                    employerControl.percentage -= realChange;
                    targetControl.percentage   += realChange;
                    Console.WriteLine(realChange + " Points traded");
                }
                Helper.SaveCurrentMap(map);
                FactionControl afterBattleOwnerControl = system.FindHighestControl();
                Faction        newOwner = afterBattleOwnerControl.faction;
                if (oldOwner != newOwner)
                {
                    hresult.planetSwitched = true;
                }
                else
                {
                    hresult.planetSwitched = false;
                }
                hresult.system = mresult.systemName;
                Holder.resultHistory.Add(hresult);
                return(system);
            }
            catch (Exception e) {
                Logger.LogError(e);
                return(null);
            }
        }