示例#1
0
        internal static void SetUnlockedTechState(string param)
        {
            ProceduralAvionicsUtils.Log("Setting unlocked tech state");
            unlockedTech = new Dictionary <string, string>();
            if (param != null)
            {
                string[] typeStrings = param.Split('|');
                if (typeStrings.Length > 1)
                {
                    for (int i = 0; i < typeStrings.Length; i += 2)
                    {
                        var configName = typeStrings[i];
                        if (allTechNodes.Any(x => x.name == configName))
                        {
                            unlockedTech.Add(configName, typeStrings[i + 1]);
                        }
                    }
                }
            }
            ProceduralAvionicsUtils.Log("unlocked tech has ", unlockedTech.Keys.Count.ToString(), " nodes");

            //At this point, we can go through our configs and see if we have any that need to be unlocked
            foreach (var config in allTechNodes)
            {
                if (!unlockedTech.ContainsKey(config.name))
                {
                    var freeTech = config.TechNodes.Values.FirstOrDefault(techNode => GetUnlockCost(config.name, techNode) <= 1 && techNode.IsAvailable);
                    if (freeTech != null)
                    {
                        unlockedTech.Add(config.name, freeTech.name);
                    }
                }
            }
        }
示例#2
0
        public void Load(ConfigNode node)
        {
            ProceduralAvionicsUtils.Log("Loading Config nodes");
            ConfigNode.LoadObjectFromConfig(this, node);
            techNodes = new Dictionary <string, ProceduralAvionicsTechNode>();
            if (name == null)
            {
                name = node.GetValue("name");
            }
            if (node.HasNode("TECHLIMIT"))
            {
                foreach (ConfigNode tNode in node.GetNodes("TECHLIMIT"))
                {
                    ProceduralAvionicsTechNode techNode = new ProceduralAvionicsTechNode();
                    techNode.Load(tNode);
                    techNodes.Add(techNode.name, techNode);
                    ProceduralAvionicsUtils.Log("Loaded TechNode: " + techNode.name);
                }

                List <ProceduralAvionicsTechNode> techNodeList = techNodes.Values.ToList();
                techNodesSerialized = ObjectSerializer.Serialize(techNodeList);
                ProceduralAvionicsUtils.Log("Serialized TechNodes");
            }
            else
            {
                ProceduralAvionicsUtils.Log("No technodes found for " + name);
            }
        }
        internal static void SetUnlockedTechState(string param)
        {
            ProceduralAvionicsUtils.Log("Setting unlocked tech state");
            unlockedTech = new Dictionary <string, string>();
            if (param != null)
            {
                string[] typeStrings = param.Split('|');
                if (typeStrings.Length > 1)
                {
                    for (int i = 0; i < typeStrings.Length; i += 2)
                    {
                        unlockedTech.Add(typeStrings[i], typeStrings[i + 1]);
                    }
                }
            }
            ProceduralAvionicsUtils.Log("unlocked tech has ", unlockedTech.Keys.Count.ToString(), " nodes");

            //At this point, we can go through our configs and see if we have any that need to be unlocked
            foreach (ProceduralAvionicsConfig config in allTechNodes)
            {
                if (!unlockedTech.ContainsKey(config.name))
                {
                    //We don't have max level for this config, should we?
                    ProceduralAvionicsTechNode freeTech =
                        config.TechNodes.Values.Where(techNode => techNode.unlockCost == 0).FirstOrDefault();
                    if (freeTech != null)
                    {
                        unlockedTech.Add(config.name, freeTech.name);
                    }
                }
            }
        }
示例#4
0
        public override void OnSave(ConfigNode node)
        {
            ProceduralAvionicsUtils.Log("ScenarioModule onsave");
            ConfigNode n = new ConfigNode(UNLOCKED_TECH_NODE_NAME);

            n.AddValue(UNLOCKED_TECH_STATE, ProceduralAvionicsTechManager.GetUnlockedTechState());
            node.AddNode(n);
            ProceduralAvionicsUtils.Log("ScenarioModule calling base save");
            base.OnSave(node);
            ProceduralAvionicsUtils.Log("ScenarioModule save done");
        }
示例#5
0
 public static void LoadAvionicsConfigs(ConfigNode node)
 {
     allTechNodes = new List <ProceduralAvionicsConfig>();
     foreach (ConfigNode tNode in node.GetNodes("AVIONICSCONFIG"))
     {
         ProceduralAvionicsConfig config = new ProceduralAvionicsConfig();
         config.Load(tNode);
         config.InitializeTechNodes();
         allTechNodes.Add(config);
         ProceduralAvionicsUtils.Log("Loaded AvionicsConfg: ", config.name);
     }
 }
示例#6
0
        public void InitializeTechNodes()
        {
            ProceduralAvionicsUtils.Log("TechNode deserialization needed");
            techNodes = new Dictionary <string, ProceduralAvionicsTechNode>();
            var techNodeList = techNodesSerialized == null ? new List <ProceduralAvionicsTechNode>() : ObjectSerializer.Deserialize <List <ProceduralAvionicsTechNode> >(techNodesSerialized);

            foreach (var item in techNodeList)
            {
                ProceduralAvionicsUtils.Log("Deserialized " + item.name);
                techNodes.Add(item.name, item);
            }
            ProceduralAvionicsUtils.Log("Deserialized " + techNodes.Count + " techNodes");
        }
示例#7
0
 internal static void SetMaxUnlockedTech(string avionicsConfigName, string techNodeName)
 {
     ProceduralAvionicsUtils.Log("Unlocking ", techNodeName, " for ", avionicsConfigName);
     if (!unlockedTech.ContainsKey(avionicsConfigName))
     {
         ProceduralAvionicsUtils.Log("Unlocking for the first time");
         unlockedTech.Add(avionicsConfigName, techNodeName);
     }
     else
     {
         ProceduralAvionicsUtils.Log("Unlocking new level");
         unlockedTech[avionicsConfigName] = techNodeName;
     }
 }
        public static List <string> GetAvailableConfigs()
        {
            ProceduralAvionicsUtils.Log("Getting Available configs, procedural avionics has ", allTechNodes.Count, " nodes loaded");
            List <string> availableConfigs = new List <string>();

            foreach (var config in allTechNodes)
            {
                if (!TechIsEnabled || (config.TechNodes.Values.Where(node => node.IsAvailable).Count() > 0))
                {
                    availableConfigs.Add(config.name);
                }
            }
            return(availableConfigs);
        }
示例#9
0
        internal static object GetUnlockedTechState()
        {
            StringBuilder builder = StringBuilderCache.Acquire();

            foreach (string unlockedTechType in unlockedTech.Keys)
            {
                if (builder.Length != 0)
                {
                    builder.Append("|");
                }
                builder.Append(unlockedTechType);
                builder.Append("|");
                builder.Append(unlockedTech[unlockedTechType]);
            }
            string state = builder.ToStringAndRelease();

            ProceduralAvionicsUtils.Log("Unlocked Tech state:", state);
            return(state);
        }
示例#10
0
        public override void OnLoad(ConfigNode node)
        {
            ProceduralAvionicsUtils.Log("ScenarioModule onload");
            base.OnLoad(node);

            ConfigNode n = node.GetNode(UNLOCKED_TECH_NODE_NAME);

            string serialized = "";

            if (n != null)
            {
                string param = n.GetValue(UNLOCKED_TECH_STATE);
                if (param != null)
                {
                    serialized = param;
                }
            }
            ProceduralAvionicsUtils.Log("setting unlocked state: ", serialized);
            ProceduralAvionicsTechManager.SetUnlockedTechState(serialized);
        }