public NpcInfo Create(string id)
        {
            TextAsset npcText = m_assetBundle.LoadAsset <TextAsset>(id);

            if (npcText == null)
            {
                return(null);
            }

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.LoadXml(npcText.text); //读取此XML字符串至doc
            }
            catch (XmlException e)
            {
                Debug.LogException(e);
                return(null);
            }
            NpcInfo npcInfo = new NpcInfo();
            XmlNode npcNode = doc.FirstChild;                   //取得此NPC节点

            npcInfo.Name = npcNode.Attributes["Name"].Value;    //此NPC的名字
            npcInfo.Id   = npcNode.Attributes["Id"].Value;      //此NPC的ID
            string spriteId = npcNode.Attributes["Sprite"].Value;

            npcInfo.Sprite = MYXZConfigLoader.Instance.GetSprite(spriteId);

            foreach (XmlNode node in npcNode.ChildNodes)
            {
                switch (node.Name)
                {
                case "Task":
                    npcInfo.TaskIds = node.Attributes["Id"].Value.Split(',');           //获取此NPC的任务
                    break;

                case "Talk":
                    npcInfo.Talks = ConfigFactoryHelper.GetTalks(node);                                     //获取此NPC的交谈
                    break;

                default:
                    break;
                }
            }

            return(npcInfo);
        }
Exemple #2
0
        public Task Create(string id)
        {
            TextAsset taskText = m_assetBundle.LoadAsset <TextAsset>(id);

            if (taskText == null)
            {
                Debug.LogError("无法找到id为" + id + "的Task的信息");
                return(null);
            }

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.LoadXml(taskText.text);   //读取此XML字符串至doc
            }
            catch (XmlException e)
            {
                Debug.LogException(e);
                return(null);
            }

            XmlNode taskNode = doc.FirstChild;

            Task task = new Task();

            task.Name      = taskNode.Attributes["Name"].Value;         //任务名字
            task.Id        = taskNode.Attributes["Id"].Value;           //任务ID
            task.Publisher = taskNode.Attributes["Publisher"].Value;    //任务发布者ID
            task.Deliverer = taskNode.Attributes["Deliverer"].Value;    //任务交付者ID

            foreach (XmlNode node in taskNode.ChildNodes)
            {
                switch (node.Name)
                {
                case "Require":
                    if (!node.Attributes["Predecessors"].Value.Equals(""))                                     //如果有前置任务
                    {
                        task.Predecessors = ConfigFactoryHelper.GetIds(node.Attributes["Predecessors"].Value); //设置前置任务
                    }
                    task.LevelRequirement = Int32.Parse(node.Attributes["Level"].Value);                       //等级需求
                    if (!node.Attributes["Item"].Value.Equals(""))                                             //如果有道具需求
                    {
                        task.RequireItems = ConfigFactoryHelper.GetIdsWithCount(
                            node.Attributes["Item"].Value       //接取任务所需要的物品,item[0]是ID,item[1]是数量
                            );
                    }
                    break;

                case "Description":
                    task.Description = node.InnerText;                //对任务的描述
                    break;

                case "Target":
                    task.Targets = new Task.Target[node.ChildNodes.Count];
                    for (int i = 0; i < node.ChildNodes.Count; i++)
                    {
                        task.Targets[i]          = new Task.Target();
                        task.Targets[i].Type     = (TaskTargetType)Enum.Parse(typeof(TaskTargetType), node.ChildNodes[i].Attributes["Type"].Value); //任务类型
                        task.Targets[i].TargetId = node.ChildNodes[i].Attributes["Id"].Value;                                                       //任务目标ID
                        task.Targets[i].Count    = int.Parse(node.ChildNodes[i].Attributes["Count"].Value);                                         //对目标操作次数
                    }
                    break;

                case "TakeTask":
                    task.TakeTaskTalk = ConfigFactoryHelper.GetTalks(node);         //接取任务时的对话
                    break;

                case "InTask":
                    task.InTaskTalk = ConfigFactoryHelper.GetTalks(node);           //在任务中的对话
                    break;

                case "FinishTask":
                    task.FinishTaskTalk = ConfigFactoryHelper.GetTalks(node);       //任务交付时的对话,只有交付者不是010000(系统)时才有
                    break;

                case "TakeTaskReward":
                    task.TakeTaskExperience = int.Parse(node.Attributes["Experience"].Value);
                    ConfigFactoryHelper.ReadRewardMoney(node.Attributes["Money"].Value, ref task.TakeTaskGold, ref task.TakeTaskSilver, ref task.TakeTaskCopper);
                    task.TakeTaskItem = ConfigFactoryHelper.GetIdsWithCount(node.InnerText);
                    break;

                case "FinishTaskReward":
                    task.FinishTaskExperience = int.Parse(node.Attributes["Experience"].Value);
                    ConfigFactoryHelper.ReadRewardMoney(node.Attributes["Money"].Value, ref task.FinishTaskGold, ref task.FinishTaskSilver, ref task.FinishTaskCopper);
                    task.FinishTaskItem = ConfigFactoryHelper.GetIdsWithCount(node.InnerText);
                    break;

                default:
                    break;
                }
            }

            return(task);
        }