Skip to content

Commit

Permalink
Split config cost query into a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Aug 14, 2024
1 parent 98243f2 commit 9c44ba1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Source/ModuleROHeatshield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ public bool IsConfigUnlocked(string configName)

public bool PurchaseConfig(PartUpgradeHandler.Upgrade upgd)
{
CurrencyModifierQuery cmq = CurrencyModifierQuery.RunQuery(TransactionReasons.RnDPartPurchase, -upgd.entryCost, 0, 0);
if (!cmq.CanAfford())
if (!CanAffordEntryCost(upgd.entryCost))
return false;

PartUpgradeManager.Handler.SetUnlocked(upgd.name, true);
Expand Down Expand Up @@ -464,7 +463,7 @@ private PartResource EnsureAblatorResource(string name)
}

/// <summary>
/// Called from RP0KCT
/// Called from RP-1
/// </summary>
/// <param name="validationError"></param>
/// <param name="canBeResolved"></param>
Expand Down Expand Up @@ -497,7 +496,7 @@ public virtual bool Validate(out string validationError, out bool canBeResolved,
}

/// <summary>
/// Called from RP0KCT
/// Called from RP-1
/// </summary>
/// <returns></returns>
public virtual bool ResolveValidationError()
Expand All @@ -508,6 +507,17 @@ public virtual bool ResolveValidationError()
return PurchaseConfig(upgd);
}

/// <summary>
/// NOTE: Harmony-patched from RP-1 to factor in unlock credit.
/// </summary>
/// <param name="cost"></param>
/// <returns></returns>
private static bool CanAffordEntryCost(float cost)
{
CurrencyModifierQuery cmq = CurrencyModifierQuery.RunQuery(TransactionReasons.RnDPartPurchase, -cost, 0, 0);
return cmq.CanAfford();
}

#endregion Custom Methods
}
}

0 comments on commit 9c44ba1

Please sign in to comment.