private void OnEffectQuery(CurrencyModifierQuery qry)
        {
            // Check the reason is a match
            if (!affectReasons.Contains(qry.reason) || !shipManned)
            {
                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 multiplier = Parent.GetLeveledListItem(multipliers);
            foreach (Currency currency in currencies)
            {
                qry.AddDelta(currency, multiplier * qry.GetInput(currency) - qry.GetInput(currency));
            }
        }
        protected override void OnEffectQuery(CurrencyModifierQuery qry)
        {
            // Check if it's for our body
            if (lastBody == null || !bodies.Contains(lastBody))
            {
                return;
            }

            base.OnEffectQuery(qry);
        }
        protected override void OnEffectQuery(CurrencyModifierQuery qry)
        {
            // Check if it's non-zero
            if (Math.Abs(qry.GetInput(Currency.Funds)) < 0.01 && Math.Abs(qry.GetInput(Currency.Science)) < 0.01 && Math.Abs(qry.GetInput(Currency.Reputation)) < 0.01)
            {
                return;
            }

            base.OnEffectQuery(qry);
        }
Beispiel #4
0
        private void CurrenciesModified(CurrencyModifierQuery query)
        {
            if (CareerEventScope.ShouldIgnore)
            {
                return;
            }

            float changeDelta = query.GetTotal(Currency.Funds);

            if (changeDelta != 0f)
            {
                FundsChanged(changeDelta, query.reason);
            }
        }
        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;
            }

            string hash = string.Join("|", new string[] {
                qry.GetInput(Currency.Funds).ToString("F0"),
                qry.GetInput(Currency.Science).ToString("F0"),
                qry.GetInput(Currency.Reputation).ToString("F0"),
                qry.reason.ToString()
            });

            // Get the multiplier
            float multiplier = 0.0f;

            if (!valueCache.ContainsKey(hash))
            {
                float lowerValue = Parent.GetLeveledListItem(lowerValues);
                float upperValue = Parent.GetLeveledListItem(upperValues);

                multiplier       = (float)(random.NextDouble() * (upperValue - lowerValue) + lowerValue);
                valueCache[hash] = multiplier;
            }
            multiplier = valueCache[hash];

            foreach (Currency currency in currencies)
            {
                float delta = (float)Math.Round(multiplier * qry.GetInput(currency) - qry.GetInput(currency));
                if (delta != 0.0f)
                {
                    qry.AddDelta(currency, delta);
                }
            }
        }
Beispiel #6
0
 private void OnCurrencyModified(CurrencyModifierQuery qry)
 {
     // Check for changes
     if (Math.Abs(fundsDelta) > 0.01)
     {
         CurrencyPopup.Instance.AddPopup(Currency.Funds, fundsDelta, qry.reason, Parent.Config.Title, true);
     }
     if (Math.Abs(reputationDelta) > 0.01)
     {
         CurrencyPopup.Instance.AddPopup(Currency.Reputation, reputationDelta, qry.reason, Parent.Config.Title, true);
     }
     if (Math.Abs(scienceDelta) > 0.01)
     {
         CurrencyPopup.Instance.AddPopup(Currency.Science, scienceDelta, qry.reason, Parent.Config.Title, true);
     }
 }
 private void OnCurrencyModified(CurrencyModifierQuery qry)
 {
     // Check for changes
     if (Math.Abs(fundsDelta) > 0.01)
     {
         CurrencyPopup.Instance.AddPopup(Currency.Funds, fundsDelta, qry.reason, Parent.Config.Title, true);
     }
     if (Math.Abs(reputationDelta) > 0.01)
     {
         CurrencyPopup.Instance.AddPopup(Currency.Reputation, reputationDelta, qry.reason, Parent.Config.Title, true);
     }
     if (Math.Abs(scienceDelta) > 0.01)
     {
         CurrencyPopup.Instance.AddPopup(Currency.Science, scienceDelta, qry.reason, Parent.Config.Title, true);
     }
 }
        protected override void OnEffectQuery(CurrencyModifierQuery qry)
        {
            if (qry.reason != TransactionReasons.StructureConstruction)
            {
                return;
            }

            fundsDelta      = qry.GetEffectDelta(Currency.Funds);
            reputationDelta = qry.GetEffectDelta(Currency.Reputation);
            scienceDelta    = qry.GetEffectDelta(Currency.Science);

            base.OnEffectQuery(qry);

            // Calculate any changes
            fundsDelta      = qry.GetEffectDelta(Currency.Funds) - fundsDelta;
            reputationDelta = qry.GetEffectDelta(Currency.Reputation) - reputationDelta;
            scienceDelta    = qry.GetEffectDelta(Currency.Science) - scienceDelta;
        }
