private static void TechnologyResearch(TechNodeInfo tech)
        {
            System.StartIgnoringEvents();
            var node = AssetBase.RnDTechTree.GetTreeTechs().ToList().Find(n => n.techID == tech.Id);

            //Unlock the technology
            ResearchAndDevelopment.Instance.UnlockProtoTechNode(node);

            //Refresh RD nodes in case we are in the RD screen
            if (RDController.Instance && RDController.Instance.partList)
            {
                RDController.Instance.partList.Refresh();
                RDController.Instance.UpdatePanel();
            }

            //Refresh the tech tree
            ResearchAndDevelopment.RefreshTechTreeUI();

            //Refresh the part list in case we are in the VAB/SPH
            if (EditorPartList.Instance)
            {
                EditorPartList.Instance.Refresh();
            }

            System.StopIgnoringEvents();
            LunaLog.Log($"TechnologyResearch received - technology researched: {tech.Id}");
        }
Esempio n. 2
0
        private static void TechnologyUpdate(string techId)
        {
            System.StartIgnoringEvents();
            var nodes = AssetBase.RnDTechTree.GetTreeTechs();

            foreach (var n in nodes)
            {
                if (n.techID == techId)
                {
                    ResearchAndDevelopment.Instance.UnlockProtoTechNode(n);
                }
            }

            ResearchAndDevelopment.RefreshTechTreeUI();
            System.StopIgnoringEvents();
            LunaLog.Log($"TechnologyUpdate received - technology unlocked: {techId}");
        }
Esempio n. 3
0
        protected virtual void unlockTechNode()
        {
            if (HighLogic.CurrentGame.Mode != Game.Modes.CAREER && HighLogic.CurrentGame.Mode != Game.Modes.SCIENCE_SANDBOX)
            {
                return;
            }

            int unlockRoll = UnityEngine.Random.Range(1, dieRoll);

            if (unlockRoll < unlockTargetNumber)
            {
                return;
            }

            //Get the list of unavailable nodes and their tech IDs
            List <ProtoTechNode> unavailableNodes = AssetBase.RnDTechTree.GetNextUnavailableNodes();

            if (unavailableNodes.Count <= 0)
            {
                return;
            }
            ProtoTechNode            node;
            int                      index     = 0;
            Dictionary <string, int> techNodes = new Dictionary <string, int>();

            for (index = 0; index < unavailableNodes.Count; index++)
            {
                if (techNodes.ContainsKey(unavailableNodes[index].techID) == false)
                {
                    techNodes.Add(unavailableNodes[index].techID, index);
                }
            }

            index = UnityEngine.Random.Range(0, unavailableNodes.Count);
            node  = unavailableNodes[index];
            ResearchAndDevelopment.Instance.UnlockProtoTechNode(node);
            ResearchAndDevelopment.RefreshTechTreeUI();

            ScreenMessages.PostScreenMessage(unlockMessage, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
            ScreenMessages.PostScreenMessage(ResearchAndDevelopment.GetTechnologyTitle(node.techID) + kUnlockTechNodeMsg, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
        }
        public void ExperimentRequirementsMet(string experimentID, float chanceOfSuccess, float resultRoll)
        {
            Log("ExperimentRequirementsMet called");

            //Career/Science mode only
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                Log("Not in flight scene.");
                return;
            }
            if (HighLogic.CurrentGame.Mode != Game.Modes.CAREER && HighLogic.CurrentGame.Mode != Game.Modes.SCIENCE_SANDBOX)
            {
                Log("Current game is neither career nor science sandbox.");
                return;
            }
            if (resultRoll < chanceOfSuccess)
            {
                Log(string.Format("resultRoll ({0:f2}) < chanceOfSuccess ({1:f2}), exiting.", resultRoll, chanceOfSuccess));
                return;
            }

            //Make sure we reach our target number
            int unlockRoll = UnityEngine.Random.Range(1, dieRoll);

            if (unlockRoll < targetNumber)
            {
                Log(string.Format("unlockRoll ({0:n}) < targetNumber ({1:n}), exiting.", unlockRoll, targetNumber));
                return;
            }

            //Get the list of unavailable nodes and their tech IDs
            List <ProtoTechNode> unavailableNodes = AssetBase.RnDTechTree.GetNextUnavailableNodes();

            if (unavailableNodes.Count <= 0)
            {
                return;
            }
            ProtoTechNode            node;
            int                      index     = 0;
            Dictionary <string, int> techNodes = new Dictionary <string, int>();

            for (index = 0; index < unavailableNodes.Count; index++)
            {
                if (techNodes.ContainsKey(unavailableNodes[index].techID) == false)
                {
                    techNodes.Add(unavailableNodes[index].techID, index);
                }
            }

            //Unlock the first tech node on our priority list that hasn't been unlocked yet.
            char[] delimiters = new char[] { ';' };
            if (!string.IsNullOrEmpty(priorityNodes))
            {
                string[] priorityList = priorityNodes.Split(delimiters);
                Log("priorityList length: " + priorityList.Length);

                for (index = 0; index < priorityList.Length; index++)
                {
                    //Check the compiled list for the tech item we're interested in
                    //If we find one, the unlock the node
                    if (techNodes.ContainsKey(priorityList[index]))
                    {
                        node = unavailableNodes[techNodes[priorityList[index]]];
                        ResearchAndDevelopment.Instance.UnlockProtoTechNode(node);
                        ResearchAndDevelopment.RefreshTechTreeUI();

                        ScreenMessages.PostScreenMessage(kUnlockTechNodeMsg + ResearchAndDevelopment.GetTechnologyTitle(node.techID), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                        return;
                    }
                }
            }

            //Ok, at this point we need to try and unlock a random node.
            //If we have no blacklisted nodes then just select one at random.
            if (string.IsNullOrEmpty(blacklistNodes))
            {
                index = UnityEngine.Random.Range(0, unavailableNodes.Count);
                node  = unavailableNodes[index];
                ResearchAndDevelopment.Instance.UnlockProtoTechNode(node);
                ResearchAndDevelopment.RefreshTechTreeUI();

                ScreenMessages.PostScreenMessage(kUnlockTechNodeMsg + ResearchAndDevelopment.GetTechnologyTitle(node.techID), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
            }

            //We must skip any nodes that are blacklisted.
            //We have a maximum number of tries equal to the number of blacklisted nodes.
            else
            {
                string[] nodesBlacklisted = blacklistNodes.Split(delimiters);
                int      nodeIndex        = -1;
                for (index = 0; index < nodesBlacklisted.Length; index++)
                {
                    nodeIndex = UnityEngine.Random.Range(0, unavailableNodes.Count);
                    node      = unavailableNodes[nodeIndex];

                    if (!blacklistNodes.Contains(node.techID))
                    {
                        ResearchAndDevelopment.Instance.UnlockProtoTechNode(node);
                        ResearchAndDevelopment.RefreshTechTreeUI();

                        ScreenMessages.PostScreenMessage(kUnlockTechNodeMsg + ResearchAndDevelopment.GetTechnologyTitle(node.techID), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                        return;
                    }
                }
            }
        }