Skip to content

Commit

Permalink
Allow setting repToConfidence in a PROGRAM which will use a different…
Browse files Browse the repository at this point in the history
… multiplier to rep than the default when paying confidence for optional contracts.
  • Loading branch information
NathanKell committed May 27, 2023
1 parent 7fcf710 commit 1096e17
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Source/Harmony/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ internal static bool Postfix_TextAward(ref string __result, string title, string
if (_contract == null)
return true;

if (Programs.ProgramHandler.Instance != null && Programs.ProgramHandler.Instance.IsContractOptional(_contract))
if (Programs.ProgramHandler.Instance != null && Programs.ProgramHandler.Instance.RepToConfidenceForContract(_contract) is float repToConf && repToConf > 0f)
{
var cmq = CurrencyModifierQueryRP0.RunQuery(TransactionReasonsRP0.ContractReward, 0d, 0d, 0d, _contract.ReputationCompletion * Programs.ProgramHandler.Settings.repToConfidence, 0d);
var cmq = CurrencyModifierQueryRP0.RunQuery(TransactionReasonsRP0.ContractReward, 0d, 0d, 0d, _contract.ReputationCompletion * repToConf, 0d);
value += $"<color={CurrencyModifierQueryRP0.CurrencyColor(CurrencyRP0.Confidence)}>{CurrencyModifierQueryRP0.SpriteString(CurrencyRP0.Confidence)} {cmq.GetTotal(CurrencyRP0.Confidence):N0} {cmq.GetEffectDeltaText(CurrencyRP0.Confidence, "N0", CurrencyModifierQuery.TextStyling.OnGUI)} </color>";
}
if (KerbalConstructionTime.PresetManager.Instance != null)
Expand Down
6 changes: 3 additions & 3 deletions Source/Harmony/ContractParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ 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.IsContractOptional(cc))
if (__instance.Root is ContractConfigurator.ConfiguredContract cc && Programs.ProgramHandler.Instance != null && Programs.ProgramHandler.Instance.RepToConfidenceForContract(cc) is float repToConf && repToConf > 0f)
{
var cmq = CurrencyModifierQueryRP0.RunQuery(TransactionReasonsRP0.ContractReward, 0d, 0d, 0d, _storedRep * Programs.ProgramHandler.Settings.repToConfidence, 0d);
var cmq = CurrencyModifierQueryRP0.RunQuery(TransactionReasonsRP0.ContractReward, 0d, 0d, 0d, _storedRep * repToConf, 0d);
message += $"<color={CurrencyModifierQueryRP0.CurrencyColor(CurrencyRP0.Confidence)}>{CurrencyModifierQueryRP0.SpriteString(CurrencyRP0.Confidence)} {cmq.GetTotal(CurrencyRP0.Confidence):N0} {cmq.GetEffectDeltaText(CurrencyRP0.Confidence, "N0", CurrencyModifierQuery.TextStyling.OnGUI)} </color>";
}
}
Expand All @@ -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.IsContractOptional(cc))
if (__instance.Root is ContractConfigurator.ConfiguredContract cc && Programs.ProgramHandler.Instance != null && Programs.ProgramHandler.Instance.RepToConfidenceForContract(cc) is float repToConf && repToConf > 0f)
{
_storedRep = __instance.ReputationCompletion;
}
Expand Down
5 changes: 5 additions & 0 deletions Source/Programs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public static double RepPenaltyPerYearLateCalc(Speed spd, double pen)
return pen * mult;
}

[Persistent(isPersistant = false)]
public float repToConfidence = -1f;
public float RepToConfidence => repToConfidence >= 0f ? repToConfidence : ProgramHandler.Settings.repToConfidence;

public List<string> programsToDisableOnAccept = new List<string>();

public List<string> optionalContracts = new List<string>();
Expand Down Expand Up @@ -186,6 +190,7 @@ public Program(Program toCopy) : this()
optionalContracts = toCopy.optionalContracts;
speed = toCopy.speed;
confidenceCosts = toCopy.confidenceCosts;
repToConfidence = toCopy.repToConfidence;
}

public override string ToString() => $"{name} ({(IsComplete ? "Complete" : IsActive ? "Active" : "Inactive")})";
Expand Down
11 changes: 6 additions & 5 deletions Source/Programs/ProgramHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,17 @@ internal void OnGUI()
}
}

public bool IsContractOptional(ConfiguredContract cc)
public float RepToConfidenceForContract(ConfiguredContract cc)
{
foreach (Program p in ActivePrograms)
{
if (p.optionalContracts.Contains(cc.contractType.name))
{
return true;
return p.RepToConfidence;
}
}

return false;
return 0f;
}

private void OnContractAccept(Contract data)
Expand Down Expand Up @@ -242,13 +242,14 @@ private IEnumerator ContractCompleteRoutine(Contract data)
KerbalConstructionTime.KerbalConstructionTimeData.Instance.Applicants += applicants;

// Handle Confidence
if (IsContractOptional(cc))
float repToConf = RepToConfidenceForContract(cc);
if (repToConf > 0f)
{
float rep = 0;
foreach (var param in cc.AllParameters)
if (param.Optional && param.ReputationCompletion > 0 && param.State == ParameterState.Complete)
rep += param.ReputationCompletion;
Confidence.Instance.AddConfidence(Settings.repToConfidence * (rep + data.ReputationCompletion), TransactionReasons.ContractReward);
Confidence.Instance.AddConfidence(repToConf * (rep + data.ReputationCompletion), TransactionReasons.ContractReward);
}
}
}
Expand Down

0 comments on commit 1096e17

Please sign in to comment.