Beispiel #9
0
        internal void paramPenalties(ContractParameter cP)
        {
            CurrencyModifierQuery currencyQuery = CurrencyModifierQuery.RunQuery(TransactionReasons.ContractPenalty, (float)cP.FundsFailure, 0f, cP.ReputationFailure);

            fundsPenalty  = cP.FundsFailure;
            fundsPen      = "- " + fundsPenalty.ToString("N0");
            fundsPenStrat = currencyQuery.GetEffectDelta(Currency.Funds);
            if (fundsPenStrat != 0f)
            {
                fundsPen = string.Format("- {0:N0} ({1:N0})", fundsPenalty + fundsPenStrat, fundsPenStrat);
            }
            repPenalty  = cP.ReputationFailure;
            repPen      = "- " + repPenalty.ToString("N0");
            repPenStrat = currencyQuery.GetEffectDelta(Currency.Reputation);
            if (repPenStrat != 0f)
            {
                repPen = string.Format("- {0:N0} ({1:N0})", repPenalty + repPenStrat, repPenStrat);
            }
        }
 void OnCurrencyModified(CurrencyModifierQuery qry)
 {
     if (qry.reason == TransactionReasons.StructureConstruction)
     {
         // Check for changes
         if (Math.Abs(fundsDelta) > 0.01)
         {
             CurrencyPopup.Instance.AddFacilityPopup(Currency.Funds, fundsDelta, qry.reason, Parent.Config.Title, true);
         }
         if (Math.Abs(reputationDelta) > 0.01)
         {
             CurrencyPopup.Instance.AddFacilityPopup(Currency.Reputation, reputationDelta, qry.reason, Parent.Config.Title, true);
         }
         if (Math.Abs(scienceDelta) > 0.01)
         {
             CurrencyPopup.Instance.AddFacilityPopup(Currency.Science, scienceDelta, qry.reason, Parent.Config.Title, true);
         }
     }
 }
Beispiel #11
0
 void OnCurrencyModified(CurrencyModifierQuery qry)
 {
     if (qry.reason == TransactionReasons.StructureConstruction)
     {
         AddFacilityPopup(Currency.Funds, qry.GetInput(Currency.Funds), qry.reason, "Upgrade", false);
     }
     else if (qry.reason == TransactionReasons.StructureRepair)
     {
         AddFacilityPopup(Currency.Funds, qry.GetInput(Currency.Funds), qry.reason, "Repair", false);
     }
     else if (qry.reason == TransactionReasons.CrewRecruited)
     {
         AddPopup(Currency.Funds, qry.GetInput(Currency.Funds), qry.reason, "Hiring Kerbal", false);
     }
     else if (qry.reason == TransactionReasons.ScienceTransmission)
     {
         AddPopup(Currency.Science, qry.GetInput(Currency.Science), qry.reason, "Science Transmission", false);
     }
 }
Beispiel #12
0
        private void contractAdvance()
        {
            CurrencyModifierQuery currencyQuery = CurrencyModifierQuery.RunQuery(TransactionReasons.ContractAdvance, (float)root.FundsAdvance, 0, 0);

            fundsAdv      = (float)root.FundsAdvance;
            fundsAdvStrat = currencyQuery.GetEffectDelta(Currency.Funds);

            if (fundsAdvStrat != 0)
            {
                fundsAdvString = string.Format("- {0:N0} ({1:N0})", fundsAdv + fundsAdvStrat, fundsAdvStrat);
            }
            else if (fundsAdv != 0)
            {
                fundsAdvString = fundsAdv.ToString("N0");
            }
            else
            {
                fundsAdvString = "";
            }
        }
