예제 #1
0
    public static void AddAllBuilds()
    {
        Reset();

        foreach (KeyValuePair<BuildGroups, string> kv in BuildGroupXMLDict)
        {
            if (!BuildGroupDict.ContainsKey(kv.Key))
            {
                BuildGroup sb = new BuildGroup(kv.Key.ToString());
                BuildGroupDict.Add(kv.Key, sb);
            }

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

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(text);
            XmlElement allBuilds = doc.DocumentElement;
            for (int i = 0; i < allBuilds.ChildNodes.Count; i++)
            {
                XmlNode buildInfoNode = allBuilds.ChildNodes.Item(i);
                BuildInfo buildInfo = BuildInfo.GetBuildInfoFromXML(buildInfoNode, out bool needRefresh, BuildCards.DefaultCardLimitNumTypes.BasedOnCardBaseInfoLimitNum);
                NeedReload |= needRefresh;
                BuildStoryDatabase.Instance.AddOrModifyBuild(kv.Key.ToString(), buildInfo);
                BuildGroupDict[kv.Key].AddBuild(buildInfo.BuildName, buildInfo);
            }
        }

        //If any problem, refresh XML and reload
        if (NeedReload)
        {
            NeedReload = false;
            RefreshAllBuildXML();
            ReloadBuildXML();
        }
    }
예제 #2
0
    public static Level GetLevelFromXML(XmlNode node_levelInfo, out bool needRefresh)
    {
        needRefresh = false;
        string Name_zh = node_levelInfo.Attributes["name_zh"].Value;
        string Name_en = node_levelInfo.Attributes["name_en"].Value;
        SortedDictionary <string, string> names = new SortedDictionary <string, string> {
            { "zh", Name_zh }, { "en", Name_en }
        };
        int        picID           = int.Parse(node_levelInfo.Attributes["picID"].Value);
        LevelTypes levelType       = (LevelTypes)Enum.Parse(typeof(LevelTypes), node_levelInfo.Attributes["levelType"].Value);
        int        difficultyLevel = int.Parse(node_levelInfo.Attributes["difficultyLevel"].Value);

        switch (levelType)
        {
        case LevelTypes.Enemy:
        {
            XmlNode   node_EnemyInfo = node_levelInfo.FirstChild;
            EnemyType enemyType      = (EnemyType)Enum.Parse(typeof(EnemyType), node_EnemyInfo.Attributes["enemyType"].Value);

            BuildInfo bi = BuildInfo.GetBuildInfoFromXML(node_EnemyInfo.FirstChild, out bool _needRefresh_build, BuildCards.DefaultCardLimitNumTypes.BasedOnCardBaseInfoLimitNum);
            needRefresh |= _needRefresh_build;

            XmlNode           node_BonusGroupInfos = node_EnemyInfo.ChildNodes.Item(1);
            List <BonusGroup> BonusGroups          = new List <BonusGroup>();
            for (int i = 0; i < node_BonusGroupInfos.ChildNodes.Count; i++)
            {
                XmlNode    bonusGroupInfo = node_BonusGroupInfos.ChildNodes.Item(i);
                BonusGroup bg             = BonusGroup.GenerateBonusGroupFromXML(bonusGroupInfo, out bool _needRefresh_bonus);
                needRefresh |= _needRefresh_bonus;
                BonusGroups.Add(bg);
            }

            XmlNode      node_CardPriorityInfos = node_EnemyInfo.ChildNodes.Item(2);
            CardPriority CardPriority           = CardPriority.GenerateCardPriorityFromXML(node_CardPriorityInfos, out bool _needRefresh_priority);

            XmlNode          node_ComboListInfos = node_EnemyInfo.ChildNodes.Item(3);
            List <CardCombo> ComboList           = new List <CardCombo>();
            for (int i = 0; i < node_ComboListInfos.ChildNodes.Count; i++)
            {
                XmlNode   comboInfo = node_ComboListInfos.ChildNodes.Item(i);
                CardCombo cc        = CardCombo.GenerateCardComboFromXML(comboInfo, out bool _needRefresh_combo);
                needRefresh |= _needRefresh_combo;
                ComboList.Add(cc);
            }

            Enemy enemy = new Enemy(picID, names, difficultyLevel, bi, enemyType, BonusGroups, ComboList, CardPriority);
            return(enemy);
        }

        case LevelTypes.Shop:
        {
            XmlNode         node_ShopInfo = node_levelInfo.FirstChild;
            List <ShopItem> shopItems     = new List <ShopItem>();
            for (int i = 0; i < node_ShopInfo.ChildNodes.Count; i++)
            {
                XmlNode  node_ShopItem = node_ShopInfo.ChildNodes.Item(i);
                ShopItem si            = ShopItem.GenerateShopItemFromXML(node_ShopItem, out bool _needRefresh_shop);
                needRefresh |= _needRefresh_shop;
                if (si != null)
                {
                    shopItems.Add(si);
                }
            }

            int shopItemCardCount   = int.Parse(node_ShopInfo.Attributes["shopItemCardCount"].Value);
            int shopItemOthersCount = int.Parse(node_ShopInfo.Attributes["shopItemOthersCount"].Value);

            Shop shop = new Shop(picID, names, difficultyLevel, shopItems, shopItemCardCount, shopItemOthersCount);
            return(shop);
        }
        }

        return(null);
    }
예제 #3
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();
        }
    }