临时1

using System;
using System.Xml;
using System.Collections.Generic;
using UnityEngine;


namespace Arth.Config
{
    using MissionDic = Dictionary<int, DSceneData>;
    using tempDic = Dictionary<int, DChapterData>;
    using ChapterDic = Dictionary<int, Dictionary<int, DChapterData>>;
    
class DMapData : BaseData
{
//场景id
int _next_sceneid; //下一场景id
public int next_sceneid{ get { return _next_sceneid; } }
string _name; //场景名
public string name{ get { return _name; } }
string _describe; //场景描述
public string describe{ get { return _describe; } }
int _level; //地图开启等级
public int level{ get { return _level; } }


public DMapData()
{


}


public override void init(XmlElement element)
{
base.init(element);


string tempBuff;
string [] tempStrArray;
int.TryParse(element.GetAttribute("next_sceneid"), out _next_sceneid);


_describe = element.GetAttribute("describe");


_name = element.GetAttribute("name");


int.TryParse(element.GetAttribute("level"), out _level);


}
}


    class ASceneData : BaseData
    {
        //关卡id
        int _icon_id; //关卡图标id
        public int icon_id { get { return _icon_id; } }
        int _pos_x; //图标起始
        public int pos_x { get { return _pos_x; } }
        int _pos_y; //图标起始
        public int pos_y { get { return _pos_y; } }
        int _size_x; //图标大小
        public int size_x { get { return _size_x; } }
        int _size_y; //图标大小
        public int size_y { get { return _size_y; } }
        string _obj_path; //图标材质
        public string obj_path { get { return _obj_path; } }


        public ASceneData()
        {


        }


        public override void init(XmlElement element)
        {
            base.init(element);


            int.TryParse(element.GetAttribute("pos_x"), out _pos_x);


            int.TryParse(element.GetAttribute("pos_y"), out _pos_y);


            int.TryParse(element.GetAttribute("icon_id"), out _icon_id);


            int.TryParse(element.GetAttribute("size_x"), out _size_x);


            int.TryParse(element.GetAttribute("size_y"), out _size_y);


            _obj_path = element.GetAttribute("obj_path");


        }
    }


   class DSceneData : BaseData
{
//关卡id
int _map_id; //地图ID
public int map_id{ get { return _map_id; } }
int _chapter_id; //章节ID
public int chapter_id{ get { return _chapter_id; } }
string _name; //章节点名称
public string name{ get { return _name; } }
string _describe; //章节点描述
public string describe{ get { return _describe; } }
int _mission_type; //1.章节类功能
//2.商店类功能
//3.竞技场类功能
//4.兵营功能
//5.采集点功能
//6.宝箱类功能
//7.异界之地功能点
public int mission_type{ get { return _mission_type; } }
int _next_mission1_map; //下一关卡1
public int next_mission1_map{ get { return _next_mission1_map; } }
int _next_mission1_chapter; //下一关卡1
public int next_mission1_chapter{ get { return _next_mission1_chapter; } }
int _next_mission2_map; //下一关卡2
public int next_mission2_map{ get { return _next_mission2_map; } }
int _next_mission2_chapter; //下一关卡2
public int next_mission2_chapter{ get { return _next_mission2_chapter; } }
int _hide; //是否隐藏
public int hide{ get { return _hide; } }
int _condition; //显示条件
//1.城主等级
//2.接取某一任务
//3.完成某一任务
//4.完成某一关卡点
public int condition{ get { return _condition; } }
int _param; //条件参数
public int param{ get { return _param; } }


public DSceneData()
{


}


public override void init(XmlElement element)
{
base.init(element);


string tempBuff;
string [] tempStrArray;
int.TryParse(element.GetAttribute("chapter_id"), out _chapter_id);


int.TryParse(element.GetAttribute("map_id"), out _map_id);


_name = element.GetAttribute("name");


_describe = element.GetAttribute("describe");


int.TryParse(element.GetAttribute("param"), out _param);


int.TryParse(element.GetAttribute("next_mission2_map"), out _next_mission2_map);


int.TryParse(element.GetAttribute("hide"), out _hide);


int.TryParse(element.GetAttribute("next_mission1_chapter"), out _next_mission1_chapter);


int.TryParse(element.GetAttribute("next_mission1_map"), out _next_mission1_map);


int.TryParse(element.GetAttribute("next_mission2_chapter"), out _next_mission2_chapter);


int.TryParse(element.GetAttribute("condition"), out _condition);


int.TryParse(element.GetAttribute("mission_type"), out _mission_type);


}
}

