private void handleCargoInventoryEvent(CargoInventoryEvent @event) { //// CargoInventoryEvent does not contain stolen, missionid, or cost information so merge it here //foreach (Cargo cargo in @event.inventory) //{ // bool added = false; // foreach (Cargo inventoryCargo in inventory) // { // if (inventoryCargo.commodity == cargo.commodity) // { // // Match of commodity // added = true; // } // } // if (!added) // { // // We haven't heard of this cargo so add it to the inventory directly // AddCargo(cargo); // } //} //inventory.Clear(); //foreach (Cargo cargo in @event.inventory) //{ // inventory.Add(cargo); //} }
public void _handleCargoInventoryEvent(CargoInventoryEvent @event) { // CargoInventoryEvent does not contain missionid or cost information so fill in gaps here foreach (Cargo cargo in @event.inventory) { Cargo inventoryCargo = inventory.FirstOrDefault(c => c.edname.ToLowerInvariant() == cargo.edname.ToLowerInvariant()); if (inventoryCargo != null) { // Found match of commodity inventoryCargo.total = cargo.total; inventoryCargo.stolen = cargo.stolen; if (inventoryCargo.haulageamounts == null || !inventoryCargo.haulageamounts.Any()) { inventoryCargo.haulage = 0; inventoryCargo.need = 0; } else { inventoryCargo.CalculateNeed(); } inventoryCargo.owned = cargo.total - cargo.stolen - inventoryCargo.haulage; inventoryCargo.ejected = 0; } else { // We haven't heard of this cargo so add it to the inventory directly AddCargo(cargo); } } // Remove strays from the manifest foreach (Cargo inventoryCargo in inventory.ToList()) { Cargo cargo = @event.inventory.FirstOrDefault(c => c.edname.ToLowerInvariant() == inventoryCargo.edname.ToLowerInvariant()); if (cargo == null) { // Check for pending missions if (inventoryCargo.haulageamounts == null || !inventoryCargo.haulageamounts.Any()) { // Strip out the stray from the manifest _RemoveCargoWithEDName(inventoryCargo.edname); } else { // Keep cargo entry in manifest with zeroed amounts, if missions are pending inventoryCargo.haulage = 0; inventoryCargo.owned = 0; inventoryCargo.stolen = 0; inventoryCargo.ejected = 0; } } } }
private void handleCargoInventoryEvent(CargoInventoryEvent @event) { _handleCargoInventoryEvent(@event); writeInventory(); }