@@ -1341,60 +1341,14 @@ private async Task<bool> eventCarrierJumpedAsync( CarrierJumpedEvent @event )
13411341 // Update our system properties
13421342 if ( CurrentStarSystem is null ) { return false ; }
13431343
1344- CurrentStarSystem . x = @event . x ;
1345- CurrentStarSystem . y = @event . y ;
1346- CurrentStarSystem . z = @event . z ;
1347-
1348- // Update Thargoid war data, when available
1349- CurrentStarSystem . ThargoidWar = @event . ThargoidWar ;
1344+ await ApplyCurrentSystemSnapshotAsync ( CurrentStarSystem , @event . systemname , @event . systemAddress , @event . x , @event . y , @event . z , @event . controllingsystemfaction , @event . factions , @event . conflicts , @event . systemEconomy , @event . systemEconomy2 , @event . securityLevel , @event . population , @event . Power , @event . NearbyPowers , @event . PowerState , @event . powerAcquisitionProgress , @event . powerControlProgress , @event . powerReinforcementControlPoints , @event . powerUnderminingControlPoints , @event . ThargoidWar , @event . timestamp , true ) . ConfigureAwait ( false ) ;
13501345
13511346 if ( CurrentStation != null )
13521347 {
13531348 // Add our carrier to the new current star system
13541349 CurrentStarSystem . AddOrUpdateStation ( CurrentStation ) ;
13551350 }
13561351
1357- // Update the mutable system data from the journal
1358- if ( @event . population != null )
1359- {
1360- CurrentStarSystem . population = @event . population ;
1361- CurrentStarSystem . Economies = [ @event . systemEconomy , @event . systemEconomy2 ] ;
1362- CurrentStarSystem . securityLevel = @event . securityLevel ;
1363- CurrentStarSystem . Faction = @event . controllingsystemfaction ;
1364- }
1365-
1366- // Update system faction data if available
1367- if ( @event . factions != null )
1368- {
1369- CurrentStarSystem . factions = @event . factions ;
1370- CurrentStarSystem . conflicts = @event . conflicts ;
1371-
1372- // Update station controlling faction data
1373- foreach ( var station in CurrentStarSystem . stations )
1374- {
1375- var stationFaction = @event . factions
1376- . FirstOrDefault ( f => f . name == station . Faction ? . name ) ;
1377- if ( stationFaction != null )
1378- {
1379- station . Faction = stationFaction ;
1380- }
1381- }
1382- }
1383-
1384- // (When pledged) Powerplay information
1385- CurrentStarSystem . Power = @event . Power ;
1386- CurrentStarSystem . NearbyPowers = @event . NearbyPowers ;
1387- CurrentStarSystem . powerState = @event . PowerState ?? CurrentStarSystem . powerState ;
1388- CurrentStarSystem . powerAcquisitionProgress = @event . powerAcquisitionProgress ;
1389- CurrentStarSystem . powerControlProgress = @event . powerControlProgress ;
1390- CurrentStarSystem . powerReinforcementControlPoints = @event . powerReinforcementControlPoints ;
1391- CurrentStarSystem . powerUnderminingControlPoints = @event . powerUnderminingControlPoints ;
1392-
1393- // Update to most recent information
1394- CurrentStarSystem . visitLog . Add ( @event . timestamp ) ;
1395- CurrentStarSystem . updatedat = Dates . fromDateTimeToSeconds ( @event . timestamp ) ;
1396- await DataProvider . SaveStarSystemAsync ( CurrentStarSystem ) . ConfigureAwait ( false ) ;
1397-
13981352 // Kick off the profile refresh if the companion API is available
13991353 if ( CompanionAppService . Instance . CurrentState == CompanionAppService . State . Authorized && carrierID != null )
14001354 {
@@ -1635,48 +1589,7 @@ internal async Task<bool> eventLocationAsync( LocationEvent theEvent )
16351589 await updateCurrentSystemAsync ( theEvent . systemname , theEvent . systemAddress ) . ConfigureAwait ( false ) ;
16361590 if ( CurrentStarSystem is null ) { return false ; }
16371591
1638- // Always update the current system with the current co-ordinates, just in case things have changed or coordinates are not yet known
1639- CurrentStarSystem . x = theEvent . x ;
1640- CurrentStarSystem . y = theEvent . y ;
1641- CurrentStarSystem . z = theEvent . z ;
1642-
1643- // Update Thargoid war data, as applicable
1644- CurrentStarSystem . ThargoidWar = theEvent . ThargoidWar ;
1645-
1646- // Update the mutable system data from the journal
1647- if ( theEvent . population != null )
1648- {
1649- CurrentStarSystem . population = theEvent . population ;
1650- CurrentStarSystem . Economies = [ theEvent . Economy , theEvent . Economy2 ] ;
1651- CurrentStarSystem . securityLevel = theEvent . securityLevel ;
1652- CurrentStarSystem . Faction = theEvent . controllingsystemfaction ;
1653- }
1654-
1655- // Update system faction data if available
1656- if ( theEvent . factions != null )
1657- {
1658- CurrentStarSystem . factions = theEvent . factions ;
1659- CurrentStarSystem . conflicts = theEvent . conflicts ;
1660-
1661- // Update station controlling faction data
1662- foreach ( var station in CurrentStarSystem . stations )
1663- {
1664- var stationFaction = theEvent . factions . FirstOrDefault ( f => f . name == station ? . Faction ? . name ) ;
1665- if ( stationFaction != null )
1666- {
1667- station . Faction = stationFaction ;
1668- }
1669- }
1670- }
1671-
1672- // (When pledged) Powerplay information
1673- CurrentStarSystem . Power = theEvent . Power ;
1674- CurrentStarSystem . NearbyPowers = theEvent . NearbyPowers ;
1675- CurrentStarSystem . powerState = theEvent . PowerState ?? CurrentStarSystem . powerState ;
1676- CurrentStarSystem . powerAcquisitionProgress = theEvent . powerAcquisitionProgress ;
1677- CurrentStarSystem . powerControlProgress = theEvent . powerControlProgress ;
1678- CurrentStarSystem . powerReinforcementControlPoints = theEvent . powerReinforcementControlPoints ;
1679- CurrentStarSystem . powerUnderminingControlPoints = theEvent . powerUnderminingControlPoints ;
1592+ await ApplyCurrentSystemSnapshotAsync ( CurrentStarSystem , theEvent . systemname , theEvent . systemAddress , theEvent . x , theEvent . y , theEvent . z , theEvent . controllingsystemfaction , theEvent . factions , theEvent . conflicts , theEvent . Economy , theEvent . Economy2 , theEvent . securityLevel , theEvent . population , theEvent . Power , theEvent . NearbyPowers , theEvent . PowerState , theEvent . powerAcquisitionProgress , theEvent . powerControlProgress , theEvent . powerReinforcementControlPoints , theEvent . powerUnderminingControlPoints , theEvent . ThargoidWar , theEvent . timestamp , true ) . ConfigureAwait ( false ) ;
16801593
16811594 if ( theEvent . docked )
16821595 {
@@ -2070,6 +1983,82 @@ private async Task<bool> eventShipyardAsync(ShipyardEvent theEvent)
20701983 return false ;
20711984 }
20721985
1986+ private async Task ApplyCurrentSystemSnapshotAsync (
1987+ StarSystem system ,
1988+ string systemName ,
1989+ ulong systemAddress ,
1990+ decimal ? x ,
1991+ decimal ? y ,
1992+ decimal ? z ,
1993+ Faction controllingFaction ,
1994+ List < Faction > factions ,
1995+ List < Conflict > conflicts ,
1996+ Economy economy ,
1997+ Economy economy2 ,
1998+ SecurityLevel security ,
1999+ long ? population ,
2000+ Power power ,
2001+ List < Power > nearbyPowers ,
2002+ PowerplayState powerState ,
2003+ List < PowerAcquisitionProgress > acquisitionProgress ,
2004+ decimal controlProgress ,
2005+ int reinforcementPoints ,
2006+ int underminingPoints ,
2007+ ThargoidWar thargoidWar ,
2008+ DateTime timestamp ,
2009+ bool addVisit )
2010+ {
2011+ if ( system is null )
2012+ { return ; }
2013+
2014+ system . systemname = systemName ;
2015+ system . systemAddress = systemAddress ;
2016+ system . x = x ;
2017+ system . y = y ;
2018+ system . z = z ;
2019+
2020+ if ( factions != null )
2021+ {
2022+ system . factions = factions ;
2023+ system . conflicts = conflicts ;
2024+
2025+ // Make the controlling faction reference the same object as the factions list.
2026+ system . Faction = factions . FirstOrDefault ( f => f . name == controllingFaction ? . name )
2027+ ?? controllingFaction ;
2028+ }
2029+ else
2030+ {
2031+ system . Faction = controllingFaction ;
2032+ system . conflicts = conflicts ;
2033+ }
2034+
2035+ system . ThargoidWar = thargoidWar ;
2036+ system . Economies = [ economy , economy2 ] ;
2037+ system . securityLevel = security ?? SecurityLevel . None ;
2038+
2039+ if ( population != null )
2040+ {
2041+ system . population = population ;
2042+ }
2043+
2044+ system . Power = power ;
2045+ system . NearbyPowers = nearbyPowers ;
2046+ system . powerState = powerState ?? system . powerState ;
2047+ system . powerAcquisitionProgress = acquisitionProgress ;
2048+ system . powerControlProgress = controlProgress ;
2049+ system . powerReinforcementControlPoints = reinforcementPoints ;
2050+ system . powerUnderminingControlPoints = underminingPoints ;
2051+
2052+ if ( addVisit )
2053+ {
2054+ system . visitLog . Add ( timestamp ) ;
2055+ }
2056+
2057+ system . updatedat = Dates . fromDateTimeToSeconds ( timestamp ) ;
2058+
2059+ await DataProvider . SaveStarSystemAsync ( system ) . ConfigureAwait ( false ) ;
2060+ }
2061+
20732062 internal async Task updateCurrentSystemAsync ( [ NotNull ] string systemName , ulong systemAddress )
20742063 {
20752064 try
@@ -2151,10 +2140,12 @@ internal async Task<bool> eventFSDEngagedAsync( FSDEngagedEvent @event )
21512140 ? Constants . ENVIRONMENT_SUPERCRUISE
21522141 : Constants . ENVIRONMENT_WITCH_SPACE ;
21532142
2154- // Set the destination system as the current star system
2155- if ( @event . systemAddress != null )
2143+ // Set the destination system as the next star system
2144+ if ( @event . systemAddress != null && @event . systemAddress != NextStarSystem ? . systemAddress )
21562145 {
2157- await updateCurrentSystemAsync ( @event . systemname , ( ulong ) @event . systemAddress ) . ConfigureAwait ( false ) ;
2146+ NextStarSystem = await DataProvider
2147+ . GetOrCreateStarSystemAsync ( ( ulong ) @event . systemAddress , @event . systemname )
2148+ . ConfigureAwait ( false ) ;
21582149 }
21592150
21602151 // Remove information about the current station and stellar body
@@ -2229,7 +2220,7 @@ internal async Task<bool> eventJumpedAsync( JumpedEvent theEvent )
22292220 Vehicle = Constants . VEHICLE_SHIP ;
22302221 }
22312222
2232- if ( LastStarSystem ? . systemAddress > 0 && LastStarSystem . systemAddress == theEvent . systemAddress )
2223+ if ( CurrentStarSystem ? . systemAddress > 0 && CurrentStarSystem . systemAddress == theEvent . systemAddress )
22332224 {
22342225 // Thargoid Hyperdiction
22352226 Logging . Info ( $ "Jump Interrupted: Hyperdicted in { theEvent . system } " ) ;
@@ -2255,50 +2246,7 @@ internal async Task<bool> eventJumpedAsync( JumpedEvent theEvent )
22552246
22562247 await updateCurrentSystemAsync ( theEvent . system , theEvent . systemAddress ) . ConfigureAwait ( false ) ;
22572248 if ( CurrentStarSystem is null ) { return false ; }
2258- CurrentStarSystem . systemAddress = theEvent . systemAddress ;
2259- CurrentStarSystem . x = theEvent . x ;
2260- CurrentStarSystem . y = theEvent . y ;
2261- CurrentStarSystem . z = theEvent . z ;
2262- CurrentStarSystem . Faction = theEvent . controllingfaction ;
2263- CurrentStarSystem . conflicts = theEvent . conflicts ;
2264- CurrentStarSystem . ThargoidWar = theEvent . ThargoidWar ;
2265-
2266- // Update system faction data if available
2267- if ( theEvent . factions != null )
2268- {
2269- CurrentStarSystem . factions = theEvent . factions ;
2270-
2271- // Update station controlling faction data
2272- foreach ( var station in CurrentStarSystem . stations )
2273- {
2274- var stationFaction = theEvent . factions . Find ( f => f . name == station ? . Faction ? . name ) ;
2275- if ( stationFaction != null )
2276- {
2277- station . Faction = stationFaction ;
2278- }
2279- }
2280- }
2281-
2282- CurrentStarSystem . Economies = [ theEvent . Economy , theEvent . Economy2 ] ;
2283- CurrentStarSystem . securityLevel = theEvent . securityLevel ;
2284- if ( theEvent . population != null )
2285- {
2286- CurrentStarSystem . population = theEvent . population ;
2287- }
2288-
2289- // Powerplay information
2290- CurrentStarSystem . Power = theEvent . Power ;
2291- CurrentStarSystem . NearbyPowers = theEvent . NearbyPowers ;
2292- CurrentStarSystem . powerState = theEvent . PowerState ;
2293- CurrentStarSystem . powerAcquisitionProgress = theEvent . powerAcquisitionProgress ;
2294- CurrentStarSystem . powerControlProgress = theEvent . powerControlProgress ;
2295- CurrentStarSystem . powerReinforcementControlPoints = theEvent . powerReinforcementControlPoints ;
2296- CurrentStarSystem . powerUnderminingControlPoints = theEvent . powerUnderminingControlPoints ;
2297-
2298- // Update to most recent information
2299- CurrentStarSystem . visitLog . Add ( theEvent . timestamp ) ;
2300- CurrentStarSystem . updatedat = Dates . fromDateTimeToSeconds ( theEvent . timestamp ) ;
2301- await DataProvider . SaveStarSystemAsync ( CurrentStarSystem ) . ConfigureAwait ( false ) ;
2249+ await ApplyCurrentSystemSnapshotAsync ( CurrentStarSystem , theEvent . system , theEvent . systemAddress , theEvent . x , theEvent . y , theEvent . z , theEvent . controllingfaction , theEvent . factions , theEvent . conflicts , theEvent . Economy , theEvent . Economy2 , theEvent . securityLevel , theEvent . population , theEvent . Power , theEvent . NearbyPowers , theEvent . PowerState , theEvent . powerAcquisitionProgress , theEvent . powerControlProgress , theEvent . powerReinforcementControlPoints , theEvent . powerUnderminingControlPoints , theEvent . ThargoidWar , theEvent . timestamp , true ) . ConfigureAwait ( false ) ;
23022250
23032251 return passEvent ;
23042252 }
0 commit comments