Beispiel #13
0
        private void Upgrade()
        {
            var protoFacility = ProtoFacility;

            if (protoFacility.GetLevel() == protoFacility.GetLevelCount())
            {
                throw new KOSException("Facility is already max level");
            }

            var upgradeableFacility = protoFacility.facilityRefs[0];
            var upgradeCost         = upgradeableFacility.GetUpgradeCost();

            if (!CurrencyModifierQuery.RunQuery(TransactionReasons.StructureConstruction, -upgradeCost, 0f, 0f).CanAfford())
            {
                throw new KOSException("Insufficient funds");
            }

            Funding.Instance.AddFunds(-upgradeCost, TransactionReasons.StructureConstruction);
            upgradeableFacility.SetLevel(upgradeableFacility.FacilityLevel + 1);
        }
Beispiel #14
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 value = qry.GetInput(currency);

            if (Math.Abs(qry.GetInput(Currency.Funds)) < 0.01 &&
                Math.Abs(qry.GetInput(Currency.Science)) < 0.01 &&
                Math.Abs(qry.GetInput(Currency.Reputation)) < 0.01)
            {
                return;
            }

            // Calculate the delta
            qry.AddDelta(currency, CurrentMultiplier());
        }
Beispiel #15
0
        protected override void OnEffectQuery(CurrencyModifierQuery qry)
        {
            fundsDelta      = 0.0f;
            reputationDelta = 0.0f;
            scienceDelta    = 0.0f;

            // Check if it's non-zero
            if (Math.Abs(qry.GetInput(Currency.Funds)) < 0.01 && Math.Abs(qry.GetInput(Currency.Science)) < 0.01 && Math.Abs(qry.GetInput(Currency.Reputation)) < 0.01)
            {
                return;
            }

            fundsDelta      = qry.GetEffectDelta(Currency.Funds);
            reputationDelta = qry.GetEffectDelta(Currency.Reputation);
            scienceDelta    = qry.GetEffectDelta(Currency.Science);

            base.OnEffectQuery(qry);

            // Calculate any changes
            fundsDelta      = qry.GetEffectDelta(Currency.Funds) - fundsDelta;
            reputationDelta = qry.GetEffectDelta(Currency.Reputation) - reputationDelta;
            scienceDelta    = qry.GetEffectDelta(Currency.Science) - scienceDelta;
        }
Beispiel #16
0
        /// <summary>
        /// Fires every time a currency transaction is modified by a CurrencyModifierQuery object
        /// </summary>
        /// <param name="query">The object with all of the modification info</param>
        public void currencyModifiedEvent(CurrencyModifierQuery query)
        {
            BeanCounter.LogFormatted_DebugOnly("--------- currencyModifiedEvent ------------");

            BeanCounter.LogFormatted_DebugOnly("Currency modified! Reason: {0}, Funds {1:f2}, Science {2:f2}, Rep {3:f3}",
                                               query.reason.ToString(),
                                               query.GetEffectDelta(Currency.Funds),
                                               query.GetEffectDelta(Currency.Reputation),
                                               query.GetEffectDelta(Currency.Science)
                                               );

            //BeanCounter.LogFormatted_DebugOnly("Stack Trace: {0}", System.Environment.StackTrace);

            if (currencyModTime != HighLogic.CurrentGame.UniversalTime)
            {
                currencyModTime  = HighLogic.CurrentGame.UniversalTime;
                lastCurrencyMods = new List <CurrencyModifierQuery>();
            }

            lastCurrencyMods.Add(query);

            BeanCounter.LogFormatted_DebugOnly("-------- /currencyModifiedEvent ------------");
        }
        protected override void OnEffectQuery(CurrencyModifierQuery qry)
        {
            fundsDelta = 0.0f;
            reputationDelta = 0.0f;
            scienceDelta = 0.0f;

            // Check if it's non-zero
            if (Math.Abs(qry.GetInput(Currency.Funds)) < 0.01 && Math.Abs(qry.GetInput(Currency.Science)) < 0.01 && Math.Abs(qry.GetInput(Currency.Reputation)) < 0.01)
            {
                return;
            }

            fundsDelta = qry.GetEffectDelta(Currency.Funds);
            reputationDelta = qry.GetEffectDelta(Currency.Reputation);
            scienceDelta = qry.GetEffectDelta(Currency.Science);

            base.OnEffectQuery(qry);

            // Calculate any changes
            fundsDelta = qry.GetEffectDelta(Currency.Funds) - fundsDelta;
            reputationDelta = qry.GetEffectDelta(Currency.Reputation) - reputationDelta;
            scienceDelta = qry.GetEffectDelta(Currency.Science) - scienceDelta;
        }
