Exemplo n.º 1
0
 internal CargoDepotEvent InvokeEvent(CargoDepotEvent arg)
 {
     if (_api.ValidateEvent(arg))
     {
         CargoDepot?.Invoke(_api, arg);
     }
     return(arg);
 }
Exemplo n.º 2
0
 private void handleCargoDepotEvent(CargoDepotEvent @event)
 {
     if (@event.timestamp > updateDat)
     {
         updateDat = @event.timestamp;
         _handleCargoDepotEvent(@event);
         writeInventory();
     }
 }
Exemplo n.º 3
0
 private void AssertEvent(CargoDepotEvent @event)
 {
     Assert.NotNull(@event);
     Assert.Equal(DateTime.Parse("2019-09-08T10:25:03Z"), @event.Timestamp);
     Assert.Equal(EventName, @event.Event);
     Assert.Equal(508888377, @event.MissionId);
     Assert.Equal(CargoUpdateType.Collect, @event.UpdateType);
     Assert.Equal("Superconductors", @event.CargoType);
     Assert.Equal("Сверхпроводники", @event.CargoTypeLocalised);
     Assert.Equal(3223641856, @event.StartMarketId);
     Assert.Equal(3223642368, @event.EndMarketId);
     Assert.Equal(45, @event.Count);
     Assert.Equal(45, @event.ItemsCollected);
     Assert.Equal(0, @event.ItemsDelivered);
     Assert.Equal(45, @event.TotalItemsToDeliver);
     Assert.Equal(1.000000, @event.Progress, 6);
 }
