コード例 #1
0
        public void TestLoadoutParsing()
        {
            string data = System.IO.File.ReadAllText("loadout.json");

            List <Event> events = JournalMonitor.ParseJournalEntry(data);

            Assert.AreEqual(1, events.Count);
            ShipLoadoutEvent loadoutEvent = events[0] as ShipLoadoutEvent;

            Assert.AreEqual("Peppermint", loadoutEvent.shipname);
            Assert.AreEqual(18, loadoutEvent.compartments.Count);
            Assert.AreEqual(7, loadoutEvent.hardpoints.Count);

            ShipMonitor shipMonitor   = new ShipMonitor();
            var         privateObject = new PrivateObject(shipMonitor);

            object[] args = new object[] { loadoutEvent };
            Ship     ship = privateObject.Invoke("ParseShipLoadoutEvent", args) as Ship;

            Assert.AreEqual("Peppermint", ship.name);
            Assert.AreEqual("Int_FuelScoop_Size7_Class5", ship.compartments[0].module.edname);
            Assert.AreEqual("Fuel Scoop", ship.compartments[0].module.invariantName);
            Assert.AreEqual(16, ship.fueltankcapacity);
            Assert.AreEqual(24, ship.fueltanktotalcapacity);
        }
コード例 #2
0
        public void TestFighterLoadoutEvent()
        {
            var privateObject = new PrivateObject(new ShipMonitor());

            privateObject.SetFieldOrProperty("shipyard", new ObservableCollection <Ship>());

            string           data         = System.IO.File.ReadAllText("loadout.json");
            List <Event>     events       = JournalMonitor.ParseJournalEntry(data);
            ShipLoadoutEvent loadoutEvent = events[0] as ShipLoadoutEvent;

            object[] loadoutArgs = new object[] { loadoutEvent, false };
            privateObject.Invoke("handleShipLoadoutEvent", loadoutArgs);

            string data2 = System.IO.File.ReadAllText("fighterLoadout.json");

            events = JournalMonitor.ParseJournalEntry(data2);
            ShipLoadoutEvent fighterLoadoutEvent = events[0] as ShipLoadoutEvent;

            object[] fighterLoadoutArgs = new object[] { fighterLoadoutEvent, false };
            privateObject.Invoke("handleShipLoadoutEvent", fighterLoadoutArgs);

            // After a loadout event generated from a fighter,
            // we still want to track the ship we launched from as our current ship.
            Assert.AreEqual(loadoutEvent.shipid, EDDI.Instance.CurrentShip.LocalId);
            Assert.AreNotEqual(fighterLoadoutEvent.shipid, EDDI.Instance.CurrentShip.LocalId);
        }
コード例 #3
0
ファイル: ShipTests.cs プロジェクト: pekwalker/EDDI
        public void TestLoadoutParsing()
        {
            string data = System.IO.File.ReadAllText("loadout.json");

            List <Event> events = JournalMonitor.ParseJournalEntry(data);

            Assert.AreEqual(1, events.Count);
            ShipLoadoutEvent loadoutEvent = events[0] as ShipLoadoutEvent;

            Assert.AreEqual("Peppermint", loadoutEvent.shipname);
            Assert.AreEqual(18, loadoutEvent.compartments.Count);
            Assert.AreEqual(7, loadoutEvent.hardpoints.Count);

            ShipMonitor shipMonitor   = new ShipMonitor();
            var         privateObject = new PrivateObject(shipMonitor);

            object[] args = new object[] { loadoutEvent };
            Ship     ship = privateObject.Invoke("ParseShipLoadoutEvent", args) as Ship;

            Assert.AreEqual("Peppermint", ship.name);
        }
