private void UpdateCargoFromInfo(Cargo cargo, List <CargoInfo> infoList) { cargo.total = infoList.Sum(i => i.count); cargo.haulage = infoList.Where(i => i.missionid != null).Sum(i => i.count); cargo.stolen = infoList.Where(i => i.missionid == null).Sum(i => i.stolen); cargo.owned = cargo.total - cargo.haulage - cargo.stolen; MissionMonitor missionMonitor = (MissionMonitor)EDDI.Instance.ObtainMonitor("Mission monitor"); foreach (CargoInfo info in infoList.Where(i => i.missionid != null).ToList()) { Mission mission = missionMonitor?.GetMissionWithMissionId(info.missionid ?? 0); Haulage cargoHaulage = cargo.haulageData.FirstOrDefault(h => h.missionid == info.missionid); if (cargoHaulage != null) { int need = cargoHaulage.remaining - info.count; // Check for sold haulage if (need != cargoHaulage.need) { if (checkHaulage && need > cargoHaulage.need) { // We lost haulage switch (cargoHaulage.typeEDName) { case "delivery": case "deliverywing": case "smuggle": { cargoHaulage.status = "Failed"; if (mission != null) { mission.statusDef = MissionStatus.FromEDName("Failed"); } } break; } } cargoHaulage.need = need; } } else { string name = mission?.name ?? "Mission_None"; int amount = mission?.amount ?? info.count; DateTime?expiry = mission?.expiry; cargoHaulage = new Haulage(info.missionid ?? 0, name, mission?.originsystem, amount, expiry); cargo.haulageData.Add(cargoHaulage); } } cargo.CalculateNeed(); checkHaulage = false; }
private bool _handleCommodityEjectedEvent(CommodityEjectedEvent @event) { bool update = false; Cargo cargo = GetCargoWithEDName(@event.commodityDefinition?.edname); if (cargo != null) { if (EDDI.Instance?.Vehicle != Constants.VEHICLE_SHIP) { if (@event.missionid != null) { cargo.haulage -= @event.amount; } else { cargo.owned -= @event.amount; } cargo.CalculateNeed(); update = true; } Haulage haulage = cargo.haulageData.FirstOrDefault(h => h.missionid == @event.missionid); if (haulage != null) { MissionMonitor missionMonitor = (MissionMonitor)EDDI.Instance.ObtainMonitor("Mission monitor"); switch (haulage.typeEDName) { case "delivery": case "deliverywing": case "smuggle": { haulage.status = "Failed"; Mission mission = missionMonitor?.GetMissionWithMissionId(@event.missionid ?? 0); if (mission != null) { mission.statusDef = MissionStatus.FromEDName("Failed"); } update = true; } break; } } } return(update); }