/// <summary> /// Build the list of Qualities. /// </summary> private void BuildQualityList() { if (_blnLoading) { return; } string strCategory = cboCategory.SelectedValue?.ToString(); string strFilter = "(" + _objCharacter.Options.BookXPath() + ")"; if (!string.IsNullOrEmpty(strCategory) && strCategory != "Show All" && (_objCharacter.Options.SearchInCategoryOnly || txtSearch.TextLength == 0)) { strFilter += " and category = \"" + strCategory + "\""; } else { StringBuilder objCategoryFilter = new StringBuilder(); foreach (string strItem in _lstCategory.Select(x => x.Value)) { if (!string.IsNullOrEmpty(strItem)) { objCategoryFilter.Append("category = \"" + strItem + "\" or "); } } if (objCategoryFilter.Length > 0) { strFilter += " and (" + objCategoryFilter.ToString().TrimEnd(" or ") + ")"; } } if (!string.IsNullOrWhiteSpace(txtSearch.Text)) { // Treat everything as being uppercase so the search is case-insensitive. string strSearchText = txtSearch.Text.ToUpper(); strFilter += " and ((contains(translate(name,'abcdefghijklmnopqrstuvwxyzàáâãäåçèéêëìíîïñòóôõöùúûüýß','ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝß'), \"" + strSearchText + "\") and not(translate)) or contains(translate(translate,'abcdefghijklmnopqrstuvwxyzàáâãäåçèéêëìíîïñòóôõöùúûüýß','ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝß'), \"" + strSearchText + "\"))"; } if (chkMetagenetic.Checked) { strFilter += " and (metagenetic = 'yes' or required/oneof[contains(., 'Changeling')])"; } else if (chkNotMetagenetic.Checked) { strFilter += " and not(metagenetic = 'yes') and not(required/oneof[contains(., 'Changeling')])"; } if (nudValueBP.Value != 0) { strFilter += "and karma = " + nudValueBP.Value; } else { if (nudMinimumBP.Value != 0) { strFilter += "and karma >= " + nudMinimumBP.Value; } if (nudMaximumBP.Value != 0) { strFilter += "and karma <= " + nudMaximumBP.Value; } } XmlDocument objXmlMetatypeDocument = XmlManager.Load("metatypes.xml"); XmlDocument objXmlCrittersDocument = XmlManager.Load("critters.xml"); bool blnNeedQualityWhitelist = false; XmlNode objXmlMetatype = objXmlMetatypeDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + _objCharacter.Metatype + "\"]"); if (objXmlMetatype?.SelectSingleNode("qualityrestriction") != null) { blnNeedQualityWhitelist = true; } else { objXmlMetatype = objXmlCrittersDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + _objCharacter.Metatype + "\"]"); if (objXmlMetatype?.SelectSingleNode("qualityrestriction") != null) { blnNeedQualityWhitelist = true; } } XmlNodeList objXmlQualityList = _objXmlDocument.SelectNodes("/chummer/qualities/quality[" + strFilter + "]"); List <ListItem> lstQuality = new List <ListItem>(); foreach (XmlNode objXmlQuality in objXmlQualityList) { if (objXmlQuality["name"] == null) { continue; } if (blnNeedQualityWhitelist) { if (strCategory == "Show All") { bool blnAllowed = false; foreach (ListItem objCategory in _lstCategory) { if (objXmlMetatype.SelectSingleNode("qualityrestriction/*/quality[. = \"" + objXmlQuality["name"].InnerText + "\"]") != null) { blnAllowed = true; break; } } if (!blnAllowed) { continue; } } else if (objXmlMetatype.SelectSingleNode("qualityrestriction/" + strCategory.ToLower() + "/quality[. = \"" + objXmlQuality["name"].InnerText + "\"]") == null) { continue; } } if (!chkLimitList.Checked || SelectionShared.RequirementsMet(objXmlQuality, false, _objCharacter, objXmlMetatypeDocument, objXmlCrittersDocument, _objXmlDocument, IgnoreQuality)) { ListItem objItem = new ListItem(); objItem.Value = objXmlQuality["name"].InnerText; objItem.Name = objXmlQuality["translate"]?.InnerText ?? objItem.Value; lstQuality.Add(objItem); } } SortListItem objSort = new SortListItem(); lstQuality.Sort(objSort.Compare); lstQualities.BeginUpdate(); lstQualities.DataSource = null; lstQualities.ValueMember = "Value"; lstQualities.DisplayMember = "Name"; lstQualities.DataSource = lstQuality; lstQualities.EndUpdate(); }
private void frmSelectItem_Load(object sender, EventArgs e) { IList<ListItem> lstItems = new List<ListItem>(); if (_strMode == "Gear") { string strSpace = LanguageManager.GetString("String_Space", GlobalOptions.Language); cboAmmo.DropDownStyle = ComboBoxStyle.DropDownList; // Add each of the items to a new List since we need to also grab their plugin information. foreach (Gear objGear in _lstGear) { string strAmmoName = objGear.DisplayNameShort(GlobalOptions.Language); // Retrieve the plugin information if it has any. if (objGear.Children.Count > 0) { string strPlugins = string.Empty; foreach (Gear objChild in objGear.Children) { strPlugins += objChild.DisplayNameShort(GlobalOptions.Language) + ',' + strSpace; } // Remove the trailing comma. strPlugins = strPlugins.Substring(0, strPlugins.Length - 1 - strSpace.Length); // Append the plugin information to the name. strAmmoName += strSpace + '[' + strPlugins + ']'; } if (objGear.Rating > 0) strAmmoName += strSpace + '(' + LanguageManager.GetString("String_Rating", GlobalOptions.Language) + strSpace + objGear.Rating.ToString(GlobalOptions.CultureInfo) + ')'; strAmmoName += strSpace + 'x' + objGear.Quantity.ToString(GlobalOptions.InvariantCultureInfo); lstItems.Add(new ListItem(objGear.InternalId, strAmmoName)); } } else if (_strMode == "Vehicles") { cboAmmo.DropDownStyle = ComboBoxStyle.DropDownList; // Add each of the items to a new List. foreach (Vehicle objVehicle in _lstVehicles) { lstItems.Add(new ListItem(objVehicle.InternalId, objVehicle.DisplayName(GlobalOptions.Language))); } } else if (_strMode == "General") { cboAmmo.DropDownStyle = ComboBoxStyle.DropDownList; lstItems = _lstGeneralItems; } else if (_strMode == "Dropdown") { cboAmmo.DropDownStyle = ComboBoxStyle.DropDown; lstItems = _lstGeneralItems; } else if (_strMode == "Restricted") { cboAmmo.DropDownStyle = ComboBoxStyle.DropDown; if (!_objCharacter.Options.LicenseRestricted) { using (XmlNodeList objXmlList = XmlManager.Load("licenses.xml").SelectNodes("/chummer/licenses/license")) if (objXmlList != null) foreach (XmlNode objNode in objXmlList) { string strInnerText = objNode.InnerText; lstItems.Add(new ListItem(strInnerText, objNode.Attributes?["translate"]?.InnerText ?? strInnerText)); } } else { // Cyberware/Bioware. foreach (Cyberware objCyberware in _objCharacter.Cyberware.GetAllDescendants(x => x.Children)) { if (objCyberware.TotalAvailTuple(false).Suffix == 'R') { lstItems.Add(new ListItem(objCyberware.InternalId, objCyberware.DisplayName(GlobalOptions.Language))); } foreach (Gear objGear in objCyberware.Gear.DeepWhere(x => x.Children, x => x.TotalAvailTuple(false).Suffix == 'R')) { lstItems.Add(new ListItem(objGear.InternalId, objGear.DisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language))); } } // Armor. foreach (Armor objArmor in _objCharacter.Armor) { if (objArmor.TotalAvailTuple(false).Suffix == 'R') { lstItems.Add(new ListItem(objArmor.InternalId, objArmor.DisplayName(GlobalOptions.Language))); } foreach (ArmorMod objMod in objArmor.ArmorMods) { if (objMod.TotalAvailTuple(false).Suffix == 'R') { lstItems.Add(new ListItem(objMod.InternalId, objMod.DisplayName(GlobalOptions.Language))); } foreach (Gear objGear in objMod.Gear.DeepWhere(x => x.Children, x => x.TotalAvailTuple(false).Suffix == 'R')) { lstItems.Add(new ListItem(objGear.InternalId, objGear.DisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language))); } } foreach (Gear objGear in objArmor.Gear.DeepWhere(x => x.Children, x => x.TotalAvailTuple(false).Suffix == 'R')) { lstItems.Add(new ListItem(objGear.InternalId, objGear.DisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language))); } } // Weapons. foreach (Weapon objWeapon in _objCharacter.Weapons.GetAllDescendants(x => x.Children)) { if (objWeapon.TotalAvailTuple(false).Suffix == 'R') { lstItems.Add(new ListItem(objWeapon.InternalId, objWeapon.DisplayName(GlobalOptions.Language))); } foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories) { if (!objAccessory.IncludedInWeapon && objAccessory.TotalAvailTuple(false).Suffix == 'R') { lstItems.Add(new ListItem(objAccessory.InternalId, objAccessory.DisplayName(GlobalOptions.Language))); } foreach (Gear objGear in objAccessory.Gear.DeepWhere(x => x.Children, x => x.TotalAvailTuple(false).Suffix == 'R')) { lstItems.Add(new ListItem(objGear.InternalId, objGear.DisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language))); } } } // Gear. foreach (Gear objGear in _objCharacter.Gear.DeepWhere(x => x.Children, x => x.TotalAvailTuple(false).Suffix == 'R')) { lstItems.Add(new ListItem(objGear.InternalId, objGear.DisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language))); } // Vehicles. foreach (Vehicle objVehicle in _objCharacter.Vehicles) { if (objVehicle.TotalAvailTuple(false).Suffix == 'R') { lstItems.Add(new ListItem(objVehicle.InternalId, objVehicle.DisplayName(GlobalOptions.Language))); } foreach (VehicleMod objMod in objVehicle.Mods) { if (!objMod.IncludedInVehicle && objMod.TotalAvailTuple(false).Suffix == 'R') { lstItems.Add(new ListItem(objMod.InternalId, objMod.DisplayName(GlobalOptions.Language))); } foreach (Weapon objWeapon in objMod.Weapons.GetAllDescendants(x => x.Children)) { if (objWeapon.TotalAvailTuple(false).Suffix == 'R') { lstItems.Add(new ListItem(objWeapon.InternalId, objWeapon.DisplayName(GlobalOptions.Language))); } foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories) { if (!objAccessory.IncludedInWeapon && objAccessory.TotalAvailTuple(false).Suffix == 'R') { lstItems.Add(new ListItem(objAccessory.InternalId, objAccessory.DisplayName(GlobalOptions.Language))); } foreach (Gear objGear in objAccessory.Gear.DeepWhere(x => x.Children, x => x.TotalAvailTuple(false).Suffix == 'R')) { lstItems.Add(new ListItem(objGear.InternalId, objGear.DisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language))); } } } } foreach (WeaponMount objWeaponMount in objVehicle.WeaponMounts) { if (!objWeaponMount.IncludedInVehicle && objWeaponMount.TotalAvailTuple(false).Suffix == 'R') { lstItems.Add(new ListItem(objWeaponMount.InternalId, objWeaponMount.DisplayName(GlobalOptions.Language))); } foreach (Weapon objWeapon in objWeaponMount.Weapons.GetAllDescendants(x => x.Children)) { if (objWeapon.TotalAvailTuple(false).Suffix == 'R') { lstItems.Add(new ListItem(objWeapon.InternalId, objWeapon.DisplayName(GlobalOptions.Language))); } foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories) { if (!objAccessory.IncludedInWeapon && objAccessory.TotalAvailTuple(false).Suffix == 'R') { lstItems.Add(new ListItem(objAccessory.InternalId, objAccessory.DisplayName(GlobalOptions.Language))); } foreach (Gear objGear in objAccessory.Gear.DeepWhere(x => x.Children, x => x.TotalAvailTuple(false).Suffix == 'R')) { lstItems.Add(new ListItem(objGear.InternalId, objGear.DisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language))); } } } } foreach (Gear objGear in objVehicle.Gear.DeepWhere(x => x.Children, x => x.TotalAvailTuple(false).Suffix == 'R')) { lstItems.Add(new ListItem(objGear.InternalId, objGear.DisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language))); } } } } // Populate the lists. cboAmmo.BeginUpdate(); cboAmmo.ValueMember = "Value"; cboAmmo.DisplayMember = "Name"; cboAmmo.DataSource = lstItems; // If there's only 1 value in the list, the character doesn't have a choice, so just accept it. if (cboAmmo.Items.Count == 1 && _blnAllowAutoSelect) AcceptForm(); if (!string.IsNullOrEmpty(_strForceItem)) { cboAmmo.SelectedIndex = cboAmmo.FindStringExact(_strForceItem); if (cboAmmo.SelectedIndex != -1) AcceptForm(); } if (!string.IsNullOrEmpty(_strSelectItemOnLoad)) { if (cboAmmo.DropDownStyle == ComboBoxStyle.DropDownList) { string strOldSelected = cboAmmo.SelectedValue?.ToString(); cboAmmo.SelectedValue = _strSelectItemOnLoad; if (cboAmmo.SelectedIndex == -1 && !string.IsNullOrEmpty(strOldSelected)) cboAmmo.SelectedValue = strOldSelected; } else cboAmmo.Text = _strSelectItemOnLoad; } cboAmmo.EndUpdate(); if (cboAmmo.Items.Count < 0) cmdOK.Enabled = false; }
public frmSelectWeaponCategory() { InitializeComponent(); LanguageManager.Load(GlobalOptions.Language, this); _objXmlDocument = XmlManager.Load("weapons.xml"); }
void TestMetatype(string strFile) { XmlDocument objXmlDocument = XmlManager.Load(strFile); pgbProgress.Minimum = 0; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlDocument.SelectNodes("/chummer/metatypes/metatype").Count; foreach (XmlNode objXmlMetatype in objXmlDocument.SelectNodes("/chummer/metatypes/metatype")) { pgbProgress.Value++; Application.DoEvents(); objXmlDocument = XmlManager.Load(strFile); Character objCharacter = new Character(); try { int intForce = 0; if (objXmlMetatype["forcecreature"] != null) { intForce = 1; } // Set Metatype information. if (strFile != "critters.xml" || objXmlMetatype["name"].InnerText == "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.MAGAdept.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)); objCharacter.DEP.AssignLimits(ExpressionToString(objXmlMetatype["depmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["depmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["depaug"].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.MAGAdept.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)); objCharacter.DEP.AssignLimits(ExpressionToString(objXmlMetatype["depmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["depmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["depmin"].InnerText, intForce, 3)); } /* If we're working with a Critter, set the Attributes to their default values. * if (strFile == "critters.xml") * { * _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)); * _objCharacter.DEP.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["depmin"].InnerText, intForce, 0)); * } * * // Sprites can never have Physical Attributes or WIL. * if (objXmlMetatype["name"].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.Metatype = objXmlMetatype["name"].InnerText; * _objCharacter.MetatypeCategory = objXmlMetatype["category"].InnerText; * _objCharacter.Metavariant = string.Empty; * _objCharacter.MetatypeBP = 400; * * 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")) * objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Metatype, objXmlMetatype["name"].InnerText, objXmlMetatype.SelectSingleNode("bonus"), false, 1, objXmlMetatype["name"].InnerText); * * // 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 + "\"]"); * List<Weapon> lstWeapons = new List<Weapon>(); * 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, lstWeapons, strForceValue); * _objCharacter.Qualities.Add(objQuality); * } * foreach (XmlNode objXmlQualityItem in objXmlMetatype.SelectNodes("qualities/negative/quality")) * { * XmlNode objXmlQuality = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQualityItem.InnerText + "\"]"); * List<Weapon> lstWeapons = new List<Weapon>(); * 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, lstWeapons, strForceValue); * _objCharacter.Qualities.Add(objQuality); * } * * /* Run through the character's Attributes one more time and make sure their value matches their minimum value. * if (strFile == "metatypes.xml") * { * _objCharacter.BOD.Value = _objCharacter.BOD.TotalMinimum; * _objCharacter.AGI.Value = _objCharacter.AGI.TotalMinimum; * _objCharacter.REA.Value = _objCharacter.REA.TotalMinimum; * _objCharacter.STR.Value = _objCharacter.STR.TotalMinimum; * _objCharacter.CHA.Value = _objCharacter.CHA.TotalMinimum; * _objCharacter.INT.Value = _objCharacter.INT.TotalMinimum; * _objCharacter.LOG.Value = _objCharacter.LOG.TotalMinimum; * _objCharacter.WIL.Value = _objCharacter.WIL.TotalMinimum; * }*/ // 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 = 0; if (objXmlPower.Attributes["rating"] != null) { intRating = Convert.ToInt32(objXmlPower.Attributes["rating"].InnerText); } objPower.Create(objXmlCritterPower, 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) //{ //SkillSpecialization objSpec = new SkillSpecialization(objXmlSkill.Attributes["spec"].InnerText); //objExotic.Specializations.Add(objSpec); //} //if (Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(intForce), 0)) > 6) // objExotic.RatingMaximum = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(intForce), 0)); //objExotic.Rating = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(intForce), 0)); //objExotic.Name = objXmlSkill.InnerText; //_objCharacter.Skills.Add(objExotic); } else { foreach (Skill objSkill in objCharacter.SkillsSection.Skills) { if (objSkill.Name == objXmlSkill.InnerText) { if (objXmlSkill.Attributes["spec"] != null) { //SkillSpecialization objSpec = new SkillSpecialization(objXmlSkill.Attributes["spec"].InnerText); //objSkill.Specializations.Add(objSpec); } //if (Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(intForce), 0)) > 6) // objSkill.RatingMaximum = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(intForce), 0)); //objSkill.Rating = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(intForce), 0)); break; } } } } //TODO: Sorry, whenever we get critter book... // 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(intForce), 0)); // objSkill.Rating = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(intForce), 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) // { // //SkillSpecialization objSpec = new SkillSpecialization(objXmlSkill.Attributes["spec"].InnerText); // //objKnowledge.Specializations.Add(objSpec); // } // 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.SkillsSection.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. } // Add any Complex Forms the Critter comes with (typically Sprites) XmlDocument objXmlProgramDocument = XmlManager.Load("complexforms.xml"); foreach (XmlNode objXmlComplexForm in objXmlCritter.SelectNodes("complexforms/complexform")) { int intRating = 0; if (objXmlComplexForm.Attributes["rating"] != null) { intRating = ExpressionToInt(objXmlComplexForm.Attributes["rating"].InnerText, intForce, 0); } 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, intForce, 0); } string strForceValue = objXmlGear.Attributes?["select"]?.InnerText ?? string.Empty; XmlNode objXmlGearItem = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlGear.InnerText + "\"]"); Gear objGear = new Gear(objCharacter); List <Weapon> lstWeapons = new List <Weapon>(); objGear.Create(objXmlGearItem, intRating, lstWeapons, strForceValue); objGear.Cost = "0"; objCharacter.Gear.Add(objGear); } } catch { txtOutput.Text += objCharacter.Metatype + " general failure\r\n"; } objCharacter.DeleteCharacter(); } }
/// <summary> /// Print the object's XML to the XmlWriter. /// </summary> /// <param name="objWriter">XmlTextWriter to write with.</param> /// <param name="objCulture">Culture in which to print numbers.</param> /// <param name="strLanguageToPrint">Language in which to print.</param> public void Print(XmlTextWriter objWriter, CultureInfo objCulture, string strLanguageToPrint) { // Translate the Critter name if applicable. string strName = Name; XmlNode objXmlCritterNode = GetNode(strLanguageToPrint); if (strLanguageToPrint != GlobalOptions.DefaultLanguage) { strName = objXmlCritterNode?["translate"]?.InnerText ?? Name; } objWriter.WriteStartElement("spirit"); objWriter.WriteElementString("name", strName); objWriter.WriteElementString("name_english", Name); objWriter.WriteElementString("crittername", CritterName); objWriter.WriteElementString("fettered", Fettered.ToString(GlobalOptions.InvariantCultureInfo)); objWriter.WriteElementString("bound", Bound.ToString(GlobalOptions.InvariantCultureInfo)); objWriter.WriteElementString("services", ServicesOwed.ToString(objCulture)); objWriter.WriteElementString("force", Force.ToString(objCulture)); if (objXmlCritterNode != null) { //Attributes for spirits, named differently as to not confuse <attribtue> Dictionary <string, int> dicAttributes = new Dictionary <string, int>(); objWriter.WriteStartElement("spiritattributes"); foreach (string strAttribute in new[] { "bod", "agi", "rea", "str", "cha", "int", "wil", "log", "ini" }) { string strInner = string.Empty; if (objXmlCritterNode.TryGetStringFieldQuickly(strAttribute, ref strInner)) { object objProcess = CommonFunctions.EvaluateInvariantXPath(strInner.Replace("F", _intForce.ToString()), out bool blnIsSuccess); int intValue = Math.Max(blnIsSuccess ? Convert.ToInt32(objProcess) : _intForce, 1); objWriter.WriteElementString(strAttribute, intValue.ToString(objCulture)); dicAttributes[strAttribute] = intValue; } } objWriter.WriteEndElement(); //Dump skills, (optional)powers if present to output XPathNavigator xmlSpiritPowersBaseChummerNode = XmlManager.Load("spiritpowers.xml", strLanguageToPrint).GetFastNavigator().SelectSingleNode("/chummer"); XPathNavigator xmlCritterPowersBaseChummerNode = XmlManager.Load("critterpowers.xml", strLanguageToPrint).GetFastNavigator().SelectSingleNode("/chummer"); XmlNode xmlPowersNode = objXmlCritterNode["powers"]; if (xmlPowersNode != null) { objWriter.WriteStartElement("powers"); foreach (XmlNode objXmlPowerNode in xmlPowersNode.ChildNodes) { PrintPowerInfo(objWriter, xmlSpiritPowersBaseChummerNode, xmlCritterPowersBaseChummerNode, objXmlPowerNode, GlobalOptions.Language); } objWriter.WriteEndElement(); } xmlPowersNode = objXmlCritterNode["optionalpowers"]; if (xmlPowersNode != null) { objWriter.WriteStartElement("optionalpowers"); foreach (XmlNode objXmlPowerNode in xmlPowersNode.ChildNodes) { PrintPowerInfo(objWriter, xmlSpiritPowersBaseChummerNode, xmlCritterPowersBaseChummerNode, objXmlPowerNode, GlobalOptions.Language); } objWriter.WriteEndElement(); } xmlPowersNode = objXmlCritterNode["skills"]; if (xmlPowersNode != null) { XmlDocument xmlSkillsDocument = XmlManager.Load("skills.xml", strLanguageToPrint); objWriter.WriteStartElement("skills"); foreach (XmlNode xmlSkillNode in xmlPowersNode.ChildNodes) { string strAttrName = xmlSkillNode.Attributes?["attr"]?.Value ?? string.Empty; if (!dicAttributes.TryGetValue(strAttrName, out int intAttrValue)) { intAttrValue = _intForce; } int intDicepool = intAttrValue + _intForce; string strEnglishName = xmlSkillNode.InnerText; string strTranslatedName = xmlSkillsDocument.SelectSingleNode("/chummer/skills/skill[name = \"" + strEnglishName + "\"]/translate")?.InnerText ?? xmlSkillsDocument.SelectSingleNode("/chummer/knowledgeskills/skill[name = \"" + strEnglishName + "\"]/translate")?.InnerText ?? strEnglishName; objWriter.WriteStartElement("skill"); objWriter.WriteElementString("name", strTranslatedName); objWriter.WriteElementString("name_english", strEnglishName); objWriter.WriteElementString("attr", strAttrName); objWriter.WriteElementString("pool", intDicepool.ToString(objCulture)); objWriter.WriteEndElement(); } objWriter.WriteEndElement(); } xmlPowersNode = objXmlCritterNode["weaknesses"]; if (xmlPowersNode != null) { objWriter.WriteStartElement("weaknesses"); foreach (XmlNode objXmlPowerNode in xmlPowersNode.ChildNodes) { PrintPowerInfo(objWriter, xmlSpiritPowersBaseChummerNode, xmlCritterPowersBaseChummerNode, objXmlPowerNode, GlobalOptions.Language); } objWriter.WriteEndElement(); } //Page in book for reference string strSource = string.Empty; string strPage = string.Empty; if (objXmlCritterNode.TryGetStringFieldQuickly("source", ref strSource)) { objWriter.WriteElementString("source", CommonFunctions.LanguageBookShort(strSource, strLanguageToPrint)); } if (objXmlCritterNode.TryGetStringFieldQuickly("altpage", ref strPage) || objXmlCritterNode.TryGetStringFieldQuickly("page", ref strPage)) { objWriter.WriteElementString("page", strPage); } } objWriter.WriteElementString("bound", Bound.ToString()); objWriter.WriteElementString("type", EntityType.ToString()); if (CharacterObject.Options.PrintNotes) { objWriter.WriteElementString("notes", Notes); } PrintMugshots(objWriter); objWriter.WriteEndElement(); }
private void TestWeapons() { Character objCharacter = new Character(); XmlDocument objXmlDocument = XmlManager.Load("weapons.xml"); pgbProgress.Minimum = 0; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlDocument.SelectNodes("/chummer/weapons/weapon").Count; pgbProgress.Maximum += objXmlDocument.SelectNodes("/chummer/accessories/accessory").Count; pgbProgress.Maximum += objXmlDocument.SelectNodes("/chummer/mods/mod").Count; // Weapons. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/weapons/weapon")) { pgbProgress.Value++; Application.DoEvents(); try { Weapon objTemp = new Weapon(objCharacter); objTemp.Create(objXmlGear, null); try { decimal objValue = objTemp.TotalCost; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\r\n"; } try { string objValue = objTemp.TotalAP(GlobalOptions.Language); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAP\r\n"; } try { string objValue = objTemp.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.Language); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\r\n"; } try { string objValue = objTemp.TotalRC; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalRC\r\n"; } try { int objValue = objTemp.TotalReach; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalReach\r\n"; } try { string objValue = objTemp.CalculatedAmmo(GlobalOptions.CultureInfo, GlobalOptions.Language); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedAmmo\r\n"; } try { string objValue = objTemp.CalculatedConcealability(GlobalOptions.CultureInfo); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedConcealability\r\n"; } try { string objValue = objTemp.CalculatedDamage(GlobalOptions.CultureInfo, GlobalOptions.Language); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedDamage\r\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\r\n"; } } // Weapon Accessories. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/accessories/accessory")) { pgbProgress.Value++; Application.DoEvents(); try { WeaponAccessory objTemp = new WeaponAccessory(objCharacter); objTemp.Create(objXmlGear, new Tuple <string, string>(string.Empty, string.Empty), 0); try { decimal objValue = objTemp.TotalCost; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCost\r\n"; } try { string objValue = objTemp.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.Language); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\r\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\r\n"; } } objCharacter.DeleteCharacter(); }
private void TestGear() { Character objCharacter = new Character(); XmlDocument objXmlDocument = XmlManager.Load("gear.xml"); pgbProgress.Minimum = 0; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlDocument.SelectNodes("/chummer/gears/gear").Count; // Gear. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/gears/gear")) { pgbProgress.Value++; Application.DoEvents(); try { Gear objTemp = new Gear(objCharacter); List <Weapon> lstWeapons = new List <Weapon>(); objTemp.Create(objXmlGear, 1, lstWeapons); try { decimal objValue = objTemp.TotalCost; } catch { if (objXmlGear["category"].InnerText != "Mook") { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\r\n"; } } try { string objValue = objTemp.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.Language); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\r\n"; } try { string objValue = objTemp.CalculatedArmorCapacity; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedArmorCapacity\r\n"; } try { string objValue = objTemp.CalculatedCapacity; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCapacity\r\n"; } try { decimal objValue = objTemp.CalculatedCost; } catch { if (objXmlGear["category"].InnerText != "Mook") { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCost\r\n"; } } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\r\n"; } } objCharacter.DeleteCharacter(); }
/// <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(LanguageManager.GetString("Message_UnknownCritterType", GlobalOptions.Language), strCritterName), LanguageManager.GetString("MessageTitle_SelectCritterType", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // The Critter should use the same settings file as the character. 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; } // Ask the user to select a filename for the new character. string strForce = LanguageManager.GetString("String_Force", GlobalOptions.Language); if (_objSpirit.EntityType == SpiritType.Sprite) { strForce = LanguageManager.GetString("String_Rating", GlobalOptions.Language); } string strSpaceCharacter = LanguageManager.GetString("String_Space", GlobalOptions.Language); SaveFileDialog saveFileDialog = new SaveFileDialog { Filter = LanguageManager.GetString("DialogFilter_Chum5", GlobalOptions.Language) + '|' + LanguageManager.GetString("DialogFilter_All", GlobalOptions.Language), FileName = strCritterName + strSpaceCharacter + '(' + strForce + strSpaceCharacter + _objSpirit.Force.ToString() + ").chum5" }; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { string strFileName = saveFileDialog.FileName; objCharacter.FileName = strFileName; } else { objCharacter.DeleteCharacter(); return; } Cursor = Cursors.WaitCursor; // 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")) { 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"), false, 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>(); 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); 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(); 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 = 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>(); 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>(); Weapon objWeapon = new Weapon(objCharacter); objWeapon.Create(objXmlWeapon, lstWeapons); objWeapon.ParentID = Guid.NewGuid().ToString("D"); // 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()) { Cursor = Cursors.Default; objCharacter.DeleteCharacter(); return; } string strOpenFile = objCharacter.FileName; objCharacter.DeleteCharacter(); // Link the newly-created Critter to the Spirit. _objSpirit.FileName = strOpenFile; imgLink.SetToolTip(LanguageManager.GetString(_objSpirit.EntityType == SpiritType.Spirit ? "Tip_Spirit_OpenFile" : "Tip_Sprite_OpenFile", GlobalOptions.Language)); ContactDetailChanged?.Invoke(this, null); Character objOpenCharacter = await Program.MainForm.LoadCharacter(strOpenFile); Cursor = Cursors.Default; Program.MainForm.OpenCharacter(objOpenCharacter); }
public frmSelectSkillGroup() { InitializeComponent(); this.TranslateWinForm(); _objXmlDocument = XmlManager.Load("skills.xml"); }
private void LoadContactList() { if (_blnEnemy) { if (!string.IsNullOrEmpty(_strContactRole)) { cboContactRole.Text = _strContactRole; } return; } if (_objContact.ReadOnly) { chkFree.Enabled = chkGroup.Enabled = nudConnection.Enabled = nudLoyalty.Enabled = false; cmdDelete.Visible = false; } // Read the list of Categories from the XML file. List <ListItem> lstCategories = new List <ListItem>(); List <ListItem> lstMetatypes = new List <ListItem>(); List <ListItem> lstSexes = new List <ListItem>(); List <ListItem> lstAges = new List <ListItem>(); List <ListItem> lstPersonalLives = new List <ListItem>(); List <ListItem> lstTypes = new List <ListItem>(); List <ListItem> lstPreferredPayments = new List <ListItem>(); List <ListItem> lstHobbiesVices = new List <ListItem>(); ListItem objBlank = new ListItem(); objBlank.Value = string.Empty; objBlank.Name = string.Empty; lstCategories.Add(objBlank); lstMetatypes.Add(objBlank); lstSexes.Add(objBlank); lstAges.Add(objBlank); lstPersonalLives.Add(objBlank); lstTypes.Add(objBlank); lstPreferredPayments.Add(objBlank); lstHobbiesVices.Add(objBlank); XmlDocument objXmlDocument = XmlManager.Load("contacts.xml"); XmlNodeList objXmlNodeList = objXmlDocument.SelectNodes("/chummer/contacts/contact"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstCategories.Add(objItem); } } objXmlNodeList = objXmlDocument.SelectNodes("/chummer/sexes/sex"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstSexes.Add(objItem); } } objXmlNodeList = objXmlDocument.SelectNodes("/chummer/ages/age"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstAges.Add(objItem); } } objXmlNodeList = objXmlDocument.SelectNodes("/chummer/personallives/personallife"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstPersonalLives.Add(objItem); } } objXmlNodeList = objXmlDocument.SelectNodes("/chummer/types/type"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstTypes.Add(objItem); } } objXmlNodeList = objXmlDocument.SelectNodes("/chummer/preferredpayments/preferredpayment"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstPreferredPayments.Add(objItem); } } objXmlNodeList = objXmlDocument.SelectNodes("/chummer/hobbiesvices/hobbyvice"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstHobbiesVices.Add(objItem); } } objXmlNodeList = XmlManager.Load("metatypes.xml")?.SelectNodes("/chummer/metatypes/metatype"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode["name"].InnerText; objItem.Name = objXmlNode["translate"]?.InnerText ?? objXmlNode["name"].InnerText; lstMetatypes.Add(objItem); } } SortListItem objContactSort = new SortListItem(); lstCategories.Sort(objContactSort.Compare); lstMetatypes.Sort(objContactSort.Compare); lstSexes.Sort(objContactSort.Compare); lstAges.Sort(objContactSort.Compare); lstPersonalLives.Sort(objContactSort.Compare); lstTypes.Sort(objContactSort.Compare); lstHobbiesVices.Sort(objContactSort.Compare); lstPreferredPayments.Sort(objContactSort.Compare); chkGroup.DataBindings.Add("Checked", _objContact, nameof(_objContact.IsGroup), false, DataSourceUpdateMode.OnPropertyChanged); chkFree.DataBindings.Add("Checked", _objContact, nameof(_objContact.Free), false, DataSourceUpdateMode.OnPropertyChanged); chkFamily.DataBindings.Add("Checked", _objContact, nameof(_objContact.Family), false, DataSourceUpdateMode.OnPropertyChanged); chkBlackmail.DataBindings.Add("Checked", _objContact, nameof(_objContact.Blackmail), false, DataSourceUpdateMode.OnPropertyChanged); lblQuickStats.DataBindings.Add("Text", _objContact, nameof(_objContact.QuickText), false, DataSourceUpdateMode.OnPropertyChanged); nudLoyalty.DataBindings.Add("Value", _objContact, nameof(_objContact.Loyalty), false, DataSourceUpdateMode.OnPropertyChanged); nudLoyalty.DataBindings.Add("Enabled", _objContact, nameof(_objContact.LoyaltyEnabled), false, DataSourceUpdateMode.OnPropertyChanged); nudConnection.DataBindings.Add("Value", _objContact, nameof(_objContact.Connection), false, DataSourceUpdateMode.OnPropertyChanged); nudConnection.DataBindings.Add("Maximum", _objContact, nameof(_objContact.ConnectionMaximum), false, DataSourceUpdateMode.OnPropertyChanged); txtContactName.DataBindings.Add("Text", _objContact, nameof(_objContact.Name), false, DataSourceUpdateMode.OnPropertyChanged); txtContactLocation.DataBindings.Add("Text", _objContact, nameof(_objContact.Location), false, DataSourceUpdateMode.OnPropertyChanged); cboContactRole.BeginUpdate(); cboContactRole.ValueMember = "Value"; cboContactRole.DisplayMember = "Name"; cboContactRole.DataSource = lstCategories; cboContactRole.DataBindings.Add("Text", _objContact, nameof(_objContact.Role), false, DataSourceUpdateMode.OnPropertyChanged); cboContactRole.EndUpdate(); cboMetatype.BeginUpdate(); cboMetatype.ValueMember = "Value"; cboMetatype.DisplayMember = "Name"; cboMetatype.DataSource = lstMetatypes; cboMetatype.DataBindings.Add("Text", _objContact, nameof(_objContact.Metatype), false, DataSourceUpdateMode.OnPropertyChanged); cboMetatype.EndUpdate(); cboSex.BeginUpdate(); cboSex.ValueMember = "Value"; cboSex.DisplayMember = "Name"; cboSex.DataSource = lstSexes; cboSex.DataBindings.Add("Text", _objContact, nameof(_objContact.Sex), false, DataSourceUpdateMode.OnPropertyChanged); cboSex.EndUpdate(); cboAge.BeginUpdate(); cboAge.ValueMember = "Value"; cboAge.DisplayMember = "Name"; cboAge.DataSource = lstAges; cboAge.DataBindings.Add("Text", _objContact, nameof(_objContact.Age), false, DataSourceUpdateMode.OnPropertyChanged); cboAge.EndUpdate(); cboPersonalLife.BeginUpdate(); cboPersonalLife.ValueMember = "Value"; cboPersonalLife.DisplayMember = "Name"; cboPersonalLife.DataSource = lstPersonalLives; cboPersonalLife.DataBindings.Add("Text", _objContact, nameof(_objContact.PersonalLife), false, DataSourceUpdateMode.OnPropertyChanged); cboPersonalLife.EndUpdate(); cboType.BeginUpdate(); cboType.ValueMember = "Value"; cboType.DisplayMember = "Name"; cboType.DataSource = lstTypes; cboType.DataBindings.Add("Text", _objContact, nameof(_objContact.Type), false, DataSourceUpdateMode.OnPropertyChanged); cboType.EndUpdate(); cboPreferredPayment.BeginUpdate(); cboPreferredPayment.ValueMember = "Value"; cboPreferredPayment.DisplayMember = "Name"; cboPreferredPayment.DataSource = lstPreferredPayments; cboPreferredPayment.DataBindings.Add("Text", _objContact, nameof(_objContact.PreferredPayment), false, DataSourceUpdateMode.OnPropertyChanged); cboPreferredPayment.EndUpdate(); cboHobbiesVice.BeginUpdate(); cboHobbiesVice.ValueMember = "Value"; cboHobbiesVice.DisplayMember = "Name"; cboHobbiesVice.DataSource = lstHobbiesVices; cboHobbiesVice.DataBindings.Add("Text", _objContact, nameof(_objContact.HobbiesVice), false, DataSourceUpdateMode.OnPropertyChanged); cboHobbiesVice.EndUpdate(); _loading = false; }
// Rebuild the list of Spirits/Sprites based on the character's selected Tradition/Stream. public void RebuildSpiritList(Tradition objTradition) { if (objTradition == null) { return; } string strCurrentValue = cboSpiritName.SelectedValue?.ToString() ?? _objSpirit.Name; XmlDocument objXmlDocument = _objSpirit.EntityType == SpiritType.Spirit ? XmlManager.Load("traditions.xml") : XmlManager.Load("streams.xml"); XmlDocument objXmlCritterDocument = XmlManager.Load("critters.xml"); HashSet <string> lstLimitCategories = new HashSet <string>(); foreach (Improvement improvement in _objSpirit.CharacterObject.Improvements.Where(x => x.ImproveType == Improvement.ImprovementType.LimitSpiritCategory && x.Enabled)) { lstLimitCategories.Add(improvement.ImprovedName); } List <ListItem> lstCritters = new List <ListItem>(); if (objTradition.IsCustomTradition) { string strSpiritCombat = objTradition.SpiritCombat; string strSpiritDetection = objTradition.SpiritDetection; string strSpiritHealth = objTradition.SpiritHealth; string strSpiritIllusion = objTradition.SpiritIllusion; string strSpiritManipulation = objTradition.SpiritManipulation; if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritCombat)) && !string.IsNullOrWhiteSpace(strSpiritCombat)) { XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritCombat + "\"]"); lstCritters.Add(new ListItem(strSpiritCombat, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritCombat)); } if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritDetection)) && !string.IsNullOrWhiteSpace(strSpiritDetection)) { XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritDetection + "\"]"); lstCritters.Add(new ListItem(strSpiritDetection, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritDetection)); } if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritHealth)) && !string.IsNullOrWhiteSpace(strSpiritHealth)) { XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritHealth + "\"]"); lstCritters.Add(new ListItem(strSpiritHealth, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritHealth)); } if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritIllusion)) && !string.IsNullOrWhiteSpace(strSpiritIllusion)) { XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritIllusion + "\"]"); lstCritters.Add(new ListItem(strSpiritIllusion, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritIllusion)); } if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritManipulation)) && !string.IsNullOrWhiteSpace(strSpiritManipulation)) { XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritManipulation + "\"]"); lstCritters.Add(new ListItem(strSpiritManipulation, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritManipulation)); } } else { if (objTradition.GetNode()?.SelectSingleNode("spirits/spirit[. = \"All\"]") != null) { if (lstLimitCategories.Count == 0) { using (XmlNodeList xmlSpiritList = objXmlDocument.SelectNodes("/chummer/spirits/spirit")) if (xmlSpiritList != null) { foreach (XmlNode objXmlCritterNode in xmlSpiritList) { string strSpiritName = objXmlCritterNode["name"]?.InnerText; lstCritters.Add(new ListItem(strSpiritName, objXmlCritterNode["translate"]?.InnerText ?? strSpiritName)); } } } else { foreach (string strSpiritName in lstLimitCategories) { XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritName + "\"]"); lstCritters.Add(new ListItem(strSpiritName, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritName)); } } } else { using (XmlNodeList xmlSpiritList = objTradition.GetNode()?.SelectSingleNode("spirits")?.ChildNodes) if (xmlSpiritList != null) { foreach (XmlNode objXmlSpirit in xmlSpiritList) { string strSpiritName = objXmlSpirit.InnerText; if (lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritName)) { XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritName + "\"]"); lstCritters.Add(new ListItem(strSpiritName, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritName)); } } } } } if (_objSpirit.CharacterObject.RESEnabled) { // Add any additional Sprites the character has Access to through improvements. lstCritters.AddRange(from objImprovement in _objSpirit.CharacterObject.Improvements .Where(imp => imp.ImproveType == Improvement.ImprovementType.AddSprite && imp.Enabled) let objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + objImprovement.ImprovedName + "\"]") select new ListItem(objImprovement.ImprovedName, objXmlCritterNode?["translate"]?.InnerText ?? objImprovement.ImprovedName)); } if (_objSpirit.CharacterObject.MAGEnabled) { // Add any additional Spirits the character has Access to through improvements. lstCritters.AddRange(from objImprovement in _objSpirit.CharacterObject.Improvements .Where(imp => imp.ImproveType == Improvement.ImprovementType.AddSpirit && imp.Enabled) let objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + objImprovement.ImprovedName + "\"]") select new ListItem(objImprovement.ImprovedName, objXmlCritterNode?["translate"]?.InnerText ?? objImprovement.ImprovedName)); } cboSpiritName.BeginUpdate(); cboSpiritName.DisplayMember = "Name"; cboSpiritName.ValueMember = "Value"; cboSpiritName.DataSource = lstCritters; // Set the control back to its original value. cboSpiritName.SelectedValue = strCurrentValue; cboSpiritName.EndUpdate(); }
/// <summary> /// Update the Program List based on a base program node list. /// </summary> private void UpdateProgramList(XmlNodeList objXmlNodeList) { List <ListItem> lstPrograms = new List <ListItem>(); bool blnCheckForOptional = false; XmlNode objXmlCritter = null; XmlDocument objXmlCritterDocument = null; if (_objCharacter.IsCritter) { objXmlCritterDocument = XmlManager.Load("critters.xml"); objXmlCritter = objXmlCritterDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + _objCharacter.Metatype + "\"]"); if (objXmlCritter.InnerXml.Contains("<optionalaiprograms>")) { blnCheckForOptional = true; } } foreach (XmlNode objXmlProgram in objXmlNodeList) { bool blnAdd = true; if (chkLimitList.Checked && objXmlProgram["require"] != null) { blnAdd = false; foreach (AIProgram objAIProgram in _objCharacter.AIPrograms) { if (objAIProgram.Name == objXmlProgram["require"].InnerText) { blnAdd = true; break; } } if (!blnAdd) { continue; } } // If this is a critter with Optional Programs, see if this Program is allowed. if (blnCheckForOptional) { blnAdd = false; foreach (XmlNode objXmlForm in objXmlCritter.SelectNodes("optionalaiprograms/program")) { if (objXmlForm.InnerText == objXmlProgram["name"].InnerText) { blnAdd = true; break; } } if (!blnAdd) { continue; } } string strDisplayName = objXmlProgram["translate"]?.InnerText ?? objXmlProgram["name"].InnerText; if (!_objCharacter.Options.SearchInCategoryOnly && txtSearch.TextLength != 0) { string strCategory = objXmlProgram["category"]?.InnerText; if (!string.IsNullOrEmpty(strCategory)) { ListItem objFoundItem = _lstCategory.Find(objFind => objFind.Value == strCategory); if (!string.IsNullOrEmpty(objFoundItem.Name)) { strDisplayName += " [" + objFoundItem.Name + "]"; } } } lstPrograms.Add(new ListItem(objXmlProgram["id"].InnerText, strDisplayName)); } lstPrograms.Sort(CompareListItems.CompareNames); lstAIPrograms.BeginUpdate(); lstAIPrograms.DataSource = null; lstAIPrograms.ValueMember = "Value"; lstAIPrograms.DisplayMember = "Name"; lstAIPrograms.DataSource = lstPrograms; lstAIPrograms.EndUpdate(); }
/// <summary> /// Attempt to translate any Extra text for an item. /// </summary> /// <param name="strExtra">Extra string to translate.</param> public static string TranslateExtra(string strExtra) { string strReturn = string.Empty; // Only attempt to translate if we're not using English. Don't attempt to translate an empty string either. if (_strLanguage != GlobalOptions.DefaultLanguage && !string.IsNullOrWhiteSpace(strExtra)) { // Attempt to translate CharacterAttribute names. switch (strExtra) { case "BOD": strReturn = GetString("String_AttributeBODShort"); break; case "AGI": strReturn = GetString("String_AttributeAGIShort"); break; case "REA": strReturn = GetString("String_AttributeREAShort"); break; case "STR": strReturn = GetString("String_AttributeSTRShort"); break; case "CHA": strReturn = GetString("String_AttributeCHAShort"); break; case "INT": strReturn = GetString("String_AttributeINTShort"); break; case "LOG": strReturn = GetString("String_AttributeLOGShort"); break; case "WIL": strReturn = GetString("String_AttributeWILShort"); break; case "EDG": strReturn = GetString("String_AttributeEDGShort"); break; case "MAG": strReturn = GetString("String_AttributeMAGShort"); break; case "MAGAdept": strReturn = GetString("String_AttributeMAGShort") + " (" + GetString("String_DescAdept") + ")"; break; case "RES": strReturn = GetString("String_AttributeRESShort"); break; case "DEP": strReturn = GetString("String_AttributeDEPShort"); break; case "Physical": strReturn = GetString("Node_Physical"); break; case "Mental": strReturn = GetString("Node_Mental"); break; case "Social": strReturn = GetString("Node_Social"); break; case "Left": strReturn = GetString("String_Improvement_SideLeft"); break; case "Right": strReturn = GetString("String_Improvement_SideRight"); break; default: string strExtraNoQuotes = strExtra.FastEscape('\"'); object strReturnLock = new object(); Parallel.For(0, lstXPathsToSearch.Length, (i, state) => { Tuple <string, string, Func <XmlNode, string>, Func <XmlNode, string> > objXPathPair = lstXPathsToSearch[i]; foreach (XmlNode objNode in XmlManager.Load(objXPathPair.Item1).SelectNodes(objXPathPair.Item2)) { if (objXPathPair.Item3(objNode) == strExtraNoQuotes) { string strTranslate = objXPathPair.Item4(objNode); if (!string.IsNullOrEmpty(strTranslate)) { lock (strReturnLock) strReturn = strTranslate; state.Stop(); break; } } } }); break; } } // If no translation could be found, just use whatever we were passed. if (string.IsNullOrEmpty(strReturn) || strReturn.Contains("Error finding string for key - ")) { strReturn = strExtra; } return(strReturn); }
/// <summary> /// Update the labels and images based on the selected treenode. /// </summary> /// <param name="objCache"></param> private void UpdateCharacter(CharacterCache objCache) { if(objCache != null) { string strUnknown = LanguageManager.GetString("String_Unknown", GlobalOptions.Language); string strNone = LanguageManager.GetString("String_None", GlobalOptions.Language); txtCharacterBio.Text = objCache.Description; txtCharacterBackground.Text = objCache.Background; txtCharacterNotes.Text = objCache.CharacterNotes; txtGameNotes.Text = objCache.GameNotes; txtCharacterConcept.Text = objCache.Concept; lblCareerKarma.Text = objCache.Karma; if(string.IsNullOrEmpty(lblCareerKarma.Text) || lblCareerKarma.Text == "0") lblCareerKarma.Text = strNone; lblPlayerName.Text = objCache.PlayerName; if(string.IsNullOrEmpty(lblPlayerName.Text)) lblPlayerName.Text = strUnknown; lblCharacterName.Text = objCache.CharacterName; if(string.IsNullOrEmpty(lblCharacterName.Text)) lblCharacterName.Text = strUnknown; lblCharacterAlias.Text = objCache.CharacterAlias; if(string.IsNullOrEmpty(lblCharacterAlias.Text)) lblCharacterAlias.Text = strUnknown; lblEssence.Text = objCache.Essence; if(string.IsNullOrEmpty(lblEssence.Text)) lblEssence.Text = strUnknown; lblFilePath.Text = objCache.FileName; if(string.IsNullOrEmpty(lblFilePath.Text)) lblFilePath.Text = LanguageManager.GetString("MessageTitle_FileNotFound", GlobalOptions.Language); lblSettings.Text = objCache.SettingsFile; if(string.IsNullOrEmpty(lblSettings.Text)) lblSettings.Text = strUnknown; lblFilePath.SetToolTip(objCache.FilePath.CheapReplace(Utils.GetStartupPath, () => '<' + Application.ProductName + '>')); picMugshot.Image = objCache.Mugshot; // Populate character information fields. XmlDocument objMetatypeDoc = XmlManager.Load("metatypes.xml"); if (objCache.Metatype != null) { XmlNode objMetatypeNode = objMetatypeDoc.SelectSingleNode("/chummer/metatypes/metatype[name = " + objCache.Metatype?.CleanXPath() + "]"); if (objMetatypeNode == null) { objMetatypeDoc = XmlManager.Load("critters.xml"); objMetatypeNode = objMetatypeDoc.SelectSingleNode("/chummer/metatypes/metatype[name = " + objCache.Metatype?.CleanXPath() + "]"); } string strMetatype = objMetatypeNode?["translate"]?.InnerText ?? objCache.Metatype; if (!string.IsNullOrEmpty(objCache.Metavariant) && objCache.Metavariant != "None") { objMetatypeNode = objMetatypeNode?.SelectSingleNode("metavariants/metavariant[name = " + objCache.Metavariant.CleanXPath() + "]"); strMetatype += LanguageManager.GetString("String_Space", GlobalOptions.Language) + '(' + (objMetatypeNode?["translate"]?.InnerText ?? objCache.Metavariant) + ')'; } lblMetatype.Text = strMetatype; } else lblMetatype.Text = "Error loading metatype!"; tabCharacterText.Visible = true; if (!String.IsNullOrEmpty(objCache.ErrorText)) { txtCharacterBio.Text = objCache.ErrorText; txtCharacterBio.ForeColor = Color.Red; txtCharacterBio.BringToFront(); } } else { tabCharacterText.Visible = false; txtCharacterBio.Text = string.Empty; txtCharacterBackground.Text = string.Empty; txtCharacterNotes.Text = string.Empty; txtGameNotes.Text = string.Empty; txtCharacterConcept.Text = string.Empty; lblCareerKarma.Text = string.Empty; lblMetatype.Text = string.Empty; lblPlayerName.Text = string.Empty; lblCharacterName.Text = string.Empty; lblCharacterAlias.Text = string.Empty; lblEssence.Text = string.Empty; lblFilePath.Text = string.Empty; lblFilePath.SetToolTip(string.Empty); lblSettings.Text = string.Empty; picMugshot.Image = null; } lblCareerKarmaLabel.Visible = !string.IsNullOrEmpty(lblCareerKarma.Text); lblMetatypeLabel.Visible = !string.IsNullOrEmpty(lblMetatype.Text); lblPlayerNameLabel.Visible = !string.IsNullOrEmpty(lblPlayerName.Text); lblCharacterNameLabel.Visible = !string.IsNullOrEmpty(lblCharacterName.Text); lblCharacterAliasLabel.Visible = !string.IsNullOrEmpty(lblCharacterAlias.Text); lblEssenceLabel.Visible = !string.IsNullOrEmpty(lblEssence.Text); lblFilePathLabel.Visible = !string.IsNullOrEmpty(lblFilePath.Text); lblSettingsLabel.Visible = !string.IsNullOrEmpty(lblSettings.Text); ProcessMugshotSizeMode(); }
private void LoadContactList() { if (_blnEnemy) { if (!string.IsNullOrEmpty(_strContactRole)) { cboContactRole.Text = _strContactRole; } return; } if (_objContact.ReadOnly) { chkFree.Enabled = chkGroup.Enabled = nudConnection.Enabled = nudLoyalty.Enabled = false; cmdDelete.Visible = false; } // Read the list of Categories from the XML file. List <ListItem> lstCategories = new List <ListItem>(); List <ListItem> lstMetatypes = new List <ListItem>(); List <ListItem> lstSexes = new List <ListItem>(); List <ListItem> lstAges = new List <ListItem>(); List <ListItem> lstPersonalLives = new List <ListItem>(); List <ListItem> lstTypes = new List <ListItem>(); List <ListItem> lstPreferredPayments = new List <ListItem>(); List <ListItem> lstHobbiesVices = new List <ListItem>(); ListItem objBlank = new ListItem(); objBlank.Value = string.Empty; objBlank.Name = string.Empty; lstCategories.Add(objBlank); lstMetatypes.Add(objBlank); lstSexes.Add(objBlank); lstAges.Add(objBlank); lstPersonalLives.Add(objBlank); lstTypes.Add(objBlank); lstPreferredPayments.Add(objBlank); lstHobbiesVices.Add(objBlank); XmlDocument objXmlDocument = XmlManager.Load("contacts.xml"); XmlNodeList objXmlNodeList = objXmlDocument.SelectNodes("/chummer/contacts/contact"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstCategories.Add(objItem); } } objXmlNodeList = objXmlDocument.SelectNodes("/chummer/sexes/sex"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstSexes.Add(objItem); } } objXmlNodeList = objXmlDocument.SelectNodes("/chummer/ages/age"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstAges.Add(objItem); } } objXmlNodeList = objXmlDocument.SelectNodes("/chummer/personallives/personallife"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstPersonalLives.Add(objItem); } } objXmlNodeList = objXmlDocument.SelectNodes("/chummer/types/type"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstTypes.Add(objItem); } } objXmlNodeList = objXmlDocument.SelectNodes("/chummer/preferredpayments/preferredpayment"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstPreferredPayments.Add(objItem); } } objXmlNodeList = objXmlDocument.SelectNodes("/chummer/hobbiesvices/hobbyvice"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode.InnerText; objItem.Name = objXmlNode.Attributes?["translate"]?.InnerText ?? objXmlNode.InnerText; lstHobbiesVices.Add(objItem); } } objXmlNodeList = XmlManager.Load("metatypes.xml")?.SelectNodes("/chummer/metatypes/metatype"); if (objXmlNodeList != null) { foreach (XmlNode objXmlNode in objXmlNodeList) { ListItem objItem = new ListItem(); objItem.Value = objXmlNode["name"].InnerText; objItem.Name = objXmlNode["translate"]?.InnerText ?? objXmlNode["name"].InnerText; lstMetatypes.Add(objItem); } } SortListItem objContactSort = new SortListItem(); lstCategories.Sort(objContactSort.Compare); lstMetatypes.Sort(objContactSort.Compare); lstSexes.Sort(objContactSort.Compare); lstAges.Sort(objContactSort.Compare); lstPersonalLives.Sort(objContactSort.Compare); lstTypes.Sort(objContactSort.Compare); lstHobbiesVices.Sort(objContactSort.Compare); lstPreferredPayments.Sort(objContactSort.Compare); cboContactRole.BeginUpdate(); cboContactRole.ValueMember = "Value"; cboContactRole.DisplayMember = "Name"; cboContactRole.DataSource = lstCategories; cboContactRole.EndUpdate(); cboMetatype.BeginUpdate(); cboMetatype.ValueMember = "Value"; cboMetatype.DisplayMember = "Name"; cboMetatype.DataSource = lstMetatypes; cboMetatype.EndUpdate(); cboSex.BeginUpdate(); cboSex.ValueMember = "Value"; cboSex.DisplayMember = "Name"; cboSex.DataSource = lstSexes; cboSex.EndUpdate(); cboAge.BeginUpdate(); cboAge.ValueMember = "Value"; cboAge.DisplayMember = "Name"; cboAge.DataSource = lstAges; cboAge.EndUpdate(); cboPersonalLife.BeginUpdate(); cboPersonalLife.ValueMember = "Value"; cboPersonalLife.DisplayMember = "Name"; cboPersonalLife.DataSource = lstPersonalLives; cboPersonalLife.EndUpdate(); cboType.BeginUpdate(); cboType.ValueMember = "Value"; cboType.DisplayMember = "Name"; cboType.DataSource = lstTypes; cboType.EndUpdate(); cboPreferredPayment.BeginUpdate(); cboPreferredPayment.ValueMember = "Value"; cboPreferredPayment.DisplayMember = "Name"; cboPreferredPayment.DataSource = lstPreferredPayments; cboPreferredPayment.EndUpdate(); cboHobbiesVice.BeginUpdate(); cboHobbiesVice.ValueMember = "Value"; cboHobbiesVice.DisplayMember = "Name"; cboHobbiesVice.DataSource = lstHobbiesVices; cboHobbiesVice.EndUpdate(); }
/// <summary> /// Update the labels and images based on the selected treenode. /// </summary> /// <param name="objCache"></param> private void UpdateCharacter(HeroLabCharacterCache objCache) { if (objCache != null) { txtCharacterBio.Text = objCache.Description; string strUnknown = LanguageManager.GetString("String_Unknown"); string strNone = LanguageManager.GetString("String_None"); lblCharacterName.Text = objCache.CharacterName; if (string.IsNullOrEmpty(lblCharacterName.Text)) { lblCharacterName.Text = strUnknown; } lblCharacterNameLabel.Visible = !string.IsNullOrEmpty(lblCharacterName.Text); lblCharacterName.Visible = !string.IsNullOrEmpty(lblCharacterName.Text); lblCharacterAlias.Text = objCache.CharacterAlias; if (string.IsNullOrEmpty(lblCharacterAlias.Text)) { lblCharacterAlias.Text = strUnknown; } lblCharacterAliasLabel.Visible = !string.IsNullOrEmpty(lblCharacterAlias.Text); lblCharacterAlias.Visible = !string.IsNullOrEmpty(lblCharacterAlias.Text); lblPlayerName.Text = objCache.PlayerName; if (string.IsNullOrEmpty(lblPlayerName.Text)) { lblPlayerName.Text = strUnknown; } lblPlayerNameLabel.Visible = !string.IsNullOrEmpty(lblPlayerName.Text); lblPlayerName.Visible = !string.IsNullOrEmpty(lblPlayerName.Text); lblCareerKarma.Text = objCache.Karma; if (string.IsNullOrEmpty(lblCareerKarma.Text) || lblCareerKarma.Text == 0.ToString(GlobalOptions.CultureInfo)) { lblCareerKarma.Text = strNone; } lblCareerKarmaLabel.Visible = !string.IsNullOrEmpty(lblCareerKarma.Text); lblCareerKarma.Visible = !string.IsNullOrEmpty(lblCareerKarma.Text); lblEssence.Text = objCache.Essence; if (string.IsNullOrEmpty(lblEssence.Text)) { lblEssence.Text = strUnknown; } lblEssenceLabel.Visible = !string.IsNullOrEmpty(lblEssence.Text); lblEssence.Visible = !string.IsNullOrEmpty(lblEssence.Text); picMugshot.Image = objCache.Mugshot; // Populate character information fields. XmlDocument objMetatypeDoc = XmlManager.Load("metatypes.xml"); XmlNode objMetatypeNode = objMetatypeDoc.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + objCache.Metatype + "\"]"); if (objMetatypeNode == null) { objMetatypeDoc = XmlManager.Load("critters.xml"); objMetatypeNode = objMetatypeDoc.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + objCache.Metatype + "\"]"); } string strMetatype = objMetatypeNode?["translate"]?.InnerText ?? objCache.Metatype; if (!string.IsNullOrEmpty(objCache.Metavariant) && objCache.Metavariant != "None") { objMetatypeNode = objMetatypeNode?.SelectSingleNode("metavariants/metavariant[name = \"" + objCache.Metavariant + "\"]"); strMetatype += " (" + (objMetatypeNode?["translate"]?.InnerText ?? objCache.Metavariant) + ')'; } lblMetatype.Text = strMetatype; if (string.IsNullOrEmpty(lblMetatype.Text)) { lblMetatype.Text = strUnknown; } lblMetatypeLabel.Visible = !string.IsNullOrEmpty(lblMetatype.Text); lblMetatype.Visible = !string.IsNullOrEmpty(lblMetatype.Text); cmdImport.Enabled = true; } else { txtCharacterBio.Text = string.Empty; lblCharacterNameLabel.Visible = false; lblCharacterName.Visible = false; lblCharacterAliasLabel.Visible = false; lblCharacterAlias.Visible = false; lblPlayerNameLabel.Visible = false; lblPlayerName.Visible = false; lblMetatypeLabel.Visible = false; lblMetatype.Visible = false; lblCareerKarmaLabel.Visible = false; lblCareerKarma.Visible = false; lblEssenceLabel.Visible = false; lblEssence.Visible = false; picMugshot.Image = null; cmdImport.Enabled = false; } picMugshot_SizeChanged(null, EventArgs.Empty); }
/// <summary> /// Update the labels and images based on the selected treenode. /// </summary> /// <param name="objCache"></param> public void UpdateCharacter(CharacterCache objCache) { if (IsDisposed) // Safety check for external calls { return; } if (objCache != null) { string strUnknown = LanguageManager.GetString("String_Unknown"); string strNone = LanguageManager.GetString("String_None"); txtCharacterBio.Text = objCache.Description.RtfToPlainText(); txtCharacterBackground.Text = objCache.Background.RtfToPlainText(); txtCharacterNotes.Text = objCache.CharacterNotes.RtfToPlainText(); txtGameNotes.Text = objCache.GameNotes.RtfToPlainText(); txtCharacterConcept.Text = objCache.Concept.RtfToPlainText(); lblCareerKarma.Text = objCache.Karma; if (string.IsNullOrEmpty(lblCareerKarma.Text) || lblCareerKarma.Text == 0.ToString(GlobalOptions.CultureInfo)) { lblCareerKarma.Text = strNone; } lblPlayerName.Text = objCache.PlayerName; if (string.IsNullOrEmpty(lblPlayerName.Text)) { lblPlayerName.Text = strUnknown; } lblCharacterName.Text = objCache.CharacterName; if (string.IsNullOrEmpty(lblCharacterName.Text)) { lblCharacterName.Text = strUnknown; } lblCharacterAlias.Text = objCache.CharacterAlias; if (string.IsNullOrEmpty(lblCharacterAlias.Text)) { lblCharacterAlias.Text = strUnknown; } lblEssence.Text = objCache.Essence; if (string.IsNullOrEmpty(lblEssence.Text)) { lblEssence.Text = strUnknown; } lblFilePath.Text = objCache.FileName; if (string.IsNullOrEmpty(lblFilePath.Text)) { lblFilePath.Text = LanguageManager.GetString("MessageTitle_FileNotFound"); } lblSettings.Text = objCache.SettingsFile; if (string.IsNullOrEmpty(lblSettings.Text)) { lblSettings.Text = strUnknown; } lblFilePath.SetToolTip(objCache.FilePath.CheapReplace(Utils.GetStartupPath, () => '<' + Application.ProductName + '>')); picMugshot.Image?.Dispose(); picMugshot.Image = objCache.Mugshot; // Populate character information fields. XmlDocument objMetatypeDoc = XmlManager.Load("metatypes.xml"); if (objCache.Metatype != null) { XmlNode objMetatypeNode = objMetatypeDoc.SelectSingleNode("/chummer/metatypes/metatype[name = " + objCache.Metatype?.CleanXPath() + "]"); if (objMetatypeNode == null) { objMetatypeDoc = XmlManager.Load("critters.xml"); objMetatypeNode = objMetatypeDoc.SelectSingleNode("/chummer/metatypes/metatype[name = " + objCache.Metatype?.CleanXPath() + "]"); } StringBuilder sbdMetatype = new StringBuilder(objMetatypeNode?["translate"]?.InnerText ?? objCache.Metatype); if (!string.IsNullOrEmpty(objCache.Metavariant) && objCache.Metavariant != "None") { objMetatypeNode = objMetatypeNode?.SelectSingleNode("metavariants/metavariant[name = " + objCache.Metavariant.CleanXPath() + "]"); sbdMetatype.Append(LanguageManager.GetString("String_Space")).Append('(').Append(objMetatypeNode?["translate"]?.InnerText ?? objCache.Metavariant).Append(')'); } lblMetatype.Text = sbdMetatype.ToString(); } else { lblMetatype.Text = LanguageManager.GetString("String_MetatypeLoadError"); } tabCharacterText.Visible = true; if (!string.IsNullOrEmpty(objCache.ErrorText)) { txtCharacterBio.Text = objCache.ErrorText; txtCharacterBio.ForeColor = ColorManager.ErrorColor; txtCharacterBio.BringToFront(); } else { txtCharacterBio.ForeColor = ColorManager.WindowText; } } else { tabCharacterText.Visible = false; txtCharacterBio.Clear(); txtCharacterBackground.Clear(); txtCharacterNotes.Clear(); txtGameNotes.Clear(); txtCharacterConcept.Clear(); lblCareerKarma.Text = string.Empty; lblMetatype.Text = string.Empty; lblPlayerName.Text = string.Empty; lblCharacterName.Text = string.Empty; lblCharacterAlias.Text = string.Empty; lblEssence.Text = string.Empty; lblFilePath.Text = string.Empty; lblFilePath.SetToolTip(string.Empty); lblSettings.Text = string.Empty; picMugshot.Image = null; } lblCareerKarmaLabel.Visible = !string.IsNullOrEmpty(lblCareerKarma.Text); lblMetatypeLabel.Visible = !string.IsNullOrEmpty(lblMetatype.Text); lblPlayerNameLabel.Visible = !string.IsNullOrEmpty(lblPlayerName.Text); lblCharacterNameLabel.Visible = !string.IsNullOrEmpty(lblCharacterName.Text); lblCharacterAliasLabel.Visible = !string.IsNullOrEmpty(lblCharacterAlias.Text); lblEssenceLabel.Visible = !string.IsNullOrEmpty(lblEssence.Text); lblFilePathLabel.Visible = !string.IsNullOrEmpty(lblFilePath.Text); lblSettingsLabel.Visible = !string.IsNullOrEmpty(lblSettings.Text); ProcessMugshotSizeMode(); }
/// <summary> /// Generates a character cache, which prevents us from repeatedly loading XmlNodes or caching a full character. /// </summary> /// <param name="strFile"></param> private TreeNode CacheCharacters(string strFile) { if (!File.Exists(strFile)) { Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_File_Cannot_Be_Accessed") + Environment.NewLine + Environment.NewLine + strFile); return(null); } List <XmlDocument> lstCharacterXmlStatblocks = new List <XmlDocument>(); try { using (ZipArchive zipArchive = ZipFile.Open(strFile, ZipArchiveMode.Read, Encoding.GetEncoding(850))) { foreach (ZipArchiveEntry entry in zipArchive.Entries) { string strEntryFullName = entry.FullName; if (strEntryFullName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) && strEntryFullName.StartsWith("statblocks_xml", StringComparison.Ordinal)) { XmlDocument xmlSourceDoc = new XmlDocument { XmlResolver = null }; // If we run into any problems loading the character cache, fail out early. try { using (StreamReader sr = new StreamReader(entry.Open(), true)) using (XmlReader objXmlReader = XmlReader.Create(sr, new XmlReaderSettings { XmlResolver = null })) xmlSourceDoc.Load(objXmlReader); lstCharacterXmlStatblocks.Add(xmlSourceDoc); } // If we run into any problems loading the character cache, fail out early. catch (IOException) { Utils.BreakIfDebug(); } catch (XmlException) { Utils.BreakIfDebug(); } } else if (strEntryFullName.StartsWith("images", StringComparison.Ordinal) && strEntryFullName.Contains('.')) { string strKey = Path.GetFileName(strEntryFullName); Bitmap bmpMugshot = new Bitmap(entry.Open(), true); if (bmpMugshot.PixelFormat == PixelFormat.Format32bppPArgb) { if (_dicImages.ContainsKey(strKey)) { _dicImages[strKey].Dispose(); _dicImages[strKey] = bmpMugshot; } else { _dicImages.Add(strKey, bmpMugshot); } } else { try { Bitmap bmpMugshotCorrected = bmpMugshot.ConvertPixelFormat(PixelFormat.Format32bppPArgb); if (_dicImages.ContainsKey(strKey)) { _dicImages[strKey].Dispose(); _dicImages[strKey] = bmpMugshotCorrected; } else { _dicImages.Add(strKey, bmpMugshotCorrected); } } finally { bmpMugshot.Dispose(); } } } } } } catch (IOException) { Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_File_Cannot_Be_Accessed") + Environment.NewLine + Environment.NewLine + strFile); return(null); } catch (NotSupportedException) { Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_File_Cannot_Be_Accessed") + Environment.NewLine + Environment.NewLine + strFile); return(null); } catch (UnauthorizedAccessException) { Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_Insufficient_Permissions_Warning")); return(null); } string strFileText = strFile.CheapReplace(Application.StartupPath, () => "<" + Application.ProductName + ">"); TreeNode nodRootNode = new TreeNode { Text = strFileText, ToolTipText = strFileText }; XmlDocument xmlMetatypesDocument = XmlManager.Load("metatypes.xml"); foreach (XmlDocument xmlCharacterDocument in lstCharacterXmlStatblocks) { XmlNode xmlBaseCharacterNode = xmlCharacterDocument.SelectSingleNode("/document/public/character"); if (xmlBaseCharacterNode != null) { HeroLabCharacterCache objCache = new HeroLabCharacterCache { PlayerName = xmlBaseCharacterNode.Attributes?["playername"]?.InnerText }; string strNameString = xmlBaseCharacterNode.Attributes?["name"]?.InnerText ?? string.Empty; objCache.CharacterId = strNameString; if (!string.IsNullOrEmpty(strNameString)) { int intAsIndex = strNameString.IndexOf(" as ", StringComparison.Ordinal); if (intAsIndex != -1) { objCache.CharacterName = strNameString.Substring(0, intAsIndex); objCache.CharacterAlias = strNameString.Substring(intAsIndex).TrimStart(" as ").Trim('\''); } else { objCache.CharacterName = strNameString; } } string strRaceString = xmlBaseCharacterNode.SelectSingleNode("race/@name")?.InnerText; if (strRaceString == "Metasapient") { strRaceString = "A.I."; } if (!string.IsNullOrEmpty(strRaceString)) { using (XmlNodeList xmlMetatypeList = xmlMetatypesDocument.SelectNodes("/chummer/metatypes/metatype")) { if (xmlMetatypeList?.Count > 0) { foreach (XmlNode xmlMetatype in xmlMetatypeList) { string strMetatypeName = xmlMetatype["name"]?.InnerText ?? string.Empty; if (strMetatypeName == strRaceString) { objCache.Metatype = strMetatypeName; objCache.Metavariant = "None"; break; } using (XmlNodeList xmlMetavariantList = xmlMetatype.SelectNodes("metavariants/metavariant")) { if (xmlMetavariantList?.Count > 0) { foreach (XmlNode xmlMetavariant in xmlMetavariantList) { string strMetavariantName = xmlMetavariant["name"]?.InnerText ?? string.Empty; if (strMetavariantName == strRaceString) { objCache.Metatype = strMetatypeName; objCache.Metavariant = strMetavariantName; break; } } } } } } } } objCache.Description = xmlBaseCharacterNode.SelectSingleNode("personal/description")?.InnerText; objCache.Karma = xmlBaseCharacterNode.SelectSingleNode("karma/@total")?.InnerText ?? "0"; objCache.Essence = xmlBaseCharacterNode.SelectSingleNode("attributes/attribute[@name = \"Essence\"]/@text")?.InnerText; objCache.BuildMethod = xmlBaseCharacterNode.SelectSingleNode("creation/bp/@total")?.InnerText == "25" ? CharacterBuildMethod.Priority.ToString() : CharacterBuildMethod.Karma.ToString(); objCache.Created = objCache.Karma != "0"; if (!objCache.Created) { XmlNodeList xmlJournalEntries = xmlBaseCharacterNode.SelectNodes("journals/journal"); if (xmlJournalEntries?.Count > 1) { objCache.Created = true; } else if (xmlJournalEntries?.Count == 1 && xmlJournalEntries[0]?.Attributes?["name"]?.InnerText != "Title") { objCache.Created = true; } } string strImageString = xmlBaseCharacterNode.SelectSingleNode("images/image/@filename")?.InnerText; if (!string.IsNullOrEmpty(strImageString) && _dicImages.TryGetValue(strImageString, out Bitmap objTemp)) { objCache.Mugshot = objTemp; } objCache.FilePath = strFile; TreeNode objNode = new TreeNode { Text = CalculatedName(objCache), ToolTipText = strFile.CheapReplace(Application.StartupPath, () => "<" + Application.ProductName + ">") }; nodRootNode.Nodes.Add(objNode); lock (_lstCharacterCacheLock) { _lstCharacterCache.Add(objCache); objNode.Tag = _lstCharacterCache.IndexOf(objCache); } } } nodRootNode.Expand(); return(nodRootNode); }
private void TestArmor() { Character objCharacter = new Character(); XmlDocument objXmlDocument = XmlManager.Load("armor.xml"); pgbProgress.Minimum = 0; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlDocument.SelectNodes("/chummer/armors/armor").Count; pgbProgress.Maximum += objXmlDocument.SelectNodes("/chummer/mods/mod").Count; // Armor. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/armors/armor")) { pgbProgress.Value++; Application.DoEvents(); try { Armor objTemp = new Armor(objCharacter); List <Weapon> lstWeapons = new List <Weapon>(); objTemp.Create(objXmlGear, 0, lstWeapons); try { decimal objValue = objTemp.TotalCost; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\r\n"; } try { int objValue = objTemp.TotalArmor; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalArmor\r\n"; } try { string objValue = objTemp.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.Language); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\r\n"; } try { string objValue = objTemp.CalculatedCapacity; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCapacity\r\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\r\n"; } } // Armor Mods. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/mods/mod")) { pgbProgress.Value++; Application.DoEvents(); try { ArmorMod objTemp = new ArmorMod(objCharacter); List <Weapon> lstWeapons = new List <Weapon>(); objTemp.Create(objXmlGear, 1, lstWeapons); try { string objValue = objTemp.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.Language); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\r\n"; } try { string objValue = objTemp.CalculatedCapacity; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCapacity\r\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\r\n"; } } }
public frmSelectWeaponCategory() { InitializeComponent(); this.TranslateWinForm(); _objXmlDocument = XmlManager.Load("weapons.xml"); }
private void TestCyberware(string strFile) { string strPrefix = "cyberware"; Improvement.ImprovementSource objSource = Improvement.ImprovementSource.Cyberware; if (strFile == "bioware.xml") { strPrefix = "bioware"; objSource = Improvement.ImprovementSource.Bioware; } Character objCharacter = new Character(); XmlDocument objXmlDocument = XmlManager.Load(strFile); pgbProgress.Minimum = 0; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlDocument.SelectNodes("/chummer/" + strPrefix + "s/" + strPrefix).Count; Grade objTestGrade = objCharacter.GetGradeList(objSource).FirstOrDefault(x => x.Name == "Standard"); // Gear. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/" + strPrefix + "s/" + strPrefix)) { pgbProgress.Value++; Application.DoEvents(); try { Cyberware objTemp = new Cyberware(objCharacter); List <Weapon> lstWeapons = new List <Weapon>(); List <Vehicle> objVehicles = new List <Vehicle>(); objTemp.Create(objXmlGear, objCharacter, objTestGrade, objSource, 1, lstWeapons, objVehicles); try { decimal objValue = objTemp.TotalCost; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\r\n"; } try { string objValue = objTemp.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.Language); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\r\n"; } try { int objValue = objTemp.TotalAgility; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAgility\r\n"; } try { int objValue = objTemp.TotalBody; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalBody\r\n"; } try { int objValue = objTemp.TotalStrength; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalStrength\r\n"; } try { string objValue = objTemp.CalculatedCapacity; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCapacity\r\n"; } try { decimal objValue = objTemp.CalculatedESS(); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedESS()\r\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\r\n"; } } objCharacter.DeleteCharacter(); }
private void cmdAddMod_Click(object sender, EventArgs e) { bool blnAddAgain; XmlNode xmlSelectedMount = null; string strSelectedMount = cboSize.SelectedValue?.ToString(); if (!string.IsNullOrEmpty(strSelectedMount)) { xmlSelectedMount = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedMount + "\"]"); } int intSlots = Convert.ToInt32(xmlSelectedMount?["slots"]?.InnerText); string[] astrSelectedValues = { cboVisibility.SelectedValue?.ToString(), cboFlexibility.SelectedValue?.ToString(), cboControl.SelectedValue?.ToString() }; for (int i = 0; i < astrSelectedValues.Length; ++i) { string strSelectedId = astrSelectedValues[i]; if (!string.IsNullOrEmpty(strSelectedId)) { XmlNode xmlLoopNode = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedId + "\"]"); if (xmlLoopNode != null) { intSlots += Convert.ToInt32(xmlLoopNode["slots"]?.InnerText); } } } foreach (VehicleMod objMod in _lstMods) { intSlots += objMod.CalculatedSlots; } TreeNode objModsParentNode = treMods.FindNode("Node_AdditionalMods"); do { frmSelectVehicleMod frmPickVehicleMod = new frmSelectVehicleMod(_objCharacter, _objMount?.Mods) { // Pass the selected vehicle on to the form. SelectedVehicle = _objVehicle, VehicleMountMods = true, WeaponMountSlots = intSlots }; frmPickVehicleMod.ShowDialog(this); // Make sure the dialogue window was not canceled. if (frmPickVehicleMod.DialogResult == DialogResult.Cancel) { frmPickVehicleMod.Dispose(); break; } blnAddAgain = frmPickVehicleMod.AddAgain; XmlDocument objXmlDocument = XmlManager.Load("vehicles.xml"); XmlNode objXmlMod = objXmlDocument.SelectSingleNode("/chummer/weaponmountmods/mod[id = \"" + frmPickVehicleMod.SelectedMod + "\"]"); VehicleMod objMod = new VehicleMod(_objCharacter) { DiscountCost = frmPickVehicleMod.BlackMarketDiscount }; objMod.Create(objXmlMod, frmPickVehicleMod.SelectedRating, _objVehicle, frmPickVehicleMod.Markup); // Check the item's Cost and make sure the character can afford it. decimal decOriginalCost = _objVehicle.TotalCost; if (frmPickVehicleMod.FreeCost) { objMod.Cost = "0"; } frmPickVehicleMod.Dispose(); // Do not allow the user to add a new Vehicle Mod if the Vehicle's Capacity has been reached. if (_objCharacter.Options.EnforceCapacity) { bool blnOverCapacity = false; if (_objCharacter.Options.BookEnabled("R5")) { if (_objVehicle.IsDrone && GlobalOptions.Dronemods) { if (_objVehicle.DroneModSlotsUsed > _objVehicle.DroneModSlots) { blnOverCapacity = true; } } else { int intUsed = _objVehicle.CalcCategoryUsed(objMod.Category); int intAvail = _objVehicle.CalcCategoryAvail(objMod.Category); if (intUsed > intAvail) { blnOverCapacity = true; } } } else if (_objVehicle.Slots < _objVehicle.SlotsUsed) { blnOverCapacity = true; } if (blnOverCapacity) { MessageBox.Show(LanguageManager.GetString("Message_CapacityReached", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_CapacityReached", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); continue; } } if (_objCharacter.Created) { decimal decCost = _objVehicle.TotalCost - decOriginalCost; // Multiply the cost if applicable. char chrAvail = objMod.TotalAvailTuple().Suffix; if (chrAvail == 'R' && _objCharacter.Options.MultiplyRestrictedCost) { decCost *= _objCharacter.Options.RestrictedCostMultiplier; } if (chrAvail == 'F' && _objCharacter.Options.MultiplyForbiddenCost) { decCost *= _objCharacter.Options.ForbiddenCostMultiplier; } if (decCost > _objCharacter.Nuyen) { MessageBox.Show(LanguageManager.GetString("Message_NotEnoughNuyen", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_NotEnoughNuyen", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); continue; } // Create the Expense Log Entry. ExpenseLogEntry objExpense = new ExpenseLogEntry(_objCharacter); objExpense.Create(decCost * -1, LanguageManager.GetString("String_ExpensePurchaseVehicleMod", GlobalOptions.Language) + ' ' + objMod.DisplayNameShort(GlobalOptions.Language), ExpenseType.Nuyen, DateTime.Now); _objCharacter.ExpenseEntries.AddWithSort(objExpense); _objCharacter.Nuyen -= decCost; ExpenseUndo objUndo = new ExpenseUndo(); objUndo.CreateNuyen(NuyenExpenseType.AddVehicleWeaponMountMod, objMod.InternalId); objExpense.Undo = objUndo; } _lstMods.Add(objMod); intSlots += objMod.CalculatedSlots; // Check for Improved Sensor bonus. if (objMod.Bonus?["selecttext"] != null) { frmSelectText frmPickText = new frmSelectText { Description = LanguageManager.GetString("String_Improvement_SelectText", GlobalOptions.Language).Replace("{0}", objMod.DisplayNameShort(GlobalOptions.Language)) }; frmPickText.ShowDialog(this); objMod.Extra = frmPickText.SelectedValue; frmPickText.Dispose(); } TreeNode objNewNode = objMod.CreateTreeNode(null, null, null, null, null, null); if (objModsParentNode == null) { objModsParentNode = new TreeNode { Tag = "Node_AdditionalMods", Text = LanguageManager.GetString("Node_AdditionalMods", GlobalOptions.Language) }; treMods.Nodes.Add(objModsParentNode); objModsParentNode.Expand(); } objModsParentNode.Nodes.Add(objNewNode); treMods.SelectedNode = objNewNode; }while (blnAddAgain); }
private void TestVehicles() { Character objCharacter = new Character(); XmlDocument objXmlDocument = XmlManager.Load("vehicles.xml"); pgbProgress.Minimum = 0; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlDocument.SelectNodes("/chummer/vehicles/vehicle").Count; pgbProgress.Maximum += objXmlDocument.SelectNodes("/chummer/mods/mod").Count; // Vehicles. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/vehicles/vehicle")) { pgbProgress.Value++; Application.DoEvents(); try { Vehicle objTemp = new Vehicle(objCharacter); objTemp.Create(objXmlGear); try { decimal objValue = objTemp.TotalCost; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\r\n"; } try { string objValue = objTemp.TotalAccel; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAccel\r\n"; } try { int objValue = objTemp.TotalArmor; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalArmor\r\n"; } try { int objValue = objTemp.TotalBody; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalBody\r\n"; } try { string objValue = objTemp.TotalHandling; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalHandling\r\n"; } try { string objValue = objTemp.TotalSpeed; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalSpeed\r\n"; } try { string objValue = objTemp.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.Language); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedAvail\r\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\r\n"; } } // Vehicle Mods. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/mods/mod")) { pgbProgress.Value++; Application.DoEvents(); try { VehicleMod objTemp = new VehicleMod(objCharacter); objTemp.Create(objXmlGear, 1, null); try { decimal objValue = objTemp.TotalCost; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\r\n"; } try { string objValue = objTemp.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.DefaultLanguage); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\r\n"; } try { int objValue = objTemp.CalculatedSlots; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedSlots\r\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\r\n"; } } objCharacter.DeleteCharacter(); }
/// <summary> /// Returns a current language translation given an improvement name. /// </summary> /// <param name="strImprovementType"> The selector for the target translation. Often just _strSelect. </param> /// <param name="strToTranslate"> The string which to translate. Usually name. Guid in the case of adept powers.</param> /// <returns></returns> private string TranslateField(string strImprovementType, string strToTranslate) { XmlNode objXmlNode; switch (strImprovementType) { case "SelectAttribute": case "SelectPhysicalAttribute": case "SelectMentalAttribute": case "SelectSpecialAttribute": return(strToTranslate == "MAGAdept" ? LanguageManager.GetString("String_AttributeMAGShort") + LanguageManager.GetString("String_Space") + '(' + LanguageManager.GetString("String_DescAdept") + ')' : LanguageManager.GetString("String_Attribute" + strToTranslate + "Short")); case "SelectSkill": if (strToTranslate.Contains("Exotic Melee Weapon") || strToTranslate.Contains("Exotic Ranged Weapon") || strToTranslate.Contains("Pilot Exotic Vehicle")) { string[] astrToTranslateParts = strToTranslate.Split('('); astrToTranslateParts[0] = astrToTranslateParts[0].Trim(); astrToTranslateParts[1] = astrToTranslateParts[1].Substring(0, astrToTranslateParts[1].Length - 1); objXmlNode = XmlManager.Load("skills.xml").SelectSingleNode("/chummer/skills/skill[name = \"" + astrToTranslateParts[0] + "\"]"); string strFirstPartTranslated = objXmlNode?.SelectSingleNode("translate")?.InnerText ?? objXmlNode?.SelectSingleNode("name")?.InnerText ?? astrToTranslateParts[0]; return(strFirstPartTranslated + LanguageManager.GetString("String_Space") + '(' + LanguageManager.TranslateExtra(astrToTranslateParts[1]) + ')'); } else { objXmlNode = XmlManager.Load("skills.xml").SelectSingleNode("/chummer/skills/skill[name = \"" + strToTranslate + "\"]"); return(objXmlNode?.SelectSingleNode("translate")?.InnerText ?? objXmlNode?.SelectSingleNode("name")?.InnerText ?? strToTranslate); } case "SelectKnowSkill": objXmlNode = XmlManager.Load("skills.xml").SelectSingleNode("/chummer/knowledgeskills/skill[name = \"" + strToTranslate + "\"]"); return(objXmlNode?.SelectSingleNode("translate")?.InnerText ?? objXmlNode?.SelectSingleNode("name")?.InnerText ?? strToTranslate); case "SelectSkillCategory": objXmlNode = XmlManager.Load("skills.xml").SelectSingleNode("/chummer/categories/category[. = \"" + strToTranslate + "\"]"); return(objXmlNode?.Attributes?["translate"]?.InnerText ?? objXmlNode?.SelectSingleNode(".")?.InnerText ?? strToTranslate); case "SelectSkillGroup": objXmlNode = XmlManager.Load("skills.xml").SelectSingleNode("/chummer/skillgroups/name[. = \"" + strToTranslate + "\"]"); return(objXmlNode?.Attributes?["translate"]?.InnerText ?? objXmlNode?.SelectSingleNode(".")?.InnerText ?? strToTranslate); case "SelectWeaponCategory": objXmlNode = XmlManager.Load("weapons.xml").SelectSingleNode("/chummer/categories/category[. = \"" + strToTranslate + "\"]"); return(objXmlNode?.Attributes?["translate"]?.InnerText ?? objXmlNode?.SelectSingleNode(".")?.InnerText ?? strToTranslate); case "SelectSpellCategory": objXmlNode = XmlManager.Load("spells.xml").SelectSingleNode("/chummer/categories/category[. = \"" + strToTranslate + "\"]"); return(objXmlNode?.Attributes?["translate"]?.InnerText ?? objXmlNode?.SelectSingleNode(".")?.InnerText ?? strToTranslate); case "SelectAdeptPower": objXmlNode = XmlManager.Load("powers.xml").SelectSingleNode("/chummer/powers/power[id = \"" + strToTranslate + "\" or name = \"" + strToTranslate + "\"]"); return(objXmlNode?.SelectSingleNode("translate")?.InnerText ?? objXmlNode?.SelectSingleNode("name")?.InnerText ?? strToTranslate); default: return(strToTranslate); } }
private void frmCreateWeaponMount_Load(object sender, EventArgs e) { _xmlDoc = XmlManager.Load("vehicles.xml"); // Populate the Armor Category list. XmlNodeList nodeList = _xmlDoc.SelectNodes("/chummer/weaponmounts/weaponmount"); if (nodeList != null) { foreach (XmlNode node in nodeList) { ListItem objItem = new ListItem(); objItem.Value = node["id"].InnerText; objItem.Name = node.Attributes?["translate"]?.InnerText ?? node["name"].InnerText; switch (node["category"].InnerText) { case "Visibility": _lstVisibility.Add(objItem); break; case "Flexibility": _lstFlexibility.Add(objItem); break; case "Control": _lstControl.Add(objItem); break; case "Size": _lstSize.Add(objItem); break; default: Utils.BreakIfDebug(); break; } } } cboSize.BeginUpdate(); cboSize.ValueMember = "Value"; cboSize.DisplayMember = "Name"; cboSize.DataSource = _lstSize; cboSize.EndUpdate(); cboVisibility.BeginUpdate(); cboVisibility.ValueMember = "Value"; cboVisibility.DisplayMember = "Name"; cboVisibility.DataSource = _lstVisibility; cboVisibility.EndUpdate(); cboFlexibility.BeginUpdate(); cboFlexibility.ValueMember = "Value"; cboFlexibility.DisplayMember = "Name"; cboFlexibility.DataSource = _lstFlexibility; cboFlexibility.EndUpdate(); cboControl.BeginUpdate(); cboControl.ValueMember = "Value"; cboControl.DisplayMember = "Name"; cboControl.DataSource = _lstControl; cboControl.EndUpdate(); _loading = false; comboBox_SelectedIndexChanged(null, null); }
private void cmdOK_Click(object sender, EventArgs e) { // Make sure the suite and file name fields are populated. if (string.IsNullOrEmpty(txtName.Text)) { MessageBox.Show(LanguageManager.GetString("Message_CyberwareSuite_SuiteName", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_CyberwareSuite_SuiteName", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txtFileName.Text)) { MessageBox.Show(LanguageManager.GetString("Message_CyberwareSuite_FileName", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_CyberwareSuite_FileName", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure the file name starts with custom and ends with _cyberware.xml. if (!txtFileName.Text.StartsWith("custom") || !txtFileName.Text.EndsWith('_' + _strType + ".xml")) { MessageBox.Show(LanguageManager.GetString("Message_CyberwareSuite_InvalidFileName", GlobalOptions.Language).Replace("{0}", _strType), LanguageManager.GetString("MessageTitle_CyberwareSuite_InvalidFileName", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // See if a Suite with this name already exists for the Custom category. // This was originally done without the XmlManager, but because amends and overrides and toggling custom data directories can change names, we need to use it. string strName = txtName.Text; if (XmlManager.Load(_strType + ".xml", GlobalOptions.Language).SelectSingleNode("/chummer/suites/suite[name = \"" + strName + "\"]") != null) { MessageBox.Show( LanguageManager.GetString("Message_CyberwareSuite_DuplicateName", GlobalOptions.Language).Replace("{0}", strName), LanguageManager.GetString("MessageTitle_CyberwareSuite_DuplicateName", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string strPath = Path.Combine(Application.StartupPath, "data", txtFileName.Text); bool blnNewFile = !File.Exists(strPath); // If this is not a new file, read in the existing contents. XmlDocument objXmlCurrentDocument = new XmlDocument(); if (!blnNewFile) { try { using (StreamReader objStreamReader = new StreamReader(strPath, Encoding.UTF8, true)) { objXmlCurrentDocument.Load(objStreamReader); } } catch (IOException ex) { MessageBox.Show(ex.ToString()); return; } catch (XmlException ex) { MessageBox.Show(ex.ToString()); return; } } FileStream objStream = new FileStream(strPath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); XmlTextWriter objWriter = new XmlTextWriter(objStream, Encoding.UTF8) { Formatting = Formatting.Indented, Indentation = 1, IndentChar = '\t' }; objWriter.WriteStartDocument(); // <chummer> objWriter.WriteStartElement("chummer"); if (!blnNewFile) { // <cyberwares> objWriter.WriteStartElement(_strType + "s"); using (XmlNodeList xmlCyberwareList = objXmlCurrentDocument.SelectNodes("/chummer/" + _strType + "s")) if (xmlCyberwareList?.Count > 0) { foreach (XmlNode xmlCyberware in xmlCyberwareList) { xmlCyberware.WriteContentTo(objWriter); } } // </cyberwares> objWriter.WriteEndElement(); } // <suites> objWriter.WriteStartElement("suites"); // If this is not a new file, write out the current contents. if (!blnNewFile) { using (XmlNodeList xmlCyberwareList = objXmlCurrentDocument.SelectNodes("/chummer/suites")) if (xmlCyberwareList?.Count > 0) { foreach (XmlNode xmlCyberware in xmlCyberwareList) { xmlCyberware.WriteContentTo(objWriter); } } } string strGrade = string.Empty; // Determine the Grade of Cyberware. foreach (Cyberware objCyberware in _objCharacter.Cyberware) { if (objCyberware.SourceType == _objSource) { strGrade = objCyberware.Grade.Name; break; } } // <suite> objWriter.WriteStartElement("suite"); // <name /> objWriter.WriteElementString("name", txtName.Text); // <grade /> objWriter.WriteElementString("grade", strGrade); // <cyberwares> objWriter.WriteStartElement(_strType + "s"); // Write out the Cyberware. foreach (Cyberware objCyberware in _objCharacter.Cyberware) { if (objCyberware.SourceType == _objSource) { // <cyberware> objWriter.WriteStartElement(_strType); objWriter.WriteElementString("name", objCyberware.Name); if (objCyberware.Rating > 0) { objWriter.WriteElementString("rating", objCyberware.Rating.ToString()); } // Write out child items. if (objCyberware.Children.Count > 0) { // <cyberwares> objWriter.WriteStartElement(_strType + "s"); foreach (Cyberware objChild in objCyberware.Children) { // Do not include items that come with the base item by default. if (objChild.Capacity != "[*]") { objWriter.WriteStartElement(_strType); objWriter.WriteElementString("name", objChild.Name); if (objChild.Rating > 0) { objWriter.WriteElementString("rating", objChild.Rating.ToString()); } // </cyberware> objWriter.WriteEndElement(); } } // </cyberwares> objWriter.WriteEndElement(); } // </cyberware> objWriter.WriteEndElement(); } } // </cyberwares> objWriter.WriteEndElement(); // </suite> objWriter.WriteEndElement(); // </chummer> objWriter.WriteEndElement(); objWriter.WriteEndDocument(); objWriter.Close(); MessageBox.Show(LanguageManager.GetString("Message_CyberwareSuite_SuiteCreated", GlobalOptions.Language).Replace("{0}", txtName.Text), LanguageManager.GetString("MessageTitle_CyberwareSuite_SuiteCreated", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; }
static GlobalOptions() { if (Utils.IsRunningInVisualStudio()) { return; } _objBaseChummerKey = Registry.CurrentUser.CreateSubKey("Software\\Chummer5"); if (_objBaseChummerKey == null) { return; } _objBaseChummerKey.CreateSubKey("Sourcebook"); string settingsDirectoryPath = Path.Combine(Application.StartupPath, "settings"); if (!Directory.Exists(settingsDirectoryPath)) { try { Directory.CreateDirectory(settingsDirectoryPath); } catch (UnauthorizedAccessException) { MessageBox.Show(LanguageManager.GetString("Message_Insufficient_Permissions_Warning")); } } // Automatic Update. LoadBoolFromRegistry(ref _blnAutomaticUpdate, "autoupdate"); LoadBoolFromRegistry(ref _blnLiveCustomData, "livecustomdata"); LoadBoolFromRegistry(ref _lifeModuleEnabled, "lifemodule"); LoadBoolFromRegistry(ref _omaeEnabled, "omaeenabled"); // Whether or not the app should only download localised files in the user's selected language. LoadBoolFromRegistry(ref _blnLocalisedUpdatesOnly, "localisedupdatesonly"); // Whether or not the app should use logging. LoadBoolFromRegistry(ref _blnUseLogging, "uselogging"); // Whether or not dates should include the time. LoadBoolFromRegistry(ref _blnDatesIncludeTime, "datesincludetime"); LoadBoolFromRegistry(ref _blnMissionsOnly, "missionsonly"); LoadBoolFromRegistry(ref _blnDronemods, "dronemods"); LoadBoolFromRegistry(ref _blnDronemodsMaximumPilot, "dronemodsPilot"); // Whether or not printouts should be sent to a file before loading them in the browser. This is a fix for getting printing to work properly on Linux using Wine. LoadBoolFromRegistry(ref _blnPrintToFileFirst, "printtofilefirst"); // Default character sheet. LoadStringFromRegistry(ref _strDefaultCharacterSheet, "defaultsheet"); // Omae Settings. // Username. LoadStringFromRegistry(ref _strOmaeUserName, "omaeusername"); // Password. LoadStringFromRegistry(ref _strOmaePassword, "omaepassword"); // AutoLogin. LoadBoolFromRegistry(ref _blnOmaeAutoLogin, "omaeautologin"); // Language. LoadStringFromRegistry(ref _strLanguage, "language"); switch (_strLanguage) { case "en-us2": _strLanguage = GlobalOptions.DefaultLanguage; break; case "de": _strLanguage = "de-de"; break; case "fr": _strLanguage = "fr-fr"; break; case "jp": _strLanguage = "jp-jp"; break; case "zh": _strLanguage = "zh-cn"; break; } // Startup in Fullscreen mode. LoadBoolFromRegistry(ref _blnStartupFullscreen, "startupfullscreen"); // Single instace of the Dice Roller window. LoadBoolFromRegistry(ref _blnSingleDiceRoller, "singlediceroller"); // Open PDFs as URLs. For use with Chrome, Firefox, etc. LoadStringFromRegistry(ref _strPDFParameters, "pdfparameters"); // PDF application path. LoadStringFromRegistry(ref _strPDFAppPath, "pdfapppath"); // Folder path to check for characters. LoadStringFromRegistry(ref _strCharacterRosterPath, "characterrosterpath"); // Prefer Nightly Updates. LoadBoolFromRegistry(ref _blnPreferNightlyUpdates, "prefernightlybuilds"); // Retrieve CustomDataDirectoryInfo objects from registry RegistryKey objCustomDataDirectoryKey = _objBaseChummerKey.OpenSubKey("CustomDataDirectory"); if (objCustomDataDirectoryKey != null) { List <KeyValuePair <CustomDataDirectoryInfo, int> > lstUnorderedCustomDataDirectories = new List <KeyValuePair <CustomDataDirectoryInfo, int> > (objCustomDataDirectoryKey.SubKeyCount); string[] astrCustomDataDirectoryNames = objCustomDataDirectoryKey.GetSubKeyNames(); int intMinLoadOrderValue = int.MaxValue; int intMaxLoadOrderValue = int.MinValue; for (int i = 0; i < astrCustomDataDirectoryNames.Length; ++i) { RegistryKey objLoopKey = objCustomDataDirectoryKey.OpenSubKey(astrCustomDataDirectoryNames[i]); string strPath = string.Empty; object objRegistryResult = objLoopKey.GetValue("Path"); if (objRegistryResult != null) { strPath = objRegistryResult.ToString(); } if (!string.IsNullOrEmpty(strPath) && Directory.Exists(strPath)) { CustomDataDirectoryInfo objCustomDataDirectory = new CustomDataDirectoryInfo(); objCustomDataDirectory.Name = astrCustomDataDirectoryNames[i]; objCustomDataDirectory.Path = strPath; objRegistryResult = objLoopKey.GetValue("Enabled"); if (objRegistryResult != null) { bool blnTemp; if (bool.TryParse(objRegistryResult.ToString(), out blnTemp)) { objCustomDataDirectory.Enabled = blnTemp; } } int intLoadOrder = 0; objRegistryResult = objLoopKey.GetValue("LoadOrder"); if (objRegistryResult != null && int.TryParse(objRegistryResult.ToString(), out intLoadOrder)) { // First load the infos alongside their load orders into a list whose order we don't care about intMaxLoadOrderValue = Math.Max(intMaxLoadOrderValue, intLoadOrder); intMinLoadOrderValue = Math.Min(intMinLoadOrderValue, intLoadOrder); lstUnorderedCustomDataDirectories.Add(new KeyValuePair <CustomDataDirectoryInfo, int>(objCustomDataDirectory, intLoadOrder)); } else { lstUnorderedCustomDataDirectories.Add(new KeyValuePair <CustomDataDirectoryInfo, int>(objCustomDataDirectory, int.MinValue)); } } } // Now translate the list of infos whose order we don't care about into the list where we do care about the order of infos for (int i = intMinLoadOrderValue; i <= intMaxLoadOrderValue; ++i) { KeyValuePair <CustomDataDirectoryInfo, int> objLoopPair = lstUnorderedCustomDataDirectories.FirstOrDefault(x => x.Value == i); if (!objLoopPair.Equals(default(KeyValuePair <CustomDataDirectoryInfo, int>))) { _lstCustomDataDirectoryInfo.Add(objLoopPair.Key); } } foreach (KeyValuePair <CustomDataDirectoryInfo, int> objLoopPair in lstUnorderedCustomDataDirectories.Where(x => x.Value == int.MinValue)) { _lstCustomDataDirectoryInfo.Add(objLoopPair.Key); } } // Auto-populate the rest of the list from customdata string strCustomDataRootPath = Path.Combine(Application.StartupPath, "customdata"); if (Directory.Exists(strCustomDataRootPath)) { foreach (string strLoopDirectoryPath in Directory.GetDirectories(strCustomDataRootPath)) { // Only add directories for which we don't already have entries loaded from registry if (!_lstCustomDataDirectoryInfo.Any(x => x.Path == strLoopDirectoryPath)) { CustomDataDirectoryInfo objCustomDataDirectory = new CustomDataDirectoryInfo(); objCustomDataDirectory.Name = Path.GetFileName(strLoopDirectoryPath); objCustomDataDirectory.Path = strLoopDirectoryPath; _lstCustomDataDirectoryInfo.Add(objCustomDataDirectory); } } } // Retrieve the SourcebookInfo objects. XmlDocument objXmlDocument = XmlManager.Load("books.xml"); foreach (XmlNode objXmlBook in objXmlDocument.SelectNodes("/chummer/books/book")) { if (objXmlBook["code"] != null && objXmlBook["hide"] == null) { SourcebookInfo objSource = new SourcebookInfo(); objSource.Code = objXmlBook["code"].InnerText; string strTemp = string.Empty; try { LoadStringFromRegistry(ref strTemp, objXmlBook["code"].InnerText, "Sourcebook"); if (!string.IsNullOrEmpty(strTemp)) { string[] strParts = strTemp.Split('|'); objSource.Path = strParts[0]; if (strParts.Length > 1) { int intTmp; if (int.TryParse(strParts[1], out intTmp)) { objSource.Offset = intTmp; } } } } catch (System.Security.SecurityException) { } catch (UnauthorizedAccessException) { } _lstSourcebookInfo.Add(objSource); } } }
/// <summary> /// Load the Power from the XmlNode. /// </summary> /// <param name="objNode">XmlNode to load.</param> public void Load(XmlNode objNode) { objNode.TryGetField("guid", Guid.TryParse, out _guiID); objNode.TryGetStringFieldQuickly("name", ref _strName); if (objNode.TryGetField("id", Guid.TryParse, out _sourceID)) { _objCachedMyXmlNode = null; } else { string strPowerName = Name; int intPos = strPowerName.IndexOf('('); if (intPos != -1) { strPowerName = strPowerName.Substring(0, intPos - 1); } XmlDocument objXmlDocument = XmlManager.Load("powers.xml"); XmlNode xmlPower = objXmlDocument.SelectSingleNode("/chummer/powers/power[starts-with(./name,\"" + strPowerName + "\")]"); if (xmlPower.TryGetField("id", Guid.TryParse, out _sourceID)) { _objCachedMyXmlNode = null; } } Extra = objNode["extra"]?.InnerText ?? string.Empty; _strPointsPerLevel = objNode["pointsperlevel"]?.InnerText; objNode.TryGetStringFieldQuickly("action", ref _strAction); _strAdeptWayDiscount = objNode["adeptway"]?.InnerText; if (string.IsNullOrEmpty(_strAdeptWayDiscount)) { string strPowerName = Name; int intPos = strPowerName.IndexOf('('); if (intPos != -1) { strPowerName = strPowerName.Substring(0, intPos - 1); } _strAdeptWayDiscount = XmlManager.Load("powers.xml").SelectSingleNode("/chummer/powers/power[starts-with(./name,\"" + strPowerName + "\")]/adeptway")?.InnerText ?? string.Empty; } objNode.TryGetInt32FieldQuickly("rating", ref _intRating); objNode.TryGetBoolFieldQuickly("levels", ref _blnLevelsEnabled); objNode.TryGetInt32FieldQuickly("maxlevel", 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("source", ref _strSource); objNode.TryGetStringFieldQuickly("page", ref _strPage); objNode.TryGetStringFieldQuickly("notes", ref _strNotes); Bonus = objNode["bonus"]; if (objNode["adeptway"] != null) { _nodAdeptWayRequirements = objNode["adeptwayrequires"] ?? GetNode()?["adeptwayrequires"]; } if (Name != "Improved Reflexes" && Name.StartsWith("Improved Reflexes")) { XmlNode objXmlPower = XmlManager.Load("powers.xml").SelectSingleNode("/chummer/powers/power[starts-with(./name,\"Improved Reflexes\")]"); if (objXmlPower != null) { if (int.TryParse(Name.TrimStartOnce("Improved Reflexes", true).Trim(), out int intTemp)) { Create(objXmlPower, intTemp, null, false); objNode.TryGetStringFieldQuickly("notes", ref _strNotes); } } } else { 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); } } } SourceDetail = new SourceString(_strSource, _strPage); }
private void cmdChangeSelection_Click(object sender, EventArgs e) { switch (_strSelect) { case "SelectAttribute": { List <string> lstAbbrevs = new List <string>(Backend.Attributes.AttributeSection.AttributeStrings); lstAbbrevs.Remove("ESS"); if (!_objCharacter.MAGEnabled) { lstAbbrevs.Remove("MAG"); lstAbbrevs.Remove("MAGAdept"); } else if (!_objCharacter.IsMysticAdept || !_objCharacter.Options.MysAdeptSecondMAGAttribute) { lstAbbrevs.Remove("MAGAdept"); } if (!_objCharacter.RESEnabled) { lstAbbrevs.Remove("RES"); } if (!_objCharacter.DEPEnabled) { lstAbbrevs.Remove("DEP"); } frmSelectAttribute frmPickAttribute = new frmSelectAttribute(lstAbbrevs.ToArray()) { Description = LanguageManager.GetString("Title_SelectAttribute", GlobalOptions.Language) }; frmPickAttribute.ShowDialog(this); if (frmPickAttribute.DialogResult == DialogResult.OK) { txtSelect.Text = frmPickAttribute.SelectedAttribute; } } break; case "SelectMentalAttribute": { frmSelectAttribute frmPickAttribute = new frmSelectAttribute(Backend.Attributes.AttributeSection.MentalAttributes.ToArray()) { Description = LanguageManager.GetString("Title_SelectAttribute", GlobalOptions.Language) }; frmPickAttribute.ShowDialog(this); if (frmPickAttribute.DialogResult == DialogResult.OK) { txtSelect.Text = frmPickAttribute.SelectedAttribute; } } break; case "SelectPhysicalAttribute": { frmSelectAttribute frmPickAttribute = new frmSelectAttribute(Backend.Attributes.AttributeSection.PhysicalAttributes.ToArray()) { Description = LanguageManager.GetString("Title_SelectAttribute", GlobalOptions.Language) }; frmPickAttribute.ShowDialog(this); if (frmPickAttribute.DialogResult == DialogResult.OK) { txtSelect.Text = frmPickAttribute.SelectedAttribute; } } break; case "SelectSpecialAttribute": { List <string> lstAbbrevs = new List <string>(Backend.Attributes.AttributeSection.AttributeStrings); lstAbbrevs.RemoveAll(x => Backend.Attributes.AttributeSection.PhysicalAttributes.Contains(x) || Backend.Attributes.AttributeSection.MentalAttributes.Contains(x)); lstAbbrevs.Remove("ESS"); /* * if (!_objCharacter.MAGEnabled) * { * lstAbbrevs.Remove("MAG"); * lstAbbrevs.Remove("MAGAdept"); * } * else if (!_objCharacter.IsMysticAdept || !_objCharacter.Options.MysAdeptSecondMAGAttribute) * lstAbbrevs.Remove("MAGAdept"); * * if (!_objCharacter.RESEnabled) * lstAbbrevs.Remove("RES"); * if (!_objCharacter.DEPEnabled) * lstAbbrevs.Remove("DEP"); */ frmSelectAttribute frmPickAttribute = new frmSelectAttribute(lstAbbrevs.ToArray()) { Description = LanguageManager.GetString("Title_SelectAttribute", GlobalOptions.Language) }; frmPickAttribute.ShowDialog(this); if (frmPickAttribute.DialogResult == DialogResult.OK) { txtSelect.Text = frmPickAttribute.SelectedAttribute; } } break; case "SelectSkill": { frmSelectSkill frmPickSkill = new frmSelectSkill(_objCharacter) { Description = LanguageManager.GetString("Title_SelectSkill", GlobalOptions.Language) }; frmPickSkill.ShowDialog(this); if (frmPickSkill.DialogResult == DialogResult.OK) { txtSelect.Text = frmPickSkill.SelectedSkill; } } break; case "SelectKnowSkill": { List <ListItem> lstDropdownItems = new List <ListItem>(); HashSet <string> setProcessedSkillNames = new HashSet <string>(); foreach (KnowledgeSkill objKnowledgeSkill in _objCharacter.SkillsSection.KnowledgeSkills) { lstDropdownItems.Add(new ListItem(objKnowledgeSkill.Name, objKnowledgeSkill.DisplayNameMethod(GlobalOptions.Language))); setProcessedSkillNames.Add(objKnowledgeSkill.Name); } StringBuilder objFilter = new StringBuilder(); if (setProcessedSkillNames.Count > 0) { objFilter.Append("not("); foreach (string strName in setProcessedSkillNames) { objFilter.Append("name = \"" + strName + "\" or "); } objFilter.Length -= 4; objFilter.Append(')'); } string strFilter = objFilter.Length > 0 ? '[' + objFilter.ToString() + ']' : string.Empty; using (XmlNodeList xmlSkillList = XmlManager.Load("skills.xml", GlobalOptions.Language).SelectNodes("/chummer/knowledgeskills/skill" + strFilter)) { if (xmlSkillList?.Count > 0) { foreach (XmlNode xmlSkill in xmlSkillList) { string strName = xmlSkill["name"]?.InnerText; if (!string.IsNullOrEmpty(strName)) { lstDropdownItems.Add(new ListItem(strName, xmlSkill["translate"]?.InnerText ?? strName)); } } } } lstDropdownItems.Sort(CompareListItems.CompareNames); frmSelectItem frmPickSkill = new frmSelectItem { DropdownItems = lstDropdownItems, Description = LanguageManager.GetString("Title_SelectSkill", GlobalOptions.Language) }; frmPickSkill.ShowDialog(this); if (frmPickSkill.DialogResult == DialogResult.OK) { txtSelect.Text = frmPickSkill.SelectedItem; } } break; case "SelectSkillCategory": frmSelectSkillCategory frmPickSkillCategory = new frmSelectSkillCategory { Description = LanguageManager.GetString("Title_SelectSkillCategory", GlobalOptions.Language) }; frmPickSkillCategory.ShowDialog(this); if (frmPickSkillCategory.DialogResult == DialogResult.OK) { txtSelect.Text = frmPickSkillCategory.SelectedCategory; } break; case "SelectSkillGroup": frmSelectSkillGroup frmPickSkillGroup = new frmSelectSkillGroup { Description = LanguageManager.GetString("Title_SelectSkillGroup", GlobalOptions.Language) }; frmPickSkillGroup.ShowDialog(this); if (frmPickSkillGroup.DialogResult == DialogResult.OK) { txtSelect.Text = frmPickSkillGroup.SelectedSkillGroup; } break; case "SelectWeaponCategory": frmSelectWeaponCategory frmPickWeaponCategory = new frmSelectWeaponCategory { Description = LanguageManager.GetString("Title_SelectWeaponCategory", GlobalOptions.Language) }; frmPickWeaponCategory.ShowDialog(this); if (frmPickWeaponCategory.DialogResult == DialogResult.OK) { txtSelect.Text = frmPickWeaponCategory.SelectedCategory; } break; case "SelectSpellCategory": frmSelectSpellCategory frmPickSpellCategory = new frmSelectSpellCategory { Description = LanguageManager.GetString("Title_SelectSpellCategory", GlobalOptions.Language) }; frmPickSpellCategory.ShowDialog(this); if (frmPickSpellCategory.DialogResult == DialogResult.OK) { txtSelect.Text = frmPickSpellCategory.SelectedCategory; } break; case "SelectAdeptPower": frmSelectPower frmPickPower = new frmSelectPower(_objCharacter); frmPickPower.ShowDialog(this); if (frmPickPower.DialogResult == DialogResult.OK) { txtSelect.Text = XmlManager.Load("powers.xml").SelectSingleNode("/chummer/powers/power[id = \"" + frmPickPower.SelectedPower + "\"]/name")?.InnerText; } break; } }
public frmSelectBuildMethod(Character objCharacter, bool blnUseCurrentValues = false) { _objCharacter = objCharacter; InitializeComponent(); LanguageManager.TranslateWinForm(GlobalOptions.Language, this); _xmlGameplayOptionsDataGameplayOptionsNode = XmlManager.Load("gameplayoptions.xml").GetFastNavigator().SelectSingleNode("/chummer/gameplayoptions"); // Populate the Build Method list. List <ListItem> lstBuildMethod = new List <ListItem> { new ListItem("Karma", LanguageManager.GetString("String_Karma", GlobalOptions.Language)), new ListItem("Priority", LanguageManager.GetString("String_Priority", GlobalOptions.Language)), new ListItem("SumtoTen", LanguageManager.GetString("String_SumtoTen", GlobalOptions.Language)), }; if (GlobalOptions.LifeModuleEnabled) { lstBuildMethod.Add(new ListItem("LifeModule", LanguageManager.GetString("String_LifeModule", GlobalOptions.Language))); } cboBuildMethod.BeginUpdate(); cboBuildMethod.ValueMember = nameof(ListItem.Value); cboBuildMethod.DisplayMember = nameof(ListItem.Name); cboBuildMethod.DataSource = lstBuildMethod; cboBuildMethod.SelectedValue = GlobalOptions.DefaultBuildMethod; cboBuildMethod.EndUpdate(); // Populate the Gameplay Options list. List <ListItem> lstGameplayOptions = new List <ListItem>(); if (_xmlGameplayOptionsDataGameplayOptionsNode != null) { foreach (XPathNavigator objXmlGameplayOption in _xmlGameplayOptionsDataGameplayOptionsNode.Select("gameplayoption")) { string strName = objXmlGameplayOption.SelectSingleNode("name")?.Value; if (!string.IsNullOrEmpty(strName)) { if (objXmlGameplayOption.SelectSingleNode("default")?.Value == bool.TrueString) { objXmlGameplayOption.TryGetInt32FieldQuickly("maxavailability", ref _intDefaultMaxAvail); objXmlGameplayOption.TryGetInt32FieldQuickly("sumtoten", ref _intDefaultSumToTen); objXmlGameplayOption.TryGetInt32FieldQuickly("pointbuykarma", ref _intDefaultPointBuyKarma); objXmlGameplayOption.TryGetInt32FieldQuickly("lifemoduleskarma", ref _intDefaultLifeModulesKarma); } lstGameplayOptions.Add(new ListItem(strName, objXmlGameplayOption.SelectSingleNode("translate")?.Value ?? strName)); } } } cboGamePlay.BeginUpdate(); cboGamePlay.ValueMember = "Value"; cboGamePlay.DisplayMember = "Name"; cboGamePlay.DataSource = lstGameplayOptions; cboGamePlay.SelectedValue = _strDefaultOption; cboGamePlay.EndUpdate(); chkIgnoreRules.SetToolTip(LanguageManager.GetString("Tip_SelectKarma_IgnoreRules", GlobalOptions.Language)); if (blnUseCurrentValues) { cboGamePlay.SelectedValue = _objCharacter.GameplayOption; if (cboGamePlay.SelectedIndex == -1) { cboGamePlay.SelectedValue = _strDefaultOption; } cboBuildMethod.Enabled = false; cboBuildMethod.SelectedValue = _objCharacter.BuildMethod.ToString(); nudKarma.Value = objCharacter.BuildKarma; nudMaxNuyen.Value = _decNuyenBP = _objCharacter.NuyenMaximumBP; _intQualityLimits = _objCharacter.GameplayOptionQualityLimit; chkIgnoreRules.Checked = _objCharacter.IgnoreRules; nudMaxAvail.Value = objCharacter.MaximumAvailability; nudSumtoTen.Value = objCharacter.SumtoTen; } else if (_xmlGameplayOptionsDataGameplayOptionsNode != null) { XPathNavigator objXmlSelectedGameplayOption = _xmlGameplayOptionsDataGameplayOptionsNode.SelectSingleNode("gameplayoption[name = \"" + cboGamePlay.SelectedValue.ToString() + "\"]"); objXmlSelectedGameplayOption.TryGetInt32FieldQuickly("karma", ref _intQualityLimits); objXmlSelectedGameplayOption.TryGetDecFieldQuickly("maxnuyen", ref _decNuyenBP); nudMaxNuyen.Value = _decNuyenBP; nudKarma.Value = _intQualityLimits; int intTemp = _intDefaultMaxAvail; objXmlSelectedGameplayOption.TryGetInt32FieldQuickly("maxavailability", ref intTemp); nudMaxAvail.Value = intTemp; intTemp = _intDefaultSumToTen; objXmlSelectedGameplayOption.TryGetInt32FieldQuickly("sumtoten", ref intTemp); nudSumtoTen.Value = intTemp; } }