Esempio n. 1
0
 private void HandleVessel(Vessel vessel)
 {
     // Update the level for all crew in the vessel
     foreach (ProtoCrewMember pcm in VesselUtil.GetVesselCrew(vessel))
     {
         HandleCrew(pcm);
     }
 }
        private void OnEffectQuery(CurrencyModifierQuery qry)
        {
            // Check the reason is a match
            if (!affectReasons.Contains(qry.reason))
            {
                return;
            }

            // Check if it's non-zero
            float total = 0.0f;

            foreach (Currency currency in currencies)
            {
                total += Math.Abs(qry.GetInput(currency));
            }
            if (total < 0.01f)
            {
                return;
            }

            // Figure out the vessel to look at
            Vessel vessel = null;

            if (FlightGlobals.ActiveVessel != null)
            {
                vessel = FlightGlobals.ActiveVessel;
            }
            else if (cachedVessel != null && cacheTime < Time.fixedTime + 5.0f)
            {
                vessel = cachedVessel;
            }

            // Check for matching crew
            if (vessel != null)
            {
                bool crewFound = false;
                foreach (ProtoCrewMember pcm in VesselUtil.GetVesselCrew(vessel))
                {
                    if (pcm.experienceTrait.Config.Name == trait)
                    {
                        crewFound = true;
                        break;
                    }
                }
                if (!crewFound)
                {
                    return;
                }
            }

            float multiplier = Parent.GetLeveledListItem(multipliers);

            foreach (Currency currency in currencies)
            {
                qry.AddDelta(currency, multiplier * qry.GetInput(currency) - qry.GetInput(currency));
            }
        }
Esempio n. 3
0
        private void OnEffectQuery(CurrencyModifierQuery qry)
        {
            scienceDelta = 0.0f;

            // Check the reason is a match
            if (!affectReasons.Contains(qry.reason))
            {
                return;
            }

            // Check if it's non-zero
            float total = 0.0f;

            foreach (Currency currency in currencies)
            {
                total += Math.Abs(qry.GetInput(currency));
            }
            if (total < 0.01f)
            {
                return;
            }

            // Figure out the vessel to look at
            Vessel vessel = null;

            if (FlightGlobals.ActiveVessel != null)
            {
                vessel = FlightGlobals.ActiveVessel;
            }
            else if (cachedVessel != null && cacheTime < Time.fixedTime + 5.0f)
            {
                vessel = cachedVessel;
            }

            // Check for matching crew
            if (vessel != null)
            {
                if (VesselUtil.GetVesselCrew(vessel).Any())
                {
                    return;
                }
            }

            float multiplier = Parent.GetLeveledListItem(multipliers);

            foreach (Currency currency in currencies)
            {
                float amount = multiplier * qry.GetInput(currency) - qry.GetInput(currency);
                qry.AddDelta(currency, amount);

                if (qry.reason == TransactionReasons.ScienceTransmission && currency == Currency.Science)
                {
                    scienceDelta = amount;
                }
            }
        }
Esempio n. 4
0
 private void OnVesselRecovered(ProtoVessel vessel, bool quick)
 {
     foreach (ProtoCrewMember pcm in VesselUtil.GetVesselCrew(vessel.vesselRef))
     {
         // Award the media star XP for each planet landed on
         foreach (string target in pcm.flightLog.Entries.
                  Where(fle => fle.type == FlightLog.EntryType.Land.ToString()).
                  Select(fle => fle.target).ToList())
         {
             pcm.flightLog.AddEntry(MEDIA_STAR_XP, target);
         }
     }
 }
Esempio n. 5
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;
        }
Esempio n. 6
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;
        }
