From 4486befa131405f554b859dde57e8187cd590cb0 Mon Sep 17 00:00:00 2001 From: Marcel Houweling Date: Thu, 20 May 2021 13:16:14 +0200 Subject: [PATCH] improved support for odyssey improved credit calculation --- .../EDEngineer/Resources/Data/entryData.json | 3 +- Elite/App.xaml.cs | 12 + Elite/Data.cs | 379 ++++++++++++------ Elite/Elite.csproj | 2 +- Elite/Material.cs | 69 +++- Elite/Properties/AssemblyInfo.cs | 4 +- Elite/Templates/engineers.cshtml | 25 +- Elite/packages.config | 2 +- EliteJournalReader/BackpackWatcher.cs | 242 +++++++++++ EliteJournalReader/EliteJournalReader.csproj | 7 +- .../Events/BackPackChangeEvent.cs | 32 ++ ...PackMaterialsEvent.cs => BackPackEvent.cs} | 18 +- EliteJournalReader/Events/LiftoffEvent.cs | 10 +- EliteJournalReader/Events/LoadGameEvent.cs | 1 + .../Events/LoadoutEquipModuleEvent.cs | 1 + .../Events/LoadoutRemoveModuleEvent.cs | 1 + EliteJournalReader/Events/StatusFileEvent.cs | 7 +- EliteJournalReader/Events/SuitLoadoutEvent.cs | 33 ++ EliteJournalReader/Events/TouchdownEvent.cs | 10 +- ImportData/Program.cs | 4 +- ImportData/Properties/AssemblyInfo.cs | 4 +- 21 files changed, 691 insertions(+), 175 deletions(-) create mode 100644 EliteJournalReader/BackpackWatcher.cs create mode 100644 EliteJournalReader/Events/BackPackChangeEvent.cs rename EliteJournalReader/Events/{BackPackMaterialsEvent.cs => BackPackEvent.cs} (74%) create mode 100644 EliteJournalReader/Events/SuitLoadoutEvent.cs diff --git a/EDEngineer/EDEngineer/Resources/Data/entryData.json b/EDEngineer/EDEngineer/Resources/Data/entryData.json index 5037103..8d2c4eb 100644 --- a/EDEngineer/EDEngineer/Resources/Data/entryData.json +++ b/EDEngineer/EDEngineer/Resources/Data/entryData.json @@ -1187,8 +1187,7 @@ "OriginDetails": [ "Surface prospecting" ], - "Group": "Category3", - "MaximumCapacity": 100 + "Group": "Category3" }, { "Name": "Salvaged Alloys", diff --git a/Elite/App.xaml.cs b/Elite/App.xaml.cs index 964cb5d..22f19e1 100644 --- a/Elite/App.xaml.cs +++ b/Elite/App.xaml.cs @@ -51,6 +51,7 @@ public partial class App : Application public static JournalWatcher journalWatcher; public static CargoWatcher cargoWatcher; public static NavRouteWatcher navRouteWatcher; + public static BackPackWatcher backPackWatcher; private static StatusWatcher _statusWatcher; @@ -578,6 +579,13 @@ protected override void OnStartup(StartupEventArgs evtArgs) navRouteWatcher.StartWatching(); + splashScreen.Dispatcher.Invoke(() => splashScreen.ProgressText.Text = "Starting Elite BackPack Watcher..."); + backPackWatcher = new BackPackWatcher(path); + + backPackWatcher.BackPackUpdated += Data.HandleBackPackEvent; + + backPackWatcher.StartWatching(); + splashScreen.Dispatcher.Invoke(() => splashScreen.ProgressText.Text = "Initializing FIP..."); if (!FipHandler.Initialize()) { @@ -692,6 +700,10 @@ protected override void OnExit(ExitEventArgs e) navRouteWatcher.StopWatching(); + backPackWatcher.BackPackUpdated -= Data.HandleBackPackEvent; + + backPackWatcher.StopWatching(); + FipHandler.Close(); _notifyIcon.Dispose(); //the icon would clean up automatically, but this is cleaner diff --git a/Elite/Data.cs b/Elite/Data.cs index 645a682..bd669f0 100644 --- a/Elite/Data.cs +++ b/Elite/Data.cs @@ -427,8 +427,11 @@ public class Status public bool Hot { get; set; } public bool VeryCold { get; set; } public bool VeryHot { get; set; } - - + public bool GlideMode { get; set; } + public bool OnFootInHangar { get; set; } + public bool OnFootSocialSpace { get; set; } + public bool OnFootExterior { get; set; } + public bool BreathableAtmosphere { get; set; } } @@ -511,6 +514,12 @@ public static void HandleStatusEvents(object sender, StatusFileEvent evt) StatusData.VeryCold = (evt.Flags2 & StatusFlags2.VeryCold) != 0; StatusData.VeryHot = (evt.Flags2 & StatusFlags2.VeryHot) != 0; + StatusData.GlideMode = (evt.Flags2 & StatusFlags2.GlideMode) != 0; + StatusData.OnFootInHangar = (evt.Flags2 & StatusFlags2.OnFootInHangar) != 0; + StatusData.OnFootSocialSpace = (evt.Flags2 & StatusFlags2.OnFootSocialSpace) != 0; + StatusData.OnFootExterior = (evt.Flags2 & StatusFlags2.OnFootExterior) != 0; + StatusData.BreathableAtmosphere = (evt.Flags2 & StatusFlags2.BreathableAtmosphere) != 0; + var shipData = Ships.GetCurrentShip(); if (shipData != null) { @@ -553,6 +562,13 @@ private static string UpdateReputationState(double reputation) return ""; } + public static void HandleBackPackEvent(object sender, BackPackEvent.BackPackEventArgs e) + { + if (e?.Components == null) return; + + Material.HandleBackPackEvent(e); + } + public static void HandleNavRouteEvent(object sender, NavRouteEvent.NavRouteEventArgs e) { if (e?.Route == null) return; @@ -800,33 +816,146 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) break; - case "ModuleRetrieve": - //When Written: when fetching a previously stored module - var moduleRetrieveInfo = (ModuleRetrieveEvent.ModuleRetrieveEventArgs)e; + case "RefuelAll": + //When Written: when refuelling (full tank) + var refuelAllInfo = (RefuelAllEvent.RefuelAllEventArgs) e; - Module.HandleModuleRetrieve(moduleRetrieveInfo); + CommanderData.Credits -= refuelAllInfo.Cost; + break; + + case "RefuelPartial": + //When Written: when refuelling (10%) + var RefuelPartialInfo = (RefuelPartialEvent.RefuelPartialEventArgs)e; + CommanderData.Credits -= RefuelPartialInfo.Cost; break; - case "ModuleBuy": - //When Written: when buying a module in outfitting - var moduleBuyInfo = (ModuleBuyEvent.ModuleBuyEventArgs) e; + case "RestockVehicle": + //When Written: when purchasing an SRV or Fighter + var restockVehicleInfo = (RestockVehicleEvent.RestockVehicleEventArgs)e; - Module.HandleModuleBuy(moduleBuyInfo); + CommanderData.Credits -= restockVehicleInfo.Cost; + break; + + case "Resurrect": + //When Written: when purchasing an SRV or Fighter + var ResurrectInfo = (ResurrectEvent.ResurrectEventArgs)e; + CommanderData.Credits -= ResurrectInfo.Cost; break; - case "ModuleSwap": - //When Written: when moving a module to a different slot on the ship - var moduleSwapInfo = (ModuleSwapEvent.ModuleSwapEventArgs)e; + case "RepairAll": + //When Written: when repairing the ship + var repairAllInfo = (RepairAllEvent.RepairAllEventArgs) e; - Module.HandleModuleSwap(moduleSwapInfo); + CommanderData.Credits -= repairAllInfo.Cost; + break; + + case "Repair": + //When Written: when repairing the ship + var repairInfo = (RepairEvent.RepairEventArgs) e; + + CommanderData.Credits -= repairInfo.Cost; + break; + + case "BuyTradeData": + //When Written: when buying trade data in the galaxy map + var buyTradeDataInfo = (BuyTradeDataEvent.BuyTradeDataEventArgs) e; + + CommanderData.Credits -= buyTradeDataInfo.Cost; + break; + + case "BuyExplorationData": + //When Written: when buying system data via the galaxy map + var buyExplorationDataInfo = (BuyExplorationDataEvent.BuyExplorationDataEventArgs) e; + + CommanderData.Credits -= buyExplorationDataInfo.Cost; + break; + + case "BuyDrones": + //When Written: when purchasing drones + var buyDronesInfo = (BuyDronesEvent.BuyDronesEventArgs) e; + + CommanderData.Credits -= buyDronesInfo.TotalCost; + break; + + case "BuyAmmo": + //When Written: when purchasing ammunition + var buyAmmoInfo = (BuyAmmoEvent.BuyAmmoEventArgs) e; + + CommanderData.Credits -= buyAmmoInfo.Cost; + break; + + case "PayBounties": + //When written: when paying off bounties + var payBountiesInfo = (PayBountiesEvent.PayBountiesEventArgs)e; + + // shipID + + CommanderData.Credits -= payBountiesInfo.Amount; + break; + + case "RedeemVoucher": + var redeemVoucherInfo = (RedeemVoucherEvent.RedeemVoucherEventArgs)e; + + CommanderData.Credits += redeemVoucherInfo.Amount; + + break; + + case "MarketSell": + //When Written: when selling goods in the market + + var marketSellInfo = (MarketSellEvent.MarketSellEventArgs)e; + + CommanderData.Credits += marketSellInfo.TotalSale; + + Cargo.HandleMarketSellEvent(marketSellInfo); + + break; + + case "MarketBuy": + + var marketBuyInfo = (MarketBuyEvent.MarketBuyEventArgs)e; + + CommanderData.Credits -= marketBuyInfo.TotalCost; + + Cargo.HandleMarketBuyEvent(marketBuyInfo); + + break; + + case "SellDrones": + //When Written: when selling unwanted drones back to the market + + var sellDronesInfo = (SellDronesEvent.SellDronesEventArgs)e; + + CommanderData.Credits += sellDronesInfo.TotalSale; + + break; + + case "PayFines": + //When Written: when paying fines + var payFinesInfo = (PayFinesEvent.PayFinesEventArgs)e; + + // shipID + + CommanderData.Credits -= payFinesInfo.Amount; + break; + + case "ModuleBuy": + //When Written: when buying a module in outfitting + var moduleBuyInfo = (ModuleBuyEvent.ModuleBuyEventArgs)e; + + CommanderData.Credits -= moduleBuyInfo.BuyPrice + (moduleBuyInfo.SellPrice ?? 0); + + Module.HandleModuleBuy(moduleBuyInfo); break; case "ModuleSell": //When Written: when selling a module in outfitting - var moduleSellInfo = (ModuleSellEvent.ModuleSellEventArgs) e; + var moduleSellInfo = (ModuleSellEvent.ModuleSellEventArgs)e; + + CommanderData.Credits += moduleSellInfo.SellPrice; Module.HandleModuleSell(moduleSellInfo); @@ -836,18 +965,40 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) //When Written: when selling a module in outfitting var moduleSellRemoteInfo = (ModuleSellRemoteEvent.ModuleSellRemoteEventArgs)e; + CommanderData.Credits += moduleSellRemoteInfo.SellPrice; + Module.HandleModuleSellRemote(moduleSellRemoteInfo); - + + break; + + case "ModuleRetrieve": + //When Written: when fetching a previously stored module + var moduleRetrieveInfo = (ModuleRetrieveEvent.ModuleRetrieveEventArgs)e; + + //CommanderData.Credits -= moduleRetrieveInfo.Cost; ??????????????? + + Module.HandleModuleRetrieve(moduleRetrieveInfo); + break; case "ModuleStore": //When Written: when fetching a previously stored module - var moduleStoreInfo = (ModuleStoreEvent.ModuleStoreEventArgs) e; + var moduleStoreInfo = (ModuleStoreEvent.ModuleStoreEventArgs)e; + + //CommanderData.Credits -= moduleStoreInfo.Cost; ??????????????? Module.HandleModuleStore(moduleStoreInfo); break; + case "ModuleSwap": + //When Written: when moving a module to a different slot on the ship + var moduleSwapInfo = (ModuleSwapEvent.ModuleSwapEventArgs)e; + + Module.HandleModuleSwap(moduleSwapInfo); + + break; + case "MassModuleStore": //When written: when putting multiple modules into storage var massModuleStoreInfo = (MassModuleStoreEvent.MassModuleStoreEventArgs)e; @@ -861,10 +1012,21 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) var fetchRemoteModuleInfo = (FetchRemoteModuleEvent.FetchRemoteModuleEventArgs)e; + CommanderData.Credits -= fetchRemoteModuleInfo.TransferCost; + Module.HandleFetchRemoteModule(fetchRemoteModuleInfo); break; + case "PowerplayFastTrack": + //When written: when paying to fast-track allocation of commodities + + var powerplayFastTrackInfo = (PowerplayFastTrackEvent.PowerplayFastTrackEventArgs)e; + + CommanderData.Credits -= powerplayFastTrackInfo.Cost; + + break; + case "StoredModules": // When written: when first visiting Outfitting, and when the set of stored modules has changed @@ -874,73 +1036,85 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) break; - case "RefuelAll": - //When Written: when refuelling (full tank) - var refuelAllInfo = (RefuelAllEvent.RefuelAllEventArgs) e; + case "SellShipOnRebuy": + //When written: When selling a stored ship to raise funds when on insurance/rebuy screen + var SellShipOnRebuyInfo = (SellShipOnRebuyEvent.SellShipOnRebuyEventArgs)e; + + CommanderData.Credits += SellShipOnRebuyInfo.ShipPrice; - CommanderData.Credits -= refuelAllInfo.Cost; break; - case "RepairAll": - //When Written: when repairing the ship - var repairAllInfo = (RepairAllEvent.RepairAllEventArgs) e; + case "ShipyardBuy": + //When Written: when buying a new ship in the shipyard + //Note: the new ship’s ShipID will be logged in a separate event after the purchase - CommanderData.Credits -= repairAllInfo.Cost; - break; + var shipyardBuyInfo = (ShipyardBuyEvent.ShipyardBuyEventArgs)e; - case "Repair": - //When Written: when repairing the ship - var repairInfo = (RepairEvent.RepairEventArgs) e; + CommanderData.Credits -= shipyardBuyInfo.ShipPrice + (shipyardBuyInfo.SellPrice ?? 0); + + Ships.HandleShipyardBuy(shipyardBuyInfo); - CommanderData.Credits -= repairInfo.Cost; break; - case "BuyTradeData": - //When Written: when buying trade data in the galaxy map - var buyTradeDataInfo = (BuyTradeDataEvent.BuyTradeDataEventArgs) e; + case "ShipyardSell": + //When Written: when selling a ship stored in the shipyard + + var shipyardSellInfo = (ShipyardSellEvent.ShipyardSellEventArgs)e; + + CommanderData.Credits += shipyardSellInfo.ShipPrice; + + Ships.HandleShipyardSell(shipyardSellInfo); - CommanderData.Credits -= buyTradeDataInfo.Cost; break; - case "BuyExplorationData": - //When Written: when buying system data via the galaxy map - var buyExplorationDataInfo = (BuyExplorationDataEvent.BuyExplorationDataEventArgs) e; + case "ShipyardSwap": + //When Written: when switching to another ship already stored at this station + var shipyardSwapInfo = (ShipyardSwapEvent.ShipyardSwapEventArgs)e; + + CommanderData.Credits += shipyardSwapInfo.SellPrice ?? 0; + + Ships.HandleShipyardSwap(shipyardSwapInfo); - CommanderData.Credits -= buyExplorationDataInfo.Cost; break; - case "BuyDrones": - //When Written: when purchasing drones - var buyDronesInfo = (BuyDronesEvent.BuyDronesEventArgs) e; + case "ShipyardTransfer": + //When Written: when requesting a ship at another station be transported to this station + + var shipyardTransferInfo = (ShipyardTransferEvent.ShipyardTransferEventArgs)e; + + CommanderData.Credits -= shipyardTransferInfo.TransferPrice; + + //ShipID - CommanderData.Credits -= buyDronesInfo.TotalCost; break; - case "BuyAmmo": - //When Written: when purchasing ammunition - var buyAmmoInfo = (BuyAmmoEvent.BuyAmmoEventArgs) e; + case "ShipyardNew": + //When written: after a new ship has been purchased + var shipyardNewInfo = (ShipyardNewEvent.ShipyardNewEventArgs)e; + + Ships.HandleShipyardNew(shipyardNewInfo); - CommanderData.Credits -= buyAmmoInfo.Cost; break; - case "PayBounties": - //When written: when paying off bounties - var payBountiesInfo = (PayBountiesEvent.PayBountiesEventArgs)e; + case "StoredShips": + // When written: when visiting shipyard + var storedShipsInfo = (StoredShipsEvent.StoredShipsEventArgs)e; - // shipID + //ShipID + + Ships.HandleStoredShips(storedShipsInfo); - CommanderData.Credits -= payBountiesInfo.Amount; break; - case "PayFines": - //When Written: when paying fines - var payFinesInfo = (PayFinesEvent.PayFinesEventArgs)e; + case "CrewHire": + //When Written: when engaging a new member of crew + var crewHireInfo = (CrewHireEvent.CrewHireEventArgs)e; - // shipID + CommanderData.Credits -= crewHireInfo.Cost; - CommanderData.Credits -= payFinesInfo.Amount; break; + case "ApproachBody": // When written: when in Supercruise, and distance from planet drops to within the 'Orbital Cruise' zone var approachBodyInfo = (ApproachBodyEvent.ApproachBodyEventArgs) e; @@ -1081,6 +1255,14 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) break; + case "CarrierBuy": + //When Written: Player has bought a fleet carrier + var CarrierBuyInfo = (CarrierBuyEvent.CarrierBuyEventArgs)e; + + CommanderData.Credits -= CarrierBuyInfo.Price; + + break; + case "CarrierJump": //When written: when jumping from one star system to another when docked on a a carrier var carrierJumpInfo = (CarrierJumpEvent.CarrierJumpEventArgs)e; @@ -1515,13 +1697,6 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) break; - case "MarketBuy": - - var marketBuyInfo = (MarketBuyEvent.MarketBuyEventArgs)e; - - Cargo.HandleMarketBuyEvent(marketBuyInfo); - - break; case "MiningRefined": @@ -1531,14 +1706,6 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) break; - case "MarketSell": - - var marketSellInfo = (MarketSellEvent.MarketSellEventArgs)e; - - Cargo.HandleMarketSellEvent(marketSellInfo); - - break; - case "CargoDepot": var cargoDepotInfo = (CargoDepotEvent.CargoDepotEventArgs)e; @@ -1555,58 +1722,6 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) break; - case "ShipyardBuy": - //When Written: when buying a new ship in the shipyard - //Note: the new ship’s ShipID will be logged in a separate event after the purchase - - var shipyardBuyInfo = (ShipyardBuyEvent.ShipyardBuyEventArgs)e; - - Ships.HandleShipyardBuy(shipyardBuyInfo); - - break; - - case "ShipyardSell": - //When Written: when selling a ship stored in the shipyard - - var shipyardSellInfo = (ShipyardSellEvent.ShipyardSellEventArgs)e; - - Ships.HandleShipyardSell(shipyardSellInfo); - - break; - - case "ShipyardNew": - //When written: after a new ship has been purchased - var shipyardNewInfo = (ShipyardNewEvent.ShipyardNewEventArgs)e; - - Ships.HandleShipyardNew(shipyardNewInfo); - - break; - - case "ShipyardSwap": - //When Written: when switching to another ship already stored at this station - var shipyardSwapInfo = (ShipyardSwapEvent.ShipyardSwapEventArgs)e; - - Ships.HandleShipyardSwap(shipyardSwapInfo); - - break; - - case "ShipyardTransfer": - //When Written: when requesting a ship at another station be transported to this station - //var shipyardTransferInfo = (ShipyardTransferEvent.ShipyardTransferEventArgs)e; - - //ShipID - - break; - - case "StoredShips": - // When written: when visiting shipyard - var storedShipsInfo = (StoredShipsEvent.StoredShipsEventArgs)e; - - //ShipID - - Ships.HandleStoredShips(storedShipsInfo); - - break; case "Promotion": var promotionInfo = (PromotionEvent.PromotionEventArgs)e; @@ -1656,7 +1771,7 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) case "SellSuit": var sellSuitInfo = (SellSuitEvent.SellSuitEventArgs)e; - CommanderData.Credits -= sellSuitInfo.Price; + CommanderData.Credits += sellSuitInfo.Price; break; case "UpgradeSuit": @@ -1674,6 +1789,12 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) var switchSuitLoadoutInfo = (SwitchSuitLoadoutEvent.SwitchSuitLoadoutEventArgs)e; break; + + case "SuitLoadout": + var suitLoadoutInfo = (SuitLoadoutEvent.SuitLoadoutEventArgs)e; + + break; + case "CreateSuitLoadout": var createSuitLoadoutInfo = (CreateSuitLoadoutEvent.CreateSuitLoadoutEventArgs)e; @@ -1692,7 +1813,7 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) case "SellWeapon": var sellWeaponInfo = (SellWeaponEvent.SellWeaponEventArgs)e; - CommanderData.Credits -= sellWeaponInfo.Price; + CommanderData.Credits += sellWeaponInfo.Price; break; case "UpgradeWeapon": @@ -1702,12 +1823,13 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) break; - case "BackPackMaterials": - var backPackMaterialsInfo = (BackPackMaterialsEvent.BackPackMaterialsEventArgs)e; + case "BackPackChange": + var backPackChangeInfo = (BackPackChangeEvent.BackPackChangeEventArgs)e; - Material.HandleBackPackMaterialsEvent(backPackMaterialsInfo); + Material.HandleBackPackChangeEvent(backPackChangeInfo); break; + case "ShipLockerMaterials": var shipLockerMaterialsInfo = (ShipLockerMaterialsEvent.ShipLockerMaterialsEventArgs)e; @@ -1830,6 +1952,7 @@ public static void HandleEliteEvents(object sender, JournalEventArgs e) break; + case "Music": var musicInfo = (MusicEvent.MusicEventArgs)e; diff --git a/Elite/Elite.csproj b/Elite/Elite.csproj index 80e5e70..6b199c4 100644 --- a/Elite/Elite.csproj +++ b/Elite/Elite.csproj @@ -57,7 +57,7 @@ ..\packages\Costura.Fody.4.1.0\lib\net40\Costura.dll - ..\packages\CsvHelper.27.0.2\lib\net47\CsvHelper.dll + ..\packages\CsvHelper.27.0.4\lib\net47\CsvHelper.dll ..\packages\Hardcodet.NotifyIcon.Wpf.1.1.0\lib\net472\Hardcodet.NotifyIcon.Wpf.dll diff --git a/Elite/Material.cs b/Elite/Material.cs index d155932..f1ebbd2 100644 --- a/Elite/Material.cs +++ b/Elite/Material.cs @@ -245,7 +245,7 @@ public static void HandleMissionCompletedEvent(MissionCompletedEvent.MissionComp } } - public static void HandleBackPackMaterialsEvent(BackPackMaterialsEvent.BackPackMaterialsEventArgs info) + public static void HandleBackPackEvent(BackPackEvent.BackPackEventArgs info) { BackPackList = new Dictionary(); @@ -290,7 +290,46 @@ public static void HandleBackPackMaterialsEvent(BackPackMaterialsEvent.BackPackM } } + public static void HandleBackPackChangeEvent(BackPackChangeEvent.BackPackChangeEventArgs info) + { + if (info.Added?.Any() == true) + { + foreach (var e in info.Added) + { + var name = (e.Name_Localised ?? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(e.Name.ToLower())).Trim(); + + if (BackPackList.ContainsKey(e.Name)) + { + BackPackList[e.Name].Count += e.Count; + } + else + { + BackPackList.Add(e.Name, new MaterialItem { Category = e.Type, Name = name, Count = e.Count }); + } + + } + } + if (info.Removed?.Any() == true) + { + foreach (var e in info.Removed) + { + var name = (e.Name_Localised ?? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(e.Name.ToLower())).Trim(); + + if (BackPackList.ContainsKey(e.Name)) + { + BackPackList[e.Name].Count -= e.Count; + + if (BackPackList[e.Name].Count == 0) + { + BackPackList.Remove(e.Name); + } + } + } + } + + } + public static void HandleShipLockerMaterialsEvent(ShipLockerMaterialsEvent.ShipLockerMaterialsEventArgs info) { ShipLockerList = new Dictionary(); @@ -370,6 +409,30 @@ public static void HandleSellMicroResourcesEvent(SellMicroResourcesEvent.SellMic } } + public static void HandleTradeMicroResourcesEvent(TradeMicroResourcesEvent.TradeMicroResourcesEventArgs info) + { + foreach (var e in info.Offered) + { + if (ShipLockerList.ContainsKey(e.Name)) + { + ShipLockerList[e.Name].Count -= e.Count; + + if (ShipLockerList[e.Name].Count == 0) + { + ShipLockerList.Remove(e.Name); + } + } + } + + //????????????????var name = (info.Name_Localised ?? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(info.Received.ToLower())).Trim(); + + ShipLockerList.Add(info.Received, new MaterialItem { Category = info.Category, Name = info.Received, Count = info.Count }); + + //??????????????? + + } + + // "Transfers":[ { "Name":"healthpack", "Name_Localised":"Medkit", "Category":"Consumable", "Count":1, "Direction":"ToShipLocker" }, { "Name":"energycell", "Name_Localised":"Energy Cell", "Category":"Consumable", "Count":1, "Direction":"ToShipLocker" } ] } public static void HandleTransferMicroResourcesEvent(TransferMicroResourcesEvent.TransferMicroResourcesEventArgs info) { @@ -475,10 +538,6 @@ public static void HandleUseConsumableEvent(UseConsumableEvent.UseConsumableEven } - public static void HandleTradeMicroResourcesEvent(TradeMicroResourcesEvent.TradeMicroResourcesEventArgs info) - { - //???????????????????????????????? - } } diff --git a/Elite/Properties/AssemblyInfo.cs b/Elite/Properties/AssemblyInfo.cs index 42f8d36..bb08611 100644 --- a/Elite/Properties/AssemblyInfo.cs +++ b/Elite/Properties/AssemblyInfo.cs @@ -31,7 +31,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.7.2.0")] -[assembly: AssemblyFileVersion("1.7.2.0")] +[assembly: AssemblyVersion("1.7.3.0")] +[assembly: AssemblyFileVersion("1.7.3.0")] [assembly: log4net.Config.XmlConfigurator(Watch = true)] \ No newline at end of file diff --git a/Elite/Templates/engineers.cshtml b/Elite/Templates/engineers.cshtml index 21d9a69..d11bbf9 100644 --- a/Elite/Templates/engineers.cshtml +++ b/Elite/Templates/engineers.cshtml @@ -105,17 +105,20 @@ - - - @foreach (var m in Model.Blueprints) - { - - - - - } - -
   @m.GradeString@m.Type
+ if (Model.Blueprints != null) + { + + + @foreach (var m in Model.Blueprints) + { + + + + + } + +
   @m.GradeString@m.Type
+ } } diff --git a/Elite/packages.config b/Elite/packages.config index 0c2098e..05823a0 100644 --- a/Elite/packages.config +++ b/Elite/packages.config @@ -1,7 +1,7 @@  - + diff --git a/EliteJournalReader/BackpackWatcher.cs b/EliteJournalReader/BackpackWatcher.cs new file mode 100644 index 0000000..bae7d68 --- /dev/null +++ b/EliteJournalReader/BackpackWatcher.cs @@ -0,0 +1,242 @@ +using EliteJournalReader.Events; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace EliteJournalReader +{ + + // copied from https://github.com/MagicMau/EliteJournalReader + + public class BackPackWatcher : FileSystemWatcher + { + public event EventHandler BackPackUpdated; + + /// + /// The default filter + /// + private const string DefaultFilter = @"Backpack.json"; + + /// + /// Token to signal that we are no longer watching + /// + private CancellationTokenSource _cancellationTokenSource; + + public BackPackWatcher(string path) + { + Initialize(path); + } + + private void Initialize(string path) + { + Filter = DefaultFilter; + NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.LastWrite; + + try + { + Path = System.IO.Path.GetFullPath(path); + } + catch (Exception ex) + { + Trace.TraceError("Exception in setting path: " + ex.Message); + } + } + + // copied from https://github.com/EDCD/EDDI + + private static bool IsFileLocked(FileInfo file) + { + FileStream stream = null; + + try + { + stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None); + } + catch (IOException) + { + //the file is unavailable because it is: + //still being written to + //or being processed by another thread + //or does not exist (has already been processed) + return true; + } + finally + { + stream?.Close(); + } + + //file is not locked + return false; + } + + private static FileInfo FileInfo(string backPackPath) + { + try + { + var info = new FileInfo(backPackPath); + if (info.Exists) + { + // This info can be cached so force a refresh + info.Refresh(); + } + return info; + } + catch { return null; } + } + + public BackPackEvent.BackPackEventArgs ReadBackPackJson() + { + try + { + Thread.Sleep(100); + + var backPackPath = System.IO.Path.Combine(Path, "Backpack.json"); + + FileInfo fileInfo = null; + try + { + fileInfo = FileInfo(backPackPath); + } + catch (NotSupportedException) + { + // do nothing + } + + if (fileInfo != null) + { + var maxTries = 6; + while (IsFileLocked(fileInfo)) + { + Thread.Sleep(100); + maxTries--; + if (maxTries == 0) + { + return null; + } + } + + using (var fs = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + using (var reader = new StreamReader(fs, Encoding.UTF8)) + { + fs.Seek(0, SeekOrigin.Begin); + var json = reader.ReadToEnd(); + + if (string.IsNullOrEmpty(json)) + { + return null; + } + var obj = JObject.Parse(json); + var backPack = obj.ToObject(); + return backPack; + + } + } + } + catch (Exception e) + { + Trace.TraceWarning($"Error reading Backpack.json journal file: {e.Message}"); + Trace.TraceInformation(e.ToString()); + } + + return null; + } + + public virtual void StartWatching() + { + if (EnableRaisingEvents) + { + // Already watching + return; + } + + if (!Directory.Exists(Path)) + { + Trace.TraceError($"Cannot watch non-existing folder {Path}."); + return; + } + + _cancellationTokenSource?.Cancel(); // should not happen, but let's be safe, okay? + + _cancellationTokenSource = new CancellationTokenSource(); + + Changed -= UpdateBackPack; + Changed += UpdateBackPack; + + // start with reading any existing status + var statusJsonPath = System.IO.Path.Combine(Path, "Backpack.json"); + if (File.Exists(statusJsonPath)) + UpdateBackPack(statusJsonPath); + + EnableRaisingEvents = true; + } + + public virtual void StopWatching() + { + try + { + if (!EnableRaisingEvents) return; + + Changed -= UpdateBackPack; + + _cancellationTokenSource?.Cancel(); + + EnableRaisingEvents = false; + + } + catch (Exception e) + { + Trace.TraceError($"Error while stopping Journal watcher: {e.Message}"); + Trace.TraceInformation(e.StackTrace); + } + } + + private void UpdateBackPack(object sender, FileSystemEventArgs e) + { + UpdateBackPack(e.FullPath); + } + + private DateTime _lastTimestamp = DateTime.MinValue; + + private void UpdateBackPack(string fullPath) + { + try + { + var backPack = ReadBackPackJson(); + + if (backPack != null) + { + // only fire the event if it's new data + if (backPack.Timestamp > _lastTimestamp) + { + _lastTimestamp = backPack.Timestamp; + FireBackPackUpdatedEvent(backPack); + } + } + } +#if DEBUG + catch (Exception ex) + { + Trace.TraceInformation($"Error while reading from Backpack.json: {ex.Message}\n{ex.StackTrace}"); +#else + catch (Exception) + { +#endif + } + } + + private void FireBackPackUpdatedEvent(BackPackEvent.BackPackEventArgs evt) => BackPackUpdated?.Invoke(this, evt); + + } + +} diff --git a/EliteJournalReader/EliteJournalReader.csproj b/EliteJournalReader/EliteJournalReader.csproj index 40d4533..59ab2e6 100644 --- a/EliteJournalReader/EliteJournalReader.csproj +++ b/EliteJournalReader/EliteJournalReader.csproj @@ -101,7 +101,10 @@ + + + @@ -123,7 +126,6 @@ - @@ -131,6 +133,9 @@ + + Component + diff --git a/EliteJournalReader/Events/BackPackChangeEvent.cs b/EliteJournalReader/Events/BackPackChangeEvent.cs new file mode 100644 index 0000000..cafaae0 --- /dev/null +++ b/EliteJournalReader/Events/BackPackChangeEvent.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; + +namespace EliteJournalReader.Events +{ + + public class BackPackChangeEvent : JournalEvent + { + public BackPackChangeEvent() : base("BackPackChange") { } + + public class BackPackChangeEventArgs : JournalEventArgs + { + public struct Item + { + public string Name { get; set; } + public string Name_Localised { get; set; } + public long OwnerID { get; set; } + public string MissionID { get; set; } + public int Count { get; set; } + public string Type { get; set; } + } + + public Item[] Added { get; set; } + public Item[] Removed { get; set; } + + } + } +} diff --git a/EliteJournalReader/Events/BackPackMaterialsEvent.cs b/EliteJournalReader/Events/BackPackEvent.cs similarity index 74% rename from EliteJournalReader/Events/BackPackMaterialsEvent.cs rename to EliteJournalReader/Events/BackPackEvent.cs index ce68922..5265bec 100644 --- a/EliteJournalReader/Events/BackPackMaterialsEvent.cs +++ b/EliteJournalReader/Events/BackPackEvent.cs @@ -7,23 +7,11 @@ namespace EliteJournalReader.Events { - //The "BackPackMaterials" event contains: - /* - {"timestamp":"2021-03-31T21:32:03Z","event":"BackPackMaterials", - "Items":[ - {"Name":"largecapacitypowerregulator", - "Name_Localised":"Power Regulator", - "OwnerID":6737826, - "MissionID":737622845, - "Count":1}], - "Components":[], - "Consumables":[]} - */ - public class BackPackMaterialsEvent : JournalEvent + public class BackPackEvent : JournalEvent { - public BackPackMaterialsEvent() : base("BackPackMaterials") { } + public BackPackEvent() : base("BackPack") { } - public class BackPackMaterialsEventArgs : JournalEventArgs + public class BackPackEventArgs : JournalEventArgs { public struct Item { diff --git a/EliteJournalReader/Events/LiftoffEvent.cs b/EliteJournalReader/Events/LiftoffEvent.cs index 1074055..679b9b2 100644 --- a/EliteJournalReader/Events/LiftoffEvent.cs +++ b/EliteJournalReader/Events/LiftoffEvent.cs @@ -18,8 +18,14 @@ public LiftoffEvent() : base("Liftoff") { } public class LiftoffEventArgs : JournalEventArgs { - public double Latitude { get; set; } - public double Longitude { get; set; } + public double? Latitude { get; set; } + public double? Longitude { get; set; } + public string StarSystem { get; set; } + public long SystemAddress { get; set; } + public string Body { get; set; } + public long BodyID { get; set; } + public bool OnStation { get; set; } + public bool OnPlanet { get; set; } public string NearestDestination { get; set; } public string NearestDestination_Localised { get; set; } public bool PlayerControlled { get; set; } diff --git a/EliteJournalReader/Events/LoadGameEvent.cs b/EliteJournalReader/Events/LoadGameEvent.cs index 09fe26a..83f77a3 100644 --- a/EliteJournalReader/Events/LoadGameEvent.cs +++ b/EliteJournalReader/Events/LoadGameEvent.cs @@ -35,6 +35,7 @@ public class LoadGameEventArgs : JournalEventArgs public string Commander { get; set; } public string FID { get; set; } public bool Horizons { get; set; } + public bool Odyssey { get; set; } public string Ship { get; set; } public string ShipID { get; set; } public string Ship_Localised { get; set; } diff --git a/EliteJournalReader/Events/LoadoutEquipModuleEvent.cs b/EliteJournalReader/Events/LoadoutEquipModuleEvent.cs index 3a7f94b..efc1665 100644 --- a/EliteJournalReader/Events/LoadoutEquipModuleEvent.cs +++ b/EliteJournalReader/Events/LoadoutEquipModuleEvent.cs @@ -19,6 +19,7 @@ public class LoadoutEquipModuleEventArgs : JournalEventArgs { public string SuitID { get; set; } public string SuitName { get; set; } + public string SlotName { get; set; } public string LoadoutID { get; set; } public string LoadoutName { get; set; } public string ModuleName { get; set; } diff --git a/EliteJournalReader/Events/LoadoutRemoveModuleEvent.cs b/EliteJournalReader/Events/LoadoutRemoveModuleEvent.cs index ef49c70..cb4e988 100644 --- a/EliteJournalReader/Events/LoadoutRemoveModuleEvent.cs +++ b/EliteJournalReader/Events/LoadoutRemoveModuleEvent.cs @@ -19,6 +19,7 @@ public class LoadoutRemoveModuleEventArgs : JournalEventArgs { public string SuitID { get; set; } public string SuitName { get; set; } + public string SlotName { get; set; } public string LoadoutID { get; set; } public string LoadoutName { get; set; } public string ModuleName { get; set; } diff --git a/EliteJournalReader/Events/StatusFileEvent.cs b/EliteJournalReader/Events/StatusFileEvent.cs index 1ab82f9..d56dc18 100644 --- a/EliteJournalReader/Events/StatusFileEvent.cs +++ b/EliteJournalReader/Events/StatusFileEvent.cs @@ -137,7 +137,12 @@ public enum StatusFlags2 : long Cold = 0x00000100, Hot = 0x00000200, VeryCold = 0x00000400, - VeryHot = 0x00000800 + VeryHot = 0x00000800, + GlideMode = 0x00001000, + OnFootInHangar = 0x00002000, + OnFootSocialSpace = 0x00004000, + OnFootExterior = 0x00008000, + BreathableAtmosphere = 0x00010001 } public enum StatusGuiFocus diff --git a/EliteJournalReader/Events/SuitLoadoutEvent.cs b/EliteJournalReader/Events/SuitLoadoutEvent.cs new file mode 100644 index 0000000..3ff3d0e --- /dev/null +++ b/EliteJournalReader/Events/SuitLoadoutEvent.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; + +namespace EliteJournalReader.Events +{ + + + public class SuitLoadoutEvent : JournalEvent + { + public SuitLoadoutEvent() : base("SuitLoadout") { } + + public class SuitLoadoutEventArgs : JournalEventArgs + { + public struct Module + { + public string SlotName { get; set; } + public string SuitModuleID { get; set; } + public string ModuleName { get; set; } + public string ModuleName_Localised { get; set; } + } + public string SuitID { get; set; } + public string SuitName { get; set; } + public string LoadoutID { get; set; } + public string LoadoutName { get; set; } + + public Module[] Modules { get; set; } + } + } +} diff --git a/EliteJournalReader/Events/TouchdownEvent.cs b/EliteJournalReader/Events/TouchdownEvent.cs index 4f22669..f13131b 100644 --- a/EliteJournalReader/Events/TouchdownEvent.cs +++ b/EliteJournalReader/Events/TouchdownEvent.cs @@ -18,8 +18,14 @@ public TouchdownEvent() : base("Touchdown") { } public class TouchdownEventArgs : JournalEventArgs { - public double Latitude { get; set; } - public double Longitude { get; set; } + public double? Latitude { get; set; } + public double? Longitude { get; set; } + public string StarSystem { get; set; } + public long SystemAddress { get; set; } + public string Body { get; set; } + public long BodyID { get; set; } + public bool OnStation { get; set; } + public bool OnPlanet { get; set; } public string NearestDestination { get; set; } public string NearestDestination_Localised { get; set; } public bool PlayerControlled { get; set; } diff --git a/ImportData/Program.cs b/ImportData/Program.cs index 021596a..1d9f7f3 100644 --- a/ImportData/Program.cs +++ b/ImportData/Program.cs @@ -772,9 +772,9 @@ static void Main(string[] args) populatedSystemsEDDBbyEdsmId.TryGetValue(z.SystemId, out var system); z.PopulatedSystemEDDB = system; - z.PrimaryEconomy = z.AdditionalStationDataEDDB?.Economies?.First() ?? z.PopulatedSystemEDDB?.PrimaryEconomy ?? z.Economy; + z.PrimaryEconomy = z.AdditionalStationDataEDDB?.Economies?.FirstOrDefault() ?? z.PopulatedSystemEDDB?.PrimaryEconomy ?? z.Economy; - z.SecondaryEconomy = z.AdditionalStationDataEDDB?.Economies?.Last() ?? z.PopulatedSystemEDDB?.PrimaryEconomy ?? z.Economy; + z.SecondaryEconomy = z.AdditionalStationDataEDDB?.Economies?.LastOrDefault() ?? z.PopulatedSystemEDDB?.PrimaryEconomy ?? z.Economy; if (z.AdditionalStationDataEDDB?.Economies?.Count == 2 && !string.IsNullOrEmpty(z.PopulatedSystemEDDB?.PrimaryEconomy) && z.PrimaryEconomy != z.PopulatedSystemEDDB.PrimaryEconomy) { diff --git a/ImportData/Properties/AssemblyInfo.cs b/ImportData/Properties/AssemblyInfo.cs index 1e61ddd..5897df8 100644 --- a/ImportData/Properties/AssemblyInfo.cs +++ b/ImportData/Properties/AssemblyInfo.cs @@ -31,7 +31,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.7.2.0")] -[assembly: AssemblyFileVersion("1.7.2.0")] +[assembly: AssemblyVersion("1.7.3.0")] +[assembly: AssemblyFileVersion("1.7.3.0")] [assembly: log4net.Config.XmlConfigurator(Watch = true)]