Пример #1
0
        /// <summary>
        /// Build the list of available weapon accessories.
        /// </summary>
        private void RefreshList()
        {
            List <ListItem> lstAccessories = new List <ListItem>();

            // Populate the Accessory list.
            StringBuilder sbdMount = new StringBuilder("(contains(mount, \"Internal\") or contains(mount, \"None\") or mount = \"\"");

            foreach (var strAllowedMount in _lstAllowedMounts.Where(strAllowedMount => !string.IsNullOrEmpty(strAllowedMount)))
            {
                sbdMount.Append(" or contains(mount, \"" + strAllowedMount + "\")");
            }

            sbdMount.Append(')').Append(CommonFunctions.GenerateSearchXPath(txtSearch.Text));
            int intOverLimit = 0;

            foreach (XPathNavigator objXmlAccessory in _xmlBaseChummerNode.Select(string.Format(GlobalOptions.InvariantCultureInfo, "accessories/accessory[({0}) and ({1})]",
                                                                                                sbdMount, _objCharacter.Options.BookXPath())))
            {
                string strId = objXmlAccessory.SelectSingleNode("id")?.Value;
                if (string.IsNullOrEmpty(strId))
                {
                    continue;
                }
                if (!_objParentWeapon.CheckAccessoryRequirements(objXmlAccessory))
                {
                    continue;
                }

                decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                if (_blnIsParentWeaponBlackMarketAllowed)
                {
                    decCostMultiplier *= 0.9m;
                }
                if ((!chkHideOverAvailLimit.Checked || objXmlAccessory.CheckAvailRestriction(_objCharacter) &&
                     (chkFreeItem.Checked || !chkShowOnlyAffordItems.Checked ||
                      objXmlAccessory.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier))))
                {
                    lstAccessories.Add(new ListItem(strId,
                                                    objXmlAccessory.SelectSingleNode("translate")?.Value ??
                                                    objXmlAccessory.SelectSingleNode("name")?.Value ??
                                                    LanguageManager.GetString("String_Unknown")));
                }
                else
                {
                    ++intOverLimit;
                }
            }

            lstAccessories.Sort(CompareListItems.CompareNames);
            if (intOverLimit > 0)
            {
                // Add after sort so that it's always at the end
                lstAccessories.Add(new ListItem(string.Empty, string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("String_RestrictedItemsHidden"),
                                                                            intOverLimit)));
            }
            string strOldSelected = lstAccessory.SelectedValue?.ToString();

            _blnLoading = true;
            lstAccessory.BeginUpdate();
            lstAccessory.ValueMember   = nameof(ListItem.Value);
            lstAccessory.DisplayMember = nameof(ListItem.Name);
            lstAccessory.DataSource    = lstAccessories;
            _blnLoading = false;
            if (!string.IsNullOrEmpty(strOldSelected))
            {
                lstAccessory.SelectedValue = strOldSelected;
            }
            else
            {
                lstAccessory.SelectedIndex = -1;
            }
            lstAccessory.EndUpdate();
        }
Пример #2
0
        /// <summary>
        /// Create a Critter, put them into Career Mode, link them, and open the newly-created Critter.
        /// </summary>
        /// <param name="strCritterName">Name of the Critter's Metatype.</param>
        /// <param name="intForce">Critter's Force.</param>
        private async void CreateCritter(string strCritterName, int intForce)
        {
            // Code from frmMetatype.
            XmlDocument objXmlDocument = _objSpirit.CharacterObject.LoadData("critters.xml");

            XmlNode objXmlMetatype = objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + strCritterName + "\"]");

            // If the Critter could not be found, show an error and get out of here.
            if (objXmlMetatype == null)
            {
                Program.MainForm.ShowMessageBox(string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("Message_UnknownCritterType"), strCritterName), LanguageManager.GetString("MessageTitle_SelectCritterType"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            using (new CursorWait(this))
            {
                // The Critter should use the same settings file as the character.
                using (Character objCharacter = new Character
                {
                    CharacterOptionsKey = _objSpirit.CharacterObject.CharacterOptionsKey,
                    // Override the defaults for the setting.
                    IgnoreRules = true,
                    IsCritter = true
                })
                {
                    if (!string.IsNullOrEmpty(txtCritterName.Text))
                    {
                        objCharacter.Name = txtCritterName.Text;
                    }

                    string strSpace = LanguageManager.GetString("String_Space");
                    using (SaveFileDialog saveFileDialog = new SaveFileDialog
                    {
                        Filter = LanguageManager.GetString("DialogFilter_Chum5") + '|' + LanguageManager.GetString("DialogFilter_All"),
                        FileName = new StringBuilder(strCritterName)
                                   .Append(strSpace).Append('(').Append(LanguageManager.GetString(_objSpirit.RatingLabel))
                                   .Append(strSpace).Append(_objSpirit.Force.ToString(GlobalOptions.InvariantCultureInfo)).Append(").chum5").ToString()
                    })
                    {
                        if (saveFileDialog.ShowDialog(this) != DialogResult.OK)
                        {
                            return;
                        }
                        string strFileName = saveFileDialog.FileName;
                        objCharacter.FileName = strFileName;
                    }

                    // Set Metatype information.
                    if (strCritterName == "Ally Spirit")
                    {
                        objCharacter.BOD.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["bodmin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["bodmax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["bodaug"]?.InnerText, intForce, 0, 0));
                        objCharacter.AGI.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["agimin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["agimax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["agiaug"]?.InnerText, intForce, 0, 0));
                        objCharacter.REA.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["reamin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["reamax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["reaaug"]?.InnerText, intForce, 0, 0));
                        objCharacter.STR.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["strmin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["strmax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["straug"]?.InnerText, intForce, 0, 0));
                        objCharacter.CHA.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["chamin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["chamax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["chaaug"]?.InnerText, intForce, 0, 0));
                        objCharacter.INT.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["intmin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["intmax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["intaug"]?.InnerText, intForce, 0, 0));
                        objCharacter.LOG.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["logmin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["logmax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["logaug"]?.InnerText, intForce, 0, 0));
                        objCharacter.WIL.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["wilmin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["wilmax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["wilaug"]?.InnerText, intForce, 0, 0));
                        objCharacter.MAG.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["magmin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["magmax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["magaug"]?.InnerText, intForce, 0, 0));
                        objCharacter.RES.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["resmin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["resmax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["resaug"]?.InnerText, intForce, 0, 0));
                        objCharacter.EDG.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["edgmin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["edgmax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["edgaug"]?.InnerText, intForce, 0, 0));
                        objCharacter.ESS.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["essmin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["essmax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["essaug"]?.InnerText, intForce, 0, 0));
                    }
                    else
                    {
                        int intMinModifier = -3;
                        objCharacter.BOD.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["bodmin"]?.InnerText, intForce, intMinModifier, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["bodmin"]?.InnerText, intForce, 3, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["bodmin"]?.InnerText, intForce, 3, 0));
                        objCharacter.AGI.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["agimin"]?.InnerText, intForce, intMinModifier, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["agimin"]?.InnerText, intForce, 3, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["agimin"]?.InnerText, intForce, 3, 0));
                        objCharacter.REA.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["reamin"]?.InnerText, intForce, intMinModifier, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["reamin"]?.InnerText, intForce, 3, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["reamin"]?.InnerText, intForce, 3, 0));
                        objCharacter.STR.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["strmin"]?.InnerText, intForce, intMinModifier, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["strmin"]?.InnerText, intForce, 3, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["strmin"]?.InnerText, intForce, 3, 0));
                        objCharacter.CHA.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["chamin"]?.InnerText, intForce, intMinModifier, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["chamin"]?.InnerText, intForce, 3, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["chamin"]?.InnerText, intForce, 3, 0));
                        objCharacter.INT.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["intmin"]?.InnerText, intForce, intMinModifier, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["intmin"]?.InnerText, intForce, 3, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["intmin"]?.InnerText, intForce, 3, 0));
                        objCharacter.LOG.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["logmin"]?.InnerText, intForce, intMinModifier, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["logmin"]?.InnerText, intForce, 3, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["logmin"]?.InnerText, intForce, 3, 0));
                        objCharacter.WIL.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["wilmin"]?.InnerText, intForce, intMinModifier, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["wilmin"]?.InnerText, intForce, 3, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["wilmin"]?.InnerText, intForce, 3, 0));
                        objCharacter.MAG.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["magmin"]?.InnerText, intForce, intMinModifier, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["magmin"]?.InnerText, intForce, 3, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["magmin"]?.InnerText, intForce, 3, 0));
                        objCharacter.RES.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["resmin"]?.InnerText, intForce, intMinModifier, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["resmin"]?.InnerText, intForce, 3, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["resmin"]?.InnerText, intForce, 3, 0));
                        objCharacter.EDG.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["edgmin"]?.InnerText, intForce, intMinModifier, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["edgmin"]?.InnerText, intForce, 3, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["edgmin"]?.InnerText, intForce, 3, 0));
                        objCharacter.ESS.AssignLimits(
                            CommonFunctions.ExpressionToInt(objXmlMetatype["essmin"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["essmax"]?.InnerText, intForce, 0, 0),
                            CommonFunctions.ExpressionToInt(objXmlMetatype["essaug"]?.InnerText, intForce, 0, 0));
                    }

                    // If we're working with a Critter, set the Attributes to their default values.
                    objCharacter.BOD.MetatypeMinimum = CommonFunctions.ExpressionToInt(objXmlMetatype["bodmin"]?.InnerText, intForce, 0, 0);
                    objCharacter.AGI.MetatypeMinimum = CommonFunctions.ExpressionToInt(objXmlMetatype["agimin"]?.InnerText, intForce, 0, 0);
                    objCharacter.REA.MetatypeMinimum = CommonFunctions.ExpressionToInt(objXmlMetatype["reamin"]?.InnerText, intForce, 0, 0);
                    objCharacter.STR.MetatypeMinimum = CommonFunctions.ExpressionToInt(objXmlMetatype["strmin"]?.InnerText, intForce, 0, 0);
                    objCharacter.CHA.MetatypeMinimum = CommonFunctions.ExpressionToInt(objXmlMetatype["chamin"]?.InnerText, intForce, 0, 0);
                    objCharacter.INT.MetatypeMinimum = CommonFunctions.ExpressionToInt(objXmlMetatype["intmin"]?.InnerText, intForce, 0, 0);
                    objCharacter.LOG.MetatypeMinimum = CommonFunctions.ExpressionToInt(objXmlMetatype["logmin"]?.InnerText, intForce, 0, 0);
                    objCharacter.WIL.MetatypeMinimum = CommonFunctions.ExpressionToInt(objXmlMetatype["wilmin"]?.InnerText, intForce, 0, 0);
                    objCharacter.MAG.MetatypeMinimum = CommonFunctions.ExpressionToInt(objXmlMetatype["magmin"]?.InnerText, intForce, 0, 0);
                    objCharacter.RES.MetatypeMinimum = CommonFunctions.ExpressionToInt(objXmlMetatype["resmin"]?.InnerText, intForce, 0, 0);
                    objCharacter.EDG.MetatypeMinimum = CommonFunctions.ExpressionToInt(objXmlMetatype["edgmin"]?.InnerText, intForce, 0, 0);
                    objCharacter.ESS.MetatypeMinimum = CommonFunctions.ExpressionToInt(objXmlMetatype["essmax"]?.InnerText, intForce, 0, 0);

                    // Sprites can never have Physical Attributes.
                    if (objXmlMetatype["category"].InnerText.EndsWith("Sprite", StringComparison.Ordinal))
                    {
                        objCharacter.BOD.AssignLimits(0, 0, 0);
                        objCharacter.AGI.AssignLimits(0, 0, 0);
                        objCharacter.REA.AssignLimits(0, 0, 0);
                        objCharacter.STR.AssignLimits(0, 0, 0);
                    }

                    objCharacter.Metatype         = strCritterName;
                    objCharacter.MetatypeCategory = objXmlMetatype["category"].InnerText;
                    objCharacter.Metavariant      = string.Empty;
                    objCharacter.MetatypeBP       = 0;

                    if (objXmlMetatype["movement"] != null)
                    {
                        objCharacter.Movement = objXmlMetatype["movement"].InnerText;
                    }
                    // Load the Qualities file.
                    XmlDocument objXmlQualityDocument = _objSpirit.CharacterObject.LoadData("qualities.xml");

                    // Determine if the Metatype has any bonuses.
                    if (objXmlMetatype.InnerXml.Contains("bonus"))
                    {
                        ImprovementManager.CreateImprovements(objCharacter, Improvement.ImprovementSource.Metatype, strCritterName, objXmlMetatype.SelectSingleNode("bonus"), 1, strCritterName);
                    }

                    // Create the Qualities that come with the Metatype.
                    foreach (XmlNode objXmlQualityItem in objXmlMetatype.SelectNodes("qualities/*/quality"))
                    {
                        XmlNode       objXmlQuality = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQualityItem.InnerText + "\"]");
                        List <Weapon> lstWeapons    = new List <Weapon>(1);
                        Quality       objQuality    = new Quality(objCharacter);
                        string        strForceValue = objXmlQualityItem.Attributes?["select"]?.InnerText ?? string.Empty;
                        QualitySource objSource     = objXmlQualityItem.Attributes["removable"]?.InnerText == bool.TrueString ? QualitySource.MetatypeRemovable : QualitySource.Metatype;
                        objQuality.Create(objXmlQuality, objSource, lstWeapons, strForceValue);
                        objCharacter.Qualities.Add(objQuality);

                        // Add any created Weapons to the character.
                        foreach (Weapon objWeapon in lstWeapons)
                        {
                            objCharacter.Weapons.Add(objWeapon);
                        }
                    }

                    // Add any Critter Powers the Metatype/Critter should have.
                    XmlNode objXmlCritter = objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + objCharacter.Metatype + "\"]");

                    objXmlDocument = _objSpirit.CharacterObject.LoadData("critterpowers.xml");
                    foreach (XmlNode objXmlPower in objXmlCritter.SelectNodes("powers/power"))
                    {
                        XmlNode      objXmlCritterPower = objXmlDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower.InnerText + "\"]");
                        CritterPower objPower           = new CritterPower(objCharacter);
                        string       strForcedValue     = objXmlPower.Attributes?["select"]?.InnerText ?? string.Empty;
                        int          intRating          = CommonFunctions.ExpressionToInt(objXmlPower.Attributes?["rating"]?.InnerText, intForce, 0, 0);

                        objPower.Create(objXmlCritterPower, intRating, strForcedValue);
                        objCharacter.CritterPowers.Add(objPower);
                    }

                    if (objXmlCritter["optionalpowers"] != null)
                    {
                        //For every 3 full points of Force a spirit has, it may gain one Optional Power.
                        for (int i = intForce - 3; i >= 0; i -= 3)
                        {
                            XmlDocument objDummyDocument = new XmlDocument
                            {
                                XmlResolver = null
                            };
                            XmlNode bonusNode = objDummyDocument.CreateNode(XmlNodeType.Element, "bonus", null);
                            objDummyDocument.AppendChild(bonusNode);
                            XmlNode powerNode = objDummyDocument.ImportNode(objXmlMetatype["optionalpowers"].CloneNode(true), true);
                            objDummyDocument.ImportNode(powerNode, true);
                            bonusNode.AppendChild(powerNode);
                            ImprovementManager.CreateImprovements(objCharacter, Improvement.ImprovementSource.Metatype, objCharacter.Metatype, bonusNode, 1, objCharacter.Metatype);
                        }
                    }

                    // Add any Complex Forms the Critter comes with (typically Sprites)
                    XmlDocument objXmlProgramDocument = _objSpirit.CharacterObject.LoadData("complexforms.xml");
                    foreach (XmlNode objXmlComplexForm in objXmlCritter.SelectNodes("complexforms/complexform"))
                    {
                        string      strForceValue         = objXmlComplexForm.Attributes?["select"]?.InnerText ?? string.Empty;
                        XmlNode     objXmlComplexFormData = objXmlProgramDocument.SelectSingleNode("/chummer/complexforms/complexform[name = \"" + objXmlComplexForm.InnerText + "\"]");
                        ComplexForm objComplexForm        = new ComplexForm(objCharacter);
                        objComplexForm.Create(objXmlComplexFormData, strForceValue);
                        objCharacter.ComplexForms.Add(objComplexForm);
                    }

                    objCharacter.Alias   = strCritterName;
                    objCharacter.Created = true;
                    if (!objCharacter.Save())
                    {
                        return;
                    }
                }

                // Link the newly-created Critter to the Spirit.
                imgLink.SetToolTip(LanguageManager.GetString(_objSpirit.EntityType == SpiritType.Spirit ? "Tip_Spirit_OpenFile" : "Tip_Sprite_OpenFile"));
                ContactDetailChanged?.Invoke(this, EventArgs.Empty);

                Character objOpenCharacter = await Program.MainForm.LoadCharacter(_objSpirit.FileName).ConfigureAwait(true);

                Program.MainForm.OpenCharacter(objOpenCharacter);
            }
        }
