Esempio n. 1
0
        public void Inspect()
        {
            StringBuilder sb = new StringBuilder();

            List <FailureModule> failModules = part.Modules.OfType <FailureModule>().ToList();

            // The part doesn't have any failure module:
            // instead of a black message, return a placeholder
            if (failModules.Count == 0)
            {
                sb.AppendLine("This part seems to be as good as new");
            }
            else
            {
                foreach (FailureModule fm in failModules)
                {
                    fm.TimeOfLastInspection = DangIt.Now();     // set the time of inspection so that the module gains the inspection bonus
                    sb.AppendLine(fm.ScreenName + ":");
                    sb.AppendLine(fm.InspectionMessage());
                    sb.AppendLine("");
                }
            }

            DangIt.PostMessage("Inspection results",
                               sb.ToString(),
                               MessageSystemButton.MessageButtonColor.BLUE,
                               MessageSystemButton.ButtonIcons.MESSAGE,
                               overrideMute: true);
        }
Esempio n. 2
0
        public void Fail()
        {
            try
            {
                this.FailureLog("Initiating Fail()");

                // First, run the custom failure logic
                // The child class can refuse to fail in FailBegin()
                if (!this.DI_FailBegin())
                {
                    this.FailureLog(this.DebugName + " has not agreed to fail, failure aborted!");
                    return;
                }
                else
                {
                    this.FailureLog(this.DebugName + " has agreed to fail, failure allowed.");
                }

                // If control reaches this point, the child class has agreed to fail
                // Disable the part and handle the internal state and notifications

                this.DI_Disable();

                TimeWarp.SetRate(0, true);      // stop instantly
                this.SetFailureState(true);     // Sets the failure state, handles the events

                if (!this.Silent)
                {
                    DangIt.Broadcast(this.FailureMessage);
                    DangIt.PostMessage("Failure!",
                                       this.FailureMessage,
                                       MessageSystemButton.MessageButtonColor.RED,
                                       MessageSystemButton.ButtonIcons.ALERT);

                    AlarmManager alarmManager = FindObjectOfType <AlarmManager>();
                    if (alarmManager != null)
                    {
                        Logger.Info("alarmManager is not null");
                        alarmManager.AddAlarm(this, DangIt.Instance.CurrentSettings.GetSoundLoopsForPriority(Priority));
                        if (alarmManager.HasAlarmsForModule(this))
                        {
                            Logger.Info("Muting the alarm");
                            Events["MuteAlarms"].active    = true;
                            Events["MuteAlarms"].guiActive = true;
                        }
                    }
                    else
                    {
                        Logger.Info("alarmManager is null");
                    }
                }

                DangIt.FlightLog(this.FailureMessage);
            }
            catch (Exception e)
            {
                OnError(e);
            }
        }