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 (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); } }
public CurrencyTransaction(double timestamp, CurrencyModifierQuery query) : this( timestamp, query.reason, (float)((double)query.GetEffectDelta(Currency.Funds) + (double)query.GetInput(Currency.Funds)), query.GetEffectDelta(Currency.Science) + query.GetInput(Currency.Science), query.GetEffectDelta(Currency.Reputation) + query.GetInput(Currency.Reputation)) { }
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) { 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; } } }
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); }
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); } } }
/// <summary> /// Updates the research on the team's current part /// </summary> /// <returns>The amount of du added to the part this update.</returns> public float UpdateResearch(float normalizedTime, float currentPartData) { if (PartInResearch != "" && ResearchActive) { float pointsForTick = Points * normalizedTime * PartRnDRate; pointsForTick = Mathf.Min(pointsForTick, MaxData - currentPartData); float costForTick = Cost * normalizedTime * PartRnDCost; Log("Points " + pointsForTick + ", Cost " + costForTick); if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { CurrencyModifierQuery query = CurrencyModifierQuery.RunQuery(TransactionReasons.RnDPartPurchase, -costForTick, 0f, 0f); float totalCost = query.GetInput(Currency.Funds) + query.GetEffectDelta(Currency.Funds); Log("Total cost " + totalCost); if (totalCost < Funding.Instance.Funds) { Log("Subtracting cost..."); Funding.Instance.AddFunds(totalCost, TransactionReasons.RnDPartPurchase); return(pointsForTick); } else { return(0f); } } else { return(pointsForTick); } } return(0f); }
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); } }
private static float NextKerbalHireCost() { if (GameVariables.Instance == null || HighLogic.CurrentGame == null) { return(1.0f); } CurrencyModifierQuery currencyModifierQuery = CurrencyModifierQuery.RunQuery(TransactionReasons.CrewRecruited, -GameVariables.Instance.GetRecruitHireCost(HighLogic.CurrentGame.CrewRoster.GetActiveCrewCount()) * HighLogic.CurrentGame.Parameters.Career.FundsLossMultiplier, 0.0f, 0.0f); return(-(currencyModifierQuery.GetInput(Currency.Funds) + currencyModifierQuery.GetEffectDelta(Currency.Funds))); }
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()); }
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; }
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 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; } 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)); } }