Пример #3
0
        private void lstMartialArts_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }

            string strSelectedId = lstMartialArts.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                // Populate the Martial Arts list.
                XPathNavigator objXmlArt = _xmlBaseMartialArtsNode.SelectSingleNode("martialart[id = " + strSelectedId.CleanXPath() + "]");

                if (objXmlArt != null)
                {
                    lblKarmaCost.Text         = objXmlArt.SelectSingleNode("cost")?.Value ?? 7.ToString(GlobalOptions.CultureInfo);
                    lblKarmaCostLabel.Visible = !string.IsNullOrEmpty(lblKarmaCost.Text);

                    StringBuilder objTechniqueStringBuilder = new StringBuilder();
                    foreach (XPathNavigator xmlMartialArtsTechnique in objXmlArt.Select("techniques/technique"))
                    {
                        string strLoopTechniqueName = xmlMartialArtsTechnique.SelectSingleNode("name")?.Value ?? string.Empty;
                        if (!string.IsNullOrEmpty(strLoopTechniqueName))
                        {
                            XPathNavigator xmlTechniqueNode = _xmlBaseMartialArtsTechniquesNode.SelectSingleNode(string.Format(GlobalOptions.InvariantCultureInfo, "technique[name = {0} and ({1})]",
                                                                                                                               strLoopTechniqueName.CleanXPath(), _objCharacter.Options.BookXPath()));
                            if (xmlTechniqueNode != null)
                            {
                                if (objTechniqueStringBuilder.Length > 0)
                                {
                                    objTechniqueStringBuilder.AppendLine(",");
                                }

                                objTechniqueStringBuilder.Append(GlobalOptions.Language != GlobalOptions.DefaultLanguage ? xmlTechniqueNode.SelectSingleNode("translate")?.Value ?? strLoopTechniqueName: strLoopTechniqueName);
                            }
                        }
                    }
                    lblIncludedTechniques.Text    = objTechniqueStringBuilder.ToString();
                    gpbIncludedTechniques.Visible = !string.IsNullOrEmpty(lblIncludedTechniques.Text);

                    string       strSource       = objXmlArt.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown");
                    string       strPage         = objXmlArt.SelectSingleNode("altpage")?.Value ?? objXmlArt.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown");
                    SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter);
                    objSourceString.SetControl(lblSource);
                    lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
                }
                else
                {
                    lblKarmaCostLabel.Visible     = false;
                    lblKarmaCost.Text             = string.Empty;
                    gpbIncludedTechniques.Visible = false;
                    lblIncludedTechniques.Text    = string.Empty;
                    lblSourceLabel.Visible        = false;
                    lblSource.Text = string.Empty;
                    lblSource.SetToolTip(string.Empty);
                }
            }
            else
            {
                lblKarmaCostLabel.Visible     = false;
                lblKarmaCost.Text             = string.Empty;
                gpbIncludedTechniques.Visible = false;
                lblIncludedTechniques.Text    = string.Empty;
                lblSourceLabel.Visible        = false;
                lblSource.Text = string.Empty;
                lblSource.SetToolTip(string.Empty);
            }
        }
Пример #4
0
 /// <summary>
 /// Print the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 /// <param name="objCulture">Culture in which to print numbers.</param>
 /// <param name="strLanguageToPrint">Language in which to print.</param>
 public void Print(XmlTextWriter objWriter, CultureInfo objCulture, string strLanguageToPrint)
 {
     if (objWriter == null)
     {
         return;
     }
     objWriter.WriteStartElement("spell");
     objWriter.WriteElementString("guid", InternalId);
     objWriter.WriteElementString("sourceid", SourceIDString);
     if (Limited)
     {
         objWriter.WriteElementString("name", string.Format(objCulture, "{0}{1}({2})",
                                                            DisplayNameShort(strLanguageToPrint), LanguageManager.GetString("String_Space", strLanguageToPrint), LanguageManager.GetString("String_SpellLimited", strLanguageToPrint)));
     }
     else if (Alchemical)
     {
         objWriter.WriteElementString("name", string.Format(objCulture, "{0}{1}({2})",
                                                            DisplayNameShort(strLanguageToPrint), LanguageManager.GetString("String_Space", strLanguageToPrint), LanguageManager.GetString("String_SpellAlchemical", strLanguageToPrint)));
     }
     else
     {
         objWriter.WriteElementString("name", DisplayNameShort(strLanguageToPrint));
     }
     objWriter.WriteElementString("name_english", Name);
     objWriter.WriteElementString("descriptors", DisplayDescriptors(strLanguageToPrint));
     objWriter.WriteElementString("category", DisplayCategory(strLanguageToPrint));
     objWriter.WriteElementString("category_english", Category);
     objWriter.WriteElementString("type", DisplayType(strLanguageToPrint));
     objWriter.WriteElementString("range", DisplayRange(strLanguageToPrint));
     objWriter.WriteElementString("damage", DisplayDamage(strLanguageToPrint));
     objWriter.WriteElementString("duration", DisplayDuration(strLanguageToPrint));
     objWriter.WriteElementString("dv", DisplayDV(strLanguageToPrint));
     objWriter.WriteElementString("alchemy", Alchemical.ToString(GlobalOptions.InvariantCultureInfo));
     objWriter.WriteElementString("dicepool", DicePool.ToString(objCulture));
     objWriter.WriteElementString("source", _objCharacter.LanguageBookShort(Source, strLanguageToPrint));
     objWriter.WriteElementString("page", DisplayPage(strLanguageToPrint));
     objWriter.WriteElementString("extra", _objCharacter.TranslateExtra(Extra, strLanguageToPrint));
     if (_objCharacter.Options.PrintNotes)
     {
         objWriter.WriteElementString("notes", Notes);
     }
     objWriter.WriteEndElement();
 }
Пример #5
0
        private void tsRemoveCharacter_Click(object sender, EventArgs e)
        {
            // Remove the file association from the Contact.
            if (Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_RemoveCharacterAssociation"), LanguageManager.GetString("MessageTitle_RemoveCharacterAssociation"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                _objSpirit.FileName         = string.Empty;
                _objSpirit.RelativeFileName = string.Empty;
                imgLink.SetToolTip(LanguageManager.GetString(_objSpirit.EntityType == SpiritType.Spirit ? "Tip_Spirit_LinkSpirit" : "Tip_Sprite_LinkSprite"));

                // Set the relative path.
                Uri uriApplication = new Uri(Utils.GetStartupPath);
                Uri uriFile        = new Uri(_objSpirit.FileName);
                Uri uriRelative    = uriApplication.MakeRelativeUri(uriFile);
                _objSpirit.RelativeFileName = "../" + uriRelative;

                ContactDetailChanged?.Invoke(this, e);
            }
        }
Пример #6
0
        private void tsSaveAsHTML_Click(object sender, EventArgs e)
        {
            // Save the generated output as HTML.
            SaveFileDialog1.Filter = LanguageManager.GetString("DialogFilter_Html") + '|' + LanguageManager.GetString("DialogFilter_All");
            SaveFileDialog1.Title  = LanguageManager.GetString("Button_Viewer_SaveAsHtml");
            SaveFileDialog1.ShowDialog();
            string strSaveFile = SaveFileDialog1.FileName;

            if (string.IsNullOrEmpty(strSaveFile))
            {
                return;
            }

            if (!strSaveFile.EndsWith(".html", StringComparison.OrdinalIgnoreCase) &&
                !strSaveFile.EndsWith(".htm", StringComparison.OrdinalIgnoreCase))
            {
                strSaveFile += ".htm";
            }

            using (TextWriter objWriter = new StreamWriter(strSaveFile, false, Encoding.UTF8))
                objWriter.Write(webViewer.DocumentText);
        }
Пример #7
0
        private void cmdSaveAsPdf_Click(object sender, EventArgs e)
        {
            // Save the generated output as PDF.
            SaveFileDialog1.Filter = LanguageManager.GetString("DialogFilter_Pdf") + '|' + LanguageManager.GetString("DialogFilter_All");
            SaveFileDialog1.Title  = LanguageManager.GetString("Button_Viewer_SaveAsPdf");
            SaveFileDialog1.ShowDialog();
            string strSaveFile = SaveFileDialog1.FileName;

            if (string.IsNullOrEmpty(strSaveFile))
            {
                return;
            }

            if (!strSaveFile.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase))
            {
                strSaveFile += ".pdf";
            }

            if (!Directory.Exists(Path.GetDirectoryName(strSaveFile)) || !Utils.CanWriteToPath(strSaveFile))
            {
                Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_File_Cannot_Be_Accessed"));
                return;
            }
            if (File.Exists(strSaveFile))
            {
                try
                {
                    File.Delete(strSaveFile);
                }
                catch (IOException)
                {
                    Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_File_Cannot_Be_Accessed"));
                    return;
                }
                catch (UnauthorizedAccessException)
                {
                    Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_File_Cannot_Be_Accessed"));
                    return;
                }
            }

            PdfDocument objPdfDocument = new PdfDocument
            {
                Html = webViewer.DocumentText
            };

            objPdfDocument.ExtraParams.Add("encoding", "UTF-8");
            objPdfDocument.ExtraParams.Add("dpi", "300");
            objPdfDocument.ExtraParams.Add("margin-top", "13");
            objPdfDocument.ExtraParams.Add("margin-bottom", "19");
            objPdfDocument.ExtraParams.Add("margin-left", "13");
            objPdfDocument.ExtraParams.Add("margin-right", "13");
            objPdfDocument.ExtraParams.Add("image-quality", "100");
            objPdfDocument.ExtraParams.Add("print-media-type", string.Empty);

            try
            {
                PdfConvert.ConvertHtmlToPdf(objPdfDocument, new PdfConvertEnvironment
                {
                    WkHtmlToPdfPath = Path.Combine(Utils.GetStartupPath, "wkhtmltopdf.exe"),
                    Timeout         = 60000,
                    TempFolderPath  = Path.GetTempPath()
                }, new PdfOutput
                {
                    OutputFilePath = strSaveFile
                });

                if (!string.IsNullOrWhiteSpace(GlobalOptions.PDFAppPath))
                {
                    Uri    uriPath   = new Uri(strSaveFile);
                    string strParams = GlobalOptions.PDFParameters
                                       .Replace("{page}", "1")
                                       .Replace("{localpath}", uriPath.LocalPath)
                                       .Replace("{absolutepath}", uriPath.AbsolutePath);
                    ProcessStartInfo objPdfProgramProcess = new ProcessStartInfo
                    {
                        FileName    = GlobalOptions.PDFAppPath,
                        Arguments   = strParams,
                        WindowStyle = ProcessWindowStyle.Hidden
                    };
                    Process.Start(objPdfProgramProcess);
                }
            }
            catch (Exception ex)
            {
                Program.MainForm.ShowMessageBox(this, ex.ToString());
            }
        }
