/// <summary> /// Populate the list of Bonded Foci. /// </summary> public void PopulateFocusList(TreeView treFoci) { treFoci.Nodes.Clear(); int intFociTotal = 0; bool blnWarned = false; foreach (Gear objGear in _objCharacter.Gear) { if (objGear.Category == "Foci" || objGear.Category == "Metamagic Foci") { TreeNode objNode = new TreeNode(); objNode.Text = objGear.DisplayName.Replace(LanguageManager.Instance.GetString("String_Rating"), LanguageManager.Instance.GetString("String_Force")); objNode.Tag = objGear.InternalId; foreach (Focus objFocus in _objCharacter.Foci) { if (objFocus.GearId == objGear.InternalId) { objNode.Checked = true; objFocus.Rating = objGear.Rating; intFociTotal += objFocus.Rating; // Do not let the number of BP spend on bonded Foci exceed MAG * 5. if (intFociTotal > _objCharacter.MAG.TotalValue * 5 && !_objCharacter.IgnoreRules) { // Mark the Gear a Bonded. foreach (Gear objCharacterGear in _objCharacter.Gear) { if (objCharacterGear.InternalId == objFocus.GearId) { objCharacterGear.Bonded = false; } } _objCharacter.Foci.Remove(objFocus); if (!blnWarned) { objNode.Checked = false; MessageBox.Show(LanguageManager.Instance.GetString("Message_FocusMaximumForce"), LanguageManager.Instance.GetString("MessageTitle_FocusMaximum"), MessageBoxButtons.OK, MessageBoxIcon.Information); blnWarned = true; break; } } } } treFoci.Nodes.Add(objNode); } } // Add Stacked Foci. foreach (Gear objGear in _objCharacter.Gear) { if (objGear.Category == "Stacked Focus") { foreach (StackedFocus objStack in _objCharacter.StackedFoci) { if (objStack.GearId == objGear.InternalId) { TreeNode objNode = new TreeNode(); objNode.Text = LanguageManager.Instance.GetString("String_StackedFocus") + ": " + objStack.Name; objNode.Tag = objStack.InternalId; _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.StackedFocus, objStack.InternalId); if (objStack.Bonded) { foreach (Gear objFociGear in objStack.Gear) { if (objFociGear.Extra != string.Empty) { _objImprovementManager.ForcedValue = objFociGear.Extra; } _objImprovementManager.CreateImprovements(Improvement.ImprovementSource.StackedFocus, objStack.InternalId, objFociGear.Bonus, false, objFociGear.Rating, objFociGear.DisplayNameShort); } objNode.Checked = true; } treFoci.Nodes.Add(objNode); } } } } }
/// <summary> /// Create a Mentor Spirit from an XmlNode. /// </summary> /// <param name="xmlMentor">XmlNode to create the object from.</param> /// <param name="eMentorType">Whether this is a Mentor or a Paragon.</param> /// <param name="strForceValueChoice1">Name/Text for Choice 1.</param> /// <param name="strForceValueChoice2">Name/Text for Choice 2.</param> /// <param name="strForceValue">Force a value to be selected for the Mentor Spirit.</param> /// <param name="blnMentorMask">Whether the Mentor's Mask is enabled.</param> public void Create(XmlNode xmlMentor, Improvement.ImprovementType eMentorType, string strForceValue = "", string strForceValueChoice1 = "", string strForceValueChoice2 = "", bool blnMentorMask = false) { _blnMentorMask = blnMentorMask; _eMentorType = eMentorType; _objCachedMyXmlNode = null; xmlMentor.TryGetStringFieldQuickly("name", ref _strName); xmlMentor.TryGetStringFieldQuickly("source", ref _strSource); xmlMentor.TryGetStringFieldQuickly("page", ref _strPage); if (!xmlMentor.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { xmlMentor.TryGetStringFieldQuickly("notes", ref _strNotes); } if (xmlMentor.TryGetField("id", Guid.TryParse, out Guid guiTemp)) { _sourceID = guiTemp; } // Build the list of advantages gained through the Mentor Spirit. if (!xmlMentor.TryGetStringFieldQuickly("altadvantage", ref _strAdvantage)) { xmlMentor.TryGetStringFieldQuickly("advantage", ref _strAdvantage); } if (!xmlMentor.TryGetStringFieldQuickly("altdisadvantage", ref _strDisadvantage)) { xmlMentor.TryGetStringFieldQuickly("disadvantage", ref _strDisadvantage); } _nodBonus = xmlMentor["bonus"]; if (_nodBonus != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = strForceValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), _nodBonus, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } _strExtra = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (!string.IsNullOrEmpty(strForceValue)) { _strExtra = strForceValue; } _nodChoice1 = xmlMentor.SelectSingleNode("choices/choice[name = \"" + strForceValueChoice1 + "\"]/bonus"); if (_nodChoice1 != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; //ImprovementManager.ForcedValue = strForceValueChoice1; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), _nodChoice1, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (string.IsNullOrEmpty(_strExtra)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (string.IsNullOrEmpty(_strExtra) && !string.IsNullOrEmpty(strForceValueChoice1)) { _strExtra = strForceValueChoice1; } _nodChoice2 = xmlMentor.SelectSingleNode("choices/choice[name = \"" + strForceValueChoice2 + "\"]/bonus"); if (_nodChoice2 != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; //ImprovementManager.ForcedValue = strForceValueChoice2; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), _nodChoice2, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (string.IsNullOrEmpty(_strExtra)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (string.IsNullOrEmpty(_strExtra) && !string.IsNullOrEmpty(strForceValueChoice2)) { _strExtra = strForceValueChoice2; } if (_blnMentorMask) { ImprovementManager.CreateImprovement(_objCharacter, string.Empty, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), Improvement.ImprovementType.AdeptPowerPoints, string.Empty, 1); ImprovementManager.CreateImprovement(_objCharacter, string.Empty, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), Improvement.ImprovementType.DrainValue, string.Empty, -1); ImprovementManager.Commit(_objCharacter); } /* * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPDF($"{_strSource} {_strPage}", _strName); * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPDF($"{Source} {Page(GlobalOptions.Language)}", DisplayName(GlobalOptions.Language)); * } * }*/ }
/// Create a Armor Modification from an XmlNode and return the TreeNodes for it. /// <param name="objXmlArmorNode">XmlNode to create the object from.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="intRating">Rating of the selected ArmorMod.</param> /// <param name="objWeapons">List of Weapons that are created by the Armor.</param> /// <param name="objWeaponNodes">List of Weapon Nodes that are created by the Armor.</param> /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param> public void Create(XmlNode objXmlArmorNode, TreeNode objNode, int intRating, List<Weapon> objWeapons, List<TreeNode> objWeaponNodes, bool blnSkipCost = false) { _strName = objXmlArmorNode["name"].InnerText; _strCategory = objXmlArmorNode["category"].InnerText; _strArmorCapacity = objXmlArmorNode["armorcapacity"].InnerText; _intA = Convert.ToInt32(objXmlArmorNode["armor"].InnerText); _intRating = intRating; _intMaxRating = Convert.ToInt32(objXmlArmorNode["maxrating"].InnerText); _strAvail = objXmlArmorNode["avail"].InnerText; _strCost = objXmlArmorNode["cost"].InnerText; _strSource = objXmlArmorNode["source"].InnerText; _strPage = objXmlArmorNode["page"].InnerText; _nodBonus = objXmlArmorNode["bonus"]; if (GlobalOptions.Instance.Language != "en-us") { XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml"); XmlNode objArmorNode = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + _strName + "\"]"); if (objArmorNode != null) { if (objArmorNode["translate"] != null) _strAltName = objArmorNode["translate"].InnerText; if (objArmorNode["altpage"] != null) _strAltPage = objArmorNode["altpage"].InnerText; } objArmorNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]"); if (objArmorNode != null) { if (objArmorNode.Attributes["translate"] != null) _strAltCategory = objArmorNode.Attributes["translate"].InnerText; } } if (objXmlArmorNode["bonus"] != null && !blnSkipCost) { ImprovementManager objImprovementManager = new ImprovementManager(_objCharacter); if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.ArmorMod, _guiID.ToString(), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (objImprovementManager.SelectedValue != "") { _strExtra = objImprovementManager.SelectedValue; objNode.Text += " (" + objImprovementManager.SelectedValue + ")"; } } // Add Weapons if applicable. if (objXmlArmorNode.InnerXml.Contains("<addweapon>")) { XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml"); // More than one Weapon can be added, so loop through all occurrences. foreach (XmlNode objXmlAddWeapon in objXmlArmorNode.SelectNodes("addweapon")) { XmlNode objXmlWeapon = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlAddWeapon.InnerText + "\" and starts-with(category, \"Cyberware\")]"); TreeNode objGearWeaponNode = new TreeNode(); Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Create(objXmlWeapon, _objCharacter, objGearWeaponNode, null, null); objGearWeaponNode.ForeColor = SystemColors.GrayText; objWeaponNodes.Add(objGearWeaponNode); objWeapons.Add(objGearWeapon); _guiWeaponID = Guid.Parse(objGearWeapon.InternalId); } } objNode.Text = DisplayName; objNode.Tag = _guiID.ToString(); }
/// <summary> /// Create a Mentor Spirit from an XmlNode. /// </summary> /// <param name="xmlMentor">XmlNode to create the object from.</param> /// <param name="eMentorType">Whether this is a Mentor or a Paragon.</param> /// <param name="strForceValueChoice1">Name/Text for Choice 1.</param> /// <param name="strForceValueChoice2">Name/Text for Choice 2.</param> /// <param name="strForceValue">Force a value to be selected for the Mentor Spirit.</param> public void Create(XmlNode xmlMentor, Improvement.ImprovementType eMentorType, string strForceValue = "", string strForceValueChoice1 = "", string strForceValueChoice2 = "") { _eMentorType = eMentorType; _objCachedMyXmlNode = null; _objCachedMyXPathNode = null; xmlMentor.TryGetStringFieldQuickly("name", ref _strName); xmlMentor.TryGetStringFieldQuickly("source", ref _strSource); xmlMentor.TryGetStringFieldQuickly("page", ref _strPage); if (!xmlMentor.TryGetMultiLineStringFieldQuickly("altnotes", ref _strNotes)) { xmlMentor.TryGetMultiLineStringFieldQuickly("notes", ref _strNotes); } if (string.IsNullOrEmpty(_strNotes)) { _strNotes = CommonFunctions.GetBookNotes(xmlMentor, Name, CurrentDisplayNameShort, Source, Page, DisplayPage(GlobalSettings.Language), _objCharacter); } if (!xmlMentor.TryGetField("id", Guid.TryParse, out _guiSourceID)) { Log.Warn(new object[] { "Missing id field for xmlnode", xmlMentor }); Utils.BreakIfDebug(); } // Cache the English list of advantages gained through the Mentor Spirit. xmlMentor.TryGetMultiLineStringFieldQuickly("advantage", ref _strAdvantage); xmlMentor.TryGetMultiLineStringFieldQuickly("disadvantage", ref _strDisadvantage); _nodBonus = xmlMentor["bonus"]; if (_nodBonus != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = strForceValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D", GlobalSettings.InvariantCultureInfo), _nodBonus, 1, CurrentDisplayNameShort)) { _guiID = Guid.Empty; return; } _strExtra = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (!string.IsNullOrEmpty(strForceValue)) { _strExtra = strForceValue; } _nodChoice1 = xmlMentor.SelectSingleNode("choices/choice[name = " + strForceValueChoice1.CleanXPath() + "]/bonus"); if (_nodChoice1 != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; //ImprovementManager.ForcedValue = strForceValueChoice1; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D", GlobalSettings.InvariantCultureInfo), _nodChoice1, 1, CurrentDisplayNameShort)) { _guiID = Guid.Empty; return; } if (string.IsNullOrEmpty(_strExtra)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (string.IsNullOrEmpty(_strExtra) && !string.IsNullOrEmpty(strForceValueChoice1)) { _strExtra = strForceValueChoice1; } _nodChoice2 = xmlMentor.SelectSingleNode("choices/choice[name = " + strForceValueChoice2.CleanXPath() + "]/bonus"); if (_nodChoice2 != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; //ImprovementManager.ForcedValue = strForceValueChoice2; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D", GlobalSettings.InvariantCultureInfo), _nodChoice2, 1, CurrentDisplayNameShort)) { _guiID = Guid.Empty; return; } if (string.IsNullOrEmpty(_strExtra)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (string.IsNullOrEmpty(_strExtra) && !string.IsNullOrEmpty(strForceValueChoice2)) { _strExtra = strForceValueChoice2; } /* * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPdf(_strSource + ' ' + _strPage, _strName); * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPdf(Source + ' ' + DisplayPage(GlobalSettings.Language), CurrentDisplayName); * } * } */ }
/// <summary> /// Accept the values on the Form and create the required XML data. /// </summary> private void AcceptForm() { // Make sure a value has been selected if necessary. if (txtTranslateSelection.Visible && string.IsNullOrEmpty(txtSelect.Text)) { Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_SelectItem"), LanguageManager.GetString("MessageTitle_SelectItem"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Make sure a value has been provided for the name. if (string.IsNullOrEmpty(txtName.Text)) { Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_ImprovementName"), LanguageManager.GetString("MessageTitle_ImprovementName"), MessageBoxButtons.OK, MessageBoxIcon.Error); txtName.Focus(); return; } XmlDocument objBonusXml = new XmlDocument { XmlResolver = null }; using (MemoryStream objStream = new MemoryStream()) { // Here instead of later because objWriter.Close() needs Stream to not be disposed, but StreamReader.Close() will dispose the Stream. using (StreamReader objReader = new StreamReader(objStream, Encoding.UTF8, true)) { using (XmlWriter objWriter = XmlWriter.Create(objStream)) { // Build the XML for the Improvement. XmlNode objFetchNode = _objDocument.SelectSingleNode("/chummer/improvements/improvement[id = \"" + cboImprovemetType.SelectedValue + "\"]"); string strInternal = objFetchNode?["internal"]?.InnerText; if (string.IsNullOrEmpty(strInternal)) { return; } objWriter.WriteStartDocument(); // <bonus> objWriter.WriteStartElement("bonus"); // <whatever element> objWriter.WriteStartElement(strInternal); string strRating = string.Empty; if (chkApplyToRating.Checked) { strRating = "<applytorating>True</applytorating>"; } // Retrieve the XML data from the document and replace the values as necessary. // ReSharper disable once PossibleNullReferenceException string strXml = objFetchNode["xml"].InnerText .Replace("{val}", nudVal.Value.ToString(GlobalOptions.InvariantCultureInfo)) .Replace("{min}", nudMin.Value.ToString(GlobalOptions.InvariantCultureInfo)) .Replace("{max}", nudMax.Value.ToString(GlobalOptions.InvariantCultureInfo)) .Replace("{aug}", nudAug.Value.ToString(GlobalOptions.InvariantCultureInfo)) .Replace("{free}", chkFree.Checked.ToString(GlobalOptions.InvariantCultureInfo).ToLowerInvariant()) .Replace("{select}", txtSelect.Text) .Replace("{applytorating}", strRating); objWriter.WriteRaw(strXml); // Write the rest of the document. // </whatever element> objWriter.WriteEndElement(); // </bonus> objWriter.WriteEndElement(); objWriter.WriteEndDocument(); objWriter.Flush(); objStream.Position = 0; // Read it back in as an XmlDocument. using (XmlReader objXmlReader = XmlReader.Create(objReader, GlobalOptions.SafeXmlReaderSettings)) objBonusXml.Load(objXmlReader); } } } // Pluck out the bonus information. XmlNode objNode = objBonusXml.SelectSingleNode("/bonus"); // Pass it to the Improvement Manager so that it can be added to the character. string strGuid = Guid.NewGuid().ToString("D", GlobalOptions.InvariantCultureInfo); ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.Custom, strGuid, objNode, 1, txtName.Text); // If an Improvement was passed in, remove it from the character. string strNotes = string.Empty; int intOrder = 0; if (EditImprovementObject != null) { // Copy the notes over to the new item. strNotes = EditImprovementObject.Notes; intOrder = EditImprovementObject.SortOrder; ImprovementManager.RemoveImprovements(_objCharacter, Improvement.ImprovementSource.Custom, EditImprovementObject.SourceName); } // Find the newly-created Improvement and attach its custom name. Improvement objImprovement = _objCharacter.Improvements.FirstOrDefault(imp => imp.SourceName == strGuid); if (objImprovement != null) { objImprovement.CustomName = txtName.Text; objImprovement.CustomId = cboImprovemetType.SelectedValue.ToString(); objImprovement.Custom = true; objImprovement.Notes = strNotes; objImprovement.SortOrder = intOrder; objImprovement.CustomGroup = _strCustomGroup; NewImprovement = objImprovement; } else { Utils.BreakIfDebug(); } DialogResult = DialogResult.OK; }
public bool Create(XmlNode objNode, int intRating = 1, XmlNode objBonusNodeOverride = null, bool blnCreateImprovements = true) { objNode.TryGetStringFieldQuickly("name", ref _strName); objNode.TryGetField("id", Guid.TryParse, out _guiSourceID); _objCachedMyXmlNode = null; objNode.TryGetStringFieldQuickly("points", ref _strPointsPerLevel); objNode.TryGetStringFieldQuickly("adeptway", ref _strAdeptWayDiscount); objNode.TryGetBoolFieldQuickly("levels", ref _blnLevelsEnabled); _intRating = intRating; if (!objNode.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objNode.TryGetStringFieldQuickly("notes", ref _strNotes); } if (!objNode.TryGetInt32FieldQuickly("maxlevel", ref _intMaxLevels)) { objNode.TryGetInt32FieldQuickly("maxlevels", ref _intMaxLevels); } objNode.TryGetBoolFieldQuickly("discounted", ref _blnDiscountedAdeptWay); objNode.TryGetBoolFieldQuickly("discountedgeas", ref _blnDiscountedGeas); objNode.TryGetStringFieldQuickly("bonussource", ref _strBonusSource); objNode.TryGetDecFieldQuickly("freepoints", ref _decFreePoints); objNode.TryGetDecFieldQuickly("extrapointcost", ref _decExtraPointCost); objNode.TryGetStringFieldQuickly("action", ref _strAction); objNode.TryGetStringFieldQuickly("source", ref _strSource); objNode.TryGetStringFieldQuickly("page", ref _strPage); Bonus = objNode["bonus"]; if (objBonusNodeOverride != null) { Bonus = objBonusNodeOverride; } _nodAdeptWayRequirements = objNode["adeptwayrequires"]?.CreateNavigator(); XmlNode nodEnhancements = objNode["enhancements"]; if (nodEnhancements != null) { using (XmlNodeList xmlEnhancementList = nodEnhancements.SelectNodes("enhancement")) { if (xmlEnhancementList != null) { foreach (XmlNode nodEnhancement in xmlEnhancementList) { Enhancement objEnhancement = new Enhancement(CharacterObject); objEnhancement.Load(nodEnhancement); objEnhancement.Parent = this; Enhancements.Add(objEnhancement); } } } } if (blnCreateImprovements && Bonus != null && Bonus.HasChildNodes) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = Extra; if (!ImprovementManager.CreateImprovements(CharacterObject, Improvement.ImprovementSource.Power, InternalId, Bonus, TotalRating, DisplayNameShort(GlobalOptions.Language))) { ImprovementManager.ForcedValue = strOldForce; DeletePower(); return(false); } Extra = ImprovementManager.SelectedValue; ImprovementManager.SelectedValue = strOldSelected; ImprovementManager.ForcedValue = strOldForce; } if (TotalMaximumLevels < Rating) { Rating = TotalMaximumLevels; } return(true); }
/// Create a Martial Art Technique from an XmlNode. /// <param name="xmlTechniqueDataNode">XmlNode to create the object from.</param> public void Create(XmlNode xmlTechniqueDataNode) { if (!xmlTechniqueDataNode.TryGetField("id", Guid.TryParse, out _guiSourceID)) { Log.Warn(new object[] { "Missing id field for xmlnode", xmlTechniqueDataNode }); Utils.BreakIfDebug(); } if (xmlTechniqueDataNode.TryGetStringFieldQuickly("name", ref _strName)) { if (!xmlTechniqueDataNode.TryGetMultiLineStringFieldQuickly("altnotes", ref _strNotes)) { xmlTechniqueDataNode.TryGetMultiLineStringFieldQuickly("notes", ref _strNotes); } } xmlTechniqueDataNode.TryGetStringFieldQuickly("source", ref _strSource); xmlTechniqueDataNode.TryGetStringFieldQuickly("page", ref _strPage); if (string.IsNullOrEmpty(Notes)) { string strEnglishNameOnPage = Name; string strNameOnPage = string.Empty; // make sure we have something and not just an empty tag if (xmlTechniqueDataNode.TryGetStringFieldQuickly("nameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage)) { strEnglishNameOnPage = strNameOnPage; } string strQualityNotes = CommonFunctions.GetTextFromPdf(Source + ' ' + Page, strEnglishNameOnPage, _objCharacter); if (string.IsNullOrEmpty(strQualityNotes) && GlobalOptions.Language != GlobalOptions.DefaultLanguage) { string strTranslatedNameOnPage = CurrentDisplayName; // don't check again it is not translated if (strTranslatedNameOnPage != _strName) { // if we found <altnameonpage>, and is not empty and not the same as english we must use that instead if (xmlTechniqueDataNode.TryGetStringFieldQuickly("altnameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage) && strNameOnPage != strEnglishNameOnPage) { strTranslatedNameOnPage = strNameOnPage; } Notes = CommonFunctions.GetTextFromPdf(Source + ' ' + DisplayPage(GlobalOptions.Language), strTranslatedNameOnPage, _objCharacter); } } else { Notes = strQualityNotes; } } if (xmlTechniqueDataNode["bonus"] == null) { return; } if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MartialArtTechnique, _guiID.ToString("D", GlobalOptions.InvariantCultureInfo), xmlTechniqueDataNode["bonus"], 1, CurrentDisplayName)) { _guiID = Guid.Empty; } }
private void cmdOK_Click(object sender, EventArgs e) { // Make sure that each Priority has only been selected once. bool blnValid = true; if (cboPriorityMetatype.SelectedValue == cboPriorityAttributes.SelectedValue) { blnValid = false; } if (cboPriorityMetatype.SelectedValue == cboPrioritySpecial.SelectedValue) { blnValid = false; } if (cboPriorityMetatype.SelectedValue == cboPrioritySkills.SelectedValue) { blnValid = false; } if (cboPriorityMetatype.SelectedValue == cboPriorityNuyen.SelectedValue) { blnValid = false; } if (cboPriorityAttributes.SelectedValue == cboPrioritySpecial.SelectedValue) { blnValid = false; } if (cboPriorityAttributes.SelectedValue == cboPrioritySkills.SelectedValue) { blnValid = false; } if (cboPriorityAttributes.SelectedValue == cboPriorityNuyen.SelectedValue) { blnValid = false; } if (cboPrioritySpecial.SelectedValue == cboPrioritySkills.SelectedValue) { blnValid = false; } if (cboPrioritySpecial.SelectedValue == cboPriorityNuyen.SelectedValue) { blnValid = false; } if (cboPrioritySkills.SelectedValue == cboPriorityNuyen.SelectedValue) { blnValid = false; } if (!blnValid) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Priorities_UniquePriorities"), LanguageManager.Instance.GetString("MessageTitle_Priorities_UniquePriorities"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { // Determine the number of Special Attribute points that come from the selected Metatype. XmlNode objXmlMetatypesNode = _objXmlDocument.SelectSingleNode("/chummer/priorities/metatypes/metatype[priority = \"" + cboPriorityMetatype.SelectedValue.ToString() + "\"]"); XmlNode objXmlMetatypeNode = objXmlMetatypesNode.SelectSingleNode("metatypes/metatype[id = \"" + cboMetatype.SelectedValue.ToString() + "\"]"); int intSpecialAttributePoints = Convert.ToInt32(objXmlMetatypeNode["points"].InnerText); // Determine the number of Attribute Points selected. XmlNode objXmlAttributeNode = _objXmlDocument.SelectSingleNode("/chummer/priorities/attributes/attribute[priority = \"" + cboPriorityAttributes.SelectedValue.ToString() + "\"]"); int intAttributePoints = Convert.ToInt32(objXmlAttributeNode["points"].InnerText); // Determine if the character gets anything from their Special Priority. if (cboSpecial.SelectedValue != null) { if (cboSpecial.SelectedValue.ToString() != string.Empty) { XmlNode objXmlSpecialNode = _objXmlDocument.SelectSingleNode("/chummer/priorities/specials/special[priority = \"" + cboPrioritySpecial.SelectedValue.ToString() + "\"]/" + cboSpecial.SelectedValue.ToString()); if (objXmlSpecialNode["bonus"] != null) { ImprovementManager objImprovementManager = new ImprovementManager(_objCharacter); objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Priority, "Priority", objXmlSpecialNode["bonus"]); } } } // Determine the number of Skill Points selected. // Determine the amount of Nuyen selected. XmlNode objXmlNuyenNode = _objXmlDocument.SelectSingleNode("/chummer/priorities/resources/resource[priority = \"" + cboPriorityNuyen.SelectedValue.ToString() + "\"]"); int intNuyen = Convert.ToInt32(objXmlNuyenNode["nuyen"].InnerText); // Load the Metatype and set the character build information. _objCharacter.LoadMetatype(Guid.Parse(cboMetatype.SelectedValue.ToString())); _objCharacter.SpecialAttributePoints = intSpecialAttributePoints; _objCharacter.AttributePoints = intAttributePoints; _objCharacter.Nuyen = intNuyen; this.DialogResult = DialogResult.OK; } }
/// Create a Armor Modification from an XmlNode and return the TreeNodes for it. /// <param name="objXmlArmorNode">XmlNode to create the object from.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="intRating">Rating of the selected ArmorMod.</param> /// <param name="objWeapons">List of Weapons that are created by the Armor.</param> /// <param name="objWeaponNodes">List of Weapon Nodes that are created by the Armor.</param> /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param> public void Create(XmlNode objXmlArmorNode, TreeNode objNode, int intRating, List <Weapon> objWeapons, List <TreeNode> objWeaponNodes, bool blnSkipCost = false) { objXmlArmorNode.TryGetStringFieldQuickly("name", ref _strName); objXmlArmorNode.TryGetStringFieldQuickly("category", ref _strCategory); objXmlArmorNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity); _intRating = intRating; objXmlArmorNode.TryGetInt32FieldQuickly("armor", ref _intA); objXmlArmorNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating); objXmlArmorNode.TryGetStringFieldQuickly("avail", ref _strAvail); objXmlArmorNode.TryGetStringFieldQuickly("source", ref _strSource); objXmlArmorNode.TryGetStringFieldQuickly("page", ref _strPage); _nodBonus = objXmlArmorNode["bonus"]; if (GlobalOptions.Instance.Language != "en-us") { XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml"); XmlNode objArmorNode = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + _strName + "\"]"); if (objArmorNode != null) { objArmorNode.TryGetStringFieldQuickly("translate", ref _strAltName); objArmorNode.TryGetStringFieldQuickly("altpage", ref _strAltPage); } objArmorNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]"); if (objArmorNode != null) { if (objArmorNode.Attributes["translate"] != null) { _strAltCategory = objArmorNode.Attributes["translate"].InnerText; } } } // Check for a Variable Cost. if (blnSkipCost) { _strCost = "0"; } else if (objXmlArmorNode["cost"] != null) { XmlNode objXmlArmorCostNode = objXmlArmorNode["cost"]; if (objXmlArmorCostNode.InnerText.StartsWith("Variable")) { int intMin; int intMax = 0; char[] chrParentheses = { '(', ')' }; string strCost = objXmlArmorCostNode.InnerText.Replace("Variable", string.Empty).Trim(chrParentheses); if (strCost.Contains("-")) { string[] strValues = strCost.Split('-'); intMin = Convert.ToInt32(strValues[0]); intMax = Convert.ToInt32(strValues[1]); } else { intMin = Convert.ToInt32(strCost.Replace("+", string.Empty)); } if (intMin != 0 || intMax != 0) { frmSelectNumber frmPickNumber = new frmSelectNumber(); if (intMax == 0) { intMax = 1000000; } frmPickNumber.Minimum = intMin; frmPickNumber.Maximum = intMax; frmPickNumber.Description = LanguageManager.Instance.GetString("String_SelectVariableCost").Replace("{0}", DisplayNameShort); frmPickNumber.AllowCancel = false; frmPickNumber.ShowDialog(); _strCost = frmPickNumber.SelectedValue.ToString(); } } else { _strCost = objXmlArmorCostNode.InnerText; } } if (objXmlArmorNode["bonus"] != null && !blnSkipCost) { ImprovementManager objImprovementManager = new ImprovementManager(_objCharacter); if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.ArmorMod, _guiID.ToString(), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(objImprovementManager.SelectedValue)) { _strExtra = objImprovementManager.SelectedValue; objNode.Text += " (" + objImprovementManager.SelectedValue + ")"; } } // Add Weapons if applicable. if (objXmlArmorNode.InnerXml.Contains("<addweapon>")) { XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml"); // More than one Weapon can be added, so loop through all occurrences. foreach (XmlNode objXmlAddWeapon in objXmlArmorNode.SelectNodes("addweapon")) { XmlNode objXmlWeapon = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlAddWeapon.InnerText + "\" and starts-with(category, \"Cyberware\")]"); TreeNode objGearWeaponNode = new TreeNode(); Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Create(objXmlWeapon, _objCharacter, objGearWeaponNode, null, null); objGearWeaponNode.ForeColor = SystemColors.GrayText; objWeaponNodes.Add(objGearWeaponNode); objWeapons.Add(objGearWeapon); _guiWeaponID = Guid.Parse(objGearWeapon.InternalId); } } objNode.Text = DisplayName; objNode.Tag = _guiID.ToString(); }
/// Create a Metamagic from an XmlNode. /// <param name="objXmlMetamagicNode">XmlNode to create the object from.</param> /// <param name="objSource">Source of the Improvement.</param> /// <param name="strForcedValue">Value to forcefully select for any ImprovementManager prompts.</param> public void Create(XmlNode objXmlMetamagicNode, Improvement.ImprovementSource objSource, string strForcedValue = "") { if (!objXmlMetamagicNode.TryGetField("id", Guid.TryParse, out _guiSourceID)) { Log.Warn(new object[] { "Missing id field for xmlnode", objXmlMetamagicNode }); Utils.BreakIfDebug(); } if (objXmlMetamagicNode.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; _objCachedMyXPathNode = null; } objXmlMetamagicNode.TryGetStringFieldQuickly("source", ref _strSource); objXmlMetamagicNode.TryGetStringFieldQuickly("page", ref _strPage); _eImprovementSource = objSource; objXmlMetamagicNode.TryGetInt32FieldQuickly("grade", ref _intGrade); if (!objXmlMetamagicNode.TryGetMultiLineStringFieldQuickly("altnotes", ref _strNotes)) { objXmlMetamagicNode.TryGetMultiLineStringFieldQuickly("notes", ref _strNotes); } string sNotesColor = ColorTranslator.ToHtml(ColorManager.HasNotesColor); objXmlMetamagicNode.TryGetStringFieldQuickly("notesColor", ref sNotesColor); _colNotes = ColorTranslator.FromHtml(sNotesColor); if (string.IsNullOrEmpty(Notes)) { Notes = CommonFunctions.GetBookNotes(objXmlMetamagicNode, Name, CurrentDisplayName, Source, Page, DisplayPage(GlobalSettings.Language), _objCharacter); } _nodBonus = objXmlMetamagicNode["bonus"]; if (_nodBonus != null) { int intRating = _objCharacter.SubmersionGrade > 0 ? _objCharacter.SubmersionGrade : _objCharacter.InitiateGrade; string strOldFocedValue = ImprovementManager.ForcedValue; string strOldSelectedValue = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = strForcedValue; if (!ImprovementManager.CreateImprovements(_objCharacter, objSource, _guiID.ToString("D", GlobalSettings.InvariantCultureInfo), _nodBonus, intRating, DisplayNameShort(GlobalSettings.Language))) { _guiID = Guid.Empty; ImprovementManager.ForcedValue = strOldFocedValue; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strName += LanguageManager.GetString("String_Space") + '(' + ImprovementManager.SelectedValue + ')'; _objCachedMyXmlNode = null; _objCachedMyXPathNode = null; } ImprovementManager.ForcedValue = strOldFocedValue; ImprovementManager.SelectedValue = strOldSelectedValue; } /* * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPdf(_strSource + ' ' + _strPage, _strName); * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPdf(Source + ' ' + DisplayPage(GlobalSettings.Language), CurrentDisplayName); * } * } */ }
/// <summary> /// Create a LifestyleQuality from an XmlNode and return the TreeNodes for it. /// </summary> /// <param name="objXmlLifestyleQuality">XmlNode to create the object from.</param> /// <param name="objCharacter">Character object the LifestyleQuality will be added to.</param> /// <param name="objLifestyleQualitySource">Source of the LifestyleQuality.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> public void Create(XmlNode objXmlLifestyleQuality, Lifestyle objParentLifestyle, Character objCharacter, QualitySource objLifestyleQualitySource, TreeNode objNode) { _objParentLifestyle = objParentLifestyle; _SourceGuid = Guid.Parse(objXmlLifestyleQuality["id"].InnerText); objXmlLifestyleQuality.TryGetStringFieldQuickly("name", ref _strName); objXmlLifestyleQuality.TryGetInt32FieldQuickly("lp", ref _intLP); objXmlLifestyleQuality.TryGetStringFieldQuickly("cost", ref _strCost); objXmlLifestyleQuality.TryGetInt32FieldQuickly("multiplier", ref _intMultiplier); objXmlLifestyleQuality.TryGetInt32FieldQuickly("multiplierbaseonly", ref _intBaseMultiplier); if (objXmlLifestyleQuality["category"] != null) { _objLifestyleQualityType = ConvertToLifestyleQualityType(objXmlLifestyleQuality["category"].InnerText); } _objLifestyleQualitySource = objLifestyleQualitySource; if (objXmlLifestyleQuality["print"]?.InnerText == "no") { _blnPrint = false; } if (objXmlLifestyleQuality["contributetolimit"]?.InnerText == "no") { _blnContributeToLimit = false; } objXmlLifestyleQuality.TryGetStringFieldQuickly("source", ref _strSource); objXmlLifestyleQuality.TryGetStringFieldQuickly("page", ref _strPage); string strAllowedFreeLifestyles = string.Empty; if (objXmlLifestyleQuality.TryGetStringFieldQuickly("allowed", ref strAllowedFreeLifestyles)) { _lstAllowedFreeLifestyles = strAllowedFreeLifestyles.Split(',').ToList(); } if (objNode.Text.Contains('(')) { _strExtra = objNode.Text.Split('(')[1].TrimEnd(')'); } if (GlobalOptions.Language != GlobalOptions.DefaultLanguage) { XmlNode objLifestyleQualityNode = MyXmlNode; if (objLifestyleQualityNode != null) { objXmlLifestyleQuality.TryGetStringFieldQuickly("translate", ref _strAltName); objXmlLifestyleQuality.TryGetStringFieldQuickly("altpage", ref _strAltPage); } } // If the item grants a bonus, pass the information to the Improvement Manager. if (objXmlLifestyleQuality.InnerXml.Contains("<bonus>")) { if (!ImprovementManager.CreateImprovements(objCharacter, Improvement.ImprovementSource.Quality, _guiID.ToString(), objXmlLifestyleQuality["bonus"], false, 1, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; //objNode.Text += " (" + objImprovementManager.SelectedValue + ")"; } } // Built-In Qualities appear as grey text to show that they cannot be removed. if (objLifestyleQualitySource == QualitySource.BuiltIn) { objNode.ForeColor = SystemColors.GrayText; Free = true; } objNode.Name = Name; objNode.Text = DisplayName; objNode.Tag = InternalId; }
/// <summary> /// Create a Quality from an XmlNode. /// </summary> /// <param name="objXmlQuality">XmlNode to create the object from.</param> /// <param name="objQualitySource">Source of the Quality.</param> /// <param name="lstWeapons">List of Weapons that should be added to the Character.</param> /// <param name="strForceValue">Force a value to be selected for the Quality.</param> /// <param name="strSourceName">Friendly name for the improvement that added this quality.</param> public void Create(XmlNode objXmlQuality, QualitySource objQualitySource, IList <Weapon> lstWeapons, string strForceValue = "", string strSourceName = "") { _strSourceName = strSourceName; objXmlQuality.TryGetStringFieldQuickly("name", ref _strName); objXmlQuality.TryGetBoolFieldQuickly("metagenetic", ref _blnMetagenetic); if (!objXmlQuality.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objXmlQuality.TryGetStringFieldQuickly("notes", ref _strNotes); } objXmlQuality.TryGetInt32FieldQuickly("karma", ref _intBP); _eQualityType = ConvertToQualityType(objXmlQuality["category"]?.InnerText); _eQualitySource = objQualitySource; objXmlQuality.TryGetBoolFieldQuickly("doublecareer", ref _blnDoubleCostCareer); objXmlQuality.TryGetBoolFieldQuickly("canbuywithspellpoints", ref _blnCanBuyWithSpellPoints); objXmlQuality.TryGetBoolFieldQuickly("print", ref _blnPrint); objXmlQuality.TryGetBoolFieldQuickly("implemented", ref _blnImplemented); objXmlQuality.TryGetBoolFieldQuickly("contributetolimit", ref _blnContributeToLimit); objXmlQuality.TryGetStringFieldQuickly("source", ref _strSource); objXmlQuality.TryGetStringFieldQuickly("page", ref _strPage); _blnMutant = objXmlQuality["mutant"] != null; if (_eQualityType == QualityType.LifeModule) { objXmlQuality.TryGetStringFieldQuickly("stage", ref _strStage); } if (objXmlQuality.TryGetField("id", Guid.TryParse, out Guid guiTemp)) { _guiQualityId = guiTemp; _objCachedMyXmlNode = null; } // Add Weapons if applicable. // More than one Weapon can be added, so loop through all occurrences. using (XmlNodeList xmlAddWeaponList = objXmlQuality.SelectNodes("addweapon")) if (xmlAddWeaponList?.Count > 0) { XmlDocument objXmlWeaponDocument = XmlManager.Load("weapons.xml"); foreach (XmlNode objXmlAddWeapon in xmlAddWeaponList) { string strLoopID = objXmlAddWeapon.InnerText; XmlNode objXmlWeapon = strLoopID.IsGuid() ? objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + strLoopID + "\"]") : objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + strLoopID + "\"]"); Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Create(objXmlWeapon, lstWeapons); objGearWeapon.ParentID = InternalId; objGearWeapon.Cost = "0"; lstWeapons.Add(objGearWeapon); Guid.TryParse(objGearWeapon.InternalId, out _guiWeaponID); } } using (XmlNodeList xmlNaturalWeaponList = objXmlQuality.SelectNodes("naturalweapons/naturalweapon")) if (xmlNaturalWeaponList?.Count > 0) { foreach (XmlNode objXmlNaturalWeapon in xmlNaturalWeaponList) { Weapon objWeapon = new Weapon(_objCharacter); if (objXmlNaturalWeapon["name"] != null) { objWeapon.Name = objXmlNaturalWeapon["name"].InnerText; } objWeapon.Category = LanguageManager.GetString("Tab_Critter", GlobalOptions.Language); objWeapon.WeaponType = "Melee"; if (objXmlNaturalWeapon["reach"] != null) { objWeapon.Reach = Convert.ToInt32(objXmlNaturalWeapon["reach"].InnerText); } if (objXmlNaturalWeapon["accuracy"] != null) { objWeapon.Accuracy = objXmlNaturalWeapon["accuracy"].InnerText; } if (objXmlNaturalWeapon["damage"] != null) { objWeapon.Damage = objXmlNaturalWeapon["damage"].InnerText; } if (objXmlNaturalWeapon["ap"] != null) { objWeapon.AP = objXmlNaturalWeapon["ap"].InnerText; } objWeapon.Mode = "0"; objWeapon.RC = "0"; objWeapon.Concealability = 0; objWeapon.Avail = "0"; objWeapon.Cost = "0"; if (objXmlNaturalWeapon["useskill"] != null) { objWeapon.UseSkill = objXmlNaturalWeapon["useskill"].InnerText; } if (objXmlNaturalWeapon["source"] != null) { objWeapon.Source = objXmlNaturalWeapon["source"].InnerText; } if (objXmlNaturalWeapon["page"] != null) { objWeapon.Page = objXmlNaturalWeapon["page"].InnerText; } _objCharacter.Weapons.Add(objWeapon); } } _nodDiscounts = objXmlQuality["costdiscount"]; // If the item grants a bonus, pass the information to the Improvement Manager. _nodBonus = objXmlQuality["bonus"]; if (_nodBonus?.ChildNodes.Count > 0) { ImprovementManager.ForcedValue = strForceValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.Quality, InternalId, _nodBonus, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; } } else if (!string.IsNullOrEmpty(strForceValue)) { _strExtra = strForceValue; } _nodFirstLevelBonus = objXmlQuality["firstlevelbonus"]; if (_nodFirstLevelBonus?.ChildNodes.Count > 0 && Levels == 0) { ImprovementManager.ForcedValue = string.IsNullOrEmpty(strForceValue) ? Extra : strForceValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.Quality, InternalId, _nodFirstLevelBonus, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } } if (string.IsNullOrEmpty(Notes)) { string strEnglishNameOnPage = Name; string strNameOnPage = string.Empty; // make sure we have something and not just an empty tag if (objXmlQuality.TryGetStringFieldQuickly("nameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage)) { strEnglishNameOnPage = strNameOnPage; } string strQualityNotes = CommonFunctions.GetTextFromPDF($"{Source} {Page}", strEnglishNameOnPage); if (string.IsNullOrEmpty(strQualityNotes) && GlobalOptions.Language != GlobalOptions.DefaultLanguage) { string strTranslatedNameOnPage = DisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language); // don't check again it is not translated if (strTranslatedNameOnPage != _strName) { // if we found <altnameonpage>, and is not empty and not the same as english we must use that instead if (objXmlQuality.TryGetStringFieldQuickly("altnameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage) && strNameOnPage != strEnglishNameOnPage) { strTranslatedNameOnPage = strNameOnPage; } Notes = CommonFunctions.GetTextFromPDF($"{Source} {DisplayPage(GlobalOptions.Language)}", strTranslatedNameOnPage); } } else { Notes = strQualityNotes; } } }
/// <summary> /// Create a LifestyleQuality from an XmlNode and return the TreeNodes for it. /// </summary> /// <param name="objXmlLifestyleQuality">XmlNode to create the object from.</param> /// <param name="objCharacter">Character object the LifestyleQuality will be added to.</param> /// <param name="objLifestyleQualitySource">Source of the LifestyleQuality.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="objWeapons">List of Weapons that should be added to the Character.</param> /// <param name="objWeaponNodes">List of TreeNodes to represent the Weapons added.</param> /// <param name="strForceValue">Force a value to be selected for the LifestyleQuality.</param> public void Create(XmlNode objXmlLifestyleQuality, Character objCharacter, QualitySource objLifestyleQualitySource, TreeNode objNode) { _strName = objXmlLifestyleQuality["name"].InnerText; _intLP = Convert.ToInt32(objXmlLifestyleQuality["lp"].InnerText); try { _intCost = Convert.ToInt32(objXmlLifestyleQuality["cost"].InnerText); } catch {} _objLifestyleQualityType = ConvertToLifestyleQualityType(objXmlLifestyleQuality["category"].InnerText); _objLifestyleQualitySource = objLifestyleQualitySource; if (objXmlLifestyleQuality["print"] != null) { if (objXmlLifestyleQuality["print"].InnerText == "no") { _blnPrint = false; } } if (objXmlLifestyleQuality["contributetolimit"] != null) { if (objXmlLifestyleQuality["contributetolimit"].InnerText == "no") { _blnContributeToLimit = false; } } _strSource = objXmlLifestyleQuality["source"].InnerText; _strPage = objXmlLifestyleQuality["page"].InnerText; if (GlobalOptions.Instance.Language != "en-us") { XmlDocument objXmlDocument = XmlManager.Instance.Load("lifestyles.xml"); XmlNode objLifestyleQualityNode = objXmlDocument.SelectSingleNode("/chummer/qualities/LifestyleQuality[name = \"" + _strName + "\"]"); if (objLifestyleQualityNode != null) { if (objLifestyleQualityNode["translate"] != null) { _strAltName = objLifestyleQualityNode["translate"].InnerText; } if (objLifestyleQualityNode["altpage"] != null) { _strAltPage = objLifestyleQualityNode["altpage"].InnerText; } } } // If the item grants a bonus, pass the information to the Improvement Manager. if (objXmlLifestyleQuality.InnerXml.Contains("<bonus>")) { ImprovementManager objImprovementManager = new ImprovementManager(objCharacter); if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Quality, _guiID.ToString(), objXmlLifestyleQuality["bonus"], false, 1, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (objImprovementManager.SelectedValue != "") { _strExtra = objImprovementManager.SelectedValue; objNode.Text += " (" + objImprovementManager.SelectedValue + ")"; } } objNode.Text = DisplayName; objNode.Tag = InternalId; }
/// Create a Cyberware from an XmlNode and return the TreeNodes for it. /// <param name="objXmlArmorNode">XmlNode to create the object from.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="cmsArmorMod">ContextMenuStrip to apply to Armor Mode TreeNodes.</param> /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param> /// <param name="blnCreateChildren">Whether or not child items should be created.</param> public void Create(XmlNode objXmlArmorNode, TreeNode objNode, ContextMenuStrip cmsArmorMod, int intRating, bool blnSkipCost = false, bool blnCreateChildren = true) { _strName = objXmlArmorNode["name"].InnerText; _strCategory = objXmlArmorNode["category"].InnerText; _strA = objXmlArmorNode["armor"].InnerText; if (objXmlArmorNode["armoroverride"] != null) _strO = objXmlArmorNode["armoroverride"].InnerText; _intRating = intRating; if (objXmlArmorNode["rating"] != null) _intMaxRating = Convert.ToInt32(objXmlArmorNode["rating"].InnerText); _strArmorCapacity = objXmlArmorNode["armorcapacity"].InnerText; _strAvail = objXmlArmorNode["avail"].InnerText; _strSource = objXmlArmorNode["source"].InnerText; _strPage = objXmlArmorNode["page"].InnerText; _nodBonus = objXmlArmorNode["bonus"]; if (GlobalOptions.Instance.Language != "en-us") { XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml"); XmlNode objArmorNode = objXmlDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + _strName + "\"]"); if (objArmorNode != null) { if (objArmorNode["translate"] != null) _strAltName = objArmorNode["translate"].InnerText; if (objArmorNode["altpage"] != null) _strAltPage = objArmorNode["altpage"].InnerText; } objArmorNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]"); if (objNode != null) { if (objArmorNode.Attributes["translate"] != null) _strAltCategory = objArmorNode.Attributes["translate"].InnerText; } } // Check for a Variable Cost. if (objXmlArmorNode["cost"].InnerText.StartsWith("Variable")) { if (blnSkipCost) _strCost = "0"; else { int intMin = 0; int intMax = 0; string strCost = objXmlArmorNode["cost"].InnerText.Replace("Variable(", string.Empty).Replace(")", string.Empty); if (strCost.Contains("-")) { string[] strValues = strCost.Split('-'); intMin = Convert.ToInt32(strValues[0]); intMax = Convert.ToInt32(strValues[1]); } else intMin = Convert.ToInt32(strCost.Replace("+", string.Empty)); if (intMin != 0 || intMax != 0) { frmSelectNumber frmPickNumber = new frmSelectNumber(); if (intMax == 0) intMax = 1000000; frmPickNumber.Minimum = intMin; frmPickNumber.Maximum = intMax; frmPickNumber.Description = LanguageManager.Instance.GetString("String_SelectVariableCost").Replace("{0}", DisplayNameShort); frmPickNumber.AllowCancel = false; frmPickNumber.ShowDialog(); _strCost = frmPickNumber.SelectedValue.ToString(); } } } else if (objXmlArmorNode["cost"].InnerText.StartsWith("Rating")) { // If the cost is determined by the Rating, evaluate the expression. XmlDocument objXmlDocument = new XmlDocument(); XPathNavigator nav = objXmlDocument.CreateNavigator(); string strCost = ""; string strCostExpression = _strCost; strCost = strCostExpression.Replace("Rating", _intRating.ToString()); XPathExpression xprCost = nav.Compile(strCost); _strCost = nav.Evaluate(xprCost).ToString(); } else { _strCost = objXmlArmorNode["cost"].InnerText; } if (objXmlArmorNode["bonus"] != null && !blnSkipCost) { ImprovementManager objImprovementManager = new ImprovementManager(_objCharacter); if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Armor, _guiID.ToString(), objXmlArmorNode["bonus"], false, 1, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (objImprovementManager.SelectedValue != "") { _strExtra = objImprovementManager.SelectedValue; objNode.Text += " (" + objImprovementManager.SelectedValue + ")"; } } // Add any Armor Mods that come with the Armor. if (objXmlArmorNode["mods"] != null && blnCreateChildren) { XmlDocument objXmlArmorDocument = XmlManager.Instance.Load("armor.xml"); foreach (XmlNode objXmlArmorMod in objXmlArmorNode.SelectNodes("mods/name")) { intRating = 0; string strForceValue = ""; if (objXmlArmorMod.Attributes["rating"] != null) intRating = Convert.ToInt32(objXmlArmorMod.Attributes["rating"].InnerText); if (objXmlArmorMod.Attributes["select"] != null) strForceValue = objXmlArmorMod.Attributes["select"].ToString(); XmlNode objXmlMod = objXmlArmorDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlArmorMod.InnerText + "\"]"); if (objXmlMod != null) { ArmorMod objMod = new ArmorMod(_objCharacter); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); TreeNode objModNode = new TreeNode(); objMod.Create(objXmlMod, objModNode, intRating, lstWeapons, lstWeaponNodes, blnSkipCost); objMod.Parent = this; objMod.IncludedInArmor = true; objMod.ArmorCapacity = "[0]"; objMod.Cost = "0"; objMod.MaximumRating = objMod.Rating; _lstArmorMods.Add(objMod); objModNode.ContextMenuStrip = cmsArmorMod; objNode.Nodes.Add(objModNode); objNode.Expand(); } else { ArmorMod objMod = new ArmorMod(_objCharacter); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); TreeNode objModNode = new TreeNode(); objMod.Name = objXmlArmorNode["name"].InnerText; objMod.Category = "Features"; objMod.Avail = "0"; objMod.Source = _strSource; objMod.Page = _strPage; objMod.Parent = this; objMod.IncludedInArmor = true; objMod.ArmorCapacity = "[0]"; objMod.Cost = "0"; objMod.Rating = 0; objMod.MaximumRating = objMod.Rating; _lstArmorMods.Add(objMod); objModNode.ContextMenuStrip = cmsArmorMod; objNode.Nodes.Add(objModNode); objNode.Expand(); } } } // Add any Gear that comes with the Armor. if (objXmlArmorNode["gears"] != null && blnCreateChildren) { XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlArmorGear in objXmlArmorNode.SelectNodes("gears/usegear")) { intRating = 0; string strForceValue = ""; if (objXmlArmorGear.Attributes["rating"] != null) intRating = Convert.ToInt32(objXmlArmorGear.Attributes["rating"].InnerText); if (objXmlArmorGear.Attributes["select"] != null) strForceValue = objXmlArmorGear.Attributes["select"].InnerText; XmlNode objXmlGear = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlArmorGear.InnerText + "\"]"); Gear objGear = new Gear(_objCharacter); TreeNode objGearNode = new TreeNode(); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); objGear.Create(objXmlGear, _objCharacter, objGearNode, intRating, lstWeapons, lstWeaponNodes, strForceValue, false, false, !blnSkipCost); objGear.Capacity = "[0]"; objGear.ArmorCapacity = "[0]"; objGear.Cost = "0"; objGear.MaxRating = objGear.Rating; objGear.MinRating = objGear.Rating; objGear.IncludedInParent = true; _lstGear.Add(objGear); objNode.Nodes.Add(objGearNode); objNode.Expand(); } } objNode.Text = DisplayName; objNode.Tag = _guiID.ToString(); }
public bool Create(XmlNode objNode, int intRating = 1, XmlNode objBonusNodeOverride = null, bool blnCreateImprovements = true) { Name = objNode["name"].InnerText; _sourceID = Guid.Parse(objNode["id"].InnerText); _objCachedMyXmlNode = null; objNode.TryGetStringFieldQuickly("points", ref _strPointsPerLevel); objNode.TryGetStringFieldQuickly("adeptway", ref _strAdeptWayDiscount); LevelsEnabled = objNode["levels"]?.InnerText == System.Boolean.TrueString; Rating = intRating; objNode.TryGetInt32FieldQuickly("maxlevels", ref _intMaxLevel); objNode.TryGetBoolFieldQuickly("discounted", ref _blnDiscountedAdeptWay); objNode.TryGetBoolFieldQuickly("discountedgeas", ref _blnDiscountedGeas); objNode.TryGetStringFieldQuickly("bonussource", ref _strBonusSource); objNode.TryGetDecFieldQuickly("freepoints", ref _decFreePoints); objNode.TryGetDecFieldQuickly("extrapointcost", ref _decExtraPointCost); objNode.TryGetStringFieldQuickly("action", ref _strAction); objNode.TryGetStringFieldQuickly("source", ref _strSource); objNode.TryGetStringFieldQuickly("page", ref _strPage); objNode.TryGetStringFieldQuickly("notes", ref _strNotes); Bonus = objNode["bonus"]; if (objBonusNodeOverride != null) { Bonus = objBonusNodeOverride; } _nodAdeptWayRequirements = objNode["adeptwayrequires"]; if (objNode.InnerXml.Contains("enhancements")) { XmlNodeList nodEnhancements = objNode.SelectNodes("enhancements/enhancement"); if (nodEnhancements != null) { foreach (XmlNode nodEnhancement in nodEnhancements) { Enhancement objEnhancement = new Enhancement(CharacterObject); objEnhancement.Load(nodEnhancement); objEnhancement.Parent = this; Enhancements.Add(objEnhancement); } } } if (blnCreateImprovements && Bonus != null && Bonus.HasChildNodes) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = Extra; if (!ImprovementManager.CreateImprovements(CharacterObject, Improvement.ImprovementSource.Power, InternalId, Bonus, false, TotalRating, DisplayNameShort)) { ImprovementManager.ForcedValue = strOldForce; this.Deleting = true; CharacterObject.Powers.Remove(this); OnPropertyChanged(nameof(TotalRating)); return(false); } Extra = ImprovementManager.SelectedValue; ImprovementManager.SelectedValue = strOldSelected; ImprovementManager.ForcedValue = strOldForce; } if (TotalMaximumLevels < Rating) { Rating = TotalMaximumLevels; OnPropertyChanged(nameof(TotalRating)); } return(true); }
/// <summary> /// Create a Critter, put them into Career Mode, link them, and open the newly-created Critter. /// </summary> /// <param name="strCritterName">Name of the Critter's Metatype.</param> /// <param name="intForce">Critter's Force.</param> private void CreateCritter(string strCritterName, int intForce) { // The Critter should use the same settings file as the character. Character objCharacter = new Character(); objCharacter.SettingsFile = _objSpirit.CharacterObject.SettingsFile; // Override the defaults for the setting. objCharacter.IgnoreRules = true; objCharacter.IsCritter = true; objCharacter.BuildMethod = CharacterBuildMethod.BP; objCharacter.BuildPoints = 0; if (txtCritterName.Text != string.Empty) { objCharacter.Name = txtCritterName.Text; } // Make sure that Running Wild is one of the allowed source books since most of the Critter Powers come from this book. bool blnRunningWild = false; blnRunningWild = (objCharacter.Options.Books.Contains("RW")); if (!blnRunningWild) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Main_RunningWild"), LanguageManager.Instance.GetString("MessageTitle_Main_RunningWild"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Ask the user to select a filename for the new character. string strForce = LanguageManager.Instance.GetString("String_Force"); if (_objSpirit.EntityType == SpiritType.Sprite) { strForce = LanguageManager.Instance.GetString("String_Rating"); } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Chummer Files (*.chum)|*.chum|All Files (*.*)|*.*"; saveFileDialog.FileName = strCritterName + " (" + strForce + " " + _objSpirit.Force.ToString() + ").chum"; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { string strFileName = saveFileDialog.FileName; objCharacter.FileName = strFileName; } else { return; } // Code from frmMetatype. ImprovementManager objImprovementManager = new ImprovementManager(objCharacter); XmlDocument objXmlDocument = XmlManager.Instance.Load("critters.xml"); XmlNode objXmlMetatype = objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + strCritterName + "\"]"); // If the Critter could not be found, show an error and get out of here. if (objXmlMetatype == null) { MessageBox.Show(LanguageManager.Instance.GetString("Message_UnknownCritterType").Replace("{0}", strCritterName), LanguageManager.Instance.GetString("MessageTitle_SelectCritterType"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Set Metatype information. if (strCritterName == "Ally Spirit") { objCharacter.BOD.AssignLimits(ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["bodmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["bodaug"].InnerText, intForce, 0)); objCharacter.AGI.AssignLimits(ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["agimax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["agiaug"].InnerText, intForce, 0)); objCharacter.REA.AssignLimits(ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["reamax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["reaaug"].InnerText, intForce, 0)); objCharacter.STR.AssignLimits(ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["strmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["straug"].InnerText, intForce, 0)); objCharacter.CHA.AssignLimits(ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["chamax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["chaaug"].InnerText, intForce, 0)); objCharacter.INT.AssignLimits(ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["intmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["intaug"].InnerText, intForce, 0)); objCharacter.LOG.AssignLimits(ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["logmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["logaug"].InnerText, intForce, 0)); objCharacter.WIL.AssignLimits(ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["wilmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["wilaug"].InnerText, intForce, 0)); objCharacter.INI.AssignLimits(ExpressionToString(objXmlMetatype["inimin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["inimax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["iniaug"].InnerText, intForce, 0)); objCharacter.MAG.AssignLimits(ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["magmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["magaug"].InnerText, intForce, 0)); objCharacter.RES.AssignLimits(ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["resmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["resaug"].InnerText, intForce, 0)); objCharacter.EDG.AssignLimits(ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["edgmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["edgaug"].InnerText, intForce, 0)); objCharacter.ESS.AssignLimits(ExpressionToString(objXmlMetatype["essmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essaug"].InnerText, intForce, 0)); } else { int intMinModifier = -3; if (objXmlMetatype["category"].InnerText == "Mutant Critters") { intMinModifier = 0; } objCharacter.BOD.AssignLimits(ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 3)); objCharacter.AGI.AssignLimits(ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 3)); objCharacter.REA.AssignLimits(ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 3)); objCharacter.STR.AssignLimits(ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 3)); objCharacter.CHA.AssignLimits(ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 3)); objCharacter.INT.AssignLimits(ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 3)); objCharacter.LOG.AssignLimits(ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 3)); objCharacter.WIL.AssignLimits(ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 3)); objCharacter.INI.AssignLimits(ExpressionToString(objXmlMetatype["inimin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["inimax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["iniaug"].InnerText, intForce, 0)); objCharacter.MAG.AssignLimits(ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 3)); objCharacter.RES.AssignLimits(ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 3)); objCharacter.EDG.AssignLimits(ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 3)); objCharacter.ESS.AssignLimits(ExpressionToString(objXmlMetatype["essmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essaug"].InnerText, intForce, 0)); } // If we're working with a Critter, set the Attributes to their default values. objCharacter.BOD.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 0)); objCharacter.AGI.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 0)); objCharacter.REA.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 0)); objCharacter.STR.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 0)); objCharacter.CHA.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 0)); objCharacter.INT.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 0)); objCharacter.LOG.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 0)); objCharacter.WIL.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 0)); objCharacter.MAG.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 0)); objCharacter.RES.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 0)); objCharacter.EDG.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 0)); objCharacter.ESS.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["essmax"].InnerText, intForce, 0)); // Sprites can never have Physical Attributes or WIL. if (objXmlMetatype["category"].InnerText.EndsWith("Sprite")) { objCharacter.BOD.AssignLimits("0", "0", "0"); objCharacter.AGI.AssignLimits("0", "0", "0"); objCharacter.REA.AssignLimits("0", "0", "0"); objCharacter.STR.AssignLimits("0", "0", "0"); objCharacter.WIL.AssignLimits("0", "0", "0"); objCharacter.INI.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["inimax"].InnerText, intForce, 0)); objCharacter.INI.MetatypeMaximum = Convert.ToInt32(ExpressionToString(objXmlMetatype["inimax"].InnerText, intForce, 0)); } objCharacter.Metatype = strCritterName; objCharacter.MetatypeCategory = objXmlMetatype["category"].InnerText; objCharacter.Metavariant = ""; objCharacter.MetatypeBP = 0; if (objXmlMetatype["movement"] != null) { objCharacter.Movement = objXmlMetatype["movement"].InnerText; } // Load the Qualities file. XmlDocument objXmlQualityDocument = XmlManager.Instance.Load("qualities.xml"); // Determine if the Metatype has any bonuses. if (objXmlMetatype.InnerXml.Contains("bonus")) { objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Metatype, strCritterName, objXmlMetatype.SelectSingleNode("bonus"), false, 1, strCritterName); } // Create the Qualities that come with the Metatype. foreach (XmlNode objXmlQualityItem in objXmlMetatype.SelectNodes("qualities/positive/quality")) { XmlNode objXmlQuality = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQualityItem.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 (objXmlQualityItem.Attributes["select"] != null) { strForceValue = objXmlQualityItem.Attributes["select"].InnerText; } QualitySource objSource = new QualitySource(); objSource = QualitySource.Metatype; if (objXmlQualityItem.Attributes["removable"] != null) { objSource = QualitySource.MetatypeRemovable; } objQuality.Create(objXmlQuality, objCharacter, objSource, objNode, objWeapons, objWeaponNodes, strForceValue); objCharacter.Qualities.Add(objQuality); // Add any created Weapons to the character. foreach (Weapon objWeapon in objWeapons) { objCharacter.Weapons.Add(objWeapon); } } foreach (XmlNode objXmlQualityItem in objXmlMetatype.SelectNodes("qualities/negative/quality")) { XmlNode objXmlQuality = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQualityItem.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 (objXmlQualityItem.Attributes["select"] != null) { strForceValue = objXmlQualityItem.Attributes["select"].InnerText; } QualitySource objSource = new QualitySource(); objSource = QualitySource.Metatype; if (objXmlQualityItem.Attributes["removable"] != null) { objSource = QualitySource.MetatypeRemovable; } objQuality.Create(objXmlQuality, objCharacter, objSource, objNode, objWeapons, objWeaponNodes, strForceValue); objCharacter.Qualities.Add(objQuality); // Add any created Weapons to the character. foreach (Weapon objWeapon in objWeapons) { objCharacter.Weapons.Add(objWeapon); } } // Add any Critter Powers the Metatype/Critter should have. XmlNode objXmlCritter = objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + objCharacter.Metatype + "\"]"); objXmlDocument = XmlManager.Instance.Load("critterpowers.xml"); foreach (XmlNode objXmlPower in objXmlCritter.SelectNodes("powers/power")) { XmlNode objXmlCritterPower = objXmlDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower.InnerText + "\"]"); TreeNode objNode = new TreeNode(); CritterPower objPower = new CritterPower(objCharacter); string strForcedValue = ""; int intRating = 0; if (objXmlPower.Attributes["rating"] != null) { intRating = Convert.ToInt32(objXmlPower.Attributes["rating"].InnerText); } if (objXmlPower.Attributes["select"] != null) { strForcedValue = objXmlPower.Attributes["select"].InnerText; } objPower.Create(objXmlCritterPower, objCharacter, objNode, intRating, strForcedValue); objCharacter.CritterPowers.Add(objPower); } // Set the Skill Ratings for the Critter. foreach (XmlNode objXmlSkill in objXmlCritter.SelectNodes("skills/skill")) { if (objXmlSkill.InnerText.Contains("Exotic")) { Skill objExotic = new Skill(objCharacter); objExotic.ExoticSkill = true; objExotic.Attribute = "AGI"; if (objXmlSkill.Attributes["spec"] != null) { objExotic.Specialization = objXmlSkill.Attributes["spec"].InnerText; } if (Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)) > 6) { objExotic.RatingMaximum = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); } objExotic.Rating = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); objExotic.Name = objXmlSkill.InnerText; objCharacter.Skills.Add(objExotic); } else { foreach (Skill objSkill in objCharacter.Skills) { if (objSkill.Name == objXmlSkill.InnerText) { if (objXmlSkill.Attributes["spec"] != null) { objSkill.Specialization = objXmlSkill.Attributes["spec"].InnerText; } if (Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)) > 6) { objSkill.RatingMaximum = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); } objSkill.Rating = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); break; } } } } // Set the Skill Group Ratings for the Critter. foreach (XmlNode objXmlSkill in objXmlCritter.SelectNodes("skills/group")) { foreach (SkillGroup objSkill in objCharacter.SkillGroups) { if (objSkill.Name == objXmlSkill.InnerText) { objSkill.RatingMaximum = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); objSkill.Rating = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); break; } } } // Set the Knowledge Skill Ratings for the Critter. foreach (XmlNode objXmlSkill in objXmlCritter.SelectNodes("skills/knowledge")) { Skill objKnowledge = new Skill(objCharacter); objKnowledge.Name = objXmlSkill.InnerText; objKnowledge.KnowledgeSkill = true; if (objXmlSkill.Attributes["spec"] != null) { objKnowledge.Specialization = objXmlSkill.Attributes["spec"].InnerText; } objKnowledge.SkillCategory = objXmlSkill.Attributes["category"].InnerText; if (Convert.ToInt32(objXmlSkill.Attributes["rating"].InnerText) > 6) { objKnowledge.RatingMaximum = Convert.ToInt32(objXmlSkill.Attributes["rating"].InnerText); } objKnowledge.Rating = Convert.ToInt32(objXmlSkill.Attributes["rating"].InnerText); objCharacter.Skills.Add(objKnowledge); } // If this is a Critter with a Force (which dictates their Skill Rating/Maximum Skill Rating), set their Skill Rating Maximums. if (intForce > 0) { int intMaxRating = intForce; // Determine the highest Skill Rating the Critter has. foreach (Skill objSkill in objCharacter.Skills) { if (objSkill.RatingMaximum > intMaxRating) { intMaxRating = objSkill.RatingMaximum; } } // Now that we know the upper limit, set all of the Skill Rating Maximums to match. foreach (Skill objSkill in objCharacter.Skills) { objSkill.RatingMaximum = intMaxRating; } foreach (SkillGroup objGroup in objCharacter.SkillGroups) { objGroup.RatingMaximum = intMaxRating; } // Set the MaxSkillRating for the character so it can be used later when they add new Knowledge Skills or Exotic Skills. objCharacter.MaxSkillRating = intMaxRating; } // Add any Complex Forms the Critter comes with (typically Sprites) XmlDocument objXmlProgramDocument = XmlManager.Instance.Load("programs.xml"); foreach (XmlNode objXmlComplexForm in objXmlCritter.SelectNodes("complexforms/complexform")) { int intRating = 0; if (objXmlComplexForm.Attributes["rating"] != null) { intRating = Convert.ToInt32(ExpressionToString(objXmlComplexForm.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); } string strForceValue = ""; if (objXmlComplexForm.Attributes["select"] != null) { strForceValue = objXmlComplexForm.Attributes["select"].InnerText; } XmlNode objXmlProgram = objXmlProgramDocument.SelectSingleNode("/chummer/programs/program[name = \"" + objXmlComplexForm.InnerText + "\"]"); TreeNode objNode = new TreeNode(); TechProgram objProgram = new TechProgram(objCharacter); objProgram.Create(objXmlProgram, objCharacter, objNode, strForceValue); objProgram.Rating = intRating; objCharacter.TechPrograms.Add(objProgram); // Add the Program Option if applicable. if (objXmlComplexForm.Attributes["option"] != null) { int intOptRating = 0; if (objXmlComplexForm.Attributes["optionrating"] != null) { intOptRating = Convert.ToInt32(ExpressionToString(objXmlComplexForm.Attributes["optionrating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); } string strOptForceValue = ""; if (objXmlComplexForm.Attributes["optionselect"] != null) { strOptForceValue = objXmlComplexForm.Attributes["optionselect"].InnerText; } XmlNode objXmlOption = objXmlProgramDocument.SelectSingleNode("/chummer/options/option[name = \"" + objXmlComplexForm.Attributes["option"].InnerText + "\"]"); TreeNode objNodeOpt = new TreeNode(); TechProgramOption objOption = new TechProgramOption(objCharacter); objOption.Create(objXmlOption, objCharacter, objNodeOpt, strOptForceValue); objOption.Rating = intOptRating; objProgram.Options.Add(objOption); } } // Add any Gear the Critter comes with (typically Programs for A.I.s) XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlCritter.SelectNodes("gears/gear")) { int intRating = 0; if (objXmlGear.Attributes["rating"] != null) { intRating = Convert.ToInt32(ExpressionToString(objXmlGear.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); } string strForceValue = ""; if (objXmlGear.Attributes["select"] != null) { strForceValue = objXmlGear.Attributes["select"].InnerText; } XmlNode objXmlGearItem = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlGear.InnerText + "\"]"); TreeNode objNode = new TreeNode(); Gear objGear = new Gear(objCharacter); List <Weapon> lstWeapons = new List <Weapon>(); List <TreeNode> lstWeaponNodes = new List <TreeNode>(); objGear.Create(objXmlGearItem, objCharacter, objNode, intRating, lstWeapons, lstWeaponNodes, strForceValue); objGear.Cost = "0"; objGear.Cost3 = "0"; objGear.Cost6 = "0"; objGear.Cost10 = "0"; objCharacter.Gear.Add(objGear); } // If this is a Mutant Critter, count up the number of Skill points they start with. if (objCharacter.MetatypeCategory == "Mutant Critters") { foreach (Skill objSkill in objCharacter.Skills) { objCharacter.MutantCritterBaseSkills += objSkill.Rating; } } // Add the Unarmed Attack Weapon to the character. try { objXmlDocument = XmlManager.Instance.Load("weapons.xml"); XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"Unarmed Attack\"]"); TreeNode objDummy = new TreeNode(); Weapon objWeapon = new Weapon(objCharacter); objWeapon.Create(objXmlWeapon, objCharacter, objDummy, null, null, null); objCharacter.Weapons.Add(objWeapon); } catch { } objCharacter.Alias = strCritterName; objCharacter.Created = true; objCharacter.Save(); string strOpenFile = objCharacter.FileName; objCharacter = null; // Link the newly-created Critter to the Spirit. _objSpirit.FileName = strOpenFile; if (_objSpirit.EntityType == SpiritType.Spirit) { tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Spirit_OpenFile")); } else { tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Sprite_OpenFile")); } FileNameChanged(this); GlobalOptions.Instance.MainForm.LoadCharacter(strOpenFile, true); }
/// Create a Armor Modification from an XmlNode and return the TreeNodes for it. /// <param name="objXmlArmorNode">XmlNode to create the object from.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="intRating">Rating of the selected ArmorMod.</param> /// <param name="objWeapons">List of Weapons that are created by the Armor.</param> /// <param name="objWeaponNodes">List of Weapon Nodes that are created by the Armor.</param> /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param> public void Create(XmlNode objXmlArmorNode, TreeNode objNode, ContextMenuStrip cmsArmorGear, int intRating, List <Weapon> objWeapons, List <TreeNode> objWeaponNodes, bool blnSkipCost = false, bool blnSkipSelectForms = false) { if (objXmlArmorNode.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } objXmlArmorNode.TryGetStringFieldQuickly("category", ref _strCategory); objXmlArmorNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity); objXmlArmorNode.TryGetStringFieldQuickly("gearcapacity", ref _strGearCapacity); _intRating = intRating; objXmlArmorNode.TryGetInt32FieldQuickly("armor", ref _intA); objXmlArmorNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating); objXmlArmorNode.TryGetStringFieldQuickly("avail", ref _strAvail); objXmlArmorNode.TryGetStringFieldQuickly("source", ref _strSource); objXmlArmorNode.TryGetStringFieldQuickly("page", ref _strPage); objXmlArmorNode.TryGetStringFieldQuickly("notes", ref _strNotes); _nodBonus = objXmlArmorNode["bonus"]; _nodWirelessBonus = objXmlArmorNode["wirelessbonus"]; _blnWirelessOn = _nodWirelessBonus != null; // Check for a Variable Cost. if (blnSkipCost) { _strCost = "0"; } else if (objXmlArmorNode["cost"] != null) { XmlNode objXmlArmorCostNode = objXmlArmorNode["cost"]; if (objXmlArmorCostNode.InnerText.StartsWith("Variable")) { decimal decMin = 0.0m; decimal decMax = decimal.MaxValue; char[] charParentheses = { '(', ')' }; string strCost = objXmlArmorNode["cost"].InnerText.TrimStart("Variable", true).Trim(charParentheses); if (strCost.Contains('-')) { string[] strValues = strCost.Split('-'); decMin = Convert.ToDecimal(strValues[0], GlobalOptions.InvariantCultureInfo); decMax = Convert.ToDecimal(strValues[1], GlobalOptions.InvariantCultureInfo); } else { decMin = Convert.ToDecimal(strCost.FastEscape('+'), GlobalOptions.InvariantCultureInfo); } if (decMin != 0 || decMax != decimal.MaxValue) { string strNuyenFormat = _objCharacter.Options.NuyenFormat; int intDecimalPlaces = strNuyenFormat.IndexOf('.'); if (intDecimalPlaces == -1) { intDecimalPlaces = 0; } else { intDecimalPlaces = strNuyenFormat.Length - intDecimalPlaces - 1; } frmSelectNumber frmPickNumber = new frmSelectNumber(intDecimalPlaces); if (decMax > 1000000) { decMax = 1000000; } frmPickNumber.Minimum = decMin; frmPickNumber.Maximum = decMax; frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost", GlobalOptions.Language).Replace("{0}", DisplayNameShort(GlobalOptions.Language)); frmPickNumber.AllowCancel = false; frmPickNumber.ShowDialog(); _strCost = frmPickNumber.SelectedValue.ToString(GlobalOptions.InvariantCultureInfo); } } else { _strCost = objXmlArmorCostNode.InnerText; } } if (objXmlArmorNode["bonus"] != null && !blnSkipCost && !blnSkipSelectForms) { if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.ArmorMod, _guiID.ToString(), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; objNode.Text += " (" + ImprovementManager.SelectedValue + ")"; } } // Add any Gear that comes with the Armor. if (objXmlArmorNode["gears"] != null) { XmlDocument objXmlGearDocument = XmlManager.Load("gear.xml"); foreach (XmlNode objXmlArmorGear in objXmlArmorNode.SelectNodes("gears/usegear")) { intRating = 0; string strForceValue = string.Empty; objXmlArmorGear.TryGetInt32FieldQuickly("rating", ref intRating); objXmlArmorGear.TryGetStringFieldQuickly("select", ref strForceValue); XmlNode objXmlGear = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlArmorGear.InnerText + "\"]"); Gear objGear = new Gear(_objCharacter); TreeNode objGearNode = new TreeNode(); List <Weapon> lstWeapons = new List <Weapon>(); List <TreeNode> lstWeaponNodes = new List <TreeNode>(); objGear.Create(objXmlGear, objGearNode, intRating, lstWeapons, lstWeaponNodes, strForceValue, !blnSkipCost && !blnSkipSelectForms); objGear.Capacity = "[0]"; objGear.ArmorCapacity = "[0]"; objGear.Cost = "0"; objGear.MaxRating = objGear.Rating; objGear.MinRating = objGear.Rating; objGear.ParentID = InternalId; _lstGear.Add(objGear); objGearNode.ForeColor = SystemColors.GrayText; objGearNode.ContextMenuStrip = cmsArmorGear; objNode.Nodes.Add(objGearNode); objNode.Expand(); } } // Add Weapons if applicable. if (objXmlArmorNode.InnerXml.Contains("<addweapon>")) { XmlDocument objXmlWeaponDocument = XmlManager.Load("weapons.xml"); // More than one Weapon can be added, so loop through all occurrences. foreach (XmlNode objXmlAddWeapon in objXmlArmorNode.SelectNodes("addweapon")) { string strLoopID = objXmlAddWeapon.InnerText; XmlNode objXmlWeapon = strLoopID.IsGuid() ? objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + strLoopID + "\"]") : objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + strLoopID + "\"]"); List <TreeNode> lstGearWeaponNodes = new List <TreeNode>(); Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Create(objXmlWeapon, lstGearWeaponNodes, null, null, objWeapons, null, true, !blnSkipCost && !blnSkipSelectForms); objGearWeapon.ParentID = InternalId; foreach (TreeNode objLoopNode in lstGearWeaponNodes) { objLoopNode.ForeColor = SystemColors.GrayText; objWeaponNodes.Add(objLoopNode); } objWeapons.Add(objGearWeapon); _guiWeaponID = Guid.Parse(objGearWeapon.InternalId); } } objNode.Text = DisplayName(GlobalOptions.Language); objNode.Tag = _guiID.ToString(); }
/// <summary> /// Create a Critter, put them into Career Mode, link them, and open the newly-created Critter. /// </summary> /// <param name="strCritterName">Name of the Critter's Metatype.</param> /// <param name="intForce">Critter's Force.</param> private void CreateCritter(string strCritterName, int intForce) { // The Critter should use the same settings file as the character. Character objCharacter = new Character(); objCharacter.SettingsFile = _objSpirit.CharacterObject.SettingsFile; // Override the defaults for the setting. objCharacter.IgnoreRules = true; objCharacter.IsCritter = true; objCharacter.BuildMethod = CharacterBuildMethod.Karma; objCharacter.BuildPoints = 0; if (!string.IsNullOrEmpty(txtCritterName.Text)) { objCharacter.Name = txtCritterName.Text; } // Ask the user to select a filename for the new character. string strForce = LanguageManager.GetString("String_Force"); if (_objSpirit.EntityType == SpiritType.Sprite) { strForce = LanguageManager.GetString("String_Rating"); } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Chummer5 Files (*.chum5)|*.chum5|All Files (*.*)|*.*"; saveFileDialog.FileName = strCritterName + " (" + strForce + " " + _objSpirit.Force.ToString() + ").chum5"; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { string strFileName = saveFileDialog.FileName; objCharacter.FileName = strFileName; } else { objCharacter.Dispose(); return; } Cursor = Cursors.WaitCursor; // Code from frmMetatype. XmlDocument objXmlDocument = XmlManager.Load("critters.xml"); XmlNode objXmlMetatype = objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + strCritterName + "\"]"); // If the Critter could not be found, show an error and get out of here. if (objXmlMetatype == null) { MessageBox.Show(LanguageManager.GetString("Message_UnknownCritterType").Replace("{0}", strCritterName), LanguageManager.GetString("MessageTitle_SelectCritterType"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Set Metatype information. if (strCritterName == "Ally Spirit") { objCharacter.BOD.AssignLimits(ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["bodmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["bodaug"].InnerText, intForce, 0)); objCharacter.AGI.AssignLimits(ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["agimax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["agiaug"].InnerText, intForce, 0)); objCharacter.REA.AssignLimits(ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["reamax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["reaaug"].InnerText, intForce, 0)); objCharacter.STR.AssignLimits(ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["strmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["straug"].InnerText, intForce, 0)); objCharacter.CHA.AssignLimits(ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["chamax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["chaaug"].InnerText, intForce, 0)); objCharacter.INT.AssignLimits(ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["intmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["intaug"].InnerText, intForce, 0)); objCharacter.LOG.AssignLimits(ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["logmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["logaug"].InnerText, intForce, 0)); objCharacter.WIL.AssignLimits(ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["wilmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["wilaug"].InnerText, intForce, 0)); objCharacter.MAG.AssignLimits(ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["magmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["magaug"].InnerText, intForce, 0)); objCharacter.RES.AssignLimits(ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["resmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["resaug"].InnerText, intForce, 0)); objCharacter.EDG.AssignLimits(ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["edgmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["edgaug"].InnerText, intForce, 0)); objCharacter.ESS.AssignLimits(ExpressionToString(objXmlMetatype["essmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essaug"].InnerText, intForce, 0)); } else { int intMinModifier = -3; objCharacter.BOD.AssignLimits(ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 3)); objCharacter.AGI.AssignLimits(ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 3)); objCharacter.REA.AssignLimits(ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 3)); objCharacter.STR.AssignLimits(ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 3)); objCharacter.CHA.AssignLimits(ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 3)); objCharacter.INT.AssignLimits(ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 3)); objCharacter.LOG.AssignLimits(ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 3)); objCharacter.WIL.AssignLimits(ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 3)); objCharacter.MAG.AssignLimits(ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 3)); objCharacter.RES.AssignLimits(ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 3)); objCharacter.EDG.AssignLimits(ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 3)); objCharacter.ESS.AssignLimits(ExpressionToString(objXmlMetatype["essmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essaug"].InnerText, intForce, 0)); } // If we're working with a Critter, set the Attributes to their default values. objCharacter.BOD.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 0)); objCharacter.AGI.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 0)); objCharacter.REA.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 0)); objCharacter.STR.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 0)); objCharacter.CHA.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 0)); objCharacter.INT.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 0)); objCharacter.LOG.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 0)); objCharacter.WIL.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 0)); objCharacter.MAG.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 0)); objCharacter.RES.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 0)); objCharacter.EDG.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 0)); objCharacter.ESS.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["essmax"].InnerText, intForce, 0)); // Sprites can never have Physical Attributes or WIL. if (objXmlMetatype["category"].InnerText.EndsWith("Sprite")) { objCharacter.BOD.AssignLimits("0", "0", "0"); objCharacter.AGI.AssignLimits("0", "0", "0"); objCharacter.REA.AssignLimits("0", "0", "0"); objCharacter.STR.AssignLimits("0", "0", "0"); objCharacter.WIL.AssignLimits("0", "0", "0"); } objCharacter.Metatype = strCritterName; objCharacter.MetatypeCategory = objXmlMetatype["category"].InnerText; objCharacter.Metavariant = string.Empty; objCharacter.MetatypeBP = 0; if (objXmlMetatype["movement"] != null) { objCharacter.Movement = objXmlMetatype["movement"].InnerText; } // Load the Qualities file. XmlDocument objXmlQualityDocument = XmlManager.Load("qualities.xml"); // Determine if the Metatype has any bonuses. if (objXmlMetatype.InnerXml.Contains("bonus")) { ImprovementManager.CreateImprovements(objCharacter, Improvement.ImprovementSource.Metatype, strCritterName, objXmlMetatype.SelectSingleNode("bonus"), false, 1, strCritterName); } // Create the Qualities that come with the Metatype. foreach (XmlNode objXmlQualityItem in objXmlMetatype.SelectNodes("qualities/positive/quality")) { XmlNode objXmlQuality = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQualityItem.InnerText + "\"]"); TreeNode objNode = new TreeNode(); List <Weapon> objWeapons = new List <Weapon>(); List <TreeNode> objWeaponNodes = new List <TreeNode>(); Quality objQuality = new Quality(objCharacter); string strForceValue = string.Empty; if (objXmlQualityItem.Attributes["select"] != null) { strForceValue = objXmlQualityItem.Attributes["select"].InnerText; } QualitySource objSource = new QualitySource(); objSource = QualitySource.Metatype; if (objXmlQualityItem.Attributes["removable"] != null) { objSource = QualitySource.MetatypeRemovable; } objQuality.Create(objXmlQuality, objCharacter, objSource, objNode, objWeapons, objWeaponNodes, strForceValue); objCharacter.Qualities.Add(objQuality); // Add any created Weapons to the character. foreach (Weapon objWeapon in objWeapons) { objCharacter.Weapons.Add(objWeapon); } } foreach (XmlNode objXmlQualityItem in objXmlMetatype.SelectNodes("qualities/negative/quality")) { XmlNode objXmlQuality = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQualityItem.InnerText + "\"]"); TreeNode objNode = new TreeNode(); List <Weapon> objWeapons = new List <Weapon>(); List <TreeNode> objWeaponNodes = new List <TreeNode>(); Quality objQuality = new Quality(objCharacter); string strForceValue = string.Empty; if (objXmlQualityItem.Attributes["select"] != null) { strForceValue = objXmlQualityItem.Attributes["select"].InnerText; } QualitySource objSource = new QualitySource(); objSource = QualitySource.Metatype; if (objXmlQualityItem.Attributes["removable"] != null) { objSource = QualitySource.MetatypeRemovable; } objQuality.Create(objXmlQuality, objCharacter, objSource, objNode, objWeapons, objWeaponNodes, strForceValue); objCharacter.Qualities.Add(objQuality); // Add any created Weapons to the character. foreach (Weapon objWeapon in objWeapons) { objCharacter.Weapons.Add(objWeapon); } } // Add any Critter Powers the Metatype/Critter should have. XmlNode objXmlCritter = objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + objCharacter.Metatype + "\"]"); objXmlDocument = XmlManager.Load("critterpowers.xml"); foreach (XmlNode objXmlPower in objXmlCritter.SelectNodes("powers/power")) { XmlNode objXmlCritterPower = objXmlDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower.InnerText + "\"]"); TreeNode objNode = new TreeNode(); CritterPower objPower = new CritterPower(objCharacter); string strForcedValue = string.Empty; int intRating = 0; if (objXmlPower.Attributes["rating"] != null) { intRating = Convert.ToInt32(objXmlPower.Attributes["rating"].InnerText); } if (objXmlPower.Attributes["select"] != null) { strForcedValue = objXmlPower.Attributes["select"].InnerText; } objPower.Create(objXmlCritterPower, objNode, intRating, strForcedValue); objCharacter.CritterPowers.Add(objPower); } if (objXmlCritter["optionalpowers"] != null) { //For every 3 full points of Force a spirit has, it may gain one Optional Power. for (int i = intForce - 3; i >= 0; i -= 3) { XmlDocument objDummyDocument = new XmlDocument(); XmlNode bonusNode = objDummyDocument.CreateNode(XmlNodeType.Element, "bonus", null); objDummyDocument.AppendChild(bonusNode); XmlNode powerNode = objDummyDocument.ImportNode(objXmlMetatype["optionalpowers"].CloneNode(true), true); objDummyDocument.ImportNode(powerNode, true); bonusNode.AppendChild(powerNode); ImprovementManager.CreateImprovements(objCharacter, Improvement.ImprovementSource.Metatype, objCharacter.Metatype, bonusNode, false, 1, objCharacter.Metatype); } } // Add any Complex Forms the Critter comes with (typically Sprites) XmlDocument objXmlProgramDocument = XmlManager.Load("complexforms.xml"); foreach (XmlNode objXmlComplexForm in objXmlCritter.SelectNodes("complexforms/complexform")) { string strForceValue = string.Empty; if (objXmlComplexForm.Attributes["select"] != null) { strForceValue = objXmlComplexForm.Attributes["select"].InnerText; } XmlNode objXmlProgram = objXmlProgramDocument.SelectSingleNode("/chummer/complexforms/complexform[name = \"" + objXmlComplexForm.InnerText + "\"]"); TreeNode objNode = new TreeNode(); ComplexForm objProgram = new ComplexForm(objCharacter); objProgram.Create(objXmlProgram, objNode, strForceValue); objCharacter.ComplexForms.Add(objProgram); } // Add any Gear the Critter comes with (typically Programs for A.I.s) XmlDocument objXmlGearDocument = XmlManager.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlCritter.SelectNodes("gears/gear")) { int intRating = 0; if (objXmlGear.Attributes["rating"] != null) { intRating = Convert.ToInt32(ExpressionToString(objXmlGear.Attributes["rating"].InnerText, decimal.ToInt32(nudForce.Value), 0)); } string strForceValue = string.Empty; if (objXmlGear.Attributes["select"] != null) { strForceValue = objXmlGear.Attributes["select"].InnerText; } XmlNode objXmlGearItem = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlGear.InnerText + "\"]"); TreeNode objNode = new TreeNode(); Gear objGear = new Gear(objCharacter); List <Weapon> lstWeapons = new List <Weapon>(); List <TreeNode> lstWeaponNodes = new List <TreeNode>(); objGear.Create(objXmlGearItem, objNode, intRating, lstWeapons, lstWeaponNodes, strForceValue); objGear.Cost = "0"; objCharacter.Gear.Add(objGear); } // Add the Unarmed Attack Weapon to the character. objXmlDocument = XmlManager.Load("weapons.xml"); XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"Unarmed Attack\"]"); if (objXmlWeapon != null) { Weapon objWeapon = new Weapon(objCharacter); objWeapon.Create(objXmlWeapon, null, null, null, objCharacter.Weapons); objWeapon.ParentID = Guid.NewGuid().ToString(); // Unarmed Attack can never be removed objCharacter.Weapons.Add(objWeapon); } objCharacter.Alias = strCritterName; objCharacter.Created = true; if (!objCharacter.Save()) { Cursor = Cursors.Default; objCharacter.Dispose(); return; } string strOpenFile = objCharacter.FileName; objCharacter.Dispose(); objCharacter = null; // Link the newly-created Critter to the Spirit. _objSpirit.FileName = strOpenFile; if (_objSpirit.EntityType == SpiritType.Spirit) { tipTooltip.SetToolTip(imgLink, LanguageManager.GetString("Tip_Spirit_OpenFile")); } else { tipTooltip.SetToolTip(imgLink, LanguageManager.GetString("Tip_Sprite_OpenFile")); } FileNameChanged(this); Character objOpenCharacter = frmMain.LoadCharacter(strOpenFile); Cursor = Cursors.Default; GlobalOptions.MainForm.OpenCharacter(objOpenCharacter); }
/// <summary> /// Accept the values on the Form and create the required XML data. /// </summary> private void AcceptForm() { // Make sure a value has been selected if necessary. if (txtSelect.Visible && string.IsNullOrEmpty(txtSelect.Text)) { MessageBox.Show(LanguageManager.GetString("Message_SelectItem"), LanguageManager.GetString("MessageTitle_SelectItem"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Make sure a value has been provided for the name. if (string.IsNullOrEmpty(txtName.Text)) { MessageBox.Show(LanguageManager.GetString("Message_ImprovementName"), LanguageManager.GetString("MessageTitle_ImprovementName"), MessageBoxButtons.OK, MessageBoxIcon.Error); txtName.Focus(); return; } MemoryStream objStream = new MemoryStream(); XmlWriter objWriter = XmlWriter.Create(objStream); // Build the XML for the Improvement. XmlNode objFetchNode = _objDocument.SelectSingleNode("/chummer/improvements/improvement[id = \"" + cboImprovemetType.SelectedValue + "\"]"); if (objFetchNode == null) { return; } objWriter.WriteStartDocument(); // <bonus> objWriter.WriteStartElement("bonus"); // <whatever element> objWriter.WriteStartElement(objFetchNode["internal"]?.InnerText); string strRating = string.Empty; if (chkApplyToRating.Checked) { strRating = "<applytorating>yes</applytorating>"; } // Retrieve the XML data from the document and replace the values as necessary. // ReSharper disable once PossibleNullReferenceException string strXml = objFetchNode["xml"].InnerText; strXml = strXml.Replace("{val}", nudVal.Value.ToString(GlobalOptions.InvariantCultureInfo)); strXml = strXml.Replace("{min}", nudMin.Value.ToString(GlobalOptions.InvariantCultureInfo)); strXml = strXml.Replace("{max}", nudMax.Value.ToString(GlobalOptions.InvariantCultureInfo)); strXml = strXml.Replace("{aug}", nudAug.Value.ToString(GlobalOptions.InvariantCultureInfo)); strXml = strXml.Replace("{free}", chkFree.Checked.ToString().ToLower()); strXml = strXml.Replace("{select}", txtSelect.Text); strXml = strXml.Replace("{applytorating}", strRating); objWriter.WriteRaw(strXml); // Write the rest of the document. // </whatever element> objWriter.WriteEndElement(); // </bonus> objWriter.WriteEndElement(); objWriter.WriteEndDocument(); objWriter.Flush(); objStream.Position = 0; // Read it back in as an XmlDocument. StreamReader objReader = new StreamReader(objStream); XmlDocument objBonusXml = new XmlDocument(); strXml = objReader.ReadToEnd(); objBonusXml.LoadXml(strXml); objWriter.Close(); // Pluck out the bonus information. XmlNode objNode = objBonusXml.SelectSingleNode("/bonus"); // Pass it to the Improvement Manager so that it can be added to the character. string strGuid = Guid.NewGuid().ToString(); ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.Custom, strGuid, objNode, false, 1, txtName.Text); // If an Improvement was passed in, remove it from the character. string strNotes = string.Empty; int intOrder = 0; if (_objEditImprovement != null) { // Copy the notes over to the new item. strNotes = _objEditImprovement.Notes; intOrder = _objEditImprovement.SortOrder; ImprovementManager.RemoveImprovements(_objCharacter, Improvement.ImprovementSource.Custom, _objEditImprovement.SourceName); } // Find the newly-created Improvement and attach its custom name. foreach (Improvement objImprovement in _objCharacter.Improvements) { if (objImprovement.SourceName == strGuid) { objImprovement.CustomName = txtName.Text; objImprovement.CustomId = cboImprovemetType.SelectedValue.ToString(); objImprovement.Custom = true; objImprovement.Notes = strNotes; objImprovement.SortOrder = intOrder; } } DialogResult = DialogResult.OK; }
/// <summary> /// Load the CharacterAttribute from the XmlNode. /// </summary> /// <param name="objNode">XmlNode to load.</param> /// <param name="blnCopy">Whether or not we are copying an existing node.</param> public void Load(XmlNode objNode, bool blnCopy = false) { if (blnCopy || !objNode.TryGetField("guid", Guid.TryParse, out _guiID)) { _guiID = Guid.NewGuid(); } if (objNode.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } objNode.TryGetStringFieldQuickly("category", ref _strCategory); objNode.TryGetInt32FieldQuickly("armor", ref _intArmorValue); objNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity); objNode.TryGetStringFieldQuickly("gearcapacity", ref _strGearCapacity); objNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating); objNode.TryGetInt32FieldQuickly("rating", ref _intRating); objNode.TryGetStringFieldQuickly("avail", ref _strAvail); objNode.TryGetStringFieldQuickly("cost", ref _strCost); _nodBonus = objNode["bonus"]; _nodWirelessBonus = objNode["wirelessbonus"]; objNode.TryGetStringFieldQuickly("source", ref _strSource); objNode.TryGetStringFieldQuickly("page", ref _strPage); objNode.TryGetBoolFieldQuickly("included", ref _blnIncludedInArmor); objNode.TryGetBoolFieldQuickly("equipped", ref _blnEquipped); if (!objNode.TryGetBoolFieldQuickly("wirelesson", ref _blnWirelessOn)) { _blnWirelessOn = _nodWirelessBonus != null; } objNode.TryGetStringFieldQuickly("extra", ref _strExtra); objNode.TryGetField("weaponguid", Guid.TryParse, out _guiWeaponID); objNode.TryGetStringFieldQuickly("notes", ref _strNotes); objNode.TryGetBoolFieldQuickly("discountedcost", ref _blnDiscountCost); XmlNode xmlChildrenNode = objNode["gears"]; if (xmlChildrenNode != null) { using (XmlNodeList nodGears = xmlChildrenNode.SelectNodes("gear")) if (nodGears != null) { foreach (XmlNode nodGear in nodGears) { Gear objGear = new Gear(_objCharacter); objGear.Load(nodGear, blnCopy); _lstGear.Add(objGear); } } } if (!blnCopy) { return; } if (!string.IsNullOrEmpty(Extra)) { ImprovementManager.ForcedValue = Extra; } ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.ArmorMod, _guiID.ToString("D"), Bonus, false, 1, DisplayNameShort(GlobalOptions.Language)); if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { Extra = ImprovementManager.SelectedValue; } if (_blnEquipped) { return; } _blnEquipped = true; Equipped = false; }
/// <summary> /// Create a Critter, put them into Career Mode, link them, and open the newly-created Critter. /// </summary> /// <param name="strCritterName">Name of the Critter's Metatype.</param> /// <param name="intForce">Critter's Force.</param> private async void CreateCritter(string strCritterName, int intForce) { // Code from frmMetatype. XmlDocument objXmlDocument = XmlManager.Load("critters.xml"); XmlNode objXmlMetatype = objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + strCritterName + "\"]"); // If the Critter could not be found, show an error and get out of here. if (objXmlMetatype == null) { Program.MainForm.ShowMessageBox(string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("Message_UnknownCritterType"), strCritterName), LanguageManager.GetString("MessageTitle_SelectCritterType"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (new CursorWait(this)) { // The Critter should use the same settings file as the character. using (Character objCharacter = new Character { SettingsFile = _objSpirit.CharacterObject.SettingsFile, // Override the defaults for the setting. IgnoreRules = true, IsCritter = true, BuildMethod = CharacterBuildMethod.Karma }) { if (!string.IsNullOrEmpty(txtCritterName.Text)) { objCharacter.Name = txtCritterName.Text; } string strSpace = LanguageManager.GetString("String_Space"); using (SaveFileDialog saveFileDialog = new SaveFileDialog { Filter = LanguageManager.GetString("DialogFilter_Chum5") + '|' + LanguageManager.GetString("DialogFilter_All"), FileName = new StringBuilder(strCritterName) .Append(strSpace).Append('(').Append(LanguageManager.GetString(_objSpirit.RatingLabel)) .Append(strSpace).Append(_objSpirit.Force.ToString(GlobalOptions.InvariantCultureInfo)).Append(").chum5").ToString() }) { if (saveFileDialog.ShowDialog(this) != DialogResult.OK) { return; } string strFileName = saveFileDialog.FileName; objCharacter.FileName = strFileName; } // Set Metatype information. if (strCritterName == "Ally Spirit") { objCharacter.BOD.AssignLimits(ExpressionToString(objXmlMetatype["bodmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["bodmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["bodaug"]?.InnerText, intForce, 0)); objCharacter.AGI.AssignLimits(ExpressionToString(objXmlMetatype["agimin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["agimax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["agiaug"]?.InnerText, intForce, 0)); objCharacter.REA.AssignLimits(ExpressionToString(objXmlMetatype["reamin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["reamax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["reaaug"]?.InnerText, intForce, 0)); objCharacter.STR.AssignLimits(ExpressionToString(objXmlMetatype["strmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["strmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["straug"]?.InnerText, intForce, 0)); objCharacter.CHA.AssignLimits(ExpressionToString(objXmlMetatype["chamin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["chamax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["chaaug"]?.InnerText, intForce, 0)); objCharacter.INT.AssignLimits(ExpressionToString(objXmlMetatype["intmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["intmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["intaug"]?.InnerText, intForce, 0)); objCharacter.LOG.AssignLimits(ExpressionToString(objXmlMetatype["logmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["logmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["logaug"]?.InnerText, intForce, 0)); objCharacter.WIL.AssignLimits(ExpressionToString(objXmlMetatype["wilmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["wilmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["wilaug"]?.InnerText, intForce, 0)); objCharacter.MAG.AssignLimits(ExpressionToString(objXmlMetatype["magmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["magmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["magaug"]?.InnerText, intForce, 0)); objCharacter.RES.AssignLimits(ExpressionToString(objXmlMetatype["resmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["resmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["resaug"]?.InnerText, intForce, 0)); objCharacter.EDG.AssignLimits(ExpressionToString(objXmlMetatype["edgmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["edgmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["edgaug"]?.InnerText, intForce, 0)); objCharacter.ESS.AssignLimits(ExpressionToString(objXmlMetatype["essmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essaug"]?.InnerText, intForce, 0)); } else { int intMinModifier = -3; objCharacter.BOD.AssignLimits(ExpressionToString(objXmlMetatype["bodmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["bodmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["bodmin"]?.InnerText, intForce, 3)); objCharacter.AGI.AssignLimits(ExpressionToString(objXmlMetatype["agimin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["agimin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["agimin"]?.InnerText, intForce, 3)); objCharacter.REA.AssignLimits(ExpressionToString(objXmlMetatype["reamin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["reamin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["reamin"]?.InnerText, intForce, 3)); objCharacter.STR.AssignLimits(ExpressionToString(objXmlMetatype["strmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["strmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["strmin"]?.InnerText, intForce, 3)); objCharacter.CHA.AssignLimits(ExpressionToString(objXmlMetatype["chamin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["chamin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["chamin"]?.InnerText, intForce, 3)); objCharacter.INT.AssignLimits(ExpressionToString(objXmlMetatype["intmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["intmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["intmin"]?.InnerText, intForce, 3)); objCharacter.LOG.AssignLimits(ExpressionToString(objXmlMetatype["logmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["logmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["logmin"]?.InnerText, intForce, 3)); objCharacter.WIL.AssignLimits(ExpressionToString(objXmlMetatype["wilmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["wilmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["wilmin"]?.InnerText, intForce, 3)); objCharacter.MAG.AssignLimits(ExpressionToString(objXmlMetatype["magmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["magmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["magmin"]?.InnerText, intForce, 3)); objCharacter.RES.AssignLimits(ExpressionToString(objXmlMetatype["resmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["resmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["resmin"]?.InnerText, intForce, 3)); objCharacter.EDG.AssignLimits(ExpressionToString(objXmlMetatype["edgmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["edgmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["edgmin"]?.InnerText, intForce, 3)); objCharacter.ESS.AssignLimits(ExpressionToString(objXmlMetatype["essmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essaug"]?.InnerText, intForce, 0)); } // If we're working with a Critter, set the Attributes to their default values. objCharacter.BOD.MetatypeMinimum = ExpressionToInt(objXmlMetatype["bodmin"]?.InnerText, intForce, 0); objCharacter.AGI.MetatypeMinimum = ExpressionToInt(objXmlMetatype["agimin"]?.InnerText, intForce, 0); objCharacter.REA.MetatypeMinimum = ExpressionToInt(objXmlMetatype["reamin"]?.InnerText, intForce, 0); objCharacter.STR.MetatypeMinimum = ExpressionToInt(objXmlMetatype["strmin"]?.InnerText, intForce, 0); objCharacter.CHA.MetatypeMinimum = ExpressionToInt(objXmlMetatype["chamin"]?.InnerText, intForce, 0); objCharacter.INT.MetatypeMinimum = ExpressionToInt(objXmlMetatype["intmin"]?.InnerText, intForce, 0); objCharacter.LOG.MetatypeMinimum = ExpressionToInt(objXmlMetatype["logmin"]?.InnerText, intForce, 0); objCharacter.WIL.MetatypeMinimum = ExpressionToInt(objXmlMetatype["wilmin"]?.InnerText, intForce, 0); objCharacter.MAG.MetatypeMinimum = ExpressionToInt(objXmlMetatype["magmin"]?.InnerText, intForce, 0); objCharacter.RES.MetatypeMinimum = ExpressionToInt(objXmlMetatype["resmin"]?.InnerText, intForce, 0); objCharacter.EDG.MetatypeMinimum = ExpressionToInt(objXmlMetatype["edgmin"]?.InnerText, intForce, 0); objCharacter.ESS.MetatypeMinimum = ExpressionToInt(objXmlMetatype["essmax"]?.InnerText, intForce, 0); // Sprites can never have Physical Attributes. if (objXmlMetatype["category"].InnerText.EndsWith("Sprite", StringComparison.Ordinal)) { objCharacter.BOD.AssignLimits("0", "0", "0"); objCharacter.AGI.AssignLimits("0", "0", "0"); objCharacter.REA.AssignLimits("0", "0", "0"); objCharacter.STR.AssignLimits("0", "0", "0"); } objCharacter.Metatype = strCritterName; objCharacter.MetatypeCategory = objXmlMetatype["category"].InnerText; objCharacter.Metavariant = string.Empty; objCharacter.MetatypeBP = 0; if (objXmlMetatype["movement"] != null) { objCharacter.Movement = objXmlMetatype["movement"].InnerText; } // Load the Qualities file. XmlDocument objXmlQualityDocument = XmlManager.Load("qualities.xml"); // Determine if the Metatype has any bonuses. if (objXmlMetatype.InnerXml.Contains("bonus")) { ImprovementManager.CreateImprovements(objCharacter, Improvement.ImprovementSource.Metatype, strCritterName, objXmlMetatype.SelectSingleNode("bonus"), 1, strCritterName); } // Create the Qualities that come with the Metatype. foreach (XmlNode objXmlQualityItem in objXmlMetatype.SelectNodes("qualities/*/quality")) { XmlNode objXmlQuality = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQualityItem.InnerText + "\"]"); List <Weapon> lstWeapons = new List <Weapon>(1); Quality objQuality = new Quality(objCharacter); string strForceValue = objXmlQualityItem.Attributes?["select"]?.InnerText ?? string.Empty; QualitySource objSource = objXmlQualityItem.Attributes["removable"]?.InnerText == bool.TrueString ? QualitySource.MetatypeRemovable : QualitySource.Metatype; objQuality.Create(objXmlQuality, objSource, lstWeapons, strForceValue); objCharacter.Qualities.Add(objQuality); // Add any created Weapons to the character. foreach (Weapon objWeapon in lstWeapons) { objCharacter.Weapons.Add(objWeapon); } } // Add any Critter Powers the Metatype/Critter should have. XmlNode objXmlCritter = objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + objCharacter.Metatype + "\"]"); objXmlDocument = XmlManager.Load("critterpowers.xml"); foreach (XmlNode objXmlPower in objXmlCritter.SelectNodes("powers/power")) { XmlNode objXmlCritterPower = objXmlDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower.InnerText + "\"]"); CritterPower objPower = new CritterPower(objCharacter); string strForcedValue = objXmlPower.Attributes?["select"]?.InnerText ?? string.Empty; int intRating = Convert.ToInt32(objXmlPower.Attributes?["rating"]?.InnerText, GlobalOptions.InvariantCultureInfo); objPower.Create(objXmlCritterPower, intRating, strForcedValue); objCharacter.CritterPowers.Add(objPower); } if (objXmlCritter["optionalpowers"] != null) { //For every 3 full points of Force a spirit has, it may gain one Optional Power. for (int i = intForce - 3; i >= 0; i -= 3) { XmlDocument objDummyDocument = new XmlDocument { XmlResolver = null }; XmlNode bonusNode = objDummyDocument.CreateNode(XmlNodeType.Element, "bonus", null); objDummyDocument.AppendChild(bonusNode); XmlNode powerNode = objDummyDocument.ImportNode(objXmlMetatype["optionalpowers"].CloneNode(true), true); objDummyDocument.ImportNode(powerNode, true); bonusNode.AppendChild(powerNode); ImprovementManager.CreateImprovements(objCharacter, Improvement.ImprovementSource.Metatype, objCharacter.Metatype, bonusNode, 1, objCharacter.Metatype); } } // Add any Complex Forms the Critter comes with (typically Sprites) XmlDocument objXmlProgramDocument = XmlManager.Load("complexforms.xml"); foreach (XmlNode objXmlComplexForm in objXmlCritter.SelectNodes("complexforms/complexform")) { string strForceValue = objXmlComplexForm.Attributes?["select"]?.InnerText ?? string.Empty; XmlNode objXmlComplexFormData = objXmlProgramDocument.SelectSingleNode("/chummer/complexforms/complexform[name = \"" + objXmlComplexForm.InnerText + "\"]"); ComplexForm objComplexForm = new ComplexForm(objCharacter); objComplexForm.Create(objXmlComplexFormData, strForceValue); objCharacter.ComplexForms.Add(objComplexForm); } // Add any Gear the Critter comes with (typically Programs for A.I.s) XmlDocument objXmlGearDocument = XmlManager.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlCritter.SelectNodes("gears/gear")) { int intRating = 0; if (objXmlGear.Attributes["rating"] != null) { intRating = ExpressionToInt(objXmlGear.Attributes["rating"].InnerText, decimal.ToInt32(nudForce.Value), 0); } string strForceValue = objXmlGear.Attributes?["select"]?.InnerText ?? string.Empty; XmlNode objXmlGearItem = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = " + objXmlGear.InnerText.CleanXPath() + "]"); Gear objGear = new Gear(objCharacter); List <Weapon> lstWeapons = new List <Weapon>(1); objGear.Create(objXmlGearItem, intRating, lstWeapons, strForceValue); objGear.Cost = "0"; objCharacter.Gear.Add(objGear); } // Add the Unarmed Attack Weapon to the character. objXmlDocument = XmlManager.Load("weapons.xml"); XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"Unarmed Attack\"]"); if (objXmlWeapon != null) { List <Weapon> lstWeapons = new List <Weapon>(1); Weapon objWeapon = new Weapon(objCharacter); objWeapon.Create(objXmlWeapon, lstWeapons); objWeapon.ParentID = Guid.NewGuid().ToString("D", GlobalOptions.InvariantCultureInfo); // Unarmed Attack can never be removed objCharacter.Weapons.Add(objWeapon); foreach (Weapon objLoopWeapon in lstWeapons) { objCharacter.Weapons.Add(objLoopWeapon); } } objCharacter.Alias = strCritterName; objCharacter.Created = true; if (!objCharacter.Save()) { return; } _objSpirit.FileName = objCharacter.FileName; } // Link the newly-created Critter to the Spirit. imgLink.SetToolTip(LanguageManager.GetString(_objSpirit.EntityType == SpiritType.Spirit ? "Tip_Spirit_OpenFile" : "Tip_Sprite_OpenFile")); ContactDetailChanged?.Invoke(this, EventArgs.Empty); Character objOpenCharacter = await Program.MainForm.LoadCharacter(_objSpirit.FileName).ConfigureAwait(true); Program.MainForm.OpenCharacter(objOpenCharacter); } }
/// Create a Armor Modification from an XmlNode. /// <param name="objXmlArmorNode">XmlNode to create the object from.</param> /// <param name="intRating">Rating of the selected ArmorMod.</param> /// <param name="lstWeapons">List of Weapons that are created by the Armor.</param> /// <param name="blnSkipCost">Whether or not creating the ArmorMod should skip the Variable price dialogue (should only be used by frmSelectArmor).</param> /// <param name="blnSkipSelectForms">Whether or not to skip selection forms (related to improvements) when creating this ArmorMod.</param> public void Create(XmlNode objXmlArmorNode, int intRating, List <Weapon> lstWeapons, bool blnSkipCost = false, bool blnSkipSelectForms = false) { if (objXmlArmorNode.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } objXmlArmorNode.TryGetStringFieldQuickly("category", ref _strCategory); objXmlArmorNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity); objXmlArmorNode.TryGetStringFieldQuickly("gearcapacity", ref _strGearCapacity); _intRating = intRating; objXmlArmorNode.TryGetInt32FieldQuickly("armor", ref _intArmorValue); objXmlArmorNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating); objXmlArmorNode.TryGetStringFieldQuickly("avail", ref _strAvail); objXmlArmorNode.TryGetStringFieldQuickly("source", ref _strSource); objXmlArmorNode.TryGetStringFieldQuickly("page", ref _strPage); if (!objXmlArmorNode.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objXmlArmorNode.TryGetStringFieldQuickly("notes", ref _strNotes); } _nodBonus = objXmlArmorNode["bonus"]; _nodWirelessBonus = objXmlArmorNode["wirelessbonus"]; _blnWirelessOn = _nodWirelessBonus != null; objXmlArmorNode.TryGetStringFieldQuickly("cost", ref _strCost); // Check for a Variable Cost. if (!blnSkipCost && _strCost.StartsWith("Variable(")) { string strFirstHalf = _strCost.TrimStartOnce("Variable(", true).TrimEndOnce(')'); string strSecondHalf = string.Empty; int intHyphenIndex = strFirstHalf.IndexOf('-'); if (intHyphenIndex != -1) { if (intHyphenIndex + 1 < strFirstHalf.Length) { strSecondHalf = strFirstHalf.Substring(intHyphenIndex + 1); } strFirstHalf = strFirstHalf.Substring(0, intHyphenIndex); } if (!blnSkipSelectForms) { decimal decMin; decimal decMax = decimal.MaxValue; if (intHyphenIndex != -1) { decMin = Convert.ToDecimal(strFirstHalf, GlobalOptions.InvariantCultureInfo); decMax = Convert.ToDecimal(strSecondHalf, GlobalOptions.InvariantCultureInfo); } else { decMin = Convert.ToDecimal(strFirstHalf.FastEscape('+'), GlobalOptions.InvariantCultureInfo); } if (decMin != decimal.MinValue || decMax != decimal.MaxValue) { frmSelectNumber frmPickNumber = new frmSelectNumber(_objCharacter.Options.NuyenDecimals); if (decMax > 1000000) { decMax = 1000000; } frmPickNumber.Minimum = decMin; frmPickNumber.Maximum = decMax; frmPickNumber.Description = string.Format(LanguageManager.GetString("String_SelectVariableCost", GlobalOptions.Language), DisplayNameShort(GlobalOptions.Language)); frmPickNumber.AllowCancel = false; frmPickNumber.ShowDialog(); _strCost = frmPickNumber.SelectedValue.ToString(GlobalOptions.InvariantCultureInfo); } else { _strCost = strFirstHalf; } } else { _strCost = strFirstHalf; } } if (objXmlArmorNode["bonus"] != null && !blnSkipSelectForms) { if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.ArmorMod, _guiID.ToString("D"), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; } } // Add any Gear that comes with the Armor. XmlNode xmlChildrenNode = objXmlArmorNode["gears"]; if (xmlChildrenNode != null) { XmlDocument objXmlGearDocument = XmlManager.Load("gear.xml"); using (XmlNodeList xmlUseGearList = xmlChildrenNode.SelectNodes("usegear")) if (xmlUseGearList != null) { foreach (XmlNode objXmlArmorGear in xmlUseGearList) { intRating = 0; string strForceValue = string.Empty; objXmlArmorGear.TryGetInt32FieldQuickly("rating", ref intRating); objXmlArmorGear.TryGetStringFieldQuickly("select", ref strForceValue); XmlNode objXmlGear = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = " + objXmlArmorGear.InnerText.CleanXPath() + "]"); Gear objGear = new Gear(_objCharacter); objGear.Create(objXmlGear, intRating, lstWeapons, strForceValue, !blnSkipSelectForms); objGear.Capacity = "[0]"; objGear.ArmorCapacity = "[0]"; objGear.Cost = "0"; objGear.ParentID = InternalId; _lstGear.Add(objGear); } } } // Add Weapons if applicable. if (objXmlArmorNode.InnerXml.Contains("<addweapon>")) { XmlDocument objXmlWeaponDocument = XmlManager.Load("weapons.xml"); // More than one Weapon can be added, so loop through all occurrences. using (XmlNodeList xmlAddWeaponList = objXmlArmorNode.SelectNodes("addweapon")) if (xmlAddWeaponList != null) { foreach (XmlNode objXmlAddWeapon in xmlAddWeaponList) { string strLoopID = objXmlAddWeapon.InnerText; XmlNode objXmlWeapon = strLoopID.IsGuid() ? objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + strLoopID + "\"]") : objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + strLoopID + "\"]"); Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Create(objXmlWeapon, lstWeapons, true, !blnSkipSelectForms, blnSkipCost); objGearWeapon.ParentID = InternalId; objGearWeapon.Cost = "0"; lstWeapons.Add(objGearWeapon); Guid.TryParse(objGearWeapon.InternalId, out _guiWeaponID); } } } }
/// Create a Critter Power from an XmlNode. /// <param name="objXmlPowerNode">XmlNode to create the object from.</param> /// <param name="intRating">Selected Rating for the Gear.</param> /// <param name="strForcedValue">Value to forcefully select for any ImprovementManager prompts.</param> public void Create(XmlNode objXmlPowerNode, int intRating = 0, string strForcedValue = "") { if (!objXmlPowerNode.TryGetField("id", Guid.TryParse, out _guiSourceID)) { Log.Warn(new object[] { "Missing id field for power xmlnode", objXmlPowerNode }); Utils.BreakIfDebug(); } if (objXmlPowerNode.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } _intRating = intRating; _nodBonus = objXmlPowerNode.SelectSingleNode("bonus"); if (!objXmlPowerNode.TryGetMultiLineStringFieldQuickly("altnotes", ref _strNotes)) { objXmlPowerNode.TryGetMultiLineStringFieldQuickly("notes", ref _strNotes); } // If the piece grants a bonus, pass the information to the Improvement Manager. if (_nodBonus != null) { ImprovementManager.ForcedValue = strForcedValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.CritterPower, _guiID.ToString("D", GlobalOptions.InvariantCultureInfo), _nodBonus, intRating, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; } else if (intRating != 0) { _strExtra = intRating.ToString(GlobalOptions.InvariantCultureInfo); } } else if (intRating != 0) { _strExtra = intRating.ToString(GlobalOptions.InvariantCultureInfo); } else { _strExtra = strForcedValue; } objXmlPowerNode.TryGetStringFieldQuickly("category", ref _strCategory); objXmlPowerNode.TryGetStringFieldQuickly("type", ref _strType); objXmlPowerNode.TryGetStringFieldQuickly("action", ref _strAction); objXmlPowerNode.TryGetStringFieldQuickly("range", ref _strRange); objXmlPowerNode.TryGetStringFieldQuickly("duration", ref _strDuration); objXmlPowerNode.TryGetStringFieldQuickly("source", ref _strSource); objXmlPowerNode.TryGetStringFieldQuickly("page", ref _strPage); objXmlPowerNode.TryGetInt32FieldQuickly("karma", ref _intKarma); /* * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPdf(_strSource + ' ' + _strPage, _strName); * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPdf(Source + ' ' + DisplayPage(GlobalOptions.Language), CurrentDisplayName); * } * } */ }
/// <summary> /// Create a Mentor Spirit from an XmlNode. /// </summary> /// <param name="xmlMentor">XmlNode to create the object from.</param> /// <param name="eMentorType">Whether this is a Mentor or a Paragon.</param> /// <param name="strForceValueChoice1">Name/Text for Choice 1.</param> /// <param name="strForceValueChoice2">Name/Text for Choice 2.</param> /// <param name="strForceValue">Force a value to be selected for the Mentor Spirit.</param> public void Create(XmlNode xmlMentor, Improvement.ImprovementType eMentorType, string strForceValue = "", string strForceValueChoice1 = "", string strForceValueChoice2 = "") { _eMentorType = eMentorType; _objCachedMyXmlNode = null; xmlMentor.TryGetStringFieldQuickly("name", ref _strName); xmlMentor.TryGetStringFieldQuickly("source", ref _strSource); xmlMentor.TryGetStringFieldQuickly("page", ref _strPage); if (!xmlMentor.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { xmlMentor.TryGetStringFieldQuickly("notes", ref _strNotes); } if (!xmlMentor.TryGetField("id", Guid.TryParse, out _guiSourceID)) { Log.Warn(new object[] { "Missing id field for xmlnode", xmlMentor }); Utils.BreakIfDebug(); } // Build the list of advantages gained through the Mentor Spirit. if (!xmlMentor.TryGetStringFieldQuickly("altadvantage", ref _strAdvantage)) { xmlMentor.TryGetStringFieldQuickly("advantage", ref _strAdvantage); } if (!xmlMentor.TryGetStringFieldQuickly("altdisadvantage", ref _strDisadvantage)) { xmlMentor.TryGetStringFieldQuickly("disadvantage", ref _strDisadvantage); } _nodBonus = xmlMentor["bonus"]; if (_nodBonus != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = strForceValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), _nodBonus, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } _strExtra = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (!string.IsNullOrEmpty(strForceValue)) { _strExtra = strForceValue; } _nodChoice1 = xmlMentor.SelectSingleNode("choices/choice[name = \"" + strForceValueChoice1 + "\"]/bonus"); if (_nodChoice1 != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; //ImprovementManager.ForcedValue = strForceValueChoice1; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), _nodChoice1, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (string.IsNullOrEmpty(_strExtra)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (string.IsNullOrEmpty(_strExtra) && !string.IsNullOrEmpty(strForceValueChoice1)) { _strExtra = strForceValueChoice1; } _nodChoice2 = xmlMentor.SelectSingleNode("choices/choice[name = \"" + strForceValueChoice2 + "\"]/bonus"); if (_nodChoice2 != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; //ImprovementManager.ForcedValue = strForceValueChoice2; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), _nodChoice2, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (string.IsNullOrEmpty(_strExtra)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (string.IsNullOrEmpty(_strExtra) && !string.IsNullOrEmpty(strForceValueChoice2)) { _strExtra = strForceValueChoice2; } /* * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPDF($"{_strSource} {_strPage}", _strName); * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPDF($"{Source} {Page(GlobalOptions.Language)}", DisplayName(GlobalOptions.Language)); * } * }*/ }
/// <summary> /// Create a LifestyleQuality from an XmlNode. /// </summary> /// <param name="objXmlLifestyleQuality">XmlNode to create the object from.</param> /// <param name="objCharacter">Character object the LifestyleQuality will be added to.</param> /// <param name="objParentLifestyle">Lifestyle object to which the LifestyleQuality will be added.</param> /// <param name="objLifestyleQualitySource">Source of the LifestyleQuality.</param> /// <param name="strExtra">Forced value for the LifestyleQuality's Extra string (also used by its bonus node).</param> public void Create(XmlNode objXmlLifestyleQuality, Lifestyle objParentLifestyle, Character objCharacter, QualitySource objLifestyleQualitySource, string strExtra = "") { ParentLifestyle = objParentLifestyle; if (!objXmlLifestyleQuality.TryGetField("id", Guid.TryParse, out _guiSourceID)) { Log.Warn(new object[] { "Missing id field for xmlnode", objXmlLifestyleQuality }); Utils.BreakIfDebug(); } else { _objCachedMyXmlNode = null; } if (objXmlLifestyleQuality.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } objXmlLifestyleQuality.TryGetInt32FieldQuickly("lp", ref _intLP); objXmlLifestyleQuality.TryGetStringFieldQuickly("cost", ref _strCost); objXmlLifestyleQuality.TryGetInt32FieldQuickly("multiplier", ref _intMultiplier); objXmlLifestyleQuality.TryGetInt32FieldQuickly("multiplierbaseonly", ref _intBaseMultiplier); if (objXmlLifestyleQuality.TryGetStringFieldQuickly("category", ref _strCategory)) { Type = ConvertToLifestyleQualityType(_strCategory); } OriginSource = objLifestyleQualitySource; objXmlLifestyleQuality.TryGetInt32FieldQuickly("areamaximum", ref _intAreaMaximum); objXmlLifestyleQuality.TryGetInt32FieldQuickly("comfortsmaximum", ref _intComfortMaximum); objXmlLifestyleQuality.TryGetInt32FieldQuickly("securitymaximum", ref _intSecurityMaximum); objXmlLifestyleQuality.TryGetInt32FieldQuickly("area", ref _intArea); objXmlLifestyleQuality.TryGetInt32FieldQuickly("comforts", ref _intComfort); objXmlLifestyleQuality.TryGetInt32FieldQuickly("security", ref _intSecurity); objXmlLifestyleQuality.TryGetBoolFieldQuickly("print", ref _blnPrint); objXmlLifestyleQuality.TryGetBoolFieldQuickly("contributetolimit", ref _blnContributeToLP); if (!objXmlLifestyleQuality.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objXmlLifestyleQuality.TryGetStringFieldQuickly("notes", ref _strNotes); } objXmlLifestyleQuality.TryGetStringFieldQuickly("source", ref _strSource); objXmlLifestyleQuality.TryGetStringFieldQuickly("page", ref _strPage); var strAllowedFreeLifestyles = string.Empty; if (objXmlLifestyleQuality.TryGetStringFieldQuickly("allowed", ref strAllowedFreeLifestyles)) { _lstAllowedFreeLifestyles = strAllowedFreeLifestyles.Split(',', StringSplitOptions.RemoveEmptyEntries); } _strExtra = strExtra; if (!string.IsNullOrEmpty(_strExtra)) { var intParenthesesIndex = _strExtra.IndexOf('('); if (intParenthesesIndex != -1) { _strExtra = intParenthesesIndex + 1 < strExtra.Length ? strExtra.Substring(intParenthesesIndex + 1).TrimEndOnce(')') : string.Empty; } } if (string.IsNullOrEmpty(Notes)) { string strEnglishNameOnPage = Name; string strNameOnPage = string.Empty; // make sure we have something and not just an empty tag if (objXmlLifestyleQuality.TryGetStringFieldQuickly("nameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage)) { strEnglishNameOnPage = strNameOnPage; } string strGearNotes = CommonFunctions.GetTextFromPDF(Source + ' ' + Page, strEnglishNameOnPage); if (string.IsNullOrEmpty(strGearNotes) && GlobalOptions.Language != GlobalOptions.DefaultLanguage) { string strTranslatedNameOnPage = CurrentDisplayName; // don't check again it is not translated if (strTranslatedNameOnPage != _strName) { // if we found <altnameonpage>, and is not empty and not the same as english we must use that instead if (objXmlLifestyleQuality.TryGetStringFieldQuickly("altnameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage) && strNameOnPage != strEnglishNameOnPage) { strTranslatedNameOnPage = strNameOnPage; } Notes = CommonFunctions.GetTextFromPDF(Source + ' ' + DisplayPage(GlobalOptions.Language), strTranslatedNameOnPage); } } else { Notes = strGearNotes; } } // If the item grants a bonus, pass the information to the Improvement Manager. XmlNode xmlBonus = objXmlLifestyleQuality["bonus"]; if (xmlBonus != null) { var strOldForced = ImprovementManager.ForcedValue; if (!string.IsNullOrEmpty(_strExtra)) { ImprovementManager.ForcedValue = _strExtra; } if (!ImprovementManager.CreateImprovements(objCharacter, Improvement.ImprovementSource.Quality, InternalId, xmlBonus, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; ImprovementManager.ForcedValue = strOldForced; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldForced; } // Built-In Qualities appear as grey text to show that they cannot be removed. if (objLifestyleQualitySource == QualitySource.BuiltIn) { Free = true; } }
/// <summary> /// Create a LifestyleQuality from an XmlNode. /// </summary> /// <param name="objXmlLifestyleQuality">XmlNode to create the object from.</param> /// <param name="objCharacter">Character object the LifestyleQuality will be added to.</param> /// <param name="objParentLifestyle">Lifestyle object to which the LifestyleQuality will be added.</param> /// <param name="objLifestyleQualitySource">Source of the LifestyleQuality.</param> /// <param name="strExtra">Forced value for the LifestyleQuality's Extra string (also used by its bonus node).</param> public void Create(XmlNode objXmlLifestyleQuality, Lifestyle objParentLifestyle, Character objCharacter, QualitySource objLifestyleQualitySource, string strExtra = "") { _objParentLifestyle = objParentLifestyle; objXmlLifestyleQuality.TryGetField("id", Guid.TryParse, out _SourceGuid); if (objXmlLifestyleQuality.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } objXmlLifestyleQuality.TryGetInt32FieldQuickly("lp", ref _intLP); objXmlLifestyleQuality.TryGetStringFieldQuickly("cost", ref _strCost); objXmlLifestyleQuality.TryGetInt32FieldQuickly("multiplier", ref _intMultiplier); objXmlLifestyleQuality.TryGetInt32FieldQuickly("multiplierbaseonly", ref _intBaseMultiplier); if (objXmlLifestyleQuality.TryGetStringFieldQuickly("category", ref _strCategory)) { _objLifestyleQualityType = ConvertToLifestyleQualityType(_strCategory); } _objLifestyleQualitySource = objLifestyleQualitySource; objXmlLifestyleQuality.TryGetBoolFieldQuickly("print", ref _blnPrint); objXmlLifestyleQuality.TryGetBoolFieldQuickly("contributetolimit", ref _blnContributeToLimit); if (!objXmlLifestyleQuality.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objXmlLifestyleQuality.TryGetStringFieldQuickly("notes", ref _strNotes); } objXmlLifestyleQuality.TryGetStringFieldQuickly("source", ref _strSource); objXmlLifestyleQuality.TryGetStringFieldQuickly("page", ref _strPage); string strAllowedFreeLifestyles = string.Empty; if (objXmlLifestyleQuality.TryGetStringFieldQuickly("allowed", ref strAllowedFreeLifestyles)) { _lstAllowedFreeLifestyles = strAllowedFreeLifestyles.Split(',').ToList(); } _strExtra = strExtra; int intParenthesesIndex = _strExtra.IndexOf('('); if (intParenthesesIndex != -1) { _strExtra = intParenthesesIndex + 1 < strExtra.Length ? strExtra.Substring(intParenthesesIndex + 1).TrimEndOnce(')') : string.Empty; } // If the item grants a bonus, pass the information to the Improvement Manager. XmlNode xmlBonus = objXmlLifestyleQuality["bonus"]; if (xmlBonus != null) { string strOldFoced = ImprovementManager.ForcedValue; if (!string.IsNullOrEmpty(_strExtra)) { ImprovementManager.ForcedValue = _strExtra; } if (!ImprovementManager.CreateImprovements(objCharacter, Improvement.ImprovementSource.Quality, InternalId, xmlBonus, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; ImprovementManager.ForcedValue = strOldFoced; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldFoced; } // Built-In Qualities appear as grey text to show that they cannot be removed. if (objLifestyleQualitySource == QualitySource.BuiltIn) { Free = true; } }
/// Create a Martial Art from an XmlNode. /// <param name="objXmlArtNode">XmlNode to create the object from.</param> public void Create(XmlNode objXmlArtNode) { if (!objXmlArtNode.TryGetField("id", Guid.TryParse, out _guiSourceID)) { Log.Warn(new object[] { "Missing id field for xmlnode", objXmlArtNode }); Utils.BreakIfDebug(); } if (objXmlArtNode.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } objXmlArtNode.TryGetStringFieldQuickly("source", ref _strSource); objXmlArtNode.TryGetStringFieldQuickly("page", ref _strPage); objXmlArtNode.TryGetInt32FieldQuickly("cost", ref _intKarmaCost); if (!objXmlArtNode.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objXmlArtNode.TryGetStringFieldQuickly("notes", ref _strNotes); } _blnIsQuality = objXmlArtNode["isquality"]?.InnerText == bool.TrueString; if (objXmlArtNode["bonus"] != null) { ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MartialArt, InternalId, objXmlArtNode["bonus"], 1, DisplayNameShort(GlobalOptions.Language)); } if (string.IsNullOrEmpty(Notes)) { string strEnglishNameOnPage = Name; string strNameOnPage = string.Empty; // make sure we have something and not just an empty tag if (objXmlArtNode.TryGetStringFieldQuickly("nameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage)) { strEnglishNameOnPage = strNameOnPage; } string strQualityNotes = CommonFunctions.GetTextFromPDF(Source + ' ' + Page, strEnglishNameOnPage); if (string.IsNullOrEmpty(strQualityNotes) && GlobalOptions.Language != GlobalOptions.DefaultLanguage) { string strTranslatedNameOnPage = CurrentDisplayName; // don't check again it is not translated if (strTranslatedNameOnPage != _strName) { // if we found <altnameonpage>, and is not empty and not the same as english we must use that instead if (objXmlArtNode.TryGetStringFieldQuickly("altnameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage) && strNameOnPage != strEnglishNameOnPage) { strTranslatedNameOnPage = strNameOnPage; } Notes = CommonFunctions.GetTextFromPDF(Source + ' ' + DisplayPage(GlobalOptions.Language), strTranslatedNameOnPage); } } else { Notes = strQualityNotes; } } }
/// Create a Armor Modification from an XmlNode and return the TreeNodes for it. /// <param name="objXmlArmorNode">XmlNode to create the object from.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="intRating">Rating of the selected ArmorMod.</param> /// <param name="objWeapons">List of Weapons that are created by the Armor.</param> /// <param name="objWeaponNodes">List of Weapon Nodes that are created by the Armor.</param> /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param> public void Create(XmlNode objXmlArmorNode, TreeNode objNode, int intRating, List <Weapon> objWeapons, List <TreeNode> objWeaponNodes, bool blnSkipCost = false, bool blnSkipSelectForms = false) { objXmlArmorNode.TryGetStringFieldQuickly("name", ref _strName); objXmlArmorNode.TryGetStringFieldQuickly("category", ref _strCategory); objXmlArmorNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity); _intRating = intRating; objXmlArmorNode.TryGetInt32FieldQuickly("armor", ref _intA); objXmlArmorNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating); objXmlArmorNode.TryGetStringFieldQuickly("avail", ref _strAvail); objXmlArmorNode.TryGetStringFieldQuickly("source", ref _strSource); objXmlArmorNode.TryGetStringFieldQuickly("page", ref _strPage); _nodBonus = objXmlArmorNode["bonus"]; _nodWirelessBonus = objXmlArmorNode["wirelessbonus"]; _blnWirelessOn = _nodWirelessBonus != null; if (GlobalOptions.Language != GlobalOptions.DefaultLanguage) { XmlNode objArmorNode = MyXmlNode; if (objArmorNode != null) { objArmorNode.TryGetStringFieldQuickly("translate", ref _strAltName); objArmorNode.TryGetStringFieldQuickly("altpage", ref _strAltPage); } XmlDocument objXmlDocument = XmlManager.Load("armor.xml"); objArmorNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]"); _strAltCategory = objArmorNode?.Attributes?["translate"]?.InnerText; } // Check for a Variable Cost. if (blnSkipCost) { _strCost = "0"; } else if (objXmlArmorNode["cost"] != null) { XmlNode objXmlArmorCostNode = objXmlArmorNode["cost"]; if (objXmlArmorCostNode.InnerText.StartsWith("Variable")) { decimal decMin = 0.0m; decimal decMax = decimal.MaxValue; char[] charParentheses = { '(', ')' }; string strCost = objXmlArmorNode["cost"].InnerText.TrimStart("Variable", true).Trim(charParentheses); if (strCost.Contains('-')) { string[] strValues = strCost.Split('-'); decMin = Convert.ToDecimal(strValues[0], GlobalOptions.InvariantCultureInfo); decMax = Convert.ToDecimal(strValues[1], GlobalOptions.InvariantCultureInfo); } else { decMin = Convert.ToDecimal(strCost.FastEscape('+'), GlobalOptions.InvariantCultureInfo); } if (decMin != 0 || decMax != decimal.MaxValue) { frmSelectNumber frmPickNumber = new frmSelectNumber(); if (decMax > 1000000) { decMax = 1000000; } frmPickNumber.Minimum = decMin; frmPickNumber.Maximum = decMax; frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost").Replace("{0}", DisplayNameShort); frmPickNumber.AllowCancel = false; frmPickNumber.ShowDialog(); _strCost = frmPickNumber.SelectedValue.ToString(); } } else { _strCost = objXmlArmorCostNode.InnerText; } } if (objXmlArmorNode["bonus"] != null && !blnSkipCost && !blnSkipSelectForms) { if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.ArmorMod, _guiID.ToString(), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; objNode.Text += " (" + ImprovementManager.SelectedValue + ")"; } } // Add Weapons if applicable. if (objXmlArmorNode.InnerXml.Contains("<addweapon>")) { XmlDocument objXmlWeaponDocument = XmlManager.Load("weapons.xml"); // More than one Weapon can be added, so loop through all occurrences. foreach (XmlNode objXmlAddWeapon in objXmlArmorNode.SelectNodes("addweapon")) { var objXmlWeapon = helpers.Guid.IsGuid(objXmlAddWeapon.InnerText) ? objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + objXmlAddWeapon.InnerText + "\" and starts-with(category, \"Cyberware\")]") : objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlAddWeapon.InnerText + "\" and starts-with(category, \"Cyberware\")]"); TreeNode objGearWeaponNode = new TreeNode(); Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Create(objXmlWeapon, objGearWeaponNode, null, null); objGearWeapon.ParentID = InternalId; objGearWeaponNode.ForeColor = SystemColors.GrayText; objWeaponNodes.Add(objGearWeaponNode); objWeapons.Add(objGearWeapon); _guiWeaponID = Guid.Parse(objGearWeapon.InternalId); } } objNode.Text = DisplayName; objNode.Tag = _guiID.ToString(); }