private void _handleCargoEvent(CargoEvent @event) { if (@event.vessel == Constants.VEHICLE_SHIP) { cargoCarried = @event.cargocarried; if (@event.inventory != null) { List <CargoInfo> infoList = @event.inventory.ToList(); // Remove strays from the manifest foreach (Cargo inventoryCargo in inventory.ToList()) { string name = inventoryCargo.edname; CargoInfo info = @event.inventory.FirstOrDefault(i => i.name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (info == null) { if (inventoryCargo.haulageData?.Any() ?? false) { // Keep cargo entry in manifest with zeroed amounts, if missions are pending inventoryCargo.haulage = 0; inventoryCargo.owned = 0; inventoryCargo.stolen = 0; inventoryCargo.CalculateNeed(); } else { // Strip out the stray from the manifest _RemoveCargoWithEDName(inventoryCargo.edname); } } } // Update existing cargo in the manifest while (infoList.Any()) { string name = infoList.ToList().First().name; List <CargoInfo> cargoInfo = infoList.Where(i => i.name.Equals(name, StringComparison.OrdinalIgnoreCase)).ToList(); Cargo cargo = inventory.FirstOrDefault(c => c.edname.Equals(name, StringComparison.OrdinalIgnoreCase)); if (cargo != null) { int total = cargoInfo.Sum(i => i.count); int stolen = cargoInfo.Where(i => i.missionid == null).Sum(i => i.stolen); int missionCount = cargoInfo.Count(i => i.missionid != null); if (total != cargo.total || stolen != cargo.stolen || missionCount != cargo.haulageData.Count()) { UpdateCargoFromInfo(cargo, cargoInfo); } } else { // Add cargo entries for those missing cargo = new Cargo(name); UpdateCargoFromInfo(cargo, cargoInfo); } AddOrUpdateCargo(cargo); infoList.RemoveAll(i => i.name == name); } } } }
private void handleCargoEvent(CargoEvent @event) { if (_handleCargoEvent(@event)) { writeInventory(); } }
private void handleCargoEvent(CargoEvent @event) { if (@event.timestamp > updateDat) { updateDat = @event.timestamp; _handleCargoEvent(@event); writeInventory(); } }
private bool _handleCargoEvent(CargoEvent @event) { bool cargoUpdated = false; if (@event.vessel == Constants.VEHICLE_SHIP) { cargoCarried = @event.cargocarried; if (@event.inventory != null) { List <CargoInfo> infoList = @event.inventory.ToList(); // Remove strays from the manifest foreach (Cargo inventoryCargo in inventory.ToList()) { CargoInfo info = @event.inventory.FirstOrDefault(i => i.name == inventoryCargo.edname.ToLowerInvariant()); if (info == null) { if (inventoryCargo.haulageData == null || !inventoryCargo.haulageData.Any()) { // Strip out the stray from the manifest _RemoveCargoWithEDName(inventoryCargo.edname); cargoUpdated = true; } else { // Keep cargo entry in manifest with zeroed amounts, if missions are pending inventoryCargo.total = 0; inventoryCargo.haulage = 0; inventoryCargo.owned = 0; inventoryCargo.stolen = 0; inventoryCargo.CalculateNeed(); } cargoUpdated = true; } } while (infoList.Count() > 0) { string name = infoList.ToList().First().name; List <CargoInfo> cargoInfo = infoList.Where(i => i.name == name).ToList(); Cargo cargo = inventory.FirstOrDefault(c => c.edname.ToLowerInvariant() == name); if (cargo != null) { int total = cargoInfo.Sum(i => i.count); int stolen = cargoInfo.Where(i => i.missionid == null).Sum(i => i.stolen); int missionCount = cargoInfo.Where(i => i.missionid != null).Count(); if (total != cargo.total || stolen != cargo.stolen || missionCount != cargo.haulageData.Count()) { UpdateCargoFromInfo(cargo, cargoInfo); if (@event.update) { return(true); } cargoUpdated = true; } } else { // Add cargo entries for those missing cargo = new Cargo(name, 0); UpdateCargoFromInfo(cargo, cargoInfo); AddCargo(cargo); cargoUpdated = true; } infoList.RemoveAll(i => i.name == name); } } } return(cargoUpdated); }