public frmCreateSpell(Character objCharacter) { _objCharacter = objCharacter; _objSpell = new Spell(_objCharacter); InitializeComponent(); LanguageManager.Instance.Load(GlobalOptions.Instance.Language, this); _objXmlDocument = XmlManager.Instance.Load("spells.xml"); MoveControls(); }
private void cmdAddSpell_Click(object sender, EventArgs e) { frmSelectSpell frmPickSpell = new frmSelectSpell(_objCharacter); frmPickSpell.ExpandedCategories = lstExpandSpellCategories; frmPickSpell.ShowDialog(this); // Make sure the dialogue window was not canceled. if (frmPickSpell.DialogResult == DialogResult.Cancel) return; // Open the Spells XML file and locate the selected piece. XmlDocument objXmlDocument = XmlManager.Instance.Load("spells.xml"); XmlNode objXmlSpell = objXmlDocument.SelectSingleNode("/chummer/spells/spell[name = \"" + frmPickSpell.SelectedSpell + "\"]"); lstExpandSpellCategories = frmPickSpell.ExpandedCategories; Spell objSpell = new Spell(_objCharacter); TreeNode objNode = new TreeNode(); objSpell.Create(objXmlSpell, _objCharacter, objNode, "", frmPickSpell.Limited, frmPickSpell.Extended, frmPickSpell.Alchemical); objNode.ContextMenuStrip = cmsSpell; if (objSpell.InternalId == Guid.Empty.ToString()) return; _objCharacter.Spells.Add(objSpell); switch (objSpell.Category) { case "Combat": treSpells.Nodes[0].Nodes.Add(objNode); treSpells.Nodes[0].Expand(); break; case "Detection": treSpells.Nodes[1].Nodes.Add(objNode); treSpells.Nodes[1].Expand(); break; case "Health": treSpells.Nodes[2].Nodes.Add(objNode); treSpells.Nodes[2].Expand(); break; case "Illusion": treSpells.Nodes[3].Nodes.Add(objNode); treSpells.Nodes[3].Expand(); break; case "Manipulation": treSpells.Nodes[4].Nodes.Add(objNode); treSpells.Nodes[4].Expand(); break; case "Rituals": int intNode = 5; if (_objCharacter.AdeptEnabled && !_objCharacter.MagicianEnabled) intNode = 0; treSpells.Nodes[intNode].Nodes.Add(objNode); treSpells.Nodes[intNode].Expand(); break; } treSpells.SelectedNode = objNode; treSpells.SortCustom(); UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); int intSpellCount = 0; foreach (TreeNode nodCategory in treSpells.Nodes) { foreach (TreeNode nodSpell in nodCategory.Nodes) { intSpellCount++; } } //if (intSpellCount - _objCharacter.SpellLimit > 0) // lblPBuildSpells.Text = String.Format("{0} " + LanguageManager.Instance.GetString("String_Of") + " {1}", (0).ToString(), _objCharacter.SpellLimit.ToString()); //else lblPBuildSpells.Text = String.Format("{0} " + LanguageManager.Instance.GetString("String_Of") + " {1}", (_objCharacter.SpellLimit - intSpellCount).ToString(), _objCharacter.SpellLimit.ToString()); if (frmPickSpell.AddAgain) { cmdAddSpell_Click(sender, e); } }
private void tsMetamagicAddRitual_Click(object sender, EventArgs e) { if (treMetamagic.SelectedNode.Level != 0) return; int intGrade = 0; foreach (InitiationGrade objGrade in _objCharacter.InitiationGrades) { if (objGrade.InternalId == treMetamagic.SelectedNode.Tag.ToString()) { intGrade = objGrade.Grade; break; } } frmSelectArt frmPickArt = new frmSelectArt(_objCharacter); frmPickArt.WindowMode = frmSelectArt.Mode.Ritual; frmPickArt.ShowDialog(this); // Make sure a value was selected. if (frmPickArt.DialogResult == DialogResult.Cancel) return; string strEnchantment = frmPickArt.SelectedItem; XmlDocument objXmlDocument = new XmlDocument(); XmlNode objXmlArt; TreeNode objNode = new TreeNode(); Spell objNewSpell = new Spell(_objCharacter); Improvement.ImprovementSource objSource; objXmlDocument = XmlManager.Instance.Load("spells.xml"); objXmlArt = objXmlDocument.SelectSingleNode("/chummer/spells/spell[name = \"" + strEnchantment + "\"]"); objSource = Improvement.ImprovementSource.Initiation; objNewSpell.Create(objXmlArt, _objCharacter, objNode, "", false, false, false, objSource); objNewSpell.Grade = intGrade; objNode.ContextMenuStrip = cmsInitiationNotes; if (objNewSpell.InternalId == Guid.Empty.ToString()) return; _objCharacter.Spells.Add(objNewSpell); TreeNode objSpellNode = new TreeNode(); objSpellNode.Text = objNode.Text; objSpellNode.Tag = objNode.Tag; string strCategory = ""; if (objNewSpell.Category == "Rituals") strCategory = LanguageManager.Instance.GetString("Label_Ritual") + " "; if (objNewSpell.Category == "Enchantments") strCategory = LanguageManager.Instance.GetString("Label_Enchantment") + " "; objNode.Text = strCategory + objNode.Text; treMetamagic.SelectedNode.Nodes.Add(objNode); treMetamagic.SelectedNode.Expand(); int intNode = 5; if (!_objCharacter.MagicianEnabled) intNode = 0; treSpells.Nodes[intNode].Nodes.Add(objSpellNode); treSpells.Nodes[intNode].Expand(); UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); }
/// <summary> /// Add a PACKS Kit to the character. /// </summary> public void AddPACKSKit() { frmSelectPACKSKit frmPickPACKSKit = new frmSelectPACKSKit(_objCharacter); frmPickPACKSKit.ShowDialog(this); bool blnCreateChildren = true; // If the form was canceled, don't do anything. if (frmPickPACKSKit.DialogResult == DialogResult.Cancel) return; XmlDocument objXmlDocument = XmlManager.Instance.Load("packs.xml"); // Do not create child items for Gear if the chosen Kit is in the Custom category since these items will contain the exact plugins desired. if (frmPickPACKSKit.SelectedCategory == "Custom") blnCreateChildren = false; XmlNode objXmlKit = objXmlDocument.SelectSingleNode("/chummer/packs/pack[name = \"" + frmPickPACKSKit.SelectedKit + "\" and category = \"" + frmPickPACKSKit.SelectedCategory + "\"]"); // Update Qualities. if (objXmlKit["qualities"] != null) { XmlDocument objXmlQualityDocument = XmlManager.Instance.Load("qualities.xml"); // Positive Qualities. foreach (XmlNode objXmlQuality in objXmlKit.SelectNodes("qualities/positive/quality")) { XmlNode objXmlQualityNode = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQuality.InnerText + "\"]"); TreeNode objNode = new TreeNode(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); Quality objQuality = new Quality(_objCharacter); string strForceValue = ""; if (objXmlQuality.Attributes["select"] != null) strForceValue = objXmlQuality.Attributes["select"].InnerText; objQuality.Create(objXmlQualityNode, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes, strForceValue); _objCharacter.Qualities.Add(objQuality); treQualities.Nodes[0].Nodes.Add(objNode); treQualities.Nodes[0].Expand(); // Add any created Weapons to the character. foreach (Weapon objWeapon in objWeapons) _objCharacter.Weapons.Add(objWeapon); // Create the Weapon Node if one exists. foreach (TreeNode objWeaponNode in objWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } } // Negative Qualities. foreach (XmlNode objXmlQuality in objXmlKit.SelectNodes("qualities/negative/quality")) { XmlNode objXmlQualityNode = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQuality.InnerText + "\"]"); TreeNode objNode = new TreeNode(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); Quality objQuality = new Quality(_objCharacter); string strForceValue = ""; if (objXmlQuality.Attributes["select"] != null) strForceValue = objXmlQuality.Attributes["select"].InnerText; objQuality.Create(objXmlQualityNode, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes, strForceValue); _objCharacter.Qualities.Add(objQuality); treQualities.Nodes[1].Nodes.Add(objNode); treQualities.Nodes[1].Expand(); // Add any created Weapons to the character. foreach (Weapon objWeapon in objWeapons) _objCharacter.Weapons.Add(objWeapon); // Create the Weapon Node if one exists. foreach (TreeNode objWeaponNode in objWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } } } // Update Attributes. if (objXmlKit["attributes"] != null) { // Reset all Attributes back to 1 so we don't go over any BP limits. nudBOD.Value = nudBOD.Minimum; nudAGI.Value = nudAGI.Minimum; nudREA.Value = nudREA.Minimum; nudSTR.Value = nudSTR.Minimum; nudCHA.Value = nudCHA.Minimum; nudINT.Value = nudINT.Minimum; nudLOG.Value = nudLOG.Minimum; nudWIL.Value = nudWIL.Minimum; nudEDG.Value = nudEDG.Minimum; nudMAG.Value = nudMAG.Minimum; nudRES.Value = nudRES.Minimum; foreach (XmlNode objXmlAttribute in objXmlKit["attributes"]) { // The Attribute is calculated as given value - (6 - Metatype Maximum) so that each Metatype has the values from the file adjusted correctly. switch (objXmlAttribute.Name) { case "bod": nudBOD.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.BOD.MetatypeMaximum); break; case "agi": nudAGI.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.AGI.MetatypeMaximum); break; case "rea": nudREA.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.REA.MetatypeMaximum); break; case "str": nudSTR.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.STR.MetatypeMaximum); break; case "cha": nudCHA.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.CHA.MetatypeMaximum); break; case "int": nudINT.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.INT.MetatypeMaximum); break; case "log": nudLOG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.LOG.MetatypeMaximum); break; case "wil": nudWIL.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.WIL.MetatypeMaximum); break; case "mag": nudMAG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.MAG.MetatypeMaximum); break; case "res": nudRES.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.RES.MetatypeMaximum); break; default: nudEDG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.EDG.MetatypeMaximum); break; } } } // Update Skills. if (objXmlKit["skills"] != null) { // Active Skills. foreach (XmlNode objXmlSkill in objXmlKit.SelectNodes("skills/skill")) { if (objXmlSkill["name"].InnerText.Contains("Exotic")) { int i = panActiveSkills.Controls.Count; Skill objSkill = new Skill(_objCharacter); SkillControl objSkillControl = new SkillControl(_objCharacter); objSkillControl.SkillObject = objSkill; objSkillControl.Width = 510; // Attach an EventHandler for the RatingChanged and SpecializationChanged Events. objSkillControl.RatingChanged += objActiveSkill_RatingChanged; objSkillControl.SpecializationChanged += objSkill_SpecializationChanged; objSkillControl.SkillName = objXmlSkill["name"].InnerText; switch (objXmlSkill["name"].InnerText) { case "Exotic Ranged Weapon": case "Exotic Melee Weapon": objSkill.Attribute = "AGI"; objSkillControl.SkillCategory = "Combat Active"; objSkill.Default = true; break; default: objSkill.Attribute = "REA"; objSkillControl.SkillCategory = "Vehicle Active"; objSkill.Default = false; break; } objSkill.ExoticSkill = true; _objCharacter.Skills.Add(objSkill); if (_objCharacter.IgnoreRules) { objSkillControl.SkillRatingMaximum = 12; } else { objSkillControl.SkillRatingMaximum = 6; } // Make sure it's not going above the maximum number. if (Convert.ToInt32(objXmlSkill["rating"].InnerText) > objSkillControl.SkillRatingMaximum) objSkillControl.SkillRating = objSkillControl.SkillRatingMaximum; else objSkillControl.SkillRating = Convert.ToInt32(objXmlSkill["rating"].InnerText); if (objXmlSkill["spec"] != null) objSkillControl.SkillSpec = objXmlSkill["spec"].InnerText; else objSkillControl.SkillSpec = ""; // Set the SkillControl's Location since scrolling the Panel causes it to actually change the child Controls' Locations. objSkillControl.Location = new Point(0, objSkillControl.Height * i + panActiveSkills.AutoScrollPosition.Y); panActiveSkills.Controls.Add(objSkillControl); } else { // Find the correct Skill Control. SkillControl objSkillControl = new SkillControl(_objCharacter); foreach (SkillControl objControl in panActiveSkills.Controls) { if (objControl.SkillName == objXmlSkill["name"].InnerText) { objSkillControl = objControl; break; } } // Make sure it's not going above the maximum number. if (Convert.ToInt32(objXmlSkill["rating"].InnerText) > objSkillControl.SkillRatingMaximum) objSkillControl.SkillRating = objSkillControl.SkillRatingMaximum; else objSkillControl.SkillRating = Convert.ToInt32(objXmlSkill["rating"].InnerText); if (objXmlSkill["spec"] != null) objSkillControl.SkillSpec = objXmlSkill["spec"].InnerText; else objSkillControl.SkillSpec = ""; } } // Skill Groups. foreach (XmlNode objXmlGroup in objXmlKit.SelectNodes("skills/skillgroup")) { // Find the correct SkillGroupControl. SkillGroupControl objSkillGroupControl = new SkillGroupControl(_objCharacter.Options, _objCharacter); foreach (SkillGroupControl objControl in panSkillGroups.Controls) { if (objControl.GroupName == objXmlGroup["name"].InnerText) { objSkillGroupControl = objControl; break; } } // Make sure it's not going above the maximum number. if (Convert.ToInt32(objXmlGroup["base"].InnerText) > objSkillGroupControl.GroupRatingMaximum) { objSkillGroupControl.BaseRating = objSkillGroupControl.GroupRatingMaximum; objSkillGroupControl.KarmaRating = 0; } else if (Convert.ToInt32(objXmlGroup["base"].InnerText) + Convert.ToInt32(objXmlGroup["karma"].InnerText) > objSkillGroupControl.GroupRatingMaximum) { objSkillGroupControl.BaseRating = Convert.ToInt32(objXmlGroup["base"].InnerText); objSkillGroupControl.KarmaRating = objSkillGroupControl.GroupRatingMaximum - objSkillGroupControl.BaseRating; } else { objSkillGroupControl.BaseRating = Convert.ToInt32(objXmlGroup["base"].InnerText); objSkillGroupControl.KarmaRating = Convert.ToInt32(objXmlGroup["karma"].InnerText); } } } // Update Knowledge Skills. if (objXmlKit["knowledgeskills"] != null) { foreach (XmlNode objXmlSkill in objXmlKit.SelectNodes("knowledgeskills/skill")) { int i = panKnowledgeSkills.Controls.Count; Skill objSkill = new Skill(_objCharacter); objSkill.Name = objXmlSkill["name"].InnerText; SkillControl objSkillControl = new SkillControl(_objCharacter); objSkillControl.SkillObject = objSkill; // Attach an EventHandler for the RatingChanged and SpecializationChanged Events. objSkillControl.RatingChanged += objKnowledgeSkill_RatingChanged; objSkillControl.SpecializationChanged += objSkill_SpecializationChanged; objSkillControl.DeleteSkill += objKnowledgeSkill_DeleteSkill; objSkillControl.KnowledgeSkill = true; objSkillControl.AllowDelete = true; if (_objCharacter.IgnoreRules) { objSkillControl.SkillRatingMaximum = 12; } else { objSkillControl.SkillRatingMaximum = 6; } // Set the SkillControl's Location since scrolling the Panel causes it to actually change the child Controls' Locations. objSkillControl.Location = new Point(0, objSkillControl.Height * i + panKnowledgeSkills.AutoScrollPosition.Y); panKnowledgeSkills.Controls.Add(objSkillControl); objSkillControl.SkillName = objXmlSkill["name"].InnerText; // Make sure it's not going above the maximum number. if (Convert.ToInt32(objXmlSkill["rating"].InnerText) > objSkillControl.SkillRatingMaximum) objSkillControl.SkillRating = objSkillControl.SkillRatingMaximum; else objSkillControl.SkillRating = Convert.ToInt32(objXmlSkill["rating"].InnerText); if (objXmlSkill["spec"] != null) objSkillControl.SkillSpec = objXmlSkill["spec"].InnerText; else objSkillControl.SkillSpec = ""; if (objXmlSkill["category"] != null) objSkillControl.SkillCategory = objXmlSkill["category"].InnerText; _objCharacter.Skills.Add(objSkill); } } // Select a Martial Art. if (objXmlKit["selectmartialart"] != null) { string strForcedValue = ""; int intRating = 1; if (objXmlKit["selectmartialart"].Attributes["select"] != null) strForcedValue = objXmlKit["selectmartialart"].Attributes["select"].InnerText; if (objXmlKit["selectmartialart"].Attributes["rating"] != null) intRating = Convert.ToInt32(objXmlKit["selectmartialart"].Attributes["rating"].InnerText); frmSelectMartialArt frmPickMartialArt = new frmSelectMartialArt(_objCharacter); frmPickMartialArt.ForcedValue = strForcedValue; frmPickMartialArt.ShowDialog(this); if (frmPickMartialArt.DialogResult != DialogResult.Cancel) { // Open the Martial Arts XML file and locate the selected piece. XmlDocument objXmlMartialArtDocument = XmlManager.Instance.Load("martialarts.xml"); XmlNode objXmlArt = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + frmPickMartialArt.SelectedMartialArt + "\"]"); TreeNode objNode = new TreeNode(); MartialArt objMartialArt = new MartialArt(_objCharacter); objMartialArt.Create(objXmlArt, objNode, _objCharacter); objMartialArt.Rating = intRating; _objCharacter.MartialArts.Add(objMartialArt); objNode.ContextMenuStrip = cmsMartialArts; treMartialArts.Nodes[0].Nodes.Add(objNode); treMartialArts.Nodes[0].Expand(); treMartialArts.SelectedNode = objNode; } } // Update Martial Arts. if (objXmlKit["martialarts"] != null) { // Open the Martial Arts XML file and locate the selected art. XmlDocument objXmlMartialArtDocument = XmlManager.Instance.Load("martialarts.xml"); foreach (XmlNode objXmlArt in objXmlKit.SelectNodes("martialarts/martialart")) { TreeNode objNode = new TreeNode(); MartialArt objArt = new MartialArt(_objCharacter); XmlNode objXmlArtNode = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + objXmlArt["name"].InnerText + "\"]"); objArt.Create(objXmlArtNode, objNode, _objCharacter); objArt.Rating = Convert.ToInt32(objXmlArt["rating"].InnerText); _objCharacter.MartialArts.Add(objArt); // Check for Advantages. foreach (XmlNode objXmlAdvantage in objXmlArt.SelectNodes("techniques/technique")) { TreeNode objChildNode = new TreeNode(); MartialArtAdvantage objAdvantage = new MartialArtAdvantage(_objCharacter); XmlNode objXmlAdvantageNode = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + objXmlArt["name"].InnerText + "\"]/techniques/technique[. = \"" + objXmlAdvantage.InnerText + "\"]"); objAdvantage.Create(objXmlAdvantageNode, _objCharacter, objChildNode); objArt.Advantages.Add(objAdvantage); objNode.Nodes.Add(objChildNode); objNode.Expand(); } treMartialArts.Nodes[0].Nodes.Add(objNode); treMartialArts.Nodes[0].Expand(); } } // Update Adept Powers. if (objXmlKit["powers"] != null) { // Open the Powers XML file and locate the selected power. XmlDocument objXmlPowerDocument = XmlManager.Instance.Load("powers.xml"); foreach (XmlNode objXmlPower in objXmlKit.SelectNodes("powers/power")) { XmlNode objXmlPowerNode = objXmlPowerDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower["name"].InnerText + "\"]"); int i = panPowers.Controls.Count; Power objPower = new Power(_objCharacter); _objCharacter.Powers.Add(objPower); PowerControl objPowerControl = new PowerControl(); objPowerControl.PowerObject = objPower; // Attach an EventHandler for the PowerRatingChanged Event. objPowerControl.PowerRatingChanged += objPower_PowerRatingChanged; objPowerControl.DeletePower += objPower_DeletePower; objPowerControl.PowerName = objXmlPowerNode["name"].InnerText; objPowerControl.PointsPerLevel = Convert.ToDecimal(objXmlPowerNode["points"].InnerText, GlobalOptions.Instance.CultureInfo); objPowerControl.AdeptWayDiscount = Convert.ToDecimal(objXmlPowerNode["adeptway"].InnerText, GlobalOptions.Instance.CultureInfo); if (objXmlPowerNode["levels"].InnerText == "no") { objPowerControl.LevelEnabled = false; } else { objPowerControl.LevelEnabled = true; if (objXmlPowerNode["levels"].InnerText != "yes") objPower.MaxLevels = Convert.ToInt32(objXmlPowerNode["levels"].InnerText); } objPower.Source = objXmlPowerNode["source"].InnerText; objPower.Page = objXmlPowerNode["page"].InnerText; if (objXmlPowerNode["doublecost"] != null) objPower.DoubleCost = false; if (objXmlPowerNode.InnerXml.Contains("bonus")) { objPower.Bonus = objXmlPowerNode["bonus"]; if (objXmlPower["name"].Attributes["select"] != null) _objImprovementManager.ForcedValue = objXmlPower["name"].Attributes["select"].InnerText; _objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Power, objPower.InternalId, objPower.Bonus, false, Convert.ToInt32(objPower.Rating), objPower.DisplayNameShort); objPowerControl.Extra = _objImprovementManager.SelectedValue; } objPowerControl.Top = i * objPowerControl.Height; panPowers.Controls.Add(objPowerControl); // Set the Rating of the Power if applicable. if (objXmlPower["rating"] != null) objPowerControl.PowerLevel = Convert.ToInt32(objXmlPower["rating"].InnerText); } } // Update Complex Forms. if (objXmlKit["programs"] != null) { // Open the Programs XML file and locate the selected program. XmlDocument objXmlProgramDocument = XmlManager.Instance.Load("complexforms.xml"); foreach (XmlNode objXmlProgram in objXmlKit.SelectNodes("complexforms/complexform")) { XmlNode objXmlProgramNode = objXmlProgramDocument.SelectSingleNode("/chummer/complexforms/complexform[name = \"" + objXmlProgram["name"].InnerText + "\"]"); string strForceValue = ""; if (objXmlProgram.Attributes["select"] != null) strForceValue = objXmlProgram.Attributes["select"].InnerText; TreeNode objNode = new TreeNode(); ComplexForm objProgram = new ComplexForm(_objCharacter); objProgram.Create(objXmlProgramNode, _objCharacter, objNode, strForceValue); treComplexForms.Nodes[0].Nodes.Add(objNode); treComplexForms.Nodes[0].Expand(); _objCharacter.ComplexForms.Add(objProgram); treComplexForms.SortCustom(); } } // Update Spells. if (objXmlKit["spells"] != null) { XmlDocument objXmlSpellDocument = XmlManager.Instance.Load("spells.xml"); foreach (XmlNode objXmlSpell in objXmlKit.SelectNodes("spells/spell")) { // Make sure the Spell has not already been added to the character. bool blnFound = false; foreach (TreeNode nodSpell in treSpells.Nodes[0].Nodes) { if (nodSpell.Text == objXmlSpell.InnerText) { blnFound = true; break; } } // The Spell is not in the list, so add it. if (!blnFound) { string strForceValue = ""; if (objXmlSpell.Attributes["select"] != null) strForceValue = objXmlSpell.Attributes["select"].InnerText; XmlNode objXmlSpellNode = objXmlSpellDocument.SelectSingleNode("/chummer/spells/spell[name = \"" + objXmlSpell.InnerText + "\"]"); Spell objSpell = new Spell(_objCharacter); TreeNode objNode = new TreeNode(); objSpell.Create(objXmlSpellNode, _objCharacter, objNode, strForceValue); objNode.ContextMenuStrip = cmsSpell; _objCharacter.Spells.Add(objSpell); switch (objSpell.Category) { case "Combat": treSpells.Nodes[0].Nodes.Add(objNode); treSpells.Nodes[0].Expand(); break; case "Detection": treSpells.Nodes[1].Nodes.Add(objNode); treSpells.Nodes[1].Expand(); break; case "Health": treSpells.Nodes[2].Nodes.Add(objNode); treSpells.Nodes[2].Expand(); break; case "Illusion": treSpells.Nodes[3].Nodes.Add(objNode); treSpells.Nodes[3].Expand(); break; case "Manipulation": treSpells.Nodes[4].Nodes.Add(objNode); treSpells.Nodes[4].Expand(); break; case "Rituals": int intNode = 5; if (_objCharacter.AdeptEnabled && !_objCharacter.MagicianEnabled) intNode = 0; treSpells.Nodes[intNode].Nodes.Add(objNode); treSpells.Nodes[intNode].Expand(); break; } treSpells.SortCustom(); } } } // Update Spirits. if (objXmlKit["spirits"] != null) { foreach (XmlNode objXmlSpirit in objXmlKit.SelectNodes("spirits/spirit")) { int i = panSpirits.Controls.Count; Spirit objSpirit = new Spirit(_objCharacter); _objCharacter.Spirits.Add(objSpirit); SpiritControl objSpiritControl = new SpiritControl(); objSpiritControl.SpiritObject = objSpirit; objSpiritControl.EntityType = SpiritType.Spirit; // Attach an EventHandler for the ServicesOwedChanged Event. objSpiritControl.ServicesOwedChanged += objSpirit_ServicesOwedChanged; objSpiritControl.ForceChanged += objSpirit_ForceChanged; objSpiritControl.BoundChanged += objSpirit_BoundChanged; objSpiritControl.DeleteSpirit += objSpirit_DeleteSpirit; objSpiritControl.Name = objXmlSpirit["name"].InnerText; objSpiritControl.Force = Convert.ToInt32(objXmlSpirit["force"].InnerText); objSpiritControl.ServicesOwed = Convert.ToInt32(objXmlSpirit["services"].InnerText); objSpiritControl.Top = i * objSpiritControl.Height; panSpirits.Controls.Add(objSpiritControl); } } // Update Lifestyles. if (objXmlKit["lifestyles"] != null) { XmlDocument objXmlLifestyleDocument = XmlManager.Instance.Load("lifestyles.xml"); foreach (XmlNode objXmlLifestyle in objXmlKit.SelectNodes("lifestyles/lifestyle")) { string strName = objXmlLifestyle["name"].InnerText; int intMonths = Convert.ToInt32(objXmlLifestyle["months"].InnerText); // Create the Lifestyle. TreeNode objNode = new TreeNode(); Lifestyle objLifestyle = new Lifestyle(_objCharacter); XmlNode objXmlLifestyleNode = objXmlLifestyleDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + strName + "\"]"); if (objXmlLifestyleNode != null) { // This is a standard Lifestyle, so just use the Create method. objLifestyle.Create(objXmlLifestyleNode, objNode); objLifestyle.Months = intMonths; } else { // This is an Advanced Lifestyle, so build it manually. objLifestyle.Name = strName; objLifestyle.Months = intMonths; objLifestyle.Cost = Convert.ToInt32(objXmlLifestyle["cost"].InnerText); objLifestyle.Dice = Convert.ToInt32(objXmlLifestyle["dice"].InnerText); objLifestyle.Multiplier = Convert.ToInt32(objXmlLifestyle["multiplier"].InnerText); objLifestyle.BaseLifestyle = objXmlLifestyle["baselifestyle"].InnerText; objLifestyle.Source = "SR5"; objLifestyle.Page = "373"; objLifestyle.Comforts = Convert.ToInt32(objXmlLifestyle["comforts"].InnerText); objLifestyle.ComfortsEntertainment = Convert.ToInt32(objXmlLifestyle["comfortsentertainment"].InnerText); objLifestyle.Security = Convert.ToInt32(objXmlLifestyle["security"].InnerText); objLifestyle.SecurityEntertainment = Convert.ToInt32(objXmlLifestyle["securityentertainment"].InnerText); objLifestyle.Area = Convert.ToInt32(objXmlLifestyle["area"].InnerText); objLifestyle.AreaEntertainment = Convert.ToInt32(objXmlLifestyle["areaentertainment"].InnerText); foreach (LifestyleQuality objXmlQuality in objXmlLifestyle.SelectNodes("lifestylequalities/lifestylequality")) objLifestyle.LifestyleQualities.Add(objXmlQuality); objNode.Text = strName; } // Add the Lifestyle to the character and Lifestyle Tree. if (objLifestyle.BaseLifestyle != "") objNode.ContextMenuStrip = cmsAdvancedLifestyle; else objNode.ContextMenuStrip = cmsLifestyleNotes; _objCharacter.Lifestyles.Add(objLifestyle); treLifestyles.Nodes[0].Nodes.Add(objNode); treLifestyles.Nodes[0].Expand(); } } // Update NuyenBP. if (objXmlKit["nuyenbp"] != null) { int intAmount = Convert.ToInt32(objXmlKit["nuyenbp"].InnerText); //if (_objCharacter.BuildMethod == CharacterBuildMethod.Karma) //intAmount *= 2; // Make sure we don't go over the field's maximum which would throw an Exception. if (nudNuyen.Value + intAmount > nudNuyen.Maximum) nudNuyen.Value = nudNuyen.Maximum; else nudNuyen.Value += intAmount; } // Update Armor. if (objXmlKit["armors"] != null) { XmlDocument objXmlArmorDocument = XmlManager.Instance.Load("armor.xml"); foreach (XmlNode objXmlArmor in objXmlKit.SelectNodes("armors/armor")) { XmlNode objXmlArmorNode = objXmlArmorDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + objXmlArmor["name"].InnerText + "\"]"); Armor objArmor = new Armor(_objCharacter); TreeNode objNode = new TreeNode(); objArmor.Create(objXmlArmorNode, objNode, cmsArmorMod, Convert.ToInt32(objXmlArmor["rating"].InnerText), false, blnCreateChildren); _objCharacter.Armor.Add(objArmor); // Look for Armor Mods. if (objXmlArmor["mods"] != null) { foreach (XmlNode objXmlMod in objXmlArmor.SelectNodes("mods/mod")) { List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); XmlNode objXmlModNode = objXmlArmorDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]"); ArmorMod objMod = new ArmorMod(_objCharacter); TreeNode objModNode = new TreeNode(); int intRating = 0; if (objXmlMod["rating"] != null) intRating = Convert.ToInt32(objXmlMod["rating"].InnerText); objMod.Create(objXmlModNode, objModNode, intRating, lstWeapons, lstWeaponNodes); objModNode.ContextMenuStrip = cmsArmorMod; objMod.Parent = objArmor; objArmor.ArmorMods.Add(objMod); objNode.Nodes.Add(objModNode); objNode.Expand(); // Add any Weapons created by the Mod. foreach (Weapon objWeapon in lstWeapons) _objCharacter.Weapons.Add(objWeapon); foreach (TreeNode objWeaponNode in lstWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } } } XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlArmor.SelectNodes("gears/gear")) AddPACKSGear(objXmlGearDocument, objXmlGear, objNode, objArmor, cmsArmorGear, blnCreateChildren); objNode.ContextMenuStrip = cmsArmor; treArmor.Nodes[0].Nodes.Add(objNode); treArmor.Nodes[0].Expand(); } } // Update Weapons. if (objXmlKit["weapons"] != null) { XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("weapons/weapon").Count; int i = 0; foreach (XmlNode objXmlWeapon in objXmlKit.SelectNodes("weapons/weapon")) { i++; pgbProgress.Value = i; Application.DoEvents(); XmlNode objXmlWeaponNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["name"].InnerText + "\"]"); Weapon objWeapon = new Weapon(_objCharacter); TreeNode objNode = new TreeNode(); objWeapon.Create(objXmlWeaponNode, _objCharacter, objNode, cmsWeapon, cmsWeaponAccessory, cmsWeaponMod, blnCreateChildren); _objCharacter.Weapons.Add(objWeapon); // Look for Weapon Accessories. if (objXmlWeapon["accessories"] != null) { foreach (XmlNode objXmlAccessory in objXmlWeapon.SelectNodes("accessories/accessory")) { XmlNode objXmlAccessoryNode = objXmlWeaponDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + objXmlAccessory["name"].InnerText + "\"]"); WeaponAccessory objMod = new WeaponAccessory(_objCharacter); TreeNode objModNode = new TreeNode(); string strMount = ""; int intRating = 0; if (objXmlAccessory["mount"] != null) strMount = objXmlAccessory["mount"].InnerText; objMod.Create(objXmlAccessoryNode, objModNode, strMount, intRating); objModNode.ContextMenuStrip = cmsWeaponAccessory; objMod.Parent = objWeapon; objWeapon.WeaponAccessories.Add(objMod); XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlAccessory.SelectNodes("gears/gear")) AddPACKSGear(objXmlGearDocument, objXmlGear, objModNode, objMod, cmsWeaponAccessoryGear, blnCreateChildren); objNode.Nodes.Add(objModNode); objNode.Expand(); } } // Look for Weapon Mods. if (objXmlWeapon["mods"] != null) { foreach (XmlNode objXmlMod in objXmlWeapon.SelectNodes("mods/mod")) { XmlNode objXmlModNode = objXmlWeaponDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]"); WeaponMod objMod = new WeaponMod(_objCharacter); TreeNode objModNode = new TreeNode(); objMod.Create(objXmlModNode, objModNode); objModNode.ContextMenuStrip = cmsWeaponMod; objMod.Parent = objWeapon; objWeapon.WeaponMods.Add(objMod); objNode.Nodes.Add(objModNode); objNode.Expand(); } } // Look for an Underbarrel Weapon. if (objXmlWeapon["underbarrel"] != null) { XmlNode objXmlUnderbarrelNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["underbarrel"].InnerText + "\"]"); Weapon objUnderbarrelWeapon = new Weapon(_objCharacter); TreeNode objUnderbarrelNode = new TreeNode(); objUnderbarrelWeapon.Create(objXmlUnderbarrelNode, _objCharacter, objUnderbarrelNode, cmsWeapon, cmsWeaponAccessory, cmsWeaponMod, blnCreateChildren); objWeapon.UnderbarrelWeapons.Add(objUnderbarrelWeapon); objNode.Nodes.Add(objUnderbarrelNode); objNode.Expand(); } objNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objNode); treWeapons.Nodes[0].Expand(); Application.DoEvents(); } } // Update Cyberware. if (objXmlKit["cyberwares"] != null) { XmlDocument objXmlCyberwareDocument = XmlManager.Instance.Load("cyberware.xml"); XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("cyberwares/cyberware").Count; int i = 0; foreach (XmlNode objXmlCyberware in objXmlKit.SelectNodes("cyberwares/cyberware")) { i++; pgbProgress.Value = i; Application.DoEvents(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); TreeNode objNode = new TreeNode(); Cyberware objCyberware = new Cyberware(_objCharacter); Grade objGrade = objCyberware.ConvertToCyberwareGrade(objXmlCyberware["grade"].InnerText, Improvement.ImprovementSource.Cyberware); int intRating = 0; if (objXmlCyberware["rating"] != null) intRating = Convert.ToInt32(objXmlCyberware["rating"].InnerText); XmlNode objXmlCyberwareNode = objXmlCyberwareDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + objXmlCyberware["name"].InnerText + "\"]"); objCyberware.Create(objXmlCyberwareNode, _objCharacter, objGrade, Improvement.ImprovementSource.Cyberware, intRating, objNode, objWeapons, objWeaponNodes, true, blnCreateChildren); _objCharacter.Cyberware.Add(objCyberware); // Add any children. if (objXmlCyberware["cyberwares"] != null) { foreach (XmlNode objXmlChild in objXmlCyberware.SelectNodes("cyberwares/cyberware")) { TreeNode objChildNode = new TreeNode(); Cyberware objChildCyberware = new Cyberware(_objCharacter); int intChildRating = 0; if (objXmlChild["rating"] != null) intChildRating = Convert.ToInt32(objXmlChild["rating"].InnerText); XmlNode objXmlChildNode = objXmlCyberwareDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + objXmlChild["name"].InnerText + "\"]"); objChildCyberware.Create(objXmlChildNode, _objCharacter, objGrade, Improvement.ImprovementSource.Cyberware, intChildRating, objChildNode, objWeapons, objWeaponNodes, true, blnCreateChildren); objCyberware.Children.Add(objChildCyberware); objChildNode.ContextMenuStrip = cmsCyberware; foreach (XmlNode objXmlGear in objXmlChild.SelectNodes("gears/gear")) AddPACKSGear(objXmlGearDocument, objXmlGear, objChildNode, objChildCyberware, cmsCyberwareGear, blnCreateChildren); objNode.Nodes.Add(objChildNode); objNode.Expand(); } } foreach (XmlNode objXmlGear in objXmlCyberware.SelectNodes("gears/gear")) AddPACKSGear(objXmlGearDocument, objXmlGear, objNode, objCyberware, cmsCyberwareGear, blnCreateChildren); objNode.ContextMenuStrip = cmsCyberware; treCyberware.Nodes[0].Nodes.Add(objNode); treCyberware.Nodes[0].Expand(); // Add any Weapons created by the Gear. foreach (Weapon objWeapon in objWeapons) _objCharacter.Weapons.Add(objWeapon); foreach (TreeNode objWeaponNode in objWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } Application.DoEvents(); } treCyberware.SortCustom(); } // Update Bioware. if (objXmlKit["biowares"] != null) { XmlDocument objXmlBiowareDocument = XmlManager.Instance.Load("bioware.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("biowares/bioware").Count; int i = 0; foreach (XmlNode objXmlBioware in objXmlKit.SelectNodes("biowares/bioware")) { i++; pgbProgress.Value = i; Application.DoEvents(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); TreeNode objNode = new TreeNode(); Cyberware objCyberware = new Cyberware(_objCharacter); Grade objGrade = objCyberware.ConvertToCyberwareGrade(objXmlBioware["grade"].InnerText, Improvement.ImprovementSource.Bioware); int intRating = 0; if (objXmlBioware["rating"] != null) intRating = Convert.ToInt32(objXmlBioware["rating"].InnerText); XmlNode objXmlBiowareNode = objXmlBiowareDocument.SelectSingleNode("/chummer/biowares/bioware[name = \"" + objXmlBioware["name"].InnerText + "\"]"); objCyberware.Create(objXmlBiowareNode, _objCharacter, objGrade, Improvement.ImprovementSource.Bioware, intRating, objNode, objWeapons, objWeaponNodes, true, blnCreateChildren); _objCharacter.Cyberware.Add(objCyberware); objNode.ContextMenuStrip = cmsBioware; treCyberware.Nodes[1].Nodes.Add(objNode); treCyberware.Nodes[1].Expand(); // Add any Weapons created by the Gear. foreach (Weapon objWeapon in objWeapons) _objCharacter.Weapons.Add(objWeapon); foreach (TreeNode objWeaponNode in objWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } Application.DoEvents(); } treCyberware.SortCustom(); } // Update Gear. if (objXmlKit["gears"] != null) { XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("gears/gear").Count; int i = 0; foreach (XmlNode objXmlGear in objXmlKit.SelectNodes("gears/gear")) { i++; pgbProgress.Value = i; Application.DoEvents(); AddPACKSGear(objXmlGearDocument, objXmlGear, treGear.Nodes[0], _objCharacter, cmsGear, blnCreateChildren); Application.DoEvents(); } } // Update Vehicles. if (objXmlKit["vehicles"] != null) { XmlDocument objXmlVehicleDocument = XmlManager.Instance.Load("vehicles.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("vehicles/vehicle").Count; int i = 0; foreach (XmlNode objXmlVehicle in objXmlKit.SelectNodes("vehicles/vehicle")) { i++; pgbProgress.Value = i; Application.DoEvents(); Gear objDefaultSensor = new Gear(_objCharacter); TreeNode objNode = new TreeNode(); Vehicle objVehicle = new Vehicle(_objCharacter); XmlNode objXmlVehicleNode = objXmlVehicleDocument.SelectSingleNode("/chummer/vehicles/vehicle[name = \"" + objXmlVehicle["name"].InnerText + "\"]"); objVehicle.Create(objXmlVehicleNode, objNode, cmsVehicle, cmsVehicleGear, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponMod, blnCreateChildren); _objCharacter.Vehicles.Add(objVehicle); // Grab the default Sensor that comes with the Vehicle. foreach (Gear objSensorGear in objVehicle.Gear) { if (objSensorGear.Category == "Sensors" && objSensorGear.Cost == "0" && objSensorGear.Rating == 0) { objDefaultSensor = objSensorGear; break; } } // Add any Vehicle Mods. if (objXmlVehicle["mods"] != null) { foreach (XmlNode objXmlMod in objXmlVehicle.SelectNodes("mods/mod")) { TreeNode objModNode = new TreeNode(); VehicleMod objMod = new VehicleMod(_objCharacter); int intRating = 0; if (objXmlMod["rating"] != null) intRating = Convert.ToInt32(objXmlMod["rating"].InnerText); XmlNode objXmlModNode = objXmlVehicleDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]"); objMod.Create(objXmlModNode, objModNode, intRating); objVehicle.Mods.Add(objMod); objNode.Nodes.Add(objModNode); objNode.Expand(); } } // Add any Vehicle Gear. if (objXmlVehicle["gears"] != null) { XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlVehicle.SelectNodes("gears/gear")) { List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); TreeNode objGearNode = new TreeNode(); Gear objGear = new Gear(_objCharacter); int intQty = 1; int intRating = 0; if (objXmlGear["rating"] != null) intRating = Convert.ToInt32(objXmlGear["rating"].InnerText); string strForceValue = ""; if (objXmlGear["name"].Attributes["select"] != null) strForceValue = objXmlGear["name"].Attributes["select"].InnerText; if (objXmlGear["qty"] != null) intQty = Convert.ToInt32(objXmlGear["qty"].InnerText); XmlNode objXmlGearNode = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlGear["name"].InnerText + "\"]"); objGear.Create(objXmlGearNode, _objCharacter, objGearNode, intRating, objWeapons, objWeaponNodes, strForceValue, false, false, false, blnCreateChildren, false); objGear.Quantity = intQty; objGearNode.Text = objGear.DisplayName; objVehicle.Gear.Add(objGear); // Look for child components. if (objXmlGear["gears"] != null) { foreach (XmlNode objXmlChild in objXmlGear.SelectNodes("gears/gear")) { AddPACKSGear(objXmlGearDocument, objXmlChild, objGearNode, objGear, cmsVehicleGear, blnCreateChildren); } } objGearNode.Expand(); objGearNode.ContextMenuStrip = cmsVehicleGear; objNode.Nodes.Add(objGearNode); objNode.Expand(); // If this is a Sensor, it will replace the Vehicle's base sensor, so remove it. if (objGear.Category == "Sensors" && objGear.Cost == "0" && objGear.Rating == 0) { objVehicle.Gear.Remove(objDefaultSensor); foreach (TreeNode objSensorNode in objNode.Nodes) { if (objSensorNode.Tag.ToString() == objDefaultSensor.InternalId) { objSensorNode.Remove(); break; } } } } } // Add any Vehicle Weapons. if (objXmlVehicle["weapons"] != null) { XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml"); foreach (XmlNode objXmlWeapon in objXmlVehicle.SelectNodes("weapons/weapon")) { TreeNode objWeaponNode = new TreeNode(); Weapon objWeapon = new Weapon(_objCharacter); XmlNode objXmlWeaponNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["name"].InnerText + "\"]"); objWeapon.Create(objXmlWeaponNode, _objCharacter, objWeaponNode, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponMod, blnCreateChildren); objWeapon.VehicleMounted = true; // Find the first Weapon Mount in the Vehicle. foreach (VehicleMod objMod in objVehicle.Mods) { if (objMod.Name.StartsWith("Weapon Mount") || objMod.Name.StartsWith("Heavy Weapon Mount")) { objMod.Weapons.Add(objWeapon); foreach (TreeNode objModNode in objNode.Nodes) { if (objModNode.Tag.ToString() == objMod.InternalId) { objWeaponNode.ContextMenuStrip = cmsVehicleWeapon; objModNode.Nodes.Add(objWeaponNode); objModNode.Expand(); break; } } break; } } // Look for Weapon Accessories. if (objXmlWeapon["accessories"] != null) { foreach (XmlNode objXmlAccessory in objXmlWeapon.SelectNodes("accessories/accessory")) { XmlNode objXmlAccessoryNode = objXmlWeaponDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + objXmlAccessory["name"].InnerText + "\"]"); WeaponAccessory objMod = new WeaponAccessory(_objCharacter); TreeNode objModNode = new TreeNode(); string strMount = ""; int intRating = 0; if (objXmlAccessory["mount"] != null) strMount = objXmlAccessory["mount"].InnerText; objMod.Create(objXmlAccessoryNode, objModNode, strMount,intRating); objModNode.ContextMenuStrip = cmsWeaponAccessory; objMod.Parent = objWeapon; objWeapon.WeaponAccessories.Add(objMod); objWeaponNode.Nodes.Add(objModNode); objWeaponNode.Expand(); } } // Look for Weapon Mods. if (objXmlWeapon["mods"] != null) { foreach (XmlNode objXmlMod in objXmlWeapon.SelectNodes("mods/mod")) { XmlNode objXmlModNode = objXmlWeaponDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]"); WeaponMod objMod = new WeaponMod(_objCharacter); TreeNode objModNode = new TreeNode(); objMod.Create(objXmlModNode, objModNode); objModNode.ContextMenuStrip = cmsVehicleWeaponMod; objMod.Parent = objWeapon; objWeapon.WeaponMods.Add(objMod); objWeaponNode.Nodes.Add(objModNode); objWeaponNode.Expand(); } } } } objNode.ContextMenuStrip = cmsVehicle; treVehicles.Nodes[0].Nodes.Add(objNode); treVehicles.Nodes[0].Expand(); Application.DoEvents(); } } pgbProgress.Visible = false; if (frmPickPACKSKit.AddAgain) AddPACKSKit(); PopulateGearList(); UpdateCharacterInfo(); }
/// <summary> /// Load the Character from an XML file. /// </summary> public bool Load() { XmlDocument objXmlDocument = new XmlDocument(); objXmlDocument.Load(_strFileName); XmlNode objXmlCharacter = objXmlDocument.SelectSingleNode("/character"); XmlNodeList objXmlNodeList; try { _blnIgnoreRules = Convert.ToBoolean(objXmlCharacter["ignorerules"].InnerText); } catch { _blnIgnoreRules = false; } try { _blnCreated = Convert.ToBoolean(objXmlCharacter["created"].InnerText); } catch { } ResetCharacter(); // Get the game edition of the file if possible and make sure it's intended to be used with this version of the application. try { if (objXmlCharacter["gameedition"].InnerText != string.Empty && objXmlCharacter["gameedition"].InnerText != "SR5") { MessageBox.Show(LanguageManager.Instance.GetString("Message_IncorrectGameVersion_SR4"), LanguageManager.Instance.GetString("MessageTitle_IncorrectGameVersion"), MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } } catch { } // Get the name of the settings file in use if possible. try { _strSettingsFileName = objXmlCharacter["settings"].InnerText; } catch { } // Load the character's settings file. if (!_objOptions.Load(_strSettingsFileName)) return false; try { _decEssenceAtSpecialStart = Convert.ToDecimal(objXmlCharacter["essenceatspecialstart"].InnerText, GlobalOptions.Instance.CultureInfo); // fix to work around a mistake made when saving decimal values in previous versions. if (_decEssenceAtSpecialStart > EssenceMaximum) _decEssenceAtSpecialStart /= 10; } catch { } try { _strVersionCreated = objXmlCharacter["createdversion"].InnerText; } catch { } // Metatype information. _strMetatype = objXmlCharacter["metatype"].InnerText; try { _strWalk = objXmlCharacter["walk"].InnerText; _strRun = objXmlCharacter["run"].InnerText; _strSprint = objXmlCharacter["sprint"].InnerText; } catch { } _intMetatypeBP = Convert.ToInt32(objXmlCharacter["metatypebp"].InnerText); _strMetavariant = objXmlCharacter["metavariant"].InnerText; try { _strMetatypeCategory = objXmlCharacter["metatypecategory"].InnerText; } catch { } try { _intMutantCritterBaseSkills = Convert.ToInt32(objXmlCharacter["mutantcritterbaseskills"].InnerText); } catch { } // General character information. _strName = objXmlCharacter["name"].InnerText; try { _strMugshot = objXmlCharacter["mugshot"].InnerText; } catch { } try { _strSex = objXmlCharacter["sex"].InnerText; } catch { } try { _strAge = objXmlCharacter["age"].InnerText; } catch { } try { _strEyes = objXmlCharacter["eyes"].InnerText; } catch { } try { _strHeight = objXmlCharacter["height"].InnerText; } catch { } try { _strWeight = objXmlCharacter["weight"].InnerText; } catch { } try { _strSkin = objXmlCharacter["skin"].InnerText; } catch { } try { _strHair = objXmlCharacter["hair"].InnerText; } catch { } try { _strDescription = objXmlCharacter["description"].InnerText; } catch { } try { _strBackground = objXmlCharacter["background"].InnerText; } catch { } try { _strConcept = objXmlCharacter["concept"].InnerText; } catch { } try { _strNotes = objXmlCharacter["notes"].InnerText; } catch { } try { _strAlias = objXmlCharacter["alias"].InnerText; } catch { } try { _strPlayerName = objXmlCharacter["playername"].InnerText; } catch { } try { _strGameNotes = objXmlCharacter["gamenotes"].InnerText; } catch { } try { _strGameplayOption = objXmlCharacter["gameplayoption"].InnerText; } catch { } try { _intMaxNuyen = Convert.ToInt32(objXmlCharacter["maxnuyen"].InnerText); } catch { } try { _intContactMultiplier = Convert.ToInt32(objXmlCharacter["contactmultiplier"].InnerText); } catch { } try { _intMaxKarma = Convert.ToInt32(objXmlCharacter["maxkarma"].InnerText); } catch { } try { _strPriorityMetatype = objXmlCharacter["prioritymetatype"].InnerText; } catch { } try { _strPriorityAttributes = objXmlCharacter["priorityattributes"].InnerText; } catch { } try { _strPrioritySpecial = objXmlCharacter["priorityspecial"].InnerText; } catch { } try { _strPrioritySkills = objXmlCharacter["priorityskills"].InnerText; } catch { } try { _strPriorityResources = objXmlCharacter["priorityresources"].InnerText; } catch { } try { _strSkill1 = objXmlCharacter["priorityskill1"].InnerText; } catch { } try { _strSkill2 = objXmlCharacter["priorityskill2"].InnerText; } catch { } try { _strSkillGroup = objXmlCharacter["priorityskillgroup"].InnerText; } catch { } try { _blnIsCritter = Convert.ToBoolean(objXmlCharacter["iscritter"].InnerText); } catch { } try { _blnPossessed = Convert.ToBoolean(objXmlCharacter["possessed"].InnerText); } catch { } try { _blnOverrideSpecialAttributeESSLoss = Convert.ToBoolean(objXmlCharacter["overridespecialattributeessloss"].InnerText); } catch { } try { _intContactPoints = Convert.ToInt32(objXmlCharacter["contactpoints"].InnerText); } catch { } try { _intContactPointsUsed = Convert.ToInt32(objXmlCharacter["contactpointsused"].InnerText); } catch { } try { _intCFPLimit = Convert.ToInt32(objXmlCharacter["cfplimit"].InnerText); } catch { } try { _intSpellLimit = Convert.ToInt32(objXmlCharacter["spelllimit"].InnerText); } catch { } try { _intKarma = Convert.ToInt32(objXmlCharacter["karma"].InnerText); } catch { } try { _intTotalKarma = Convert.ToInt32(objXmlCharacter["totalkarma"].InnerText); } catch { } try { _intSpecial = Convert.ToInt32(objXmlCharacter["special"].InnerText); } catch { } try { _intTotalSpecial = Convert.ToInt32(objXmlCharacter["totalspecial"].InnerText); } catch { } try { _intAttributes = Convert.ToInt32(objXmlCharacter["attributes"].InnerText); } catch { } try { _intTotalAttributes = Convert.ToInt32(objXmlCharacter["totalattributes"].InnerText); } catch { } try { _intContactPoints = Convert.ToInt32(objXmlCharacter["contactpoints"].InnerText); } catch { } try { _intContactPointsUsed = Convert.ToInt32(objXmlCharacter["contactpointsused"].InnerText); } catch { } try { _intStreetCred = Convert.ToInt32(objXmlCharacter["streetcred"].InnerText); } catch { } try { _intNotoriety = Convert.ToInt32(objXmlCharacter["notoriety"].InnerText); } catch { } try { _intPublicAwareness = Convert.ToInt32(objXmlCharacter["publicawareness"].InnerText); } catch { } try { _intBurntStreetCred = Convert.ToInt32(objXmlCharacter["burntstreetcred"].InnerText); } catch { } try { _intMaxAvail = Convert.ToInt32(objXmlCharacter["maxavail"].InnerText); } catch { } try { _intNuyen = Convert.ToInt32(objXmlCharacter["nuyen"].InnerText); } catch { } try { _intStartingNuyen = Convert.ToInt32(objXmlCharacter["startingnuyen"].InnerText); } catch { } try { _intAdeptWayDiscount = Convert.ToInt32(objXmlCharacter["adeptwaydiscount"].InnerText); } catch { } // Sum to X point value. try { _intSumtoTen = Convert.ToInt32(objXmlCharacter["sumtoten"].InnerText); } catch { } // Build Points/Karma. _intBuildPoints = Convert.ToInt32(objXmlCharacter["bp"].InnerText); try { _intBuildKarma = Convert.ToInt32(objXmlCharacter["buildkarma"].InnerText); if (_intMaxKarma == 0) _intMaxKarma = _intBuildKarma; if (_intBuildKarma == 35 && _strGameplayOption == "") { _strGameplayOption = "Prime Runner"; } if (_intBuildKarma == 35 && _intMaxNuyen == 0) { _intMaxNuyen = 25; } } catch { } //Maximum number of Karma that can be spent/gained on Qualities. try { _intGameplayOptionQualityLimit = Convert.ToInt32(objXmlCharacter["gameplayoptionqualitylimit"].InnerText); } catch { } try { _objBuildMethod = ConvertToCharacterBuildMethod(objXmlCharacter["buildmethod"].InnerText); } catch { } try { _intKnowledgeSkills = Convert.ToInt32(objXmlCharacter["knowskillpts"].InnerText); } catch { } _intKnowledgeSkillPoints = Convert.ToInt32(objXmlCharacter["knowpts"].InnerText); _intSkillPoints = Convert.ToInt32(objXmlCharacter["skillpts"].InnerText); _intSkillPointsMaximum = Convert.ToInt32(objXmlCharacter["skillptsmax"].InnerText); _intSkillGroups = Convert.ToInt32(objXmlCharacter["skillgrps"].InnerText); _intSkillGroupsMaximum = Convert.ToInt32(objXmlCharacter["skillgrpsmax"].InnerText); _decNuyenBP = Convert.ToDecimal(objXmlCharacter["nuyenbp"].InnerText, GlobalOptions.Instance.CultureInfo); _decNuyenMaximumBP = Convert.ToDecimal(objXmlCharacter["nuyenmaxbp"].InnerText, GlobalOptions.Instance.CultureInfo); _blnAdeptEnabled = Convert.ToBoolean(objXmlCharacter["adept"].InnerText); _blnMagicianEnabled = Convert.ToBoolean(objXmlCharacter["magician"].InnerText); _blnTechnomancerEnabled = Convert.ToBoolean(objXmlCharacter["technomancer"].InnerText); try { _blnInitiationEnabled = Convert.ToBoolean(objXmlCharacter["initiationoverride"].InnerText); } catch { } try { _blnCritterEnabled = Convert.ToBoolean(objXmlCharacter["critter"].InnerText); } catch { } try { _blnUneducated = Convert.ToBoolean(objXmlCharacter["uneducated"].InnerText); } catch { } try { _blnUncouth = Convert.ToBoolean(objXmlCharacter["uncouth"].InnerText); } catch { } try { _blnSchoolOfHardKnocks = Convert.ToBoolean(objXmlCharacter["schoolofhardknocks"].InnerText); } catch { } try { _blnFriendsInHighPlaces = Convert.ToBoolean(objXmlCharacter["friendsinhighplaces"].InnerText); } catch { } try { _blnCollegeEducation = Convert.ToBoolean(objXmlCharacter["collegeeducation"].InnerText); } catch { } try { _blnJackOfAllTrades = Convert.ToBoolean(objXmlCharacter["jackofalltrades"].InnerText); } catch { } try { _blnInfirm = Convert.ToBoolean(objXmlCharacter["infirm"].InnerText); } catch { } try { _blnBlackMarket = Convert.ToBoolean(objXmlCharacter["blackmarket"].InnerText); } catch { } try { _blnExCon = Convert.ToBoolean(objXmlCharacter["excon"].InnerText); } catch { } try { _blnTrustFund = Convert.ToBoolean(objXmlCharacter["trustfund"].InnerText); } catch { } try { _blnTechSchool = Convert.ToBoolean(objXmlCharacter["techschool"].InnerText); } catch { } try { _blnRestrictedGear = Convert.ToBoolean(objXmlCharacter["restrictedgear"].InnerText); } catch { } try { _blnOverclocker = Convert.ToBoolean(objXmlCharacter["overclocker"].InnerText); } catch { } try { _blnMadeMan = Convert.ToBoolean(objXmlCharacter["mademan"].InnerText); } catch { } try { _blnLinguist = Convert.ToBoolean(objXmlCharacter["linguist"].InnerText); } catch { } try { _blnLightningReflexes = Convert.ToBoolean(objXmlCharacter["lightningreflexes"].InnerText); } catch { } try { _blnFame = Convert.ToBoolean(objXmlCharacter["fame"].InnerText); } catch { } try { _blnBornRich = Convert.ToBoolean(objXmlCharacter["bornrich"].InnerText); } catch { } try { _blnErased = Convert.ToBoolean(objXmlCharacter["erased"].InnerText); } catch { } _blnMAGEnabled = Convert.ToBoolean(objXmlCharacter["magenabled"].InnerText); try { _intInitiateGrade = Convert.ToInt32(objXmlCharacter["initiategrade"].InnerText); } catch { } _blnRESEnabled = Convert.ToBoolean(objXmlCharacter["resenabled"].InnerText); try { _intSubmersionGrade = Convert.ToInt32(objXmlCharacter["submersiongrade"].InnerText); } catch { } try { _blnGroupMember = Convert.ToBoolean(objXmlCharacter["groupmember"].InnerText); } catch { } try { _strGroupName = objXmlCharacter["groupname"].InnerText; _strGroupNotes = objXmlCharacter["groupnotes"].InnerText; } catch { } // Improvements. XmlNodeList objXmlImprovementList = objXmlDocument.SelectNodes("/character/improvements/improvement"); foreach (XmlNode objXmlImprovement in objXmlImprovementList) { Improvement objImprovement = new Improvement(); objImprovement.Load(objXmlImprovement); _lstImprovements.Add(objImprovement); } // Qualities objXmlNodeList = objXmlDocument.SelectNodes("/character/qualities/quality"); bool blnHasOldQualities = false; foreach (XmlNode objXmlQuality in objXmlNodeList) { if (objXmlQuality["name"] != null) { Quality objQuality = new Quality(this); objQuality.Load(objXmlQuality); _lstQualities.Add(objQuality); } else { // If the Quality does not have a name tag, it is in the old format. Set the flag to show that old Qualities are in use. blnHasOldQualities = true; } } // If old Qualities are in use, they need to be converted before we can continue. if (blnHasOldQualities) ConvertOldQualities(objXmlNodeList); // Attributes. objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"BOD\"]"); _attBOD.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"AGI\"]"); _attAGI.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"REA\"]"); _attREA.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"STR\"]"); _attSTR.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"CHA\"]"); _attCHA.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"INT\"]"); _attINT.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"LOG\"]"); _attLOG.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"WIL\"]"); _attWIL.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"INI\"]"); _attINI.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"EDG\"]"); _attEDG.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"MAG\"]"); _attMAG.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"RES\"]"); _attRES.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"ESS\"]"); _attESS.Load(objXmlCharacter); // A.I. Attributes. try { _intSignal = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/attributes/signal").InnerText); _intResponse = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/attributes/response").InnerText); } catch { } // Force. try { _intMaxSkillRating = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/attributes/maxskillrating").InnerText); } catch { } // Attempt to load the split MAG Attribute information for Mystic Adepts. if (_blnAdeptEnabled && _blnMagicianEnabled) { try { _intMAGAdept = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/magsplitadept").InnerText); _intMAGMagician = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/magsplitmagician").InnerText); } catch { } } // Attempt to load the Magic Tradition. try { _strMagicTradition = objXmlDocument.SelectSingleNode("/character/tradition").InnerText; } catch { } // Attempt to load the Magic Tradition Drain Attributes. try { _strTraditionDrain = objXmlDocument.SelectSingleNode("/character/traditiondrain").InnerText; } catch { } // Attempt to load the Magic Tradition Name. try { _strTraditionName = objXmlDocument.SelectSingleNode("/character/traditionname").InnerText; } catch { } // Attempt to load the Spirit Combat Name. try { _strSpiritCombat = objXmlDocument.SelectSingleNode("/character/spiritcombat").InnerText; } catch { } // Attempt to load the Spirit Detection Name. try { _strSpiritDetection = objXmlDocument.SelectSingleNode("/character/spiritdetection").InnerText; } catch { } // Attempt to load the Spirit Health Name. try { _strSpiritHealth = objXmlDocument.SelectSingleNode("/character/spirithealth").InnerText; } catch { } // Attempt to load the Spirit Illusion Name. try { _strSpiritIllusion = objXmlDocument.SelectSingleNode("/character/spiritillusion").InnerText; } catch { } // Attempt to load the Spirit Manipulation Name. try { _strSpiritManipulation = objXmlDocument.SelectSingleNode("/character/spiritmanipulation").InnerText; } catch { } // Attempt to load the Technomancer Stream. try { _strTechnomancerStream = objXmlDocument.SelectSingleNode("/character/stream").InnerText; } catch { } // Attempt to load Condition Monitor Progress. try { _intPhysicalCMFilled = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/physicalcmfilled").InnerText); _intStunCMFilled = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/stuncmfilled").InnerText); } catch { } // Skills. foreach (Skill objSkill in _lstSkills) { XmlNode objXmlSkill = objXmlDocument.SelectSingleNode("/character/skills/skill[name = \"" + objSkill.Name + "\"]"); if (objXmlSkill != null) { objSkill.Load(objXmlSkill); } } // Exotic Skills. objXmlNodeList = objXmlDocument.SelectNodes("/character/skills/skill[exotic = \"True\"]"); foreach (XmlNode objXmlSkill in objXmlNodeList) { Skill objSkill = new Skill(this); objSkill.Load(objXmlSkill); _lstSkills.Add(objSkill); } // SkillGroups. foreach (SkillGroup objGroup in _lstSkillGroups) { XmlNode objXmlSkill = objXmlDocument.SelectSingleNode("/character/skillgroups/skillgroup[name = \"" + objGroup.Name + "\"]"); if (objXmlSkill != null) { objGroup.Load(objXmlSkill); // If the character is set to ignore rules or is in Career Mode, Skill Groups should have a maximum Rating of 6 unless they have been given a higher maximum Rating already. if ((_blnIgnoreRules || _blnCreated) && objGroup.RatingMaximum < 12) objGroup.RatingMaximum = 12; } } // Apply the broken skill group fix foreach (Skill objSkill in _lstSkills) { foreach (SkillGroup objGroup in _lstSkillGroups) { if (objGroup.Broken && objGroup.Name == objSkill.SkillGroup) { objSkill.FreeLevels = objGroup.Rating; objSkill.Base = objGroup.Rating; objSkill.Karma = objSkill.Rating - objSkill.Base; } } } foreach (SkillGroup objGroup in _lstSkillGroups) { if (objGroup.Base == 0 && objGroup.Karma == 0 && objGroup.Rating > 0) objGroup.Base = objGroup.Rating; } // Knowledge Skills. List<ListItem> lstKnowledgeSkillOrder = new List<ListItem>(); objXmlNodeList = objXmlDocument.SelectNodes("/character/skills/skill[knowledge = \"True\"]"); // Sort the Knowledge Skills in alphabetical order. foreach (XmlNode objXmlSkill in objXmlNodeList) { ListItem objGroup = new ListItem(); objGroup.Value = objXmlSkill["name"].InnerText; objGroup.Name = objXmlSkill["name"].InnerText; lstKnowledgeSkillOrder.Add(objGroup); } SortListItem objSort = new SortListItem(); lstKnowledgeSkillOrder.Sort(objSort.Compare); foreach (ListItem objItem in lstKnowledgeSkillOrder) { Skill objSkill = new Skill(this); XmlNode objNode = objXmlDocument.SelectSingleNode("/character/skills/skill[knowledge = \"True\" and name = " + CleanXPath(objItem.Value) + "]"); objSkill.Load(objNode); _lstSkills.Add(objSkill); } // Contacts. objXmlNodeList = objXmlDocument.SelectNodes("/character/contacts/contact"); foreach (XmlNode objXmlContact in objXmlNodeList) { Contact objContact = new Contact(this); objContact.Load(objXmlContact); _lstContacts.Add(objContact); } // Armor. objXmlNodeList = objXmlDocument.SelectNodes("/character/armors/armor"); foreach (XmlNode objXmlArmor in objXmlNodeList) { Armor objArmor = new Armor(this); objArmor.Load(objXmlArmor); _lstArmor.Add(objArmor); } // Weapons. objXmlNodeList = objXmlDocument.SelectNodes("/character/weapons/weapon"); foreach (XmlNode objXmlWeapon in objXmlNodeList) { Weapon objWeapon = new Weapon(this); objWeapon.Load(objXmlWeapon); _lstWeapons.Add(objWeapon); } // Cyberware/Bioware. objXmlNodeList = objXmlDocument.SelectNodes("/character/cyberwares/cyberware"); foreach (XmlNode objXmlCyberware in objXmlNodeList) { Cyberware objCyberware = new Cyberware(this); objCyberware.Load(objXmlCyberware); _lstCyberware.Add(objCyberware); } // Spells. objXmlNodeList = objXmlDocument.SelectNodes("/character/spells/spell"); foreach (XmlNode objXmlSpell in objXmlNodeList) { Spell objSpell = new Spell(this); objSpell.Load(objXmlSpell); _lstSpells.Add(objSpell); } // Foci. objXmlNodeList = objXmlDocument.SelectNodes("/character/foci/focus"); foreach (XmlNode objXmlFocus in objXmlNodeList) { Focus objFocus = new Focus(); objFocus.Load(objXmlFocus); _lstFoci.Add(objFocus); } // Stacked Foci. objXmlNodeList = objXmlDocument.SelectNodes("/character/stackedfoci/stackedfocus"); foreach (XmlNode objXmlStack in objXmlNodeList) { StackedFocus objStack = new StackedFocus(this); objStack.Load(objXmlStack); _lstStackedFoci.Add(objStack); } // Powers. List<ListItem> lstPowerOrder = new List<ListItem>(); objXmlNodeList = objXmlDocument.SelectNodes("/character/powers/power"); // Sort the Powers in alphabetical order. foreach (XmlNode objXmlPower in objXmlNodeList) { ListItem objGroup = new ListItem(); objGroup.Value = objXmlPower["extra"].InnerText; objGroup.Name = objXmlPower["name"].InnerText; lstPowerOrder.Add(objGroup); } objSort = new SortListItem(); lstPowerOrder.Sort(objSort.Compare); foreach (ListItem objItem in lstPowerOrder) { Power objPower = new Power(this); XmlNode objNode = objXmlDocument.SelectSingleNode("/character/powers/power[name = " + CleanXPath(objItem.Name) + " and extra = " + CleanXPath(objItem.Value) + "]"); objPower.Load(objNode); _lstPowers.Add(objPower); } // Spirits/Sprites. objXmlNodeList = objXmlDocument.SelectNodes("/character/spirits/spirit"); foreach (XmlNode objXmlSpirit in objXmlNodeList) { Spirit objSpirit = new Spirit(this); objSpirit.Load(objXmlSpirit); _lstSpirits.Add(objSpirit); } // Compex Forms/Technomancer Programs. objXmlNodeList = objXmlDocument.SelectNodes("/character/complexforms/complexform"); foreach (XmlNode objXmlProgram in objXmlNodeList) { ComplexForm objProgram = new ComplexForm(this); objProgram.Load(objXmlProgram); _lstComplexForms.Add(objProgram); } // Martial Arts. objXmlNodeList = objXmlDocument.SelectNodes("/character/martialarts/martialart"); foreach (XmlNode objXmlArt in objXmlNodeList) { MartialArt objMartialArt = new MartialArt(this); objMartialArt.Load(objXmlArt); _lstMartialArts.Add(objMartialArt); } // Martial Art Maneuvers. objXmlNodeList = objXmlDocument.SelectNodes("/character/martialartmaneuvers/martialartmaneuver"); foreach (XmlNode objXmlManeuver in objXmlNodeList) { MartialArtManeuver objManeuver = new MartialArtManeuver(this); objManeuver.Load(objXmlManeuver); _lstMartialArtManeuvers.Add(objManeuver); } // Limit Modifiers. objXmlNodeList = objXmlDocument.SelectNodes("/character/limitmodifiers/limitmodifier"); foreach (XmlNode objXmlLimit in objXmlNodeList) { LimitModifier obLimitModifier = new LimitModifier(this); obLimitModifier.Load(objXmlLimit); _lstLimitModifiers.Add(obLimitModifier); } // Lifestyles. objXmlNodeList = objXmlDocument.SelectNodes("/character/lifestyles/lifestyle"); foreach (XmlNode objXmlLifestyle in objXmlNodeList) { Lifestyle objLifestyle = new Lifestyle(this); objLifestyle.Load(objXmlLifestyle); _lstLifestyles.Add(objLifestyle); } // <gears> objXmlNodeList = objXmlDocument.SelectNodes("/character/gears/gear"); foreach (XmlNode objXmlGear in objXmlNodeList) { switch (objXmlGear["category"].InnerText) { case "Commlinks": case "Cyberdecks": case "Rigger Command Consoles": Commlink objCommlink = new Commlink(this); objCommlink.Load(objXmlGear); _lstGear.Add(objCommlink); break; default: Gear objGear = new Gear(this); objGear.Load(objXmlGear); _lstGear.Add(objGear); break; } } // Vehicles. objXmlNodeList = objXmlDocument.SelectNodes("/character/vehicles/vehicle"); foreach (XmlNode objXmlVehicle in objXmlNodeList) { Vehicle objVehicle = new Vehicle(this); objVehicle.Load(objXmlVehicle); _lstVehicles.Add(objVehicle); } // Metamagics/Echoes. objXmlNodeList = objXmlDocument.SelectNodes("/character/metamagics/metamagic"); foreach (XmlNode objXmlMetamagic in objXmlNodeList) { Metamagic objMetamagic = new Metamagic(this); objMetamagic.Load(objXmlMetamagic); _lstMetamagics.Add(objMetamagic); } // Arts objXmlNodeList = objXmlDocument.SelectNodes("/character/arts/art"); foreach (XmlNode objXmlArt in objXmlNodeList) { Art objArt = new Art(this); objArt.Load(objXmlArt); _lstArts.Add(objArt); } // Enhancements objXmlNodeList = objXmlDocument.SelectNodes("/character/enhancements/enhancement"); foreach (XmlNode objXmlEnhancement in objXmlNodeList) { Enhancement objEnhancement = new Enhancement(this); objEnhancement.Load(objXmlEnhancement); _lstEnhancements.Add(objEnhancement); } // Critter Powers. objXmlNodeList = objXmlDocument.SelectNodes("/character/critterpowers/critterpower"); foreach (XmlNode objXmlPower in objXmlNodeList) { CritterPower objPower = new CritterPower(this); objPower.Load(objXmlPower); _lstCritterPowers.Add(objPower); } // Initiation Grades. objXmlNodeList = objXmlDocument.SelectNodes("/character/initiationgrades/initiationgrade"); foreach (XmlNode objXmlGrade in objXmlNodeList) { InitiationGrade objGrade = new InitiationGrade(this); objGrade.Load(objXmlGrade); _lstInitiationGrades.Add(objGrade); } // Expense Log Entries. XmlNodeList objXmlExpenseList = objXmlDocument.SelectNodes("/character/expenses/expense"); foreach (XmlNode objXmlExpense in objXmlExpenseList) { ExpenseLogEntry objExpenseLogEntry = new ExpenseLogEntry(); objExpenseLogEntry.Load(objXmlExpense); _lstExpenseLog.Add(objExpenseLogEntry); } // Locations. XmlNodeList objXmlLocationList = objXmlDocument.SelectNodes("/character/locations/location"); foreach (XmlNode objXmlLocation in objXmlLocationList) { _lstLocations.Add(objXmlLocation.InnerText); } // Armor Bundles. XmlNodeList objXmlBundleList = objXmlDocument.SelectNodes("/character/armorbundles/armorbundle"); foreach (XmlNode objXmlBundle in objXmlBundleList) { _lstArmorBundles.Add(objXmlBundle.InnerText); } // Weapon Locations. XmlNodeList objXmlWeaponLocationList = objXmlDocument.SelectNodes("/character/weaponlocations/weaponlocation"); foreach (XmlNode objXmlLocation in objXmlWeaponLocationList) { _lstWeaponLocations.Add(objXmlLocation.InnerText); } // Improvement Groups. XmlNodeList objXmlGroupList = objXmlDocument.SelectNodes("/character/improvementgroups/improvementgroup"); foreach (XmlNode objXmlGroup in objXmlGroupList) { _lstImprovementGroups.Add(objXmlGroup.InnerText); } // Calendar. XmlNodeList objXmlWeekList = objXmlDocument.SelectNodes("/character/calendar/week"); foreach (XmlNode objXmlWeek in objXmlWeekList) { CalendarWeek objWeek = new CalendarWeek(); objWeek.Load(objXmlWeek); _lstCalendar.Add(objWeek); } // Look for the unarmed attack bool blnFoundUnarmed = false; foreach (Weapon objWeapon in _lstWeapons) { if (objWeapon.Name == "Unarmed Attack") blnFoundUnarmed = true; } if (!blnFoundUnarmed) { // Add the Unarmed Attack Weapon to the character. try { XmlDocument objXmlWeaponDoc = XmlManager.Instance.Load("weapons.xml"); XmlNode objXmlWeapon = objXmlWeaponDoc.SelectSingleNode("/chummer/weapons/weapon[name = \"Unarmed Attack\"]"); TreeNode objGearWeaponNode = new TreeNode(); Weapon objWeapon = new Weapon(this); objWeapon.Create(objXmlWeapon, this, objGearWeaponNode, null, null, null); objGearWeaponNode.ForeColor = SystemColors.GrayText; _lstWeapons.Add(objWeapon); } catch { } } // converting from old dwarven resistance to new dwarven resistance if (this.Metatype.ToLower().Equals("dwarf") && this.Qualities.Where(x => x.Name.Equals("Dwarf Resistance")).FirstOrDefault() == null && this.Qualities.Where(x => x.Name.Equals("Resistance to Pathogens and Toxins")).FirstOrDefault() != null) { this.Qualities.Remove(this.Qualities.Where(x => x.Name.Equals("Resistance to Pathogens and Toxins")).First()); XmlNode objXmlDwarfQuality = XmlManager.Instance.Load("qualities.xml").SelectSingleNode("/chummer/qualities/quality[name = \"Dwarf Resistance\"]"); TreeNode objNode = new TreeNode(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); Quality objQuality = new Quality(this); objQuality.Create(objXmlDwarfQuality, this, QualitySource.Metatype, objNode, objWeapons, objWeaponNodes); this._lstQualities.Add(objQuality); blnHasOldQualities = true; } // load issue where the contact multiplier was set to 0 if (_intContactMultiplier == 0 && _strGameplayOption != string.Empty) { XmlDocument objXmlDocumentPriority = XmlManager.Instance.Load("gameplayoptions.xml"); XmlNode objXmlGameplayOption = objXmlDocumentPriority.SelectSingleNode("/chummer/gameplayoptions/gameplayoption[name = \"" + _strGameplayOption + "\"]"); string strKarma = objXmlGameplayOption["karma"].InnerText; string strNuyen = objXmlGameplayOption["maxnuyen"].InnerText; string strContactMultiplier = "0"; if (!_objOptions.FreeContactsMultiplierEnabled) { strContactMultiplier = objXmlGameplayOption["contactmultiplier"].InnerText; } else { strContactMultiplier = _objOptions.FreeContactsMultiplier.ToString(); } _intMaxKarma = Convert.ToInt32(strKarma); _intMaxNuyen = Convert.ToInt32(strNuyen); _intContactMultiplier = Convert.ToInt32(strContactMultiplier); _intContactPoints = (CHA.Base + CHA.Karma) * _intContactMultiplier; } // If the character had old Qualities that were converted, immediately save the file so they are in the new format. if (blnHasOldQualities) Save(); return true; }
private void tsMetamagicAddEnchantment_Click(object sender, EventArgs e) { // Character can only have a number of Metamagics/Echoes equal to their Initiate Grade. Additional ones cost Karma. bool blnPayWithKarma = false; string strType = ""; if (treMetamagic.SelectedNode.Level != 0) return; int intGrade = 0; foreach (InitiationGrade objGrade in _objCharacter.InitiationGrades) { if (objGrade.InternalId == treMetamagic.SelectedNode.Tag.ToString()) { intGrade = objGrade.Grade; break; } } // Evaluate each object foreach (Metamagic objMetamagic in _objCharacter.Metamagics) { if (objMetamagic.Grade == intGrade) blnPayWithKarma = true; } foreach (Spell objSpell in _objCharacter.Spells) { if (objSpell.Grade == intGrade) blnPayWithKarma = true; } frmSelectArt frmPickArt = new frmSelectArt(_objCharacter); frmPickArt.WindowMode = frmSelectArt.Mode.Enchantment; frmPickArt.ShowDialog(this); // Make sure a value was selected. if (frmPickArt.DialogResult == DialogResult.Cancel) return; string strEnchantment = frmPickArt.SelectedItem; XmlDocument objXmlDocument = new XmlDocument(); XmlNode objXmlArt; TreeNode objNode = new TreeNode(); Spell objNewSpell = new Spell(_objCharacter); Improvement.ImprovementSource objSource; objXmlDocument = XmlManager.Instance.Load("spells.xml"); objXmlArt = objXmlDocument.SelectSingleNode("/chummer/spells/spell[name = \"" + strEnchantment + "\"]"); objSource = Improvement.ImprovementSource.Initiation; objNewSpell.Create(objXmlArt, _objCharacter, objNode, "", false, false, false, objSource); objNewSpell.Grade = intGrade; objNode.ContextMenuStrip = cmsInitiationNotes; if (objNewSpell.InternalId == Guid.Empty.ToString()) return; _objCharacter.Spells.Add(objNewSpell); TreeNode objSpellNode = new TreeNode(); objSpellNode.Text = objNode.Text; objSpellNode.Tag = objNode.Tag; string strCategory = ""; if (objNewSpell.Category == "Rituals") strCategory = LanguageManager.Instance.GetString("Label_Ritual") + " "; if (objNewSpell.Category == "Enchantments") strCategory = LanguageManager.Instance.GetString("Label_Enchantment") + " "; objNode.Text = strCategory + objNode.Text; treMetamagic.SelectedNode.Nodes.Add(objNode); treMetamagic.SelectedNode.Expand(); treSpells.Nodes[6].Nodes.Add(objSpellNode); treSpells.Nodes[6].Expand(); UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); }
private void cmdAddSpell_Click(object sender, EventArgs e) { // Count the number of Spells the character currently has and make sure they do not try to select more Spells than they are allowed. // The maximum number of Spells a character can start with is 2 x (highest of Spellcasting or Ritual Spellcasting Skill). int intSpellCount = 0; foreach (TreeNode nodCategory in treSpells.Nodes) { foreach (TreeNode nodSpell in nodCategory.Nodes) { intSpellCount++; } } // Run through the list of Active Skills and pick out the two applicable ones. int intSkillValue = 0; foreach (SkillControl objSkillControl in panActiveSkills.Controls) { if ((objSkillControl.SkillName == "Spellcasting" || objSkillControl.SkillName == "Ritual Spellcasting") && objSkillControl.SkillRating > intSkillValue) intSkillValue = objSkillControl.SkillRating + objSkillControl.SkillObject.RatingModifiers; } if (intSpellCount >= ((2 * intSkillValue) + _objImprovementManager.ValueOf(Improvement.ImprovementType.SpellLimit)) && !_objCharacter.IgnoreRules) { MessageBox.Show(LanguageManager.Instance.GetString("Message_SpellLimit"), LanguageManager.Instance.GetString("MessageTitle_SpellLimit"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } frmSelectSpell frmPickSpell = new frmSelectSpell(_objCharacter); frmPickSpell.ShowDialog(this); // Make sure the dialogue window was not canceled. if (frmPickSpell.DialogResult == DialogResult.Cancel) return; // Open the Spells XML file and locate the selected piece. XmlDocument objXmlDocument = XmlManager.Instance.Load("spells.xml"); XmlNode objXmlSpell = objXmlDocument.SelectSingleNode("/chummer/spells/spell[id = \"" + frmPickSpell.SelectedSpell + "\"]"); Spell objSpell = new Spell(_objCharacter); TreeNode objNode = new TreeNode(); objSpell.Create(objXmlSpell, _objCharacter, objNode, "", frmPickSpell.Limited, frmPickSpell.Extended); objNode.ContextMenuStrip = cmsSpell; if (objSpell.InternalId == Guid.Empty.ToString()) return; _objCharacter.Spells.Add(objSpell); switch (objSpell.Category) { case "Combat": treSpells.Nodes[0].Nodes.Add(objNode); treSpells.Nodes[0].Expand(); break; case "Detection": treSpells.Nodes[1].Nodes.Add(objNode); treSpells.Nodes[1].Expand(); break; case "Health": treSpells.Nodes[2].Nodes.Add(objNode); treSpells.Nodes[2].Expand(); break; case "Illusion": treSpells.Nodes[3].Nodes.Add(objNode); treSpells.Nodes[3].Expand(); break; case "Manipulation": treSpells.Nodes[4].Nodes.Add(objNode); treSpells.Nodes[4].Expand(); break; } treSpells.SelectedNode = objNode; _objFunctions.SortTree(treSpells); UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); if (frmPickSpell.AddAgain) cmdAddSpell_Click(sender, e); }
private void cmdAddSpell_Click(object sender, EventArgs e) { // Make sure the character has enough Karma before letting them select a Spell. if (_objCharacter.Karma < _objOptions.KarmaSpell) { MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Run through the list of Active Skills and pick out the two applicable ones. int intSkillValue = 0; foreach (SkillControl objSkillControl in panActiveSkills.Controls) { if ((objSkillControl.SkillName == "Spellcasting" || objSkillControl.SkillName == "Ritual Spellcasting") && objSkillControl.SkillRating > intSkillValue) intSkillValue = objSkillControl.SkillRating; } frmSelectSpell frmPickSpell = new frmSelectSpell(_objCharacter); frmPickSpell.ShowDialog(this); // Make sure the dialogue window was not canceled. if (frmPickSpell.DialogResult == DialogResult.Cancel) return; // Open the Spells XML file and locate the selected piece. XmlDocument objXmlDocument = XmlManager.Instance.Load("spells.xml"); XmlNode objXmlSpell = objXmlDocument.SelectSingleNode("/chummer/spells/spell[name = \"" + frmPickSpell.SelectedSpell + "\"]"); Spell objSpell = new Spell(_objCharacter); TreeNode objNode = new TreeNode(); objSpell.Create(objXmlSpell, _objCharacter, objNode, "", frmPickSpell.Limited, frmPickSpell.Extended, frmPickSpell.Alchemical); objNode.ContextMenuStrip = cmsSpell; if (objSpell.InternalId == Guid.Empty.ToString()) return; if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseSpend").Replace("{0}", objSpell.DisplayName).Replace("{1}", _objOptions.KarmaSpell.ToString()))) return; _objCharacter.Spells.Add(objSpell); switch (objSpell.Category) { case "Combat": treSpells.Nodes[0].Nodes.Add(objNode); treSpells.Nodes[0].Expand(); break; case "Detection": treSpells.Nodes[1].Nodes.Add(objNode); treSpells.Nodes[1].Expand(); break; case "Health": treSpells.Nodes[2].Nodes.Add(objNode); treSpells.Nodes[2].Expand(); break; case "Illusion": treSpells.Nodes[3].Nodes.Add(objNode); treSpells.Nodes[3].Expand(); break; case "Manipulation": treSpells.Nodes[4].Nodes.Add(objNode); treSpells.Nodes[4].Expand(); break; case "Rituals": int intNode = 5; if (_objCharacter.AdeptEnabled && !_objCharacter.MagicianEnabled) intNode = 0; treSpells.Nodes[intNode].Nodes.Add(objNode); treSpells.Nodes[intNode].Expand(); break; case "Enchantments": treSpells.Nodes[6].Nodes.Add(objNode); treSpells.Nodes[6].Expand(); break; } treSpells.SelectedNode = objNode; // Create the Expense Log Entry. ExpenseLogEntry objEntry = new ExpenseLogEntry(); objEntry.Create(_objOptions.KarmaSpell * -1, LanguageManager.Instance.GetString("String_ExpenseLearnSpell") + " " + objSpell.Name, ExpenseType.Karma, DateTime.Now); _objCharacter.ExpenseEntries.Add(objEntry); _objCharacter.Karma -= _objOptions.KarmaSpell; ExpenseUndo objUndo = new ExpenseUndo(); objUndo.CreateKarma(KarmaExpenseType.AddSpell, objSpell.InternalId); objEntry.Undo = objUndo; _objFunctions.SortTree(treSpells); UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); if (frmPickSpell.AddAgain) cmdAddSpell_Click(sender, e); }
private void tsMetamagicAddRitual_Click(object sender, EventArgs e) { // Character can only have a number of Metamagics/Echoes equal to their Initiate Grade. Additional ones cost Karma. bool blnPayWithKarma = false; string strType = ""; if (treMetamagic.SelectedNode.Level != 0) return; int intGrade = 0; foreach (InitiationGrade objGrade in _objCharacter.InitiationGrades) { if (objGrade.InternalId == treMetamagic.SelectedNode.Tag.ToString()) { intGrade = objGrade.Grade; break; } } // Evaluate each object foreach (Metamagic objMetamagic in _objCharacter.Metamagics) { if (objMetamagic.Grade == intGrade) blnPayWithKarma = true; } foreach (Spell objSpell in _objCharacter.Spells) { if (objSpell.Grade == intGrade) blnPayWithKarma = true; } if (blnPayWithKarma && _objCharacter.Karma < _objOptions.KarmaSpell) { // Make sure the Karma expense would not put them over the limit. MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (blnPayWithKarma) if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseSpend").Replace("{0}", LanguageManager.Instance.GetString("String_Ritual")).Replace("{1}", _objOptions.KarmaSpell.ToString()))) return; frmSelectArt frmPickArt = new frmSelectArt(_objCharacter); frmPickArt.WindowMode = frmSelectArt.Mode.Ritual; frmPickArt.ShowDialog(this); // Make sure a value was selected. if (frmPickArt.DialogResult == DialogResult.Cancel) return; string strEnchantment = frmPickArt.SelectedItem; XmlDocument objXmlDocument = new XmlDocument(); XmlNode objXmlArt; TreeNode objNode = new TreeNode(); Spell objNewSpell = new Spell(_objCharacter); Improvement.ImprovementSource objSource; objXmlDocument = XmlManager.Instance.Load("spells.xml"); objXmlArt = objXmlDocument.SelectSingleNode("/chummer/spells/spell[name = \"" + strEnchantment + "\"]"); objSource = Improvement.ImprovementSource.Initiation; objNewSpell.Create(objXmlArt, _objCharacter, objNode, "", false, false, false, objSource); objNewSpell.Grade = intGrade; objNode.ContextMenuStrip = cmsInitiationNotes; if (objNewSpell.InternalId == Guid.Empty.ToString()) return; _objCharacter.Spells.Add(objNewSpell); if (blnPayWithKarma) { // Create the Expense Log Entry. ExpenseLogEntry objEntry = new ExpenseLogEntry(); objEntry.Create(_objOptions.KarmaSpell * -1, strType + " " + frmPickArt.SelectedItem, ExpenseType.Karma, DateTime.Now); _objCharacter.ExpenseEntries.Add(objEntry); ExpenseUndo objUndo = new ExpenseUndo(); objUndo.CreateKarma(KarmaExpenseType.AddSpell, objNewSpell.InternalId); objEntry.Undo = objUndo; // Adjust the character's Karma total. _objCharacter.Karma -= _objOptions.KarmaSpell; } TreeNode objSpellNode = new TreeNode(); objSpellNode.Text = objNode.Text; objSpellNode.Tag = objNode.Tag; string strCategory = ""; if (objNewSpell.Category == "Rituals") strCategory = LanguageManager.Instance.GetString("Label_Ritual") + " "; if (objNewSpell.Category == "Enchantments") strCategory = LanguageManager.Instance.GetString("Label_Enchantment") + " "; objNode.Text = strCategory + objNode.Text; treMetamagic.SelectedNode.Nodes.Add(objNode); treMetamagic.SelectedNode.Expand(); int intNode = 5; if (!_objCharacter.MAGEnabled) intNode = 0; treSpells.Nodes[intNode].Nodes.Add(objSpellNode); treSpells.Nodes[intNode].Expand(); UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); }
public void CreateAllSpellsTest() { // Create a new Human character. Character objCharacter = new Character(); objCharacter.LoadMetatype(Guid.Parse("e28e7075-f635-4c02-937c-e4fc61c51602")); TreeNode objNode = new TreeNode(); XmlDocument objXmlDocument = XmlManager.Instance.Load("spells.xml"); foreach (XmlNode objXmlNode in objXmlDocument.SelectNodes("/chummer/spells/spell")) { Spell objSpell = new Spell(objCharacter); objSpell.Create(objXmlNode, objCharacter, objNode, "", false, false, false); } }
/// <summary> /// Load the Character from an XML file. /// </summary> public bool Load() { XmlDocument objXmlDocument = new XmlDocument(); objXmlDocument.Load(_strFileName); XmlNode objXmlCharacter = objXmlDocument.SelectSingleNode("/character"); XmlNodeList objXmlNodeList; try { _blnIgnoreRules = Convert.ToBoolean(objXmlCharacter["ignorerules"].InnerText); } catch { _blnIgnoreRules = false; } try { _blnCreated = Convert.ToBoolean(objXmlCharacter["created"].InnerText); } catch { } ResetCharacter(); // Get the game edition of the file if possible and make sure it's intended to be used with this version of the application. try { if (objXmlCharacter["gameedition"].InnerText != string.Empty && objXmlCharacter["gameedition"].InnerText != "SR4") { MessageBox.Show(LanguageManager.Instance.GetString("Message_IncorrectGameVersion_SR5"), LanguageManager.Instance.GetString("MessageTitle_IncorrectGameVersion"), MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } } catch { } // Get the name of the settings file in use if possible. try { _strSettingsFileName = objXmlCharacter["settings"].InnerText; } catch { } // Load the character's settings file. if (!_objOptions.Load(_strSettingsFileName)) return false; try { _decEssenceAtSpecialStart = Convert.ToDecimal(objXmlCharacter["essenceatspecialstart"].InnerText, GlobalOptions.Instance.CultureInfo); // fix to work around a mistake made when saving decimal values in previous versions. if (_decEssenceAtSpecialStart > EssenceMaximum) _decEssenceAtSpecialStart /= 10; } catch { } // Metatype information. _strMetatype = objXmlCharacter["metatype"].InnerText; try { _strMovement = objXmlCharacter["movement"].InnerText; } catch { } _intMetatypeBP = Convert.ToInt32(objXmlCharacter["metatypebp"].InnerText); _strMetavariant = objXmlCharacter["metavariant"].InnerText; try { _strMetatypeCategory = objXmlCharacter["metatypecategory"].InnerText; } catch { } try { _intMutantCritterBaseSkills = Convert.ToInt32(objXmlCharacter["mutantcritterbaseskills"].InnerText); } catch { } // General character information. _strName = objXmlCharacter["name"].InnerText; try { _strMugshot = objXmlCharacter["mugshot"].InnerText; } catch { } try { _strSex = objXmlCharacter["sex"].InnerText; } catch { } try { _strAge = objXmlCharacter["age"].InnerText; } catch { } try { _strEyes = objXmlCharacter["eyes"].InnerText; } catch { } try { _strHeight = objXmlCharacter["height"].InnerText; } catch { } try { _strWeight = objXmlCharacter["weight"].InnerText; } catch { } try { _strSkin = objXmlCharacter["skin"].InnerText; } catch { } try { _strHair = objXmlCharacter["hair"].InnerText; } catch { } try { _strDescription = objXmlCharacter["description"].InnerText; } catch { } try { _strBackground = objXmlCharacter["background"].InnerText; } catch { } try { _strConcept = objXmlCharacter["concept"].InnerText; } catch { } try { _strNotes = objXmlCharacter["notes"].InnerText; } catch { } try { _strAlias = objXmlCharacter["alias"].InnerText; } catch { } try { _strPlayerName = objXmlCharacter["playername"].InnerText; } catch { } try { _strGameNotes = objXmlCharacter["gamenotes"].InnerText; } catch { } try { _blnIsCritter = Convert.ToBoolean(objXmlCharacter["iscritter"].InnerText); } catch { } try { _blnPossessed = Convert.ToBoolean(objXmlCharacter["possessed"].InnerText); } catch { } try { _blnOverrideSpecialAttributeESSLoss = Convert.ToBoolean(objXmlCharacter["overridespecialattributeessloss"].InnerText); } catch { } try { _intKarma = Convert.ToInt32(objXmlCharacter["karma"].InnerText); } catch { } try { _intTotalKarma = Convert.ToInt32(objXmlCharacter["totalkarma"].InnerText); } catch { } try { _intStreetCred = Convert.ToInt32(objXmlCharacter["streetcred"].InnerText); } catch { } try { _intNotoriety = Convert.ToInt32(objXmlCharacter["notoriety"].InnerText); } catch { } try { _intPublicAwareness = Convert.ToInt32(objXmlCharacter["publicawareness"].InnerText); } catch { } try { _intBurntStreetCred = Convert.ToInt32(objXmlCharacter["burntstreetcred"].InnerText); } catch { } try { _intMaxAvail = Convert.ToInt32(objXmlCharacter["maxavail"].InnerText); } catch { } try { _intNuyen = Convert.ToInt32(objXmlCharacter["nuyen"].InnerText); } catch { } // Build Points/Karma. _intBuildPoints = Convert.ToInt32(objXmlCharacter["bp"].InnerText); try { _intBuildKarma = Convert.ToInt32(objXmlCharacter["buildkarma"].InnerText); } catch { } try { _objBuildMethod = ConvertToCharacterBuildMethod(objXmlCharacter["buildmethod"].InnerText); } catch { } _intKnowledgeSkillPoints = Convert.ToInt32(objXmlCharacter["knowpts"].InnerText); _decNuyenBP = Convert.ToDecimal(objXmlCharacter["nuyenbp"].InnerText, GlobalOptions.Instance.CultureInfo); _decNuyenMaximumBP = Convert.ToDecimal(objXmlCharacter["nuyenmaxbp"].InnerText, GlobalOptions.Instance.CultureInfo); _blnAdeptEnabled = Convert.ToBoolean(objXmlCharacter["adept"].InnerText); _blnMagicianEnabled = Convert.ToBoolean(objXmlCharacter["magician"].InnerText); _blnTechnomancerEnabled = Convert.ToBoolean(objXmlCharacter["technomancer"].InnerText); try { _blnInitiationEnabled = Convert.ToBoolean(objXmlCharacter["initiationoverride"].InnerText); } catch { } try { _blnCritterEnabled = Convert.ToBoolean(objXmlCharacter["critter"].InnerText); } catch { } try { _blnUneducated = Convert.ToBoolean(objXmlCharacter["uneducated"].InnerText); } catch { } try { _blnUncouth = Convert.ToBoolean(objXmlCharacter["uncouth"].InnerText); } catch { } try { _blnInfirm = Convert.ToBoolean(objXmlCharacter["infirm"].InnerText); } catch { } try { _blnBlackMarket = Convert.ToBoolean(objXmlCharacter["blackmarket"].InnerText); } catch { } _blnMAGEnabled = Convert.ToBoolean(objXmlCharacter["magenabled"].InnerText); try { _intInitiateGrade = Convert.ToInt32(objXmlCharacter["initiategrade"].InnerText); } catch { } _blnRESEnabled = Convert.ToBoolean(objXmlCharacter["resenabled"].InnerText); try { _intSubmersionGrade = Convert.ToInt32(objXmlCharacter["submersiongrade"].InnerText); } catch { } try { _blnGroupMember = Convert.ToBoolean(objXmlCharacter["groupmember"].InnerText); } catch { } try { _strGroupName = objXmlCharacter["groupname"].InnerText; _strGroupNotes = objXmlCharacter["groupnotes"].InnerText; } catch { } // Improvements. XmlNodeList objXmlImprovementList = objXmlDocument.SelectNodes("/character/improvements/improvement"); foreach (XmlNode objXmlImprovement in objXmlImprovementList) { Improvement objImprovement = new Improvement(); objImprovement.Load(objXmlImprovement); _lstImprovements.Add(objImprovement); } // Qualities objXmlNodeList = objXmlDocument.SelectNodes("/character/qualities/quality"); bool blnHasOldQualities = false; foreach (XmlNode objXmlQuality in objXmlNodeList) { if (objXmlQuality["name"] != null) { Quality objQuality = new Quality(this); objQuality.Load(objXmlQuality); _lstQualities.Add(objQuality); } else { // If the Quality does not have a name tag, it is in the old format. Set the flag to show that old Qualities are in use. blnHasOldQualities = true; } } // If old Qualities are in use, they need to be converted before we can continue. if (blnHasOldQualities) ConvertOldQualities(objXmlNodeList); // Attributes. objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"BOD\"]"); _attBOD.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"AGI\"]"); _attAGI.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"REA\"]"); _attREA.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"STR\"]"); _attSTR.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"CHA\"]"); _attCHA.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"INT\"]"); _attINT.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"LOG\"]"); _attLOG.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"WIL\"]"); _attWIL.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"INI\"]"); _attINI.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"EDG\"]"); _attEDG.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"MAG\"]"); _attMAG.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"RES\"]"); _attRES.Load(objXmlCharacter); objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"ESS\"]"); _attESS.Load(objXmlCharacter); // A.I. Attributes. try { _intSignal = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/attributes/signal").InnerText); _intResponse = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/attributes/response").InnerText); } catch { } // Force. try { _intMaxSkillRating = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/attributes/maxskillrating").InnerText); } catch { } // Attempt to load the split MAG Attribute information for Mystic Adepts. if (_blnAdeptEnabled && _blnMagicianEnabled) { try { _intMAGAdept = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/magsplitadept").InnerText); _intMAGMagician = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/magsplitmagician").InnerText); } catch { } } // Attempt to load the Magic Tradition. try { _strMagicTradition = objXmlDocument.SelectSingleNode("/character/tradition").InnerText; } catch { } // Attempt to load the Technomancer Stream. try { _strTechnomancerStream = objXmlDocument.SelectSingleNode("/character/stream").InnerText; } catch { } // Attempt to load Condition Monitor Progress. try { _intPhysicalCMFilled = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/physicalcmfilled").InnerText); _intStunCMFilled = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/stuncmfilled").InnerText); } catch { } // Skills. foreach (Skill objSkill in _lstSkills) { XmlNode objXmlSkill = objXmlDocument.SelectSingleNode("/character/skills/skill[name = \"" + objSkill.Name + "\"]"); if (objXmlSkill != null) { objSkill.Load(objXmlSkill); } } // Exotic Skills. objXmlNodeList = objXmlDocument.SelectNodes("/character/skills/skill[exotic = \"True\"]"); foreach (XmlNode objXmlSkill in objXmlNodeList) { Skill objSkill = new Skill(this); objSkill.Load(objXmlSkill); _lstSkills.Add(objSkill); } // SkillGroups. foreach (SkillGroup objGroup in _lstSkillGroups) { XmlNode objXmlSkill = objXmlDocument.SelectSingleNode("/character/skillgroups/skillgroup[name = \"" + objGroup.Name + "\"]"); if (objXmlSkill != null) { objGroup.Load(objXmlSkill); // If the character is set to ignore rules or is in Career Mode, Skill Groups should have a maximum Rating of 6 unless they have been given a higher maximum Rating already. if ((_blnIgnoreRules || _blnCreated) && objGroup.RatingMaximum < 6) objGroup.RatingMaximum = 6; } } // Knowledge Skills. List<ListItem> lstKnowledgeSkillOrder = new List<ListItem>(); objXmlNodeList = objXmlDocument.SelectNodes("/character/skills/skill[knowledge = \"True\"]"); // Sort the Knowledge Skills in alphabetical order. foreach (XmlNode objXmlSkill in objXmlNodeList) { ListItem objGroup = new ListItem(); objGroup.Value = objXmlSkill["name"].InnerText; objGroup.Name = objXmlSkill["name"].InnerText; lstKnowledgeSkillOrder.Add(objGroup); } SortListItem objSort = new SortListItem(); lstKnowledgeSkillOrder.Sort(objSort.Compare); foreach (ListItem objItem in lstKnowledgeSkillOrder) { Skill objSkill = new Skill(this); XmlNode objNode = objXmlDocument.SelectSingleNode("/character/skills/skill[knowledge = \"True\" and name = " + CleanXPath(objItem.Value) + "]"); objSkill.Load(objNode); _lstSkills.Add(objSkill); } // Contacts. objXmlNodeList = objXmlDocument.SelectNodes("/character/contacts/contact"); foreach (XmlNode objXmlContact in objXmlNodeList) { Contact objContact = new Contact(this); objContact.Load(objXmlContact); _lstContacts.Add(objContact); } // Armor. objXmlNodeList = objXmlDocument.SelectNodes("/character/armors/armor"); foreach (XmlNode objXmlArmor in objXmlNodeList) { Armor objArmor = new Armor(this); objArmor.Load(objXmlArmor); _lstArmor.Add(objArmor); } // Weapons. objXmlNodeList = objXmlDocument.SelectNodes("/character/weapons/weapon"); foreach (XmlNode objXmlWeapon in objXmlNodeList) { Weapon objWeapon = new Weapon(this); objWeapon.Load(objXmlWeapon); _lstWeapons.Add(objWeapon); } // Cyberware/Bioware. objXmlNodeList = objXmlDocument.SelectNodes("/character/cyberwares/cyberware"); foreach (XmlNode objXmlCyberware in objXmlNodeList) { Cyberware objCyberware = new Cyberware(this); objCyberware.Load(objXmlCyberware); _lstCyberware.Add(objCyberware); } // Spells. objXmlNodeList = objXmlDocument.SelectNodes("/character/spells/spell"); foreach (XmlNode objXmlSpell in objXmlNodeList) { Spell objSpell = new Spell(this); objSpell.Load(objXmlSpell); _lstSpells.Add(objSpell); } // Foci. objXmlNodeList = objXmlDocument.SelectNodes("/character/foci/focus"); foreach (XmlNode objXmlFocus in objXmlNodeList) { Focus objFocus = new Focus(); objFocus.Load(objXmlFocus); _lstFoci.Add(objFocus); } // Stacked Foci. objXmlNodeList = objXmlDocument.SelectNodes("/character/stackedfoci/stackedfocus"); foreach (XmlNode objXmlStack in objXmlNodeList) { StackedFocus objStack = new StackedFocus(this); objStack.Load(objXmlStack); _lstStackedFoci.Add(objStack); } // Powers. objXmlNodeList = objXmlDocument.SelectNodes("/character/powers/power"); foreach (XmlNode objXmlPower in objXmlNodeList) { Power objPower = new Power(this); objPower.Load(objXmlPower); _lstPowers.Add(objPower); } // Spirits/Sprites. objXmlNodeList = objXmlDocument.SelectNodes("/character/spirits/spirit"); foreach (XmlNode objXmlSpirit in objXmlNodeList) { Spirit objSpirit = new Spirit(this); objSpirit.Load(objXmlSpirit); _lstSpirits.Add(objSpirit); } // Compex Forms/Technomancer Programs. objXmlNodeList = objXmlDocument.SelectNodes("/character/techprograms/techprogram"); foreach (XmlNode objXmlProgram in objXmlNodeList) { TechProgram objProgram = new TechProgram(this); objProgram.Load(objXmlProgram); _lstTechPrograms.Add(objProgram); } // Martial Arts. objXmlNodeList = objXmlDocument.SelectNodes("/character/martialarts/martialart"); foreach (XmlNode objXmlArt in objXmlNodeList) { MartialArt objMartialArt = new MartialArt(this); objMartialArt.Load(objXmlArt); _lstMartialArts.Add(objMartialArt); } // Martial Art Maneuvers. objXmlNodeList = objXmlDocument.SelectNodes("/character/martialartmaneuvers/martialartmaneuver"); foreach (XmlNode objXmlManeuver in objXmlNodeList) { MartialArtManeuver objManeuver = new MartialArtManeuver(this); objManeuver.Load(objXmlManeuver); _lstMartialArtManeuvers.Add(objManeuver); } // Lifestyles. objXmlNodeList = objXmlDocument.SelectNodes("/character/lifestyles/lifestyle"); foreach (XmlNode objXmlLifestyle in objXmlNodeList) { Lifestyle objLifestyle = new Lifestyle(this); objLifestyle.Load(objXmlLifestyle); _lstLifestyles.Add(objLifestyle); } // <gears> objXmlNodeList = objXmlDocument.SelectNodes("/character/gears/gear"); foreach (XmlNode objXmlGear in objXmlNodeList) { switch (objXmlGear["category"].InnerText) { case "Commlink": case "Commlink Upgrade": Commlink objCommlink = new Commlink(this); objCommlink.Load(objXmlGear); _lstGear.Add(objCommlink); break; case "Commlink Operating System": case "Commlink Operating System Upgrade": OperatingSystem objOperatingSystem = new OperatingSystem(this); objOperatingSystem.Load(objXmlGear); _lstGear.Add(objOperatingSystem); break; default: Gear objGear = new Gear(this); objGear.Load(objXmlGear); _lstGear.Add(objGear); break; } } // Vehicles. objXmlNodeList = objXmlDocument.SelectNodes("/character/vehicles/vehicle"); foreach (XmlNode objXmlVehicle in objXmlNodeList) { Vehicle objVehicle = new Vehicle(this); objVehicle.Load(objXmlVehicle); _lstVehicles.Add(objVehicle); } // Metamagics/Echoes. objXmlNodeList = objXmlDocument.SelectNodes("/character/metamagics/metamagic"); foreach (XmlNode objXmlMetamagic in objXmlNodeList) { Metamagic objMetamagic = new Metamagic(this); objMetamagic.Load(objXmlMetamagic); _lstMetamagics.Add(objMetamagic); } // Critter Powers. objXmlNodeList = objXmlDocument.SelectNodes("/character/critterpowers/critterpower"); foreach (XmlNode objXmlPower in objXmlNodeList) { CritterPower objPower = new CritterPower(this); objPower.Load(objXmlPower); _lstCritterPowers.Add(objPower); } // Initiation Grades. objXmlNodeList = objXmlDocument.SelectNodes("/character/initiationgrades/initiationgrade"); foreach (XmlNode objXmlGrade in objXmlNodeList) { InitiationGrade objGrade = new InitiationGrade(this); objGrade.Load(objXmlGrade); _lstInitiationGrades.Add(objGrade); } // Expense Log Entries. XmlNodeList objXmlExpenseList = objXmlDocument.SelectNodes("/character/expenses/expense"); foreach (XmlNode objXmlExpense in objXmlExpenseList) { ExpenseLogEntry objExpenseLogEntry = new ExpenseLogEntry(); objExpenseLogEntry.Load(objXmlExpense); _lstExpenseLog.Add(objExpenseLogEntry); } // Locations. XmlNodeList objXmlLocationList = objXmlDocument.SelectNodes("/character/locations/location"); foreach (XmlNode objXmlLocation in objXmlLocationList) { _lstLocations.Add(objXmlLocation.InnerText); } // Armor Bundles. XmlNodeList objXmlBundleList = objXmlDocument.SelectNodes("/character/armorbundles/armorbundle"); foreach (XmlNode objXmlBundle in objXmlBundleList) { _lstArmorBundles.Add(objXmlBundle.InnerText); } // Weapon Locations. XmlNodeList objXmlWeaponLocationList = objXmlDocument.SelectNodes("/character/weaponlocations/weaponlocation"); foreach (XmlNode objXmlLocation in objXmlWeaponLocationList) { _lstWeaponLocations.Add(objXmlLocation.InnerText); } // Improvement Groups. XmlNodeList objXmlGroupList = objXmlDocument.SelectNodes("/character/improvementgroups/improvementgroup"); foreach (XmlNode objXmlGroup in objXmlGroupList) { _lstImprovementGroups.Add(objXmlGroup.InnerText); } // Calendar. XmlNodeList objXmlWeekList = objXmlDocument.SelectNodes("/character/calendar/week"); foreach (XmlNode objXmlWeek in objXmlWeekList) { CalendarWeek objWeek = new CalendarWeek(); objWeek.Load(objXmlWeek); _lstCalendar.Add(objWeek); } // If the character had old Qualities that were converted, immediately save the file so they are in the new format. if (blnHasOldQualities) Save(); return true; }
/// <summary> /// Creates a new SmallSpellControl and returns it. /// </summary> /// <param name="spell"></param> /// <returns></returns> private SmallSpellControl GetSmallSpellControl(Spell spell) { SmallSpellControl ucSpell = new SmallSpellControl(this); ucSpell.Spell = spell; ucSpell.DiceClick += DiceClick_Clicked; ucSpell.DrainResist = GetSpellDrainResist(); return ucSpell; }