private bool ReadFactionFirst() { CheckBasics(); byte index = _reader.ReadByte(); byte typeIndex = _reader.ReadByte(); if (!_knownFactionTypes.ContainsKey(typeIndex)) throw new NotSupportedException("Type is not registered"); // Neue Instanz erzeugen Type factionType = _knownFactionTypes[typeIndex]; FactionState state = null; if (factionType != null) { state = Activator.CreateInstance(factionType) as FactionState; state.SlotIndex = index; ValidatedDeserialisation(state.DeserializeFirst); } else { state = new FactionState(); SkipBlock(); } _factions.Add(index, state); _currentState.Factions.Add(state); return true; }
public StarSystem ParseStarMapSystem(JObject response) { StarSystem starSystem = new StarSystem { systemname = (string)response["name"], systemAddress = (long?)response["id64"], EDSMID = (long?)response["id"] }; if (response["coords"] is JObject) { var coords = response["coords"].ToObject <Dictionary <string, decimal?> >(); starSystem.x = coords["x"]; starSystem.y = coords["y"]; starSystem.z = coords["z"]; } if (response["primaryStar"] is JObject primarystar) { Body primaryStar = new Body() { bodyname = (string)primarystar["name"], bodyType = BodyType.FromEDName("Star"), distance = 0, stellarclass = ((string)primarystar["type"])?.Split(' ')[0] }; starSystem.AddOrUpdateBody(primaryStar); } if ((bool?)response["requirePermit"] is true) { starSystem.requirespermit = true; starSystem.permitname = (string)response["permitName"]; } if (response["information"] is JObject information) { starSystem.Reserve = ReserveLevel.FromName((string)information["reserve"]) ?? ReserveLevel.None; starSystem.population = (long?)information["population"] ?? 0; // Populated system data if (starSystem.population > 0) { Faction controllingFaction = new Faction { name = (string)information["faction"], Allegiance = Superpower.FromName((string)information["allegiance"]) ?? Superpower.None, Government = Government.FromName((string)information["government"]) ?? Government.None, }; controllingFaction.presences.Add(new FactionPresence() { systemName = starSystem.systemname, FactionState = FactionState.FromName((string)information["factionState"]) ?? FactionState.None, }); starSystem.Faction = controllingFaction; starSystem.securityLevel = SecurityLevel.FromName((string)information["security"]) ?? SecurityLevel.None; starSystem.Economies = new List <Economy>() { Economy.FromName((string)information["economy"]) ?? Economy.None, Economy.FromName((string)information["secondEconomy"]) ?? Economy.None }; } } starSystem.lastupdated = DateTime.UtcNow; return(starSystem); }