Пример #1
0
        public static Module ModuleFromJson(string name, JObject json)
        {
            long   id     = (long)json["module"]["id"];
            Module module = ModuleDefinitions.ModuleFromEliteID(id);

            if (module.name == null)
            {
                // Unknown module; log an error so that we can update the definitions
                Logging.Error("No definition for ship module", json["module"].ToString(Formatting.None));
            }

            module.price    = (long)json["module"]["value"];
            module.enabled  = (bool)json["module"]["on"];
            module.priority = (int)json["module"]["priority"];
            // Be sensible with health - round it unless it's very low
            decimal Health = (decimal)json["module"]["health"] / 10000;

            if (Health < 5)
            {
                module.health = Math.Round(Health, 1);
            }
            else
            {
                module.health = Math.Round(Health);
            }

            // Flag if module has modifications
            if (json["module"]["modifiers"] != null)
            {
                module.modified = true;
            }

            return(module);
        }
Пример #2
0
        public static Module ModuleFromProfile(string name, dynamic json)
        {
            long   id     = (long)json["module"]["id"];
            Module module = ModuleDefinitions.ModuleFromEliteID(id);

            if (module.Name == null)
            {
                // Unknown module; log an error so that we can update the definitions
                DataProviderService.LogError("No definition for ship module " + json["module"].ToString());
            }

            module.Cost     = (long)json["module"]["value"];
            module.Enabled  = (bool)json["module"]["on"];
            module.Priority = (int)json["module"]["priority"];
            // Be sensible with health - round it unless it's very low
            decimal Health = (decimal)json["module"]["health"] / 10000;

            if (Health < 5)
            {
                module.Health = Math.Round(Health, 1);
            }
            else
            {
                module.Health = Math.Round(Health);
            }

            if (json["module"]["modifiers"] != null && firstRun)
            {
                DataProviderService.LogError("Module with modification " + json["module"].ToString());
            }
            return(module);
        }
Пример #3
0
        // Obtain the list of outfitting modules from the profile
        public static List <Module> OutfittingFromProfile(dynamic json)
        {
            List <Module> Modules = new List <Module>();

            if (json["lastStarport"] != null && json["lastStarport"]["modules"] != null)
            {
                foreach (dynamic moduleJson in json["lastStarport"]["modules"])
                {
                    dynamic module = moduleJson.Value;
                    // Not interested in paintjobs, decals, ...
                    if (module["category"] == "weapon" || module["category"] == "module")
                    {
                        Module Module = ModuleDefinitions.ModuleFromEliteID((long)module["id"]);
                        if (Module.Name == null)
                        {
                            // Unknown module; log an error so that we can update the definitions
                            DataProviderService.LogError("No definition for outfitting module " + module.ToString());
                        }
                        Module.Cost = module["cost"];
                        Modules.Add(Module);
                    }
                }
            }

            return(Modules);
        }
        // Obtain the list of outfitting modules from the profile
        public static List <Module> OutfittingFromProfile(dynamic json)
        {
            List <Module> Modules = new List <Module>();

            if (json["lastStarport"] != null && json["lastStarport"]["modules"] != null)
            {
                foreach (dynamic moduleJson in json["lastStarport"]["modules"])
                {
                    dynamic module = moduleJson.Value;
                    // Not interested in paintjobs, decals, ...
                    if (module["category"] == "weapon" || module["category"] == "module")
                    {
                        Module Module = ModuleDefinitions.ModuleFromEliteID((long)module["id"]);
                        if (Module.name == null)
                        {
                            // Unknown module; log an error so that we can update the definitions
                            Logging.Error("No definition for outfitting module", module.ToString(Formatting.None));
                            // Set the name from the JSON
                            Module.EDName = (string)module["name"];
                        }
                        Module.price = module["cost"];
                        Modules.Add(Module);
                    }
                }
            }

            return(Modules);
        }
Пример #5
0
        // Obtain the list of outfitting modules from the profile
        public static List <Module> OutfittingFromProfile(dynamic json)
        {
            List <Module> Modules = new List <Module>();

            if (json["lastStarport"] != null && json["lastStarport"]["modules"] != null)
            {
                List <Module> moduleErrors = new List <Module>();
                foreach (dynamic moduleJson in json["lastStarport"]["modules"])
                {
                    dynamic module = moduleJson.Value;
                    // Not interested in paintjobs, decals, ...
                    if (module["category"] == "weapon" || module["category"] == "module" || module["category"] == "utility")
                    {
                        Module Module = ModuleDefinitions.ModuleFromEliteID((long)module["id"]);
                        if (Module.name == null)
                        {
                            // Unknown module; batch and report so that we can update the definitions
                            moduleErrors.Add(module);
                            // Set the name from the JSON
                            Module.EDName = (string)module["name"];
                        }
                        Module.price = module["cost"];
                        Modules.Add(Module);
                    }
                }
                if (moduleErrors.Count > 0)
                {
                    Logging.Report("Module definition errors", JsonConvert.SerializeObject(moduleErrors));
                }
            }

            return(Modules);
        }
Пример #6
0
        public static Module ModuleFromProfile(string name, JObject json)
        {
            long   id     = (long)json["module"]["id"];
            Module module = ModuleDefinitions.ModuleFromEliteID(id);

            if (module.name == null)
            {
                // Unknown module; log an error so that we can update the definitions
                Logging.Error("No definition for ship module", json["module"].ToString(Formatting.None));
            }

            module.price    = (long)json["module"]["value"];
            module.enabled  = (bool)json["module"]["on"];
            module.priority = (int)json["module"]["priority"];
            // Be sensible with health - round it unless it's very low
            decimal Health = (decimal)json["module"]["health"] / 10000;

            if (Health < 5)
            {
                module.health = Math.Round(Health, 1);
            }
            else
            {
                module.health = Math.Round(Health);
            }

            if (json["module"]["modifiers"] != null)
            {
                Dictionary <int, Modification> modifications = new Dictionary <int, Modification>();
                foreach (dynamic modifier in json["module"]["modifiers"]["modifiers"])
                {
                    Modification.Modify((string)modifier["name"], (decimal)modifier["value"], ref modifications);
                }
                Modification.FixUpModifications(module, modifications);

                module.modifications = modifications.Values.ToList();
            }
            return(module);
        }