public void EvaRepair() { try { this.Log("Initiating EVA repair"); // Get the EVA part (parts can hold resources) Part evaPart = DangIt.FindEVAPart(); if (evaPart == null) { DangIt.Broadcast("DangIt ERROR: couldn't find an active EVA!"); this.Log("ERROR: couldn't find an active EVA!"); return; } // Check if he is carrying enough spares if (evaPart.Resources.Contains(Spares.Name) && evaPart.Resources[Spares.Name].amount >= this.RepairCost) { this.Log("Spare parts check: OK! Repair allowed"); this.DI_EvaRepair(); this.SetFailureState(false); DangIt.FlightLog(this.RepairMessage); float intelligence = 1 - evaPart.vessel.GetVesselCrew().First().stupidity; float discountedCost = (float)Math.Round( RepairCost * (1 - UnityEngine.Random.Range(0f, intelligence)) ); float discount = RepairCost - discountedCost; this.Log("Kerbal's intelligence: " + intelligence + ", discount: " + discount); evaPart.RequestResource(Spares.Name, discountedCost); ResourceDisplay.Instance.Refresh(); DangIt.Broadcast(this.RepairMessage, true); DiscountAge(this.RepairBonus); if (discount > 0) { DangIt.Broadcast(evaPart.vessel.GetVesselCrew().First().name + " was able to save " + discount + " spare parts"); } } else { this.Log("Spare parts check: failed! Repair NOT allowed"); DangIt.Broadcast("You need " + this.RepairCost + " spares to repair this.", true); } DangIt.ResetShipGlow(this.part.vessel); } catch (Exception e) { OnError(e); } }
public void EvaRepair() { try { this.Log("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.Log("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"); } FindObjectOfType <AlarmManager>().RemoveAllAlarmsForModule(this); //Remove alarms from this module } DangIt.ResetShipGlow(this.part.vessel); } catch (Exception e) { OnError(e); } }
public void Fail() { try { this.Log("Initiating Fail()"); // First, run the custom failure logic // The child class can refuse to fail in FailBegin() if (!this.DI_FailBegin()) { this.Log(this.DebugName + " has not agreed to fail, failure aborted!"); return; } else { this.Log(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, handles the glow if (!this.Silent) { DangIt.Broadcast(this.FailureMessage); DangIt.PostMessage("Failure!", this.FailureMessage, MessageSystemButton.MessageButtonColor.RED, MessageSystemButton.ButtonIcons.ALERT); if (FindObjectOfType <AlarmManager>() != null) { FindObjectOfType <AlarmManager>().AddAlarm(this, DangIt.Instance.CurrentSettings.GetSoundLoopsForPriority(Priority)); if (FindObjectOfType <AlarmManager>().HasAlarmsForModule(this)) { Events ["MuteAlarms"].active = true; Events ["MuteAlarms"].guiActive = true; } } } DangIt.FlightLog(this.FailureMessage); } catch (Exception e) { OnError(e); } }
public void Fail() { try { this.Log("Initiating Fail()"); // First, run the custom failure logic // The child class can refuse to fail in FailBegin() if (!this.DI_FailBegin()) { this.Log(this.DebugName + " has not agreed to fail, failure aborted!"); return; } else { this.Log(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, handles the glow if (!this.Silent) { DangIt.Broadcast(this.FailureMessage); DangIt.PostMessage("Failure!", this.FailureMessage, MessageSystemButton.MessageButtonColor.RED, MessageSystemButton.ButtonIcons.ALERT); } DangIt.FlightLog(this.FailureMessage); } catch (Exception e) { OnError(e); } }