Exemple #1
0
        /// Create a Lifestyle from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlLifestyle">XmlNode to create the object from.</param>
        public void Create(XmlNode objXmlLifestyle)
        {
            objXmlLifestyle.TryGetStringFieldQuickly("name", ref _strBaseLifestyle);
            objXmlLifestyle.TryGetDecFieldQuickly("cost", ref _decCost);
            objXmlLifestyle.TryGetInt32FieldQuickly("dice", ref _intDice);
            objXmlLifestyle.TryGetDecFieldQuickly("multiplier", ref _decMultiplier);
            objXmlLifestyle.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlLifestyle.TryGetStringFieldQuickly("page", ref _strPage);
            objXmlLifestyle.TryGetDecFieldQuickly("costforarea", ref _decCostForArea);
            objXmlLifestyle.TryGetDecFieldQuickly("costforcomforts", ref _decCostForComforts);
            objXmlLifestyle.TryGetDecFieldQuickly("costforsecurity", ref _decCostForSecurity);
            objXmlLifestyle.TryGetBoolFieldQuickly("allowbonuslp", ref _blnAllowBonusLP);
            if (!objXmlLifestyle.TryGetStringFieldQuickly("altnotes", ref _strNotes))
            {
                objXmlLifestyle.TryGetStringFieldQuickly("notes", ref _strNotes);
            }
            if (!objXmlLifestyle.TryGetField("id", Guid.TryParse, out _sourceID))
            {
                Log.Warning(new object[] { "Missing id field for lifestyle xmlnode", objXmlLifestyle });

                Utils.BreakIfDebug();
            }
            else
            {
                _objCachedMyXmlNode = null;
            }
            string strTemp = string.Empty;

            if (objXmlLifestyle.TryGetStringFieldQuickly("increment", ref strTemp))
            {
                _eIncrement = ConvertToLifestyleIncrement(strTemp);
            }

            SourceDetail = new SourceString(_strSource, _strPage);
            using (XmlNodeList lstGridNodes = objXmlLifestyle.SelectNodes("freegrids/freegrid"))
            {
                if (lstGridNodes?.Count > 0)
                {
                    FreeGrids.Clear();
                    XmlDocument xmlLifestyleDocument = XmlManager.Load("lifestyles.xml");
                    foreach (XmlNode xmlNode in lstGridNodes)
                    {
                        XmlNode          xmlQuality = xmlLifestyleDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + xmlNode.InnerText + "\"]");
                        LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);
                        string           strPush    = xmlNode.Attributes?["select"]?.InnerText;
                        if (!string.IsNullOrWhiteSpace(strPush))
                        {
                            _objCharacter.Pushtext.Push(strPush);
                        }

                        objQuality.Create(xmlQuality, this, _objCharacter, QualitySource.BuiltIn);

                        FreeGrids.Add(objQuality);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Load the CharacterAttribute from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        /// <param name="blnCopy"></param>
        public void Load(XmlNode objNode, bool blnCopy = false)
        {
            //Can't out property and no backing field
            Guid source;

            if (objNode.TryGetField("sourceid", Guid.TryParse, out source))
            {
                SourceID = source;
            }

            if (blnCopy)
            {
                _guiID     = Guid.NewGuid();
                _intMonths = 0;
            }
            else
            {
                objNode.TryGetInt32FieldQuickly("months", ref _intMonths);
                objNode.TryGetField("guid", Guid.TryParse, out _guiID);
            }

            objNode.TryGetStringFieldQuickly("name", ref _strName);
            objNode.TryGetDecFieldQuickly("cost", ref _decCost);
            objNode.TryGetInt32FieldQuickly("dice", ref _intDice);
            objNode.TryGetDecFieldQuickly("multiplier", ref _decMultiplier);

            objNode.TryGetInt32FieldQuickly("area", ref _intArea);
            objNode.TryGetInt32FieldQuickly("security", ref _intSecurity);
            objNode.TryGetInt32FieldQuickly("comforts", ref _intComforts);
            objNode.TryGetInt32FieldQuickly("roommates", ref _intRoommates);
            objNode.TryGetDecFieldQuickly("percentage", ref _decPercentage);
            objNode.TryGetStringFieldQuickly("lifestylename", ref _strLifestyleName);
            objNode.TryGetBoolFieldQuickly("purchased", ref _blnPurchased);

            if (objNode.TryGetStringFieldQuickly("baselifestyle", ref _strBaseLifestyle))
            {
                if (_strBaseLifestyle == "Middle")
                {
                    _strBaseLifestyle = "Medium";
                }
            }

            objNode.TryGetStringFieldQuickly("source", ref _strSource);
            objNode.TryGetBoolFieldQuickly("trustfund", ref _blnTrustFund);
            objNode.TryGetStringFieldQuickly("page", ref _strPage);

            // Lifestyle Qualities
            XmlNodeList objXmlNodeList = objNode.SelectNodes("lifestylequalities/lifestylequality");

            if (objXmlNodeList != null)
            {
                foreach (XmlNode objXmlQuality in objXmlNodeList)
                {
                    var objQuality = new LifestyleQuality(_objCharacter);
                    objQuality.Load(objXmlQuality, this);
                    _lstLifestyleQualities.Add(objQuality);
                }
            }

            // Free Grids provided by the Lifestyle
            objXmlNodeList = objNode.SelectNodes("freegrids/lifestylequality");
            if (objXmlNodeList != null)
            {
                foreach (XmlNode objXmlQuality in objXmlNodeList)
                {
                    var objQuality = new LifestyleQuality(_objCharacter);
                    objQuality.Load(objXmlQuality, this);
                    FreeGrids.Add(objQuality);
                }
            }

            objNode.TryGetStringFieldQuickly("notes", ref _strNotes);

            var strtemp = string.Empty;

            if (objNode.TryGetStringFieldQuickly("type", ref strtemp))
            {
                _objType = ConverToLifestyleType(strtemp);
            }
        }
Exemple #3
0
        /// <summary>
        /// Load the CharacterAttribute from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        /// <param name="blnCopy"></param>
        public void Load(XmlNode objNode, bool blnCopy = false)
        {
            //Can't out property and no backing field
            if (objNode.TryGetField("sourceid", Guid.TryParse, out Guid source))
            {
                SourceID = source;
            }

            if (blnCopy)
            {
                _guiID         = Guid.NewGuid();
                _intIncrements = 0;
            }
            else
            {
                objNode.TryGetInt32FieldQuickly("months", ref _intIncrements);
                objNode.TryGetField("guid", Guid.TryParse, out _guiID);
            }

            objNode.TryGetStringFieldQuickly("name", ref _strName);
            objNode.TryGetDecFieldQuickly("cost", ref _decCost);
            objNode.TryGetInt32FieldQuickly("dice", ref _intDice);
            objNode.TryGetDecFieldQuickly("multiplier", ref _decMultiplier);

            objNode.TryGetInt32FieldQuickly("area", ref _intArea);
            objNode.TryGetInt32FieldQuickly("comforts", ref _intComforts);
            objNode.TryGetInt32FieldQuickly("security", ref _intSecurity);
            objNode.TryGetInt32FieldQuickly("basearea", ref _intBaseArea);
            objNode.TryGetInt32FieldQuickly("basecomforts", ref _intBaseComforts);
            objNode.TryGetInt32FieldQuickly("basesecurity", ref _intBaseSecurity);
            objNode.TryGetDecFieldQuickly("costforarea", ref _decCostForArea);
            objNode.TryGetDecFieldQuickly("costforcomforts", ref _decCostForComforts);
            objNode.TryGetDecFieldQuickly("costforsecurity", ref _decCostForSecurity);
            objNode.TryGetInt32FieldQuickly("roommates", ref _intRoommates);
            objNode.TryGetDecFieldQuickly("percentage", ref _decPercentage);
            objNode.TryGetStringFieldQuickly("baselifestyle", ref _strBaseLifestyle);
            objNode.TryGetInt32FieldQuickly("sortorder", ref _intSortOrder);
            if (XmlManager.Load("lifestyles.xml").SelectSingleNode($"/chummer/lifestyles/lifestyle[name =\"{_strBaseLifestyle}\"]") == null && XmlManager.Load("lifestyles.xml").SelectSingleNode($"/chummer/lifestyles/lifestyle[name =\"{_strName}\"]") != null)
            {
                string baselifestyle = _strName;
                _strName          = _strBaseLifestyle;
                _strBaseLifestyle = baselifestyle;
            }
            if (string.IsNullOrWhiteSpace(_strBaseLifestyle))
            {
                objNode.TryGetStringFieldQuickly("lifestylename", ref _strBaseLifestyle);
                if (string.IsNullOrWhiteSpace(_strBaseLifestyle))
                {
                    List <ListItem> lstQualities = new List <ListItem>();
                    using (XmlNodeList xmlLifestyleList = XmlManager.Load("lifestyles.xml").SelectNodes("/chummer/lifestyles/lifestyle"))
                        if (xmlLifestyleList != null)
                        {
                            foreach (XmlNode xmlLifestyle in xmlLifestyleList)
                            {
                                string strName = xmlLifestyle["name"]?.InnerText ?? LanguageManager.GetString("String_Error", GlobalOptions.Language);
                                lstQualities.Add(new ListItem(strName, xmlLifestyle["translate"]?.InnerText ?? strName));
                            }
                        }
                    frmSelectItem frmSelect = new frmSelectItem
                    {
                        GeneralItems = lstQualities,
                        Description  = string.Format(LanguageManager.GetString("String_CannotFindLifestyle", GlobalOptions.Language), _strName)
                    };
                    frmSelect.ShowDialog();
                    if (frmSelect.DialogResult == DialogResult.Cancel)
                    {
                        return;
                    }
                    _strBaseLifestyle = frmSelect.SelectedItem;
                }
            }
            if (_strBaseLifestyle == "Middle")
            {
                _strBaseLifestyle = "Medium";
            }
            if (!objNode.TryGetBoolFieldQuickly("allowbonuslp", ref _blnAllowBonusLP))
            {
                GetNode()?.TryGetBoolFieldQuickly("allowbonuslp", ref _blnAllowBonusLP);
            }
            if (!objNode.TryGetInt32FieldQuickly("bonuslp", ref _intBonusLP) && _strBaseLifestyle == "Traveler")
            {
                _intBonusLP = 1 + GlobalOptions.RandomGenerator.NextD6ModuloBiasRemoved();
            }
            objNode.TryGetStringFieldQuickly("source", ref _strSource);
            objNode.TryGetBoolFieldQuickly("trustfund", ref _blnTrustFund);
            if (objNode["primarytenant"] == null)
            {
                _blnIsPrimaryTenant = _intRoommates == 0;
            }
            else
            {
                objNode.TryGetBoolFieldQuickly("primarytenant", ref _blnIsPrimaryTenant);
            }
            objNode.TryGetStringFieldQuickly("page", ref _strPage);

            // Lifestyle Qualities
            using (XmlNodeList xmlQualityList = objNode.SelectNodes("lifestylequalities/lifestylequality"))
                if (xmlQualityList != null)
                {
                    foreach (XmlNode xmlQuality in xmlQualityList)
                    {
                        LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);
                        objQuality.Load(xmlQuality, this);
                        _lstLifestyleQualities.Add(objQuality);
                    }
                }

            // Free Grids provided by the Lifestyle
            using (XmlNodeList xmlQualityList = objNode.SelectNodes("freegrids/lifestylequality"))
                if (xmlQualityList != null)
                {
                    foreach (XmlNode xmlQuality in xmlQualityList)
                    {
                        LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);
                        objQuality.Load(xmlQuality, this);
                        _lstFreeGrids.Add(objQuality);
                    }
                }

            objNode.TryGetStringFieldQuickly("notes", ref _strNotes);

            string strTemp = string.Empty;

            if (objNode.TryGetStringFieldQuickly("type", ref strTemp))
            {
                _eType = ConvertToLifestyleType(strTemp);
            }
            if (objNode.TryGetStringFieldQuickly("increment", ref strTemp))
            {
                _eIncrement = ConvertToLifestyleIncrement(strTemp);
            }
            else if (_eType == LifestyleType.Safehouse)
            {
                _eIncrement = LifestyleIncrement.Week;
            }
            else
            {
                XmlNode xmlLifestyleNode = GetNode();
                if (xmlLifestyleNode != null && xmlLifestyleNode.TryGetStringFieldQuickly("increment", ref strTemp))
                {
                    _eIncrement = ConvertToLifestyleIncrement(strTemp);
                }
            }
            LegacyShim(objNode);
        }
