private void OnKerbalTypeChange(ProtoCrewMember pcm, ProtoCrewMember.KerbalType oldType, ProtoCrewMember.KerbalType newType) { if (oldType == ProtoCrewMember.KerbalType.Applicant && newType == ProtoCrewMember.KerbalType.Crew) { // Check for correct trait if (!string.IsNullOrEmpty(trait) && pcm.experienceTrait.Config.Name != trait) { return; } // Check for correct gender if (gender != null && pcm.gender != gender.Value) { return; } CelestialBody homeworld = FlightGlobals.Bodies.Where(cb => cb.isHomeWorld).FirstOrDefault(); Debug.Log("Strategia: Awarding experience to " + pcm.name); // Find existing entries int currentValue = 2; foreach (FlightLog.Entry entry in pcm.careerLog.Entries.Concat(pcm.flightLog.Entries).Where(e => e.type.Contains(SPECIAL_XP))) { // Get the entry with the largest value int entryValue = Convert.ToInt32(entry.type.Substring(SPECIAL_XP.Length, entry.type.Length - SPECIAL_XP.Length)); currentValue = Math.Max(currentValue, entryValue); } // Get the experience level int value = Parent.Level(); string type = SPECIAL_XP + value.ToString(); // Do the awarding pcm.flightLog.AddEntry(type, homeworld.name); pcm.ArchiveFlightLog(); // Force the astronaut complex GUI to refresh so we actually see the experience AstronautComplex ac = UnityEngine.Object.FindObjectOfType <AstronautComplex>(); if (ac != null) { Debug.Log("NewKerbalExperience: CreateAvailableList"); MethodInfo updateListMethod = typeof(AstronautComplex).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance). Where(mi => mi.Name == "CreateAvailableList").First(); updateListMethod.Invoke(ac, new object[] { }); Debug.Log("NewKerbalExperience: AddItem_Available"); MethodInfo addToListMethod = typeof(AstronautComplex).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance). Where(mi => mi.Name == "AddItem_Available").First(); addToListMethod.Invoke(ac, new object[] { pcm }); } } }
void Update() { AstronautComplex ac = GameObject.FindObjectOfType <AstronautComplex>(); if (ac != null) { if (ac.ScrollListApplicants.Count > 0) { Hire.Log.Info("TRP: Clearing Applicant List"); ac.ScrollListApplicants.Clear(true); } } }
internal static int crewLimit(this AstronautComplex complex) { FieldInfo crewLimit = typeof(AstronautComplex).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(k => k.Name == "crewLimit"); try { return((int)crewLimit.GetValue(complex)); } catch { return(int.MaxValue); } }
private void FixAstronauComplexUI() { if (_astronautComplex == null) { AstronautComplex[] mbs = FindObjectsOfType <AstronautComplex>(); int maxCount = -1; foreach (AstronautComplex c in mbs) { int count = c.ScrollListApplicants.Count + c.ScrollListAssigned.Count + c.ScrollListAvailable.Count + c.ScrollListKia.Count; if (count > maxCount) { maxCount = count; _astronautComplex = c; } } if (_astronautComplex == null) { return; } } int newAv = _astronautComplex.ScrollListAvailable.Count; int newAsgn = _astronautComplex.ScrollListAssigned.Count; int newKIA = _astronautComplex.ScrollListKia.Count; if (newAv != _countAvailable || newKIA != _countKIA || newAsgn != _countAssigned) { _countAvailable = newAv; _countAssigned = newAsgn; _countKIA = newKIA; foreach (UIListData <UIListItem> u in _astronautComplex.ScrollListAvailable) { CrewListItem cli = u.listItem.GetComponent <CrewListItem>(); if (cli == null) { continue; } FixTooltip(cli); if (cli.GetCrewRef().inactive) { cli.MouseoverEnabled = false; bool notTraining = true; for (int i = ActiveCourses.Count; i-- > 0 && notTraining;) { foreach (ProtoCrewMember pcm in ActiveCourses[i].Students) { if (pcm == cli.GetCrewRef()) { notTraining = false; cli.SetLabel("Training, done " + KSPUtil.PrintDate(ActiveCourses[i].startTime + ActiveCourses[i].GetTime(ActiveCourses[i].Students), false)); break; } } } if (notTraining) { cli.SetLabel("Recovering"); } } } foreach (UIListData <UIListItem> u in _astronautComplex.ScrollListAssigned) { CrewListItem cli = u.listItem.GetComponent <CrewListItem>(); if (cli != null) { FixTooltip(cli); } } foreach (UIListData <UIListItem> u in _astronautComplex.ScrollListKia) { CrewListItem cli = u.listItem.GetComponent <CrewListItem>(); if (cli != null) { if (_retirees.Contains(cli.GetName())) { cli.SetLabel("Retired"); cli.MouseoverEnabled = false; } } } } }
private void ACDespawn() { _inAC = false; _astronautComplex = null; }
internal static CrewListItem Get_widgetEnlisted(this AstronautComplex complex) { FieldInfo widgetEnlisted = typeof(AstronautComplex).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(f => f.Name == "widgetEnlisted"); return(widgetEnlisted.GetValue(complex) as CrewListItem); }