Beispiel #1
0
            public static Mailable CreateFromXml(System.Xml.XmlElement n, IXCRMParser ixcrm_parser)
            {
                Mailable retval = new Mailable();

                retval.id           = n.GetAttribute("id");
                retval.type         = n.GetAttribute("type");
                retval.label        = n.GetAttribute("label");
                retval.requirements = ixcrm_parser.ParseRequirementList(n.SelectSingleNode("./requirements") as System.Xml.XmlElement);
                retval.costs        = ixcrm_parser.ParseCostList(n.SelectSingleNode("./costs") as System.Xml.XmlElement);
                retval.on_accept    = ixcrm_parser.ParseModifierList(n.SelectSingleNode("./on_accept") as System.Xml.XmlElement);
                retval.on_give      = ixcrm_parser.ParseModifierList(n.SelectSingleNode("./on_give") as System.Xml.XmlElement);
                retval.tags         = ixcrm_parser.ParseTagList(n.SelectSingleNode("./tags") as System.Xml.XmlElement);
                return(retval);
            }
Beispiel #2
0
            public static ShopEntry CreateFromXml(System.Xml.XmlElement n, IXCRMParser xcrm_parser)
            {
                ShopEntry retval = new ShopEntry();

                retval.ikey        = n.GetAttribute("ikey");
                retval.label       = n.GetAttribute("label");
                retval.description = n.GetAttribute("description");


                System.Xml.XmlElement costs_node = n.SelectSingleNode("./costs") as System.Xml.XmlElement;
                if (costs_node != null)
                {
                    retval.costs = xcrm_parser.ParseCostList(costs_node);
                }
                // else branches not necessary as costs, modifiers and requirements are INITIALISED by definition

                System.Xml.XmlElement modifiers_node = n.SelectSingleNode("./modifiers") as System.Xml.XmlElement;
                if (modifiers_node != null)
                {
                    retval.modifiers = xcrm_parser.ParseModifierList(modifiers_node);
                }

                System.Xml.XmlElement requirements_node = n.SelectSingleNode("./requirements") as System.Xml.XmlElement;
                if (requirements_node != null)
                {
                    retval.requirements = xcrm_parser.ParseRequirementList(requirements_node);
                }

                System.Xml.XmlNodeList tag_nodes = n.SelectNodes("./tags/tag");
                foreach (System.Xml.XmlElement tag_node in tag_nodes)
                {
                    retval.tags.Add(tag_node.GetAttribute("value"));
                }

                return(retval);
            }
Beispiel #3
0
        public ShopEntry Build(System.Xml.XmlElement n)
        {
            ShopEntry retval = new ShopEntry();

            retval.ikey        = n.GetAttributeOrDefault("ikey", null);
            retval.label       = n.GetAttribute("label");
            retval.description = n.GetAttribute("description");

            foreach (System.Xml.XmlAttribute a in n.Attributes)
            {
                if (a.Name == "ikey")
                {
                    continue;
                }
                if (a.Name == "label")
                {
                    continue;
                }
                if (a.Name == "description")
                {
                    continue;
                }
                throw new UnexpectedXMLElementException("unexpected attribute, \"" + a.Name + "\", on ShopEntry");
            }

            if (retval.ikey == null)
            {
                throw new MissingXMLElementException("missing attribute, \"ikey\", on ShopEntry");
            }

            retval.costs     = new List <Cost>();
            retval.modifiers = new List <Modifier>();

            foreach (System.Xml.XmlNode nn_n in n)
            {
                if (nn_n.NodeType != System.Xml.XmlNodeType.Element)
                {
                    continue;
                }
                System.Xml.XmlElement nn = nn_n as System.Xml.XmlElement;
                switch (nn.Name)
                {
                case "costs":
                    retval.costs = CrmParser_.ParseCostList(nn);
                    break;

                case "modifiers":
                    retval.modifiers = CrmParser_.ParseModifierList(nn);
                    break;

                case "requirements":
                    retval.requirements = CrmParser_.ParseRequirementList(nn);
                    break;

                case "tags":
                    retval.tags = CrmParser_.ParseTagList(nn);
                    break;

                case "properties":
                    // retval.properties = CrmParser_.ParsePropertiesList (nn);
                    break;

                default:
                    throw new UnexpectedXMLElementException("unexpected element, \"" + nn.Name + "\", in ShopEntry");
                    //retval [nn.Name] = nn.Text;
                }
            }

            return(retval);
        }
