Beispiel #1
0
        private void cmdDeleteQuality_Click(object sender, EventArgs e)
        {
            // Locate the selected Quality.
            if (treLifestyleQualities.SelectedNode.Level == 0 || treLifestyleQualities.SelectedNode.Parent.Name == "nodFreeMatrixGrids")
            {
                return;
            }

            string strQualityId = treLifestyleQualities.SelectedNode?.Tag.ToString();

            if (!string.IsNullOrEmpty(strQualityId))
            {
                LifestyleQuality objQuality = _objLifestyle.LifestyleQualities.FirstOrDefault(x => x.InternalId == strQualityId);
                if (objQuality != null)
                {
                    if (objQuality.Name == "Not a Home" && cboBaseLifestyle.SelectedValue?.ToString() == "Bolt Hole")
                    {
                        return;
                    }
                    _objLifestyle.LifestyleQualities.Remove(objQuality);
                    treLifestyleQualities.SelectedNode.Remove();
                    CalculateValues();
                }
            }
        }
Beispiel #2
0
        private async void cmdAddQuality_Click(object sender, EventArgs e)
        {
            bool blnAddAgain;

            do
            {
                using (SelectLifestyleQuality frmSelectLifestyleQuality = new SelectLifestyleQuality(_objCharacter, cboBaseLifestyle.SelectedValue.ToString(), _objLifestyle.LifestyleQualities))
                {
                    await frmSelectLifestyleQuality.ShowDialogSafeAsync(this);

                    // Don't do anything else if the form was canceled.
                    if (frmSelectLifestyleQuality.DialogResult == DialogResult.Cancel)
                    {
                        return;
                    }
                    blnAddAgain = frmSelectLifestyleQuality.AddAgain;

                    XmlNode objXmlQuality = _xmlDocument.SelectSingleNode("/chummer/qualities/quality[id = " + frmSelectLifestyleQuality.SelectedQuality.CleanXPath() + ']');

                    LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);

                    objQuality.Create(objXmlQuality, _objLifestyle, _objCharacter, QualitySource.Selected);
                    //objNode.ContextMenuStrip = cmsQuality;
                    if (objQuality.InternalId.IsEmptyGuid())
                    {
                        objQuality.Remove(false);
                        objQuality.Dispose();
                        continue;
                    }
                    objQuality.Free = frmSelectLifestyleQuality.FreeCost;

                    _objLifestyle.LifestyleQualities.Add(objQuality);
                }
            }while (blnAddAgain);
        }
Beispiel #3
0
        private void treLifestyleQualities_AfterSelect(object sender, TreeViewEventArgs e)
        {
            string           strSelectedQuality = treLifestyleQualities.SelectedNode?.Tag.ToString();
            LifestyleQuality objQuality         = null;

            // Locate the selected Quality.
            if (!string.IsNullOrEmpty(strSelectedQuality))
            {
                objQuality = _objLifestyle.LifestyleQualities.FindById(strSelectedQuality) ?? _objLifestyle.FreeGrids.FindById(strSelectedQuality);
            }
            if (objQuality != null)
            {
                lblQualityLp.Text   = objQuality.LP.ToString();
                lblQualityCost.Text = objQuality.Cost.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                string strPage = objQuality.Page(GlobalOptions.Language);
                lblQualitySource.Text = CommonFunctions.LanguageBookShort(objQuality.Source, GlobalOptions.Language) + ' ' + strPage;
                tipTooltip.SetToolTip(lblQualitySource, CommonFunctions.LanguageBookLong(objQuality.Source, GlobalOptions.Language) + ' ' + LanguageManager.GetString("String_Page", GlobalOptions.Language) + ' ' + strPage);
                cmdDeleteQuality.Enabled = !(objQuality.Free || objQuality.OriginSource == QualitySource.BuiltIn);
            }
            else
            {
                lblQualityLp.Text     = string.Empty;
                lblQualityCost.Text   = string.Empty;
                lblQualitySource.Text = string.Empty;
                tipTooltip.SetToolTip(lblQualitySource, null);
                cmdDeleteQuality.Enabled = false;
            }
        }
        private void treLifestyleQualities_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // Locate the selected Quality.
            lblQualitySource.Text = "";
            lblQualityLp.Text     = "";
            tipTooltip.SetToolTip(lblQualitySource, null);
            try
            {
                if (treLifestyleQualities.SelectedNode.Level == 0)
                {
                    return;
                }
            }
            catch
            {
                return;
            }
            LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);

            objQuality =
                _objFunctions.FindLifestyleQuality(treLifestyleQualities.SelectedNode.Tag.ToString(),
                                                   _objLifestyle.LifestyleQualities) ??
                _objFunctions.FindLifestyleQuality(treLifestyleQualities.SelectedNode.Tag.ToString(),
                                                   _objLifestyle.FreeGrids);
            string strBook = objQuality.Source;
            string strPage = objQuality.Page;

            lblQualityLp.Text     = objQuality.LP.ToString();
            lblQualitySource.Text = strBook + " " + strPage;
            tipTooltip.SetToolTip(lblQualitySource, strBook + " " + LanguageManager.Instance.GetString("String_Page") + " " + strPage);
        }
        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);
                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.Instance.Load("lifestyles.xml");
            XmlNode     objXmlQuality  = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + frmSelectLifestyleQuality.SelectedQuality + "\"]");

            TreeNode         objNode    = new TreeNode();
            LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);

            objQuality.Create(objXmlQuality, _objLifestyle, _objCharacter, QualitySource.Selected, objNode);
            //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(objNode);
                    treLifestyleQualities.Nodes[0].Expand();
                }
                else if (objQuality.Type == QualityType.Negative)
                {
                    treLifestyleQualities.Nodes[1].Nodes.Add(objNode);
                    treLifestyleQualities.Nodes[1].Expand();
                }
                else
                {
                    treLifestyleQualities.Nodes[2].Nodes.Add(objNode);
                    treLifestyleQualities.Nodes[2].Expand();
                }
                _objLifestyle.LifestyleQualities.Add(objQuality);

                CalculateValues();

                if (frmSelectLifestyleQuality.AddAgain)
                {
                    cmdAddQuality_Click(sender, e);
                }
            }
        }
