Exemplo n.º 1
0
Arquivo: Body.cs Projeto: bilwis/SH2RL
        private Organ parseOrganDefinition(XmlTextReader reader)
        {
            string name = "ERROR";
            bool exclusive = false;

            List<OrganPart> parts = new List<OrganPart>();
            OrganPart temp = new OrganPart();
            bool readingPart=false;

            temp.critical = false;  //default

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        switch (reader.Name)
                        {
                            case "part":
                                if (readingPart)
                                    throw new Exception("Error while parsing body definition XML: New part element before end part element");
                                readingPart = true;
                                break;
                            case "name":
                                if (!readingPart)
                                    name = reader.ReadElementContentAsString();
                                else
                                    temp.name = reader.ReadElementContentAsString();
                                break;
                            case "exclusive":
                                exclusive = reader.ReadElementContentAsBoolean();
                                break;
                            case "hit_prob":
                                temp.hit_prob = reader.ReadElementContentAsFloat();
                                break;
                            case "pain":
                                temp.pain = reader.ReadElementContentAsFloat();
                                break;
                            case "blood_loss":
                                temp.blood_loss = reader.ReadElementContentAsFloat();
                                break;
                            case "resistance":
                                temp.resistance = reader.ReadElementContentAsFloat();
                                break;
                            case "on_hit_kill":
                                temp.critical = reader.ReadElementContentAsBoolean();
                                break;
                        }
                        break;
                    case XmlNodeType.EndElement:
                        switch (reader.Name)
                        {
                            case "part":
                                readingPart = false;
                                parts.Add(temp);
                                temp = new OrganPart();
                                break;
                            case "organ_def":
                                Organ self = new Organ(name, exclusive);
                                foreach (OrganPart op in parts)
                                {
                                    self.AddPart(op);
                                }
                                return self;
                        }
                        break;
                }
            }

            return null;
        }
Exemplo n.º 2
0
 public void AddPart(OrganPart part)
 {
     parts.Add(part);
 }