protected void EmptyEvaSuit(Part evaPart, Part container) { Log.Info("Emptying the EVA suit from " + evaPart.name + " to " + container.name); // Compute how much can be left in the container double capacity = container.Resources[Spares.Name].maxAmount - container.Resources[Spares.Name].amount; double deposit = Math.Min(evaPart.Resources[Spares.Name].amount, capacity); // Add it to the spares container and drain it from the EVA part container.RequestResource(Spares.Name, -deposit); // Once again, MC2 breaks the RequestResource on evaPart, but with the above checks, decrementing should work just fine instead, I think! -TrypChangeling //evaPart.RequestResource(Spares.Name, deposit); evaPart.Resources[Spares.Name].amount -= deposit; // GUI acknowledge try { DangIt.Broadcast(evaPart.protoModuleCrew[0].name + " has left " + deposit + " spares", false, 1f); } catch (Exception) // The kerbal reenters before this method is called: in that case, trying to get his name will throw an exception { DangIt.Broadcast("You left " + deposit + " spares", false, 1f); } ResourceDisplay.Instance.Refresh(); }
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); } }
public void Maintenance() { this.FailureLog("Initiating EVA maitenance"); Part evaPart = DangIt.FindEVAPart(); if (evaPart == null) { throw new Exception("ERROR: couldn't find an active EVA!"); } if (!CheckOutExperience(evaPart.protoModuleCrew[0])) { DangIt.Broadcast(evaPart.protoModuleCrew[0].name + " isn't really qualified for this...", true); return; } if (this.part.temperature > DangIt.Instance.CurrentSettings.GetMaxServicingTemp()) { DangIt.Broadcast("This is too hot to service right now", true); return; } // Check if he is carrying enough spares if (evaPart.Resources.Contains(Spares.Name) && evaPart.Resources[Spares.Name].amount >= this.MaintenanceCost) { this.FailureLog("Spare parts check: OK! Maintenance allowed allowed"); // Consume the spare parts // MC2 Breaks RequestResource, since amount is checked, simply decrement! Just like in SparesContainer! Whee! -TrypChangeling // evaPart.RequestResource(Spares.Name, this.MaintenanceCost); evaPart.Resources[Spares.Name].amount -= this.MaintenanceCost; // Distance between the kerbal's perks and the required perks, used to scale the maintenance bonus according to the kerbal's skills int expDistance = evaPart.protoModuleCrew[0].experienceLevel - this.PerksRequirementValue; //// The higher the skill gap, the higher the maintenance bonus //// The + 1 is there to makes it so that a maintenance bonus is always gained even when the perks match exactly this.DiscountAge(this.MaintenanceBonus * ((expDistance + 1) / 3)); DangIt.Broadcast("This should last a little longer now"); } else { this.FailureLog("Spare parts check: failed! Maintenance NOT allowed"); DangIt.Broadcast("You need " + this.MaintenanceCost + " spares to maintain this."); } }
/// <summary> /// Check if a kerbal is able to repair a part, /// factoring spares, perks, and additional conditions /// </summary> private bool CheckRepairConditions(Part evaPart) { bool allow = true; string reason = string.Empty; #region Amount of spare parts if (!evaPart.Resources.Contains(Spares.Name) || evaPart.Resources[Spares.Name].amount < this.RepairCost) { allow = false; reason = "not carrying enough spares"; DangIt.Broadcast("You need " + this.RepairCost + " spares to repair this.", true); } #endregion #region Part temperature if (this.part.temperature > DangIt.Instance.CurrentSettings.GetMaxServicingTemp()) { allow = false; reason = "part is too hot (" + part.temperature.ToString() + " degrees)"; DangIt.Broadcast("This is too hot to service right now", true); } #endregion if (!CheckOutExperience(evaPart.protoModuleCrew[0])) { allow = false; reason = "perks don't match requirements"; DangIt.Broadcast(evaPart.protoModuleCrew[0].name + " has no idea how to fix this...", true); } if (allow) { this.FailureLog("Repair allowed!"); } else { this.FailureLog("Repair NOT allowed. Reason: " + reason); } return(allow); }
protected void FillEvaSuit(Part evaPart, Part container) { // Check if the EVA part contains the spare parts resource: if not, add a new config node if (!evaPart.Resources.Contains(Spares.Name)) { Log.Info("The eva part doesn't contain spares, adding the config node"); ConfigNode node = new ConfigNode("RESOURCE"); node.AddValue("name", Spares.Name); node.AddValue("maxAmount", Spares.MaxEvaAmount); node.AddValue("amount", 0); evaPart.Resources.Add(node); } // Override maxAmount set by other mods (such as MC2) causing taking of parts to fail -TrypChangeling if (evaPart.Resources[Spares.Name].maxAmount < Spares.MaxEvaAmount) { evaPart.Resources[Spares.Name].maxAmount = Spares.MaxEvaAmount; } // Compute how much the kerbal can take double desired = Spares.MaxEvaAmount - evaPart.Resources[Spares.Name].amount; desired = Math.Min(desired, Spares.MinIncrement); double amountTaken = Math.Min(desired, container.Resources[Spares.Name].amount); // Take it from the container and add it to the EVA container.RequestResource(Spares.Name, amountTaken); // RequestResource is being overridden by MC2 for some reason - however, with above checks, simply incrementing the value should work... I think! - TrypChangeling // evaPart.RequestResource(Spares.Name, -amountTaken); evaPart.Resources[Spares.Name].amount += amountTaken; // GUI stuff DangIt.Broadcast(evaPart.vessel.GetVesselCrew().First().name + " has taken " + amountTaken + " spares", false, 1f); ResourceDisplay.Instance.Refresh(); }