public bool PurchaseTL(string tUName, int tl, double multiplier) { if (TLUnlocked(tUName) >= tl) { return(false); } double tuCost = TLEntryCost(tUName) * multiplier; if (!HighLogic.CurrentGame.Parameters.Difficulty.BypassEntryPurchaseAfterResearch) { if (Funding.Instance.Funds < tuCost) { return(false); } Funding.Instance.AddFunds(-tuCost, TransactionReasons.RnDPartPurchase); } float sciCost = (float)(TLSciEntryCost(tUName) * multiplier); if (sciCost > 0f && ResearchAndDevelopment.Instance != null) { if (!ResearchAndDevelopment.CanAfford(sciCost)) { return(false); } ResearchAndDevelopment.Instance.AddScience(-sciCost, TransactionReasons.RnDPartPurchase); } SetTLUnlocked(tUName, tl); return(true); }
public bool PurchaseConfig(string cfgName) { if (ConfigUnlocked(cfgName)) { return(false); } double cfgCost = ConfigEntryCost(cfgName); if (!HighLogic.CurrentGame.Parameters.Difficulty.BypassEntryPurchaseAfterResearch) { if (Funding.Instance.Funds < cfgCost) { return(false); } Funding.Instance.AddFunds(-cfgCost, TransactionReasons.RnDPartPurchase); } float sciCost = (float)ConfigSciEntryCost(cfgName); if (sciCost > 0f && ResearchAndDevelopment.Instance != null) { if (!ResearchAndDevelopment.CanAfford(sciCost)) { return(false); } ResearchAndDevelopment.Instance.AddScience(-sciCost, TransactionReasons.RnDPartPurchase); } SetConfigUnlock(cfgName, true); return(true); }
private double sellScience(bool ret = false, bool retScience = false) { double sellScience; if (double.TryParse(sellBuyString, out sellScience)) { if (retScience) { return(sellScience); } double addFunding = sellScience * currentSettings.getDouble("conversionRate") / calcModifier(); if (ret) { return(addFunding); } if (!ResearchAndDevelopment.CanAfford((float)sellScience)) { sellBuyString = "0"; return(0); } ResearchAndDevelopment.Instance.AddScience((float)-sellScience, TransactionReasons.None); Utilities.Funding.addFunds(addFunding); sellBuyString = "0"; } return(0); }
private void OnSellScience() { if (value == 0) { return; } if (ResearchAndDevelopment.CanAfford(value)) { var funds = GetBuyValue(value); Funding.Instance.AddFunds(funds, TransactionReasons.None); ResearchAndDevelopment.Instance.AddScience(-value, TransactionReasons.None); } ScreenMessages.PostScreenMessage("Transaction complete. Pleasure doing business with you!"); scienceField.text = "0"; }
protected void drawTigerTeamRepairs(UnloadedQualitySummary qualitySummary) { bool canAffordScience = true; bool canAffordFunds = true; bool commNetEnabled = true; //Do we have a repair entry? If so, draw the progress. BARISRepairProject repairProject = BARISScenario.Instance.GetRepairProject(qualitySummary.vessel); if (repairProject != null) { GUILayout.Label("<color=white><b>" + Localizer.Format(BARISScenario.RepairTimeProgress) + "</b>" + string.Format("{0:f3}", repairProject.RepairProgress) + "%</color>"); return; } //Calculate repair costs qualitySummary.CalculateRepairCosts(); //If we don't then draw the repair costs and buttons. //Science cost to upgrade flight experience. GUILayout.BeginHorizontal(); if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER || HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX) { canAffordScience = ResearchAndDevelopment.CanAfford(qualitySummary.repairCostScience); if (canAffordScience) { GUILayout.Label("<color=white><b>" + Localizer.Format(BARISScenario.TestBenchScienceCost) + "</b>" + string.Format("{0:n2}", qualitySummary.repairCostScience) + "</color>"); } else { GUILayout.Label("<color=red><b>" + Localizer.Format(BARISScenario.TestBenchScienceCost) + "</b>" + string.Format("{0:n2}", qualitySummary.repairCostScience) + "</color>"); } } //Funds cost to upgrade flight experience. if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { canAffordFunds = Funding.CanAfford(qualitySummary.repairCostFunds); if (canAffordFunds) { GUILayout.Label("<color=white><b>" + Localizer.Format(BARISScenario.TestBenchFundsCost) + "</b>" + string.Format("{0:n2}", qualitySummary.repairCostFunds) + "</color>"); } else { GUILayout.Label("<color=red><b>" + Localizer.Format(BARISScenario.TestBenchFundsCost) + "</b>" + string.Format("{0:n2}", qualitySummary.repairCostFunds) + "</color>"); } } //CommNet status if (CommNet.CommNetScenario.CommNetEnabled) { commNetEnabled = qualitySummary.vessel.connection.IsConnectedHome; } //Time to attempt repair GUILayout.Label("<color=white><b>" + Localizer.Format(BARISScenario.RepairTimeCost) + "</b>" + string.Format("{0:n2}", qualitySummary.repairCostTime) + " " + Localizer.Format(BARISScenario.RepairTimeDays) + "</color>"); //Repair button if (GUILayout.Button(wrenchIcon, buttonOptions)) { //Can we afford the funds? if (!canAffordFunds) { BARISScenario.Instance.LogPlayerMessage(Localizer.Format(BARISScenario.TigerTeamNoFunds)); GUILayout.EndHorizontal(); return; } //Can we afford the science? else if (!canAffordScience) { GUILayout.EndHorizontal(); BARISScenario.Instance.LogPlayerMessage(Localizer.Format(BARISScenario.TigerTeamNoScience)); return; } //Do we have a CommNet connection? else if (!commNetEnabled) { GUILayout.EndHorizontal(); BARISScenario.Instance.LogPlayerMessage(Localizer.Format(BARISScenario.TigerTeamNoComm)); return; } //Deduct the costs if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { Funding.Instance.AddFunds(-qualitySummary.repairCostFunds, TransactionReasons.Any); } if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER || HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX) { ResearchAndDevelopment.Instance.AddScience(-qualitySummary.repairCostScience, TransactionReasons.Any); } //Register the new project registerRepairProject(qualitySummary); } GUILayout.EndHorizontal(); }
protected override void DrawWindowContents(int windowId) { float costScience = 0f; float costFunds = 0f; bool canAffordScience, canAffordFunds; if (qualityControlModules == null) { GUILayout.Label("<color=yellow><b>" + Localizer.Format(BARISScenario.TestBenchWarning) + "</b></color>"); return; } calculateCostsAndReliability(); //Get science cost costScience = scienceCost * experienceModifier; //Get funds cost costFunds = fundsCost * experienceModifier; //Reputation gives a discount: 20% * (current rep / 1000) //Only applies in career mode. if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { float reputation = BARISScenario.ReputationCostModifier * (Reputation.Instance.reputation / Reputation.RepRange); if (reputation > 0.0f) { costScience -= (costScience * reputation); costFunds -= (costFunds * reputation); } } //Part count & reliability GUILayout.Label("<color=white><b>" + Localizer.Format(BARISScenario.TestBenchPartCount) + "</b>" + qualityControlModules.Length + "</color>"); GUILayout.BeginScrollView(originPoint, infoPanelOptions); GUILayout.Label("<color=white><b> " + Localizer.Format(BARISScenario.TestBenchReliabilityBefore) + "</b>" + reliability + "/" + maxReliability + "</color>"); GUILayout.Label("<color=white><b> " + Localizer.Format(BARISScenario.TestBenchReliabilityAfter) + "</b>" + reliabilityAfter + "/" + maxReliabilityAfter + "</color>"); GUILayout.EndScrollView(); //Science cost to upgrade flight experience. if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER || HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX) { canAffordScience = ResearchAndDevelopment.CanAfford(costScience); GUILayout.BeginScrollView(originPoint, infoPanelOptions); GUILayout.BeginHorizontal(); if (GUILayout.Button(scienceIcon, buttonOptions) && canAffordScience) { ResearchAndDevelopment.Instance.AddScience(-costScience, TransactionReasons.Any); addFlightExperience(); } if (canAffordScience) { GUILayout.Label("<color=white><b>" + Localizer.Format(BARISScenario.TestBenchScienceCost) + "</b>" + string.Format("{0:n2}", costScience) + "</color>"); } else { GUILayout.Label("<color=red><b>" + Localizer.Format(BARISScenario.TestBenchScienceCost) + "</b>" + string.Format("{0:n2}", costScience) + "</color>"); } GUILayout.EndHorizontal(); GUILayout.EndScrollView(); } //Funds cost to upgrade flight experience. if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { canAffordFunds = Funding.CanAfford(costFunds); GUILayout.BeginScrollView(originPoint, infoPanelOptions); GUILayout.BeginHorizontal(); if (GUILayout.Button(fundsIcon, buttonOptions) && canAffordFunds) { Funding.Instance.AddFunds(-costFunds, TransactionReasons.Any); addFlightExperience(); } if (canAffordFunds) { GUILayout.Label("<color=white><b>" + Localizer.Format(BARISScenario.TestBenchFundsCost) + "</b>" + string.Format("{0:n2}", costFunds) + "</color>"); } else { GUILayout.Label("<color=red><b>" + Localizer.Format(BARISScenario.TestBenchFundsCost) + "</b>" + string.Format("{0:n2}", costFunds) + "</color>"); } GUILayout.EndHorizontal(); GUILayout.EndScrollView(); } //How much experience to add GUILayout.BeginHorizontal(); GUILayout.Label("<color=white>" + Localizer.Format(BARISScenario.TestBenchExpToAdd) + "</color>"); buttonIndex = GUILayout.SelectionGrid(buttonIndex, experienceModifiers, 3); GUILayout.EndHorizontal(); switch (buttonIndex) { case 0: experienceModifier = 1; break; case 1: experienceModifier = 5; break; case 2: experienceModifier = 10; break; } }
private void MainWindow(int windowID) { GUILayout.BeginVertical(); GUILayout.Space(25); GUILayout.BeginHorizontal(); Utilities.UI.createLabel("Science amount:", textStyle); sellBuyString = GUILayout.TextField(Utilities.getOnlyNumbers(sellBuyString), 5, numberFieldStyle); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); Utilities.UI.createLabel("Conversion rate", textStyle); Utilities.UI.createLabel(currentSettings.getFloat("conversionRate").ToString("N0"), textStyle); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); Utilities.UI.createLabel("Tax & conversion fee", textStyle, "The conversion fee depends on your current reputation(" + Math.Round(Reputation.CurrentRep).ToString("N0") + "). At " + currentSettings.getFloat("repHigh").ToString("N0") + " the conversion fee is 0% and at " + currentSettings.getFloat("repLow").ToString("N0") + " the fee is " + currentSettings.getString("delta") + "%"); Utilities.UI.createLabel(Utilities.round(calcModifier(), 2).ToString(), textStyle); GUILayout.EndHorizontal(); GUILayout.Space(12); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); float buyScienceAmount = (float)buyScience(true); float sellScienceAmount = (float)sellScience(false, true); if (Utilities.UI.createButton("Buy", buttonStyle, ("Buy science for " + Math.Round(buyScience(true))), !Funding.CanAfford(buyScienceAmount) || buyScienceAmount == 0)) { buyScience(); } GUILayout.FlexibleSpace(); if (Utilities.UI.createButton("Sell", buttonStyle, ("Sell science for " + Math.Round(sellScience(true))), !ResearchAndDevelopment.CanAfford(sellScienceAmount) || sellScienceAmount == 0)) { sellScience(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); Utilities.UI.createOptionSwitcher("Use:", Toolbar.toolbarOptions, ref toolbarSelected, toolbarOptionLabelStyle); updateToolbarBool(); GUILayout.EndVertical(); Utilities.UI.updateTooltipAndDrag(); }