Esempio n. 1
0
    public static void AddAllStories()
    {
        Reset();
        foreach (string path in Directory.GetFiles(StoriesDirectory, "*.xml", SearchOption.TopDirectoryOnly))
        {
            FileInfo fi       = new FileInfo(path);
            string   pureName = fi.Name.Substring(0, fi.Name.LastIndexOf("."));

            string text;
            using (StreamReader sr = new StreamReader(path))
            {
                text = sr.ReadToEnd();
            }

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(text);
            XmlElement story = doc.DocumentElement;

            BuildInfo buildInfo = BuildInfo.GetBuildInfoFromXML(story.ChildNodes.Item(0), out bool needRefresh, BuildCards.DefaultCardLimitNumTypes.BasedOnZero);
            NeedReload |= needRefresh;
            GamePlaySettings gps = GamePlaySettings.GetGamePlaySettingsFromXML(story.ChildNodes.Item(1));

            SortedDictionary <int, Chapter> Chapters = new SortedDictionary <int, Chapter>();
            XmlNode node_Chapters = story.ChildNodes.Item(2);
            for (int i = 0; i < node_Chapters.ChildNodes.Count; i++)
            {
                Chapter chapter = Chapter.GetChapterFromXML(node_Chapters.ChildNodes[i]);
                Chapters.Add(chapter.ChapterID, chapter);
            }

            SortedDictionary <int, BuildInfo> playerBuildInfos = new SortedDictionary <int, BuildInfo>();
            playerBuildInfos.Add(buildInfo.BuildID, buildInfo);

            SortedDictionary <int, bool> cardUnlockInfos = new SortedDictionary <int, bool>();

            foreach (KeyValuePair <int, CardInfo_Base> kv in AllCards.CardDict)
            {
                cardUnlockInfos.Add(kv.Key, false);
            }

            foreach (KeyValuePair <int, BuildInfo> kv in playerBuildInfos)
            {
                foreach (KeyValuePair <int, BuildCards.CardSelectInfo> _kv in kv.Value.M_BuildCards.CardSelectInfos)
                {
                    if (_kv.Value.CardSelectUpperLimit > 0)
                    {
                        cardUnlockInfos[_kv.Key] = true;
                    }
                }
            }

            Story newStory = new Story(pureName, Chapters, playerBuildInfos, cardUnlockInfos, gps, 0);
            StoryDict.Add(newStory.StoryName, newStory);
        }

        //If any problem, refresh XML and reload
        if (NeedReload)
        {
            NeedReload = false;
            RefreshAllStoryXML();
            ReloadStoryXML();
        }
    }