示例#1
0
        public static void write(GeneratedCardDefine card, TextWriter writer)
        {
            XmlDocument doc = new XmlDocument();

            doc.CreateXmlDeclaration("1.0", "UTF-8", string.Empty);
            XmlElement cardEle = doc.CreateElement("Card");

            //ID与类型
            cardEle.SetAttribute("id", card.id.ToString());
            cardEle.SetAttribute("type", card.type);
            //属性
            if (card.type == CardDefineType.SERVANT)
            {
                XmlElement propEle = doc.CreateElement("cost");
                propEle.InnerText = card.getProp <int>("cost").ToString();
                cardEle.AppendChild(propEle);
                propEle           = doc.CreateElement("attack");
                propEle.InnerText = card.getProp <int>("attack").ToString();
                cardEle.AppendChild(propEle);
                propEle           = doc.CreateElement("life");
                propEle.InnerText = card.getProp <int>("life").ToString();
                cardEle.AppendChild(propEle);
            }
            else if (card.type == CardDefineType.SPELL)
            {
                XmlElement propEle = doc.CreateElement("cost");
                propEle.InnerText = card.getProp <int>("cost").ToString();
                cardEle.AppendChild(propEle);
            }
            //使用条件
            XmlElement conditionElement = doc.CreateElement("Condition");

            conditionElement.InnerText = card.getProp <string>("condition");
            cardEle.AppendChild(conditionElement);
            //效果
            GeneratedEffect[] effects = card.getProp <Effect[]>("effects") as GeneratedEffect[];
            if (effects != null)
            {
                for (int i = 0; i < effects.Length; i++)
                {
                    XmlElement effectEle = doc.CreateElement("Effect");
                    effectEle.SetAttribute("pile", effects[i].pile);
                    effectEle.SetAttribute("trigger", effects[i].trigger);
                    if (!string.IsNullOrEmpty(effects[i].actionScript))
                    {
                        if (!string.IsNullOrEmpty(effects[i].filterScript))
                        {
                            XmlElement checkElement = doc.CreateElement("Check");
                            checkElement.InnerText = effects[i].filterScript;
                            effectEle.AppendChild(checkElement);
                        }
                        XmlElement actionElement = doc.CreateElement("Action");
                        actionElement.InnerText = effects[i].actionScript;
                        effectEle.AppendChild(actionElement);
                    }
                    cardEle.AppendChild(effectEle);
                }
            }
            doc.AppendChild(cardEle);

            doc.Save(writer);
        }