Skip to content

Commit

Permalink
Fixed the inventory object not being updated until after the `Commo…
Browse files Browse the repository at this point in the history
…dity collected` event.
  • Loading branch information
Tkael authored and bcthund committed Jun 26, 2024
1 parent d58ade5 commit a2ab1bf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
66 changes: 32 additions & 34 deletions CargoMonitor/CargoMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public void PreHandle(Event @event)
}
else if (@event is CargoDepotEvent cargoDepotEvent)
{
// If cargo is collected or delivered in a wing mission
handleCargoDepotEvent(cargoDepotEvent);
}
else if (@event is LimpetPurchasedEvent limpetPurchasedEvent)
Expand All @@ -158,32 +157,26 @@ public void PreHandle(Event @event)
}
else if (@event is MissionsEvent missionsEvent)
{
// Remove cargo haulage stragglers for completed missions
handleMissionsEvent(missionsEvent);
}
else if (@event is MissionAbandonedEvent missionAbandonedEvent)
{
// If we abandon a mission with cargo it becomes stolen
handleMissionAbandonedEvent(missionAbandonedEvent);
}
else if (@event is MissionAcceptedEvent missionAcceptedEvent)
{
// Check to see if this is a cargo mission and update our inventory accordingly
handleMissionAcceptedEvent(missionAcceptedEvent);
}
else if (@event is MissionCompletedEvent missionCompletedEvent)
{
// Check to see if this is a cargo mission and update our inventory accordingly
handleMissionCompletedEvent(missionCompletedEvent);
}
else if (@event is MissionExpiredEvent missionExpiredEvent)
{
// Check to see if this is a cargo mission and update our inventory accordingly
handleMissionExpiredEvent(missionExpiredEvent);
}
else if (@event is MissionFailedEvent missionFailedEvent)
{
// If we fail a mission with cargo it becomes stolen
handleMissionFailedEvent(missionFailedEvent);
}
else if (@event is DiedEvent)
Expand All @@ -200,6 +193,7 @@ public void PreHandle(Event @event)
}
}

// Keeps inventory levels synced to the game
private void handleCargoEvent(CargoEvent @event)
{
if (@event.timestamp > updateDat)
Expand Down Expand Up @@ -285,39 +279,36 @@ private void handleCommodityCollectedEvent(CommodityCollectedEvent @event)

private bool _handleCommodityCollectedEvent(CommodityCollectedEvent @event)
{
var update = false;
var cargo = GetCargoWithEDName(@event.commodityDefinition?.edname);
if (cargo != null)
var cargo = GetCargoWithEDName(@event.commodityDefinition?.edname) ?? new Cargo(@event.commodityDefinition?.edname);
var haulage = cargo.haulageData.FirstOrDefault( h => h.missionid == @event.missionid );
if ( @event.missionid != null )
{
var haulage = cargo.haulageData.FirstOrDefault(h => h.missionid == @event.missionid);
if (EDDI.Instance?.Vehicle != Constants.VEHICLE_SHIP)
{
if (haulage != null)
{
cargo.AddDetailedQty(CargoType.mission, 1, 0);
}
else if (@event.stolen)
{
cargo.AddDetailedQty(CargoType.stolen, 1, 0);
}
else
{
cargo.AddDetailedQty(CargoType.legal, 1, 0);
}
cargo.CalculateNeed();
update = true;
}
if (haulage != null && ((haulage.typeEDName?.Contains("mining") ?? false)
|| (haulage.typeEDName?.Contains("piracy") ?? false)
|| (haulage.typeEDName?.Contains("rescue") ?? false)
|| (haulage.typeEDName?.Contains("salvage") ?? false)))
if ( ( haulage?.typeEDName?.Contains( "mining" ) ?? false )
|| ( haulage?.typeEDName?.Contains( "piracy" ) ?? false )
|| ( haulage?.typeEDName?.Contains( "rescue" ) ?? false )
|| ( haulage?.typeEDName?.Contains( "salvage" ) ?? false ) )
{
haulage.sourcesystem = EDDI.Instance?.CurrentStarSystem?.systemname;
haulage.sourcebody = EDDI.Instance?.CurrentStellarBody?.bodyname;
update = true;
}
}
return update;

if ( @event.missionid != null )
{
cargo.AddDetailedQty( CargoType.mission, 1, 0, haulage );
}
else if ( @event.stolen )
{
cargo.AddDetailedQty( CargoType.stolen, 1, 0 );
}
else
{
cargo.AddDetailedQty( CargoType.legal, 1, 0 );
}

cargo.CalculateNeed();
AddOrUpdateCargo( cargo );
return true;
}

private void handleCommodityEjectedEvent(CommodityEjectedEvent @event)
Expand Down Expand Up @@ -455,6 +446,7 @@ private void handleCommoditySoldEvent(CommoditySoldEvent @event)
}
}

