예제 #1
0
        /// <summary>
        /// Called from RP0KCT
        /// </summary>
        /// <param name="validationError"></param>
        /// <param name="canBeResolved"></param>
        /// <param name="costToResolve"></param>
        /// <returns></returns>
        public virtual bool Validate(out string validationError, out bool canBeResolved, out float costToResolve)
        {
            validationError = null;
            canBeResolved   = false;
            costToResolve   = 0;

            if (IsConfigUnlocked(heatShieldType))
            {
                return(true);
            }

            PartUpgradeHandler.Upgrade upgd = PartUpgradeManager.Handler.GetUpgrade(heatShieldType);
            if (PartUpgradeManager.Handler.IsAvailableToUnlock(heatShieldType))
            {
                canBeResolved   = true;
                costToResolve   = upgd.entryCost;
                validationError = $"purchase config {upgd.title}";
            }
            else
            {
                validationError = $"unlock tech {ResearchAndDevelopment.GetTechnologyTitle(upgd.techRequired)}";
            }

            return(false);
        }
예제 #2
0
        public bool IsConfigUnlocked(string configName)
        {
            if (!PartUpgradeManager.Handler.CanHaveUpgrades())
            {
                return(true);
            }

            PartUpgradeHandler.Upgrade upgd = PartUpgradeManager.Handler.GetUpgrade(configName);
            if (upgd == null)
            {
                return(true);
            }

            if (PartUpgradeManager.Handler.IsEnabled(configName))
            {
                return(true);
            }

            if (upgd.entryCost < 1.1 && PartUpgradeManager.Handler.IsAvailableToUnlock(configName) &&
                PurchaseConfig(upgd))
            {
                return(true);
            }

            return(false);
        }
예제 #3
0
        /// <summary>
        /// Called from RP0KCT
        /// </summary>
        /// <returns></returns>
        public virtual bool ResolveValidationError()
        {
            PartUpgradeHandler.Upgrade upgd = PartUpgradeManager.Handler.GetUpgrade(heatShieldType);
            if (upgd == null)
            {
                return(false);
            }

            return(PurchaseConfig(upgd));
        }
예제 #4
0
        public bool PurchaseConfig(PartUpgradeHandler.Upgrade upgd)
        {
            if (Funding.CanAfford(upgd.entryCost))
            {
                Funding.Instance?.AddFunds(-upgd.entryCost, TransactionReasons.RnDPartPurchase);
                PartUpgradeManager.Handler.SetUnlocked(upgd.name, true);
                return(true);
            }

            return(false);
        }
        Callback <bool> OnButtonClick_Upgrade(PartUpgradeHandler.Upgrade thisupgrade)
        {
            return(delegate(bool arg1)
            {
                if (arg1 == false)
                {
                    PartUpgradeManager.Handler.SetEnabled(thisupgrade.name, false);
                    if (!ListOfTemporarilyDisabledUpgrades.Contains(thisupgrade.name))
                    {
                        ListOfTemporarilyDisabledUpgrades.Add(thisupgrade.name);
                    }
                    //Debug.Log("Upgrade Editor: " + thisupgrade.name + "'s Enable set to:" + PartUpgradeManager.Handler.IsEnabled(thisupgrade.name));
                }

                if (arg1 == true)
                {
                    PartUpgradeManager.Handler.SetEnabled(thisupgrade.name, true);
                    if (ListOfTemporarilyDisabledUpgrades.Contains(thisupgrade.name))
                    {
                        ListOfTemporarilyDisabledUpgrades.Remove(thisupgrade.name);
                    }
                    //Debug.Log("Upgrade Editor: " + thisupgrade.name + "'s Enable set to:" + PartUpgradeManager.Handler.IsEnabled(thisupgrade.name));
                }
                ReloadPartModulesConfigs();
                ReapplyIgnoredUpgrades();
                RegeneratePartUpgrades(thisupgrade.name);

                //Such double check is necessary.
                foreach (ConfigNode u in allupgrades)
                {
                    var checkEnabled = PartUpgradeManager.Handler.IsEnabled(u.GetValue("name__"));
                    PartUpgradeManager.Handler.SetEnabled(u.GetValue("name__"), !ListOfTemporarilyDisabledUpgrades.Contains(u.GetValue("name__")));
                    if (PartUpgradeManager.Handler.IsEnabled(u.GetValue("name__")) != checkEnabled)
                    {
                        RegeneratePartUpgrades(u.GetValue("name__"));
                    }
                }
            });
        }