Beispiel #7
0
        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 cboBaseLifestyle_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (!_blnSkipRefresh)
     {
         //This needs a handler for translations, will fix later.
         if (cboBaseLifestyle.SelectedValue.ToString() == "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)
             {
                 XmlDocument      objXmlDocument = XmlManager.Instance.Load("lifestyles.xml");
                 XmlNode          objXmlQuality  = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"Not a Home\"]");
                 LifestyleQuality objQuality     = new LifestyleQuality(_objCharacter);
                 TreeNode         objNode        = new TreeNode();
                 try
                 {
                     objQuality.Create(objXmlQuality, _objCharacter, QualitySource.BuiltIn, objNode);
                 }
                 catch
                 {
                 }
                 objQuality.LP = 0;
                 treLifestyleQualities.Nodes[1].Nodes.Add(objNode);
                 treLifestyleQualities.Nodes[1].Expand();
                 _objLifestyle.LifestyleQualities.Add(objQuality);
             }
         }
         else
         {
             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);
                         }
                     }
                 }
             }
         }
     }
     CalculateValues();
 }
Beispiel #9
0
        /// <summary>
        /// Accept the selected item and close the form.
        /// </summary>
        private void AcceptForm()
        {
            string strSelectedId = cboLifestyle.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                XmlNode objXmlLifestyle = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[id = " + strSelectedId.CleanXPath() + ']');
                if (objXmlLifestyle == null)
                {
                    return;
                }

                _objLifestyle.Source        = objXmlLifestyle["source"]?.InnerText;
                _objLifestyle.Page          = objXmlLifestyle["page"]?.InnerText;
                _objLifestyle.Name          = txtLifestyleName.Text;
                _objLifestyle.BaseLifestyle = objXmlLifestyle["name"]?.InnerText;
                _objLifestyle.Cost          = Convert.ToDecimal(objXmlLifestyle["cost"]?.InnerText, GlobalSettings.InvariantCultureInfo);
                _objLifestyle.Roommates     = _objLifestyle.TrustFund ? 0 : nudRoommates.ValueAsInt;
                _objLifestyle.Percentage    = nudPercentage.Value;
                _objLifestyle.LifestyleQualities.Clear();
                _objLifestyle.StyleType     = StyleType;
                _objLifestyle.Dice          = Convert.ToInt32(objXmlLifestyle["dice"]?.InnerText, GlobalSettings.InvariantCultureInfo);
                _objLifestyle.Multiplier    = Convert.ToDecimal(objXmlLifestyle["multiplier"]?.InnerText, GlobalSettings.InvariantCultureInfo);
                _objLifestyle.PrimaryTenant = chkPrimaryTenant.Checked;
                _objLifestyle.TrustFund     = chkTrustFund.Checked;
                _objLifestyle.City          = cboCity.Text;
                _objLifestyle.District      = cboDistrict.Text;
                _objLifestyle.Borough       = cboBorough.Text;

                if (objXmlLifestyle.TryGetField("id", Guid.TryParse, out Guid source))
                {
                    _objLifestyle.SourceID = source;
                }
                else
                {
                    Log.Warn(new object[] { "Missing id field for xmlnode", objXmlLifestyle });
                    Utils.BreakIfDebug();
                }
                foreach (TreeNode objNode in treQualities.Nodes)
                {
                    if (!objNode.Checked)
                    {
                        continue;
                    }
                    XmlNode          objXmlLifestyleQuality = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[id = " + objNode.Tag.ToString().CleanXPath() + ']');
                    LifestyleQuality objQuality             = new LifestyleQuality(_objCharacter);
                    objQuality.Create(objXmlLifestyleQuality, _objLifestyle, _objCharacter, QualitySource.Selected);
                    _objLifestyle.LifestyleQualities.Add(objQuality);
                }
                DialogResult = DialogResult.OK;
            }
        }
        /// <summary>
        /// Accept the selected item and close the form.
        /// </summary>
        private void AcceptForm()
        {
            string strSelectedId = cboLifestyle.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                XmlNode objXmlLifestyle = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[id = \"" + strSelectedId + "\"]");
                if (objXmlLifestyle == null)
                {
                    return;
                }

                _objLifestyle.Source        = objXmlLifestyle["source"]?.InnerText;
                _objLifestyle.Page          = objXmlLifestyle["page"]?.InnerText;
                _objLifestyle.Name          = txtLifestyleName.Text;
                _objLifestyle.BaseLifestyle = objXmlLifestyle["name"]?.InnerText;
                _objLifestyle.Cost          = Convert.ToDecimal(objXmlLifestyle["cost"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                _objLifestyle.Roommates     = _objLifestyle.TrustFund ? 0 : decimal.ToInt32(nudRoommates.Value);
                _objLifestyle.Percentage    = nudPercentage.Value;
                _objLifestyle.LifestyleQualities.Clear();
                _objLifestyle.StyleType  = StyleType;
                _objLifestyle.Dice       = Convert.ToInt32(objXmlLifestyle["dice"]?.InnerText);
                _objLifestyle.Multiplier = Convert.ToDecimal(objXmlLifestyle["multiplier"]?.InnerText, GlobalOptions.InvariantCultureInfo);

                if (objXmlLifestyle.TryGetField("id", Guid.TryParse, out Guid source))
                {
                    _objLifestyle.SourceID = source;
                }
                else
                {
                    Log.Warning(new object[] { "Missing id field for lifestyle xmlnode", objXmlLifestyle });
                    Utils.BreakIfDebug();
                }
                foreach (TreeNode objNode in treQualities.Nodes)
                {
                    if (objNode.Checked)
                    {
                        XmlNode          objXmlLifestyleQuality = _objXmlDocument.SelectSingleNode($"/chummer/qualities/quality[id = \"{objNode.Tag}\"]");
                        LifestyleQuality objQuality             = new LifestyleQuality(_objCharacter);
                        objQuality.Create(objXmlLifestyleQuality, _objLifestyle, _objCharacter, QualitySource.Selected, objNode.Text);
                        _objLifestyle.LifestyleQualities.Add(objQuality);
                    }
                }
                DialogResult = DialogResult.OK;
            }
        }
Beispiel #11
0
        /// <summary>
        /// Accept the selected item and close the form.
        /// </summary>
        private void AcceptForm()
        {
            XmlNode objXmlLifestyle = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboLifestyle.SelectedValue + "\"]");

            _objLifestyle.Source        = objXmlLifestyle["source"].InnerText;
            _objLifestyle.Page          = objXmlLifestyle["page"].InnerText;
            _objLifestyle.Name          = txtLifestyleName.Text;
            _objLifestyle.LifestyleName = cboLifestyle.SelectedValue.ToString();
            _objLifestyle.BaseLifestyle = cboLifestyle.SelectedValue.ToString();
            _objLifestyle.Cost          = Convert.ToInt32(objXmlLifestyle["cost"].InnerText);
            _objLifestyle.Roommates     = Convert.ToInt32(nudRoommates.Value);
            _objLifestyle.Percentage    = Convert.ToInt32(nudPercentage.Value);
            _objLifestyle.LifestyleQualities.Clear();
            _objLifestyle.StyleType  = _objType;
            _objLifestyle.Dice       = Convert.ToInt32(objXmlLifestyle["dice"].InnerText);
            _objLifestyle.Multiplier = Convert.ToInt32(objXmlLifestyle["multiplier"].InnerText);

            Guid source;

            if (objXmlLifestyle.TryGetField("id", Guid.TryParse, out source))
            {
                _objLifestyle.SourceID = source;
            }
            else
            {
                Log.Warning(new object[] { "Missing id field for lifestyle xmlnode", objXmlLifestyle });
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }
            }
            foreach (TreeNode objNode in treQualities.Nodes)
            {
                if (objNode.Checked)
                {
                    XmlNode          objXmlLifestyleQuality = _objXmlDocument.SelectSingleNode($"/chummer/qualities/quality[id = \"{objNode.Tag}\"]");
                    LifestyleQuality objQuality             = new LifestyleQuality(_objCharacter);
                    objQuality.Create(objXmlLifestyleQuality, _objLifestyle, _objCharacter, QualitySource.Selected, objNode);
                    _objLifestyle.LifestyleQualities.Add(objQuality);
                }
            }
            DialogResult = DialogResult.OK;
        }
        private void treLifestyleQualities_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // Locate the selected Quality.
            if (treLifestyleQualities.SelectedNode == null || treLifestyleQualities.SelectedNode.Level == 0)
            {
                lblQualityLp.Text     = string.Empty;
                lblQualityCost.Text   = string.Empty;
                lblQualitySource.Text = string.Empty;
                tipTooltip.SetToolTip(lblQualitySource, null);
                cmdDeleteQuality.Enabled = false;
                return;
            }
            string           strSelectedQuality = treLifestyleQualities.SelectedNode.Tag.ToString();
            LifestyleQuality objQuality         = _objLifestyle.LifestyleQualities.FindById(strSelectedQuality) ?? _objLifestyle.FreeGrids.FindById(strSelectedQuality);

            lblQualityLp.Text     = objQuality.LP.ToString();
            lblQualityCost.Text   = objQuality.Cost.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
            lblQualitySource.Text = $@"{objQuality.Source} {objQuality.Page(GlobalOptions.Language)}";
            tipTooltip.SetToolTip(lblQualitySource, objQuality.SourceTooltip);
            cmdDeleteQuality.Enabled = !(objQuality.Free || objQuality.OriginSource == QualitySource.BuiltIn);
        }