    class AChapterData
    {
        public AChapterData(XmlElement element)
        {
            int.TryParse(element.GetAttribute("id"), out _IconID);


            _PrefabPath = element.GetAttribute("prefab_path");
        }


        int _IconID;
        public int IconID { get { return _IconID; } }
        string _PrefabPath;
        public string PrefabPath { get { return _PrefabPath; } }
    }


    class DChapterData
    {
        public DChapterData(XmlElement element)
        {
            int.TryParse(element.GetAttribute("chapter_id"), out _ChapterID);
            int.TryParse(element.GetAttribute("map_id"), out _MapID);
            int.TryParse(element.GetAttribute("scene_id"), out _SceneID);
            int.TryParse(element.GetAttribute("icon_id"), out _IconID);
            int.TryParse(element.GetAttribute("energy"), out _Energy);
            int.TryParse(element.GetAttribute("battleid"), out _Battle);


            _Dialog_Begin_ID = element.GetAttribute("dialog_begin_id");
            _Dialog_End_ID = element.GetAttribute("dialog_end_id");
            _Name = element.GetAttribute("chapter_name");
            _Desc = element.GetAttribute("desc_name");
        }


        int _ChapterID;
        public int ChapterID { get { return _ChapterID; } }
        int _MapID;
        public int MapID { get { return _MapID; } }
        int _SceneID;
        public int SceneID { get { return _SceneID; } }
        int _IconID;
        public int IconID { get { return _IconID; } }
        int _Energy;
        public int Energy { get { return _Energy; } }
        int _Battle;
        public int Battle { get { return _Battle; } }
        string _Dialog_Begin_ID;
        public string Dialog_Begin_ID { get { return _Dialog_Begin_ID; } }
        string _Dialog_End_ID;
        public string Dialog_End_ID { get { return _Dialog_End_ID; } }
        string _Name;
        public string Name { get { return _Name; } }
        string _Desc;
        public string Desc { get { return _Desc; } }
    }


    class MissionDataList
    {
        private MissionDataList() { }


        private static MissionDataList instance = null;


