/// Create a Martial Art Maneuver from an XmlNode.
        /// <param name="objXmlManeuverNode">XmlNode to create the object from.</param>
        public void Create(XmlNode objXmlManeuverNode)
        {
            if (!objXmlManeuverNode.TryGetField("id", Guid.TryParse, out _guiSourceID))
            {
                Log.Warn(new object[] { "Missing id field for xmlnode", objXmlManeuverNode });
                Utils.BreakIfDebug();
            }
            if (objXmlManeuverNode.TryGetStringFieldQuickly("name", ref _strName))
            {
                _objCachedMyXmlNode = null;
            }
            objXmlManeuverNode.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlManeuverNode.TryGetStringFieldQuickly("page", ref _strPage);
            if (!objXmlManeuverNode.TryGetStringFieldQuickly("altnotes", ref _strNotes))
            {
                objXmlManeuverNode.TryGetStringFieldQuickly("notes", ref _strNotes);
            }

            if (string.IsNullOrEmpty(Notes))
            {
                string strEnglishNameOnPage = Name;
                string strNameOnPage        = string.Empty;
                // make sure we have something and not just an empty tag
                if (objXmlManeuverNode.TryGetStringFieldQuickly("nameonpage", ref strNameOnPage) &&
                    !string.IsNullOrEmpty(strNameOnPage))
                {
                    strEnglishNameOnPage = strNameOnPage;
                }

                string strQualityNotes = CommonFunctions.GetTextFromPDF(Source + ' ' + Page, strEnglishNameOnPage);

                if (string.IsNullOrEmpty(strQualityNotes) && GlobalOptions.Language != GlobalOptions.DefaultLanguage)
                {
                    string strTranslatedNameOnPage = CurrentDisplayName;

                    // don't check again it is not translated
                    if (strTranslatedNameOnPage != _strName)
                    {
                        // if we found <altnameonpage>, and is not empty and not the same as english we must use that instead
                        if (objXmlManeuverNode.TryGetStringFieldQuickly("altnameonpage", ref strNameOnPage) &&
                            !string.IsNullOrEmpty(strNameOnPage) && strNameOnPage != strEnglishNameOnPage)
                        {
                            strTranslatedNameOnPage = strNameOnPage;
                        }

                        Notes = CommonFunctions.GetTextFromPDF(Source + ' ' + DisplayPage(GlobalOptions.Language),
                                                               strTranslatedNameOnPage);
                    }
                }
                else
                {
                    Notes = strQualityNotes;
                }
            }
        }
        private void lstItems_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnSkipRefresh)
            {
                return;
            }
            Cursor objOldCursor = Cursor;

            Cursor = Cursors.WaitCursor;
            SuspendLayout();
            if (lstItems.SelectedValue is MasterIndexEntry objEntry)
            {
                lblSourceLabel.Visible         = true;
                lblSource.Visible              = true;
                lblSourceClickReminder.Visible = true;
                lblSource.Text        = objEntry.DisplaySource.ToString();
                lblSource.ToolTipText = objEntry.DisplaySource.LanguageBookTooltip;
                if (!_dicCachedNotes.TryGetValue(objEntry, out string strNotes))
                {
                    strNotes = CommonFunctions.GetTextFromPDF(objEntry.Source.ToString(), objEntry.EnglishNameOnPage);

                    if (string.IsNullOrEmpty(strNotes) && GlobalOptions.Language != GlobalOptions.DefaultLanguage)
                    {
                        // don't check again it is not translated
                        if (objEntry.TranslatedNameOnPage != objEntry.EnglishNameOnPage || objEntry.Source.Page != objEntry.DisplaySource.Page)
                        {
                            strNotes = CommonFunctions.GetTextFromPDF(objEntry.DisplaySource.ToString(), objEntry.TranslatedNameOnPage);
                        }
                    }

                    _dicCachedNotes.TryAdd(objEntry, strNotes);
                }
                rtbNotes.Text    = strNotes;
                rtbNotes.Visible = true;
            }
            else
            {
                lblSourceLabel.Visible         = false;
                lblSource.Visible              = false;
                lblSourceClickReminder.Visible = false;
                rtbNotes.Visible = false;
            }
            ResumeLayout();
            Cursor = objOldCursor;
        }
        /// Create a Martial Art Technique from an XmlNode.
        /// <param name="xmlTechniqueDataNode">XmlNode to create the object from.</param>
        public void Create(XmlNode xmlTechniqueDataNode)
        {
            if (!xmlTechniqueDataNode.TryGetField("id", Guid.TryParse, out _guiSourceID))
            {
                Log.Warn(new object[] { "Missing id field for xmlnode", xmlTechniqueDataNode });
                Utils.BreakIfDebug();
            }

            if (xmlTechniqueDataNode.TryGetStringFieldQuickly("name", ref _strName))
            {
                if (!xmlTechniqueDataNode.TryGetStringFieldQuickly("altnotes", ref _strNotes))
                {
                    xmlTechniqueDataNode.TryGetStringFieldQuickly("notes", ref _strNotes);
                }
            }
            xmlTechniqueDataNode.TryGetStringFieldQuickly("source", ref _strSource);
            xmlTechniqueDataNode.TryGetStringFieldQuickly("page", ref _strPage);

            if (string.IsNullOrEmpty(Notes))
            {
                string strEnglishNameOnPage = Name;
                string strNameOnPage        = string.Empty;
                // make sure we have something and not just an empty tag
                if (xmlTechniqueDataNode.TryGetStringFieldQuickly("nameonpage", ref strNameOnPage) &&
                    !string.IsNullOrEmpty(strNameOnPage))
                {
                    strEnglishNameOnPage = strNameOnPage;
                }

                string strQualityNotes = CommonFunctions.GetTextFromPDF(Source + ' ' + Page, strEnglishNameOnPage);

                if (string.IsNullOrEmpty(strQualityNotes) && GlobalOptions.Language != GlobalOptions.DefaultLanguage)
                {
                    string strTranslatedNameOnPage = CurrentDisplayName;

                    // don't check again it is not translated
                    if (strTranslatedNameOnPage != _strName)
                    {
                        // if we found <altnameonpage>, and is not empty and not the same as english we must use that instead
                        if (xmlTechniqueDataNode.TryGetStringFieldQuickly("altnameonpage", ref strNameOnPage) &&
                            !string.IsNullOrEmpty(strNameOnPage) && strNameOnPage != strEnglishNameOnPage)
                        {
                            strTranslatedNameOnPage = strNameOnPage;
                        }

                        Notes = CommonFunctions.GetTextFromPDF(Source + ' ' + DisplayPage(GlobalOptions.Language),
                                                               strTranslatedNameOnPage);
                    }
                }
                else
                {
                    Notes = strQualityNotes;
                }
            }

            if (xmlTechniqueDataNode["bonus"] == null)
            {
                return;
            }
            if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MartialArtTechnique,
                                                       _guiID.ToString("D", GlobalOptions.InvariantCultureInfo), xmlTechniqueDataNode["bonus"], 1, CurrentDisplayName))
            {
                _guiID = Guid.Empty;
            }
        }
