Ejemplo n.º 1
0
        public void HandleProfile(JObject profile)
        {
            // Obtain the current ship from the profile
            Ship profileCurrentShip = FrontierApi.ShipFromJson((JObject)profile["ship"]);

            // Obtain the shipyard from the profile
            List <Ship> profileShipyard = FrontierApi.ShipyardFromJson(profileCurrentShip, profile);

            if (profileCurrentShip != null)
            {
                currentProfileId = profileCurrentShip.LocalId;
                if (currentShipId == null)
                {
                    // This means that we don't have any info so far; set our active ship
                    currentShipId = profileCurrentShip.LocalId;
                }
                Logging.Debug("Current Ship Id is: " + currentShipId + ", Profile Ship Id is: " + profileCurrentShip.LocalId);

                if (currentShipId == profileCurrentShip.LocalId)
                {
                    Ship ship = GetShip(currentShipId);
                    if (ship == null)
                    {
                        // Information from the Frontier API can be out-of-date, use it to set our ship if we don't know what it already is
                        ship = profileCurrentShip;
                        AddShip(ship);
                    }
                    else
                    {
                        ship.raw        = profileCurrentShip.raw;
                        ship.launchbays = profileCurrentShip.launchbays;
                        ship.paintjob   = profileCurrentShip.paintjob;

                        if (ship.cargohatch != null)
                        {
                            // Engineering info for each module isn't in the journal, but we only use this to pass on to Coriolis so don't
                            // need to splice it in to our model.  We do, however, have cargo hatch information from the journal that we
                            // want to make avaialable to Coriolis so need to parse the raw data and add cargo hatch info as appropriate
                            JObject cargoHatchModule = new JObject
                            {
                                { "on", ship.cargohatch.enabled },
                                { "priority", ship.cargohatch.priority },
                                { "value", ship.cargohatch.price },
                                { "health", ship.cargohatch.health },
                                { "name", "ModularCargoBayDoor" }
                            };
                            JObject cargoHatchSlot = new JObject
                            {
                                { "module", cargoHatchModule }
                            };
                            JObject parsedRaw = JObject.Parse(profileCurrentShip.raw);
                            parsedRaw["modules"]["CargoHatch"] = cargoHatchSlot;
                            ship.raw = parsedRaw.ToString(Formatting.None);
                        }
                    }
                    Logging.Debug("Ship is: " + JsonConvert.SerializeObject(ship));
                }
            }

            // Prune ships from the Shipyard that are not found in the Profile Shipyard
            List <int> idsToRemove = new List <int>(shipyard.Count);

            foreach (Ship ship in shipyard)
            {
                Ship profileShip = profileShipyard.FirstOrDefault(s => s.LocalId == ship.LocalId);
                if (profileShip == null)
                {
                    idsToRemove.Add(ship.LocalId);
                }
            }
            _RemoveShips(idsToRemove);

            // Add ships from the Profile Shipyard that are not found in the Shipyard
            // Update name, ident and value of ships in the Shipyard
            foreach (Ship profileShip in profileShipyard)
            {
                Ship ship = GetShip(profileShip.LocalId);
                if (ship == null)
                {
                    // This is a new ship, add it to the shipyard
                    AddShip(profileShip);
                }
            }

            writeShips();
        }
