Example #1
0
        private void OnEffectQuery(CurrencyModifierQuery qry)
        {
            // Check the reason is a match
            if (qry.reason != TransactionReasons.StrategySetup)
            {
                return;
            }

            if (lastActivationRequest != this || conflictStrategy == null)
            {
                return;
            }

            if (Math.Abs(qry.GetInput(Currency.Funds)) >= 0.01)
            {
                float fundsDiscount = Math.Min(InitialCostFunds, conflictStrategy.InitialCostFunds);
                qry.AddDelta(Currency.Funds, fundsDiscount);
            }

            if (Math.Abs(qry.GetInput(Currency.Science)) >= 0.01)
            {
                float scienceDiscount = Math.Min(InitialCostScience, conflictStrategy.InitialCostScience);
                qry.AddDelta(Currency.Science, scienceDiscount);
            }

            if (Math.Abs(qry.GetInput(Currency.Reputation)) >= 0.01)
            {
                float reputationDiscount = Math.Min(InitialCostReputation, conflictStrategy.InitialCostReputation);
                qry.AddDelta(Currency.Reputation, reputationDiscount);
            }
        }
Example #2
0
        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));
            }
        }
        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));
            }
        }
Example #4
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;
                }
            }
        }
        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);
                }
            }
        }
Example #6
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());
        }
        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);
                }
            }
        }
Example #8
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 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)
        {
            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;
                }
            }
        }
        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));
            }
        }
        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)
        {
            // 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));
            }
        }