示例#1
0
        public void Parse(List<Effect> outList)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(mFilename);

            XmlNodeList nodes = doc.SelectNodes(ROOT_NODE);

            foreach (XmlNode node in nodes)
            {
                Effect effect = new Effect();

                foreach (XmlNode c in node.ChildNodes)
                {
                    switch (c.Name)
                    {
                        case P_NAME:
                            {
                                effect.Name = c.InnerText;
                                break;
                            }
                        case P_ID:
                            {
                                effect.Id = Convert.ToUInt32(c.InnerText);
                                break;
                            }
                        case P_TARGETRANGE:
                            {
                                effect.Range = ParseEnum<Effect.TargetRange>(c.InnerText);
                                break;
                            }
                        case P_TARGETTYPES:
                            {
                                effect.SetTargetTypes(Convert.ToUInt32(c.InnerText));
                                break;
                            }
                        case P_MODIFIERS:
                            {
                                foreach(XmlNode n in c.ChildNodes)
                                {
                                    Effect.Modifier mod = new Effect.Modifier();
                                    mod.Type = ParseEnum<Effect.ModifierType>(n.SelectSingleNode(P_TYPE).InnerText);
                                    mod.Value = Convert.ToInt32(n.SelectSingleNode(P_VALUE).InnerText);
                                    effect.AddModifier(mod);
                                }
                                break;
                            }
                        default:
                            {
                                Console.WriteLine("Unhandled node type: " + c.Name);
                                break;
                            }
                    }
                }

                outList.Add(effect);
            }
        }
示例#2
0
        private void _AppendEffectNode(XmlDocument doc, XmlElement root, Effect data)
        {
            // Set up our effect element
            XmlElement effect = doc.CreateElement(EFFECT_NODE);

            // Declare element storage
            XmlElement element;

            // Create attribute nodes
            element = doc.CreateElement(P_NAME);
            element.InnerText = data.Name;
            effect.AppendChild(element);

            element = doc.CreateElement(P_ID);
            element.InnerText = data.Id.ToString();
            effect.AppendChild(element);

            element = doc.CreateElement(P_TARGETRANGE);
            element.InnerText = data.Range.ToString();
            effect.AppendChild(element);

            element = doc.CreateElement(P_TARGETTYPES);
            element.InnerText = data.GetTargetTypes().ToString();
            effect.AppendChild(element);

            List<Effect.Modifier> modsList = data.GetModifiers();
            if(0 < modsList.Count)
            {
                XmlElement mods = doc.CreateElement(P_MODIFIERS);

                foreach(Effect.Modifier mod in modsList)
                {
                    XmlElement modNode = doc.CreateElement(P_MODIFIER);

                    XmlElement modEle;

                    modEle = doc.CreateElement(P_TYPE);
                    modEle.InnerText = mod.Type.ToString();
                    modNode.AppendChild(modEle);

                    modEle = doc.CreateElement(P_VALUE);
                    modEle.InnerText = mod.Value.ToString();
                    modNode.AppendChild(modEle);

                    mods.AppendChild(modNode);
                }

                effect.AppendChild(mods);
            }

            // Finally, add our new effect node
            root.AppendChild(effect);
        }
示例#3
0
        /// <summary>
        /// Takes an effect reference and populates it with the current form data
        /// </summary>
        /// <param name="effect">Reference to effect</param>
        private void _FillOutDataToEffect(Effect effect)
        {
            effect.Id = EffectManager.GetInstance().GetNextValidId();
            effect.Name = EffectName_text.Text;
            effect.Range = (Effect.TargetRange)TargetRange_chooser.SelectedIndex;

            // Target Types
            effect.SetTargetTypes(0);
            if (true == TargetPlayer_checkBox.Checked) { effect.AddTargetType(GameEntity.EntityType.TYPE_PLAYER); }
            if (true == TargetCreature_checkBox.Checked) { effect.AddTargetType(GameEntity.EntityType.TYPE_CREATURE); }
            if (true == TargetRelic_checkBox.Checked) { effect.AddTargetType(GameEntity.EntityType.TYPE_RELIC); }
            if (true == TargetSpell_checkBox.Checked) { effect.AddTargetType(GameEntity.EntityType.TYPE_SPELL); }
            if (true == TargetDefSpell_checkBox.Checked) { effect.AddTargetType(GameEntity.EntityType.TYPE_DEFSPELL); }
            if (true == TargetHand_checkBox.Checked) { effect.AddTargetType(GameEntity.EntityType.TYPE_HAND); }
            if (true == TargetLibrary_checkBox.Checked) { effect.AddTargetType(GameEntity.EntityType.TYPE_LIBRARY); }
            if (true == TargetGraveyard_checkBox.Checked) { effect.AddTargetType(GameEntity.EntityType.TYPE_GRAVEYARD); }

            // Modifiers
            effect.RemoveAllModifiers();
            foreach(Effect.Modifier mod in Modifiers_listbox.Items)
            {
                effect.AddModifier((Effect.Modifier)mod);
            }
        }
示例#4
0
        private void Save_btn_Click(object sender, EventArgs e)
        {
            Effect effect;

            if(-1 == mLastSelectedIndex || mLastSelectedIndex >= EffectManager.GetInstance().GetAllEffects().Count )
            {
                // Build new effect
                effect = new Effect();
                _FillOutDataToEffect(effect);
                EffectManager.GetInstance().AddEffect(effect);
            }
            else
            {
                // Override existing effect
                effect = EffectManager.GetInstance().GetEffectByIndex(mLastSelectedIndex);
                _FillOutDataToEffect(effect);
            }

            _RefreshListbox();
        }
示例#5
0
 public void AddEffect(Effect e)
 {
     mEffects.Add(e);
 }