Example #1
0
        public KCT_TechStorageItem FromTechItem(TechItem techItem)
        {
            techName    = techItem.TechName;
            techID      = techItem.TechID;
            progress    = techItem.Progress;
            scienceCost = techItem.ScienceCost;

            return(this);
        }
Example #2
0
        public void TechUnlockEvent(GameEvents.HostTargetAction <RDTech, RDTech.OperationResult> ev)
        {
            if (!PresetManager.Instance.ActivePreset.GeneralSettings.Enabled)
            {
                return;
            }
            if (ev.target == RDTech.OperationResult.Successful)
            {
                var tech = new TechItem();
                if (ev.host != null)
                {
                    tech = new TechItem(ev.host);
                }

                if (!tech.IsInList())
                {
                    if (PresetManager.Instance.ActivePreset.GeneralSettings.TechUpgrades)
                    {
                        ScreenMessages.PostScreenMessage("[KCT] Upgrade Point Added!", 4f, ScreenMessageStyle.UPPER_LEFT);
                    }

                    if (PresetManager.Instance.ActivePreset.GeneralSettings.TechUnlockTimes && PresetManager.Instance.ActivePreset.GeneralSettings.BuildTimes)
                    {
                        KCTGameStates.TechList.Add(tech);
                        foreach (TechItem techItem in KCTGameStates.TechList)
                        {
                            techItem.UpdateBuildRate(KCTGameStates.TechList.IndexOf(techItem));
                        }
                        double timeLeft = tech.BuildRate > 0 ? tech.TimeLeft : tech.EstimatedTimeLeft;
                        ScreenMessages.PostScreenMessage($"[KCT] Node will unlock in {MagiCore.Utilities.GetFormattedTime(timeLeft)}", 4f, ScreenMessageStyle.UPPER_LEFT);

                        foreach (AvailablePart ap in ev.host.partsAssigned)
                        {
                            if (Utilities.AddExperimentalPart(ap))
                            {
                                KCTDebug.Log($"{ap.name} added to ExpParts: {ResearchAndDevelopment.IsExperimentalPart(ap)}");
                            }
                        }

                        OnTechQueued.Fire(ev.host);
                    }
                }
                else
                {
                    ResearchAndDevelopment.Instance.AddScience(tech.ScienceCost, TransactionReasons.RnDTechResearch);
                    ScreenMessages.PostScreenMessage("[KCT] This node is already being researched!", 4f, ScreenMessageStyle.UPPER_LEFT);
                    ScreenMessages.PostScreenMessage($"[KCT] It will unlock in {MagiCore.Utilities.GetFormattedTime((KCTGameStates.TechList.First(t => t.TechID == ev.host.techID)).TimeLeft)}", 4f, ScreenMessageStyle.UPPER_LEFT);
                }
            }
        }
Example #3
0
        public void FacilityUpgradedEvent(Upgradeables.UpgradeableFacility facility, int lvl)
        {
            if (KCT_GUI.IsPrimarilyDisabled)
            {
                return;
            }

            KCTDebug.Log($"Facility {facility.id} upgraded to lvl {lvl}");
            AllowedToUpgrade = false;
            foreach (KSCItem ksc in KCTGameStates.KSCs)
            {
                ksc.RecalculateBuildRates();
                ksc.RecalculateUpgradedBuildRates();
            }
            for (int i = KCTGameStates.TechList.Count - 1; i >= 0; i--)
            {
                TechItem tech = KCTGameStates.TechList[i];
                tech.UpdateBuildRate(KCTGameStates.TechList.IndexOf(tech));
            }
        }
Example #4
0
        public void PartPurchasedEvent(AvailablePart part)
        {
            if (HighLogic.CurrentGame.Parameters.Difficulty.BypassEntryPurchaseAfterResearch)
            {
                return;
            }
            TechItem tech = KCTGameStates.TechList.OfType <TechItem>().FirstOrDefault(t => t.TechID == part.TechRequired);

            if (tech != null && tech.IsInList())
            {
                ScreenMessages.PostScreenMessage("[KCT] You must wait until the node is fully researched to purchase parts!", 4f, ScreenMessageStyle.UPPER_LEFT);
                if (part.costsFunds)
                {
                    Utilities.AddFunds(part.entryCost, TransactionReasons.RnDPartPurchase);
                }
                tech.ProtoNode.partsPurchased.Remove(part);
                tech.DisableTech();
            }
            else
            {
                Utilities.RemoveExperimentalPart(part);
            }
        }