Beispiel #18
0
        private void contractPenalties()
        {
            CurrencyModifierQuery currencyQuery = CurrencyModifierQuery.RunQuery(TransactionReasons.ContractPenalty, (float)root.FundsFailure, 0f, root.ReputationFailure);

            fundsPen      = (float)root.FundsFailure;
            fundsPenStrat = currencyQuery.GetEffectDelta(Currency.Funds);

            if (fundsPenStrat != 0)
            {
                fundsPenString = string.Format("- {0:N0} ({1:N0})", fundsPen + fundsPenStrat, fundsPenStrat);
            }
            else if (fundsPen != 0)
            {
                fundsPenString = "- " + fundsPen.ToString("N0");
            }
            else
            {
                fundsPenString = "";
            }

            repPen      = root.ReputationFailure;
            repPenStrat = currencyQuery.GetEffectDelta(Currency.Reputation);

            if (repPenStrat != 0)
            {
                repPenString = string.Format("- {0:N0} ({1:N0})", repPen + repPenStrat, repPenStrat);
            }
            else if (repPen != 0)
            {
                repPenString = "- " + repPen.ToString("N0");
            }
            else
            {
                repPenString = "";
            }
        }
Beispiel #19
0
 public void OnCurrencyModifiedHandler(CurrencyModifierQuery query)
 {
     this.AddTransaction(query);
 }
Beispiel #20
0
        /// <summary>
        /// Fires every time a currency transaction is modified by a CurrencyModifierQuery object
        /// </summary>
        /// <param name="query">The object with all of the modification info</param>
        public void currencyModifiedEvent(CurrencyModifierQuery query)
        {
            BeanCounter.LogFormatted_DebugOnly("--------- currencyModifiedEvent ------------");

            BeanCounter.LogFormatted_DebugOnly("Currency modified! Reason: {0}, Funds {1:f2}, Science {2:f2}, Rep {3:f3}",
                query.reason.ToString(),
                query.GetEffectDelta(Currency.Funds),
                query.GetEffectDelta(Currency.Reputation),
                query.GetEffectDelta(Currency.Science)
                );

            //BeanCounter.LogFormatted_DebugOnly("Stack Trace: {0}", System.Environment.StackTrace);

            if (currencyModTime != HighLogic.CurrentGame.UniversalTime)
            {
                currencyModTime = HighLogic.CurrentGame.UniversalTime;
                lastCurrencyMods = new List<CurrencyModifierQuery>();
            }

            lastCurrencyMods.Add(query);

            BeanCounter.LogFormatted_DebugOnly("-------- /currencyModifiedEvent ------------");
        }