Esempio n. 7
0
        private void OnEffectQuery(CurrencyModifierQuery qry)
        {
            // Check the reason is a match
            if (!affectReasons.Contains(qry.reason))
            {
                return;
            }

            // Check if it's non-zero
            float total = 0.0f;

            foreach (Currency currency in currencies)
            {
                total += Math.Abs(qry.GetInput(currency));
            }
            if (total < 0.01f)
            {
                return;
            }

            float funds   = qry.GetInput(Currency.Funds);
            float science = qry.GetInput(Currency.Science);
            float rep     = qry.GetInput(Currency.Reputation);

            string hash = string.Join("|", new string[] {
                funds.ToString(),
                science.ToString(),
                rep.ToString(),
                qry.reason.ToString()
            });

            // Check whether the contract matches the multiplier
            if (!contractCache.ContainsKey(hash))
            {
                bool     foundMatch = false;
                Contract match      = null;
                foreach (Contract contract in ContractSystem.Instance.Contracts.
                         Where(c => c.ContractState != Contract.State.Completed || c.DateFinished == Planetarium.fetch.time || c.DateFinished == 0.0))
                {
                    // If the contract type doesn't match, don't bother
                    if (!ContractTypeMatches(contract))
                    {
                        continue;
                    }

                    string hash2 = string.Join("|", new string[] {
                        contract.FundsCompletion.ToString(),
                        contract.ScienceCompletion.ToString(),
                        contract.ReputationCompletion.ToString(),
                        TransactionReasons.ContractReward.ToString()
                    });
                    // Check contract values - allow zero values because on reward funds/science/rep all come in seperately
                    if (qry.reason == TransactionReasons.ContractAdvance &&
                        contract.FundsAdvance == funds && science == 0.0 && rep == 0.0 ||
                        qry.reason == TransactionReasons.ContractPenalty &&
                        contract.FundsFailure == funds && science == 0.0 && contract.ReputationFailure == rep ||
                        qry.reason == TransactionReasons.ContractReward &&
                        (contract.FundsCompletion == funds || funds == 0) && (contract.ScienceCompletion == science || (int)science == 0) && (contract.ReputationCompletion == rep || (int)rep == 0))
                    {
                        foundMatch = true;
                        match      = contract;
                        break;
                    }

                    // Check parameter values
                    foreach (ContractParameter parameter in contract.AllParameters)
                    {
                        if (qry.reason == TransactionReasons.ContractPenalty &&
                            parameter.FundsFailure == funds && science == 0.0 && parameter.ReputationFailure == rep ||
                            qry.reason == TransactionReasons.ContractReward &&
                            (parameter.FundsCompletion == funds || funds == 0.0) && (parameter.ScienceCompletion == science || science == 0.0) && (parameter.ReputationCompletion == rep || rep == 0.0))
                        {
                            foundMatch = true;
                            match      = contract;
                            break;
                        }
                    }
                }

                contractCache[hash] = new KeyValuePair <bool, Contract>(foundMatch, match);
            }
            if (!contractCache[hash].Key)
            {
                return;
            }

            // Figure out the vessel to look at
            Vessel vessel = null;

            if (FlightGlobals.ActiveVessel != null)
            {
                vessel = FlightGlobals.ActiveVessel;
            }
            else if (cachedVessel != null && cacheTime < Time.fixedTime + 5.0f)
            {
                vessel = cachedVessel;
            }

            // Check for matching crew
            if (vessel != null && trait != null)
            {
                bool crewFound = false;
                foreach (ProtoCrewMember pcm in VesselUtil.GetVesselCrew(vessel))
                {
                    if (pcm.experienceTrait.Config.Name == trait)
                    {
                        crewFound = true;
                        break;
                    }
                }
                if (!crewFound)
                {
                    return;
                }
            }

            float multiplier = Parent.GetLeveledListItem(multipliers);

            foreach (Currency currency in currencies)
            {
                qry.AddDelta(currency, multiplier * qry.GetInput(currency) - qry.GetInput(currency));
            }
        }
Esempio n. 8
0
        private void HandleVessel(Vessel vessel)
        {
            if (vessel == null)
            {
                return;
            }

            Debug.Log("Strategia: VesselValueImprover.HandleVessel");

            // Check for our trait
            bool needsIncrease = false;

            foreach (ProtoCrewMember pcm in VesselUtil.GetVesselCrew(vessel))
            {
                if (pcm.experienceTrait.Config.Name == trait)
                {
                    needsIncrease = true;
                    break;
                }
            }

            // Find all relevant parts
            foreach (Part p in vessel.parts)
            {
                foreach (PartModule m in p.Modules)
                {
                    switch (attribute)
                    {
                    case Attribute.ISP:
                        ModuleEngines engine = m as ModuleEngines;
                        if (engine != null)
                        {
                            FloatCurve curve = engine.atmosphereCurve;
                            ConfigNode node  = new ConfigNode();
                            curve.Save(node);

                            // Find and adjust the vacuum ISP
                            ConfigNode newNode = new ConfigNode();
                            foreach (ConfigNode.Value pair in node.values)
                            {
                                string[] values = pair.value.Split(new char[] { ' ' });
                                if (values[0] == "0")
                                {
                                    float value    = float.Parse(values[1]);
                                    float oldValue = value;
                                    SetValue(p.partInfo.name + "|" + engine.engineID, needsIncrease, ref value);
                                    values[1] = value.ToString("F1");
                                    newNode.AddValue(pair.name, string.Join(" ", values));
                                    Debug.Log("Setting ISP of " + p + " from " + oldValue + " to " + value);
                                }
                                else
                                {
                                    newNode.AddValue(pair.name, pair.value);
                                }
                            }
                            curve.Load(newNode);
                            engine.realIsp = curve.Evaluate(0);
                        }
                        break;

                    case Attribute.ParachuteDrag:
                        ModuleParachute parachute = m as ModuleParachute;
                        if (parachute != null)
                        {
                            SetValue(p.partName, needsIncrease, ref parachute.fullyDeployedDrag);
                        }
                        break;

                    case Attribute.StrutStrength:
                        CModuleStrut strut = m as CModuleStrut;
                        if (strut != null)
                        {
                            SetValue(p.partName + "_linear", needsIncrease, ref strut.linearStrength);
                            SetValue(p.partName + "_angular", needsIncrease, ref strut.angularStrength);
                        }
                        break;

                    case Attribute.ReactionWheelTorque:
                        ModuleReactionWheel reactionWheel = m as ModuleReactionWheel;
                        if (reactionWheel != null)
                        {
                            SetValue(p.partName + "_pitch", needsIncrease, ref reactionWheel.PitchTorque);
                            SetValue(p.partName + "_yaw", needsIncrease, ref reactionWheel.YawTorque);
                            SetValue(p.partName + "_roll", needsIncrease, ref reactionWheel.RollTorque);
                        }
                        break;
                    }
                }
            }
        }