Exemplo n.º 4
0
        private void _handleCargoDepotEvent(CargoDepotEvent @event)
        {
            MissionMonitor missionMonitor  = (MissionMonitor)EDDI.Instance.ObtainMonitor("Mission monitor");
            Mission        mission         = missionMonitor?.GetMissionWithMissionId(@event.missionid ?? 0);
            Cargo          cargo           = new Cargo();
            Haulage        haulage         = new Haulage();
            int            amountRemaining = @event.totaltodeliver - @event.delivered;

            switch (@event.updatetype)
            {
            case "Collect":
            {
                cargo = GetCargoWithMissionId(@event.missionid ?? 0);
                if (cargo != null)
                {
                    // Cargo instantiated by either 'Mission accepted' event or previous 'WingUpdate' update
                    haulage           = cargo.haulageData.FirstOrDefault(ha => ha.missionid == @event.missionid);
                    haulage.remaining = amountRemaining;

                    // Update commodity definition if instantiated other than 'Mission accepted'
                    cargo.commodityDef   = @event.commodityDefinition;
                    haulage.originsystem = EDDI.Instance?.CurrentStarSystem?.systemname;
                }
                else
                {
                    // First exposure to new cargo.
                    cargo = new Cargo(@event.commodityDefinition.edname, 0);         // Total will be updated by following 'Cargo' event
                    AddCargo(cargo);

                    string originSystem = EDDI.Instance?.CurrentStarSystem?.systemname;
                    string name         = mission?.name ?? "MISSION_DeliveryWing";
                    haulage = new Haulage(@event.missionid ?? 0, name, originSystem, amountRemaining, null, true);
                    cargo.haulageData.Add(haulage);
                }

                haulage.collected     = @event.collected;
                haulage.delivered     = @event.delivered;
                haulage.startmarketid = @event.startmarketid;
                haulage.endmarketid   = @event.endmarketid;
            }
            break;

            case "Deliver":
            {
                cargo = GetCargoWithMissionId(@event.missionid ?? 0);
                if (cargo != null)
                {
                    // Cargo instantiated by either 'Mission accepted' event, previous 'WingUpdate' or 'Collect' updates
                    haulage = cargo.haulageData.FirstOrDefault(ha => ha.missionid == @event.missionid);
                    if (haulage != null)
                    {
                        haulage.remaining = amountRemaining;
                        haulage.need      = amountRemaining;

                        //Update commodity definition
                        haulage.amount       = @event.totaltodeliver;
                        cargo.commodityDef   = @event.commodityDefinition;
                        haulage.originsystem = (@event.startmarketid == 0) ? EDDI.Instance?.CurrentStarSystem?.systemname : null;
                    }
                    else
                    {
                        string originSystem = (@event.startmarketid == 0) ? EDDI.Instance?.CurrentStarSystem?.systemname : null;
                        string name         = mission?.name ?? (@event.startmarketid == 0 ? "MISSION_CollectWing" : "MISSION_DeliveryWing");
                        haulage = new Haulage(@event.missionid ?? 0, name, originSystem, amountRemaining, null);
                        cargo.haulageData.Add(haulage);
                    }
                }
                else
                {
                    // Check if cargo instantiated by previous 'Market buy' event
                    cargo = GetCargoWithEDName(@event.commodityDefinition.edname);
                    if (cargo == null)
                    {
                        cargo = new Cargo(@event.commodityDefinition.edname, 0);         // Total will be updated by following 'Cargo' event
                        AddCargo(cargo);
                    }
                    string originSystem = (@event.startmarketid == 0) ? EDDI.Instance?.CurrentStarSystem?.systemname : null;
                    string name         = mission?.name ?? (@event.startmarketid == 0 ? "MISSION_CollectWing" : "MISSION_DeliveryWing");
                    haulage = new Haulage(@event.missionid ?? 0, name, originSystem, amountRemaining, null, true);
                    cargo.haulageData.Add(haulage);
                }

                // Update 'Need' when cargo is delivered, as the 'Cargo' event handler does not update 'Collect' mission types
                cargo.CalculateNeed();

                haulage.collected   = @event.collected;
                haulage.delivered   = @event.delivered;
                haulage.endmarketid = (haulage.endmarketid == 0) ? @event.endmarketid : haulage.endmarketid;

                // Check for mission completion
                if (amountRemaining == 0)
                {
                    if (haulage.shared)
                    {
                        cargo.haulageData.Remove(haulage);
                        RemoveCargo(cargo);
                    }
                    else
                    {
                        haulage.status = "Complete";
                    }
                }
            }
            break;

            case "WingUpdate":
            {
                cargo = GetCargoWithMissionId(@event.missionid ?? 0);
                if (cargo != null)
                {
                    // Cargo instantiated by either 'Mission accepted' event, previous 'WingUpdate' or 'Collect' updates
                    haulage           = cargo.haulageData.FirstOrDefault(ha => ha.missionid == @event.missionid);
                    haulage.remaining = amountRemaining;
                    haulage.need      = amountRemaining;
                }
                else
                {
                    // First exposure to new cargo, use 'Unknown' as placeholder
                    cargo = new Cargo("Unknown", 0);
                    AddCargo(cargo);
                    string name = mission?.name ?? (@event.startmarketid == 0 ? "MISSION_CollectWing" : "MISSION_DeliveryWing");
                    haulage = new Haulage(@event.missionid ?? 0, name, null, amountRemaining, null, true);
                    cargo.haulageData.Add(haulage);
                }

                // Generate a derived event when a wing-mate collects or delivers cargo for a wing mission
                int amount = Math.Max(@event.collected - haulage.collected, @event.delivered - haulage.delivered);
                if (amount > 0)
                {
                    string updatetype = @event.collected > haulage.collected ? "Collect" : "Deliver";
                    EDDI.Instance.enqueueEvent(new CargoWingUpdateEvent(DateTime.UtcNow, haulage.missionid, updatetype, cargo.commodityDef, amount, @event.collected, @event.delivered, @event.totaltodeliver));
                    haulage.collected     = @event.collected;
                    haulage.delivered     = @event.delivered;
                    haulage.startmarketid = @event.startmarketid;
                    haulage.endmarketid   = @event.endmarketid;

                    // Update 'Need' when a wing-mate delivers cargo for a wing mission
                    if (updatetype == "Deliver")
                    {
                        cargo.CalculateNeed();
                    }
                }

                // Check for mission completion
                if (amountRemaining == 0)
                {
                    if (haulage.shared)
                    {
                        cargo.haulageData.Remove(haulage);
                        RemoveCargo(cargo);
                    }
                    else
                    {
                        haulage.status = "Complete";
                    }
                }
            }
            break;
            }
        }
Exemplo n.º 5
0
 internal void InvokeCargoDepotEvent(CargoDepotEvent arg)
 {
     CargoDepotEvent?.Invoke(this, arg);
 }
Exemplo n.º 6
0
 private void handleCargoDepotEvent(CargoDepotEvent @event)
 {
     _handleCargoDepotEvent(@event);
     writeInventory();
 }