        public static MissionDataList Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new MissionDataList();
                }
                return instance;
            }
        }


        public void Load()
        {
            string AChapterDataPath = "Configs/a-Chapter";
            string DChapterDataPath = "Configs/d-Chapter";


            // load a-Charpter
            XmlDocument doc = Config.ConfigFileUtility.ReadXml(AChapterDataPath);
            XmlNodeList nodelist = doc.SelectSingleNode("a-Chapter").ChildNodes;
            foreach (var node in nodelist)
            {
                XmlElement element = (XmlElement)node;
                AChapterData chapterData = new AChapterData(element);
                m_AChapterDataList.Add(chapterData.IconID, chapterData);
            }


            // load d-Charpter
            doc = Config.ConfigFileUtility.ReadXml(DChapterDataPath);
            nodelist = doc.SelectSingleNode("d-Chapter").ChildNodes;
            foreach (var node in nodelist)
            {
                XmlElement element = (XmlElement)node;
                DChapterData chapterData = new DChapterData(element);


                Debug.Log("map: " + chapterData.MapID
                    + ", " + "scene: " + chapterData.SceneID
                    + ", " + "chapter: " + chapterData.ChapterID);
                addChapterData(chapterData);
            }


            // if there has some relationship between a-Hero and d-Hero, establish these here.
//             for (int i = 1; i <= m_DChapterDataList.Count; ++i)
//             {
//                 for (int j = 1; j <= m_DChapterDataList[i].Count; ++j)
//                 {
//                     for (int k = 1; k <= m_DChapterDataList[i][j].Count; ++k)
//                     {
//                         DChapterData data = m_DChapterDataList[i][j][k];
//                         Debug.Log(data.SceneID.ToString() + " " +
//                             data.MissionID.ToString() + " " +
//                             data.ChapterID.ToString() + " " +
//                             data.Desc + " " + data.Name + " " + data.Energy.ToString());
//                     }
//                 }
//             }
        }


        private void addChapterData(DChapterData chapterData)
        {
            if (m_DChapterDataList.ContainsKey(chapterData.MapID))
            {
                if (m_DChapterDataList[chapterData.MapID].ContainsKey(chapterData.SceneID))
                {
                    if (m_DChapterDataList[chapterData.MapID][chapterData.SceneID].ContainsKey(
                        chapterData.ChapterID))
                    {
                        // what's the fucking problem?
                    }
                    else
                    {
                        m_DChapterDataList[chapterData.MapID][chapterData.SceneID].Add(
                            chapterData.ChapterID, chapterData);
                    }
                }
                else
                {
                    Dictionary<int, DChapterData> chapter =
                        new Dictionary<int, DChapterData>();
                    m_DChapterDataList[chapterData.MapID].Add(chapterData.SceneID, chapter);


                    addChapterData(chapterData);
                }
            }
            else
            {
                Dictionary<int, Dictionary<int, DChapterData>> mission =
                    new Dictionary<int, Dictionary<int, DChapterData>>();
                m_DChapterDataList.Add(chapterData.MapID, mission);


                addChapterData(chapterData);
            }
        }


        public DChapterData GetChapterData(int sceneId, int missionId, int chapterId)
        {
            if (m_DChapterDataList.ContainsKey(sceneId))
            {
                if (m_DChapterDataList[sceneId].ContainsKey(missionId))
                {
                    if (m_DChapterDataList[sceneId][missionId].ContainsKey(chapterId))
                        return m_DChapterDataList[sceneId][missionId][chapterId];
                }
            }


            return null;
        }


        public int GetChapterCount(int mapId, int sceneId)
        {
            if (m_DChapterDataList.ContainsKey(mapId))
            {
                if (m_DChapterDataList[mapId].ContainsKey(sceneId))
                {
                    return m_DChapterDataList[mapId][sceneId].Count;
                }
            }


            return 0;
        }


        public void Release()
        {
            // if there has some relationship between a-Hero and d-Hero, disestablish these here.


            foreach (KeyValuePair<int, ChapterDic> node1 in m_DChapterDataList)
            {
                foreach (KeyValuePair<int, tempDic> node2 in node1.Value)
                {
                    node2.Value.Clear();
                }
                node1.Value.Clear();
            }


            m_DSceneDataList.Clear();
        }


        public void ReLoad()
        {
            Release();
            Load();
        }


        public int GetMissionCount(int sceneId)
        {
            if (m_DMissionDataList.ContainsKey(sceneId))
                return m_DMissionDataList[sceneId].Count;
            else
                return 0;
        }


        public DSceneData GetDSceneData(int sceneId)
        {
            if (m_DSceneDataList.ContainsKey(sceneId))
            {
                return m_DSceneDataList[sceneId];
            }


            return null;
        }


        public int GetSceneCount()
        {
            return m_DSceneDataList.Count;
        }


        private Dictionary<int, MissionDic> m_DMissionDataList = new Dictionary<int, MissionDic>();
        private Dictionary<int, DSceneData> m_DSceneDataList = new Dictionary<int, DSceneData>();
        private Dictionary<int, AChapterData> m_AChapterDataList = new Dictionary<int, AChapterData>();
        private Dictionary<int, ChapterDic> m_DChapterDataList = new Dictionary<int, ChapterDic>();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值