コード例 #4
0
        public void Handle(Event theEvent)
        {
            if (EDDI.Instance.inCQC)
            {
                // We don't do anything whilst in CQC
                return;
            }

            if (EDDI.Instance.inCrew)
            {
                // We don't do anything whilst in multicrew
                return;
            }

            if (EDDI.Instance.inBeta)
            {
                // We don't send data whilst in beta
                return;
            }

            if (starMapService != null)
            {
                if (theEvent is JumpedEvent)
                {
                    JumpedEvent jumpedEvent = (JumpedEvent)theEvent;

                    if (jumpedEvent.system != system)
                    {
                        Logging.Debug("Sending jump data to EDSM (jumped)");
                        starMapService.sendStarMapLog(jumpedEvent.timestamp, jumpedEvent.system, jumpedEvent.x, jumpedEvent.y, jumpedEvent.z);
                        system = jumpedEvent.system;
                    }
                }
                else if (theEvent is CommanderContinuedEvent)
                {
                    CommanderContinuedEvent continuedEvent = (CommanderContinuedEvent)theEvent;
                    starMapService.sendCredits(continuedEvent.credits, continuedEvent.loan);
                }
                else if (theEvent is MaterialInventoryEvent)
                {
                    MaterialInventoryEvent   materialInventoryEvent = (MaterialInventoryEvent)theEvent;
                    Dictionary <string, int> materials = new Dictionary <string, int>();
                    Dictionary <string, int> data      = new Dictionary <string, int>();
                    foreach (MaterialAmount ma in materialInventoryEvent.inventory)
                    {
                        Material material = Material.FromEDName(ma.edname);
                        if (material.category == "Element" || material.category == "Manufactured")
                        {
                            materials.Add(material.EDName, ma.amount);
                        }
                        else
                        {
                            data.Add(material.EDName, ma.amount);
                        }
                    }
                    starMapService.sendMaterials(materials);
                    starMapService.sendData(data);
                }
                else if (theEvent is ShipLoadoutEvent)
                {
                    ShipLoadoutEvent shipLoadoutEvent = (ShipLoadoutEvent)theEvent;
                    Ship             ship             = ((ShipMonitor)EDDI.Instance.ObtainMonitor("Ship monitor")).GetShip(shipLoadoutEvent.shipid);
                    starMapService.sendShip(ship);
                }
                else if (theEvent is ShipSwappedEvent)
                {
                    ShipSwappedEvent shipSwappedEvent = (ShipSwappedEvent)theEvent;
                    if (shipSwappedEvent.shipid.HasValue)
                    {
                        starMapService.sendShipSwapped((int)shipSwappedEvent.shipid);
                    }
                }
                else if (theEvent is ShipSoldEvent)
                {
                    ShipSoldEvent shipSoldEvent = (ShipSoldEvent)theEvent;
                    if (shipSoldEvent.shipid.HasValue)
                    {
                        starMapService.sendShipSold((int)shipSoldEvent.shipid);
                    }
                }
                else if (theEvent is ShipDeliveredEvent)
                {
                    ShipDeliveredEvent shipDeliveredEvent = (ShipDeliveredEvent)theEvent;
                    if (shipDeliveredEvent.shipid.HasValue)
                    {
                        starMapService.sendShipSwapped((int)shipDeliveredEvent.shipid);
                    }
                }
                else if (theEvent is CommanderProgressEvent)
                {
                    CommanderProgressEvent progressEvent = (CommanderProgressEvent)theEvent;
                    if (EDDI.Instance.Cmdr != null && EDDI.Instance.Cmdr.federationrating != null)
                    {
                        starMapService.sendRanks(EDDI.Instance.Cmdr.combatrating.rank, (int)progressEvent.combat,
                                                 EDDI.Instance.Cmdr.traderating.rank, (int)progressEvent.trade,
                                                 EDDI.Instance.Cmdr.explorationrating.rank, (int)progressEvent.exploration,
                                                 EDDI.Instance.Cmdr.cqcrating.rank, (int)progressEvent.cqc,
                                                 EDDI.Instance.Cmdr.federationrating.rank, (int)progressEvent.federation,
                                                 EDDI.Instance.Cmdr.empirerating.rank, (int)progressEvent.empire);
                    }
                }
            }
        }