Beispiel #13
0
        /// <summary>
        /// Accept the selected item and close the form.
        /// </summary>
        private void AcceptForm()
        {
            _objLifestyle.Source        = "SR5";
            _objLifestyle.Page          = "373";
            _objLifestyle.Name          = txtLifestyleName.Text;
            _objLifestyle.BaseLifestyle = cboLifestyle.SelectedValue.ToString();
            _objLifestyle.Cost          = CalculateValues(false);
            _objLifestyle.Roommates     = Convert.ToInt32(nudRoommates.Value);
            _objLifestyle.Percentage    = Convert.ToInt32(nudPercentage.Value);
            _objLifestyle.LifestyleQualities.Clear();
            _objLifestyle.StyleType = _objType;

            Guid    source;
            XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboLifestyle.SelectedValue + "\"]");

            if (objXmlAspect.TryGetField("id", Guid.TryParse, out source))
            {
                _objLifestyle.SourceID = source;
            }
            else
            {
                Log.Warning(new object[] { "Missing id field for lifestyle xmlnode", objXmlAspect });
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }
            }
            foreach (TreeNode objNode in treQualities.Nodes)
            {
                if (objNode.Checked)
                {
                    XmlNode          objXmlLifestyleQuality = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + GetQualityName(objNode.Tag.ToString()) + "\"]");
                    LifestyleQuality objQuality             = new LifestyleQuality(_objCharacter);
                    _objLifestyle.LifestyleQualities.Add(objQuality);
                    objQuality.Create(objXmlLifestyleQuality, _objCharacter, QualitySource.Selected, objNode);
                }
            }
            this.DialogResult = DialogResult.OK;
        }
        private void treLifestyleQualities_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // Locate the selected Quality.
            lblQualitySource.Text = "";
            lblQualityLp.Text     = "";
            tipTooltip.SetToolTip(lblQualitySource, null);
            if (treLifestyleQualities.SelectedNode == null || treLifestyleQualities.SelectedNode.Level == 0)
            {
                return;
            }
            LifestyleQuality objQuality =
                CommonFunctions.FindByIdWithNameCheck(treLifestyleQualities.SelectedNode.Tag.ToString(),
                                                      _objLifestyle.LifestyleQualities) ??
                CommonFunctions.FindByIdWithNameCheck(treLifestyleQualities.SelectedNode.Tag.ToString(),
                                                      _objLifestyle.FreeGrids);

            lblQualityLp.Text     = objQuality.LP.ToString();
            lblQualityCost.Text   = $"{objQuality.Cost:###,###,##0¥}";
            lblQualitySource.Text = $@"{objQuality.Source} {objQuality.Page}";
            tipTooltip.SetToolTip(lblQualitySource, objQuality.SourceTooltip);
            cmdDeleteQuality.Enabled = !(objQuality.Free || objQuality.OriginSource == QualitySource.BuiltIn);
        }
 private void treLifestyleQualities_AfterSelect(object sender, TreeViewEventArgs e)
 {
     // Locate the selected Quality.
     lblQualitySource.Text = "";
     lblQualityLp.Text = "";
     tipTooltip.SetToolTip(lblQualitySource, null);
     try
     {
         if (treLifestyleQualities.SelectedNode.Level == 0)
             return;
     }
     catch
     {
         return;
     }
     LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);
     objQuality =
             _objFunctions.FindLifestyleQuality(treLifestyleQualities.SelectedNode.Tag.ToString(),
                 _objLifestyle.LifestyleQualities) ??
             _objFunctions.FindLifestyleQuality(treLifestyleQualities.SelectedNode.Tag.ToString(),
                     _objLifestyle.FreeGrids);
     string strBook = objQuality.Source;
     string strPage = objQuality.Page;
     lblQualityLp.Text = objQuality.LP.ToString();
     lblQualitySource.Text = strBook + " " + strPage;
     tipTooltip.SetToolTip(lblQualitySource, strBook + " " + LanguageManager.Instance.GetString("String_Page") + " " + strPage);
 }
