Example #1
0
        public JObject CreateEDDNMessage(JournalDocked journal)
        {
            JObject msg = new JObject();

            msg["header"] = Header();
            msg["$schemaRef"] = "http://schemas.elite-markets.net/eddn/journal/1/test";

            JObject message = new JObject();

            message["StarSystem"] = journal.StarSystem;
            message["StationName"] = journal.StationName;
            message["StationType"] = journal.StationType;
            message["Faction"] = journal.Faction;
            message["Government"] = journal.Government;
            message["timestamp"] = journal.EventTimeUTC.ToString("yyyy-MM-ddTHH:mm:ssZ");
            message["Allegiance"] = journal.Allegiance;
            message["Security"] = journal.Security;
            message["event"] = journal.EventTypeStr;
            message["Economy"] = journal.Economy;

            msg["message"] = message;
            return msg;
        }
Example #2
0
        public static HistoryEntry FromJournalEntry(EliteDangerous.JournalEntry je, HistoryEntry prev, bool checkedsm, out bool journalupdate, SQLiteConnectionSystem conn = null)
        {
            ISystem isys    = prev == null ? new SystemClass("Unknown") : prev.System;
            int     indexno = prev == null ? 1 : prev.Indexno + 1;

            int mapcolour = 0;

            journalupdate = false;
            bool starposfromedsm = false;

            if (je.EventTypeID == EliteDangerous.JournalTypeEnum.Location || je.EventTypeID == EliteDangerous.JournalTypeEnum.FSDJump)
            {
                EDDiscovery.EliteDangerous.JournalEvents.JournalLocOrJump jl   = je as EDDiscovery.EliteDangerous.JournalEvents.JournalLocOrJump;
                EDDiscovery.EliteDangerous.JournalEvents.JournalFSDJump   jfsd = je as EDDiscovery.EliteDangerous.JournalEvents.JournalFSDJump;

                ISystem newsys;

                if (jl.HasCoordinate)       // LAZY LOAD IF it has a co-ord.. the front end will when it needs it
                {
                    newsys         = new SystemClass(jl.StarSystem, jl.StarPos.X, jl.StarPos.Y, jl.StarPos.Z);
                    newsys.id_edsm = jl.EdsmID < 0 ? 0 : jl.EdsmID;               // pass across the EDSMID for the lazy load process.

                    if (jfsd != null && jfsd.JumpDist <= 0 && isys.HasCoordinate) // if we don't have a jump distance (pre 2.2) but the last sys does, we can compute
                    {
                        jfsd.JumpDist = SystemClass.Distance(isys, newsys);       // fill it out here
                        journalupdate = true;
                    }
                }
                else
                {                           // Default one
                    newsys         = new SystemClass(jl.StarSystem);
                    newsys.id_edsm = jl.EdsmID;

                    if (checkedsm)                                          // see if we can find the right system
                    {
                        SystemClass s = SystemClass.FindEDSM(newsys, conn); // has no co-ord, did we find it?

                        if (s != null)                                      // yes, use, and update the journal with the esdmid, and also the position if we have a co-ord
                        {                                                   // so next time we don't have to do this again..
                            newsys = s;

                            if (jfsd != null && jfsd.JumpDist <= 0 && newsys.HasCoordinate && isys.HasCoordinate) // if we don't have a jump distance (pre 2.2) but the last sys does, we can compute
                            {
                                jfsd.JumpDist = SystemClass.Distance(isys, newsys);                               // fill it out here.  EDSM systems always have co-ords, but we should check anyway
                                journalupdate = true;
                            }

                            if (jl.EdsmID <= 0 && newsys.id_edsm > 0)
                            {
                                journalupdate = true;
                            }
                        }
                    }
                }

                if (jfsd != null)
                {
                    if (jfsd.JumpDist <= 0 && isys.HasCoordinate && newsys.HasCoordinate) // if no JDist, its a really old entry, and if previous has a co-ord
                    {
                        jfsd.JumpDist = SystemClass.Distance(isys, newsys);               // fill it out here
                        journalupdate = true;
                    }

                    mapcolour = jfsd.MapColor;
                }

                isys            = newsys;
                starposfromedsm = jl.HasCoordinate ? jl.StarPosFromEDSM : newsys.HasCoordinate;
            }

            string summary, info, detailed;

            je.FillInformation(out summary, out info, out detailed);

            HistoryEntry he = new HistoryEntry
            {
                Indexno           = indexno,
                EntryType         = je.EventTypeID,
                Journalid         = je.Id,
                journalEntry      = je,
                System            = isys,
                EventTimeUTC      = je.EventTimeUTC,
                MapColour         = mapcolour,
                EdsmSync          = je.SyncedEDSM,
                EDDNSync          = je.SyncedEDDN,
                StartMarker       = je.StartMarker,
                StopMarker        = je.StopMarker,
                EventSummary      = summary,
                EventDescription  = info,
                EventDetailedInfo = detailed,
                IsStarPosFromEDSM = starposfromedsm
            };

            if (prev != null && prev.travelling)      // if we are travelling..
            {
                he.travelled_distance    = prev.travelled_distance;
                he.travelled_missingjump = prev.travelled_missingjump;

                if (he.IsFSDJump)
                {
                    double dist = ((EliteDangerous.JournalEvents.JournalFSDJump)je).JumpDist;
                    if (dist <= 0)
                    {
                        he.travelled_missingjump++;
                    }
                    else
                    {
                        he.travelled_distance += dist;
                    }
                }

                he.travelled_seconds = prev.travelled_seconds;
                TimeSpan diff = he.EventTimeUTC.Subtract(prev.EventTimeUTC);

                if (he.EntryType != EliteDangerous.JournalTypeEnum.LoadGame && diff < new TimeSpan(2, 0, 0))   // time between last entry and load game is not real time
                {
                    he.travelled_seconds += diff;
                }

                if (he.StopMarker || he.StartMarker)
                {
                    he.travelling         = false;
                    he.EventDetailedInfo += ((he.EventDetailedInfo.Length > 0) ? Environment.NewLine : "") + "Travelled " + he.travelled_distance.ToString("0.0") +
                                            ((he.travelled_missingjump > 0) ? " LY(" + he.travelled_missingjump + " unknown distance jumps)" : " LY") +
                                            " time " + he.travelled_seconds;

                    he.travelled_distance = 0;
                    he.travelled_seconds  = new TimeSpan(0);
                }
                else
                {
                    he.travelling         = true;
                    he.EventDetailedInfo += ((he.EventDetailedInfo.Length > 0) ? Environment.NewLine : "") + "Travelling";

                    if (he.IsFSDJump)
                    {
                        he.EventDetailedInfo += " distance " + he.travelled_distance.ToString("0.0") + ((he.travelled_missingjump > 0) ? " LY (*)" : " LY");
                    }

                    he.EventDetailedInfo += " time " + he.travelled_seconds;
                }
            }

            if (he.StartMarker)
            {
                he.travelling = true;
            }

            // WORK out docked/landed state

            if (prev != null)
            {
                if (prev.docked.HasValue)                   // copy docked..
                {
                    he.docked = prev.docked;
                }
                if (prev.landed.HasValue)
                {
                    he.landed = prev.landed;
                }

                he.wheredocked = prev.wheredocked;
            }

            if (je.EventTypeID == JournalTypeEnum.Location)
            {
                EliteDangerous.JournalEvents.JournalLocation jl = je as EliteDangerous.JournalEvents.JournalLocation;
                he.docked      = jl.Docked;
                he.wheredocked = jl.Docked ? jl.StationName : "";
            }
            else if (je.EventTypeID == JournalTypeEnum.Docked)
            {
                EliteDangerous.JournalEvents.JournalDocked jl = je as EliteDangerous.JournalEvents.JournalDocked;
                he.docked      = true;
                he.wheredocked = jl.StationName;
            }
            else if (je.EventTypeID == JournalTypeEnum.Undocked)
            {
                he.docked = false;
            }
            else if (je.EventTypeID == JournalTypeEnum.Touchdown)
            {
                he.landed = true;
            }
            else if (je.EventTypeID == JournalTypeEnum.Liftoff)
            {
                he.landed = false;
            }
            else if (je.EventTypeID == JournalTypeEnum.LoadGame)
            {
                he.landed = (je as EliteDangerous.JournalEvents.JournalLoadGame).StartLanded;
            }

            return(he);
        }
Example #3
0
        public JObject CreateEDDNMessage(JournalDocked journal, double x, double y, double z)
        {
            JObject msg = new JObject();

            msg["header"] = Header();
            msg["$schemaRef"] = GetEDDNSchemaRef();

            JObject message = (JObject)JObject.Parse(journal.EventDataString);

            message = RemoveCommonKeys(message);
            message.Remove("CockpitBreach");

            message["StarPos"] = new JArray(new float[] { (float)x, (float)y, (float)z });

            msg["message"] = message;
            return msg;
        }