Ejemplo n.º 1
0
 protected static void setCargo(CargoMonitor cargoMonitor, ref dynamic vaProxy)
 {
     try
     {
         vaProxy.SetInt("Ship cargo carried", cargoMonitor?.cargoCarried ?? 0);
         vaProxy.SetInt("Ship limpets carried", cargoMonitor?.GetCargoWithEDName("Drones")?.total ?? 0);
     }
     catch (Exception ex)
     {
         Logging.Error("Failed to set ship cargo values", ex);
     }
 }
Ejemplo n.º 2
0
        /// <summary>Set all values</summary>
        public static void setStandardValues(ref dynamic vaProxy)
        {
            // Update our primary objects only if they don't match the state of the EDDI instance.
            try
            {
                if (EDDI.Instance.CurrentStarSystem != CurrentStarSystem)
                {
                    setStarSystemValues(EDDI.Instance.CurrentStarSystem, "System", ref vaProxy);
                    CurrentStarSystem = EDDI.Instance.CurrentStarSystem;
                }
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to set current system", ex);
            }

            try
            {
                if (EDDI.Instance.LastStarSystem != LastStarSystem)
                {
                    setStarSystemValues(EDDI.Instance.LastStarSystem, "Last system", ref vaProxy);
                    LastStarSystem = EDDI.Instance.LastStarSystem;
                }
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to set last system", ex);
            }

            try
            {
                if (EDDI.Instance.SquadronStarSystem != SquadronStarSystem)
                {
                    setStarSystemValues(EDDI.Instance.SquadronStarSystem, "Squadron system", ref vaProxy);
                    SquadronStarSystem = EDDI.Instance.SquadronStarSystem;
                }
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to set last system", ex);
            }

            try
            {
                if (EDDI.Instance.CurrentStellarBody != CurrentStellarBody)
                {
                    setDetailedBodyValues(EDDI.Instance.CurrentStellarBody, "Body", ref vaProxy);
                    CurrentStellarBody = EDDI.Instance.CurrentStellarBody;
                }
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to set stellar body", ex);
            }

            try
            {
                if (EDDI.Instance.CurrentStation != CurrentStation)
                {
                    setStationValues(EDDI.Instance.CurrentStation, "Last station", ref vaProxy);
                    CurrentStation = EDDI.Instance.CurrentStation;
                }
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to set last station", ex);
            }

            try
            {
                CargoMonitor cargoMonitor = ((CargoMonitor)EDDI.Instance.ObtainMonitor("Cargo monitor"));
                vaProxy.SetInt("Ship cargo carried", cargoMonitor?.cargoCarried ?? 0);
                vaProxy.SetInt("Ship limpets carried", cargoMonitor?.GetCargoWithEDName("Drones")?.total ?? 0);
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to set ship cargo values", ex);
            }

            try
            {
                ShipMonitor shipMonitor = ((ShipMonitor)EDDI.Instance.ObtainMonitor("Ship monitor"));

                try
                {
                    if (shipMonitor?.GetCurrentShip() != Ship)
                    {
                        setShipValues(shipMonitor?.GetCurrentShip(), "Ship", ref vaProxy);
                        Ship = shipMonitor.GetCurrentShip();
                    }
                }
                catch (Exception ex)
                {
                    Logging.Error("Failed to set current ship values", ex);
                }

                try
                {
                    if (shipMonitor?.shipyard != Shipyard)
                    {
                        List <Ship> shipyard = new List <Ship>(shipMonitor?.shipyard);
                        if (shipyard != null)
                        {
                            int currentStoredShip = 1;
                            foreach (Ship StoredShip in shipyard)
                            {
                                setShipValues(StoredShip, "Stored ship " + currentStoredShip, ref vaProxy);
                                currentStoredShip++;
                            }
                            vaProxy.SetInt("Stored ship entries", shipMonitor?.shipyard.Count);
                        }
                        Shipyard = shipMonitor.shipyard;
                    }
                }
                catch (Exception ex)
                {
                    Logging.Error("Failed to set shipyard", ex);
                }
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to obtain ship monitor & set VoiceAttack values", ex);
            }

            try
            {
                if (EDDI.Instance.HomeStarSystem != HomeStarSystem)
                {
                    setStarSystemValues(EDDI.Instance.HomeStarSystem, "Home system", ref vaProxy);
                    HomeStarSystem = EDDI.Instance.HomeStarSystem;

                    // Backwards-compatibility with 1.x
                    try
                    {
                        if (EDDI.Instance.HomeStarSystem != null)
                        {
                            vaProxy.SetText("Home system", EDDI.Instance.HomeStarSystem.name);
                            vaProxy.SetText("Home system (spoken)", Translations.StarSystem(EDDI.Instance.HomeStarSystem.name));
                        }
                        if (EDDI.Instance.HomeStation != null)
                        {
                            vaProxy.SetText("Home station", EDDI.Instance.HomeStation.name);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Error("Failed to set 1.x home system values", ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to set home system", ex);
            }

            try
            {
                Status currentStatus = ((StatusMonitor)EDDI.Instance.ObtainMonitor("Status monitor"))?.GetStatus();
                if (currentStatus != Status)
                {
                    setStatusValues(StatusMonitor.currentStatus, "Status", ref vaProxy);
                    Status = currentStatus;
                }
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to set current status", ex);
            }

            try
            {
                // Set SetState values
                if (EDDI.Instance.State != State)
                {
                    setDictionaryValues(EDDI.Instance.State, "state", ref vaProxy);
                    State = EDDI.Instance.State;
                }
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to set state", ex);
            }

            try
            {
                if (EDDI.Instance.Cmdr != Commander)
                {
                    setCommanderValues(EDDI.Instance.Cmdr, ref vaProxy);
                    Commander = EDDI.Instance.Cmdr;
                }
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to set commander values", ex);
            }

            // On every event...
            // Set miscellaneous values
            try
            {
                vaProxy.SetText("Environment", EDDI.Instance.Environment);
                vaProxy.SetText("Vehicle", EDDI.Instance.Vehicle);
                vaProxy.SetText("EDDI version", Constants.EDDI_VERSION.ToString());
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to set misc values", ex);
            }
        }