コード例 #5
0
ファイル: EDSMResponder.cs プロジェクト: pekwalker/EDDI
        private string prepareEventData(Event theEvent)
        {
            // Prep transient game state info (metadata) per https://www.edsm.net/en/api-journal-v1.
            // Unpackage the event, add transient game state info as applicable, then repackage and send the event
            IDictionary <string, object> eventObject = Deserializtion.DeserializeData(theEvent.raw);
            string eventType = JsonParsing.getString(eventObject, "event");

            if (ignoredEvents.Contains(eventType) || theEvent.raw == null)
            {
                return(null);
            }

            // Add metadata from events
            switch (eventType)
            {
            case "LoadGame":
            {
                eventObject.Add("_systemAddress", null);
                eventObject.Add("_systemName", null);
                eventObject.Add("_systemCoordinates", null);
                eventObject.Add("_marketId", null);
                eventObject.Add("_stationName", null);
                break;
            }

            case "SetUserShipName":
            {
                ShipRenamedEvent shipRenamedEvent = (ShipRenamedEvent)theEvent;
                eventObject.Add("_shipId", shipRenamedEvent.shipid);
                break;
            }

            case "ShipyardBuy":
            {
                eventObject.Add("_shipId", null);
                break;
            }

            case "ShipyardSwap":
            {
                ShipSwappedEvent shipSwappedEvent = (ShipSwappedEvent)theEvent;
                eventObject.Add("_shipId", shipSwappedEvent.shipid);
                break;
            }

            case "Loadout":
            {
                ShipLoadoutEvent shipLoadoutEvent = (ShipLoadoutEvent)theEvent;
                eventObject.Add("_shipId", shipLoadoutEvent.shipid);
                break;
            }

            case "Undocked":
            {
                eventObject.Add("_marketId", null);
                eventObject.Add("_stationName", null);
                break;
            }

            case "Location":
            {
                LocationEvent locationEvent = (LocationEvent)theEvent;
                eventObject.Add("_systemAddress", null);         // We don't collect this info yet
                eventObject.Add("_systemName", locationEvent.system);
                List <decimal?> _systemCoordinates = new List <decimal?>
                {
                    locationEvent.x,
                    locationEvent.y,
                    locationEvent.z
                };
                eventObject.Add("_systemCoordinates", _systemCoordinates);
                eventObject.Add("_marketId", null);         // We don't collect this info yet
                eventObject.Add("_stationName", locationEvent.station);
                break;
            }

            case "FSDJump":
            {
                JumpedEvent jumpedEvent = (JumpedEvent)theEvent;
                eventObject.Add("_systemAddress", null);         // We don't collect this info yet
                eventObject.Add("_systemName", jumpedEvent.system);
                List <decimal?> _systemCoordinates = new List <decimal?>
                {
                    jumpedEvent.x,
                    jumpedEvent.y,
                    jumpedEvent.z
                };
                eventObject.Add("_systemCoordinates", _systemCoordinates);
                break;
            }

            case "Docked":
            {
                DockedEvent dockedEvent = (DockedEvent)theEvent;
                eventObject.Add("_systemAddress", null);         // We don't collect this info yet
                eventObject.Add("_systemName", dockedEvent.system);
                eventObject.Add("_systemCoordinates", null);
                eventObject.Add("_marketId", null);         // We don't collect this info yet
                eventObject.Add("_stationName", dockedEvent.station);
                break;
            }
            }

            // Supplement with metadata from the tracked game state, as applicable
            if (EDDI.Instance.CurrentStarSystem != null)
            {
                if (!eventObject.ContainsKey("_systemAddress") && !eventObject.ContainsKey("SystemAddress"))
                {
                    eventObject.Add("_systemAddress", null); // We don't collect this info yet
                }
                if (!eventObject.ContainsKey("_systemName") && !eventObject.ContainsKey("SystemName"))
                {
                    eventObject.Add("_systemName", EDDI.Instance.CurrentStarSystem.name);
                }
                if (!eventObject.ContainsKey("_systemCoordinates") && !eventObject.ContainsKey("StarPos"))
                {
                    List <decimal?> _coordinates = new List <decimal?>
                    {
                        EDDI.Instance.CurrentStarSystem.x,
                        EDDI.Instance.CurrentStarSystem.y,
                        EDDI.Instance.CurrentStarSystem.z
                    };
                    eventObject.Add("_systemCoordinates", _coordinates);
                }
            }
            if (EDDI.Instance.CurrentStation != null)
            {
                if (!eventObject.ContainsKey("_marketId") && !eventObject.ContainsKey("MarketID"))
                {
                    eventObject.Add("_marketId", null); // We don't collect this info yet
                }
                if (!eventObject.ContainsKey("_stationName") && !eventObject.ContainsKey("StationName"))
                {
                    eventObject.Add("_stationName", EDDI.Instance.CurrentStation.name);
                }
            }
            if (EDDI.Instance.CurrentShip != null && !eventObject.ContainsKey("ShipId") && !eventObject.ContainsKey("_shipId"))
            {
                eventObject.Add("_shipId", EDDI.Instance.CurrentShip.LocalId);
            }

            return(JsonConvert.SerializeObject(eventObject).Normalize());
        }