Example #5
0
        public void FacilityUpgradedEvent(Upgradeables.UpgradeableFacility facility, int lvl)
        {
            if (KCT_GUI.IsPrimarilyDisabled)
            {
                bool isLaunchpad = facility.id.ToLower().Contains("launchpad");
                if (!isLaunchpad)
                {
                    return;
                }

                KCTGameStates.ActiveKSC.ActiveLPInstance.Upgrade(lvl);
            }

            KCTDebug.Log($"Facility {facility.id} upgraded to lvl {lvl}");
            if (facility.id.ToLower().Contains("launchpad"))
            {
                if (!AllowedToUpgrade)
                {
                    KCTGameStates.ActiveKSC.ActiveLPInstance.Upgrade(lvl);    //also repairs the launchpad
                }
                else
                {
                    KCTGameStates.ActiveKSC.ActiveLPInstance.level = lvl;
                }
            }
            AllowedToUpgrade = false;
            foreach (KSCItem ksc in KCTGameStates.KSCs)
            {
                ksc.RecalculateBuildRates();
                ksc.RecalculateUpgradedBuildRates();
            }
            for (int i = KCTGameStates.TechList.Count - 1; i >= 0; i--)
            {
                TechItem tech = KCTGameStates.TechList[i];
                tech.UpdateBuildRate(KCTGameStates.TechList.IndexOf(tech));
            }
        }
Example #6
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);
            LoadTree();

            if (Utilities.CurrentGameIsMission())
            {
                return;
            }

            KCTDebug.Log("Reading from persistence.");
            KCTGameStates.KSCs.Clear();
            KCTGameStates.ActiveKSC = null;
            KCTGameStates.InitAndClearTechList();
            KCTGameStates.TechUpgradesTotal = 0;
            KCTGameStates.SciPointsTotal    = -1;
            KCT_GUI.ResetUpgradePointCounts();

            var        kctVS = new KCT_DataStorage();
            ConfigNode cn    = node.GetNode(kctVS.GetType().Name);

            if (cn != null)
            {
                ConfigNode.LoadObjectFromConfig(kctVS, cn);
            }

            bool foundStockKSC = false;

            foreach (ConfigNode ksc in node.GetNodes("KSC"))
            {
                string name       = ksc.GetValue("KSCName");
                var    loaded_KSC = new KSCItem(name);
                loaded_KSC.FromConfigNode(ksc);
                if (loaded_KSC != null && loaded_KSC.KSCName != null && loaded_KSC.KSCName.Length > 0)
                {
                    loaded_KSC.RDUpgrades[1] = KCTGameStates.TechUpgradesTotal;
                    if (KCTGameStates.KSCs.Find(k => k.KSCName == loaded_KSC.KSCName) == null)
                    {
                        KCTGameStates.KSCs.Add(loaded_KSC);
                    }
                    foundStockKSC |= string.Equals(loaded_KSC.KSCName, Utilities._legacyDefaultKscId, StringComparison.OrdinalIgnoreCase);
                }
            }

            Utilities.SetActiveKSCToRSS();
            if (foundStockKSC)
            {
                TryMigrateStockKSC();
            }

            var protoTechNodes      = new Dictionary <string, ProtoTechNode>(); // list of all the protoTechNodes that have been researched
            var inDevProtoTechNodes = new Dictionary <string, ProtoTechNode>(); // list of all the protoTechNodes that are being researched

            // get the TechList node containing the TechItems with the tech nodes currently being researched from KCT's ConfigNode
            if (node.GetNode("TechList") is ConfigNode tmp)
            {
                foreach (ConfigNode techNode in tmp.GetNodes("Tech"))
                {
                    var techStorageItem = new KCT_TechStorageItem();
                    ConfigNode.LoadObjectFromConfig(techStorageItem, techNode);
                    TechItem techItem = techStorageItem.ToTechItem();
                    techItem.ProtoNode = new ProtoTechNode(techNode.GetNode("ProtoNode"));
                    KCTGameStates.TechList.Add(techItem);

                    // save proto nodes that are in development
                    inDevProtoTechNodes.Add(techItem.ProtoNode.techID, techItem.ProtoNode);
                }
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                // get the nodes that have been researched from ResearchAndDevelopment
                protoTechNodes = Utilities.GetUnlockedProtoTechNodes();
                // iterate through all loaded parts to check if any of them should be experimental
                foreach (AvailablePart ap in PartLoader.LoadedPartsList)
                {
                    if (Utilities.PartIsUnlockedButNotPurchased(protoTechNodes, ap) || inDevProtoTechNodes.ContainsKey(ap.TechRequired))
                    {
                        Utilities.AddExperimentalPart(ap);
                    }
                }
            }

            KCTGameStates.ErroredDuringOnLoad.OnLoadFinish();
        }