Beispiel #16
0
        private void cboBaseLifestyle_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!_blnSkipRefresh)
            {
                XmlDocument objXmlDocument = XmlManager.Instance.Load("lifestyles.xml");
                XmlNode     objXmlAspect   = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                lblSource.Text = objXmlAspect["source"].InnerText + " " + objXmlAspect["page"].InnerText;

                objXmlAspect        = _objXmlDocument.SelectSingleNode("/chummer/comforts/comfort[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                nudComforts.Minimum = Convert.ToInt32(objXmlAspect["minimum"].InnerText);
                nudComforts.Value   = Convert.ToInt32(objXmlAspect["minimum"].InnerText);
                // Area.
                objXmlAspect    = _objXmlDocument.SelectSingleNode("/chummer/neighborhoods/neighborhood[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                nudArea.Minimum = Convert.ToInt32(objXmlAspect["minimum"].InnerText);
                nudArea.Value   = Convert.ToInt32(objXmlAspect["minimum"].InnerText);
                // Security.
                objXmlAspect        = _objXmlDocument.SelectSingleNode("/chummer/securities/security[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                nudSecurity.Minimum = Convert.ToInt32(objXmlAspect["minimum"].InnerText);
                nudSecurity.Value   = Convert.ToInt32(objXmlAspect["minimum"].InnerText);


                //This needs a handler for translations, will fix later.
                if (cboBaseLifestyle.SelectedValue.ToString() == "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);
                        TreeNode         objNode       = new TreeNode();
                        try
                        {
                            objQuality.Create(objXmlQuality, _objCharacter, QualitySource.BuiltIn, objNode);
                        }
                        catch
                        {
                        }
                        objQuality.LP = 0;
                        treLifestyleQualities.Nodes[1].Nodes.Add(objNode);
                        treLifestyleQualities.Nodes[1].Expand();
                        _objLifestyle.LifestyleQualities.Add(objQuality);
                    }
                }
                else
                {
                    if (cboBaseLifestyle.SelectedValue.ToString() == "Traveler")
                    {
                        Random rndTavelerLp = new Random();
                        _intTravelerRdmLP = rndTavelerLp.Next(1, 7);
                    }
                    //Characters with the Trust Fund Quality can have the lifestyle discounted.
                    if (_objCharacter.TrustFund == 1 && cboBaseLifestyle.SelectedValue.ToString() == "Medium")
                    {
                        chkTrustFund.Visible = true;
                    }
                    else if (_objCharacter.TrustFund == 2 && cboBaseLifestyle.SelectedValue.ToString() == "Low")
                    {
                        chkTrustFund.Visible = true;
                    }
                    else if (_objCharacter.TrustFund == 3 && cboBaseLifestyle.SelectedValue.ToString() == "High")
                    {
                        chkTrustFund.Visible = true;
                    }
                    else if (_objCharacter.TrustFund == 4 && cboBaseLifestyle.SelectedValue.ToString() == "Medium")
                    {
                        chkTrustFund.Visible = true;
                    }
                    else
                    {
                        chkTrustFund.Checked = false;
                        chkTrustFund.Visible = false;
                    }

                    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);
                                }
                            }
                        }
                    }
                }
            }
            CalculateValues();
        }
        private void cboBaseLifestyle_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!_blnSkipRefresh)
            {
                _objLifestyle.BaseLifestyle = cboBaseLifestyle.SelectedValue.ToString();
                XmlDocument objXmlDocument = XmlManager.Instance.Load("lifestyles.xml");
                XmlNode     objXmlAspect   = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                if (objXmlAspect?["source"] != null && objXmlAspect["page"] != null)
                {
                    lblSource.Text = objXmlAspect["source"].InnerText + " " + objXmlAspect["page"].InnerText;
                }

                objXmlAspect        = _objXmlDocument.SelectSingleNode("/chummer/comforts/comfort[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                nudComforts.Minimum = objXmlAspect?["minimum"] != null?Convert.ToInt32(objXmlAspect["minimum"].InnerText) : 0;

                nudComforts.Value = nudComforts.Minimum;
                // Area.
                objXmlAspect    = _objXmlDocument.SelectSingleNode("/chummer/neighborhoods/neighborhood[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                nudArea.Minimum = objXmlAspect?["minimum"] != null?Convert.ToInt32(objXmlAspect["minimum"].InnerText) : 0;

                nudArea.Value = nudArea.Minimum;
                // Security.
                objXmlAspect        = _objXmlDocument.SelectSingleNode("/chummer/securities/security[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                nudSecurity.Minimum = objXmlAspect?["minimum"] != null?Convert.ToInt32(objXmlAspect["minimum"].InnerText) : 0;

                nudSecurity.Value = nudSecurity.Minimum;


                //This needs a handler for translations, will fix later.
                if (cboBaseLifestyle.SelectedValue.ToString() == "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);
                        TreeNode         objNode       = new TreeNode();
                        objQuality.Create(objXmlQuality, _objLifestyle, _objCharacter, QualitySource.BuiltIn, objNode);
                        treLifestyleQualities.Nodes[1].Nodes.Add(objNode);
                        treLifestyleQualities.Nodes[1].Expand();
                        _objLifestyle.LifestyleQualities.Add(objQuality);
                    }
                }
                else
                {
                    if (cboBaseLifestyle.SelectedValue.ToString() == "Traveler")
                    {
                        Random rndTavelerLp = MersenneTwister.SfmtRandom.Create();
                        _intTravelerRdmLP = rndTavelerLp.Next(1, 7);
                    }
                    //Characters with the Trust Fund Quality can have the lifestyle discounted.
                    if (cboBaseLifestyle.SelectedValue.ToString() == "Medium" &&
                        (_objCharacter.TrustFund == 1 || _objCharacter.TrustFund == 4))
                    {
                        chkTrustFund.Visible = true;
                    }
                    else if (cboBaseLifestyle.SelectedValue.ToString() == "Low" &&
                             _objCharacter.TrustFund == 2)
                    {
                        chkTrustFund.Visible = true;
                    }
                    else if (cboBaseLifestyle.SelectedValue.ToString() == "High" &&
                             _objCharacter.TrustFund == 3)
                    {
                        chkTrustFund.Visible = true;
                    }
                    else
                    {
                        chkTrustFund.Checked = false;
                        chkTrustFund.Visible = false;
                    }

                    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);
                                }
                            }
                        }
                    }
                }

                XmlNode     objLifestyleNode = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                XmlNodeList objGridNodes     = objLifestyleNode?.SelectNodes("freegrids/freegrid");
                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);
                        TreeNode         objNode       = new TreeNode();
                        string           push          = objXmlNode.Attributes?["select"]?.InnerText;
                        if (!string.IsNullOrWhiteSpace(push))
                        {
                            _objCharacter.Pushtext.Push(push);
                        }
                        objQuality.Create(objXmlQuality, _objLifestyle, _objCharacter, QualitySource.BuiltIn, objNode);
                        objNode.Text = objQuality.DisplayName;
                        treLifestyleQualities.Nodes[3].Nodes.Add(objNode);
                        treLifestyleQualities.Nodes[3].Expand();
                        _objLifestyle.FreeGrids.Add(objQuality);
                    }
                }
            }
            CalculateValues();
        }
        private void cmdAddQuality_Click(object sender, EventArgs e)
        {
            frmSelectLifestyleQuality frmSelectLifestyleQuality = new frmSelectLifestyleQuality(_objCharacter);
            frmSelectLifestyleQuality.ShowDialog(this);

                        // Don't do anything else if the form was canceled.
            if (frmSelectLifestyleQuality.DialogResult == DialogResult.Cancel)
                return;

            XmlDocument objXmlDocument = XmlManager.Instance.Load("lifestyles.xml");
            XmlNode objXmlQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + frmSelectLifestyleQuality.SelectedQuality + "\"]");

            TreeNode objNode = new TreeNode();
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);

            try { objQuality.Create(objXmlQuality, _objCharacter, QualitySource.Selected, objNode); }
            catch { }
            //objNode.ContextMenuStrip = cmsQuality;
            if (objQuality.InternalId == Guid.Empty.ToString())
                return;

            if (frmSelectLifestyleQuality.FreeCost)
                objQuality.LP = 0;

            // If the item being checked would cause the limit of 25 BP spent on Positive Qualities to be exceed, do not let it be checked and display a message.
            string strAmount = "";
            strAmount = "25 " + LanguageManager.Instance.GetString("String_Karma");

            // 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(objNode);
                    treLifestyleQualities.Nodes[0].Expand();
                }
                else if (objQuality.Type == QualityType.Negative)
                {
                    treLifestyleQualities.Nodes[1].Nodes.Add(objNode);
                    treLifestyleQualities.Nodes[1].Expand();
                }
                else
                {
                    treLifestyleQualities.Nodes[2].Nodes.Add(objNode);
                    treLifestyleQualities.Nodes[2].Expand();
                }
                //_objLifestyle.LifestyleQualities.Add(objQuality);

                CalculateValues();

                if (frmSelectLifestyleQuality.AddAgain)
                    cmdAddQuality_Click(sender, e);
            }
        }
        /// <summary>
        /// Accept the selected item and close the form.
        /// </summary>
        private void AcceptForm()
        {
            _objLifestyle.Source                = "RF";
            _objLifestyle.Page                  = "154";
            _objLifestyle.Name                  = txtLifestyleName.Text;
            _objLifestyle.Cost                  = CalculateValues();
            _objLifestyle.Roommates             = Convert.ToInt32(nudRoommates.Value);
            _objLifestyle.Percentage            = Convert.ToInt32(nudPercentage.Value);
            _objLifestyle.BaseLifestyle         = cboBaseLifestyle.Text;
            _objLifestyle.Area                  = Convert.ToInt32(nudArea.Value);
            _objLifestyle.AreaEntertainment     = Convert.ToInt32(nudAreaEntertainment.Value);
            _objLifestyle.Comforts              = Convert.ToInt32(nudComforts.Value);
            _objLifestyle.ComfortsEntertainment = Convert.ToInt32(nudComfortsEntertainment.Value);
            _objLifestyle.Security              = Convert.ToInt32(nudSecurity.Value);
            _objLifestyle.SecurityEntertainment = Convert.ToInt32(nudSecurityEntertainment.Value);
            _objLifestyle.BaseLifestyle         = cboBaseLifestyle.SelectedValue.ToString();

            // Get the starting Nuyen information.
            XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");

            _objLifestyle.Dice       = Convert.ToInt32(objXmlAspect["dice"].InnerText);
            _objLifestyle.Multiplier = Convert.ToInt32(objXmlAspect["multiplier"].InnerText);
            _objLifestyle.StyleType  = _objType;

            XmlDocument objXmlDocument = XmlManager.Instance.Load("lifestyles.xml");

            Guid source;

            if (objXmlAspect.TryGetField("id", Guid.TryParse, out source))
            {
                _objLifestyle.SourceID = source;
            }
            else
            {
                Log.Warning(new object[] { "Missing id field for lifestyle xmlnode", objXmlAspect });
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }
            }

            foreach (TreeNode objNode in treLifestyleQualities.Nodes[0].Nodes)
            {
                XmlNode          objXmlLifestyleQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objNode.Text + "\"]");
                LifestyleQuality objQuality             = new LifestyleQuality(_objCharacter);

                objQuality.Create(objXmlLifestyleQuality, _objCharacter, QualitySource.Selected, objNode);
            }
            foreach (TreeNode objNode in treLifestyleQualities.Nodes[1].Nodes)
            {
                if ((objNode.Text == "Not a Home") && (_objLifestyle.BaseLifestyle == "Bolt Hole"))
                {
                    //Already handled as part of the Bolt Hole shenanigans, doesn't need to be added again.
                }
                else
                {
                    XmlNode          objXmlLifestyleQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objNode.Text + "\"]");
                    LifestyleQuality objQuality             = new LifestyleQuality(_objCharacter);

                    objQuality.Create(objXmlLifestyleQuality, _objCharacter, QualitySource.Selected, objNode);
                }
            }
            foreach (TreeNode objNode in treLifestyleQualities.Nodes[2].Nodes)
            {
                XmlNode          objXmlLifestyleQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objNode.Text + "\"]");
                LifestyleQuality objQuality             = new LifestyleQuality(_objCharacter);

                objQuality.Create(objXmlLifestyleQuality, _objCharacter, QualitySource.Selected, objNode);
            }
            this.DialogResult = DialogResult.OK;
        }