Ejemplo n.º 2
0
        // Note: At a minimum, the API Profile data is required to update the current ship's launchbay status
        public void HandleProfile(JObject profile)
        {
            // Obtain the current ship from the profile
            Ship profileCurrentShip = FrontierApi.ShipFromJson((JObject)profile["ship"]);

            // Obtain the shipyard from the profile
            List <Ship> profileShipyard = FrontierApi.ShipyardFromJson(profileCurrentShip, profile);

            if (profileCurrentShip != null)
            {
                currentProfileId = profileCurrentShip.LocalId;
                if (currentShipId == null)
                {
                    // This means that we don't have any info so far; set our active ship
                    currentShipId = profileCurrentShip.LocalId;
                }
                Logging.Debug("Current Ship Id is: " + currentShipId + ", Profile Ship Id is: " + profileCurrentShip.LocalId);

                if (currentShipId == profileCurrentShip.LocalId)
                {
                    Ship ship = GetShip(currentShipId);
                    if (ship == null)
                    {
                        // Information from the Frontier API can be out-of-date, use it to set our ship if we don't know what it already is
                        ship = profileCurrentShip;
                        AddShip(ship);
                    }
                    // Ship launchbay data is exclusively from the API, always update.
                    else
                    {
                        if (profileCurrentShip.launchbays == null || !profileCurrentShip.launchbays.Any())
                        {
                            ship.launchbays.Clear();
                        }
                        else
                        {
                            ship.launchbays = profileCurrentShip.launchbays;
                        }
                    }
                    Logging.Debug("Ship is: " + JsonConvert.SerializeObject(ship));
                }
            }

            // Prune ships from the Shipyard that are not found in the Profile Shipyard
            List <int> idsToRemove = new List <int>(shipyard.Count);

            foreach (Ship ship in shipyard)
            {
                Ship profileShip = profileShipyard.FirstOrDefault(s => s.LocalId == ship.LocalId);
                if (profileShip == null)
                {
                    idsToRemove.Add(ship.LocalId);
                }
            }
            _RemoveShips(idsToRemove);

            // Add ships from the Profile Shipyard that are not found in the Shipyard
            // Update name, ident and value of ships in the Shipyard
            foreach (Ship profileShip in profileShipyard)
            {
                Ship ship = GetShip(profileShip.LocalId);
                if (ship == null)
                {
                    // This is a new ship, add it to the shipyard
                    AddShip(profileShip);
                }
            }

            writeShips();
        }
        public void HandleProfile(JObject profile)
        {
            // Obtain the current ship from the profile
            Ship profileCurrentShip = FrontierApi.ShipFromJson((JObject)profile["ship"]);

            // Obtain the shipyard from the profile
            List <Ship> profileShipyard = FrontierApi.ShipyardFromJson(profileCurrentShip, profile);

            // Information from the Frontier API can be out-of-date so we only use it to set our ship if we don't know what it already is
            if (currentShipId == null)
            {
                // This means that we don't have any info so far; set our active ship
                if (profileCurrentShip != null)
                {
                    SetCurrentShip(profileCurrentShip.LocalId, profileCurrentShip.model);
                }
            }

            // Add the raw JSON for each known ship provided in the profile
            // TODO Rationalise companion API data - munge the JSON according to the compartment information, removing anything that is out-of-sync
            if (profileCurrentShip != null)
            {
                Ship ship = GetShip(profileCurrentShip.LocalId);
                if (ship == null)
                {
                    // This means that we haven't seen the ship in the profile before.  Add it to the shipyard
                    ship = profileCurrentShip;
                    AddShip(ship);
                }
                if (ship.model == null)
                {
                    // We don't know this ship's model but can fill it from the info we have
                    ship.model = profileCurrentShip.model;
                    ship.Augment();
                }
                // Obtain items that we can't obtain from the journal
                ship.value = profileCurrentShip.value;
                if (ship.cargohatch != null)
                {
                    // Engineering info for each module isn't in the journal, but we only use this to pass on to Coriolis so don't
                    // need to splice it in to our model.  We do, however, have cargo hatch information from the journal that we
                    // want to make avaialable to Coriolis so need to parse the raw data and add cargo hatch info as appropriate
                    JObject cargoHatchModule = new JObject
                    {
                        { "on", ship.cargohatch.enabled },
                        { "priority", ship.cargohatch.priority },
                        { "value", ship.cargohatch.price },
                        { "health", ship.cargohatch.health },
                        { "name", "ModularCargoBayDoor" }
                    };
                    JObject cargoHatchSlot = new JObject
                    {
                        { "module", cargoHatchModule }
                    };
                    JObject parsedRaw = JObject.Parse(profileCurrentShip.raw);
                    parsedRaw["modules"]["CargoHatch"] = cargoHatchSlot;
                    ship.raw = parsedRaw.ToString(Formatting.None);
                }
            }

            // As of 2.3.0 Frontier no longer supplies module information for ships other than the active ship, so we
            // keep around the oldest information that we have available
            //foreach (Ship profileShip in profileShipyard)
            //{
            //    Ship ship = GetShip(profileShip.LocalId);
            //    if (ship != null)
            //    {
            //        ship.raw = profileShip.raw;
            //        if (ship.model == null)
            //        {
            //            // We don't know this ship's model but can fill it from the info we have
            //            ship.model = profileShip.model;
            //            ship.Augment();
            //        }
            //        // Obtain items that we can't obtain from the journal
            //        ship.value = profileShip.value;
            //    }
            //}

            writeShips();
        }