private void cmdAddQuality_Click(object sender, EventArgs e) { bool blnAddAgain; do { frmSelectLifestyleQuality frmSelectLifestyleQuality = new frmSelectLifestyleQuality(_objCharacter, cboBaseLifestyle.SelectedValue.ToString(), _objLifestyle.LifestyleQualities); frmSelectLifestyleQuality.ShowDialog(this); // Don't do anything else if the form was canceled. if (frmSelectLifestyleQuality.DialogResult == DialogResult.Cancel) { frmSelectLifestyleQuality.Close(); return; } blnAddAgain = frmSelectLifestyleQuality.AddAgain; XmlNode objXmlQuality = _xmlDocument.SelectSingleNode("/chummer/qualities/quality[id = \"" + frmSelectLifestyleQuality.SelectedQuality + "\"]"); LifestyleQuality objQuality = new LifestyleQuality(_objCharacter); objQuality.Create(objXmlQuality, _objLifestyle, _objCharacter, QualitySource.Selected); objQuality.Free = frmSelectLifestyleQuality.FreeCost; frmSelectLifestyleQuality.Close(); //objNode.ContextMenuStrip = cmsQuality; if (objQuality.InternalId.IsEmptyGuid()) { continue; } _objLifestyle.LifestyleQualities.Add(objQuality); TreeNode objLoopNode = objQuality.CreateTreeNode(); if (objLoopNode != null) { TreeNode nodParent; // Add the Quality to the appropriate parent node. if (objQuality.Type == QualityType.Positive) { nodParent = treLifestyleQualities.Nodes[0]; } else if (objQuality.Type == QualityType.Negative) { nodParent = treLifestyleQualities.Nodes[1]; } else { nodParent = treLifestyleQualities.Nodes[2]; } nodParent.Nodes.Add(objQuality.CreateTreeNode()); nodParent.Expand(); } CalculateValues(); }while (blnAddAgain); }
private void cmdAddQuality_Click(object sender, EventArgs e) { frmSelectLifestyleQuality frmSelectLifestyleQuality = new frmSelectLifestyleQuality(_objCharacter, cboBaseLifestyle.SelectedValue.ToString()); frmSelectLifestyleQuality.ShowDialog(this); // Don't do anything else if the form was canceled. if (frmSelectLifestyleQuality.DialogResult == DialogResult.Cancel) { return; } XmlDocument objXmlDocument = XmlManager.Load("lifestyles.xml"); XmlNode objXmlQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[id = \"" + frmSelectLifestyleQuality.SelectedQuality + "\"]"); LifestyleQuality objQuality = new LifestyleQuality(_objCharacter); objQuality.Create(objXmlQuality, _objLifestyle, _objCharacter, QualitySource.Selected); //objNode.ContextMenuStrip = cmsQuality; if (objQuality.InternalId == Guid.Empty.ToString()) { return; } objQuality.Free = frmSelectLifestyleQuality.FreeCost; // Make sure that adding the Quality would not cause the character to exceed their BP limits. //bool blnAddItem = true; //if (blnAddItem) { // Add the Quality to the appropriate parent node. if (objQuality.Type == QualityType.Positive) { treLifestyleQualities.Nodes[0].Nodes.Add(objQuality.CreateTreeNode()); treLifestyleQualities.Nodes[0].Expand(); } else if (objQuality.Type == QualityType.Negative) { treLifestyleQualities.Nodes[1].Nodes.Add(objQuality.CreateTreeNode()); treLifestyleQualities.Nodes[1].Expand(); } else { treLifestyleQualities.Nodes[2].Nodes.Add(objQuality.CreateTreeNode()); treLifestyleQualities.Nodes[2].Expand(); } _objLifestyle.LifestyleQualities.Add(objQuality); CalculateValues(); if (frmSelectLifestyleQuality.AddAgain) { cmdAddQuality_Click(sender, e); } } }
private void cboBaseLifestyle_SelectedIndexChanged(object sender, EventArgs e) { if (!_blnSkipRefresh) { string strBaseLifestyle = cboBaseLifestyle.SelectedValue.ToString(); _objLifestyle.BaseLifestyle = strBaseLifestyle; XmlDocument objXmlDocument = XmlManager.Load("lifestyles.xml"); XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + strBaseLifestyle + "\"]"); XmlNodeList objGridNodes = null; if (objXmlAspect != null) { objGridNodes = objXmlAspect.SelectNodes("freegrids/freegrid"); string strSource = objXmlAspect["source"]?.InnerText; if (!string.IsNullOrEmpty(strSource)) { string strPage = objXmlAspect["altpage"]?.InnerText ?? objXmlAspect["page"]?.InnerText; if (!string.IsNullOrEmpty(strPage)) { lblSource.Text = CommonFunctions.LanguageBookShort(strSource, GlobalOptions.Language) + ' ' + strPage; } } } objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/comforts/comfort[name = \"" + strBaseLifestyle + "\"]/limit"); nudComforts.Maximum = Convert.ToInt32(objXmlAspect?.InnerText); // Area. objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/neighborhoods/neighborhood[name = \"" + strBaseLifestyle + "\"]/limit"); nudArea.Maximum = Convert.ToInt32(objXmlAspect?.InnerText); // Security. objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/securities/security[name = \"" + strBaseLifestyle + "\"]/limit"); nudSecurity.Maximum = Convert.ToInt32(objXmlAspect?.InnerText); nudArea.Value = 0; nudComforts.Value = 0; nudSecurity.Value = 0; //This needs a handler for translations, will fix later. if (strBaseLifestyle == "Bolt Hole") { bool blnAddQuality = true; foreach (TreeNode objNode in treLifestyleQualities.Nodes[1].Nodes) { //Bolt Holes automatically come with the Not a Home quality. if (objNode.Name == "Not a Home") { blnAddQuality = false; break; } } if (blnAddQuality) { XmlNode objXmlQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"Not a Home\"]"); LifestyleQuality objQuality = new LifestyleQuality(_objCharacter); objQuality.Create(objXmlQuality, _objLifestyle, _objCharacter, QualitySource.BuiltIn); treLifestyleQualities.Nodes[1].Nodes.Add(objQuality.CreateTreeNode()); treLifestyleQualities.Nodes[1].Expand(); _objLifestyle.LifestyleQualities.Add(objQuality); } } else { //Characters with the Trust Fund Quality can have the lifestyle discounted. if (strBaseLifestyle == "Medium" && (_objCharacter.TrustFund == 1 || _objCharacter.TrustFund == 4)) { chkTrustFund.Visible = true; } else if (strBaseLifestyle == "Low" && _objCharacter.TrustFund == 2) { chkTrustFund.Visible = true; } else if (strBaseLifestyle == "High" && _objCharacter.TrustFund == 3) { chkTrustFund.Visible = true; } else { chkTrustFund.Checked = false; chkTrustFund.Visible = false; if (strBaseLifestyle == "Traveler") { Random rndTavelerLp = MersenneTwister.SfmtRandom.Create(); int intModuloTemp = 0; do { intModuloTemp = rndTavelerLp.Next(); }while (intModuloTemp >= int.MaxValue - 1); // Modulo bias removal for 1d6 _intTravelerRdmLP = 1 + intModuloTemp % 6; } } foreach (LifestyleQuality objQuality in _objLifestyle.LifestyleQualities.ToList()) { if (objQuality.Name == "Not a Home") { _objLifestyle.LifestyleQualities.Remove(objQuality); foreach (TreeNode objNode in treLifestyleQualities.Nodes[1].Nodes) { //Bolt Holes automatically come with the Not a Home quality. if (objNode.Text == "Not a Home") { treLifestyleQualities.Nodes[1].Nodes.Remove(objNode); } } } else if (objQuality.Name == "Dug a Hole") { _objLifestyle.LifestyleQualities.Remove(objQuality); foreach (TreeNode objNode in treLifestyleQualities.Nodes[0].Nodes) { //Bolt Holes automatically come with the Not a Home quality. if (objNode.Text == "Dug a Hole") { treLifestyleQualities.Nodes[1].Nodes.Remove(objNode); } } } } } if (objGridNodes != null) { _objLifestyle.FreeGrids.Clear(); treLifestyleQualities.Nodes[3].Nodes.Clear(); foreach (XmlNode objXmlNode in objGridNodes) { XmlNode objXmlQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlNode.InnerText + "\"]"); LifestyleQuality objQuality = new LifestyleQuality(_objCharacter); string push = objXmlNode.Attributes?["select"]?.InnerText; if (!string.IsNullOrWhiteSpace(push)) { _objCharacter.Pushtext.Push(push); } objQuality.Create(objXmlQuality, _objLifestyle, _objCharacter, QualitySource.BuiltIn); treLifestyleQualities.Nodes[3].Nodes.Add(objQuality.CreateTreeNode()); treLifestyleQualities.Nodes[3].Expand(); _objLifestyle.FreeGrids.Add(objQuality); } } } CalculateValues(); }