protected void DoAwarding()
        {
            IEnumerable <ProtoCrewMember> awardees = crew.Union(kerbals.Where(k => k.pcm != null).Select(k => k.pcm));

            LoggingUtil.LogDebug(this, "Awarding {0} points to {1} crew member(s)", experience, awardees.Count());

            // Set the homeworld
            if (homeworld == null)
            {
                homeworld = FlightGlobals.Bodies.Where(cb => cb.isHomeWorld).FirstOrDefault();
            }

            foreach (ProtoCrewMember pcm in awardees.Where(pcm => pcm != null))
            {
                LoggingUtil.LogVerbose(this, "    Awarding experience to {0}", 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);
                }

                // Can't go above 64 special experience
                int value = Math.Min(currentValue + experience, 64);

                // Increment the entry's experience value
                string type = SPECIAL_XP + value.ToString();

                // Do the awarding
                pcm.flightLog.AddEntry(type, homeworld.name);
                if (pcm.rosterStatus != ProtoCrewMember.RosterStatus.Assigned)
                {
                    pcm.ArchiveFlightLog();
                }
                else if (awardImmediately)
                {
                    pcm.experience     += experience;
                    pcm.experienceLevel = KerbalRoster.CalculateExperienceLevel(pcm.experience);
                }
            }

            // Prevent duplicate awards
            crew.Clear();
        }
Beispiel #2
0
        private void HandleVessel(Vessel vessel)
        {
            // Get the level
            int level = Parent.GetLeveledListItem <int>(levels);

            // Update the level for all crew that match up
            foreach (ProtoCrewMember pcm in VesselUtil.GetVesselCrew(vessel).
                     Where(p =>
                           string.IsNullOrEmpty(trait) || p.experienceTrait.Config.Name == trait &&
                           gender == null || p.gender == gender
                           ))
            {
                pcm.experienceLevel = KerbalRoster.CalculateExperienceLevel(pcm.experience) + level;
            }

            return;
        }
        private void HandleCrew(ProtoCrewMember pcm)
        {
            // Get the level
            int level = Parent.GetLeveledListItem <int>(levels);

            if (string.IsNullOrEmpty(trait) || pcm.experienceTrait.Config.Name == trait &&
                gender == null || pcm.gender == gender)
            {
                // Crew portraits break down if they have to display more than five stars, complicating EVA immensely.
                // To prevent this, we have to limit the total level to 5.
                pcm.experienceLevel = Math.Min(KerbalRoster.CalculateExperienceLevel(pcm.experience) + level, 5);

                // Force an update of the portrait, if present
                if (pcm.KerbalRef != null)
                {
                    KerbalPortraitGallery.Instance.UpdatePortrait(pcm.KerbalRef);
                }
            }
        }
Beispiel #4
0
        private void HandleVessel(Vessel vessel)
        {
            // Get the level
            int level = Parent.GetLeveledListItem <int>(levels);

            // Update the level for all crew that match up
            foreach (ProtoCrewMember pcm in VesselUtil.GetVesselCrew(vessel).
                     Where(p =>
                           string.IsNullOrEmpty(trait) || p.experienceTrait.Config.Name == trait &&
                           gender == null || p.gender == gender
                           ))
            {
                // Crew portraits break down if they have to display more than five stars, complicating EVA immensely.
                // To prevent this, we have to limit the total level to 5.
                int newLevel = KerbalRoster.CalculateExperienceLevel(pcm.experience) + level;
                pcm.experienceLevel = newLevel > 5 ? 5 : newLevel;
            }

            return;
        }
Beispiel #5
0
        public void Training()
        {
            foreach (ProtoCrewMember crew in vessel.GetVesselCrew())
            {
                var thisCrew = crew;
                var oldLevel = crew.experienceLevel;
                var teacher  = GetTeacher(crew.experienceTrait.Title);
                //Teachers have to be a level higher than students
                if (teacher.experienceLevel > crew.experienceLevel)
                {
                    //Then, we simulate training by creating some new flights.
                    var maxLevel = GetSituationLevel();

                    foreach (var flight in teacher.careerLog.GetFlights())
                    {
                        if (crew.experienceLevel < maxLevel)
                        {
                            foreach (var logEntry in flight.Entries)
                            {
                                if (!crew.flightLog.HasEntry(logEntry.type, logEntry.target))
                                {
                                    if (logEntry.type != FlightLog.EntryType.PlantFlag.ToString())
                                    {
                                        crew.flightLog.AddEntry(logEntry.type, logEntry.target);
                                        crew.careerLog.AddEntry(logEntry.type, logEntry.target);
                                    }
                                }
                                crew.experience      = KerbalRoster.CalculateExperience(crew.flightLog);
                                crew.experienceLevel = KerbalRoster.CalculateExperienceLevel(crew.experience);
                            }
                        }
                    }
                    if (oldLevel < crew.experienceLevel)
                    {
                        string msg = string.Format("{0} trained to level {1} {2}", crew.name, crew.experienceLevel,
                                                   crew.experienceTrait.Title);
                        ScreenMessages.PostScreenMessage(msg, 5f, ScreenMessageStyle.UPPER_CENTER);
                    }
                }
            }
        }