Beispiel #21
0
        /// <summary>
        /// Checks if the "basic" requirements that shouldn't change due to expressions are met.
        /// </summary>
        /// <param name="contract">The contract</param>
        /// <returns>Whether the contract can be offered.</returns>
        public bool MeetBasicRequirements(ConfiguredContract contract)
        {
            LoggingUtil.LogLevel origLogLevel = LoggingUtil.logLevel;
            try
            {
                // Turn tracing on
                if (trace)
                {
                    LoggingUtil.logLevel = LoggingUtil.LogLevel.VERBOSE;
                    LoggingUtil.LogWarning(this, "Tracing enabled for contract type " + name);
                }

                // Check funding
                if (advanceFunds < 0)
                {
                    CurrencyModifierQuery q = new CurrencyModifierQuery(TransactionReasons.ContractAdvance, -advanceFunds, 0.0f, 0.0f);
                    GameEvents.Modifiers.OnCurrencyModifierQuery.Fire(q);
                    float fundsRequired = advanceFunds + q.GetEffectDelta(Currency.Funds);

                    if (!Funding.CanAfford(fundsRequired))
                    {
                        throw new ContractRequirementException("Can't afford contract advance cost.");
                    }
                }

                // Check expiry
                if ((contract.ContractState == Contract.State.Offered || contract.ContractState == Contract.State.Withdrawn) &&
                    Planetarium.fetch != null && contract.DateExpire < Planetarium.fetch.time)
                {
                    throw new ContractRequirementException("Expired contract.");
                }

                // Checks for maxSimultaneous/maxCompletions
                if (maxSimultaneous != 0 || maxCompletions != 0)
                {
                    IEnumerable <ConfiguredContract> contractList = ConfiguredContract.CurrentContracts.
                                                                    Where(c => c.contractType != null && c.contractType.name == name && c != contract);

                    // Check if we're breaching the active limit
                    int activeContracts = contractList.Count();
                    if (maxSimultaneous != 0 && activeContracts >= maxSimultaneous)
                    {
                        throw new ContractRequirementException("Too many active contracts.");
                    }

                    // Check if we're breaching the completed limit
                    if (maxCompletions != 0)
                    {
                        if (ActualCompletions() + activeContracts >= maxCompletions)
                        {
                            throw new ContractRequirementException("Too many completed/active/offered contracts.");
                        }
                    }
                }

                // Check the group values
                if (group != null)
                {
                    CheckContractGroup(contract, group);
                }

                return(true);
            }
            catch (ContractRequirementException e)
            {
                LoggingUtil.LogLevel level = contract.ContractState == Contract.State.Active ? LoggingUtil.LogLevel.INFO : contract.contractType != null ? LoggingUtil.LogLevel.DEBUG : LoggingUtil.LogLevel.VERBOSE;
                string prefix = contract.contractType != null ? "Cancelling contract of type " + name + " (" + contract.Title + "): " :
                                "Didn't generate contract of type " + name + ": ";
                LoggingUtil.Log(level, this.GetType(), prefix + e.Message);
                return(false);
            }
            catch
            {
                LoggingUtil.LogError(this, "Exception while attempting to check requirements of contract type " + name);
                throw;
            }
            finally
            {
                LoggingUtil.logLevel = origLogLevel;
                loaded = true;
            }
        }
        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;
            }

            string hash = string.Join("|", new string[]{
                qry.GetInput(Currency.Funds).ToString("F0"),
                qry.GetInput(Currency.Science).ToString("F0"),
                qry.GetInput(Currency.Reputation).ToString("F0"),
                qry.reason.ToString()
            });

            // Get the multiplier
            float multiplier = 0.0f;
            if (!valueCache.ContainsKey(hash))
            {
                float lowerValue = Parent.GetLeveledListItem(lowerValues);
                float upperValue = Parent.GetLeveledListItem(upperValues);

                multiplier = (float)(random.NextDouble() * (upperValue - lowerValue) + lowerValue);
                valueCache[hash] = multiplier;
            }
            multiplier = valueCache[hash];

            foreach (Currency currency in currencies)
            {
                float delta = (float)Math.Round(multiplier * qry.GetInput(currency) - qry.GetInput(currency));
                if (delta != 0.0f)
                {
                    qry.AddDelta(currency, delta);
                }
            }
        }
        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));
            }
        }
Beispiel #24
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));
            }
        }
 private void OnCurrencyModified(CurrencyModifierQuery qry)
 {
     if (Math.Abs(scienceDelta) > 0.01)
     {
         CurrencyPopup.Instance.AddPopup(Currency.Science, scienceDelta, qry.reason, Parent.Config.Title, true);
     }
 }
        private void OnEffectQuery(CurrencyModifierQuery qry)
        {
            // Check the reason is a match
            if (!affectReasons.Contains(qry.reason))
            {
                return;
            }

            // Check if it's non-zero
            float value = qry.GetInput(currency);
            if (Math.Abs(qry.GetInput(Currency.Funds)) < 0.01 &&
                Math.Abs(qry.GetInput(Currency.Science)) < 0.01 &&
                Math.Abs(qry.GetInput(Currency.Reputation)) < 0.01)
            {
                return;
            }

            // Calculate the delta
            qry.AddDelta(currency, CurrentMultiplier());
        }
        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));
            }
        }
        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;
                }
            }
        }
Beispiel #29
0
        internal void AddTransaction(CurrencyModifierQuery query)
        {
            CurrencyTransaction transaction = new CurrencyTransaction(Planetarium.GetUniversalTime(), query);

            this.AddTransaction(transaction);
        }
