diff --git a/Source/Harmony/Contract.cs b/Source/Harmony/Contract.cs index cd93c7c95f5..507476e7040 100644 --- a/Source/Harmony/Contract.cs +++ b/Source/Harmony/Contract.cs @@ -56,7 +56,7 @@ internal static bool Postfix_TextAward(ref string __result, string title, string if (_contract == null) return true; - if (Programs.ProgramHandler.Instance != null && Programs.ProgramHandler.Instance.RepToConfidenceForContract(_contract) is float repToConf && repToConf > 0f) + if (Programs.ProgramHandler.Instance != null && Programs.ProgramHandler.Instance.RepToConfidenceForContract(_contract, _isReward) is float repToConf && repToConf > 0f) { var cmq = CurrencyModifierQueryRP0.RunQuery(TransactionReasonsRP0.ContractReward, 0d, 0d, 0d, _contract.ReputationCompletion * repToConf, 0d); value += $"{CurrencyModifierQueryRP0.SpriteString(CurrencyRP0.Confidence)} {cmq.GetTotal(CurrencyRP0.Confidence):N0} {cmq.GetEffectDeltaText(CurrencyRP0.Confidence, "N0", CurrencyModifierQuery.TextStyling.OnGUI)} "; diff --git a/Source/Harmony/ContractParameter.cs b/Source/Harmony/ContractParameter.cs index 9a1098ce22b..9e185de0273 100644 --- a/Source/Harmony/ContractParameter.cs +++ b/Source/Harmony/ContractParameter.cs @@ -17,7 +17,7 @@ internal static void Prefix_SendStateMessage(ContractParameter __instance, ref s if (icon != MessageSystemButton.ButtonIcons.COMPLETE || !__instance.Optional) return; - if (__instance.Root is ContractConfigurator.ConfiguredContract cc && Programs.ProgramHandler.Instance != null && Programs.ProgramHandler.Instance.RepToConfidenceForContract(cc) is float repToConf && repToConf > 0f) + if (__instance.Root is ContractConfigurator.ConfiguredContract cc && Programs.ProgramHandler.Instance != null && Programs.ProgramHandler.Instance.RepToConfidenceForContract(cc, true) is float repToConf && repToConf > 0f) { var cmq = CurrencyModifierQueryRP0.RunQuery(TransactionReasonsRP0.ContractReward, 0d, 0d, 0d, _storedRep * repToConf, 0d); message += $"{CurrencyModifierQueryRP0.SpriteString(CurrencyRP0.Confidence)} {cmq.GetTotal(CurrencyRP0.Confidence):N0} {cmq.GetEffectDeltaText(CurrencyRP0.Confidence, "N0", CurrencyModifierQuery.TextStyling.OnGUI)} "; @@ -30,7 +30,7 @@ internal static void Prefix_AwardCompletion(ContractParameter __instance) { //KSP sets the rewards to 0 as part of this! //So we have to intercept and store the value. - if (__instance.Root is ContractConfigurator.ConfiguredContract cc && Programs.ProgramHandler.Instance != null && Programs.ProgramHandler.Instance.RepToConfidenceForContract(cc) is float repToConf && repToConf > 0f) + if (__instance.Root is ContractConfigurator.ConfiguredContract cc && Programs.ProgramHandler.Instance != null && Programs.ProgramHandler.Instance.RepToConfidenceForContract(cc, true) is float repToConf && repToConf > 0f) { _storedRep = __instance.ReputationCompletion; } diff --git a/Source/Programs/ProgramHandler.cs b/Source/Programs/ProgramHandler.cs index b1a7efcec98..cea3eca0903 100644 --- a/Source/Programs/ProgramHandler.cs +++ b/Source/Programs/ProgramHandler.cs @@ -215,7 +215,7 @@ internal void OnGUI() } } - public float RepToConfidenceForContract(ConfiguredContract cc) + public float RepToConfidenceForContract(ConfiguredContract cc, bool isAwarding) { foreach (Program p in ActivePrograms) { @@ -224,6 +224,17 @@ public float RepToConfidenceForContract(ConfiguredContract cc) return p.RepToConfidence; } } + if (isAwarding || cc.ContractState != Contract.State.Completed) + return 0f; + + // Since it's completed (and this is not part of the awarding step), check completed programs too. + foreach (Program p in CompletedPrograms) + { + if (p.optionalContracts.Contains(cc.contractType.name)) + { + return p.RepToConfidence; + } + } return 0f; } @@ -263,7 +274,7 @@ private IEnumerator ContractCompleteRoutine(Contract data) KerbalConstructionTime.KerbalConstructionTimeData.Instance.Applicants += applicants; // Handle Confidence - float repToConf = RepToConfidenceForContract(cc); + float repToConf = RepToConfidenceForContract(cc, true); if (repToConf > 0f) { float rep = 0;