private void buttonOK_Click(object sender, EventArgs eventArgs) { ability.Name = textBoxName.Text; ability.SpCost = (Int32)numericUpDownSP.Value; ability.Effects.Clear(); Effect e = null; foreach (DataGridViewRow row in dataGridView1.Rows) { String _type = row.Cells[0].Value.ToString(); int _pow = Int32.Parse(row.Cells[1].Value.ToString()); int _acc = Int32.Parse(row.Cells[2].Value.ToString()); int _crit = Int32.Parse(row.Cells[3].Value.ToString()); switch (_type) { case "pdmg": e = new PhysicalDamage(_pow, _acc, _crit); break; case "mdmg": e = new MagicalDamage(_pow, _acc, _crit); break; case "heal": e = new Heal(_pow, _acc, _crit); break; case "spd": e = new SPDrain(_pow, _acc, _crit); break; case "spr": e = new SPRecovery(_pow, _acc, _crit); break; case "psn": e = new PoisonEnemy(_acc); break; case "psnself": e = new PoisonSelf(_acc); break; case "par": e = new ParalyzeEnemy(_acc); break; case "parself": e = new ParalyzeSelf(_acc); break; case "bli": e = new BlindEnemy(_acc); break; case "bliself": e = new BlindSelf(_acc); break; case "cleanse": e = new Cleanse(); break; } ability.Effects.Add(e); } this.DialogResult = DialogResult.OK; this.Close(); }
public void loadFromXML(String fileName) { XmlDocument doc = new XmlDocument(); doc.Load(fileName); name = doc.SelectSingleNode("//character").Attributes["name"].Value; foreach (XmlNode statNode in doc.SelectNodes("//stat")) { switch (statNode.Attributes["key"].Value) { case "level": level = Int32.Parse(statNode.Attributes["value"].Value); break; case "ATK": ATK = Int32.Parse(statNode.Attributes["value"].Value); break; case "DEF": DEF = Int32.Parse(statNode.Attributes["value"].Value); break; case "VIT": VIT = Int32.Parse(statNode.Attributes["value"].Value); break; case "SKL": SKL = Int32.Parse(statNode.Attributes["value"].Value); break; case "MATK": MATK = Int32.Parse(statNode.Attributes["value"].Value); break; case "MDEF": MDEF = Int32.Parse(statNode.Attributes["value"].Value); break; case "AGI": AGI = Int32.Parse(statNode.Attributes["value"].Value); break; case "LCK": LCK = Int32.Parse(statNode.Attributes["value"].Value); break; } } abilities.Clear(); foreach (XmlNode abilityNode in doc.SelectNodes("//ability")) { Ability a = new Ability(); int _pow, _acc, _crit; a.Name = abilityNode.Attributes["name"].Value; a.SpCost = Int32.Parse(abilityNode.Attributes["sp"].Value); foreach (XmlNode effectNode in doc.SelectNodes("//ability[@name='" + a.Name + "']/effect")) { Effect e = null; String _type = effectNode.Attributes["type"].Value; try { _pow = Int32.Parse(effectNode.Attributes["pow"].Value); } catch (NullReferenceException) { _pow = 0; } try { _acc = Int32.Parse(effectNode.Attributes["acc"].Value); } catch (NullReferenceException) { _acc = 0; } try { _crit = Int32.Parse(effectNode.Attributes["crit"].Value); } catch (NullReferenceException) { _crit = 0; } switch (_type) { case "pdmg": e = new PhysicalDamage(_pow, _acc, _crit); break; case "mdmg": e = new MagicalDamage(_pow, _acc, _crit); break; case "heal": e = new Heal(_pow, _acc, _crit); break; case "spd": e = new SPDrain(_pow, _acc, _crit); break; case "spr": e = new SPRecovery(_pow, _acc, _crit); break; case "psn": e = new PoisonEnemy(_acc); break; case "psnself": e = new PoisonSelf(_acc); break; case "par": e = new ParalyzeEnemy(_acc); break; case "parself": e = new ParalyzeSelf(_acc); break; case "bli": e = new BlindEnemy(_acc); break; case "bliself": e = new BlindSelf(_acc); break; case "cleanse": e = new Cleanse(); break; } a.Effects.Add(e); } abilities.Add(a); } reset(); selectedAbility = abilities[0]; }