Beispiel #30
0
 void OnCurrencyModified(CurrencyModifierQuery qry)
 {
     if (qry.reason == TransactionReasons.StructureConstruction)
     {
         AddFacilityPopup(Currency.Funds, qry.GetInput(Currency.Funds), qry.reason, "Upgrade", false);
     }
     else if (qry.reason == TransactionReasons.StructureRepair)
     {
         AddFacilityPopup(Currency.Funds, qry.GetInput(Currency.Funds), qry.reason, "Repair", false);
     }
     else if (qry.reason == TransactionReasons.CrewRecruited)
     {
         AddPopup(Currency.Funds, qry.GetInput(Currency.Funds), qry.reason, "Hiring Kerbal", false);
     }
     else if (qry.reason == TransactionReasons.ScienceTransmission)
     {
         AddPopup(Currency.Science, qry.GetInput(Currency.Science), qry.reason, "Science Transmission", false);
     }
 }
        protected void MissionControlText(ContractType contractType)
        {
            string text = "<b><color=#DB8310>Briefing:</color></b>\n\n";

            // Special case for one-off contracts
            string description = contractType.genericDescription;
            if (contractType.maxCompletions == 1)
            {
                foreach (ConfiguredContract c in ConfiguredContract.CompletedContracts)
                {
                    if (c.contractType != null && c.contractType.name == contractType.name)
                    {
                        description = c.Description;
                        break;
                    }
                }
            }
            text += "<color=#CCCCCC>" + description + "</color>\n\n";

            text += "<b><color=#DB8310>Pre-Requisites:</color></b>\n\n";

            // Do text for funds
            if (contractType.advanceFunds < 0)
            {
                CurrencyModifierQuery q = new CurrencyModifierQuery(TransactionReasons.ContractAdvance, -contractType.advanceFunds, 0.0f, 0.0f);
                GameEvents.Modifiers.OnCurrencyModifierQuery.Fire(q);
                float fundsRequired = contractType.advanceFunds + q.GetEffectDelta(Currency.Funds);

                text += RequirementLine("Must have {0} funds for advance", Funding.CanAfford(fundsRequired));
            }

            // Do text for max completions
            if (contractType.maxCompletions != 0)
            {
                int completionCount = contractType.ActualCompletions();
                bool met = completionCount < contractType.maxCompletions;
                if (contractType.maxCompletions == 1)
                {
                    text += RequirementLine("Must not have been completed before", met);
                }
                else
                {
                    text += RequirementLine("May only be completed " + contractType.maxCompletions + " times", met,
                        "has been completed " + completionCount + " times");
                }
            }

            // Do check for group maxSimultaneous
            for (ContractGroup currentGroup = contractType.group; currentGroup != null; currentGroup = currentGroup.parent)
            {
                if (currentGroup.maxSimultaneous != 0)
                {
                    int count = currentGroup.CurrentContracts();
                    text += RequirementLine(string.Format("May only have {0} offered/active {1} contracts at a time",
                        currentGroup.maxSimultaneous, currentGroup.displayName, count), count < currentGroup.maxSimultaneous);
                }
            }

            // Do check of required values
            List<string> titles = new List<string>();
            Dictionary<string, bool> titlesMet = new Dictionary<string, bool>();
            foreach (KeyValuePair<string, ContractType.DataValueInfo> pair in contractType.dataValues)
            {
                string name = pair.Key;
                if (pair.Value.required && !contractType.dataNode.IsDeterministic(name) && !pair.Value.hidden && !pair.Value.IsIgnoredType())
                {
                    bool met = true;
                    try
                    {
                        contractType.CheckRequiredValue(name);
                    }
                    catch
                    {
                        met = false;
                    }

                    string title = string.IsNullOrEmpty(pair.Value.title) ? "Key " + name + " must have a value" : pair.Value.title;
                    if (titlesMet.ContainsKey(title))
                    {
                        titlesMet[title] &= met;
                    }
                    else
                    {
                        titlesMet[title] = met;
                        titles.Add(title);
                    }
                }
            }

            // Do the actual add
            foreach (string title in titles)
            {
                text += RequirementLine(title, titlesMet[title]);
            }

            // Force check requirements for this contract
            CheckRequirements(contractType.Requirements);

            // Do a Research Bodies check, if applicable
            if (Util.Version.VerifyResearchBodiesVersion() && contractType.targetBody != null)
            {
                text += ResearchBodyText(contractType);
            }

            text += ContractRequirementText(contractType.Requirements);

            MissionControl.Instance.contractText.text = text;
        }