Beispiel #4
0
        /// Create a Martial Art from an XmlNode.
        /// <param name="objXmlArtNode">XmlNode to create the object from.</param>
        public void Create(XmlNode objXmlArtNode)
        {
            if (!objXmlArtNode.TryGetField("id", Guid.TryParse, out _guiSourceID))
            {
                Log.Warn(new object[] { "Missing id field for xmlnode", objXmlArtNode });
                Utils.BreakIfDebug();
            }
            if (objXmlArtNode.TryGetStringFieldQuickly("name", ref _strName))
            {
                _objCachedMyXmlNode = null;
            }
            objXmlArtNode.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlArtNode.TryGetStringFieldQuickly("page", ref _strPage);
            objXmlArtNode.TryGetInt32FieldQuickly("cost", ref _intKarmaCost);
            if (!objXmlArtNode.TryGetStringFieldQuickly("altnotes", ref _strNotes))
            {
                objXmlArtNode.TryGetStringFieldQuickly("notes", ref _strNotes);
            }
            _blnIsQuality = objXmlArtNode["isquality"]?.InnerText == bool.TrueString;

            if (objXmlArtNode["bonus"] != null)
            {
                ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MartialArt, InternalId,
                                                      objXmlArtNode["bonus"], 1, DisplayNameShort(GlobalOptions.Language));
            }
            if (string.IsNullOrEmpty(Notes))
            {
                string strEnglishNameOnPage = Name;
                string strNameOnPage        = string.Empty;
                // make sure we have something and not just an empty tag
                if (objXmlArtNode.TryGetStringFieldQuickly("nameonpage", ref strNameOnPage) &&
                    !string.IsNullOrEmpty(strNameOnPage))
                {
                    strEnglishNameOnPage = strNameOnPage;
                }

                string strQualityNotes = CommonFunctions.GetTextFromPDF(Source + ' ' + Page, strEnglishNameOnPage);

                if (string.IsNullOrEmpty(strQualityNotes) && GlobalOptions.Language != GlobalOptions.DefaultLanguage)
                {
                    string strTranslatedNameOnPage = CurrentDisplayName;

                    // don't check again it is not translated
                    if (strTranslatedNameOnPage != _strName)
                    {
                        // if we found <altnameonpage>, and is not empty and not the same as english we must use that instead
                        if (objXmlArtNode.TryGetStringFieldQuickly("altnameonpage", ref strNameOnPage) &&
                            !string.IsNullOrEmpty(strNameOnPage) && strNameOnPage != strEnglishNameOnPage)
                        {
                            strTranslatedNameOnPage = strNameOnPage;
                        }

                        Notes = CommonFunctions.GetTextFromPDF(Source + ' ' + DisplayPage(GlobalOptions.Language),
                                                               strTranslatedNameOnPage);
                    }
                }
                else
                {
                    Notes = strQualityNotes;
                }
            }
        }
        /// <summary>
        /// Create a Quality from an XmlNode.
        /// </summary>
        /// <param name="objXmlQuality">XmlNode to create the object from.</param>
        /// <param name="objQualitySource">Source of the Quality.</param>
        /// <param name="lstWeapons">List of Weapons that should be added to the Character.</param>
        /// <param name="strForceValue">Force a value to be selected for the Quality.</param>
        /// <param name="strSourceName">Friendly name for the improvement that added this quality.</param>
        public void Create(XmlNode objXmlQuality, QualitySource objQualitySource, IList <Weapon> lstWeapons, string strForceValue = "", string strSourceName = "")
        {
            _strSourceName = strSourceName;
            objXmlQuality.TryGetStringFieldQuickly("name", ref _strName);
            objXmlQuality.TryGetBoolFieldQuickly("metagenetic", ref _blnMetagenetic);
            if (!objXmlQuality.TryGetStringFieldQuickly("altnotes", ref _strNotes))
            {
                objXmlQuality.TryGetStringFieldQuickly("notes", ref _strNotes);
            }
            objXmlQuality.TryGetInt32FieldQuickly("karma", ref _intBP);
            _eQualityType   = ConvertToQualityType(objXmlQuality["category"]?.InnerText);
            _eQualitySource = objQualitySource;
            objXmlQuality.TryGetBoolFieldQuickly("doublecareer", ref _blnDoubleCostCareer);
            objXmlQuality.TryGetBoolFieldQuickly("canbuywithspellpoints", ref _blnCanBuyWithSpellPoints);
            objXmlQuality.TryGetBoolFieldQuickly("print", ref _blnPrint);
            objXmlQuality.TryGetBoolFieldQuickly("implemented", ref _blnImplemented);
            objXmlQuality.TryGetBoolFieldQuickly("contributetolimit", ref _blnContributeToLimit);
            objXmlQuality.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlQuality.TryGetStringFieldQuickly("page", ref _strPage);
            _blnMutant = objXmlQuality["mutant"] != null;

            if (_eQualityType == QualityType.LifeModule)
            {
                objXmlQuality.TryGetStringFieldQuickly("stage", ref _strStage);
            }

            if (objXmlQuality.TryGetField("id", Guid.TryParse, out Guid guiTemp))
            {
                _guiQualityId       = guiTemp;
                _objCachedMyXmlNode = null;
            }

            // Add Weapons if applicable.
            // More than one Weapon can be added, so loop through all occurrences.
            using (XmlNodeList xmlAddWeaponList = objXmlQuality.SelectNodes("addweapon"))
                if (xmlAddWeaponList?.Count > 0)
                {
                    XmlDocument objXmlWeaponDocument = XmlManager.Load("weapons.xml");
                    foreach (XmlNode objXmlAddWeapon in xmlAddWeaponList)
                    {
                        string  strLoopID    = objXmlAddWeapon.InnerText;
                        XmlNode objXmlWeapon = strLoopID.IsGuid()
                            ? objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + strLoopID + "\"]")
                            : objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + strLoopID + "\"]");

                        Weapon objGearWeapon = new Weapon(_objCharacter);
                        objGearWeapon.Create(objXmlWeapon, lstWeapons);
                        objGearWeapon.ParentID = InternalId;
                        objGearWeapon.Cost     = "0";
                        lstWeapons.Add(objGearWeapon);

                        Guid.TryParse(objGearWeapon.InternalId, out _guiWeaponID);
                    }
                }

            using (XmlNodeList xmlNaturalWeaponList = objXmlQuality.SelectNodes("naturalweapons/naturalweapon"))
                if (xmlNaturalWeaponList?.Count > 0)
                {
                    foreach (XmlNode objXmlNaturalWeapon in xmlNaturalWeaponList)
                    {
                        Weapon objWeapon = new Weapon(_objCharacter);
                        if (objXmlNaturalWeapon["name"] != null)
                        {
                            objWeapon.Name = objXmlNaturalWeapon["name"].InnerText;
                        }
                        objWeapon.Category   = LanguageManager.GetString("Tab_Critter", GlobalOptions.Language);
                        objWeapon.WeaponType = "Melee";
                        if (objXmlNaturalWeapon["reach"] != null)
                        {
                            objWeapon.Reach = Convert.ToInt32(objXmlNaturalWeapon["reach"].InnerText);
                        }
                        if (objXmlNaturalWeapon["accuracy"] != null)
                        {
                            objWeapon.Accuracy = objXmlNaturalWeapon["accuracy"].InnerText;
                        }
                        if (objXmlNaturalWeapon["damage"] != null)
                        {
                            objWeapon.Damage = objXmlNaturalWeapon["damage"].InnerText;
                        }
                        if (objXmlNaturalWeapon["ap"] != null)
                        {
                            objWeapon.AP = objXmlNaturalWeapon["ap"].InnerText;
                        }
                        objWeapon.Mode           = "0";
                        objWeapon.RC             = "0";
                        objWeapon.Concealability = 0;
                        objWeapon.Avail          = "0";
                        objWeapon.Cost           = "0";
                        if (objXmlNaturalWeapon["useskill"] != null)
                        {
                            objWeapon.UseSkill = objXmlNaturalWeapon["useskill"].InnerText;
                        }
                        if (objXmlNaturalWeapon["source"] != null)
                        {
                            objWeapon.Source = objXmlNaturalWeapon["source"].InnerText;
                        }
                        if (objXmlNaturalWeapon["page"] != null)
                        {
                            objWeapon.Page = objXmlNaturalWeapon["page"].InnerText;
                        }

                        _objCharacter.Weapons.Add(objWeapon);
                    }
                }

            _nodDiscounts = objXmlQuality["costdiscount"];
            // If the item grants a bonus, pass the information to the Improvement Manager.
            _nodBonus = objXmlQuality["bonus"];
            if (_nodBonus?.ChildNodes.Count > 0)
            {
                ImprovementManager.ForcedValue = strForceValue;
                if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.Quality, InternalId, _nodBonus, false, 1, DisplayNameShort(GlobalOptions.Language)))
                {
                    _guiID = Guid.Empty;
                    return;
                }
                if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue))
                {
                    _strExtra = ImprovementManager.SelectedValue;
                }
            }
            else if (!string.IsNullOrEmpty(strForceValue))
            {
                _strExtra = strForceValue;
            }
            _nodFirstLevelBonus = objXmlQuality["firstlevelbonus"];
            if (_nodFirstLevelBonus?.ChildNodes.Count > 0 && Levels == 0)
            {
                ImprovementManager.ForcedValue = string.IsNullOrEmpty(strForceValue) ? Extra : strForceValue;
                if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.Quality, InternalId, _nodFirstLevelBonus, false, 1, DisplayNameShort(GlobalOptions.Language)))
                {
                    _guiID = Guid.Empty;
                    return;
                }
            }

            if (string.IsNullOrEmpty(Notes))
            {
                string strEnglishNameOnPage = Name;
                string strNameOnPage        = string.Empty;
                // make sure we have something and not just an empty tag
                if (objXmlQuality.TryGetStringFieldQuickly("nameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage))
                {
                    strEnglishNameOnPage = strNameOnPage;
                }

                string strQualityNotes = CommonFunctions.GetTextFromPDF($"{Source} {Page}", strEnglishNameOnPage);

                if (string.IsNullOrEmpty(strQualityNotes) && GlobalOptions.Language != GlobalOptions.DefaultLanguage)
                {
                    string strTranslatedNameOnPage = DisplayName(GlobalOptions.Language);

                    // don't check again it is not translated
                    if (strTranslatedNameOnPage != _strName)
                    {
                        // if we found <altnameonpage>, and is not empty and not the same as english we must use that instead
                        if (objXmlQuality.TryGetStringFieldQuickly("altnameonpage", ref strNameOnPage) &&
                            !string.IsNullOrEmpty(strNameOnPage) && strNameOnPage != strEnglishNameOnPage)
                        {
                            strTranslatedNameOnPage = strNameOnPage;
                        }

                        Notes = CommonFunctions.GetTextFromPDF($"{Source} {DisplayPage(GlobalOptions.Language)}", strTranslatedNameOnPage);
                    }
                }
                else
                {
                    Notes = strQualityNotes;
                }
            }
        }