// If cargo is collected or delivered in a wing mission
private void handleCargoDepotEvent(CargoDepotEvent @event)
{
if (@event.timestamp > updateDat)
Expand Down Expand Up @@ -648,6 +640,7 @@ private bool _handleLimpetPurchasedEvent(LimpetPurchasedEvent @event)
return true;
}

// Remove cargo haulage stragglers for completed missions
private void handleMissionsEvent(MissionsEvent @event)
{
if (@event.timestamp > updateDat)
Expand Down Expand Up @@ -679,6 +672,7 @@ private bool _handleMissionsEvent(MissionsEvent @event)
return update;
}

// If we abandon a mission with cargo it becomes stolen
private void handleMissionAbandonedEvent(MissionAbandonedEvent @event)
{
if (@event.timestamp > updateDat)
Expand Down Expand Up @@ -707,6 +701,7 @@ private bool _handleMissionAbandonedEvent(MissionAbandonedEvent @event)
return update;
}

// Check to see if this is a cargo mission and update our inventory accordingly
private void handleMissionAcceptedEvent(MissionAcceptedEvent @event)
{
if (@event.timestamp > updateDat && @event.Mission.CommodityDefinition != null)
Expand Down Expand Up @@ -779,6 +774,7 @@ private bool _handleMissionAcceptedEvent(MissionAcceptedEvent @event)
return update;
}

// Check to see if this is a cargo mission and update our inventory accordingly
private void handleMissionCompletedEvent(MissionCompletedEvent @event)
{
if (@event.commodityDefinition != null || @event.commodityrewards != null)
Expand Down Expand Up @@ -811,6 +807,7 @@ private bool _handleMissionCompletedEvent(MissionCompletedEvent @event)
return update;
}

// Check to see if this is a cargo mission and update our inventory accordingly
private void handleMissionExpiredEvent(MissionExpiredEvent @event)
{
if (@event.timestamp > updateDat)
Expand All @@ -835,6 +832,7 @@ private bool _handleMissionExpiredEvent(MissionExpiredEvent @event)
return update;
}

// If we fail a mission with cargo it becomes stolen
private void handleMissionFailedEvent(MissionFailedEvent @event)
{
if (@event.timestamp > updateDat)
Expand Down
1 change: 1 addition & 0 deletions EDDI/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Full details of the variables available for each noted event, and VoiceAttack in
* EDDI will no longer report your enviroment as "Normal Space" when starting docked. (#2598)
* EDDI will delay rather than discard speech when hit by a full Thargoid shutdown. (#2603)
* Fixed a crash when using the Cottle `dump()` function to enumerate a `Haulage` object. Removed the `expiry` property from the `Haulage` object (but it is still available from the `Mission` object). (#2593)
* Fixed the `inventory` object not being updated until after the `Commodity collected` event.
* EDDN Responder
* Add support for `DockingDenied` and `DockingGranted` schemas
* Events
Expand Down

0 comments on commit a2ab1bf

Please sign in to comment.