Example #7
0
        public TechItem ToTechItem()
        {
            var ret = new TechItem(techID, techName, progress, scienceCost);

            return(ret);
        }
Example #8
0
        public override void OnLoad(ConfigNode node)
        {
            try
            {
                base.OnLoad(node);
                LoadTree();

                if (Utilities.CurrentGameIsMission())
                {
                    return;
                }

                KCTDebug.Log("Reading from persistence.");
                KCTGameStates.KSCs.Clear();
                KCTGameStates.ActiveKSC = null;
                KCTGameStates.InitAndClearTechList();
                KCTGameStates.TechUpgradesTotal = 0;
                KCTGameStates.SciPointsTotal    = -1;
                KCT_GUI.ResetUpgradePointCounts();

                var kctVS = new KCT_DataStorage();
                if (node.GetNode(kctVS.GetType().Name) is ConfigNode cn)
                {
                    ConfigNode.LoadObjectFromConfig(kctVS, cn);
                }

                bool foundStockKSC = false;
                foreach (ConfigNode ksc in node.GetNodes("KSC"))
                {
                    string name       = ksc.GetValue("KSCName");
                    var    loaded_KSC = new KSCItem(name);
                    loaded_KSC.FromConfigNode(ksc);
                    if (loaded_KSC?.KSCName?.Length > 0)
                    {
                        loaded_KSC.RDUpgrades[1] = KCTGameStates.TechUpgradesTotal;
                        if (KCTGameStates.KSCs.Find(k => k.KSCName == loaded_KSC.KSCName) == null)
                        {
                            KCTGameStates.KSCs.Add(loaded_KSC);
                        }
                        foundStockKSC |= string.Equals(loaded_KSC.KSCName, Utilities._legacyDefaultKscId, StringComparison.OrdinalIgnoreCase);
                    }
                }

                Utilities.SetActiveKSCToRSS();
                if (foundStockKSC)
                {
                    TryMigrateStockKSC();
                }

                var protoTechNodes      = new Dictionary <string, ProtoTechNode>(); // list of all the protoTechNodes that have been researched
                var inDevProtoTechNodes = new Dictionary <string, ProtoTechNode>(); // list of all the protoTechNodes that are being researched

                // get the TechList node containing the TechItems with the tech nodes currently being researched from KCT's ConfigNode
                if (node.GetNode("TechList") is ConfigNode tmp)
                {
                    foreach (ConfigNode techNode in tmp.GetNodes("Tech"))
                    {
                        var techStorageItem = new KCT_TechStorageItem();
                        ConfigNode.LoadObjectFromConfig(techStorageItem, techNode);
                        TechItem techItem = techStorageItem.ToTechItem();
                        techItem.ProtoNode = new ProtoTechNode(techNode.GetNode("ProtoNode"));
                        KCTGameStates.TechList.Add(techItem);

                        // save proto nodes that are in development
                        inDevProtoTechNodes.Add(techItem.ProtoNode.techID, techItem.ProtoNode);
                    }
                }
                if (HighLogic.LoadedSceneIsEditor)
                {
                    // get the nodes that have been researched from ResearchAndDevelopment
                    protoTechNodes = Utilities.GetUnlockedProtoTechNodes();
                    // iterate through all loaded parts to check if any of them should be experimental
                    foreach (AvailablePart ap in PartLoader.LoadedPartsList)
                    {
                        if (Utilities.PartIsUnlockedButNotPurchased(protoTechNodes, ap) || inDevProtoTechNodes.ContainsKey(ap.TechRequired))
                        {
                            Utilities.AddExperimentalPart(ap);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                KCTGameStates.ErroredDuringOnLoad = true;
                Debug.LogError("[KCT] ERROR! An error while KCT loading data occurred. Things will be seriously broken!");
                PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "errorPopup", "Error Loading KCT Data", "ERROR! An error occurred while loading KCT data. Things will be seriously broken! Please report this error to LRTR GitHub and attach the log file. The game will be UNPLAYABLE in this state!", "Understood", false, HighLogic.UISkin);
            }
        }