Exemple #4
0
        /// <summary>
        /// Load the CharacterAttribute from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        public void Load(XmlNode objNode, bool blnCopy = false)
        {
            //Can't out property and no backing field
            Guid source;

            if (objNode.TryGetField <Guid>("sourceid", Guid.TryParse, out source))
            {
                SourceID = source;
            }

            objNode.TryGetField <Guid>("guid", Guid.TryParse, out _guiID);

            //If not present something gone totaly wrong, throw something
            if
            (
                !objNode.TryGetField("name", out _strName) ||
                !objNode.TryGetField("cost", out _intCost) ||
                !objNode.TryGetField("dice", out _intDice) ||
                !objNode.TryGetField("multiplier", out _intMultiplier) ||
                !objNode.TryGetField("months", out _intMonths)
            )
            {
                throw new ArgumentNullException("One or more of name, cost, dice, multiplier or months is missing");
            }

            objNode.TryGetField("area", out _intArea);
            objNode.TryGetField("security", out _intSecurity);
            objNode.TryGetField("comforts", out _intComforts);
            objNode.TryGetField("roommates", out _intRoommates);
            objNode.TryGetField("percentage", out _intPercentage);
            objNode.TryGetField("lifestylename", out _strLifestyleName);
            if (!objNode.TryGetField("purchased", out _blnPurchased))
            {
                throw new ArgumentNullException("purchased");
            }

            if (objNode.TryGetField("baselifestyle", out _strBaseLifestyle))
            {
                if (_strBaseLifestyle == "Middle")
                {
                    _strBaseLifestyle = "Medium";
                }
            }

            if (!objNode.TryGetField("source", out _strSource))
            {
                throw new ArgumentNullException("source");
            }
            objNode.TryGetField("trustfund", out _blnTrustFund);
            objNode.TryGetField("page", out _strPage);

            // Lifestyle Qualities
            XmlNodeList objXmlNodeList = objNode.SelectNodes("lifestylequalities/lifestylequality");

            foreach (XmlNode objXmlQuality in objXmlNodeList)
            {
                LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);
                objQuality.Load(objXmlQuality);
                _lstLifestyleQualities.Add(objQuality);
            }

            // Free Grids provided by the Lifestyle
            objXmlNodeList = objNode.SelectNodes("freegrids/lifestylequality");
            foreach (XmlNode objXmlQuality in objXmlNodeList)
            {
                LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);
                objQuality.Load(objXmlQuality);
                _lstLifestyleQualities.Add(objQuality);
            }

            objNode.TryGetField("notes", out _strNotes);

            String strtemp;

            if (objNode.TryGetField("type", out strtemp))
            {
                _objType = ConverToLifestyleType(strtemp);
            }

            try
            {
                _strNotes = objNode["notes"].InnerText;
            }
            catch
            {
            }

            try
            {
                _objType = ConverToLifestyleType(objNode["type"].InnerText);
            }
            catch
            {
            }

            if (blnCopy)
            {
                _guiID     = Guid.NewGuid();
                _intMonths = 0;
            }
        }
