Last active
April 18, 2016 17:35
-
-
Save StollD/a1fe3c1e1687d602d145729b75420fa4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Reflection; | |
using System.Linq; | |
using UnityEngine; | |
using KSP.UI.Screens; | |
/// <summary> | |
/// Makes the funds you get from a recovered vessel negative | |
/// </summary> | |
public class FundsHaxxor : MonoBehaviour | |
{ | |
/// <summary> | |
/// Create callbacks | |
/// </summary> | |
void Start() | |
{ | |
GameEvents.onVesselRecoveryProcessing.Add(onVesselRecoveryProcessing); | |
DontDestroyOnLoad(this); | |
} | |
/// <summary> | |
/// Determines whether the vessel should get it's funds haxxored | |
/// </summary> | |
protected virtual bool IsHaXXor(ProtoVessel vessel) | |
{ | |
return false; /// Implement your check here | |
} | |
void onVesselRecoveryProcessing(ProtoVessel vessel, MissionRecoveryDialog dialog, float recoveryScore) | |
{ | |
if (vessel == null) | |
return; | |
if (!IsHaXXor(vessel)) | |
return; | |
if (Funding.Instance == null) | |
return; /// Put the money under your pillow | |
double funds = 0.0; | |
foreach (ProtoPartSnapshot snapshot in vessel.protoPartSnapshots) | |
{ | |
AvailablePart partInfo = PartLoader.getPartInfoByName(snapshot.partInfo.name); | |
if (partInfo != null) | |
{ | |
float dryCost, fuelCost; | |
ShipConstruction.GetPartCosts(snapshot, partInfo, out dryCost, out fuelCost); | |
dryCost *= recoveryScore; | |
fuelCost *= recoveryScore; | |
funds += dryCost + fuelCost; | |
} | |
} | |
funds *= -2; /// I am too lazy to prevent stock from adding the value, so I just remove it before it can add it | |
if (dialog != null) | |
{ | |
dialog.fundsEarned = funds; | |
} | |
typeof(Funding).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).First(f => f.FieldType == typeof(double)).SetValue(Funding.Instance, Funding.Instance.Funds + funds); | |
CurrencyModifierQuery data = new CurrencyModifierQuery(TransactionReasons.VesselRecovery, (float)funds, 0f, 0f); | |
GameEvents.Modifiers.OnCurrencyModifierQuery.Fire(data); | |
GameEvents.Modifiers.OnCurrencyModified.Fire(data); | |
GameEvents.OnFundsChanged.Fire(Funding.Instance.Funds, TransactionReasons.VesselRecovery); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment