コード例 #1
0
        private string StripTag(string name, Government gov)
        {
            if (gov == null)
                return name;
            var re = new Regex(@"^\[" + gov.Tag + @"\]\s");
            while (re.IsMatch(name))
                name = name.Substring(gov.Tag.Length + 3);

            Puts("StripTag result = " + name);
            return name;
        }
コード例 #2
0
        public void LoadData()
        {
            govs.Clear();
            lookup.Clear();
            RankList.Clear();
            permissionList.Clear();
            var data = Interface.GetMod().DataFileSystem.GetDatafile(GovernmentDataFilename);
            var settings = Interface.GetMod().DataFileSystem.GetDatafile(GovernmentSettingsFilename);

            // Load Rank List
            if (settings["ranks"] != null)
            {
                var rankList = (List<object>)Convert.ChangeType(settings["ranks"], typeof(List<object>));
                foreach (var irank in rankList)
                {
                    RankList.Add((string)irank);
                }
            }

            // Load Permissions List
            if (settings["permissions"] != null)
            {
                var permissionData = (Dictionary<string, object>)Convert.ChangeType(settings["permissions"], typeof(Dictionary<string, object>));
                foreach (var ipermission in permissionData)
                {
                    var permitList = (List<object>)Convert.ChangeType(ipermission.Value, typeof(List<object>));
                    var newPermitList = new List<string>();
                    foreach (var permit in permitList) newPermitList.Add((string)permit);
                    permissionList.Add(ipermission.Key, newPermitList);
                }
            }
            else
            {

            }

            // Load Damage Scale Types Table
            if(settings["damageScales"] != null)
            {
                var damageScaleData = (Dictionary<string, object>)Convert.ChangeType(settings["damageScales"], typeof(Dictionary<string, object>));
                foreach(var attackerData in damageScaleData)
                {
                    var attackerRank = attackerData.Key;
                    var victimData = (Dictionary<string, object>)attackerData.Value;
                    var victims = new Dictionary<string, float>();
                    foreach(var victim in victimData)
                    {
                        var victimRank = victim.Key;
                        var damageScaleValue = (float) Convert.ChangeType(victim.Value, typeof(float));
                        victims.Add(victimRank, damageScaleValue);
                    }
                    damageScaleTable.Add(attackerRank, victims);
                }
            }
            else
            {

            }

            // Load Government Data
            if (data["governments"] != null)
            {
                var govsData = (Dictionary<string, object>)Convert.ChangeType(data["governments"], typeof(Dictionary<string, object>));
                foreach (var igov in govsData)
                {
                    var gov = (Dictionary<string, object>)igov.Value;
                    var tag = (string)igov.Key;
                    var name = (string)gov["name"];
                    var membersData = (Dictionary<string, object>)gov["members"];
                    var members = new Dictionary<string, string>();
                    foreach (var imember in membersData)
                    {
                        var memberID = (string)imember.Key;
                        var memberRank = (string)imember.Value;
                        members.Add(memberID, memberRank);
                    }
                    var guestsData = (List<object>)gov["guests"];
                    var guests = new List<string>();
                    foreach (var iguest in guestsData)
                    {
                        guests.Add(iguest.ToString());
                    }
                    var invitedsData = (List<object>)gov["inviteds"];
                    var inviteds = new List<string>();
                    foreach (var iinvited in invitedsData)
                    {
                        inviteds.Add(iinvited.ToString());
                    }
                    var newGov = new Government() { Tag = tag, Name = name};
                    foreach (var m in members) newGov.AddMember(m.Key, m.Value);
                    newGov.Guests = guests;
                    newGov.Inviteds = inviteds;
                    govs.Add(tag, newGov);
                }
            }
            Puts("Successfully loaded (" + govs.Count + ") governments.");
        }
コード例 #3
0
 public DockedEvent(DateTime timestamp, string system, string station, Superpower allegiance, string faction, State factionstate, Economy economy, Government government, SecurityLevel security) : base(timestamp, NAME)
 {
     this.system       = system;
     this.station      = station;
     this.allegiance   = (allegiance == null ? Superpower.None.name : allegiance.name);
     this.faction      = faction;
     this.factionstate = (factionstate == null ? State.None.name : factionstate.name);
     this.economy      = (economy == null ? Economy.None.name : economy.name);
     this.government   = (government == null ? Government.None.name : government.name);
     this.security     = (security == null ? SecurityLevel.Low.name : security.name);
 }