Beispiel #4
0
        public DomainObjects.Modifier ParseAModifier(System.Xml.XmlElement n)
        {
            DomainObjects.Modifier retval;
            switch (n.Name)
            {
            case "remove_items":
            {
                DomainObjects.Modifiers.RemoveItems remove_item_mod = new DomainObjects.Modifiers.RemoveItems();
                remove_item_mod.ikey = n.GetAttribute("ikey");
                if (n.HasAttribute("count"))
                {
                    if (!System.Int32.TryParse(n.GetAttribute("count"), out remove_item_mod.count))
                    {
                        throw new InvalidXMLElementException("Unable to parse remove_items count to integer");
                    }
                }
                retval = remove_item_mod;
                break;
            }

            case "grant_stat":
            {
                DomainObjects.Modifiers.GrantStat grant_stat_mod = new DomainObjects.Modifiers.GrantStat();
                grant_stat_mod.ikey = n.GetAttribute("ikey");
                grant_stat_mod.type = n.GetAttribute("type");
                if (!System.Int32.TryParse(n.GetAttribute("value"), out grant_stat_mod.value))
                {
                    throw new InvalidXMLElementException("Unable to parse grant_stat value to integer");
                }
                retval = grant_stat_mod;
                break;
            }

            case "grant_stat_range":
            {
                DomainObjects.Modifiers.GrantStatRange grant_stat_mod = new DomainObjects.Modifiers.GrantStatRange();
                grant_stat_mod.ikey = n.GetAttribute("ikey");
                grant_stat_mod.type = n.GetAttribute("type");
                if (!System.Int32.TryParse(n.GetAttribute("min"), out grant_stat_mod.min))
                {
                    throw new InvalidXMLElementException("Unable to parse grant_stat_range min to integer");
                }
                if (!System.Int32.TryParse(n.GetAttribute("max"), out grant_stat_mod.max))
                {
                    throw new InvalidXMLElementException("Unable to parse grant_stat_range max to integer");
                }
                retval = grant_stat_mod;
                break;
            }

            case "grant_item":
            {
                DomainObjects.Modifiers.GrantItem grant_state_item = new DomainObjects.Modifiers.GrantItem();
                grant_state_item.ikey = n.GetAttribute("ikey");
                retval = grant_state_item;
                break;
            }

            case "grant_xp":
            {
                DomainObjects.Modifiers.GrantXp grant_xp = new DomainObjects.Modifiers.GrantXp();
                if (!System.Int32.TryParse(n.GetAttribute("value"), out grant_xp.value))
                {
                    throw new InvalidXMLElementException("Unable to parse grant_xp value to integer");
                }
                retval = grant_xp;
                break;
            }

            case "grant_xp_range":
            {
                DomainObjects.Modifiers.GrantXpRange grant_xp_range = new DomainObjects.Modifiers.GrantXpRange();
                if (!System.Int32.TryParse(n.GetAttribute("min"), out grant_xp_range.min))
                {
                    throw new InvalidXMLElementException("Unable to parse grant_xp_range min to integer");
                }
                if (!System.Int32.TryParse(n.GetAttribute("max"), out grant_xp_range.max))
                {
                    throw new InvalidXMLElementException("Unable to parse grant_xp_range max to integer");
                }
                retval = grant_xp_range;
                break;
            }

            case "random_choice":
            {
                DomainObjects.Modifiers.RandomChoice random_choice = new DomainObjects.Modifiers.RandomChoice();
                random_choice.choices = new List <DomainObjects.Modifiers.RandomChoice.ChoiceEntry>();
                foreach (System.Xml.XmlNode nn in n)
                {
                    if (nn.NodeType != System.Xml.XmlNodeType.Element)
                    {
                        continue;
                    }

                    if (nn.Name == "choice")
                    {
                        DomainObjects.Modifiers.RandomChoice.ChoiceEntry entry = new DomainObjects.Modifiers.RandomChoice.ChoiceEntry();
                        if (!System.Int32.TryParse((nn as System.Xml.XmlElement).GetAttribute("weight"), out entry.weight))
                        {
                            throw new InvalidXMLElementException("Unable to parse choice weight to integer.");
                        }
                        foreach (System.Xml.XmlNode nnn_n in nn)
                        {
                            if (nnn_n.NodeType != System.Xml.XmlNodeType.Element)
                            {
                                continue;
                            }
                            System.Xml.XmlElement nnn = nnn_n as System.Xml.XmlElement;

                            switch (nnn.Name)
                            {
                            case "modifier":
                                entry.modifiers = crm.ParseModifierList(nnn);
                                break;

                            case "requirement":
                                entry.requirements = crm.ParseRequirementList(nnn);
                                break;

                            default:
                                throw new InvalidXMLElementException("Invalid choice element for Random Choice : " + nnn.Name);
                            }
                        }
                        random_choice.choices.Add(entry);
                    }
                    else
                    {
                        throw new InvalidXMLElementException("Invalid Random Choice node : " + nn.Name);
                    }
                }
                retval = random_choice;
                break;
            }

            case "multiple":
            {
                DomainObjects.Modifiers.Multiple m = new DomainObjects.Modifiers.Multiple();
                //TODO: Fill me in!
                retval = m;
                break;
            }

            case "nothing":
            {
                retval = new DomainObjects.Modifiers.Nothing();
                break;
            }

            case "named":
            {
                DomainObjects.Modifiers.NamedReference m = new DomainObjects.Modifiers.NamedReference();
                //TODO: Fill me in!
                retval = m;
                break;
            }

            case "if_then_else":
            {
                DomainObjects.Modifiers.IfThenElse m = new DomainObjects.Modifiers.IfThenElse();
                foreach (System.Xml.XmlNode nn_n in n)
                {
                    if (nn_n.NodeType != System.Xml.XmlNodeType.Element)
                    {
                        continue;
                    }
                    System.Xml.XmlElement nn = nn_n as System.Xml.XmlElement;

                    switch (nn.Name)
                    {
                    case "if":
                        m.if_ = crm.ParseRequirementList(nn);
                        break;

                    case "then":
                        m.then_ = crm.ParseModifierList(nn);
                        break;

                    case "else":
                        m.else_ = crm.ParseModifierList(nn);
                        break;

                    default:
                        throw new InvalidXMLElementException("Invalid if-then-else node : " + nn.Name);
                    }
                }
                retval = m;
                break;
            }

            default:
                throw new InvalidXMLElementException("Invalid modifier type : " + n.Name);
            }
            return(retval);
        }