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); } }
public void EvaRepair() { try { this.FailureLog("Initiating EVA repair"); // Get the EVA part (parts can hold resources) Part evaPart = DangIt.FindEVAPart(); if (evaPart == null) { throw new Exception("ERROR: couldn't find an active EVA!"); } // Check if the kerbal is able to perform the repair if (CheckRepairConditions(evaPart)) { this.DI_EvaRepair(); this.SetFailureState(false); DangIt.FlightLog(this.RepairMessage); //TODO: experience repair boni float intelligence = 1 - evaPart.protoModuleCrew[0].stupidity; float discountedCost = (float)Math.Round(RepairCost * (1 - UnityEngine.Random.Range(0f, intelligence))); float discount = RepairCost - discountedCost; this.FailureLog("Kerbal's intelligence: " + intelligence + ", discount: " + discount); // One more MC2 hack - TrypChangeling // evaPart.RequestResource(Spares.Name, discountedCost); evaPart.Resources[Spares.Name].amount -= discountedCost; ResourceDisplay.Instance.Refresh(); DangIt.Broadcast(this.RepairMessage, true); this.DiscountAge(this.RepairBonus); if (discount > 0) { DangIt.Broadcast(evaPart.protoModuleCrew[0].name + " was able to save " + discount + " spare parts"); } AlarmManager alarmManager = FindObjectOfType <AlarmManager>(); alarmManager.RemoveAllAlarmsForModule(this); //Remove alarms from this module RemoveBCRepaired(this.part); DisableAlarm(false); } } catch (Exception e) { OnError(e); } }