示例#1
0
        private void loadData()
        {
            XmlTextReader reader = new XmlTextReader(contentPath + "\\Weapons.item");
            reader.WhitespaceHandling = WhitespaceHandling.None;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "Weapon")
                    {
                        weapon.name = reader["Name"];
                        weapon.type = reader["Type"];
                    }
                    if (reader.Name == "Equip")
                    {
                        reader.MoveToFirstAttribute();
                        string[] eachClass = reader.Value.Split(' ');
                        foreach(string s in eachClass)
                            if (!s.Contains(" "))
                            weapon.equipClass.Add(s);
                    }
                    if (reader.Name == "Image")
                        weapon.textureName = contentPath + "\\" + reader["Texture"];
                    if (reader.Name == "Attack")
                        weapon.attack = int.Parse(reader.ReadInnerXml());
                    if (reader.Name == "Acc")
                        weapon.acc = int.Parse(reader.ReadInnerXml());
                    if (reader.Name == "Parry")
                        weapon.parry = int.Parse(reader.ReadInnerXml());
                    if (reader.Name == "Str")
                        weapon.strbonus = int.Parse(reader.ReadInnerXml());
                    if (reader.Name == "Dex")
                        weapon.dexbonus = int.Parse(reader.ReadInnerXml());
                    if (reader.Name == "Agi")
                        weapon.agibonus = int.Parse(reader.ReadInnerXml());
                    if (reader.Name == "Sta")
                        weapon.stabonus = int.Parse(reader.ReadInnerXml());
                    if (reader.Name == "DamageType")
                        weapon.damageType = reader.ReadInnerXml();
                }

                else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Weapon")
                {
                    weaponList.Add(weapon.name, weapon);
                    existingWeaponComboBox.Items.Add(weapon.name);
                    weapon = new Weapon();
                }
            }
            reader.Close();
        }
示例#2
0
        private void loadCheckBoxes()
        {
            int topPosition = 0;
            Skills sk = new Skills();
            Spells sp = new Spells();
            Weapon wea = new Weapon();
            Armor arm = new Armor();

            XmlTextReader reader = new XmlTextReader(contentPath + "\\skills.item");
            reader.WhitespaceHandling = WhitespaceHandling.None;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "Skill")
                    {
                        sk.name = reader["name"];
                        skills.Add(sk);
                        sk = new Skills();
                    }
                }
            }
            reader.Close();
            reader = new XmlTextReader(contentPath + "\\Spells.item");

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "Spell")
                    {
                        sp.name = reader["name"];
                        spells.Add(sp);
                        sp = new Spells();
                    }
                }
            }
            reader.Close();

            this.SuspendLayout();

            foreach (Skills skill in skills)
            {
                CheckBox checkbox = new CheckBox();
                checkbox.Top = topPosition;
                checkbox.Left = 0;
                checkbox.Text = skill.name;
                checkbox.Name = skill.name;
                topPosition += 23;

                skillPanel.Controls.Add(checkbox);
            }

            topPosition = 0;
            foreach (Spells spell in spells)
            {
                CheckBox checkbox = new CheckBox();
                checkbox.Top = topPosition;
                checkbox.Left = 0;
                checkbox.Text = spell.name;
                checkbox.Name = spell.name;
                topPosition += 23;

                spellPanel.Controls.Add(checkbox);
            }

            this.ResumeLayout();
        }