Exemplo n.º 7
0
        private void _handleCargoDepotEvent(CargoDepotEvent @event)
        {
            Cargo         cargo           = new Cargo();
            HaulageAmount haulageAmount   = new HaulageAmount();
            int           amountRemaining = @event.totaltodeliver - @event.delivered;

            switch (@event.updatetype)
            {
            case "Collect":
            {
                cargo = GetCargoWithMissionId(@event.missionid ?? 0);
                if (cargo != null)
                {
                    // Cargo instantiated by either 'Mission accepted' event or previous 'WingUpdate' update
                    haulageAmount        = cargo.haulageamounts.FirstOrDefault(ha => ha.id == @event.missionid);
                    haulageAmount.amount = amountRemaining;

                    // Update commodity definition if intantiated by previous 'WingUpdate' update
                    if (cargo.commodityDef.edname == "Unknown")
                    {
                        cargo.commodityDef = @event.commodityDefinition;
                    }
                }
                else
                {
                    // First exposure to new cargo.
                    cargo = new Cargo(@event.commodityDefinition.edname, 0);
                    AddCargo(cargo);

                    haulageAmount = new HaulageAmount(@event.missionid ?? 0, "MISSION_DeliveryWing", amountRemaining, DateTime.MaxValue, true);
                    cargo.haulageamounts.Add(haulageAmount);
                }
                cargo.haulage += @event.amount ?? 0;
                cargo.CalculateNeed();
                haulageAmount.collected = @event.collected;
                haulageAmount.delivered = @event.delivered;
            }
            break;

            case "Deliver":
            {
                cargo = GetCargoWithMissionId(@event.missionid ?? 0);
                if (cargo != null)
                {
                    // Cargo instantiated by either 'Mission accepted' event, previous 'WingUpdate' or 'Collect' updates
                    haulageAmount        = cargo.haulageamounts.FirstOrDefault(ha => ha.id == @event.missionid);
                    haulageAmount.amount = amountRemaining;

                    //Update commodity definition if intantiated by previous 'WingUpdate' update
                    if (cargo.commodityDef.edname == "Unknown")
                    {
                        cargo.commodityDef = @event.commodityDefinition;
                    }
                }
                else
                {
                    // Cargo instantiated by previous 'Market buy' event
                    cargo = GetCargoWithEDName(@event.commodityDefinition.edname);

                    string type = @event.collected > 0 ? "MISSION_DeliveryWing" : "MISSION_CollectWing";
                    haulageAmount = new HaulageAmount(@event.missionid ?? 0, type, amountRemaining, DateTime.MaxValue, true);
                    cargo.haulageamounts.Add(haulageAmount);
                }

                if (haulageAmount.type.Contains("delivery"))
                {
                    cargo.haulage -= @event.amount ?? 0;
                }
                else
                {
                    cargo.owned -= @event.amount ?? 0;
                }
                cargo.CalculateNeed();
                haulageAmount.collected = @event.collected;
                haulageAmount.delivered = @event.delivered;

                // Check for shared mission completion
                if (haulageAmount.shared && amountRemaining == 0)
                {
                    cargo.haulageamounts.Remove(haulageAmount);
                    RemoveCargo(cargo);
                }
            }
            break;

            case "WingUpdate":
            {
                cargo = GetCargoWithMissionId(@event.missionid ?? 0);
                if (cargo != null)
                {
                    // Cargo instantiated by either 'Mission accepted' event, previous 'WingUpdate' or 'Collect' updates
                    haulageAmount        = cargo.haulageamounts.FirstOrDefault(ha => ha.id == @event.missionid);
                    haulageAmount.amount = amountRemaining;
                }
                else
                {
                    // First exposure to new cargo, use 'Unknown' as placeholder
                    cargo = new Cargo("Unknown", 0);
                    AddCargo(cargo);
                    string type = @event.collected > 0 ? "MISSION_DeliveryWing" : "MISSION_CollectWing";
                    haulageAmount = new HaulageAmount(@event.missionid ?? 0, type, amountRemaining, DateTime.MaxValue, true);
                    cargo.haulageamounts.Add(haulageAmount);
                }

                int amount = Math.Max(@event.collected - haulageAmount.collected, @event.delivered - haulageAmount.delivered);
                if (amount > 0)
                {
                    string updatetype = @event.collected > haulageAmount.collected ? "Collect" : "Deliver";
                    EDDI.Instance.eventHandler(new CargoWingUpdateEvent(DateTime.Now, haulageAmount.id, updatetype, cargo.commodityDef, amount, @event.collected, @event.delivered, @event.totaltodeliver));
                }
                cargo.CalculateNeed();
                haulageAmount.collected = @event.collected;
                haulageAmount.delivered = @event.delivered;

                // Check for shared mission completion
                if (haulageAmount.shared && amountRemaining == 0)
                {
                    cargo.haulageamounts.Remove(haulageAmount);
                    RemoveCargo(cargo);
                }
            }
            break;
            }
        }
Exemplo n.º 8
0
 internal void InvokeCargoDepotEvent(CargoDepotEvent arg) => CargoDepotEvent?.Invoke(null, arg);