private static string TestExtensionsFactions(AllFactions allFactions, out int errorsAdded) { int num = 0; string str = ""; if (allFactions.factions.Count != 2) { ++num; str = str + "\nExpected 2 factions, got " + (object)allFactions.factions.Count; } CustomFaction faction = allFactions.factions["tfac"] as CustomFaction; if (faction == null) { ++num; str = str + "\nFaction 1 not listed as custom faction! Reports self as " + (object)faction; } if (faction.name != "Test Faction") { ++num; str += "\nFaction name incorrect!"; } if (faction.playerValue != 0) { ++num; str += "\nFaction starting player value incorrect!"; } if (faction.CustomActions.Count != 5) { ++num; str = str + "\nIncorrect number of custom faction actions! Expected 5, got " + (object)faction.CustomActions.Count; } errorsAdded = num; return(str); }
internal static XElement GetAllFactionsSaveElement(AllFactions factions) { var result = new XElement("AllFactions"); result.SetAttributeValue("current", factions.currentFaction); foreach (var faction in factions.factions) { result.Add(GetFactionSaveElement(faction.Value)); } return(result); }
public static Faction CreateFaction(FactionRelationKind kind, Func <FactionDef, bool> qualifier, bool isGameStart) { //Log.Message("Creating faction..."); var factionDefs = (from fa in DefDatabase <FactionDef> .AllDefs where fa.canMakeRandomly && qualifier(fa) && (!isGameStart || AllFactions.Count(f => f.def == fa) < fa.maxCountAtGameStart) select fa).ToArray(); var facDef = !AllFactions.Any() ? factionDefs.RandomElement() : factionDefs.RandomElementByWeight(FactionChance); Faction faction = FactionGenerator.NewGeneratedFaction(facDef); InitializeFaction(faction, kind); return(faction); }
static async Task Main(string[] args) { string ParentFactionId; // Get Faction Name Console.WriteLine("Please enter the EliteBGS Faction ID. This will default to the Fatherhood if left blank"); string input = Console.ReadLine(); _ = string.IsNullOrEmpty(input) ? ParentFactionId = "5ae4bfccd1b6a37c3c947ddc" : ParentFactionId = input; List <EddbModel> AllFactions; List <KeyValuePair <string, string> > EmptySystemsList = new List <KeyValuePair <string, string> >(); Console.WriteLine("Supply path to EDDB Factions file. Leaving this blank will download this information for this session only and may take some time. You can download this from https://eddb.io/archive/v6/factions.json."); string EddbLocation = Console.ReadLine(); if (string.IsNullOrEmpty(EddbLocation)) { Console.WriteLine("Downloading faction list from EDDB, this may take a moment..."); using (var client = new HttpClient()) { client.BaseAddress = new Uri($"https://eddb.io"); client.DefaultRequestHeaders.Add("User-Agent", "PlayerFactionSystemFinder"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = client.GetAsync($"archive/v6/factions.json").Result; response.EnsureSuccessStatusCode(); AllFactions = JsonConvert.DeserializeObject <List <EddbModel> >(response.Content.ReadAsStringAsync().Result); } } else { using StreamReader file = File.OpenText(EddbLocation); AllFactions = JsonConvert.DeserializeObject <List <EddbModel> >(file.ReadToEnd()); } Welcome ParentSystem; Console.WriteLine("Faction List Done.. Getting list of systems for target faction..."); using (var client = new HttpClient()) { client.BaseAddress = new Uri($"https://elitebgs.app"); client.DefaultRequestHeaders.Add("User-Agent", "PlayerFactionSystemFinder"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = client.GetAsync($"api/ebgs/v5/factions?id={ParentFactionId}").Result; response.EnsureSuccessStatusCode(); ParentSystem = JsonConvert.DeserializeObject <Welcome>(response.Content.ReadAsStringAsync().Result); Console.WriteLine("Done.. Ready to perform search, this will take some time depending on the size of the target faction. Press any key when you're ready to continue..."); Console.ReadKey(); foreach (FactionPresence searchSystem in ParentSystem.Docs[0].FactionPresence) { Console.WriteLine($"Performing search on {searchSystem.SystemName}"); var CubeResponse = client.GetAsync($"api/ebgs/v5/systems?referenceSystemId={searchSystem.SystemId}").Result; response.EnsureSuccessStatusCode(); SystemWelcome CheckSystemResponse = JsonConvert.DeserializeObject <SystemWelcome>(CubeResponse.Content.ReadAsStringAsync().Result); bool systemEmpty; int totalPages = CheckSystemResponse.Pages; for (int page = 1; page <= totalPages; page++) { if (page > 1) { CubeResponse = client.GetAsync($"api/ebgs/v5/systems?referenceSystemId={searchSystem.SystemId}&page={page}").Result; response.EnsureSuccessStatusCode(); CheckSystemResponse = JsonConvert.DeserializeObject <SystemWelcome>(CubeResponse.Content.ReadAsStringAsync().Result); } foreach (SystemDoc CheckSystem in CheckSystemResponse.Docs) { systemEmpty = true; if (CheckSystem.Factions != null) { foreach (FactionElement faction in CheckSystem.Factions) { if (AllFactions.Where(a => a.Name.Equals(faction.Name) && a.IsPlayerFaction.Value == true).Count() > 0) { systemEmpty = false; } } } if (systemEmpty && EmptySystemsList.Where(a => a.Key.Equals(CheckSystem.Name)).Count() == 0) { EmptySystemsList.Add(new KeyValuePair <string, string>(CheckSystem.Name, CheckSystem.Id)); } } await Task.Delay(1000); } } } if (EmptySystemsList.Count() > 0) { Console.WriteLine("The Following systems in the multicube of influence do not contain a player faction..."); foreach (var emptySystem in EmptySystemsList) { Console.WriteLine($">{emptySystem.Key} - https://elitebgs.app/system/{emptySystem.Value}"); } } Console.ReadKey(); return; }
public static void LoadSaveFile(Stream stream, OS os) { var reader = new StreamReader(stream); var saveFileText = reader.ReadToEnd(); if (string.IsNullOrEmpty(saveFileText)) { throw new FormatException("Blank account data detected! (This is a vanilla saving issue)"); } var executor = new EventExecutor(saveFileText, isPath: false); var subExecutor = new ParsedTreeExecutor(); executor.AddExecutor("HacknetSave", (exec, info) => { /* OS.loadTitleSaveData */ MissionGenerator.generationCount = info.Attributes.GetInt("generatedMissionCount", 100); os.defaultUser.name = os.username = info.Attributes.GetValue("Username"); os.LanguageCreatedIn = info.Attributes.GetValueOrDefault("Language", "en-us"); os.IsInDLCMode = info.Attributes.GetBool("DLCMode") && Util.Extensions.CheckLabyrinths(); os.DisableEmailIcon = info.Attributes.GetBool("DisableMailIcon") && Util.Extensions.CheckLabyrinths(); }); /* OS.LoadExtraTitleSaveData / OS.ReadDLCSaveData */ executor.AddExecutor("HacknetSave.DLC", (exec, info) => { os.IsInDLCMode = info.Attributes.GetBool("Active"); var hasLoadedDLC = os.HasLoadedDLCContent = info.Attributes.GetBool("LoadedContent"); if (hasLoadedDLC) { "This save".ThrowNoLabyrinths(); } }); executor.AddExecutor("HacknetSave.DLC.Flags", (exec, info) => os.PreDLCFaction = info.Attributes.GetValue("OriginalFaction")); executor.AddExecutor("HacknetSave.DLC.OriginalVisibleNodes", (exec, info) => os.PreDLCVisibleNodesCache = info.Value, true); executor.AddExecutor("HacknetSave.DLC.ConditionalActions", (exec, info) => { os.ConditionalActions = ActionsLoader.LoadConditionalActions(info); }, true); executor.AddExecutor("HacknetSave.Flags", (exec, info) => { /* ProgressionFlags.Load */ var flags = os.Flags; flags.Flags.Clear(); if (info.Value == null) { return; } foreach (var flag in info.Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { var trueFlag = flag.Replace("[%%COMMAREPLACED%%]", ","); // ReSharper disable StringLiteralTypo if (trueFlag == "décrypté") { trueFlag = "decypher"; } // ReSharper restore StringLiteralTypo flags.AddFlag(trueFlag); } }, true); /* NetworkMap.load */ executor.AddExecutor("HacknetSave.NetworkMap", (exec, info) => { var sortAlgo = info.Attributes.GetValue("sort"); if (!Enum.TryParse(sortAlgo, out os.netMap.SortingAlgorithm)) { /* TODO: Error reporting here */ } subExecutor.Execute(info); foreach (var d in os.netMap.nodes.SelectMany(node => node.daemons)) { d.loadInit(); } os.netMap.loadAssignGameNodes(); }, true); executor.AddExecutor("HacknetSave.NetworkMap.visible", (exec, info) => { var visibleNodes = info.Value; foreach (var node in visibleNodes.Split()) { os.netMap.visibleNodes.Add(Convert.ToInt32(node)); } }, true); executor.AddExecutor("HacknetSave.NetworkMap.network.computer", (exec, info) => { var computer = SaveLoader.LoadComputer(info, os); os.netMap.nodes.Add(computer); }, true); executor.AddExecutor("HacknetSave.mission", (exec, info) => { os.currentMission = SaveLoader.LoadMission(info); }, true); executor.AddExecutor("HacknetSave.AllFactions", (exec, info) => { /* AllFactions.loadFromSave */ var loadedFactions = new AllFactions(); string curFac = loadedFactions.currentFaction = info.Attributes.GetValue("current"); foreach (var child in info.Children) { Faction loaded = LoadFaction(child); loadedFactions.factions.Add(loaded.idName, loaded); } os.allFactions = loadedFactions; if (curFac != "") { os.currentFaction = loadedFactions.factions[curFac]; } }, true); executor.AddExecutor("HacknetSave.other", (exec, info) => { /* OS.loadOtherSaveData */ MusicManager.playSongImmediatley(info.Attributes.GetValue("music")); os.homeNodeID = info.Attributes.GetValueOrDefault("homeNode", "entropy00"); os.homeAssetServerID = info.Attributes.GetValueOrDefault("homeAssetsNode", "entropy01"); }, true); foreach (var exec in SaveDataLoaders) { executor.AddExecutor(exec.Key, exec.Value); } executor.OnOpenFile += OnOpenFile; executor.OnRead += OnRead; executor.OnReadElement += OnReadElement; executor.OnReadEndElement += OnReadEndElement; executor.OnReadDocument += OnReadDocument; executor.OnReadComment += OnReadComment; executor.OnReadText += OnReadText; executor.OnReadProcessingInstructions += OnReadProcessingInstructions; executor.OnCloseFile += OnCloseFile; executor.OnCloseFile += _ => { OS.WillLoadSave = false; os.FirstTimeStartup = false; }; /* hook up child parser */ subExecutor.delegateData = executor.delegateData; executor.Parse(); }
public bool TryGetRandomNonColonyHumanlikeFaction_NewTemp(out Faction faction, bool tryMedievalOrBetter, bool allowDefeated = false, TechLevel minTechLevel = TechLevel.Undefined, bool allowTemporary = false) { return(AllFactions.Where((Faction x) => !x.IsPlayer && !x.Hidden && x.def.humanlikeFaction && (allowDefeated || !x.defeated) && (allowTemporary || !x.temporary) && (minTechLevel == TechLevel.Undefined || (int)x.def.techLevel >= (int)minTechLevel)).TryRandomElementByWeight((Faction x) => (tryMedievalOrBetter && (int)x.def.techLevel < 3) ? 0.1f : 1f, out faction)); }