Exemple #5
0
        /// <summary>
        /// Load the CharacterAttribute from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        /// <param name="blnCopy"></param>
        public void Load(XmlNode objNode, bool blnCopy = false)
        {
            //Can't out property and no backing field
            if (objNode.TryGetField("sourceid", Guid.TryParse, out Guid source))
            {
                SourceID = source;
            }

            if (blnCopy)
            {
                _guiID     = Guid.NewGuid();
                _intMonths = 0;
            }
            else
            {
                objNode.TryGetInt32FieldQuickly("months", ref _intMonths);
                objNode.TryGetField("guid", Guid.TryParse, out _guiID);
            }

            objNode.TryGetStringFieldQuickly("name", ref _strName);
            objNode.TryGetDecFieldQuickly("cost", ref _decCost);
            objNode.TryGetInt32FieldQuickly("dice", ref _intDice);
            objNode.TryGetDecFieldQuickly("multiplier", ref _decMultiplier);

            objNode.TryGetInt32FieldQuickly("area", ref _intArea);
            objNode.TryGetInt32FieldQuickly("comforts", ref _intComforts);
            objNode.TryGetInt32FieldQuickly("security", ref _intSecurity);
            objNode.TryGetInt32FieldQuickly("basearea", ref _intBaseArea);
            objNode.TryGetInt32FieldQuickly("basecomforts", ref _intBaseComforts);
            objNode.TryGetInt32FieldQuickly("basesecurity", ref _intBaseSecurity);
            objNode.TryGetInt32FieldQuickly("costforarea", ref _costForArea);
            objNode.TryGetInt32FieldQuickly("costforcomforts", ref _costForComforts);
            objNode.TryGetInt32FieldQuickly("costforsecurity", ref _costForSecurity);
            objNode.TryGetInt32FieldQuickly("roommates", ref _intRoommates);
            objNode.TryGetDecFieldQuickly("percentage", ref _decPercentage);
            objNode.TryGetBoolFieldQuickly("purchased", ref _blnPurchased);
            objNode.TryGetStringFieldQuickly("baselifestyle", ref _strBaseLifestyle);
            if (string.IsNullOrWhiteSpace(_strBaseLifestyle))
            {
                objNode.TryGetStringFieldQuickly("lifestylename", ref _strBaseLifestyle);
                if (string.IsNullOrWhiteSpace(_strBaseLifestyle))
                {
                    XmlDocument objXmlDocument = XmlManager.Load("lifestyles.xml");
                    var         lstQualities   = new List <ListItem>();
                    foreach (XmlNode n in objXmlDocument.SelectNodes("/chummer/lifestyles/lifestyle"))
                    {
                        string strName = n["name"].InnerText;
                        lstQualities.Add(new ListItem(strName, n["translate"]?.InnerText ?? strName));
                    }
                    var frmSelect = new frmSelectItem
                    {
                        GeneralItems = lstQualities,
                        Description  = LanguageManager.GetString("String_CannotFindLifestyle", GlobalOptions.Language).Replace("{0}", _strName)
                    };
                    frmSelect.ShowDialog();
                    if (frmSelect.DialogResult == DialogResult.Cancel)
                    {
                        return;
                    }
                    _strBaseLifestyle = frmSelect.SelectedItem;
                }
            }
            if (_strBaseLifestyle == "Middle")
            {
                _strBaseLifestyle = "Medium";
            }
            objNode.TryGetStringFieldQuickly("source", ref _strSource);
            objNode.TryGetBoolFieldQuickly("trustfund", ref _blnTrustFund);
            if (objNode["primarytenant"] == null)
            {
                _primaryTenant = _intRoommates == 0;
            }
            else
            {
                objNode.TryGetBoolFieldQuickly("primarytenant", ref _primaryTenant);
            }
            objNode.TryGetStringFieldQuickly("page", ref _strPage);

            // Lifestyle Qualities
            var objXmlNodeList = objNode.SelectNodes("lifestylequalities/lifestylequality");

            if (objXmlNodeList != null)
            {
                foreach (XmlNode objXmlQuality in objXmlNodeList)
                {
                    var objQuality = new LifestyleQuality(_objCharacter);
                    objQuality.Load(objXmlQuality, this);
                    _lstLifestyleQualities.Add(objQuality);
                }
            }

            // Free Grids provided by the Lifestyle
            objXmlNodeList = objNode.SelectNodes("freegrids/lifestylequality");
            if (objXmlNodeList != null)
            {
                foreach (XmlNode objXmlQuality in objXmlNodeList)
                {
                    var objQuality = new LifestyleQuality(_objCharacter);
                    objQuality.Load(objXmlQuality, this);
                    FreeGrids.Add(objQuality);
                }
            }

            objNode.TryGetStringFieldQuickly("notes", ref _strNotes);

            var strtemp = string.Empty;

            if (objNode.TryGetStringFieldQuickly("type", ref strtemp))
            {
                _objType = ConverToLifestyleType(strtemp);
            }
            LegacyShim(objNode);
        }