Beispiel #20
0
        private void cmdAddQuality_Click(object sender, EventArgs e)
        {
            frmSelectLifestyleQuality frmSelectLifestyleQuality = new frmSelectLifestyleQuality(_objCharacter);

            frmSelectLifestyleQuality.ShowDialog(this);

            // Don't do anything else if the form was canceled.
            if (frmSelectLifestyleQuality.DialogResult == DialogResult.Cancel)
            {
                return;
            }

            XmlDocument objXmlDocument = XmlManager.Instance.Load("lifestyles.xml");
            XmlNode     objXmlQuality  = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + frmSelectLifestyleQuality.SelectedQuality + "\"]");

            TreeNode         objNode        = new TreeNode();
            List <Weapon>    objWeapons     = new List <Weapon>();
            List <TreeNode>  objWeaponNodes = new List <TreeNode>();
            LifestyleQuality objQuality     = new LifestyleQuality(_objCharacter);

            try { objQuality.Create(objXmlQuality, _objCharacter, QualitySource.Selected, objNode); }
            catch { }
            //objNode.ContextMenuStrip = cmsQuality;
            if (objQuality.InternalId == Guid.Empty.ToString())
            {
                return;
            }

            if (frmSelectLifestyleQuality.FreeCost)
            {
                objQuality.LP = 0;
            }

            // If the item being checked would cause the limit of 25 BP spent on Positive Qualities to be exceed, do not let it be checked and display a message.
            string strAmount = "";

            strAmount = "25 " + LanguageManager.Instance.GetString("String_Karma");

            // 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(objNode);
                    treLifestyleQualities.Nodes[0].Expand();
                }
                else if (objQuality.Type == QualityType.Negative)
                {
                    treLifestyleQualities.Nodes[1].Nodes.Add(objNode);
                    treLifestyleQualities.Nodes[1].Expand();
                }
                else
                {
                    treLifestyleQualities.Nodes[2].Nodes.Add(objNode);
                    treLifestyleQualities.Nodes[2].Expand();
                }
                //_objLifestyle.LifestyleQualities.Add(objQuality);

                CalculateValues();

                if (frmSelectLifestyleQuality.AddAgain)
                {
                    cmdAddQuality_Click(sender, e);
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Accept the selected item and close the form.
        /// </summary>
        private async ValueTask AcceptForm()
        {
            string strSelectedId = await cboLifestyle.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString());

            if (string.IsNullOrEmpty(strSelectedId))
            {
                return;
            }
            XmlNode objXmlLifestyle = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[id = " + strSelectedId.CleanXPath() + ']');

            if (objXmlLifestyle == null)
            {
                return;
            }

            _objLifestyle.Source = objXmlLifestyle["source"]?.InnerText;
            _objLifestyle.Page   = objXmlLifestyle["page"]?.InnerText;
            _objLifestyle.Name   = await txtLifestyleName.DoThreadSafeFuncAsync(x => x.Text);

            _objLifestyle.BaseLifestyle = objXmlLifestyle["name"]?.InnerText;
            _objLifestyle.Cost          = Convert.ToDecimal(objXmlLifestyle["cost"]?.InnerText, GlobalSettings.InvariantCultureInfo);
            _objLifestyle.Roommates     = _objLifestyle.TrustFund ? 0 : await nudRoommates.DoThreadSafeFuncAsync(x => x.ValueAsInt);

            _objLifestyle.Percentage = await nudPercentage.DoThreadSafeFuncAsync(x => x.Value);

            _objLifestyle.StyleType     = StyleType;
            _objLifestyle.Dice          = Convert.ToInt32(objXmlLifestyle["dice"]?.InnerText, GlobalSettings.InvariantCultureInfo);
            _objLifestyle.Multiplier    = Convert.ToDecimal(objXmlLifestyle["multiplier"]?.InnerText, GlobalSettings.InvariantCultureInfo);
            _objLifestyle.PrimaryTenant = await chkPrimaryTenant.DoThreadSafeFuncAsync(x => x.Checked);

            _objLifestyle.TrustFund = await chkTrustFund.DoThreadSafeFuncAsync(x => x.Checked);

            _objLifestyle.City = await cboCity.DoThreadSafeFuncAsync(x => x.Text);

            _objLifestyle.District = await cboDistrict.DoThreadSafeFuncAsync(x => x.Text);

            _objLifestyle.Borough = await cboBorough.DoThreadSafeFuncAsync(x => x.Text);

            if (objXmlLifestyle.TryGetField("id", Guid.TryParse, out Guid source))
            {
                _objLifestyle.SourceID = source;
            }
            else
            {
                Log.Warn(new object[] { "Missing id field for xmlnode", objXmlLifestyle });
                Utils.BreakIfDebug();
            }

            HashSet <string> setLifestyleQualityIds = new HashSet <string>();

            foreach (TreeNode objNode in await treQualities.DoThreadSafeFuncAsync(x => x.Nodes))
            {
                if (!objNode.Checked)
                {
                    continue;
                }
                string strLoopId = objNode.Tag.ToString();
                setLifestyleQualityIds.Add(strLoopId);
                if (_objLifestyle.LifestyleQualities.Any(x => x.SourceIDString == strLoopId))
                {
                    continue;
                }
                XmlNode          objXmlLifestyleQuality = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[id = " + strLoopId.CleanXPath() + ']');
                LifestyleQuality objQuality             = new LifestyleQuality(_objCharacter);
                objQuality.Create(objXmlLifestyleQuality, _objLifestyle, _objCharacter, QualitySource.Selected);
                await _objLifestyle.LifestyleQualities.AddAsync(objQuality);
            }

            foreach (LifestyleQuality objLifestyleQuality in _objLifestyle.LifestyleQualities.Where(x =>
                                                                                                    !setLifestyleQualityIds.Contains(x.SourceIDString)).ToList())
            {
                objLifestyleQuality.Remove(false);
            }

            DialogResult = DialogResult.OK;
        }
        /// <summary>
        /// Accept the selected item and close the form.
        /// </summary>
        private void AcceptForm()
        {
            XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboLifestyle.SelectedValue + "\"]");
            _objLifestyle.Source = "SR5";
            _objLifestyle.Page = "373";
            _objLifestyle.Name = txtLifestyleName.Text;
            _objLifestyle.BaseLifestyle = cboLifestyle.SelectedValue.ToString();
            _objLifestyle.Cost = Convert.ToInt32(objXmlAspect["cost"].InnerText);
            _objLifestyle.Roommates = Convert.ToInt32(nudRoommates.Value);
            _objLifestyle.Percentage = Convert.ToInt32(nudPercentage.Value);
            _objLifestyle.LifestyleQualities.Clear();
            _objLifestyle.StyleType = _objType;

            Guid source;
            if (objXmlAspect.TryGetField("id", Guid.TryParse, out source))
            {
                _objLifestyle.SourceID = source;
            }
            else
            {
                Log.Warning(new object[] { "Missing id field for lifestyle xmlnode", objXmlAspect });
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }
            }
            foreach (TreeNode objNode in treQualities.Nodes)
            {
                if (objNode.Checked)
                {
                    XmlNode objXmlLifestyleQuality = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + GetQualityName(objNode.Tag.ToString()) + "\"]");
                    LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);
                    _objLifestyle.LifestyleQualities.Add(objQuality);
                    objQuality.Create(objXmlLifestyleQuality, _objCharacter, QualitySource.Selected, objNode);
                }
            }
            this.DialogResult = DialogResult.OK;
        }
        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();
        }
        private void cboBaseLifestyle_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!_blnSkipRefresh)
            {
                XmlDocument objXmlDocument = XmlManager.Instance.Load("lifestyles.xml");
                XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                lblSource.Text = objXmlAspect["source"].InnerText+ " " + objXmlAspect["page"].InnerText;

                objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/comforts/comfort[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                nudComforts.Minimum = Convert.ToInt32(objXmlAspect["minimum"].InnerText);
                nudComforts.Value = Convert.ToInt32(objXmlAspect["minimum"].InnerText);
                // Area.
                objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/neighborhoods/neighborhood[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                nudArea.Minimum = Convert.ToInt32(objXmlAspect["minimum"].InnerText);
                nudArea.Value = Convert.ToInt32(objXmlAspect["minimum"].InnerText);
                // Security.
                objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/securities/security[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                nudSecurity.Minimum = Convert.ToInt32(objXmlAspect["minimum"].InnerText);
                nudSecurity.Value = Convert.ToInt32(objXmlAspect["minimum"].InnerText);

                //This needs a handler for translations, will fix later.
                if (cboBaseLifestyle.SelectedValue.ToString() == "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);
                        TreeNode objNode = new TreeNode();
                        try
                        {
                            objQuality.Create(objXmlQuality, _objCharacter, QualitySource.BuiltIn, objNode);
                        }
                        catch
                        {
                        }
                        objQuality.LP = 0;
                        treLifestyleQualities.Nodes[1].Nodes.Add(objNode);
                        treLifestyleQualities.Nodes[1].Expand();
                        _objLifestyle.LifestyleQualities.Add(objQuality);
                    }
                }
                else
                {
                    if (cboBaseLifestyle.SelectedValue.ToString() == "Traveler")
                    {
                        Random rndTavelerLp = new Random();
                        _intTravelerRdmLP = rndTavelerLp.Next(1, 7);
                    }
                    //Characters with the Trust Fund Quality can have the lifestyle discounted.
                    if (_objCharacter.TrustFund == 1 && cboBaseLifestyle.SelectedValue.ToString() == "Medium")
                    {
                        chkTrustFund.Visible = true;
                    }
                    else if (_objCharacter.TrustFund == 2 && cboBaseLifestyle.SelectedValue.ToString() == "Low")
                    {
                        chkTrustFund.Visible = true;
                    }
                    else if (_objCharacter.TrustFund == 3 && cboBaseLifestyle.SelectedValue.ToString() == "High")
                    {
                        chkTrustFund.Visible = true;
                    }
                    else if (_objCharacter.TrustFund == 4 && cboBaseLifestyle.SelectedValue.ToString() == "Medium")
                    {
                        chkTrustFund.Visible = true;
                    }
                    else
                    {
                        chkTrustFund.Checked = false;
                        chkTrustFund.Visible = false;
                    }

                    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);
                                }
                            }
                        }

                    }
                }

                XmlNode objLifestyleNode = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
                XmlNodeList objGridNodes = objLifestyleNode.SelectNodes("freegrids/freegrid");
                _objLifestyle.FreeGrids.Clear();
                treLifestyleQualities.Nodes[3].Nodes.Clear();
                if (objGridNodes != null)
                {
                    foreach (XmlNode objXmlNode in objGridNodes)
                    {
                        XmlNode objXmlQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlNode.InnerText + "\"]");
                        LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);
                        TreeNode objNode = new TreeNode();
                        try
                        {

                            if (objXmlNode.Attributes["select"] != null)
                            {
                                String push = objXmlNode.Attributes["select"].InnerText;
                                if (!String.IsNullOrWhiteSpace(push))
                                {
                                    _objCharacter.Pushtext.Push(push);
                                }
                            }
                            objQuality.Create(objXmlQuality, _objCharacter, QualitySource.BuiltIn, objNode);
                        }
                        catch
                        {
                        }
                        objQuality.LP = 0;
                        objNode.Text = objQuality.DisplayName;
                        treLifestyleQualities.Nodes[3].Nodes.Add(objNode);
                        treLifestyleQualities.Nodes[3].Expand();
                        _objLifestyle.FreeGrids.Add(objQuality);
                    }
                }
            }
            CalculateValues();
        }
        /// <summary>
        /// Accept the selected item and close the form.
        /// </summary>
        private void AcceptForm()
        {
            _objLifestyle.Source = "RF";
            _objLifestyle.Page = "154";
            _objLifestyle.Name = txtLifestyleName.Text;
            _objLifestyle.Cost = CalculateValues();
            _objLifestyle.Roommates = Convert.ToInt32(nudRoommates.Value);
            _objLifestyle.Percentage = Convert.ToInt32(nudPercentage.Value);
            _objLifestyle.BaseLifestyle = cboBaseLifestyle.Text;
            _objLifestyle.Area = Convert.ToInt32(nudArea.Value);
            _objLifestyle.AreaEntertainment = Convert.ToInt32(nudAreaEntertainment.Value);
            _objLifestyle.Comforts = Convert.ToInt32(nudComforts.Value);
            _objLifestyle.ComfortsEntertainment = Convert.ToInt32(nudComfortsEntertainment.Value);
            _objLifestyle.Security = Convert.ToInt32(nudSecurity.Value);
            _objLifestyle.SecurityEntertainment = Convert.ToInt32(nudSecurityEntertainment.Value);
            _objLifestyle.BaseLifestyle = cboBaseLifestyle.SelectedValue.ToString();
            _objLifestyle.TrustFund = chkTrustFund.Checked;

            // Get the starting Nuyen information.
            XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboBaseLifestyle.SelectedValue + "\"]");
            _objLifestyle.Dice = Convert.ToInt32(objXmlAspect["dice"].InnerText);
            _objLifestyle.Multiplier = Convert.ToInt32(objXmlAspect["multiplier"].InnerText);
            _objLifestyle.StyleType = _objType;

            XmlDocument objXmlDocument = XmlManager.Instance.Load("lifestyles.xml");

            Guid source;
            if (objXmlAspect.TryGetField("id", Guid.TryParse, out source))
            {
                _objLifestyle.SourceID = source;
            }
            else
            {
                Log.Warning(new object[] { "Missing id field for lifestyle xmlnode", objXmlAspect });
                if (System.Diagnostics.Debugger.IsAttached)
                    {
                        System.Diagnostics.Debugger.Break();
                    }
            }

            foreach (TreeNode objNode in treLifestyleQualities.Nodes[0].Nodes)
            {
                XmlNode objXmlLifestyleQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objNode.Text + "\"]");
                LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);

                objQuality.Create(objXmlLifestyleQuality, _objCharacter, QualitySource.Selected, objNode);
            }
            foreach (TreeNode objNode in treLifestyleQualities.Nodes[1].Nodes)
            {
                if ((objNode.Text == "Not a Home") && (_objLifestyle.BaseLifestyle == "Bolt Hole"))
                {
                    //Already handled as part of the Bolt Hole shenanigans, doesn't need to be added again.
                }
                else
                {
                    XmlNode objXmlLifestyleQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objNode.Text + "\"]");
                    LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);

                    objQuality.Create(objXmlLifestyleQuality, _objCharacter, QualitySource.Selected, objNode);
                }
            }
            foreach (TreeNode objNode in treLifestyleQualities.Nodes[2].Nodes)
            {
                XmlNode objXmlLifestyleQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objNode.Text + "\"]");
                LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);

                objQuality.Create(objXmlLifestyleQuality, _objCharacter, QualitySource.Selected, objNode);
            }
            this.DialogResult = DialogResult.OK;
        }
        private void cboBaseLifestyle_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!_blnSkipRefresh)
            {
                //This needs a handler for translations, will fix later.
                if (cboBaseLifestyle.SelectedValue.ToString() == "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)
                    {
                        XmlDocument objXmlDocument = XmlManager.Instance.Load("lifestyles.xml");
                        XmlNode objXmlQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"Not a Home\"]");
                        LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);
                        TreeNode objNode = new TreeNode();
                        try
                        {
                            objQuality.Create(objXmlQuality, _objCharacter, QualitySource.BuiltIn, objNode);
                        }
                        catch
                        {
                        }
                        objQuality.LP = 0;
                        treLifestyleQualities.Nodes[1].Nodes.Add(objNode);
                        treLifestyleQualities.Nodes[1].Expand();
                        _objLifestyle.LifestyleQualities.Add(objQuality);
                    }
                }
                else
                {
                    //Characters with the Trust Fund Quality can have the lifestyle discounted.
                    if (_objCharacter.TrustFund == 1 && cboBaseLifestyle.SelectedValue.ToString() == "Medium")
                    {
                        chkTrustFund.Visible = true;
                    }
                    else if (_objCharacter.TrustFund == 2 && cboBaseLifestyle.SelectedValue.ToString() == "Low")
                    {
                        chkTrustFund.Visible = true;
                    }
                    else if (_objCharacter.TrustFund == 3 && cboBaseLifestyle.SelectedValue.ToString() == "High")
                    {
                        chkTrustFund.Visible = true;
                    }
                    else if (_objCharacter.TrustFund == 4 && cboBaseLifestyle.SelectedValue.ToString() == "Medium")
                    {
                        chkTrustFund.Visible = true;
                    }
                    else
                    {
                        chkTrustFund.Checked = false;
                        chkTrustFund.Visible = false;
                    }

                    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);
                                }
                            }
                        }
                    }
                }
            }
            CalculateValues();
        }