示例#3
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if ( attackDamageTextBox.Text.Length < 1 || accuracyTextBox.Text.Length < 1  ||
                parryTextBox.Text.Length < 1 || strTextBox.Text.Length < 1 ||
                dexListBox.Text.Length < 1 || agiTextBox.Text.Length < 1 ||
                staTextBox.Text.Length < 1 || imageFileTextBox.Text.Length < contentPath.Length + 1)
            {
                MessageBox.Show("Not All Fields Have Values");
                return;
            }

            weapon.name = weaponNameTextBox.Text;
            weapon.type = typeComboBox.Text;
            string[] eachClass = classesTextBox.Text.Split(' ');
            foreach (string c in eachClass)
                weapon.equipClass.Add(c);
            weapon.textureName = imageFileTextBox.Text;
            weapon.attack = int.Parse(attackDamageTextBox.Text);
            weapon.acc = int.Parse(accuracyTextBox.Text);
            weapon.parry = int.Parse(parryTextBox.Text);
            weapon.strbonus = int.Parse(strTextBox.Text);
            weapon.dexbonus = int.Parse(dexListBox.Text);
            weapon.agibonus = int.Parse(agiTextBox.Text);
            weapon.stabonus = int.Parse(staTextBox.Text);
            weapon.damageType = damageTypeComboBox.Text;
            weapon.specialAbility = specialAbilityComboBox.Text;

            if (existingWeaponComboBox.SelectedItem == null)
            {
                weaponList.Add(weapon.name, weapon);
                existingWeaponComboBox.Items.Add(weapon.name);
                existingWeaponComboBox.SelectedItem = weapon.name;
                weapon = new Weapon();
            }
            else
            {
                if (existingWeaponComboBox.Text != weapon.name)
                {
                    weaponList.Add(weapon.name, weapon);
                    weaponList.Remove(existingWeaponComboBox.Text);
                    existingWeaponComboBox.Items.Remove(existingWeaponComboBox.SelectedItem);
                    existingWeaponComboBox.Items.Add(weapon.name);
                    existingWeaponComboBox.SelectedItem = weapon.name;
                }

                else
                    weaponList[weapon.name] = weapon;

                weapon = new Weapon();
            }

            XmlDocument doc = new XmlDocument();

            XmlElement rootElement = doc.CreateElement("Weapons");
            doc.AppendChild(rootElement);

            Dictionary<int, Weapon> sortList = new Dictionary<int, Weapon>();
            foreach (Weapon weap in weaponList.Values)
            {
                int wpn = 1;
                foreach (Weapon wepn in weaponList.Values)
                {
                    if (weap == wepn)
                        continue;
                    if (weap.attack >= wepn.attack)
                        wpn++;
                }
                while (sortList.ContainsKey(wpn))
                    wpn--;
                sortList.Add(wpn, weap);
            }

            for (int wep = 1; wep <= sortList.Keys.Count; wep++)
            {
                Weapon wea = sortList[wep];
                {
                XmlElement weaponElement = doc.CreateElement("Weapon");
                rootElement.AppendChild(weaponElement);
                XmlAttribute wAttr = doc.CreateAttribute("Name");
                wAttr.Value = wea.name;
                XmlAttribute wAttr2 = doc.CreateAttribute("Type");
                wAttr2.Value = wea.type;
                weaponElement.Attributes.Append(wAttr);
                weaponElement.Attributes.Append(wAttr2);
                XmlElement equipElement = doc.CreateElement("Equip");
                weaponElement.AppendChild(equipElement);
                XmlAttribute eAttr = doc.CreateAttribute("Class");
                foreach (string eq in wea.equipClass)
                {
                    eAttr.Value += eq + " ";
                }
                equipElement.Attributes.Append(eAttr);
                XmlElement textureElement = doc.CreateElement("Image");
                weaponElement.AppendChild(textureElement);
                XmlAttribute tAttr = doc.CreateAttribute("Texture");
                tAttr.Value = wea.textureName.Replace(contentPath + "\\", "");
                textureElement.Attributes.Append(tAttr);
                XmlElement attackElement = doc.CreateElement("Attack");
                attackElement.InnerText = wea.attack.ToString();
                weaponElement.AppendChild(attackElement);

                XmlElement accElement = doc.CreateElement("Acc");
                accElement.InnerText = wea.acc.ToString();
                weaponElement.AppendChild(accElement);
                XmlElement parryElement = doc.CreateElement("Parry");
                parryElement.InnerText = wea.parry.ToString();
                weaponElement.AppendChild(parryElement);

                XmlElement attribbonusElement = doc.CreateElement("AttribBonus");
                weaponElement.AppendChild(attribbonusElement);
                XmlElement strElement = doc.CreateElement("Str");
                strElement.InnerText = wea.strbonus.ToString();
                attribbonusElement.AppendChild(strElement);
                XmlElement dexElement = doc.CreateElement("Dex");
                dexElement.InnerText = wea.dexbonus.ToString();
                attribbonusElement.AppendChild(dexElement);
                XmlElement agiElement = doc.CreateElement("Agi");
                agiElement.InnerText = wea.agibonus.ToString();
                attribbonusElement.AppendChild(agiElement);
                XmlElement staElement = doc.CreateElement("Sta");
                staElement.InnerText = wea.stabonus.ToString();
                attribbonusElement.AppendChild(staElement);

                XmlElement dType = doc.CreateElement("DamageType");
                dType.InnerText = wea.damageType;
                weaponElement.AppendChild(dType);
                XmlElement special = doc.CreateElement("Special");
                special.InnerText = wea.specialAbility;
                weaponElement.AppendChild(special);
                }
            }
            doc.Save(contentPath + "\\" + "Weapons.item");
        }