Пример #8
0
        private void frmSelectArmor_Load(object sender, EventArgs e)
        {
            if (_objCharacter.Created)
            {
                chkHideOverAvailLimit.Visible = false;
                chkHideOverAvailLimit.Checked = false;
                lblMarkupLabel.Visible        = true;
                nudMarkup.Visible             = true;
                lblMarkupPercentLabel.Visible = true;
            }
            else
            {
                chkHideOverAvailLimit.Text    = string.Format(GlobalOptions.CultureInfo, chkHideOverAvailLimit.Text, _objCharacter.MaximumAvailability.ToString(GlobalOptions.CultureInfo));
                chkHideOverAvailLimit.Checked = _objCharacter.Options.HideItemsOverAvailLimit;
                lblMarkupLabel.Visible        = false;
                nudMarkup.Visible             = false;
                lblMarkupPercentLabel.Visible = false;
            }

            DataGridViewCellStyle dataGridViewNuyenCellStyle = new DataGridViewCellStyle
            {
                Alignment = DataGridViewContentAlignment.TopRight,
                Format    = _objCharacter.Options.NuyenFormat + '¥',
                NullValue = null
            };

            Cost.DefaultCellStyle = dataGridViewNuyenCellStyle;

            // Populate the Armor Category list.
            XmlNodeList objXmlCategoryList = _objXmlDocument.SelectNodes("/chummer/categories/category");

            if (objXmlCategoryList != null)
            {
                foreach (XmlNode objXmlCategory in objXmlCategoryList)
                {
                    string strInnerText = objXmlCategory.InnerText;
                    _lstCategory.Add(new ListItem(strInnerText,
                                                  objXmlCategory.Attributes?["translate"]?.InnerText ?? strInnerText));
                }
            }
            _lstCategory.Sort(CompareListItems.CompareNames);

            if (_lstCategory.Count > 0)
            {
                _lstCategory.Insert(0, new ListItem("Show All", LanguageManager.GetString("String_ShowAll")));
            }

            cboCategory.BeginUpdate();
            cboCategory.ValueMember        = nameof(ListItem.Value);
            cboCategory.DisplayMember      = nameof(ListItem.Name);
            cboCategory.DataSource         = _lstCategory;
            chkBlackMarketDiscount.Visible = _objCharacter.BlackMarketDiscount;
            // Select the first Category in the list.
            if (!string.IsNullOrEmpty(s_StrSelectCategory))
            {
                cboCategory.SelectedValue = s_StrSelectCategory;
            }

            if (cboCategory.SelectedIndex == -1)
            {
                cboCategory.SelectedIndex = 0;
            }
            cboCategory.EndUpdate();

            _blnLoading = false;

            RefreshList();
        }
        private void UpdateInfo()
        {
            if (_blnLoading)
            {
                return;
            }

            XmlNode xmlSelectedMount = null;
            string  strSelectedMount = cboSize.SelectedValue?.ToString();

            if (string.IsNullOrEmpty(strSelectedMount))
            {
                cmdOK.Enabled = false;
            }
            else
            {
                xmlSelectedMount = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedMount + "\"]");
                if (xmlSelectedMount == null)
                {
                    cmdOK.Enabled = false;
                }
                else
                {
                    string strSelectedControl = cboControl.SelectedValue?.ToString();
                    if (string.IsNullOrEmpty(strSelectedControl))
                    {
                        cmdOK.Enabled = false;
                    }
                    else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedControl + "\"]") == null)
                    {
                        cmdOK.Enabled = false;
                    }
                    else
                    {
                        string strSelectedFlexibility = cboFlexibility.SelectedValue?.ToString();
                        if (string.IsNullOrEmpty(strSelectedFlexibility))
                        {
                            cmdOK.Enabled = false;
                        }
                        else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedFlexibility + "\"]") == null)
                        {
                            cmdOK.Enabled = false;
                        }
                        else
                        {
                            string strSelectedVisibility = cboVisibility.SelectedValue?.ToString();
                            if (string.IsNullOrEmpty(strSelectedVisibility))
                            {
                                cmdOK.Enabled = false;
                            }
                            else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedVisibility + "\"]") == null)
                            {
                                cmdOK.Enabled = false;
                            }
                            else
                            {
                                cmdOK.Enabled = true;
                            }
                        }
                    }
                }
            }

            string[] astrSelectedValues = { cboVisibility.SelectedValue?.ToString(), cboFlexibility.SelectedValue?.ToString(), cboControl.SelectedValue?.ToString() };

            cmdDeleteMod.Enabled = false;
            string strSelectedModId = treMods.SelectedNode?.Tag.ToString();
            string strSpace         = LanguageManager.GetString("String_Space");

            if (!string.IsNullOrEmpty(strSelectedModId) && strSelectedModId.IsGuid())
            {
                VehicleMod objMod = _lstMods.FirstOrDefault(x => x.InternalId == strSelectedModId);
                if (objMod != null)
                {
                    cmdDeleteMod.Enabled = !objMod.IncludedInVehicle;
                    lblSlots.Text        = objMod.CalculatedSlots.ToString(GlobalOptions.InvariantCultureInfo);
                    lblAvailability.Text = objMod.DisplayTotalAvail;

                    if (chkFreeItem.Checked)
                    {
                        lblCost.Text = (0.0m).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    }
                    else
                    {
                        int intTotalSlots = Convert.ToInt32(xmlSelectedMount?["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                        foreach (string strSelectedId in astrSelectedValues)
                        {
                            if (!string.IsNullOrEmpty(strSelectedId))
                            {
                                XmlNode xmlLoopNode = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedId + "\"]");
                                if (xmlLoopNode != null)
                                {
                                    intTotalSlots += Convert.ToInt32(xmlLoopNode["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                                }
                            }
                        }
                        foreach (VehicleMod objLoopMod in _lstMods)
                        {
                            intTotalSlots += objLoopMod.CalculatedSlots;
                        }
                        lblCost.Text = (objMod.TotalCostInMountCreation(intTotalSlots) * (1 + (nudMarkup.Value / 100.0m))).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    }

                    objMod.SetSourceDetail(lblSource);
                    lblCostLabel.Visible         = !string.IsNullOrEmpty(lblCost.Text);
                    lblSlotsLabel.Visible        = !string.IsNullOrEmpty(lblSlots.Text);
                    lblAvailabilityLabel.Visible = !string.IsNullOrEmpty(lblAvailability.Text);
                    lblSourceLabel.Visible       = !string.IsNullOrEmpty(lblSource.Text);
                    return;
                }
            }

            if (xmlSelectedMount == null)
            {
                lblCost.Text                 = string.Empty;
                lblSlots.Text                = string.Empty;
                lblAvailability.Text         = string.Empty;
                lblCostLabel.Visible         = false;
                lblSlotsLabel.Visible        = false;
                lblAvailabilityLabel.Visible = false;
                return;
            }
            decimal decCost  = !chkFreeItem.Checked ? Convert.ToDecimal(xmlSelectedMount["cost"]?.InnerText, GlobalOptions.InvariantCultureInfo) : 0;
            int     intSlots = Convert.ToInt32(xmlSelectedMount["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);

            string strAvail       = xmlSelectedMount["avail"]?.InnerText ?? string.Empty;
            char   chrAvailSuffix = strAvail.Length > 0 ? strAvail[strAvail.Length - 1] : ' ';

            if (chrAvailSuffix == 'F' || chrAvailSuffix == 'R')
            {
                strAvail = strAvail.Substring(0, strAvail.Length - 1);
            }
            else
            {
                chrAvailSuffix = ' ';
            }
            int intAvail = Convert.ToInt32(strAvail, GlobalOptions.InvariantCultureInfo);

            foreach (string strSelectedId in astrSelectedValues)
            {
                if (!string.IsNullOrEmpty(strSelectedId))
                {
                    XmlNode xmlLoopNode = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedId + "\"]");
                    if (xmlLoopNode != null)
                    {
                        if (!chkFreeItem.Checked)
                        {
                            decCost += Convert.ToInt32(xmlLoopNode["cost"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                        }

                        intSlots += Convert.ToInt32(xmlLoopNode["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);

                        string strLoopAvail       = xmlLoopNode["avail"]?.InnerText ?? string.Empty;
                        char   chrLoopAvailSuffix = strLoopAvail.Length > 0 ? strLoopAvail[strLoopAvail.Length - 1] : ' ';
                        if (chrLoopAvailSuffix == 'F')
                        {
                            strLoopAvail   = strLoopAvail.Substring(0, strLoopAvail.Length - 1);
                            chrAvailSuffix = 'F';
                        }
                        else if (chrLoopAvailSuffix == 'R')
                        {
                            strLoopAvail = strLoopAvail.Substring(0, strLoopAvail.Length - 1);
                            if (chrAvailSuffix == ' ')
                            {
                                chrAvailSuffix = 'R';
                            }
                        }
                        intAvail += Convert.ToInt32(strLoopAvail, GlobalOptions.InvariantCultureInfo);
                    }
                }
            }
            foreach (VehicleMod objMod in _lstMods)
            {
                intSlots += objMod.CalculatedSlots;
                AvailabilityValue objLoopAvail = objMod.TotalAvailTuple();
                char chrLoopAvailSuffix        = objLoopAvail.Suffix;
                if (chrLoopAvailSuffix == 'F')
                {
                    chrAvailSuffix = 'F';
                }
                else if (chrAvailSuffix != 'F' && chrLoopAvailSuffix == 'R')
                {
                    chrAvailSuffix = 'R';
                }
                intAvail += objLoopAvail.Value;
            }
            if (!chkFreeItem.Checked)
            {
                foreach (VehicleMod objMod in _lstMods)
                {
                    decCost += objMod.TotalCostInMountCreation(intSlots);
                }
            }

            string strAvailText = intAvail.ToString(GlobalOptions.CultureInfo);

            if (chrAvailSuffix == 'F')
            {
                strAvailText += LanguageManager.GetString("String_AvailForbidden");
            }
            else if (chrAvailSuffix == 'R')
            {
                strAvailText += LanguageManager.GetString("String_AvailRestricted");
            }

            decCost                     *= 1 + (nudMarkup.Value / 100.0m);
            lblCost.Text                 = decCost.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
            lblSlots.Text                = intSlots.ToString(GlobalOptions.CultureInfo);
            lblAvailability.Text         = strAvailText;
            lblCostLabel.Visible         = !string.IsNullOrEmpty(lblCost.Text);
            lblSlotsLabel.Visible        = !string.IsNullOrEmpty(lblSlots.Text);
            lblAvailabilityLabel.Visible = !string.IsNullOrEmpty(lblAvailability.Text);

            string strSource = xmlSelectedMount["source"]?.InnerText ?? LanguageManager.GetString("String_Unknown");
            string strPage   = xmlSelectedMount["altpage"]?.InnerText ?? xmlSelectedMount["page"]?.InnerText ?? LanguageManager.GetString("String_Unknown");

            lblSource.Text = CommonFunctions.LanguageBookShort(strSource) + strSpace + strPage;
            lblSource.SetToolTip(CommonFunctions.LanguageBookLong(strSource) + strSpace +
                                 LanguageManager.GetString("String_Page") + strSpace + strPage);
            lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
        }
Пример #10
0
        private void lstArmor_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }

            XmlNode xmlArmor      = null;
            string  strSelectedId = lstArmor.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                xmlArmor = _objXmlDocument.SelectSingleNode("/chummer/armors/armor[id = \"" + strSelectedId + "\"]");
            }
            if (xmlArmor != null)
            {
                // Create the Armor so we can show its Total Avail (some Armor includes Chemical Seal which adds +6 which wouldn't be factored in properly otherwise).
                Armor         objArmor   = new Armor(_objCharacter);
                List <Weapon> lstWeapons = new List <Weapon>();
                objArmor.Create(xmlArmor, 0, lstWeapons, true, true, true);

                _objSelectedArmor = objArmor;

                string strRating = xmlArmor["rating"]?.InnerText;
                if (!string.IsNullOrEmpty(strRating))
                {
                    nudRating.Maximum = Convert.ToInt32(strRating, GlobalOptions.InvariantCultureInfo);
                    if (chkHideOverAvailLimit.Checked)
                    {
                        while (nudRating.Maximum > 1 && !SelectionShared.CheckAvailRestriction(xmlArmor, _objCharacter, decimal.ToInt32(nudRating.Maximum)))
                        {
                            nudRating.Maximum -= 1;
                        }
                    }

                    if (chkShowOnlyAffordItems.Checked && !chkFreeItem.Checked)
                    {
                        decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                        if (_setBlackMarketMaps.Contains(xmlArmor.SelectSingleNode("category")?.Value))
                        {
                            decCostMultiplier *= 0.9m;
                        }
                        while (nudRating.Maximum > 1 && !SelectionShared.CheckNuyenRestriction(xmlArmor, _objCharacter.Nuyen, decCostMultiplier, decimal.ToInt32(nudRating.Maximum)))
                        {
                            nudRating.Maximum -= 1;
                        }
                    }
                    lblRatingLabel.Visible   = true;
                    nudRating.Minimum        = 1;
                    nudRating.Value          = 1;
                    nudRating.Enabled        = nudRating.Minimum != nudRating.Maximum;
                    nudRating.Visible        = true;
                    lblRatingNALabel.Visible = false;
                }
                else
                {
                    lblRatingLabel.Visible   = true;
                    lblRatingNALabel.Visible = true;
                    nudRating.Minimum        = 0;
                    nudRating.Maximum        = 0;
                    nudRating.Value          = 0;
                    nudRating.Enabled        = false;
                    nudRating.Visible        = false;
                }

                string strRatingLabel = xmlArmor.SelectSingleNode("ratinglabel")?.Value;
                lblRatingLabel.Text = !string.IsNullOrEmpty(strRatingLabel)
                    ? string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("Label_RatingFormat"),
                                    LanguageManager.GetString(strRatingLabel))
                    : LanguageManager.GetString("Label_Rating");
            }
            else
            {
                _objSelectedArmor        = null;
                lblRatingLabel.Visible   = false;
                lblRatingNALabel.Visible = false;
                nudRating.Visible        = false;
                nudRating.Enabled        = false;
                nudRating.Minimum        = 0;
                nudRating.Value          = 0;
            }

            UpdateArmorInfo();
        }
Пример #11
0
        /// <summary>
        /// Builds the list of Armors to render in the active tab.
        /// </summary>
        /// <param name="objXmlArmorList">XmlNodeList of Armors to render.</param>
        private void BuildArmorList(XmlNodeList objXmlArmorList)
        {
            switch (tabControl.SelectedIndex)
            {
            case 1:
                DataTable tabArmor = new DataTable("armor");
                tabArmor.Columns.Add("ArmorGuid");
                tabArmor.Columns.Add("ArmorName");
                tabArmor.Columns.Add("Armor");
                tabArmor.Columns["Armor"].DataType = typeof(int);
                tabArmor.Columns.Add("Capacity");
                tabArmor.Columns["Capacity"].DataType = typeof(decimal);
                tabArmor.Columns.Add("Avail");
                tabArmor.Columns["Avail"].DataType = typeof(AvailabilityValue);
                tabArmor.Columns.Add("Special");
                tabArmor.Columns.Add("Source");
                tabArmor.Columns["Source"].DataType = typeof(SourceString);
                tabArmor.Columns.Add("Cost");
                tabArmor.Columns["Cost"].DataType = typeof(NuyenString);

                // Populate the Armor list.
                foreach (XmlNode objXmlArmor in objXmlArmorList)
                {
                    decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                    if (_setBlackMarketMaps.Contains(objXmlArmor["category"]?.InnerText))
                    {
                        decCostMultiplier *= 0.9m;
                    }
                    if (!chkHideOverAvailLimit.Checked || SelectionShared.CheckAvailRestriction(objXmlArmor, _objCharacter) &&
                        (chkFreeItem.Checked || !chkShowOnlyAffordItems.Checked ||
                         SelectionShared.CheckNuyenRestriction(objXmlArmor, _objCharacter.Nuyen, decCostMultiplier)))
                    {
                        Armor         objArmor   = new Armor(_objCharacter);
                        List <Weapon> lstWeapons = new List <Weapon>();
                        objArmor.Create(objXmlArmor, 0, lstWeapons, true, true, true);

                        string            strArmorGuid   = objArmor.SourceIDString;
                        string            strArmorName   = objArmor.CurrentDisplayName;
                        int               intArmor       = objArmor.TotalArmor;
                        decimal           decCapacity    = Convert.ToDecimal(objArmor.CalculatedCapacity, GlobalOptions.CultureInfo);
                        AvailabilityValue objAvail       = objArmor.TotalAvailTuple();
                        StringBuilder     strAccessories = new StringBuilder();
                        foreach (ArmorMod objMod in objArmor.ArmorMods)
                        {
                            strAccessories.AppendLine(objMod.CurrentDisplayName);
                        }
                        foreach (Gear objGear in objArmor.Gear)
                        {
                            strAccessories.AppendLine(objGear.CurrentDisplayName);
                        }
                        if (strAccessories.Length > 0)
                        {
                            strAccessories.Length -= Environment.NewLine.Length;
                        }
                        SourceString strSource = new SourceString(objArmor.Source, objArmor.DisplayPage(GlobalOptions.Language), GlobalOptions.Language, GlobalOptions.CultureInfo);
                        NuyenString  strCost   = new NuyenString(objArmor.DisplayCost(out decimal _, false));

                        tabArmor.Rows.Add(strArmorGuid, strArmorName, intArmor, decCapacity, objAvail, strAccessories.ToString(), strSource, strCost);
                    }
                }

                DataSet set = new DataSet("armor");
                set.Tables.Add(tabArmor);

                dgvArmor.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                dgvArmor.DataSource       = set;
                dgvArmor.DataMember       = "armor";
                break;

            default:
                List <ListItem> lstArmors    = new List <ListItem>();
                int             intOverLimit = 0;
                string          strSpace     = LanguageManager.GetString("String_Space");
                foreach (XmlNode objXmlArmor in objXmlArmorList)
                {
                    decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                    if (_setBlackMarketMaps.Contains(objXmlArmor["category"]?.InnerText))
                    {
                        decCostMultiplier *= 0.9m;
                    }
                    if ((!chkHideOverAvailLimit.Checked ||
                         (chkHideOverAvailLimit.Checked &&
                          SelectionShared.CheckAvailRestriction(objXmlArmor, _objCharacter))) &&
                        (chkFreeItem.Checked ||
                         !chkShowOnlyAffordItems.Checked ||
                         (chkShowOnlyAffordItems.Checked &&
                          SelectionShared.CheckNuyenRestriction(objXmlArmor, _objCharacter.Nuyen, decCostMultiplier))))
                    {
                        string strDisplayName = objXmlArmor["translate"]?.InnerText ?? objXmlArmor["name"]?.InnerText;
                        if (!_objCharacter.Options.SearchInCategoryOnly && txtSearch.TextLength != 0)
                        {
                            string strCategory = objXmlArmor["category"]?.InnerText;
                            if (!string.IsNullOrEmpty(strCategory))
                            {
                                ListItem objFoundItem = _lstCategory.Find(objFind => objFind.Value.ToString() == strCategory);
                                if (!string.IsNullOrEmpty(objFoundItem.Name))
                                {
                                    strDisplayName += strSpace + '[' + objFoundItem.Name + ']';
                                }
                            }
                        }

                        lstArmors.Add(new ListItem(objXmlArmor["id"]?.InnerText, strDisplayName));
                    }
                    else
                    {
                        ++intOverLimit;
                    }
                }

                lstArmors.Sort(CompareListItems.CompareNames);
                if (intOverLimit > 0)
                {
                    // Add after sort so that it's always at the end
                    lstArmors.Add(new ListItem(string.Empty,
                                               string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("String_RestrictedItemsHidden"),
                                                             intOverLimit)));
                }
                _blnLoading = true;
                string strOldSelected = lstArmor.SelectedValue?.ToString();
                lstArmor.BeginUpdate();
                lstArmor.ValueMember   = nameof(ListItem.Value);
                lstArmor.DisplayMember = nameof(ListItem.Name);
                lstArmor.DataSource    = lstArmors;
                _blnLoading            = false;
                if (!string.IsNullOrEmpty(strOldSelected))
                {
                    lstArmor.SelectedValue = strOldSelected;
                }
                else
                {
                    lstArmor.SelectedIndex = -1;
                }
                lstArmor.EndUpdate();
                break;
            }
        }
Пример #12
0
        private void frmSelectItem_Load(object sender, EventArgs e)
        {
            List <ListItem> lstItems = new List <ListItem>();

            if (_strMode == "Gear")
            {
                // Add each of the items to a new List since we need to also grab their plugin information.
                foreach (Gear objGear in _lstGear)
                {
                    ListItem objAmmo = new ListItem();
                    objAmmo.Value = objGear.InternalId;
                    objAmmo.Name  = objGear.DisplayNameShort;
                    // Retrieve the plugin information if it has any.
                    if (objGear.Children.Count > 0)
                    {
                        string strPlugins = string.Empty;
                        foreach (Gear objChild in objGear.Children)
                        {
                            strPlugins += objChild.DisplayNameShort + ", ";
                        }
                        // Remove the trailing comma.
                        strPlugins = strPlugins.Substring(0, strPlugins.Length - 2);
                        // Append the plugin information to the name.
                        objAmmo.Name += " [" + strPlugins + "]";
                    }
                    if (objGear.Rating > 0)
                    {
                        objAmmo.Name += " (" + LanguageManager.GetString("String_Rating") + " " + objGear.Rating.ToString() + ")";
                    }
                    objAmmo.Name += " x" + objGear.Quantity.ToString();
                    lstItems.Add(objAmmo);
                }
            }
            else if (_strMode == "Vehicles")
            {
                // Add each of the items to a new List.
                foreach (Vehicle objVehicle in _lstVehicles)
                {
                    ListItem objItem = new ListItem();
                    objItem.Value = objVehicle.InternalId;
                    objItem.Name  = objVehicle.DisplayName;
                    lstItems.Add(objItem);
                }
            }
            else if (_strMode == "VehicleMods")
            {
                // Add each of the items to a new List.
                foreach (VehicleMod objMod in _lstVehicleMods)
                {
                    ListItem objItem = new ListItem();
                    objItem.Value = objMod.InternalId;
                    objItem.Name  = objMod.DisplayName;
                    lstItems.Add(objItem);
                }
            }
            else if (_strMode == "General")
            {
                lstItems = _lstGeneralItems;
            }
            else if (_strMode == "Dropdown")
            {
                cboAmmo.DropDownStyle = ComboBoxStyle.DropDown;
                lstItems = _lstGeneralItems;
            }
            else if (_strMode == "Restricted")
            {
                cboAmmo.DropDownStyle = ComboBoxStyle.DropDown;

                if (!_objCharacter.Options.LicenseRestricted)
                {
                    XmlDocument objXmlDocument = XmlManager.Load("licenses.xml");
                    XmlNodeList objXmlList     = objXmlDocument.SelectNodes("/chummer/licenses/license");

                    foreach (XmlNode objNode in objXmlList)
                    {
                        ListItem objItem = new ListItem();
                        objItem.Value = objNode.InnerText;
                        objItem.Name  = objNode.Attributes?["translate"]?.InnerText ?? objNode.InnerText;
                        lstItems.Add(objItem);
                    }
                }
                else
                {
                    // Cyberware/Bioware.
                    foreach (Cyberware objCyberware in _objCharacter.Cyberware)
                    {
                        if (objCyberware.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                        {
                            ListItem objItem = new ListItem();
                            objItem.Value = objCyberware.DisplayNameShort;
                            objItem.Name  = objCyberware.DisplayNameShort;
                            lstItems.Add(objItem);
                        }
                        foreach (Cyberware objChild in objCyberware.Children)
                        {
                            if (objChild.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                            {
                                ListItem objItem = new ListItem();
                                objItem.Value = objChild.DisplayNameShort;
                                objItem.Name  = objChild.DisplayNameShort;
                                lstItems.Add(objItem);
                            }
                        }
                    }

                    // Armor.
                    foreach (Armor objArmor in _objCharacter.Armor)
                    {
                        if (objArmor.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                        {
                            ListItem objItem = new ListItem();
                            objItem.Value = objArmor.DisplayNameShort;
                            objItem.Name  = objArmor.DisplayNameShort;
                            lstItems.Add(objItem);
                        }
                        foreach (ArmorMod objMod in objArmor.ArmorMods)
                        {
                            if (objMod.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                            {
                                ListItem objItem = new ListItem();
                                objItem.Value = objMod.DisplayNameShort;
                                objItem.Name  = objMod.DisplayNameShort;
                                lstItems.Add(objItem);
                            }
                        }
                        foreach (Gear objGear in objArmor.Gear)
                        {
                            if (objGear.TotalAvail().EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                            {
                                ListItem objItem = new ListItem();
                                objItem.Value = objGear.DisplayNameShort;
                                objItem.Name  = objGear.DisplayNameShort;
                                lstItems.Add(objItem);
                            }
                        }
                    }

                    // Weapons.
                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                    {
                        if (objWeapon.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                        {
                            ListItem objItem = new ListItem();
                            objItem.Value = objWeapon.DisplayNameShort;
                            objItem.Name  = objWeapon.DisplayNameShort;
                            lstItems.Add(objItem);
                        }
                        foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                        {
                            if (objAccessory.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")) && !objAccessory.IncludedInWeapon)
                            {
                                ListItem objItem = new ListItem();
                                objItem.Value = objAccessory.DisplayNameShort;
                                objItem.Name  = objAccessory.DisplayNameShort;
                                lstItems.Add(objItem);
                            }
                        }
                        if (objWeapon.UnderbarrelWeapons.Count > 0)
                        {
                            foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                            {
                                if (objUnderbarrelWeapon.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                                {
                                    ListItem objItem = new ListItem();
                                    objItem.Value = objUnderbarrelWeapon.DisplayNameShort;
                                    objItem.Name  = objUnderbarrelWeapon.DisplayNameShort;
                                    lstItems.Add(objItem);
                                }
                                foreach (WeaponAccessory objAccessory in objUnderbarrelWeapon.WeaponAccessories)
                                {
                                    if (objAccessory.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")) && !objAccessory.IncludedInWeapon)
                                    {
                                        ListItem objItem = new ListItem();
                                        objItem.Value = objAccessory.DisplayNameShort;
                                        objItem.Name  = objAccessory.DisplayNameShort;
                                        lstItems.Add(objItem);
                                    }
                                }
                            }
                        }
                    }

                    // Gear.
                    foreach (Gear objGear in _objCharacter.Gear)
                    {
                        if (objGear.TotalAvail().EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                        {
                            ListItem objItem = new ListItem();
                            objItem.Value = objGear.DisplayNameShort;
                            objItem.Name  = objGear.DisplayNameShort;
                            lstItems.Add(objItem);
                        }
                        foreach (Gear objChild in objGear.Children)
                        {
                            if (objChild.TotalAvail().EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                            {
                                ListItem objItem = new ListItem();
                                objItem.Value = objChild.DisplayNameShort;
                                objItem.Name  = objChild.DisplayNameShort;
                                lstItems.Add(objItem);
                            }
                            foreach (Gear objSubChild in objChild.Children)
                            {
                                if (objSubChild.TotalAvail().EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                                {
                                    ListItem objItem = new ListItem();
                                    objItem.Value = objSubChild.DisplayNameShort;
                                    objItem.Name  = objSubChild.DisplayNameShort;
                                    lstItems.Add(objItem);
                                }
                            }
                        }
                    }

                    // Vehicles.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        if (objVehicle.CalculatedAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                        {
                            ListItem objItem = new ListItem();
                            objItem.Value = objVehicle.DisplayNameShort;
                            objItem.Name  = objVehicle.DisplayNameShort;
                            lstItems.Add(objItem);
                        }
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            if (objMod.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")) && !objMod.IncludedInVehicle)
                            {
                                ListItem objItem = new ListItem();
                                objItem.Value = objMod.DisplayNameShort;
                                objItem.Name  = objMod.DisplayNameShort;
                                lstItems.Add(objItem);
                            }
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                if (objWeapon.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                                {
                                    ListItem objItem = new ListItem();
                                    objItem.Value = objWeapon.DisplayNameShort;
                                    objItem.Name  = objWeapon.DisplayNameShort;
                                    lstItems.Add(objItem);
                                }
                                foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                                {
                                    if (objAccessory.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")) && !objAccessory.IncludedInWeapon)
                                    {
                                        ListItem objItem = new ListItem();
                                        objItem.Value = objAccessory.DisplayNameShort;
                                        objItem.Name  = objAccessory.DisplayNameShort;
                                        lstItems.Add(objItem);
                                    }
                                }
                                if (objWeapon.UnderbarrelWeapons.Count > 0)
                                {
                                    foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                    {
                                        if (objUnderbarrelWeapon.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                                        {
                                            ListItem objItem = new ListItem();
                                            objItem.Value = objUnderbarrelWeapon.DisplayNameShort;
                                            objItem.Name  = objUnderbarrelWeapon.DisplayNameShort;
                                            lstItems.Add(objItem);
                                        }
                                        foreach (WeaponAccessory objAccessory in objUnderbarrelWeapon.WeaponAccessories)
                                        {
                                            if (objAccessory.TotalAvail.EndsWith(LanguageManager.GetString("String_AvailRestricted")) && !objAccessory.IncludedInWeapon)
                                            {
                                                ListItem objItem = new ListItem();
                                                objItem.Value = objAccessory.DisplayNameShort;
                                                objItem.Name  = objAccessory.DisplayNameShort;
                                                lstItems.Add(objItem);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        foreach (Gear objGear in objVehicle.Gear)
                        {
                            if (objGear.TotalAvail().EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                            {
                                ListItem objItem = new ListItem();
                                objItem.Value = objGear.DisplayNameShort;
                                objItem.Name  = objGear.DisplayNameShort;
                                lstItems.Add(objItem);
                            }
                            foreach (Gear objChild in objGear.Children)
                            {
                                if (objChild.TotalAvail().EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                                {
                                    ListItem objItem = new ListItem();
                                    objItem.Value = objChild.DisplayNameShort;
                                    objItem.Name  = objChild.DisplayNameShort;
                                    lstItems.Add(objItem);
                                }
                                foreach (Gear objSubChild in objChild.Children)
                                {
                                    if (objSubChild.TotalAvail().EndsWith(LanguageManager.GetString("String_AvailRestricted")))
                                    {
                                        ListItem objItem = new ListItem();
                                        objItem.Value = objSubChild.DisplayNameShort;
                                        objItem.Name  = objSubChild.DisplayNameShort;
                                        lstItems.Add(objItem);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Populate the lists.
            cboAmmo.BeginUpdate();
            cboAmmo.ValueMember   = "Value";
            cboAmmo.DisplayMember = "Name";
            cboAmmo.DataSource    = lstItems;

            // If there's only 1 value in the list, the character doesn't have a choice, so just accept it.
            if (cboAmmo.Items.Count == 1 && _blnAllowAutoSelect)
            {
                AcceptForm();
            }

            if (!string.IsNullOrEmpty(_strForceItem))
            {
                cboAmmo.SelectedIndex = cboAmmo.FindStringExact(_strForceItem);
                if (cboAmmo.SelectedIndex != -1)
                {
                    AcceptForm();
                }
            }
            cboAmmo.EndUpdate();
        }
Пример #13
0
        private void cmdRollDice_Click(object sender, EventArgs e)
        {
            List <int> lstRandom          = new List <int>();
            int        intHitCount        = 0;
            int        intGlitchCount     = 0;
            int        intGlitchThreshold = 0;
            int        intGlitchMin       = 1;

            intGlitchThreshold = Convert.ToInt32(Math.Ceiling((nudDice.Value + 1.0m) / 2.0m));
            // Deduct the Gremlins Rating from the Glitch Threshold.
            intGlitchThreshold -= Convert.ToInt32(nudGremlins.Value);
            if (intGlitchThreshold < 1)
            {
                intGlitchThreshold = 1;
            }

            // If Rushed Job is checked, the minimum die result for a Glitch becomes 2.
            if (chkRushJob.Checked)
            {
                intGlitchMin = 2;
            }

            for (int intCounter = 1; intCounter <= nudDice.Value; intCounter++)
            {
                if (chkRuleOf6.Checked)
                {
                    int intResult = 0;
                    do
                    {
                        do
                        {
                            _intModuloTemp = _objRandom.Next();
                        }while (_intModuloTemp >= int.MaxValue - 1); // Modulo bias removal for 1d6
                        intResult = 1 + _intModuloTemp % 6;
                        lstRandom.Add(intResult);
                    } while (intResult == 6);
                }
                else
                {
                    do
                    {
                        _intModuloTemp = _objRandom.Next();
                    }while (_intModuloTemp >= int.MaxValue - 1); // Modulo bias removal for 1d6
                    int intResult = 1 + _intModuloTemp % 6;
                    lstRandom.Add(intResult);
                }
            }

            _lstResults.Clear();
            foreach (int intResult in lstRandom)
            {
                ListItem objBubbleDieItem = new ListItem(intResult.ToString(), intResult.ToString());
                _lstResults.Add(objBubbleDieItem);

                if (cboMethod.SelectedValue.ToString() == "Standard")
                {
                    int intTarget = 5;
                    // If Cinematic Gameplay is turned on, Hits occur on 4, 5, or 6 instead.
                    if (chkCinematicGameplay.Checked)
                    {
                        intTarget = 4;
                    }

                    if (intResult >= intTarget)
                    {
                        intHitCount++;
                    }
                    if (intResult <= intGlitchMin)
                    {
                        intGlitchCount++;
                    }
                }
                else if (cboMethod.SelectedValue.ToString() == "Large")
                {
                    if (intResult >= 3)
                    {
                        intHitCount++;
                    }
                    if (intResult <= intGlitchMin)
                    {
                        intGlitchCount++;
                    }
                }
                else if (cboMethod.SelectedValue.ToString() == "ReallyLarge")
                {
                    intHitCount += intResult;
                }
            }
            if (chkBubbleDie.Checked && intGlitchCount == intGlitchThreshold - 1 && Convert.ToInt32(nudDice.Value) % 2 == 0)
            {
                do
                {
                    _intModuloTemp = _objRandom.Next();
                }while (_intModuloTemp >= int.MaxValue - 1); // Modulo bias removal for 1d6
                int      intBubbleDieResult = 1 + _intModuloTemp % 6;
                ListItem objBubbleDieItem   = new ListItem(intBubbleDieResult.ToString(), LanguageManager.GetString("String_BubbleDie") + " (" + intBubbleDieResult.ToString() + ")");
                _lstResults.Add(objBubbleDieItem);
                if (cboMethod.SelectedValue.ToString() == "Standard" || cboMethod.SelectedValue.ToString() == "Large")
                {
                    if (intBubbleDieResult <= intGlitchMin)
                    {
                        intGlitchCount++;
                    }
                }
            }

            lblResults.Text = LanguageManager.GetString("Label_DiceRoller_Result") + " ";
            if (intGlitchCount >= intGlitchThreshold)
            {
                if (intHitCount > 0)
                {
                    if (nudThreshold.Value > 0)
                    {
                        if (intHitCount >= nudThreshold.Value)
                        {
                            lblResults.Text += LanguageManager.GetString("String_DiceRoller_Success") + " (" + LanguageManager.GetString("String_DiceRoller_Glitch").Replace("{0}", intHitCount.ToString()) + ")";
                        }
                        else
                        {
                            lblResults.Text += LanguageManager.GetString("String_DiceRoller_Failure") + " (" + LanguageManager.GetString("String_DiceRoller_Glitch").Replace("{0}", intHitCount.ToString()) + ")";
                        }
                    }
                    else
                    {
                        lblResults.Text += LanguageManager.GetString("String_DiceRoller_Glitch").Replace("{0}", intHitCount.ToString());
                    }
                }
                else
                {
                    lblResults.Text += LanguageManager.GetString("String_DiceRoller_CriticalGlitch");
                }
            }
            else
            {
                if (nudThreshold.Value > 0)
                {
                    if (intHitCount >= nudThreshold.Value)
                    {
                        lblResults.Text += LanguageManager.GetString("String_DiceRoller_Success") + " (" + LanguageManager.GetString("String_DiceRoller_Hits").Replace("{0}", intHitCount.ToString()) + ")";
                    }
                    else
                    {
                        lblResults.Text += LanguageManager.GetString("String_DiceRoller_Failure") + " (" + LanguageManager.GetString("String_DiceRoller_Hits").Replace("{0}", intHitCount.ToString()) + ")";
                    }
                }
                else
                {
                    lblResults.Text += LanguageManager.GetString("String_DiceRoller_Hits").Replace("{0}", intHitCount.ToString());
                }
            }
            lblResults.Text += "\n\n" + LanguageManager.GetString("Label_DiceRoller_Sum") + " " + lstRandom.Sum().ToString();
            lstResults.BeginUpdate();
            lstResults.DataSource    = null;
            lstResults.ValueMember   = "Value";
            lstResults.DisplayMember = "Name";
            lstResults.DataSource    = _lstResults;
            lstResults.EndUpdate();
        }
Пример #14
0
        private void cmdRollDice_Click(object sender, EventArgs e)
        {
            // TODO roll the dice
            List <int> results = new List <int>();
            int        val     = 0;

            for (int i = 0; i < NumberOfDice; i++)
            {
                do
                {
                    _intModuloTemp = s_ObjRandom.Next();
                }while (_intModuloTemp >= int.MaxValue - 1); // Modulo bias removal for 1d6
                val = 1 + _intModuloTemp % 6;
                results.Add(val);

                // check for pushing the limit
                if (EdgeUse == EdgeUses.PushTheLimit || chkRuleOf6.Checked)
                {
                    while (val == 6)
                    {
                        do
                        {
                            _intModuloTemp = s_ObjRandom.Next();
                        }while (_intModuloTemp >= int.MaxValue - 1); // Modulo bias removal for 1d6
                        val = 1 + _intModuloTemp % 6;
                        results.Add(val);
                    }
                }
            }

            // populate the text box
            StringBuilder sb = new StringBuilder();
            // show the number of hits
            int hits = 0;
            // calculate the 1 (and 2's)
            int glitches = 0;

            foreach (int intResult in results)
            {
                if (intResult == 5 || intResult == 6)
                {
                    hits += 1;
                }
                else if (intResult == 1 || (chkRushJob.Checked && intResult == 2))
                {
                    glitches += 1;
                }
                sb.Append(intResult.ToString());
                sb.Append(", ");
            }
            if (sb.Length > 0)
            {
                sb.Length -= 2; // remove trailing comma
            }
            if (chkBubbleDie.Checked && results.Count % 2 == 0 && results.Count / 2 == glitches + Gremlins)
            {
                do
                {
                    _intModuloTemp = s_ObjRandom.Next();
                }while (_intModuloTemp >= int.MaxValue - 1); // Modulo bias removal for 1d6
                int intBubbleDieResult = 1 + _intModuloTemp % 6;
                sb.Append(", " + LanguageManager.GetString("String_BubbleDie", GlobalOptions.Language) + " (" + intBubbleDieResult.ToString() + ")");
                if (intBubbleDieResult == 1 || (chkRushJob.Checked && intBubbleDieResult == 2))
                {
                    glitches++;
                }
            }
            txtResults.Text = sb.ToString();

            // calculate if we glitched or critically glitched (using gremlins)
            bool glitch = false, criticalGlitch = false;

            glitch = glitches + Gremlins > 0 && results.Count / (glitches + Gremlins) < 2;

            if (glitch && hits == 0)
            {
                criticalGlitch = true;
            }
            int limitAppliedHits = hits;

            if (limitAppliedHits > Limit && EdgeUse != EdgeUses.PushTheLimit)
            {
                limitAppliedHits = Limit;
            }

            // show the results
            // we have not gone over our limit
            sb = new StringBuilder();
            if (hits > 0 && limitAppliedHits == hits)
            {
                sb.Append("Results: " + hits + " Hits!");
            }
            if (limitAppliedHits < hits)
            {
                sb.Append("Results: " + limitAppliedHits + " Hits by Limit!");
            }
            if (glitch && !criticalGlitch)
            {
                sb.Append(" Glitch!");   // we glitched though...
            }
            if (criticalGlitch)
            {
                sb.Append("Results: Critical Glitch!");   // we crited!
            }
            if (hits == 0 && !glitch)
            {
                sb.Append("Results: 0 Hits.");   // we have no hits and no glitches
            }
            if (Threshold > 0)
            {
                if (hits >= Threshold || limitAppliedHits >= Threshold)
                {
                    lblThreshold.Text = "Success! Threshold:";   // we succeded on the threshold test...
                }
            }
            lblResults.Text = sb.ToString();
        }
Пример #15
0
        /// <summary>
        /// Calculate the LP value for the selected items.
        /// </summary>
        private void CalculateValues(bool blnIncludePercentage = true)
        {
            if (_blnSkipRefresh)
            {
                return;
            }

            decimal decBaseCost = 0;
            decimal decCost     = 0;
            decimal decMod      = 0;
            // Get the base cost of the lifestyle
            string strSelectedId = cboLifestyle.SelectedValue?.ToString();

            if (strSelectedId != null)
            {
                XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[id = \"" + strSelectedId + "\"]");

                if (objXmlAspect != null)
                {
                    decBaseCost += Convert.ToDecimal(objXmlAspect["cost"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                    string strSource = objXmlAspect["source"]?.InnerText;
                    string strPage   = objXmlAspect["altpage"]?.InnerText ?? objXmlAspect["page"]?.InnerText;
                    if (!string.IsNullOrEmpty(strSource) && !string.IsNullOrEmpty(strPage))
                    {
                        string strSpaceCharacter = LanguageManager.GetString("String_Space", GlobalOptions.Language);
                        lblSource.Text = CommonFunctions.LanguageBookShort(strSource, GlobalOptions.Language) + strSpaceCharacter + strPage;
                        lblSource.SetToolTip(CommonFunctions.LanguageBookLong(strSource, GlobalOptions.Language) + strSpaceCharacter + LanguageManager.GetString("String_Page", GlobalOptions.Language) + strSpaceCharacter + strPage);
                    }
                    else
                    {
                        lblSource.Text = LanguageManager.GetString("String_Unknown", GlobalOptions.Language);
                        lblSource.SetToolTip(LanguageManager.GetString("String_Unknown", GlobalOptions.Language));
                    }

                    lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);

                    // Add the flat costs from qualities
                    foreach (TreeNode objNode in treQualities.Nodes)
                    {
                        if (objNode.Checked)
                        {
                            string strCost = _objXmlDocument.SelectSingleNode($"/chummer/qualities/quality[id = \"{objNode.Tag}\"]/cost")?.InnerText;
                            if (!string.IsNullOrEmpty(strCost))
                            {
                                object objProcess = CommonFunctions.EvaluateInvariantXPath(strCost, out bool blnIsSuccess);
                                if (blnIsSuccess)
                                {
                                    decCost += Convert.ToDecimal(objProcess, GlobalOptions.InvariantCultureInfo);
                                }
                            }
                        }
                    }

                    decimal decBaseMultiplier = 0;
                    if (blnIncludePercentage)
                    {
                        // Add the modifiers from qualities
                        foreach (TreeNode objNode in treQualities.Nodes)
                        {
                            if (!objNode.Checked)
                            {
                                continue;
                            }
                            objXmlAspect = _objXmlDocument.SelectSingleNode($"/chummer/qualities/quality[id = \"{objNode.Tag}\"]");
                            if (objXmlAspect == null)
                            {
                                continue;
                            }
                            string strMultiplier = objXmlAspect["multiplier"]?.InnerText;
                            if (!string.IsNullOrEmpty(strMultiplier))
                            {
                                decMod += Convert.ToDecimal(strMultiplier, GlobalOptions.InvariantCultureInfo) / 100.0m;
                            }
                            strMultiplier = objXmlAspect["multiplierbaseonly"]?.InnerText;
                            if (!string.IsNullOrEmpty(strMultiplier))
                            {
                                decBaseMultiplier += Convert.ToDecimal(strMultiplier, GlobalOptions.InvariantCultureInfo) / 100.0m;
                            }
                        }

                        // Check for modifiers in the improvements
                        decimal decModifier = Convert.ToDecimal(ImprovementManager.ValueOf(_objCharacter, Improvement.ImprovementType.LifestyleCost), GlobalOptions.InvariantCultureInfo);
                        decMod += decModifier / 100.0m;
                    }

                    decBaseCost += decBaseCost * decBaseMultiplier;
                }
            }

            decimal decNuyen = decBaseCost + decBaseCost * decMod + decCost;

            lblCost.Text = decNuyen.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
            if (nudPercentage.Value != 100)
            {
                decimal decDiscount = decNuyen;
                decDiscount   = decDiscount * (nudPercentage.Value / 100);
                lblCost.Text += LanguageManager.GetString("String_Space", GlobalOptions.Language) + '(' + decDiscount.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + "¥)";
            }

            lblCostLabel.Visible = !string.IsNullOrEmpty(lblCost.Text);
        }
Пример #16
0
        private void frmCreateWeaponMount_Load(object sender, EventArgs e)
        {
            XmlNode         xmlVehicleNode = _objVehicle.GetNode();
            List <ListItem> lstSize        = new List <ListItem>();
            // Populate the Weapon Mount Category list.
            string strSizeFilter = "category = \"Size\" and " + _objCharacter.Options.BookXPath();

            if (!_objVehicle.IsDrone && GlobalOptions.Dronemods)
            {
                strSizeFilter += " and not(optionaldrone)";
            }
            using (XmlNodeList xmlSizeNodeList = _xmlDoc.SelectNodes("/chummer/weaponmounts/weaponmount[" + strSizeFilter + "]"))
                if (xmlSizeNodeList?.Count > 0)
                {
                    foreach (XmlNode xmlSizeNode in xmlSizeNodeList)
                    {
                        string strId = xmlSizeNode["id"]?.InnerText;
                        if (string.IsNullOrEmpty(strId))
                        {
                            continue;
                        }

                        XmlNode xmlTestNode = xmlSizeNode.SelectSingleNode("forbidden/vehicledetails");
                        if (xmlTestNode != null)
                        {
                            // Assumes topmost parent is an AND node
                            if (xmlVehicleNode.ProcessFilterOperationNode(xmlTestNode, false))
                            {
                                continue;
                            }
                        }
                        xmlTestNode = xmlSizeNode.SelectSingleNode("required/vehicledetails");
                        if (xmlTestNode != null)
                        {
                            // Assumes topmost parent is an AND node
                            if (!xmlVehicleNode.ProcessFilterOperationNode(xmlTestNode, false))
                            {
                                continue;
                            }
                        }

                        lstSize.Add(new ListItem(strId, xmlSizeNode["translate"]?.InnerText ?? xmlSizeNode["name"]?.InnerText ?? LanguageManager.GetString("String_Unknown")));
                    }
                }

            cboSize.BeginUpdate();
            cboSize.ValueMember   = "Value";
            cboSize.DisplayMember = "Name";
            cboSize.DataSource    = lstSize;
            cboSize.Enabled       = lstSize.Count > 1;
            cboSize.EndUpdate();

            if (_objMount != null)
            {
                TreeNode objModsParentNode = new TreeNode
                {
                    Tag  = "Node_AdditionalMods",
                    Text = LanguageManager.GetString("Node_AdditionalMods")
                };
                treMods.Nodes.Add(objModsParentNode);
                objModsParentNode.Expand();
                foreach (VehicleMod objMod in _objMount.Mods)
                {
                    TreeNode objLoopNode = objMod.CreateTreeNode(null, null, null, null, null, null);
                    if (objLoopNode != null)
                    {
                        objModsParentNode.Nodes.Add(objLoopNode);
                    }
                }
                _lstMods.AddRange(_objMount.Mods);

                cboSize.SelectedValue = _objMount.SourceIDString;
            }
            if (cboSize.SelectedIndex == -1)
            {
                if (lstSize.Count > 0)
                {
                    cboSize.SelectedIndex = 0;
                }
            }
            else
            {
                RefreshCBOs();
            }

            nudMarkup.Visible             = AllowDiscounts;
            lblMarkupLabel.Visible        = AllowDiscounts;
            lblMarkupPercentLabel.Visible = AllowDiscounts;

            if (_objMount != null)
            {
                List <ListItem> lstVisibility  = cboVisibility.Items.Cast <ListItem>().ToList();
                List <ListItem> lstFlexibility = cboFlexibility.Items.Cast <ListItem>().ToList();
                List <ListItem> lstControl     = cboControl.Items.Cast <ListItem>().ToList();
                foreach (WeaponMountOption objExistingOption in _objMount.WeaponMountOptions)
                {
                    string strLoopId = objExistingOption.SourceIDString;
                    if (lstVisibility.Any(x => x.Value.ToString() == strLoopId))
                    {
                        cboVisibility.SelectedValue = strLoopId;
                    }
                    else if (lstFlexibility.Any(x => x.Value.ToString() == strLoopId))
                    {
                        cboFlexibility.SelectedValue = strLoopId;
                    }
                    else if (lstControl.Any(x => x.Value.ToString() == strLoopId))
                    {
                        cboControl.SelectedValue = strLoopId;
                    }
                }
            }

            _blnLoading = false;
            UpdateInfo();
            LanguageManager.TranslateWinForm(GlobalOptions.Language, this);
        }
Пример #17
0
        private void frmSelectLifestyle_Load(object sender, EventArgs e)
        {
            string strSelectedId = string.Empty;
            // Populate the Lifestyle ComboBoxes.
            List <ListItem> lstLifestyle = new List <ListItem>();

            using (XmlNodeList xmlLifestyleList = _objXmlDocument.SelectNodes("/chummer/lifestyles/lifestyle[" + _objCharacter.Options.BookXPath() + "]"))
                if (xmlLifestyleList?.Count > 0)
                {
                    foreach (XmlNode objXmlLifestyle in xmlLifestyleList)
                    {
                        string strLifeStyleId = objXmlLifestyle["id"]?.InnerText;
                        if (!string.IsNullOrEmpty(strLifeStyleId) && !strLifeStyleId.IsEmptyGuid())
                        {
                            string strName = objXmlLifestyle["name"]?.InnerText ?? LanguageManager.GetString("String_Unknown", GlobalOptions.Language);
                            if (strName == _objLifestyle?.BaseLifestyle)
                            {
                                strSelectedId = strLifeStyleId;
                            }
                            lstLifestyle.Add(new ListItem(strLifeStyleId, objXmlLifestyle["translate"]?.InnerText ?? strName));
                        }
                    }
                }

            cboLifestyle.BeginUpdate();
            cboLifestyle.ValueMember   = "Value";
            cboLifestyle.DisplayMember = "Name";
            cboLifestyle.DataSource    = lstLifestyle;

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                cboLifestyle.SelectedValue = strSelectedId;
            }
            if (cboLifestyle.SelectedIndex == -1)
            {
                cboLifestyle.SelectedIndex = 0;
            }
            cboLifestyle.EndUpdate();

            string strSpaceCharacter = LanguageManager.GetString("String_Space", GlobalOptions.Language);

            // Fill the Options list.
            using (XmlNodeList xmlLifestyleOptionsList = _objXmlDocument.SelectNodes("/chummer/qualities/quality[(source = \"" + "SR5" + "\" or category = \"" + "Contracts" + "\") and (" + _objCharacter.Options.BookXPath() + ")]"))
                if (xmlLifestyleOptionsList?.Count > 0)
                {
                    foreach (XmlNode objXmlOption in xmlLifestyleOptionsList)
                    {
                        string strOptionName = objXmlOption["name"]?.InnerText;
                        if (string.IsNullOrEmpty(strOptionName))
                        {
                            continue;
                        }
                        TreeNode nodOption     = new TreeNode();
                        XmlNode  nodMultiplier = objXmlOption["multiplier"];
                        string   strBaseString = string.Empty;
                        if (nodMultiplier == null)
                        {
                            nodMultiplier = objXmlOption["multiplierbaseonly"];
                            strBaseString = strSpaceCharacter + LanguageManager.GetString("Label_Base", GlobalOptions.Language);
                        }
                        nodOption.Tag = objXmlOption["id"]?.InnerText;
                        if (nodMultiplier != null && int.TryParse(nodMultiplier.InnerText, out int intCost))
                        {
                            nodOption.Text = intCost > 0
                                ? $"{objXmlOption["translate"]?.InnerText ?? strOptionName} [+{intCost}{strBaseString}%]"
                                : $"{objXmlOption["translate"]?.InnerText ?? strOptionName} [{intCost}{strBaseString}%]";
                        }
                        else
                        {
                            string  strCost    = objXmlOption["cost"]?.InnerText;
                            object  objProcess = CommonFunctions.EvaluateInvariantXPath(strCost, out bool blnIsSuccess);
                            decimal decCost    = blnIsSuccess ? Convert.ToDecimal((double)objProcess) : 0;
                            nodOption.Text = $"{objXmlOption["translate"]?.InnerText ?? strOptionName} [{decCost.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo)}¥]";
                        }
                        treQualities.Nodes.Add(nodOption);
                    }
                }

            SortTree(treQualities);

            if (_objSourceLifestyle != null)
            {
                txtLifestyleName.Text = _objSourceLifestyle.Name;
                nudRoommates.Value    = _objSourceLifestyle.Roommates;
                nudPercentage.Value   = _objSourceLifestyle.Percentage;
                foreach (LifestyleQuality objQuality in _objSourceLifestyle.LifestyleQualities)
                {
                    TreeNode objNode = treQualities.FindNode(objQuality.SourceIDString);
                    if (objNode != null)
                    {
                        objNode.Checked = true;
                    }
                }
            }

            _blnSkipRefresh = false;
            CalculateValues();
        }
Пример #18
0
        private void cmdAddMod_Click(object sender, EventArgs e)
        {
            bool blnAddAgain;

            XmlNode xmlSelectedMount = null;
            string  strSelectedMount = cboSize.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedMount))
            {
                xmlSelectedMount = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedMount + "\"]");
            }

            int intSlots = Convert.ToInt32(xmlSelectedMount?["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);

            string[] astrSelectedValues = { cboVisibility.SelectedValue?.ToString(), cboFlexibility.SelectedValue?.ToString(), cboControl.SelectedValue?.ToString() };
            foreach (string strSelectedId in astrSelectedValues)
            {
                if (!string.IsNullOrEmpty(strSelectedId))
                {
                    XmlNode xmlLoopNode = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedId + "\"]");
                    if (xmlLoopNode != null)
                    {
                        intSlots += Convert.ToInt32(xmlLoopNode["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                    }
                }
            }
            foreach (VehicleMod objMod in _lstMods)
            {
                intSlots += objMod.CalculatedSlots;
            }

            string   strSpace          = LanguageManager.GetString("String_Space");
            TreeNode objModsParentNode = treMods.FindNode("Node_AdditionalMods");

            do
            {
                frmSelectVehicleMod frmPickVehicleMod = new frmSelectVehicleMod(_objCharacter, _objMount?.Mods)
                {
                    // Pass the selected vehicle on to the form.
                    SelectedVehicle  = _objVehicle,
                    VehicleMountMods = true,
                    WeaponMountSlots = intSlots
                };

                frmPickVehicleMod.ShowDialog(this);

                // Make sure the dialogue window was not canceled.
                if (frmPickVehicleMod.DialogResult == DialogResult.Cancel)
                {
                    frmPickVehicleMod.Dispose();
                    break;
                }
                blnAddAgain = frmPickVehicleMod.AddAgain;
                XmlDocument objXmlDocument = XmlManager.Load("vehicles.xml");
                XmlNode     objXmlMod      = objXmlDocument.SelectSingleNode("/chummer/weaponmountmods/mod[id = \"" + frmPickVehicleMod.SelectedMod + "\"]");

                VehicleMod objMod = new VehicleMod(_objCharacter)
                {
                    DiscountCost = frmPickVehicleMod.BlackMarketDiscount
                };
                objMod.Create(objXmlMod, frmPickVehicleMod.SelectedRating, _objVehicle, frmPickVehicleMod.Markup);
                // Check the item's Cost and make sure the character can afford it.
                decimal decOriginalCost = _objVehicle.TotalCost;
                if (frmPickVehicleMod.FreeCost)
                {
                    objMod.Cost = "0";
                }
                frmPickVehicleMod.Dispose();

                // Do not allow the user to add a new Vehicle Mod if the Vehicle's Capacity has been reached.
                if (_objCharacter.Options.EnforceCapacity)
                {
                    bool blnOverCapacity = false;
                    if (_objCharacter.Options.BookEnabled("R5"))
                    {
                        if (_objVehicle.IsDrone && GlobalOptions.Dronemods)
                        {
                            if (_objVehicle.DroneModSlotsUsed > _objVehicle.DroneModSlots)
                            {
                                blnOverCapacity = true;
                            }
                        }
                        else
                        {
                            int intUsed  = _objVehicle.CalcCategoryUsed(objMod.Category);
                            int intAvail = _objVehicle.CalcCategoryAvail(objMod.Category);
                            if (intUsed > intAvail)
                            {
                                blnOverCapacity = true;
                            }
                        }
                    }
                    else if (_objVehicle.Slots < _objVehicle.SlotsUsed)
                    {
                        blnOverCapacity = true;
                    }

                    if (blnOverCapacity)
                    {
                        Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_CapacityReached"), LanguageManager.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        continue;
                    }
                }
                if (_objCharacter.Created)
                {
                    decimal decCost = _objVehicle.TotalCost - decOriginalCost;

                    // Multiply the cost if applicable.
                    char chrAvail = objMod.TotalAvailTuple().Suffix;
                    if (chrAvail == 'R' && _objCharacter.Options.MultiplyRestrictedCost)
                    {
                        decCost *= _objCharacter.Options.RestrictedCostMultiplier;
                    }
                    if (chrAvail == 'F' && _objCharacter.Options.MultiplyForbiddenCost)
                    {
                        decCost *= _objCharacter.Options.ForbiddenCostMultiplier;
                    }

                    if (decCost > _objCharacter.Nuyen)
                    {
                        Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_NotEnoughNuyen"),
                                                        LanguageManager.GetString("MessageTitle_NotEnoughNuyen"),
                                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                        continue;
                    }
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry(_objCharacter);
                    objExpense.Create(decCost * -1,
                                      LanguageManager.GetString("String_ExpensePurchaseVehicleMod") +
                                      strSpace + objMod.DisplayNameShort(GlobalOptions.Language), ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.AddWithSort(objExpense);
                    _objCharacter.Nuyen -= decCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddVehicleWeaponMountMod, objMod.InternalId);
                    objExpense.Undo = objUndo;
                }
                _lstMods.Add(objMod);
                intSlots += objMod.CalculatedSlots;

                TreeNode objNewNode = objMod.CreateTreeNode(null, null, null, null, null, null);

                if (objModsParentNode == null)
                {
                    objModsParentNode = new TreeNode
                    {
                        Tag  = "Node_AdditionalMods",
                        Text = LanguageManager.GetString("Node_AdditionalMods")
                    };
                    treMods.Nodes.Add(objModsParentNode);
                    objModsParentNode.Expand();
                }

                objModsParentNode.Nodes.Add(objNewNode);
                treMods.SelectedNode = objNewNode;
            }while (blnAddAgain);
        }
Пример #19
0
        private void tsSaveAsXml_Click(object sender, EventArgs e)
        {
            // Save the printout XML generated by the character.
            SaveFileDialog1.Filter = LanguageManager.GetString("DialogFilter_Xml") + '|' + LanguageManager.GetString("DialogFilter_All");
            SaveFileDialog1.Title  = LanguageManager.GetString("Button_Viewer_SaveAsXml");
            SaveFileDialog1.ShowDialog();
            string strSaveFile = SaveFileDialog1.FileName;

            if (string.IsNullOrEmpty(strSaveFile))
            {
                return;
            }

            if (!strSaveFile.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
            {
                strSaveFile += ".xml";
            }

            try
            {
                _objCharacterXml.Save(strSaveFile);
            }
            catch (XmlException)
            {
                Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_Save_Error_Warning"));
            }
            catch (UnauthorizedAccessException)
            {
                Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_Save_Error_Warning"));
            }
        }
Пример #20
0
        private void RefreshCBOs()
        {
            XmlNode xmlRequiredNode  = null;
            XmlNode xmlForbiddenNode = null;
            string  strSelectedMount = cboSize.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedMount))
            {
                XmlNode xmlSelectedMount = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedMount + "\"]");
                if (xmlSelectedMount != null)
                {
                    xmlForbiddenNode = xmlSelectedMount.SelectSingleNode("forbidden/weaponmountdetails");
                    xmlRequiredNode  = xmlSelectedMount.SelectSingleNode("required/weaponmountdetails");
                }
            }

            XmlNode         xmlVehicleNode = _objVehicle.GetNode();
            List <ListItem> lstVisibility  = new List <ListItem>();
            List <ListItem> lstFlexibility = new List <ListItem>();
            List <ListItem> lstControl     = new List <ListItem>();
            // Populate the Weapon Mount Category list.
            string strFilter = "category != \"Size\" and not(hide)";

            if (!_objVehicle.IsDrone || !GlobalOptions.Dronemods)
            {
                strFilter += " and not(optionaldrone)";
            }
            using (XmlNodeList xmlWeaponMountOptionNodeList = _xmlDoc.SelectNodes("/chummer/weaponmounts/weaponmount[" + strFilter + "]"))
                if (xmlWeaponMountOptionNodeList?.Count > 0)
                {
                    foreach (XmlNode xmlWeaponMountOptionNode in xmlWeaponMountOptionNodeList)
                    {
                        string strId = xmlWeaponMountOptionNode["id"]?.InnerText;
                        if (string.IsNullOrEmpty(strId))
                        {
                            continue;
                        }

                        XmlNode xmlTestNode = xmlWeaponMountOptionNode.SelectSingleNode("forbidden/vehicledetails");
                        if (xmlTestNode != null)
                        {
                            // Assumes topmost parent is an AND node
                            if (xmlVehicleNode.ProcessFilterOperationNode(xmlTestNode, false))
                            {
                                continue;
                            }
                        }
                        xmlTestNode = xmlWeaponMountOptionNode.SelectSingleNode("required/vehicledetails");
                        if (xmlTestNode != null)
                        {
                            // Assumes topmost parent is an AND node
                            if (!xmlVehicleNode.ProcessFilterOperationNode(xmlTestNode, false))
                            {
                                continue;
                            }
                        }

                        string strName    = xmlWeaponMountOptionNode["name"]?.InnerText ?? LanguageManager.GetString("String_Unknown");
                        bool   blnAddItem = true;
                        switch (xmlWeaponMountOptionNode["category"]?.InnerText)
                        {
                        case "Visibility":
                        {
                            XmlNodeList xmlNodeList = xmlForbiddenNode?.SelectNodes("visibility");
                            if (xmlNodeList?.Count > 0)
                            {
                                foreach (XmlNode xmlLoopNode in xmlNodeList)
                                {
                                    if (xmlLoopNode.InnerText == strName)
                                    {
                                        blnAddItem = false;
                                        break;
                                    }
                                }
                            }

                            if (xmlRequiredNode != null)
                            {
                                blnAddItem  = false;
                                xmlNodeList = xmlRequiredNode.SelectNodes("visibility");
                                if (xmlNodeList?.Count > 0)
                                {
                                    foreach (XmlNode xmlLoopNode in xmlNodeList)
                                    {
                                        if (xmlLoopNode.InnerText == strName)
                                        {
                                            blnAddItem = true;
                                            break;
                                        }
                                    }
                                }
                            }

                            if (blnAddItem)
                            {
                                lstVisibility.Add(new ListItem(strId, xmlWeaponMountOptionNode["translate"]?.InnerText ?? strName));
                            }
                        }
                        break;

                        case "Flexibility":
                        {
                            XmlNodeList xmlNodeList = xmlForbiddenNode?.SelectNodes("flexibility");
                            if (xmlNodeList?.Count > 0)
                            {
                                foreach (XmlNode xmlLoopNode in xmlNodeList)
                                {
                                    if (xmlLoopNode.InnerText == strName)
                                    {
                                        blnAddItem = false;
                                        break;
                                    }
                                }
                            }

                            if (xmlRequiredNode != null)
                            {
                                blnAddItem  = false;
                                xmlNodeList = xmlRequiredNode.SelectNodes("flexibility");
                                if (xmlNodeList?.Count > 0)
                                {
                                    foreach (XmlNode xmlLoopNode in xmlNodeList)
                                    {
                                        if (xmlLoopNode.InnerText == strName)
                                        {
                                            blnAddItem = true;
                                            break;
                                        }
                                    }
                                }
                            }

                            if (blnAddItem)
                            {
                                lstFlexibility.Add(new ListItem(strId, xmlWeaponMountOptionNode["translate"]?.InnerText ?? strName));
                            }
                        }
                        break;

                        case "Control":
                        {
                            XmlNodeList xmlNodeList = xmlForbiddenNode?.SelectNodes("control");
                            if (xmlNodeList?.Count > 0)
                            {
                                foreach (XmlNode xmlLoopNode in xmlNodeList)
                                {
                                    if (xmlLoopNode.InnerText == strName)
                                    {
                                        blnAddItem = false;
                                        break;
                                    }
                                }
                            }

                            if (xmlRequiredNode != null)
                            {
                                blnAddItem  = false;
                                xmlNodeList = xmlRequiredNode.SelectNodes("control");
                                if (xmlNodeList?.Count > 0)
                                {
                                    foreach (XmlNode xmlLoopNode in xmlNodeList)
                                    {
                                        if (xmlLoopNode.InnerText == strName)
                                        {
                                            blnAddItem = true;
                                            break;
                                        }
                                    }
                                }
                            }

                            if (blnAddItem)
                            {
                                lstControl.Add(new ListItem(strId, xmlWeaponMountOptionNode["translate"]?.InnerText ?? strName));
                            }
                        }
                        break;

                        default:
                            Utils.BreakIfDebug();
                            break;
                        }
                    }
                }

            bool blnOldLoading = _blnLoading;

            _blnLoading = true;
            string strOldVisibility  = cboVisibility.SelectedValue?.ToString();
            string strOldFlexibility = cboFlexibility.SelectedValue?.ToString();
            string strOldControl     = cboControl.SelectedValue?.ToString();

            cboVisibility.BeginUpdate();
            cboVisibility.ValueMember   = "Value";
            cboVisibility.DisplayMember = "Name";
            cboVisibility.DataSource    = lstVisibility;
            cboVisibility.Enabled       = lstVisibility.Count > 1;
            if (!string.IsNullOrEmpty(strOldVisibility))
            {
                cboVisibility.SelectedValue = strOldVisibility;
            }
            if (cboVisibility.SelectedIndex == -1 && lstVisibility.Count > 0)
            {
                cboVisibility.SelectedIndex = 0;
            }
            cboVisibility.EndUpdate();

            cboFlexibility.BeginUpdate();
            cboFlexibility.ValueMember   = "Value";
            cboFlexibility.DisplayMember = "Name";
            cboFlexibility.DataSource    = lstFlexibility;
            cboFlexibility.Enabled       = lstFlexibility.Count > 1;
            if (!string.IsNullOrEmpty(strOldFlexibility))
            {
                cboFlexibility.SelectedValue = strOldFlexibility;
            }
            if (cboFlexibility.SelectedIndex == -1 && lstFlexibility.Count > 0)
            {
                cboFlexibility.SelectedIndex = 0;
            }
            cboFlexibility.EndUpdate();

            cboControl.BeginUpdate();
            cboControl.ValueMember   = "Value";
            cboControl.DisplayMember = "Name";
            cboControl.DataSource    = lstControl;
            cboControl.Enabled       = lstControl.Count > 1;
            if (!string.IsNullOrEmpty(strOldControl))
            {
                cboControl.SelectedValue = strOldControl;
            }
            if (cboControl.SelectedIndex == -1 && lstControl.Count > 0)
            {
                cboControl.SelectedIndex = 0;
            }
            cboControl.EndUpdate();

            _blnLoading = blnOldLoading;
        }
Пример #21
0
 private void tsRemoveCharacter_Click(object sender, EventArgs e)
 {
     // Remove the file association from the Contact.
     if (Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_RemoveCharacterAssociation"), LanguageManager.GetString("MessageTitle_RemoveCharacterAssociation"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         _objContact.FileName         = string.Empty;
         _objContact.RelativeFileName = string.Empty;
         imgLink.SetToolTip(LanguageManager.GetString("Tip_Contact_LinkFile"));
         ContactDetailChanged?.Invoke(this, new TextEventArgs("File"));
     }
 }
Пример #22
0
        private void tsAttachCharacter_Click(object sender, EventArgs e)
        {
            // Prompt the user to select a save file to associate with this Contact.
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Filter = LanguageManager.GetString("DialogFilter_Chum5", GlobalOptions.Language) + '|' + LanguageManager.GetString("DialogFilter_All", GlobalOptions.Language)
            };

            if (!string.IsNullOrEmpty(_objContact.FileName) && File.Exists(_objContact.FileName))
            {
                openFileDialog.InitialDirectory = Path.GetDirectoryName(_objContact.FileName);
                openFileDialog.FileName         = Path.GetFileName(_objContact.FileName);
            }

            if (openFileDialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }
            _objContact.FileName = openFileDialog.FileName;
            GlobalOptions.ToolTipProcessor.SetToolTip(imgLink,
                                                      _objContact.EntityType == ContactType.Enemy
                    ? LanguageManager.GetString("Tip_Enemy_OpenFile", GlobalOptions.Language)
                    : LanguageManager.GetString("Tip_Contact_OpenFile", GlobalOptions.Language));

            // Set the relative path.
            Uri uriApplication = new Uri(Application.StartupPath);
            Uri uriFile        = new Uri(_objContact.FileName);
            Uri uriRelative    = uriApplication.MakeRelativeUri(uriFile);

            _objContact.RelativeFileName = "../" + uriRelative;

            ContactDetailChanged?.Invoke(this, new TextEventArgs("File"));
        }
Пример #23
0
        private async void tsContactOpen_Click(object sender, EventArgs e)
        {
            if (_objSpirit.LinkedCharacter != null)
            {
                Character objOpenCharacter = Program.MainForm.OpenCharacters.FirstOrDefault(x => x == _objSpirit.LinkedCharacter);
                using (new CursorWait(this))
                {
                    if (objOpenCharacter == null || !Program.MainForm.SwitchToOpenCharacter(objOpenCharacter, true))
                    {
                        objOpenCharacter = await Program.MainForm.LoadCharacter(_objSpirit.LinkedCharacter.FileName).ConfigureAwait(true);

                        Program.MainForm.OpenCharacter(objOpenCharacter);
                    }
                }
            }
            else
            {
                bool blnUseRelative = false;

                // Make sure the file still exists before attempting to load it.
                if (!File.Exists(_objSpirit.FileName))
                {
                    bool blnError = false;
                    // If the file doesn't exist, use the relative path if one is available.
                    if (string.IsNullOrEmpty(_objSpirit.RelativeFileName))
                    {
                        blnError = true;
                    }
                    else if (!File.Exists(Path.GetFullPath(_objSpirit.RelativeFileName)))
                    {
                        blnError = true;
                    }
                    else
                    {
                        blnUseRelative = true;
                    }

                    if (blnError)
                    {
                        Program.MainForm.ShowMessageBox(string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("Message_FileNotFound"), _objSpirit.FileName), LanguageManager.GetString("MessageTitle_FileNotFound"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                string strFile = blnUseRelative ? Path.GetFullPath(_objSpirit.RelativeFileName) : _objSpirit.FileName;
                System.Diagnostics.Process.Start(strFile);
            }
        }
Пример #24
0
 private void tsRemoveCharacter_Click(object sender, EventArgs e)
 {
     // Remove the file association from the Contact.
     if (MessageBox.Show(LanguageManager.GetString("Message_RemoveCharacterAssociation", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_RemoveCharacterAssociation", GlobalOptions.Language), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         _objContact.FileName         = string.Empty;
         _objContact.RelativeFileName = string.Empty;
         GlobalOptions.ToolTipProcessor.SetToolTip(imgLink,
                                                   _objContact.EntityType == ContactType.Enemy
                 ? LanguageManager.GetString("Tip_Enemy_LinkFile", GlobalOptions.Language)
                 : LanguageManager.GetString("Tip_Contact_LinkFile", GlobalOptions.Language));
         ContactDetailChanged?.Invoke(this, new TextEventArgs("File"));
     }
 }
Пример #25
0
        private void tsCreateCharacter_Click(object sender, EventArgs e)
        {
            string strSpiritName = cboSpiritName.SelectedValue?.ToString();

            if (string.IsNullOrEmpty(strSpiritName))
            {
                Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_SelectCritterType"), LanguageManager.GetString("MessageTitle_SelectCritterType"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            CreateCritter(strSpiritName, nudForce.ValueAsInt);
        }
Пример #26
0
 private void cmdOK_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtLifestyleName.Text))
     {
         MessageBox.Show(LanguageManager.GetString("Message_SelectAdvancedLifestyle_LifestyleName", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_SelectAdvancedLifestyle_LifestyleName", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     _blnAddAgain = false;
     AcceptForm();
 }
Пример #27
0
        /// <summary>
        /// Restarts Chummer5a.
        /// </summary>
        /// <param name="strLanguage">Language in which to display any prompts or warnings.</param>
        /// <param name="strText">Text to display in the prompt to restart. If empty, no prompt is displayed.</param>
        public static void RestartApplication(string strLanguage, string strText)
        {
            if (!string.IsNullOrEmpty(strText))
            {
                string text    = LanguageManager.GetString(strText, strLanguage);
                string caption = LanguageManager.GetString("MessageTitle_Options_CloseForms", strLanguage);

                if (MessageBox.Show(text, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                {
                    return;
                }
            }
            // Need to do this here in case filenames are changed while closing forms (because a character who previously did not have a filename was saved when prompted)
            // Cannot use foreach because saving a character as created removes the current form and adds a new one
            for (int i = 0; i < Program.MainForm.OpenCharacterForms.Count; ++i)
            {
                CharacterShared objOpenCharacterForm = Program.MainForm.OpenCharacterForms[i];
                if (objOpenCharacterForm.IsDirty)
                {
                    string       strCharacterName = objOpenCharacterForm.CharacterObject.CharacterName;
                    DialogResult objResult        = MessageBox.Show(string.Format(LanguageManager.GetString("Message_UnsavedChanges", strLanguage), strCharacterName), LanguageManager.GetString("MessageTitle_UnsavedChanges", strLanguage), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (objResult == DialogResult.Yes)
                    {
                        // Attempt to save the Character. If the user cancels the Save As dialogue that may open, cancel the closing event so that changes are not lost.
                        bool blnResult = objOpenCharacterForm.SaveCharacter();
                        if (!blnResult)
                        {
                            return;
                        }
                        // We saved a character as created, which closed the current form and added a new one
                        // This works regardless of dispose, because dispose would just set the objOpenCharacterForm pointer to null, so OpenCharacterForms would never contain it
                        else if (!Program.MainForm.OpenCharacterForms.Contains(objOpenCharacterForm))
                        {
                            i -= 1;
                        }
                    }
                    else if (objResult == DialogResult.Cancel)
                    {
                        return;
                    }
                }
            }
            Log.Info("Restart Chummer");
            Program.MainForm.Cursor = Cursors.WaitCursor;
            // Get the parameters/arguments passed to program if any
            string arguments = string.Empty;

            foreach (CharacterShared objOpenCharacterForm in Program.MainForm.OpenCharacterForms)
            {
                arguments += '\"' + objOpenCharacterForm.CharacterObject.FileName + "\" ";
            }
            arguments = arguments.Trim();
            // Restart current application, with same arguments/parameters
            foreach (Form objForm in Program.MainForm.MdiChildren)
            {
                objForm.Close();
            }
            ProcessStartInfo startInfo = new ProcessStartInfo
            {
                FileName  = GetStartupPath + Path.DirectorySeparatorChar + AppDomain.CurrentDomain.FriendlyName,
                Arguments = arguments
            };

            Application.Exit();
            Process.Start(startInfo);
        }
Пример #28
0
        private void treQualities_AfterSelect(object sender, TreeViewEventArgs e)
        {
            string strSource         = string.Empty;
            string strPage           = string.Empty;
            string strSourceIDString = treQualities.SelectedNode?.Tag.ToString();

            if (!string.IsNullOrEmpty(strSourceIDString))
            {
                XmlNode objXmlQuality = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[id = \"" + strSourceIDString + "\"]");
                if (objXmlQuality != null)
                {
                    strSource = objXmlQuality["source"]?.InnerText ?? string.Empty;
                    strPage   = objXmlQuality["altpage"]?.InnerText ?? objXmlQuality["page"]?.InnerText ?? string.Empty;
                }
            }

            if (!string.IsNullOrEmpty(strSource) && !string.IsNullOrEmpty(strPage))
            {
                string strSpaceCharacter = LanguageManager.GetString("String_Space", GlobalOptions.Language);
                lblSource.Text = CommonFunctions.LanguageBookShort(strSource, GlobalOptions.Language) + strSpaceCharacter + strPage;
                lblSource.SetToolTip(CommonFunctions.LanguageBookLong(strSource, GlobalOptions.Language) + strSpaceCharacter + LanguageManager.GetString("String_Page", GlobalOptions.Language) + strSpaceCharacter + strPage);
            }
            else
            {
                lblSource.Text = string.Empty;
                lblSource.SetToolTip(string.Empty);
            }

            lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
        }
Пример #29
0
        private void cmdChangeSelection_Click(object sender, EventArgs e)
        {
            switch (_strSelect)
            {
            case "SelectActionDicePool":
                List <ListItem> lstActions = new List <ListItem>();
                foreach (XPathNavigator xmlAction in _objCharacter.LoadDataXPath("actions.xml").Select("/chummer/actions/action"))
                {
                    string strName = xmlAction.SelectSingleNode("name")?.Value;
                    if (!string.IsNullOrEmpty(strName))
                    {
                        lstActions.Add(new ListItem(strName, xmlAction.SelectSingleNode("translate")?.Value ?? strName));
                    }
                }

                using (frmSelectItem frmSelectAction = new frmSelectItem
                {
                    Description = LanguageManager.GetString("Title_SelectAction")
                })
                {
                    frmSelectAction.SetDropdownItemsMode(lstActions);
                    frmSelectAction.ShowDialog(this);

                    if (frmSelectAction.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmSelectAction.SelectedName;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmSelectAction.SelectedName);
                    }
                }
                break;

            case "SelectAttribute":
            {
                List <string> lstAbbrevs = new List <string>(Backend.Attributes.AttributeSection.AttributeStrings);

                lstAbbrevs.Remove("ESS");
                if (!_objCharacter.MAGEnabled)
                {
                    lstAbbrevs.Remove("MAG");
                    lstAbbrevs.Remove("MAGAdept");
                }
                else if (!_objCharacter.IsMysticAdept || !_objCharacter.Options.MysAdeptSecondMAGAttribute)
                {
                    lstAbbrevs.Remove("MAGAdept");
                }

                if (!_objCharacter.RESEnabled)
                {
                    lstAbbrevs.Remove("RES");
                }
                if (!_objCharacter.DEPEnabled)
                {
                    lstAbbrevs.Remove("DEP");
                }
                using (frmSelectAttribute frmPickAttribute = new frmSelectAttribute(lstAbbrevs.ToArray())
                    {
                        Description = LanguageManager.GetString("Title_SelectAttribute")
                    })
                {
                    frmPickAttribute.ShowDialog(this);

                    if (frmPickAttribute.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmPickAttribute.SelectedAttribute;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickAttribute.SelectedAttribute);
                    }
                }
            }
            break;

            case "SelectEcho":
                using (frmSelectMetamagic frmPickMetamagic = new frmSelectMetamagic(_objCharacter, frmSelectMetamagic.Mode.Echo))
                {
                    frmPickMetamagic.ShowDialog(this);
                    if (frmPickMetamagic.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmPickMetamagic.SelectedMetamagic;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickMetamagic.SelectedMetamagic);
                    }
                }
                break;

            case "SelectMetamagic":
                using (frmSelectMetamagic frmPickMetamagic = new frmSelectMetamagic(_objCharacter, frmSelectMetamagic.Mode.Metamagic))
                {
                    frmPickMetamagic.ShowDialog(this);
                    if (frmPickMetamagic.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmPickMetamagic.SelectedMetamagic;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickMetamagic.SelectedMetamagic);
                    }
                }
                break;

            case "SelectMentalAttribute":
                using (frmSelectAttribute frmPickAttribute = new frmSelectAttribute(Backend.Attributes.AttributeSection.MentalAttributes.ToArray()))
                {
                    frmPickAttribute.Description = LanguageManager.GetString("Title_SelectAttribute");
                    frmPickAttribute.ShowDialog(this);

                    if (frmPickAttribute.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmPickAttribute.SelectedAttribute;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickAttribute.SelectedAttribute);
                    }
                }
                break;

            case "SelectPhysicalAttribute":
                using (frmSelectAttribute frmPickAttribute = new frmSelectAttribute(Backend.Attributes.AttributeSection.PhysicalAttributes.ToArray()))
                {
                    frmPickAttribute.Description = LanguageManager.GetString("Title_SelectAttribute");
                    frmPickAttribute.ShowDialog(this);

                    if (frmPickAttribute.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmPickAttribute.SelectedAttribute;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickAttribute.SelectedAttribute);
                    }
                }
                break;

            case "SelectSpecialAttribute":
            {
                List <string> lstAbbrevs = new List <string>(Backend.Attributes.AttributeSection.AttributeStrings);
                lstAbbrevs.RemoveAll(x => Backend.Attributes.AttributeSection.PhysicalAttributes.Contains(x) || Backend.Attributes.AttributeSection.MentalAttributes.Contains(x));
                lstAbbrevs.Remove("ESS");

                /*
                 * if (!_objCharacter.MAGEnabled)
                 * {
                 *  lstAbbrevs.Remove("MAG");
                 *  lstAbbrevs.Remove("MAGAdept");
                 * }
                 * else if (!_objCharacter.IsMysticAdept || !_objCharacter.Options.MysAdeptSecondMAGAttribute)
                 *  lstAbbrevs.Remove("MAGAdept");
                 *
                 * if (!_objCharacter.RESEnabled)
                 *  lstAbbrevs.Remove("RES");
                 * if (!_objCharacter.DEPEnabled)
                 *  lstAbbrevs.Remove("DEP");
                 */
                using (frmSelectAttribute frmPickAttribute = new frmSelectAttribute(lstAbbrevs.ToArray())
                    {
                        Description = LanguageManager.GetString("Title_SelectAttribute")
                    })
                {
                    frmPickAttribute.ShowDialog(this);

                    if (frmPickAttribute.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmPickAttribute.SelectedAttribute;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickAttribute.SelectedAttribute);
                    }
                }
            }
            break;

            case "SelectSkill":
                using (frmSelectSkill frmPickSkill = new frmSelectSkill(_objCharacter))
                {
                    frmPickSkill.Description = LanguageManager.GetString("Title_SelectSkill");
                    frmPickSkill.ShowDialog(this);

                    if (frmPickSkill.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmPickSkill.SelectedSkill;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickSkill.SelectedSkill);
                    }
                }
                break;

            case "SelectKnowSkill":
            {
                List <ListItem>  lstDropdownItems       = new List <ListItem>(_objCharacter.SkillsSection.KnowledgeSkills.Count);
                HashSet <string> setProcessedSkillNames = new HashSet <string>();
                foreach (KnowledgeSkill objKnowledgeSkill in _objCharacter.SkillsSection.KnowledgeSkills)
                {
                    lstDropdownItems.Add(new ListItem(objKnowledgeSkill.Name, objKnowledgeSkill.CurrentDisplayName));
                    setProcessedSkillNames.Add(objKnowledgeSkill.Name);
                }
                StringBuilder objFilter = new StringBuilder();
                if (setProcessedSkillNames.Count > 0)
                {
                    objFilter.Append("not(");
                    foreach (string strName in setProcessedSkillNames)
                    {
                        objFilter.Append("name = " + strName.CleanXPath() + " or ");
                    }
                    objFilter.Length -= 4;
                    objFilter.Append(')');
                }

                string strFilter = objFilter.Length > 0 ? '[' + objFilter.ToString() + ']' : string.Empty;
                foreach (XPathNavigator xmlSkill in _objCharacter.LoadDataXPath("skills.xml").Select("/chummer/knowledgeskills/skill" + strFilter))
                {
                    string strName = xmlSkill.SelectSingleNode("name")?.Value;
                    if (!string.IsNullOrEmpty(strName))
                    {
                        lstDropdownItems.Add(new ListItem(strName, xmlSkill.SelectSingleNode("translate")?.Value ?? strName));
                    }
                }

                lstDropdownItems.Sort(CompareListItems.CompareNames);

                using (frmSelectItem frmPickSkill = new frmSelectItem
                    {
                        Description = LanguageManager.GetString("Title_SelectSkill")
                    })
                {
                    frmPickSkill.SetDropdownItemsMode(lstDropdownItems);
                    frmPickSkill.ShowDialog(this);

                    if (frmPickSkill.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmPickSkill.SelectedItem;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickSkill.SelectedItem);
                    }
                }
            }
            break;

            case "SelectSkillCategory":
                using (frmSelectSkillCategory frmPickSkillCategory = new frmSelectSkillCategory(_objCharacter))
                {
                    frmPickSkillCategory.Description = LanguageManager.GetString("Title_SelectSkillCategory");
                    frmPickSkillCategory.ShowDialog(this);

                    if (frmPickSkillCategory.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmPickSkillCategory.SelectedCategory;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickSkillCategory.SelectedCategory);
                    }
                }
                break;

            case "SelectSkillGroup":
                using (frmSelectSkillGroup frmPickSkillGroup = new frmSelectSkillGroup(_objCharacter))
                {
                    frmPickSkillGroup.Description = LanguageManager.GetString("Title_SelectSkillGroup");
                    frmPickSkillGroup.ShowDialog(this);

                    if (frmPickSkillGroup.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmPickSkillGroup.SelectedSkillGroup;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickSkillGroup.SelectedSkillGroup);
                    }
                }
                break;

            case "SelectSpell":
                List <ListItem> lstSpells = new List <ListItem>();
                foreach (XPathNavigator xmlSpell in _objCharacter.LoadDataXPath("spells.xml").Select("/chummer/spells/spell"))
                {
                    string strName = xmlSpell.SelectSingleNode("name")?.Value;
                    if (!string.IsNullOrEmpty(strName))
                    {
                        lstSpells.Add(new ListItem(strName, xmlSpell.SelectSingleNode("translate")?.Value ?? strName));
                    }
                }

                using (frmSelectItem selectSpell = new frmSelectItem
                {
                    Description = LanguageManager.GetString("Title_SelectSpell")
                })
                {
                    selectSpell.SetDropdownItemsMode(lstSpells);
                    selectSpell.ShowDialog(this);

                    if (selectSpell.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = selectSpell.SelectedName;
                        txtTranslateSelection.Text = TranslateField(_strSelect, selectSpell.SelectedName);
                    }
                }
                break;

            case "SelectWeaponCategory":
                using (frmSelectWeaponCategory frmPickWeaponCategory = new frmSelectWeaponCategory(_objCharacter))
                {
                    frmPickWeaponCategory.Description = LanguageManager.GetString("Title_SelectWeaponCategory");
                    frmPickWeaponCategory.ShowDialog(this);

                    if (frmPickWeaponCategory.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmPickWeaponCategory.SelectedCategory;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickWeaponCategory.SelectedCategory);
                    }
                }
                break;

            case "SelectSpellCategory":
                using (frmSelectSpellCategory frmPickSpellCategory = new frmSelectSpellCategory(_objCharacter))
                {
                    frmPickSpellCategory.Description = LanguageManager.GetString("Title_SelectSpellCategory");
                    frmPickSpellCategory.ShowDialog(this);

                    if (frmPickSpellCategory.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = frmPickSpellCategory.SelectedCategory;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickSpellCategory.SelectedCategory);
                    }
                }
                break;

            case "SelectAdeptPower":
                using (frmSelectPower frmPickPower = new frmSelectPower(_objCharacter))
                {
                    frmPickPower.IgnoreLimits = chkIgnoreLimits.Checked;
                    frmPickPower.ShowDialog(this);

                    if (frmPickPower.DialogResult == DialogResult.OK)
                    {
                        txtSelect.Text             = _objCharacter.LoadDataXPath("powers.xml").SelectSingleNode("/chummer/powers/power[id = " + frmPickPower.SelectedPower.CleanXPath() + "]/name")?.Value;
                        txtTranslateSelection.Text = TranslateField(_strSelect, frmPickPower.SelectedPower);
                    }
                }
                break;
            }
        }
Пример #30
0
        private void UpdateGearInfo(bool blnUpdateMountCBOs = true)
        {
            if (_blnLoading)
            {
                return;
            }

            XPathNavigator xmlAccessory  = null;
            string         strSelectedId = lstAccessory.SelectedValue?.ToString();

            // Retrieve the information for the selected Accessory.
            if (!string.IsNullOrEmpty(strSelectedId))
            {
                xmlAccessory = _xmlBaseChummerNode.SelectSingleNode("accessories/accessory[id = \"" + strSelectedId + "\"]");
            }
            if (xmlAccessory == null)
            {
                lblRC.Visible            = false;
                lblRCLabel.Visible       = false;
                nudRating.Enabled        = false;
                nudRating.Visible        = false;
                lblRatingLabel.Visible   = false;
                lblRatingNALabel.Visible = false;
                lblMountLabel.Visible    = false;
                cboMount.Visible         = false;
                cboMount.Items.Clear();
                lblExtraMountLabel.Visible = false;
                cboExtraMount.Visible      = false;
                cboExtraMount.Items.Clear();
                lblAvailLabel.Visible  = false;
                lblAvail.Text          = string.Empty;
                lblCostLabel.Visible   = false;
                lblCost.Text           = string.Empty;
                lblTestLabel.Visible   = false;
                lblTest.Text           = string.Empty;
                lblSourceLabel.Visible = false;
                lblSource.Text         = string.Empty;
                lblSource.SetToolTip(string.Empty);
                return;
            }

            string strSpace = LanguageManager.GetString("String_Space");
            string strRC    = xmlAccessory.SelectSingleNode("rc")?.Value;

            if (!string.IsNullOrEmpty(strRC))
            {
                lblRC.Visible      = true;
                lblRCLabel.Visible = true;
                lblRC.Text         = strRC;
            }
            else
            {
                lblRC.Visible      = false;
                lblRCLabel.Visible = false;
            }
            if (int.TryParse(xmlAccessory.SelectSingleNode("rating")?.Value, out int intMaxRating) && intMaxRating > 0)
            {
                nudRating.Maximum = intMaxRating;
                if (chkHideOverAvailLimit.Checked)
                {
                    while (nudRating.Maximum > nudRating.Minimum && !xmlAccessory.CheckAvailRestriction(_objCharacter, nudRating.MaximumAsInt))
                    {
                        nudRating.Maximum -= 1;
                    }
                }
                if (chkShowOnlyAffordItems.Checked && !chkFreeItem.Checked)
                {
                    decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                    if (_setBlackMarketMaps.Contains(xmlAccessory.SelectSingleNode("category")?.Value))
                    {
                        decCostMultiplier *= 0.9m;
                    }
                    while (nudRating.Maximum > nudRating.Minimum && !xmlAccessory.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier, nudRating.MaximumAsInt))
                    {
                        nudRating.Maximum -= 1;
                    }
                }
                nudRating.Enabled        = nudRating.Maximum != nudRating.Minimum;
                nudRating.Visible        = true;
                lblRatingLabel.Visible   = true;
                lblRatingNALabel.Visible = false;
            }
            else
            {
                lblRatingNALabel.Visible = true;
                nudRating.Enabled        = false;
                nudRating.Visible        = false;
                lblRatingLabel.Visible   = true;
            }

            if (blnUpdateMountCBOs)
            {
                string        strDataMounts = xmlAccessory.SelectSingleNode("mount")?.Value;
                List <string> strMounts     = new List <string>();
                if (!string.IsNullOrEmpty(strDataMounts))
                {
                    strMounts.AddRange(strDataMounts.SplitNoAlloc('/', StringSplitOptions.RemoveEmptyEntries));
                }

                strMounts.Add("None");

                List <string> strAllowed = new List <string>(_lstAllowedMounts)
                {
                    "None"
                };
                cboMount.Visible = true;
                cboMount.Items.Clear();
                foreach (string strCurrentMount in strMounts)
                {
                    if (!string.IsNullOrEmpty(strCurrentMount))
                    {
                        foreach (string strAllowedMount in strAllowed)
                        {
                            if (strCurrentMount == strAllowedMount)
                            {
                                cboMount.Items.Add(strCurrentMount);
                            }
                        }
                    }
                }

                cboMount.Enabled       = cboMount.Items.Count > 1;
                cboMount.SelectedIndex = 0;
                lblMountLabel.Visible  = true;

                List <string> strExtraMounts = new List <string>();
                string        strExtraMount  = xmlAccessory.SelectSingleNode("extramount")?.Value;
                if (!string.IsNullOrEmpty(strExtraMount))
                {
                    foreach (string strItem in strExtraMount.SplitNoAlloc('/', StringSplitOptions.RemoveEmptyEntries))
                    {
                        strExtraMounts.Add(strItem);
                    }
                }

                strExtraMounts.Add("None");

                cboExtraMount.Items.Clear();
                foreach (string strCurrentMount in strExtraMounts)
                {
                    if (!string.IsNullOrEmpty(strCurrentMount))
                    {
                        foreach (string strAllowedMount in strAllowed)
                        {
                            if (strCurrentMount == strAllowedMount)
                            {
                                cboExtraMount.Items.Add(strCurrentMount);
                            }
                        }
                    }
                }

                cboExtraMount.Enabled       = cboExtraMount.Items.Count > 1;
                cboExtraMount.SelectedIndex = 0;
                if (cboMount.SelectedItem.ToString() != "None" && cboExtraMount.SelectedItem.ToString() != "None" &&
                    cboMount.SelectedItem.ToString() == cboExtraMount.SelectedItem.ToString())
                {
                    cboExtraMount.SelectedIndex += 1;
                }
                cboExtraMount.Visible      = cboExtraMount.Enabled && cboExtraMount.SelectedItem.ToString() != "None";
                lblExtraMountLabel.Visible = cboExtraMount.Visible;
            }

            // Avail.
            // If avail contains "F" or "R", remove it from the string so we can use the expression.
            lblAvail.Text         = new AvailabilityValue(Convert.ToInt32(nudRating.Value), xmlAccessory.SelectSingleNode("avail")?.Value).ToString();
            lblAvailLabel.Visible = !string.IsNullOrEmpty(lblAvail.Text);

            if (!chkFreeItem.Checked)
            {
                string strCost = "0";
                if (xmlAccessory.TryGetStringFieldQuickly("cost", ref strCost))
                {
                    strCost = strCost.CheapReplace("Weapon Cost", () => _objParentWeapon.OwnCost.ToString(GlobalOptions.InvariantCultureInfo))
                              .CheapReplace("Weapon Total Cost", () => _objParentWeapon.MultipliableCost(null).ToString(GlobalOptions.InvariantCultureInfo))
                              .Replace("Rating", nudRating.Value.ToString(GlobalOptions.CultureInfo));
                }
                if (strCost.StartsWith("Variable(", StringComparison.Ordinal))
                {
                    decimal decMin;
                    decimal decMax = decimal.MaxValue;
                    strCost = strCost.TrimStartOnce("Variable(", true).TrimEndOnce(')');
                    if (strCost.Contains('-'))
                    {
                        string[] strValues = strCost.Split('-');
                        decimal.TryParse(strValues[0], NumberStyles.Any, GlobalOptions.InvariantCultureInfo, out decMin);
                        decimal.TryParse(strValues[1], NumberStyles.Any, GlobalOptions.InvariantCultureInfo, out decMax);
                    }
                    else
                    {
                        decimal.TryParse(strCost.FastEscape('+'), NumberStyles.Any, GlobalOptions.InvariantCultureInfo, out decMin);
                    }

                    if (decMax == decimal.MaxValue)
                    {
                        lblCost.Text = decMin.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + "¥+";
                    }
                    else
                    {
                        lblCost.Text = new StringBuilder(decMin.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo))
                                       .Append(strSpace).Append('-').Append(strSpace)
                                       .Append(decMax.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo)).Append('¥').ToString();
                    }

                    lblTest.Text = _objCharacter.AvailTest(decMax, lblAvail.Text);
                }
                else
                {
                    object  objProcess = CommonFunctions.EvaluateInvariantXPath(strCost, out bool blnIsSuccess);
                    decimal decCost    = blnIsSuccess ? Convert.ToDecimal(objProcess, GlobalOptions.InvariantCultureInfo) : 0;

                    // Apply any markup.
                    decCost *= 1 + (nudMarkup.Value / 100.0m);

                    if (chkBlackMarketDiscount.Checked)
                    {
                        decCost *= 0.9m;
                    }
                    decCost *= _objParentWeapon.AccessoryMultiplier;
                    if (!string.IsNullOrEmpty(_objParentWeapon.DoubledCostModificationSlots))
                    {
                        string[] astrParentDoubledCostModificationSlots = _objParentWeapon.DoubledCostModificationSlots.Split('/', StringSplitOptions.RemoveEmptyEntries);
                        if (astrParentDoubledCostModificationSlots.Contains(cboMount.SelectedItem?.ToString()) ||
                            astrParentDoubledCostModificationSlots.Contains(cboExtraMount.SelectedItem?.ToString()))
                        {
                            decCost *= 2;
                        }
                    }

                    lblCost.Text = decCost.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    lblTest.Text = _objCharacter.AvailTest(decCost, lblAvail.Text);
                }
            }
            else
            {
                lblCost.Text = (0.0m).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                lblTest.Text = _objCharacter.AvailTest(0, lblAvail.Text);
            }

            lblRatingLabel.Text = xmlAccessory.SelectSingleNode("ratinglabel") != null
                ? string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("Label_RatingFormat"),
                                LanguageManager.GetString(xmlAccessory.SelectSingleNode("ratinglabel").Value))
                : LanguageManager.GetString("Label_Rating");

            lblCostLabel.Visible = !string.IsNullOrEmpty(lblCost.Text);
            lblTestLabel.Visible = !string.IsNullOrEmpty(lblTest.Text);


            if (!chkBlackMarketDiscount.Checked)
            {
                chkBlackMarketDiscount.Checked = GlobalOptions.AssumeBlackMarket && _blnIsParentWeaponBlackMarketAllowed;
            }
            else if (!_blnIsParentWeaponBlackMarketAllowed)
            {
                //Prevent chkBlackMarketDiscount from being checked if the gear category doesn't match.
                chkBlackMarketDiscount.Checked = false;
            }

            chkBlackMarketDiscount.Enabled = _blnIsParentWeaponBlackMarketAllowed;
            string       strSource       = xmlAccessory.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown");
            string       strPage         = xmlAccessory.SelectSingleNode("altpage")?.Value ?? xmlAccessory.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown");
            SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language);

            objSourceString.SetControl(lblSource);
            lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
        }