コード例 #4
0
 private void CreateGovernment(string tag, string name, string creatorID)
 {
     var newGov = new Government() { Tag = tag, Name = name };
     govs.Add(tag, newGov);
     newGov.AddMember(creatorID, Rank("DICTATOR"));
 }
コード例 #5
0
        /// <summary>
        /// Build a store from a list of variables
        /// </summary>
        private BuiltinStore buildStore(Dictionary <string, Cottle.Value> vars)
        {
            BuiltinStore store = new BuiltinStore();

            // TODO fetch this from configuration
            bool useICAO = SpeechServiceConfiguration.FromFile().EnableIcao;

            // Function to call another script
            store["F"] = new NativeFunction((values) =>
            {
                return(new ScriptResolver(scripts).resolve(values[0].AsString, store, false));
            }, 1);

            // Translation functions
            store["P"] = new NativeFunction((values) =>
            {
                string val         = values[0].AsString;
                string translation = val;
                if (translation == val)
                {
                    translation = Translations.Body(val, useICAO);
                }
                if (translation == val)
                {
                    translation = Translations.StarSystem(val, useICAO);
                }
                if (translation == val)
                {
                    translation = Translations.Faction(val);
                }
                if (translation == val)
                {
                    translation = Translations.Power(val);
                }
                if (translation == val)
                {
                    Ship ship = ShipDefinitions.FromModel(val);
                    if (ship != null && ship.EDID > 0)
                    {
                        translation = ship.SpokenModel();
                    }
                }
                if (translation == val)
                {
                    Ship ship = ShipDefinitions.FromEDModel(val);
                    if (ship != null && ship.EDID > 0)
                    {
                        translation = ship.SpokenModel();
                    }
                }
                return(translation);
            }, 1);

            // Boolean constants
            store["true"]  = true;
            store["false"] = false;

            // Helper functions
            store["OneOf"] = new NativeFunction((values) =>
            {
                return(new ScriptResolver(scripts).resolveScript(values[random.Next(values.Count)].AsString, store, false));
            });

            store["Occasionally"] = new NativeFunction((values) =>
            {
                if (random.Next((int)values[0].AsNumber) == 0)
                {
                    return(new ScriptResolver(scripts).resolveScript(values[1].AsString, store, false));
                }
                else
                {
                    return("");
                }
            }, 2);

            store["Humanise"] = new NativeFunction((values) =>
            {
                return(Translations.Humanize(values[0].AsNumber));
            }, 1);

            store["List"] = new NativeFunction((values) =>
            {
                string output             = String.Empty;
                const string localisedAnd = "and";
                if (values.Count == 1)
                {
                    foreach (KeyValuePair <Cottle.Value, Cottle.Value> value in values[0].Fields)
                    {
                        string valueString = value.Value.ToString();
                        if (value.Key == 0)
                        {
                            output = valueString;
                        }
                        else if (value.Key < (values[0].Fields.Count - 1))
                        {
                            output = $"{output}, {valueString}";
                        }
                        else
                        {
                            output = $"{output}, {localisedAnd} {valueString}";
                        }
                    }
                }
                return(output);
            }, 1);

            store["Pause"] = new NativeFunction((values) =>
            {
                return(@"<break time=""" + values[0].AsNumber + @"ms"" />");
            }, 1);

            store["Play"] = new NativeFunction((values) =>
            {
                return(@"<audio src=""" + values[0].AsString + @""" />");
            }, 1);

            store["Spacialise"] = new NativeFunction((values) =>
            {
                string Entree = values[0].AsString;
                if (Entree == "")
                {
                    return("");
                }
                string Sortie      = "";
                string UpperSortie = "";
                foreach (char c in Entree)
                {
                    Sortie = Sortie + c + " ";
                }
                UpperSortie = Sortie.ToUpper();
                return(UpperSortie);
            }, 1);

            store["Emphasize"] = new NativeFunction((values) =>
            {
                if (values.Count == 1)
                {
                    return(@"<emphasis level =""strong"">" + values[0].AsString + @"</emphasis>");
                }
                else if (values.Count == 2)
                {
                    return(@"<emphasis level =""" + values[1].AsString + @""">" + values[0].AsString + @"</emphasis>");
                }
                else
                {
                    return("The Emphasize function is used improperly. Please review the documentation for correct usage.");
                }
            }, 1, 2);

            store["SpeechPitch"] = new NativeFunction((values) =>
            {
                string text  = values[0].AsString;
                string pitch = "default";
                if (values.Count == 1 || string.IsNullOrEmpty(values[1].AsString))
                {
                    return(text);
                }
                else if (values.Count == 2)
                {
                    pitch = values[1].AsString;
                    return(@"<prosody pitch=""" + pitch + @""">" + text + "</prosody>");
                }
                else
                {
                    return("The SpeechPitch function is used improperly. Please review the documentation for correct usage.");
                }
            }, 1, 2);

            store["SpeechRate"] = new NativeFunction((values) =>
            {
                string text = values[0].AsString;
                string rate = "default";
                if (values.Count == 1 || string.IsNullOrEmpty(values[1].AsString))
                {
                    return(text);
                }
                else if (values.Count == 2)
                {
                    rate = values[1].AsString;
                    return(@"<prosody rate=""" + rate + @""">" + text + "</prosody>");
                }
                else
                {
                    return("The SpeechRate function is used improperly. Please review the documentation for correct usage.");
                }
            }, 1, 2);

            store["SpeechVolume"] = new NativeFunction((values) =>
            {
                string text   = values[0].AsString;
                string volume = "default";
                if (values.Count == 1 || string.IsNullOrEmpty(values[1].AsString))
                {
                    return(text);
                }
                else if (values.Count == 2)
                {
                    volume = values[1].AsString;
                    return(@"<prosody volume=""" + volume + @""">" + text + "</prosody>");
                }
                else
                {
                    return("The SpeechVolume function is used improperly. Please review the documentation for correct usage.");
                }
            }, 1, 2);

            store["StartsWithVowel"] = new NativeFunction((values) =>
            {
                string Entree = values[0].AsString;
                if (Entree == "")
                {
                    return("");
                }

                char[] vowels       = { 'a', 'à', 'â', 'ä', 'e', 'ê', 'é', 'è', 'ë', 'i', 'î', 'ï', 'o', 'ô', 'ö', 'u', 'ù', 'û', 'ü', 'œ', 'y' };
                char firstCharacter = Entree.ToLower().ToCharArray().ElementAt(0);
                Boolean result      = vowels.Contains(firstCharacter);

                return(result);
            }, 1);

            //
            // Commander-specific functions
            //
            store["ShipName"] = new NativeFunction((values) =>
            {
                int?localId   = (values.Count == 0 ? (int?)null : (int)values[0].AsNumber);
                string model  = (values.Count == 2 ? values[1].AsString : null);
                Ship ship     = findShip(localId, model);
                string result = (ship == null ? "your ship" : ship.SpokenName());
                return(result);
            }, 0, 2);

            store["ShipCallsign"] = new NativeFunction((values) =>
            {
                int?localId = (values.Count == 0 ? (int?)null : (int)values[0].AsNumber);
                Ship ship   = findShip(localId, null);

                string result;
                if (ship != null)
                {
                    if (EDDI.Instance.Cmdr != null && EDDI.Instance.Cmdr.name != null)
                    {
                        // Obtain the first three characters
                        string chars = new Regex("[^a-zA-Z0-9]").Replace(EDDI.Instance.Cmdr.name, "").ToUpperInvariant().Substring(0, 3);
                        result       = ship.SpokenManufacturer() + " " + Translations.ICAO(chars);
                    }
                    else
                    {
                        if (ship.SpokenManufacturer() == null)
                        {
                            result = "unidentified ship";
                        }
                        else
                        {
                            result = "unidentified " + ship.SpokenManufacturer() + " " + ship.SpokenModel();
                        }
                    }
                }
                else
                {
                    result = "unidentified ship";
                }
                return(result);
            }, 0, 1);

            //
            // Obtain definition objects for various items
            //

            store["SecondsSince"] = new NativeFunction((values) =>
            {
                long?date = (long?)values[0].AsNumber;
                if (date == null)
                {
                    return(null);
                }
                long now = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

                return(now - date);
            }, 1);

            store["ICAO"] = new NativeFunction((values) =>
            {
                // Turn a string in to an ICAO definition
                string value = values[0].AsString;
                if (value == null || value == "")
                {
                    return("");
                }

                // Remove anything that isn't alphanumeric
                Logging.Warn("value is " + value);
                value = value.ToUpperInvariant().Replace("[^A-Z0-9]", "");
                Logging.Warn("value is " + value);

                // Translate to ICAO
                return(Translations.ICAO(value));
            }, 1);

            store["ShipDetails"] = new NativeFunction((values) =>
            {
                Ship result = ShipDefinitions.FromModel(values[0].AsString);
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["CombatRatingDetails"] = new NativeFunction((values) =>
            {
                CombatRating result = CombatRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = CombatRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["TradeRatingDetails"] = new NativeFunction((values) =>
            {
                TradeRating result = TradeRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = TradeRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["ExplorationRatingDetails"] = new NativeFunction((values) =>
            {
                ExplorationRating result = ExplorationRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = ExplorationRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["EmpireRatingDetails"] = new NativeFunction((values) =>
            {
                EmpireRating result = EmpireRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = EmpireRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["FederationRatingDetails"] = new NativeFunction((values) =>
            {
                FederationRating result = FederationRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = FederationRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["SystemDetails"] = new NativeFunction((values) =>
            {
                StarSystem result = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(values[0].AsString, true);
                setSystemDistanceFromHome(result);
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["BodyDetails"] = new NativeFunction((values) =>
            {
                StarSystem system;
                if (values.Count == 1 || string.IsNullOrEmpty(values[1].AsString))
                {
                    // Current system
                    system = EDDI.Instance.CurrentStarSystem;
                }
                else
                {
                    // Named system
                    system = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(values[1].AsString, true);
                }
                Body result = system != null && system.bodies != null ? system.bodies.FirstOrDefault(v => v.name == values[0].AsString) : null;
                if (result != null && result.type == "Star" && result.chromaticity == null)
                {
                    // Need to set our internal extras for the star
                    result.setStellarExtras();
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1, 2);

            store["StationDetails"] = new NativeFunction((values) =>
            {
                if (values.Count == 0)
                {
                    return(null);
                }
                StarSystem system;
                if (values.Count == 1)
                {
                    // Current system
                    system = EDDI.Instance.CurrentStarSystem;
                }
                else
                {
                    // Named system
                    system = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(values[1].AsString, true);
                }
                Station result = system != null && system.stations != null ? system.stations.FirstOrDefault(v => v.name == values[0].AsString) : null;
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1, 2);

            store["SuperpowerDetails"] = new NativeFunction((values) =>
            {
                Superpower result = Superpower.FromName(values[0].AsString);
                if (result == null)
                {
                    result = Superpower.From(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["StateDetails"] = new NativeFunction((values) =>
            {
                State result = State.FromName(values[0].AsString);
                if (result == null)
                {
                    result = State.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["EconomyDetails"] = new NativeFunction((values) =>
            {
                Economy result = Economy.FromName(values[0].AsString);
                if (result == null)
                {
                    result = Economy.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["GovernmentDetails"] = new NativeFunction((values) =>
            {
                Government result = Government.FromName(values[0].AsString);
                if (result == null)
                {
                    result = Government.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["SecurityLevelDetails"] = new NativeFunction((values) =>
            {
                SecurityLevel result = SecurityLevel.FromName(values[0].AsString);
                if (result == null)
                {
                    result = SecurityLevel.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["MaterialDetails"] = new NativeFunction((values) =>
            {
                if (string.IsNullOrEmpty(values[0].AsString))
                {
                    return(new ReflectionValue(new object()));
                }

                Material result = Material.FromName(values[0].AsString);
                if (result == null)
                {
                    result = Material.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["BlueprintDetails"] = new NativeFunction((values) =>
            {
                BlueprintMaterials result = BlueprintMaterials.FromName(values[0].AsString);
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["GalnetNewsArticle"] = new NativeFunction((values) =>
            {
                News result = GalnetSqLiteRepository.Instance.GetArticle(values[0].AsString);
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["GalnetNewsArticles"] = new NativeFunction((values) =>
            {
                List <News> results = null;
                if (values.Count == 0)
                {
                    // Obtain all unread articles
                    results = GalnetSqLiteRepository.Instance.GetArticles();
                }
                else if (values.Count == 1)
                {
                    // Obtain all unread news of a given category
                    results = GalnetSqLiteRepository.Instance.GetArticles(values[0].AsString);
                }
                else if (values.Count == 2)
                {
                    // Obtain all news of a given category
                    results = GalnetSqLiteRepository.Instance.GetArticles(values[0].AsString, values[1].AsBoolean);
                }
                return(results == null ? new ReflectionValue(new List <News>()) : new ReflectionValue(results));
            }, 0, 2);

            store["GalnetNewsMarkRead"] = new NativeFunction((values) =>
            {
                News result = GalnetSqLiteRepository.Instance.GetArticle(values[0].AsString);
                if (result != null)
                {
                    GalnetSqLiteRepository.Instance.MarkRead(result);
                }
                return("");
            }, 1);

            store["GalnetNewsMarkUnread"] = new NativeFunction((values) =>
            {
                News result = GalnetSqLiteRepository.Instance.GetArticle(values[0].AsString);
                if (result != null)
                {
                    GalnetSqLiteRepository.Instance.MarkUnread(result);
                }
                return("");
            }, 1);

            store["GalnetNewsDelete"] = new NativeFunction((values) =>
            {
                News result = GalnetSqLiteRepository.Instance.GetArticle(values[0].AsString);
                if (result != null)
                {
                    GalnetSqLiteRepository.Instance.DeleteNews(result);
                }
                return("");
            }, 1);

            store["Distance"] = new NativeFunction((values) =>
            {
                return((decimal)Math.Round(Math.Sqrt(Math.Pow((double)(values[0].AsNumber - values[3].AsNumber), 2)
                                                     + Math.Pow((double)(values[1].AsNumber - values[4].AsNumber), 2)
                                                     + Math.Pow((double)(values[2].AsNumber - values[5].AsNumber), 2)), 2));
            }, 6);

            store["Log"] = new NativeFunction((values) =>
            {
                Logging.Info(values[0].AsString);
                return("");
            }, 1);

            store["SetState"] = new NativeFunction((values) =>
            {
                string name        = values[0].AsString.ToLowerInvariant().Replace(" ", "_");
                Cottle.Value value = values[1];
                if (value.Type == Cottle.ValueContent.Boolean)
                {
                    EDDI.Instance.State[name] = value.AsBoolean;
                    store["state"]            = buildState();
                }
                else if (value.Type == Cottle.ValueContent.Number)
                {
                    EDDI.Instance.State[name] = value.AsNumber;
                    store["state"]            = buildState();
                }
                else if (value.Type == Cottle.ValueContent.String)
                {
                    EDDI.Instance.State[name] = value.AsString;
                    store["state"]            = buildState();
                }
                // Ignore other possibilities
                return("");
            }, 2);

            // Variables
            foreach (KeyValuePair <string, Cottle.Value> entry in vars)
            {
                store[entry.Key] = entry.Value;
            }

            return(store);
        }
コード例 #6
0
ファイル: EdsmSystemData.cs プロジェクト: vadark1976/EDDI
        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);
        }
コード例 #7
0
ファイル: DockedEvent.cs プロジェクト: TalShaf/EDDI
 public DockedEvent(DateTime timestamp, string system, string station, string state, string model, Superpower allegiance, string faction, State factionstate, Economy economy, Government government, decimal?distancefromstar, List <string> stationservices) : base(timestamp, NAME)
 {
     this.system           = system;
     this.station          = station;
     this.state            = state;
     this.model            = model;
     this.allegiance       = allegiance;
     this.faction          = faction;
     this.factionstate     = (factionstate == null ? State.None.name : factionstate.name);
     this.economy          = (economy == null ? Economy.None.name : economy.name);
     this.government       = (government == null ? Government.None.name : government.name);
     this.distancefromstar = distancefromstar;
     this.stationservices  = stationservices;
 }
コード例 #8
0
ファイル: EdsmStationData.cs プロジェクト: lagoth/EDDI
        private static Station ParseStarMapStation(JObject station, string system)
        {
            Station Station = new Station
            {
                systemname       = system,
                name             = (string)station["name"],
                marketId         = (long?)station["marketId"],
                EDSMID           = (long?)station["id"],
                Model            = StationModel.FromName((string)station["type"]) ?? StationModel.None,
                distancefromstar = (decimal?)station["distanceToArrival"], // Light seconds
            };

            var faction = station["controllingFaction"]?.ToObject <Dictionary <string, object> >();

            Station.Faction = new Faction()
            {
                name       = (string)faction?["name"] ?? string.Empty,
                EDSMID     = (long?)faction?["id"],
                Allegiance = Superpower.FromName((string)station["allegiance"]) ?? Superpower.None,
                Government = Government.FromName((string)station["government"]) ?? Government.None,
            };

            List <Economy> Economies = new List <Economy>()
            {
                Economy.FromName((string)station["economy"]) ?? Economy.None,
                Economy.FromName((string)station["secondEconomy"]) ?? Economy.None
            };

            Station.Economies = Economies;

            List <StationService> stationServices = new List <StationService>();

            if ((bool?)station["haveMarket"] is true)
            {
                stationServices.Add(StationService.FromEDName("Commodities"));
            }
            ;
            if ((bool?)station["haveShipyard"] is true)
            {
                stationServices.Add(StationService.FromEDName("Shipyard"));
            }
            ;
            if ((bool?)station["haveOutfitting"] is true)
            {
                stationServices.Add(StationService.FromEDName("Outfitting"));
            }
            ;
            var services = station["otherServices"].ToObject <List <string> >();

            foreach (string service in services)
            {
                stationServices.Add(StationService.FromName(service));
            }
            ;
            // Add always available services for dockable stations
            stationServices.Add(StationService.FromEDName("Dock"));
            stationServices.Add(StationService.FromEDName("AutoDock"));
            stationServices.Add(StationService.FromEDName("Exploration"));
            stationServices.Add(StationService.FromEDName("Workshop"));
            stationServices.Add(StationService.FromEDName("FlightController"));
            stationServices.Add(StationService.FromEDName("StationOperations"));
            stationServices.Add(StationService.FromEDName("Powerplay"));
            Station.stationServices = stationServices;

            var    updateTimes = station["updateTime"].ToObject <Dictionary <string, object> >();
            string datetime;

            datetime = JsonParsing.getString(updateTimes, "information");
            long?infoLastUpdated = Dates.fromDateTimeStringToSeconds(datetime);

            datetime = JsonParsing.getString(updateTimes, "market");
            long?marketLastUpdated = Dates.fromDateTimeStringToSeconds(datetime);

            datetime = JsonParsing.getString(updateTimes, "shipyard");
            long?shipyardLastUpdated = Dates.fromDateTimeStringToSeconds(datetime);

            datetime = JsonParsing.getString(updateTimes, "outfitting");
            long?        outfittingLastUpdated = Dates.fromDateTimeStringToSeconds(datetime);
            List <long?> updatedAt             = new List <long?>()
            {
                infoLastUpdated, marketLastUpdated, shipyardLastUpdated, outfittingLastUpdated
            };

            Station.updatedat            = updatedAt.Max();
            Station.outfittingupdatedat  = outfittingLastUpdated;
            Station.commoditiesupdatedat = marketLastUpdated;
            Station.shipyardupdatedat    = shipyardLastUpdated;

            return(Station);
        }
コード例 #9
0
 public JumpedEvent(DateTime timestamp, string system, decimal x, decimal y, decimal z, decimal distance, decimal fuelused, decimal fuelremaining, Superpower allegiance, string faction, State factionstate, Economy economy, Government government, SecurityLevel security, long?population) : base(timestamp, NAME)
 {
     this.system        = system;
     this.x             = x;
     this.y             = y;
     this.z             = z;
     this.distance      = distance;
     this.fuelused      = fuelused;
     this.fuelremaining = fuelremaining;
     this.allegiance    = (allegiance == null ? Superpower.None.name : allegiance.name);
     this.faction       = faction;
     this.factionstate  = (factionstate == null ? State.None.name : factionstate.name);
     this.economy       = (economy == null ? Economy.None.name : economy.name);
     this.government    = (government == null ? Government.None.name : government.name);
     this.security      = (security == null ? SecurityLevel.None.name : security.name);
     this.population    = population;
 }