public void Awake() { tileManager = (TileManager)target; resourceManager = tileManager.GetComponent<ResourceManager>(); improvementManager = tileManager.GetComponent<ImprovementManager>(); if (tileManager.tiles != null) { foldoutOpen = new bool[tileManager.tiles.Count]; } }
/// Create a Armor Modification from an XmlNode and return the TreeNodes for it. /// <param name="objXmlArmorNode">XmlNode to create the object from.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="intRating">Rating of the selected ArmorMod.</param> /// <param name="objWeapons">List of Weapons that are created by the Armor.</param> /// <param name="objWeaponNodes">List of Weapon Nodes that are created by the Armor.</param> /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param> public void Create(XmlNode objXmlArmorNode, TreeNode objNode, int intRating, List<Weapon> objWeapons, List<TreeNode> objWeaponNodes, bool blnSkipCost = false) { _strName = objXmlArmorNode["name"].InnerText; _strCategory = objXmlArmorNode["category"].InnerText; _strArmorCapacity = objXmlArmorNode["armorcapacity"].InnerText; _intA = Convert.ToInt32(objXmlArmorNode["armor"].InnerText); _intRating = intRating; _intMaxRating = Convert.ToInt32(objXmlArmorNode["maxrating"].InnerText); _strAvail = objXmlArmorNode["avail"].InnerText; _strCost = objXmlArmorNode["cost"].InnerText; _strSource = objXmlArmorNode["source"].InnerText; _strPage = objXmlArmorNode["page"].InnerText; _nodBonus = objXmlArmorNode["bonus"]; if (GlobalOptions.Instance.Language != "en-us") { XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml"); XmlNode objArmorNode = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + _strName + "\"]"); if (objArmorNode != null) { if (objArmorNode["translate"] != null) _strAltName = objArmorNode["translate"].InnerText; if (objArmorNode["altpage"] != null) _strAltPage = objArmorNode["altpage"].InnerText; } objArmorNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]"); if (objArmorNode != null) { if (objArmorNode.Attributes["translate"] != null) _strAltCategory = objArmorNode.Attributes["translate"].InnerText; } } if (objXmlArmorNode["bonus"] != null && !blnSkipCost) { ImprovementManager objImprovementManager = new ImprovementManager(_objCharacter); if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.ArmorMod, _guiID.ToString(), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (objImprovementManager.SelectedValue != "") { _strExtra = objImprovementManager.SelectedValue; objNode.Text += " (" + objImprovementManager.SelectedValue + ")"; } } // Add Weapons if applicable. if (objXmlArmorNode.InnerXml.Contains("<addweapon>")) { XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml"); // More than one Weapon can be added, so loop through all occurrences. foreach (XmlNode objXmlAddWeapon in objXmlArmorNode.SelectNodes("addweapon")) { XmlNode objXmlWeapon = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlAddWeapon.InnerText + "\" and starts-with(category, \"Cyberware\")]"); TreeNode objGearWeaponNode = new TreeNode(); Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Create(objXmlWeapon, _objCharacter, objGearWeaponNode, null, null); objGearWeaponNode.ForeColor = SystemColors.GrayText; objWeaponNodes.Add(objGearWeaponNode); objWeapons.Add(objGearWeapon); _guiWeaponID = Guid.Parse(objGearWeapon.InternalId); } } objNode.Text = DisplayName; objNode.Tag = _guiID.ToString(); }
/// <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 = XmlManager.Load("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; } // The Critter should use the same settings file as the character. using (Character objCharacter = new Character { SettingsFile = _objSpirit.CharacterObject.SettingsFile, // Override the defaults for the setting. IgnoreRules = true, IsCritter = true, BuildMethod = CharacterBuildMethod.Karma }) { 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 = strCritterName + strSpace + '(' + LanguageManager.GetString(_objSpirit.RatingLabel) + strSpace + _objSpirit.Force.ToString(GlobalOptions.InvariantCultureInfo) + ").chum5" }) { if (saveFileDialog.ShowDialog(this) != DialogResult.OK) { return; } string strFileName = saveFileDialog.FileName; objCharacter.FileName = strFileName; } Cursor = Cursors.WaitCursor; // Set Metatype information. if (strCritterName == "Ally Spirit") { objCharacter.BOD.AssignLimits(ExpressionToString(objXmlMetatype["bodmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["bodmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["bodaug"]?.InnerText, intForce, 0)); objCharacter.AGI.AssignLimits(ExpressionToString(objXmlMetatype["agimin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["agimax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["agiaug"]?.InnerText, intForce, 0)); objCharacter.REA.AssignLimits(ExpressionToString(objXmlMetatype["reamin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["reamax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["reaaug"]?.InnerText, intForce, 0)); objCharacter.STR.AssignLimits(ExpressionToString(objXmlMetatype["strmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["strmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["straug"]?.InnerText, intForce, 0)); objCharacter.CHA.AssignLimits(ExpressionToString(objXmlMetatype["chamin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["chamax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["chaaug"]?.InnerText, intForce, 0)); objCharacter.INT.AssignLimits(ExpressionToString(objXmlMetatype["intmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["intmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["intaug"]?.InnerText, intForce, 0)); objCharacter.LOG.AssignLimits(ExpressionToString(objXmlMetatype["logmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["logmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["logaug"]?.InnerText, intForce, 0)); objCharacter.WIL.AssignLimits(ExpressionToString(objXmlMetatype["wilmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["wilmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["wilaug"]?.InnerText, intForce, 0)); objCharacter.MAG.AssignLimits(ExpressionToString(objXmlMetatype["magmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["magmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["magaug"]?.InnerText, intForce, 0)); objCharacter.RES.AssignLimits(ExpressionToString(objXmlMetatype["resmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["resmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["resaug"]?.InnerText, intForce, 0)); objCharacter.EDG.AssignLimits(ExpressionToString(objXmlMetatype["edgmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["edgmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["edgaug"]?.InnerText, intForce, 0)); objCharacter.ESS.AssignLimits(ExpressionToString(objXmlMetatype["essmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essaug"]?.InnerText, intForce, 0)); } else { int intMinModifier = -3; objCharacter.BOD.AssignLimits(ExpressionToString(objXmlMetatype["bodmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["bodmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["bodmin"]?.InnerText, intForce, 3)); objCharacter.AGI.AssignLimits(ExpressionToString(objXmlMetatype["agimin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["agimin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["agimin"]?.InnerText, intForce, 3)); objCharacter.REA.AssignLimits(ExpressionToString(objXmlMetatype["reamin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["reamin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["reamin"]?.InnerText, intForce, 3)); objCharacter.STR.AssignLimits(ExpressionToString(objXmlMetatype["strmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["strmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["strmin"]?.InnerText, intForce, 3)); objCharacter.CHA.AssignLimits(ExpressionToString(objXmlMetatype["chamin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["chamin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["chamin"]?.InnerText, intForce, 3)); objCharacter.INT.AssignLimits(ExpressionToString(objXmlMetatype["intmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["intmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["intmin"]?.InnerText, intForce, 3)); objCharacter.LOG.AssignLimits(ExpressionToString(objXmlMetatype["logmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["logmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["logmin"]?.InnerText, intForce, 3)); objCharacter.WIL.AssignLimits(ExpressionToString(objXmlMetatype["wilmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["wilmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["wilmin"]?.InnerText, intForce, 3)); objCharacter.MAG.AssignLimits(ExpressionToString(objXmlMetatype["magmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["magmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["magmin"]?.InnerText, intForce, 3)); objCharacter.RES.AssignLimits(ExpressionToString(objXmlMetatype["resmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["resmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["resmin"]?.InnerText, intForce, 3)); objCharacter.EDG.AssignLimits(ExpressionToString(objXmlMetatype["edgmin"]?.InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["edgmin"]?.InnerText, intForce, 3), ExpressionToString(objXmlMetatype["edgmin"]?.InnerText, intForce, 3)); objCharacter.ESS.AssignLimits(ExpressionToString(objXmlMetatype["essmin"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essmax"]?.InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essaug"]?.InnerText, intForce, 0)); } // If we're working with a Critter, set the Attributes to their default values. objCharacter.BOD.MetatypeMinimum = ExpressionToInt(objXmlMetatype["bodmin"]?.InnerText, intForce, 0); objCharacter.AGI.MetatypeMinimum = ExpressionToInt(objXmlMetatype["agimin"]?.InnerText, intForce, 0); objCharacter.REA.MetatypeMinimum = ExpressionToInt(objXmlMetatype["reamin"]?.InnerText, intForce, 0); objCharacter.STR.MetatypeMinimum = ExpressionToInt(objXmlMetatype["strmin"]?.InnerText, intForce, 0); objCharacter.CHA.MetatypeMinimum = ExpressionToInt(objXmlMetatype["chamin"]?.InnerText, intForce, 0); objCharacter.INT.MetatypeMinimum = ExpressionToInt(objXmlMetatype["intmin"]?.InnerText, intForce, 0); objCharacter.LOG.MetatypeMinimum = ExpressionToInt(objXmlMetatype["logmin"]?.InnerText, intForce, 0); objCharacter.WIL.MetatypeMinimum = ExpressionToInt(objXmlMetatype["wilmin"]?.InnerText, intForce, 0); objCharacter.MAG.MetatypeMinimum = ExpressionToInt(objXmlMetatype["magmin"]?.InnerText, intForce, 0); objCharacter.RES.MetatypeMinimum = ExpressionToInt(objXmlMetatype["resmin"]?.InnerText, intForce, 0); objCharacter.EDG.MetatypeMinimum = ExpressionToInt(objXmlMetatype["edgmin"]?.InnerText, intForce, 0); objCharacter.ESS.MetatypeMinimum = ExpressionToInt(objXmlMetatype["essmax"]?.InnerText, intForce, 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 = XmlManager.Load("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 = XmlManager.Load("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 = Convert.ToInt32(objXmlPower.Attributes?["rating"]?.InnerText, GlobalOptions.InvariantCultureInfo); 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 = XmlManager.Load("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); } // Add any Gear the Critter comes with (typically Programs for A.I.s) XmlDocument objXmlGearDocument = XmlManager.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlCritter.SelectNodes("gears/gear")) { int intRating = 0; if (objXmlGear.Attributes["rating"] != null) { intRating = ExpressionToInt(objXmlGear.Attributes["rating"].InnerText, decimal.ToInt32(nudForce.Value), 0); } string strForceValue = objXmlGear.Attributes?["select"]?.InnerText ?? string.Empty; XmlNode objXmlGearItem = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = " + objXmlGear.InnerText.CleanXPath() + "]"); Gear objGear = new Gear(objCharacter); List <Weapon> lstWeapons = new List <Weapon>(1); objGear.Create(objXmlGearItem, intRating, lstWeapons, strForceValue); objGear.Cost = "0"; objCharacter.Gear.Add(objGear); } // Add the Unarmed Attack Weapon to the character. objXmlDocument = XmlManager.Load("weapons.xml"); XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"Unarmed Attack\"]"); if (objXmlWeapon != null) { List <Weapon> lstWeapons = new List <Weapon>(1); Weapon objWeapon = new Weapon(objCharacter); objWeapon.Create(objXmlWeapon, lstWeapons); objWeapon.ParentID = Guid.NewGuid().ToString("D", GlobalOptions.InvariantCultureInfo); // Unarmed Attack can never be removed objCharacter.Weapons.Add(objWeapon); foreach (Weapon objLoopWeapon in lstWeapons) { objCharacter.Weapons.Add(objLoopWeapon); } } objCharacter.Alias = strCritterName; objCharacter.Created = true; if (!objCharacter.Save()) { Cursor = Cursors.Default; return; } _objSpirit.FileName = objCharacter.FileName; } // 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, null); Character objOpenCharacter = await Program.MainForm.LoadCharacter(_objSpirit.FileName).ConfigureAwait(true); Cursor = Cursors.Default; Program.MainForm.OpenCharacter(objOpenCharacter); }
/// <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; string strBaseLifestyle = string.Empty; // Get the base cost of the lifestyle string strSelectedId = cboLifestyle.SelectedValue?.ToString(); if (strSelectedId != null) { XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[id = " + strSelectedId.CleanXPath() + "]"); if (objXmlAspect != null) { objXmlAspect.TryGetStringFieldQuickly("name", ref strBaseLifestyle); decimal decTemp = 0; if (objXmlAspect.TryGetDecFieldQuickly("cost", ref decTemp)) { decBaseCost += decTemp; } string strSource = objXmlAspect["source"]?.InnerText; string strPage = objXmlAspect["altpage"]?.InnerText ?? objXmlAspect["page"]?.InnerText; if (!string.IsNullOrEmpty(strSource) && !string.IsNullOrEmpty(strPage)) { SourceString objSource = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter); lblSource.Text = objSource.ToString(); lblSource.SetToolTip(objSource.LanguageBookTooltip); } else { lblSource.Text = LanguageManager.GetString("String_Unknown"); lblSource.SetToolTip(LanguageManager.GetString("String_Unknown")); } 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.ToString().CleanXPath() + "]/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.ToString().CleanXPath() + "]"); if (objXmlAspect == null) { continue; } if (objXmlAspect.TryGetDecFieldQuickly("multiplier", ref decTemp)) { decMod += decTemp / 100.0m; } if (objXmlAspect.TryGetDecFieldQuickly("multiplierbaseonly", ref decTemp)) { decBaseMultiplier += decTemp / 100.0m; } } // Check for modifiers in the improvements decMod += ImprovementManager.ValueOf(_objCharacter, Improvement.ImprovementType.LifestyleCost) / 100.0m; } decBaseCost += decBaseCost * decBaseMultiplier; if (nudRoommates.Value > 0) { decBaseCost *= 1.0m + Math.Max(nudRoommates.Value / 10.0m, 0); } } } decimal decNuyen = decBaseCost + decBaseCost * decMod + decCost; lblCost.Text = decNuyen.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥'; if (nudPercentage.Value != 100 || nudRoommates.Value != 0 && !chkPrimaryTenant.Checked) { decimal decDiscount = decNuyen; decDiscount *= nudPercentage.Value / 100; if (nudRoommates.Value != 0) { decDiscount /= nudRoommates.Value; } lblCost.Text += LanguageManager.GetString("String_Space") + '(' + decDiscount.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + "¥)"; } lblCostLabel.Visible = !string.IsNullOrEmpty(lblCost.Text); // Characters with the Trust Fund Quality can have the lifestyle discounted. if (Lifestyle.StaticIsTrustFundEligible(_objCharacter, strBaseLifestyle)) { chkTrustFund.Visible = true; chkTrustFund.Checked = _objSourceLifestyle.TrustFund; } else { chkTrustFund.Checked = false; chkTrustFund.Visible = false; } }
/// <summary> /// Create a LifestyleQuality from an XmlNode. /// </summary> /// <param name="objXmlLifestyleQuality">XmlNode to create the object from.</param> /// <param name="objCharacter">Character object the LifestyleQuality will be added to.</param> /// <param name="objParentLifestyle">Lifestyle object to which the LifestyleQuality will be added.</param> /// <param name="objLifestyleQualitySource">Source of the LifestyleQuality.</param> /// <param name="strExtra">Forced value for the LifestyleQuality's Extra string (also used by its bonus node).</param> public void Create(XmlNode objXmlLifestyleQuality, Lifestyle objParentLifestyle, Character objCharacter, QualitySource objLifestyleQualitySource, string strExtra = "") { _objParentLifestyle = objParentLifestyle; if (!objXmlLifestyleQuality.TryGetField("id", Guid.TryParse, out _guiSourceID)) { Log.Warn(new object[] { "Missing id field for xmlnode", objXmlLifestyleQuality }); Utils.BreakIfDebug(); } else { _objCachedMyXmlNode = null; } if (objXmlLifestyleQuality.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } objXmlLifestyleQuality.TryGetInt32FieldQuickly("lp", ref _intLP); objXmlLifestyleQuality.TryGetStringFieldQuickly("cost", ref _strCost); objXmlLifestyleQuality.TryGetInt32FieldQuickly("multiplier", ref _intMultiplier); objXmlLifestyleQuality.TryGetInt32FieldQuickly("multiplierbaseonly", ref _intBaseMultiplier); if (objXmlLifestyleQuality.TryGetStringFieldQuickly("category", ref _strCategory)) { _objLifestyleQualityType = ConvertToLifestyleQualityType(_strCategory); } _objLifestyleQualitySource = objLifestyleQualitySource; objXmlLifestyleQuality.TryGetBoolFieldQuickly("print", ref _blnPrint); objXmlLifestyleQuality.TryGetBoolFieldQuickly("contributetolimit", ref _blnContributeToLP); if (!objXmlLifestyleQuality.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objXmlLifestyleQuality.TryGetStringFieldQuickly("notes", ref _strNotes); } objXmlLifestyleQuality.TryGetStringFieldQuickly("source", ref _strSource); objXmlLifestyleQuality.TryGetStringFieldQuickly("page", ref _strPage); string strAllowedFreeLifestyles = string.Empty; if (objXmlLifestyleQuality.TryGetStringFieldQuickly("allowed", ref strAllowedFreeLifestyles)) { _lstAllowedFreeLifestyles = strAllowedFreeLifestyles.Split(',').ToList(); } _strExtra = strExtra; int intParenthesesIndex = _strExtra.IndexOf('('); if (intParenthesesIndex != -1) { _strExtra = intParenthesesIndex + 1 < strExtra.Length ? strExtra.Substring(intParenthesesIndex + 1).TrimEndOnce(')') : string.Empty; } // If the item grants a bonus, pass the information to the Improvement Manager. XmlNode xmlBonus = objXmlLifestyleQuality["bonus"]; if (xmlBonus != null) { string strOldFoced = ImprovementManager.ForcedValue; if (!string.IsNullOrEmpty(_strExtra)) { ImprovementManager.ForcedValue = _strExtra; } if (!ImprovementManager.CreateImprovements(objCharacter, Improvement.ImprovementSource.Quality, InternalId, xmlBonus, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; ImprovementManager.ForcedValue = strOldFoced; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldFoced; } // Built-In Qualities appear as grey text to show that they cannot be removed. if (objLifestyleQualitySource == QualitySource.BuiltIn) { Free = true; } }
/// <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 void CreateCritter(string strCritterName, int intForce) { // The Critter should use the same settings file as the character. Character objCharacter = new Character(); objCharacter.SettingsFile = _objSpirit.CharacterObject.SettingsFile; // Override the defaults for the setting. objCharacter.IgnoreRules = true; objCharacter.IsCritter = true; objCharacter.BuildMethod = CharacterBuildMethod.Karma; objCharacter.BuildPoints = 0; if (txtCritterName.Text != string.Empty) { objCharacter.Name = txtCritterName.Text; } // Make sure that Running Wild is one of the allowed source books since most of the Critter Powers come from this book. bool blnRunningWild = false; blnRunningWild = (objCharacter.Options.Books.Contains("RW")); if (!blnRunningWild) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Main_RunningWild"), LanguageManager.Instance.GetString("MessageTitle_Main_RunningWild"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Ask the user to select a filename for the new character. string strForce = LanguageManager.Instance.GetString("String_Force"); if (_objSpirit.EntityType == SpiritType.Sprite) { strForce = LanguageManager.Instance.GetString("String_Rating"); } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Chummer5 Files (*.chum5)|*.chum5|All Files (*.*)|*.*"; saveFileDialog.FileName = strCritterName + " (" + strForce + " " + _objSpirit.Force.ToString() + ").chum5"; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { string strFileName = saveFileDialog.FileName; objCharacter.FileName = strFileName; } else { return; } // Code from frmMetatype. ImprovementManager objImprovementManager = new ImprovementManager(objCharacter); XmlDocument objXmlDocument = XmlManager.Instance.Load("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) { MessageBox.Show(LanguageManager.Instance.GetString("Message_UnknownCritterType").Replace("{0}", strCritterName), LanguageManager.Instance.GetString("MessageTitle_SelectCritterType"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Set Metatype information. if (strCritterName == "Ally Spirit") { objCharacter.BOD.AssignLimits(ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["bodmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["bodaug"].InnerText, intForce, 0)); objCharacter.AGI.AssignLimits(ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["agimax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["agiaug"].InnerText, intForce, 0)); objCharacter.REA.AssignLimits(ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["reamax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["reaaug"].InnerText, intForce, 0)); objCharacter.STR.AssignLimits(ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["strmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["straug"].InnerText, intForce, 0)); objCharacter.CHA.AssignLimits(ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["chamax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["chaaug"].InnerText, intForce, 0)); objCharacter.INT.AssignLimits(ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["intmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["intaug"].InnerText, intForce, 0)); objCharacter.LOG.AssignLimits(ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["logmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["logaug"].InnerText, intForce, 0)); objCharacter.WIL.AssignLimits(ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["wilmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["wilaug"].InnerText, intForce, 0)); objCharacter.INI.AssignLimits(ExpressionToString(objXmlMetatype["inimin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["inimax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["iniaug"].InnerText, intForce, 0)); objCharacter.MAG.AssignLimits(ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["magmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["magaug"].InnerText, intForce, 0)); objCharacter.RES.AssignLimits(ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["resmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["resaug"].InnerText, intForce, 0)); objCharacter.EDG.AssignLimits(ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["edgmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["edgaug"].InnerText, intForce, 0)); objCharacter.ESS.AssignLimits(ExpressionToString(objXmlMetatype["essmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essaug"].InnerText, intForce, 0)); } else { int intMinModifier = -3; if (objXmlMetatype["category"].InnerText == "Mutant Critters") { intMinModifier = 0; } objCharacter.BOD.AssignLimits(ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 3)); objCharacter.AGI.AssignLimits(ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 3)); objCharacter.REA.AssignLimits(ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 3)); objCharacter.STR.AssignLimits(ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 3)); objCharacter.CHA.AssignLimits(ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 3)); objCharacter.INT.AssignLimits(ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 3)); objCharacter.LOG.AssignLimits(ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 3)); objCharacter.WIL.AssignLimits(ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 3)); objCharacter.INI.AssignLimits(ExpressionToString(objXmlMetatype["inimin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["inimax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["iniaug"].InnerText, intForce, 0)); objCharacter.MAG.AssignLimits(ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 3)); objCharacter.RES.AssignLimits(ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 3)); objCharacter.EDG.AssignLimits(ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 3)); objCharacter.ESS.AssignLimits(ExpressionToString(objXmlMetatype["essmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essaug"].InnerText, intForce, 0)); } // If we're working with a Critter, set the Attributes to their default values. objCharacter.BOD.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 0)); objCharacter.AGI.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 0)); objCharacter.REA.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 0)); objCharacter.STR.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 0)); objCharacter.CHA.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 0)); objCharacter.INT.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 0)); objCharacter.LOG.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 0)); objCharacter.WIL.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 0)); objCharacter.MAG.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 0)); objCharacter.RES.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 0)); objCharacter.EDG.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 0)); objCharacter.ESS.Value = Convert.ToInt32(ExpressionToString(objXmlMetatype["essmax"].InnerText, intForce, 0)); // Sprites can never have Physical Attributes or WIL. if (objXmlMetatype["category"].InnerText.EndsWith("Sprite")) { 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.WIL.AssignLimits("0", "0", "0"); objCharacter.INI.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["inimax"].InnerText, intForce, 0)); objCharacter.INI.MetatypeMaximum = Convert.ToInt32(ExpressionToString(objXmlMetatype["inimax"].InnerText, intForce, 0)); } objCharacter.Metatype = strCritterName; objCharacter.MetatypeCategory = objXmlMetatype["category"].InnerText; objCharacter.Metavariant = ""; objCharacter.MetatypeBP = 0; if (objXmlMetatype["movement"] != null) { objCharacter.Movement = objXmlMetatype["movement"].InnerText; } // Load the Qualities file. XmlDocument objXmlQualityDocument = XmlManager.Instance.Load("qualities.xml"); // Determine if the Metatype has any bonuses. if (objXmlMetatype.InnerXml.Contains("bonus")) { objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Metatype, strCritterName, objXmlMetatype.SelectSingleNode("bonus"), false, 1, strCritterName); } // Create the Qualities that come with the Metatype. foreach (XmlNode objXmlQualityItem in objXmlMetatype.SelectNodes("qualities/positive/quality")) { XmlNode objXmlQuality = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQualityItem.InnerText + "\"]"); TreeNode objNode = new TreeNode(); List <Weapon> objWeapons = new List <Weapon>(); List <TreeNode> objWeaponNodes = new List <TreeNode>(); Quality objQuality = new Quality(objCharacter); string strForceValue = ""; if (objXmlQualityItem.Attributes["select"] != null) { strForceValue = objXmlQualityItem.Attributes["select"].InnerText; } QualitySource objSource = new QualitySource(); objSource = QualitySource.Metatype; if (objXmlQualityItem.Attributes["removable"] != null) { objSource = QualitySource.MetatypeRemovable; } objQuality.Create(objXmlQuality, objCharacter, objSource, objNode, objWeapons, objWeaponNodes, strForceValue); objCharacter.Qualities.Add(objQuality); // Add any created Weapons to the character. foreach (Weapon objWeapon in objWeapons) { objCharacter.Weapons.Add(objWeapon); } } foreach (XmlNode objXmlQualityItem in objXmlMetatype.SelectNodes("qualities/negative/quality")) { XmlNode objXmlQuality = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQualityItem.InnerText + "\"]"); TreeNode objNode = new TreeNode(); List <Weapon> objWeapons = new List <Weapon>(); List <TreeNode> objWeaponNodes = new List <TreeNode>(); Quality objQuality = new Quality(objCharacter); string strForceValue = ""; if (objXmlQualityItem.Attributes["select"] != null) { strForceValue = objXmlQualityItem.Attributes["select"].InnerText; } QualitySource objSource = new QualitySource(); objSource = QualitySource.Metatype; if (objXmlQualityItem.Attributes["removable"] != null) { objSource = QualitySource.MetatypeRemovable; } objQuality.Create(objXmlQuality, objCharacter, objSource, objNode, objWeapons, objWeaponNodes, strForceValue); objCharacter.Qualities.Add(objQuality); // Add any created Weapons to the character. foreach (Weapon objWeapon in objWeapons) { objCharacter.Weapons.Add(objWeapon); } } // Add any Critter Powers the Metatype/Critter should have. XmlNode objXmlCritter = objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + objCharacter.Metatype + "\"]"); objXmlDocument = XmlManager.Instance.Load("critterpowers.xml"); foreach (XmlNode objXmlPower in objXmlCritter.SelectNodes("powers/power")) { XmlNode objXmlCritterPower = objXmlDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower.InnerText + "\"]"); TreeNode objNode = new TreeNode(); CritterPower objPower = new CritterPower(objCharacter); string strForcedValue = ""; int intRating = 0; if (objXmlPower.Attributes["rating"] != null) { intRating = Convert.ToInt32(objXmlPower.Attributes["rating"].InnerText); } if (objXmlPower.Attributes["select"] != null) { strForcedValue = objXmlPower.Attributes["select"].InnerText; } objPower.Create(objXmlCritterPower, objCharacter, objNode, intRating, strForcedValue); objCharacter.CritterPowers.Add(objPower); } //TODO, when is this shit required, 4e holdover or need? // Set the Skill Ratings for the Critter. //foreach (XmlNode objXmlSkill in objXmlCritter.SelectNodes("skills/skill")) //{ // if (objXmlSkill.InnerText.Contains("Exotic")) // { // Skill objExotic = new Skill(objCharacter); // objExotic.ExoticSkill = true; // objExotic.Attribute = "AGI"; // if (objXmlSkill.Attributes["spec"] != null) // { // SkillSpecialization objSpec = new SkillSpecialization(objXmlSkill.Attributes["spec"].InnerText); // objExotic.Specializations.Add(objSpec); // } // if (Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)) > 6) // objExotic.RatingMaximum = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); // objExotic.Rating = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); // objExotic.Name = objXmlSkill.InnerText; // objCharacter.Skills.Add(objExotic); // } // else // { // foreach (Skill objSkill in objCharacter.Skills) // { // if (objSkill.Name == objXmlSkill.InnerText) // { // if (objXmlSkill.Attributes["spec"] != null) // { // SkillSpecialization objSpec = new SkillSpecialization(objXmlSkill.Attributes["spec"].InnerText); // objSkill.Specializations.Add(objSpec); // } // if (Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)) > 6) // objSkill.RatingMaximum = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); // objSkill.Rating = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); // break; // } // } // } //} // Set the Skill Group Ratings for the Critter. //foreach (XmlNode objXmlSkill in objXmlCritter.SelectNodes("skills/group")) //{ // foreach (SkillGroup objSkill in objCharacter.SkillGroups) // { // if (objSkill.Name == objXmlSkill.InnerText) // { // objSkill.RatingMaximum = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); // objSkill.Rating = Convert.ToInt32(ExpressionToString(objXmlSkill.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); // break; // } // } //} //TODO: WHEN IS THIS NEEDED, 4e holdover? //// Set the Knowledge Skill Ratings for the Critter. //foreach (XmlNode objXmlSkill in objXmlCritter.SelectNodes("skills/knowledge")) //{ // Skill objKnowledge = new Skill(objCharacter); // objKnowledge.Name = objXmlSkill.InnerText; // objKnowledge.KnowledgeSkill = true; // if (objXmlSkill.Attributes["spec"] != null) // { // SkillSpecialization objSpec = new SkillSpecialization(objXmlSkill.Attributes["spec"].InnerText); // objKnowledge.Specializations.Add(objSpec); // } // objKnowledge.SkillCategory = objXmlSkill.Attributes["category"].InnerText; // if (Convert.ToInt32(objXmlSkill.Attributes["rating"].InnerText) > 6) // objKnowledge.RatingMaximum = Convert.ToInt32(objXmlSkill.Attributes["rating"].InnerText); // objKnowledge.Rating = Convert.ToInt32(objXmlSkill.Attributes["rating"].InnerText); // objCharacter.Skills.Add(objKnowledge); //} //// If this is a Critter with a Force (which dictates their Skill Rating/Maximum Skill Rating), set their Skill Rating Maximums. //if (intForce > 0) //{ // int intMaxRating = intForce; // // Determine the highest Skill Rating the Critter has. // foreach (Skill objSkill in objCharacter.Skills) // { // if (objSkill.RatingMaximum > intMaxRating) // intMaxRating = objSkill.RatingMaximum; // } // // Now that we know the upper limit, set all of the Skill Rating Maximums to match. // foreach (Skill objSkill in objCharacter.Skills) // objSkill.RatingMaximum = intMaxRating; // foreach (SkillGroup objGroup in objCharacter.SkillGroups) // objGroup.RatingMaximum = intMaxRating; // // Set the MaxSkillRating for the character so it can be used later when they add new Knowledge Skills or Exotic Skills. // objCharacter.MaxSkillRating = intMaxRating; //} // Add any Complex Forms the Critter comes with (typically Sprites) XmlDocument objXmlProgramDocument = XmlManager.Instance.Load("complexforms.xml"); foreach (XmlNode objXmlComplexForm in objXmlCritter.SelectNodes("complexforms/complexform")) { string strForceValue = ""; if (objXmlComplexForm.Attributes["select"] != null) { strForceValue = objXmlComplexForm.Attributes["select"].InnerText; } XmlNode objXmlProgram = objXmlProgramDocument.SelectSingleNode("/chummer/complexforms/complexform[name = \"" + objXmlComplexForm.InnerText + "\"]"); TreeNode objNode = new TreeNode(); ComplexForm objProgram = new ComplexForm(objCharacter); objProgram.Create(objXmlProgram, objCharacter, objNode, strForceValue); objCharacter.ComplexForms.Add(objProgram); } // Add any Gear the Critter comes with (typically Programs for A.I.s) XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlCritter.SelectNodes("gears/gear")) { int intRating = 0; if (objXmlGear.Attributes["rating"] != null) { intRating = Convert.ToInt32(ExpressionToString(objXmlGear.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); } string strForceValue = ""; if (objXmlGear.Attributes["select"] != null) { strForceValue = objXmlGear.Attributes["select"].InnerText; } XmlNode objXmlGearItem = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlGear.InnerText + "\"]"); TreeNode objNode = new TreeNode(); Gear objGear = new Gear(objCharacter); List <Weapon> lstWeapons = new List <Weapon>(); List <TreeNode> lstWeaponNodes = new List <TreeNode>(); objGear.Create(objXmlGearItem, objCharacter, objNode, intRating, lstWeapons, lstWeaponNodes, strForceValue); objGear.Cost = "0"; objGear.Cost3 = "0"; objGear.Cost6 = "0"; objGear.Cost10 = "0"; objCharacter.Gear.Add(objGear); } // If this is a Mutant Critter, count up the number of Skill points they start with. if (objCharacter.MetatypeCategory == "Mutant Critters") { foreach (Skill objSkill in objCharacter.SkillsSection.Skills) { objCharacter.MutantCritterBaseSkills += objSkill.Rating; } } // Add the Unarmed Attack Weapon to the character. try { objXmlDocument = XmlManager.Instance.Load("weapons.xml"); XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"Unarmed Attack\"]"); TreeNode objDummy = new TreeNode(); Weapon objWeapon = new Weapon(objCharacter); objWeapon.Create(objXmlWeapon, objCharacter, objDummy, null, null); objCharacter.Weapons.Add(objWeapon); } catch { } objCharacter.Alias = strCritterName; objCharacter.Created = true; objCharacter.Save(); string strOpenFile = objCharacter.FileName; objCharacter = null; // Link the newly-created Critter to the Spirit. _objSpirit.FileName = strOpenFile; if (_objSpirit.EntityType == SpiritType.Spirit) { tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Spirit_OpenFile")); } else { tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Sprite_OpenFile")); } FileNameChanged(this); GlobalOptions.Instance.MainForm.LoadCharacter(strOpenFile, true); }
private void InitializeTable() { _table = new TableView <Power> { Dock = DockStyle.Top, ToolTip = _tipTooltip }; // create columns TableColumn <Power> nameColumn = new TableColumn <Power>(() => new TextTableCell()) { Text = "Power", Extractor = (power => power.CurrentDisplayName), Tag = "String_Power", Sorter = (name1, name2) => string.Compare((string)name1, (string)name2, GlobalSettings.CultureInfo, CompareOptions.Ordinal) }; nameColumn.AddDependency(nameof(Power.CurrentDisplayName)); TableColumn <Power> actionColumn = new TableColumn <Power>(() => new TextTableCell()) { Text = "Action", Extractor = (power => power.DisplayAction), Tag = "ColumnHeader_Action", Sorter = (action1, action2) => string.Compare((string)action1, (string)action2, GlobalSettings.CultureInfo, CompareOptions.Ordinal) }; actionColumn.AddDependency(nameof(Power.DisplayAction)); TableColumn <Power> ratingColumn = new TableColumn <Power>(() => new SpinnerTableCell <Power>(_table) { EnabledExtractor = (p => p.LevelsEnabled), MaxExtractor = (p => Math.Max(p.TotalMaximumLevels - p.FreeLevels, 0)), ValueUpdater = (p, newRating) => { int delta = ((int)newRating) - p.Rating; if (delta != 0) { p.Rating += delta; } }, MinExtractor = (p => 0), ValueGetter = (p => p.Rating) }) { Text = "Rating", Tag = "String_Rating", Sorter = (o1, o2) => { if (o1 is Power objPower1 && o2 is Power objPower2) { return(objPower1.Rating - objPower2.Rating); } string strMessage = "Can't sort an Object of Type " + o1.GetType() + " against another one of Type " + o2.GetType() + " in the ratingColumn." + Environment.NewLine + "Both objects SHOULD be of the type \"Power\"."; throw new ArgumentException(strMessage, nameof(o1)); } }; ratingColumn.AddDependency(nameof(Power.LevelsEnabled)); ratingColumn.AddDependency(nameof(Power.FreeLevels)); ratingColumn.AddDependency(nameof(Power.TotalMaximumLevels)); ratingColumn.AddDependency(nameof(Power.TotalRating)); TableColumn <Power> totalRatingColumn = new TableColumn <Power>(() => new TextTableCell()) { Text = "Total Rating", Extractor = (power => power.TotalRating), Tag = "String_TotalRating", Sorter = (o1, o2) => { if (o1 is Power objPower1 && o2 is Power objPower2) { return(objPower1.TotalRating - objPower2.TotalRating); } string strMessage = "Can't sort an Object of Type " + o1.GetType() + " against another one of Type " + o2.GetType() + " in the totalRatingColumn." + Environment.NewLine + "Both objects SHOULD be of the type \"Power\"."; throw new ArgumentException(strMessage, nameof(o1)); } }; totalRatingColumn.AddDependency(nameof(Power.TotalRating)); TableColumn <Power> powerPointsColumn = new TableColumn <Power>(() => new TextTableCell()) { Text = "Power Points", Extractor = (power => power.DisplayPoints), Tag = "ColumnHeader_Power_Points", ToolTipExtractor = (item => item.ToolTip) }; powerPointsColumn.AddDependency(nameof(Power.DisplayPoints)); powerPointsColumn.AddDependency(nameof(Power.ToolTip)); TableColumn <Power> sourceColumn = new TableColumn <Power>(() => new TextTableCell { Cursor = Cursors.Hand }) { Text = "Source", Extractor = (power => power.SourceDetail), Tag = "Label_Source", ToolTipExtractor = (item => item.SourceDetail.LanguageBookTooltip) }; powerPointsColumn.AddDependency(nameof(Power.Source)); TableColumn <Power> adeptWayColumn = new TableColumn <Power>(() => new CheckBoxTableCell <Power> { ValueGetter = p => p.DiscountedAdeptWay, ValueUpdater = (p, check) => p.DiscountedAdeptWay = check, VisibleExtractor = p => p.AdeptWayDiscountEnabled, EnabledExtractor = p => p.CharacterObject.AllowAdeptWayPowerDiscount || p.DiscountedAdeptWay, Alignment = Alignment.Center }) { Text = "Adept Way", Tag = "Checkbox_Power_AdeptWay" }; adeptWayColumn.AddDependency(nameof(Power.DiscountedAdeptWay)); adeptWayColumn.AddDependency(nameof(Power.AdeptWayDiscountEnabled)); adeptWayColumn.AddDependency(nameof(Character.AllowAdeptWayPowerDiscount)); adeptWayColumn.AddDependency(nameof(Power.Rating)); /* * TableColumn<Power> geasColumn = new TableColumn<Power>(() => new CheckBoxTableCell<Power>() * { * ValueGetter = (p => p.DiscountedGeas), * ValueUpdater = (p, check) => p.DiscountedGeas = check, * Alignment = Alignment.Center * }) * { * Text = "Geas", * Tag = "Checkbox_Power_Geas" * }; * geasColumn.AddDependency(nameof(Power.DiscountedGeas)); */ TableColumn <Power> noteColumn = new TableColumn <Power>(() => new ButtonTableCell <Power>(new PictureBox { Image = Resources.note_edit, Size = GetImageSize(Resources.note_edit) }) { ClickHandler = async p => { using (EditNotes frmPowerNotes = new EditNotes(p.Notes, p.NotesColor)) { await frmPowerNotes.ShowDialogSafeAsync(this); if (frmPowerNotes.DialogResult == DialogResult.OK) { p.Notes = frmPowerNotes.Notes; } } }, Alignment = Alignment.Center }) { Text = "Notes", Tag = "ColumnHeader_Notes", ToolTipExtractor = (p => { string strTooltip = LanguageManager.GetString("Tip_Power_EditNotes"); if (!string.IsNullOrEmpty(p.Notes)) { strTooltip += Environment.NewLine + Environment.NewLine + p.Notes.RtfToPlainText(); } return(strTooltip.WordWrap()); }) }; noteColumn.AddDependency(nameof(Power.Notes)); TableColumn <Power> deleteColumn = new TableColumn <Power>(() => new ButtonTableCell <Power>(new Button { Text = LanguageManager.GetString("String_Delete"), Tag = "String_Delete", Dock = DockStyle.Fill }) { ClickHandler = p => { //Cache the parentform prior to deletion, otherwise the relationship is broken. Form frmParent = ParentForm; if (p.FreeLevels > 0) { string strExtra = p.Extra; string strImprovementSourceName = ImprovementManager.GetCachedImprovementListForValueOf(p.CharacterObject, Improvement.ImprovementType.AdeptPowerFreePoints, p.Name) .Find(x => x.UniqueName == strExtra)?.SourceName; if (!string.IsNullOrWhiteSpace(strImprovementSourceName)) { Gear objGear = p.CharacterObject.Gear.FindById(strImprovementSourceName); if (objGear?.Bonded == true) { objGear.Equipped = false; objGear.Extra = string.Empty; } } } p.DeletePower(); p.UnbindPower(); if (frmParent is CharacterShared objParent) { objParent.IsCharacterUpdateRequested = true; } return(Task.CompletedTask); }, EnabledExtractor = (p => p.FreeLevels == 0) });
/// Create a Armor Modification from an XmlNode and return the TreeNodes for it. /// <param name="objXmlArmorNode">XmlNode to create the object from.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="intRating">Rating of the selected ArmorMod.</param> /// <param name="objWeapons">List of Weapons that are created by the Armor.</param> /// <param name="objWeaponNodes">List of Weapon Nodes that are created by the Armor.</param> /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param> public void Create(XmlNode objXmlArmorNode, TreeNode objNode, ContextMenuStrip cmsArmorGear, int intRating, List <Weapon> objWeapons, List <TreeNode> objWeaponNodes, bool blnSkipCost = false, bool blnSkipSelectForms = false) { if (objXmlArmorNode.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } objXmlArmorNode.TryGetStringFieldQuickly("category", ref _strCategory); objXmlArmorNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity); objXmlArmorNode.TryGetStringFieldQuickly("gearcapacity", ref _strGearCapacity); _intRating = intRating; objXmlArmorNode.TryGetInt32FieldQuickly("armor", ref _intA); objXmlArmorNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating); objXmlArmorNode.TryGetStringFieldQuickly("avail", ref _strAvail); objXmlArmorNode.TryGetStringFieldQuickly("source", ref _strSource); objXmlArmorNode.TryGetStringFieldQuickly("page", ref _strPage); _nodBonus = objXmlArmorNode["bonus"]; _nodWirelessBonus = objXmlArmorNode["wirelessbonus"]; _blnWirelessOn = _nodWirelessBonus != null; if (GlobalOptions.Language != GlobalOptions.DefaultLanguage) { XmlNode objArmorNode = MyXmlNode; if (objArmorNode != null) { objArmorNode.TryGetStringFieldQuickly("translate", ref _strAltName); objArmorNode.TryGetStringFieldQuickly("altpage", ref _strAltPage); } XmlDocument objXmlDocument = XmlManager.Load("armor.xml"); objArmorNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]"); _strAltCategory = objArmorNode?.Attributes?["translate"]?.InnerText; } // Check for a Variable Cost. if (blnSkipCost) { _strCost = "0"; } else if (objXmlArmorNode["cost"] != null) { XmlNode objXmlArmorCostNode = objXmlArmorNode["cost"]; if (objXmlArmorCostNode.InnerText.StartsWith("Variable")) { decimal decMin = 0.0m; decimal decMax = decimal.MaxValue; char[] charParentheses = { '(', ')' }; string strCost = objXmlArmorNode["cost"].InnerText.TrimStart("Variable", true).Trim(charParentheses); if (strCost.Contains('-')) { string[] strValues = strCost.Split('-'); decMin = Convert.ToDecimal(strValues[0], GlobalOptions.InvariantCultureInfo); decMax = Convert.ToDecimal(strValues[1], GlobalOptions.InvariantCultureInfo); } else { decMin = Convert.ToDecimal(strCost.FastEscape('+'), GlobalOptions.InvariantCultureInfo); } if (decMin != 0 || decMax != decimal.MaxValue) { string strNuyenFormat = _objCharacter.Options.NuyenFormat; int intDecimalPlaces = strNuyenFormat.IndexOf('.'); if (intDecimalPlaces == -1) { intDecimalPlaces = 0; } else { intDecimalPlaces = strNuyenFormat.Length - intDecimalPlaces - 1; } frmSelectNumber frmPickNumber = new frmSelectNumber(intDecimalPlaces); if (decMax > 1000000) { decMax = 1000000; } frmPickNumber.Minimum = decMin; frmPickNumber.Maximum = decMax; frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost").Replace("{0}", DisplayNameShort); frmPickNumber.AllowCancel = false; frmPickNumber.ShowDialog(); _strCost = frmPickNumber.SelectedValue.ToString(); } } else { _strCost = objXmlArmorCostNode.InnerText; } } if (objXmlArmorNode["bonus"] != null && !blnSkipCost && !blnSkipSelectForms) { if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.ArmorMod, _guiID.ToString(), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; objNode.Text += " (" + ImprovementManager.SelectedValue + ")"; } } // Add any Gear that comes with the Armor. if (objXmlArmorNode["gears"] != null) { XmlDocument objXmlGearDocument = XmlManager.Load("gear.xml"); foreach (XmlNode objXmlArmorGear in objXmlArmorNode.SelectNodes("gears/usegear")) { intRating = 0; string strForceValue = string.Empty; objXmlArmorGear.TryGetInt32FieldQuickly("rating", ref intRating); objXmlArmorGear.TryGetStringFieldQuickly("select", ref strForceValue); XmlNode objXmlGear = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlArmorGear.InnerText + "\"]"); Gear objGear = new Gear(_objCharacter); TreeNode objGearNode = new TreeNode(); List <Weapon> lstWeapons = new List <Weapon>(); List <TreeNode> lstWeaponNodes = new List <TreeNode>(); if (!string.IsNullOrEmpty(objXmlGear["devicerating"]?.InnerText)) { Commlink objCommlink = new Commlink(_objCharacter); objCommlink.Create(objXmlGear, objGearNode, intRating, lstWeapons, lstWeaponNodes, strForceValue, false, false, !blnSkipCost && !blnSkipSelectForms); objGear = objCommlink; } else { objGear.Create(objXmlGear, objGearNode, intRating, lstWeapons, lstWeaponNodes, strForceValue, false, false, !blnSkipCost && !blnSkipSelectForms); } objGear.Capacity = "[0]"; objGear.ArmorCapacity = "[0]"; objGear.Cost = "0"; objGear.MaxRating = objGear.Rating; objGear.MinRating = objGear.Rating; objGear.ParentID = InternalId; _lstGear.Add(objGear); objGearNode.ForeColor = SystemColors.GrayText; objGearNode.ContextMenuStrip = cmsArmorGear; objNode.Nodes.Add(objGearNode); objNode.Expand(); } } // Add Weapons if applicable. if (objXmlArmorNode.InnerXml.Contains("<addweapon>")) { XmlDocument objXmlWeaponDocument = XmlManager.Load("weapons.xml"); // More than one Weapon can be added, so loop through all occurrences. foreach (XmlNode objXmlAddWeapon in objXmlArmorNode.SelectNodes("addweapon")) { string strLoopID = objXmlAddWeapon.InnerText; XmlNode objXmlWeapon = strLoopID.IsGuid() ? objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + strLoopID + "\"]") : objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + strLoopID + "\"]"); List <TreeNode> lstGearWeaponNodes = new List <TreeNode>(); Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Create(objXmlWeapon, lstGearWeaponNodes, null, null, objWeapons, null, true, !blnSkipCost && !blnSkipSelectForms); objGearWeapon.ParentID = InternalId; foreach (TreeNode objLoopNode in lstGearWeaponNodes) { objLoopNode.ForeColor = SystemColors.GrayText; objWeaponNodes.Add(objLoopNode); } objWeapons.Add(objGearWeapon); _guiWeaponID = Guid.Parse(objGearWeapon.InternalId); } } objNode.Text = DisplayName; objNode.Tag = _guiID.ToString(); }
/// <summary> /// Create a LifestyleQuality from an XmlNode and return the TreeNodes for it. /// </summary> /// <param name="objXmlLifestyleQuality">XmlNode to create the object from.</param> /// <param name="objCharacter">Character object the LifestyleQuality will be added to.</param> /// <param name="objLifestyleQualitySource">Source of the LifestyleQuality.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> public void Create(XmlNode objXmlLifestyleQuality, Lifestyle objParentLifestyle, Character objCharacter, QualitySource objLifestyleQualitySource, TreeNode objNode) { _objParentLifestyle = objParentLifestyle; _SourceGuid = Guid.Parse(objXmlLifestyleQuality["id"].InnerText); if (objXmlLifestyleQuality.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } objXmlLifestyleQuality.TryGetInt32FieldQuickly("lp", ref _intLP); objXmlLifestyleQuality.TryGetStringFieldQuickly("cost", ref _strCost); objXmlLifestyleQuality.TryGetInt32FieldQuickly("multiplier", ref _intMultiplier); objXmlLifestyleQuality.TryGetInt32FieldQuickly("multiplierbaseonly", ref _intBaseMultiplier); if (objXmlLifestyleQuality["category"] != null) { _objLifestyleQualityType = ConvertToLifestyleQualityType(objXmlLifestyleQuality["category"].InnerText); } _objLifestyleQualitySource = objLifestyleQualitySource; if (objXmlLifestyleQuality["print"]?.InnerText == "no") { _blnPrint = false; } if (objXmlLifestyleQuality["contributetolimit"]?.InnerText == "no") { _blnContributeToLimit = false; } objXmlLifestyleQuality.TryGetStringFieldQuickly("notes", ref _strNotes); objXmlLifestyleQuality.TryGetStringFieldQuickly("source", ref _strSource); objXmlLifestyleQuality.TryGetStringFieldQuickly("page", ref _strPage); string strAllowedFreeLifestyles = string.Empty; if (objXmlLifestyleQuality.TryGetStringFieldQuickly("allowed", ref strAllowedFreeLifestyles)) { _lstAllowedFreeLifestyles = strAllowedFreeLifestyles.Split(',').ToList(); } if (objNode.Text.Contains('(')) { _strExtra = objNode.Text.Split('(')[1].TrimEnd(')'); } // If the item grants a bonus, pass the information to the Improvement Manager. if (objXmlLifestyleQuality.InnerXml.Contains("<bonus>")) { if (!ImprovementManager.CreateImprovements(objCharacter, Improvement.ImprovementSource.Quality, _guiID.ToString(), objXmlLifestyleQuality["bonus"], false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; //objNode.Text += " (" + objImprovementManager.SelectedValue + ")"; } } // Built-In Qualities appear as grey text to show that they cannot be removed. if (objLifestyleQualitySource == QualitySource.BuiltIn) { objNode.ForeColor = SystemColors.GrayText; Free = true; } objNode.Name = Name; objNode.Text = FormattedDisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language); objNode.Tag = InternalId; }
/// <summary> /// Create a LifestyleQuality from an XmlNode. /// </summary> /// <param name="objXmlLifestyleQuality">XmlNode to create the object from.</param> /// <param name="objCharacter">Character object the LifestyleQuality will be added to.</param> /// <param name="objParentLifestyle">Lifestyle object to which the LifestyleQuality will be added.</param> /// <param name="objLifestyleQualitySource">Source of the LifestyleQuality.</param> /// <param name="strExtra">Forced value for the LifestyleQuality's Extra string (also used by its bonus node).</param> public void Create(XmlNode objXmlLifestyleQuality, Lifestyle objParentLifestyle, Character objCharacter, QualitySource objLifestyleQualitySource, string strExtra = "") { ParentLifestyle = objParentLifestyle; if (!objXmlLifestyleQuality.TryGetField("id", Guid.TryParse, out _guiSourceID)) { Log.Warn(new object[] { "Missing id field for xmlnode", objXmlLifestyleQuality }); Utils.BreakIfDebug(); } else { _objCachedMyXmlNode = null; } if (objXmlLifestyleQuality.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } objXmlLifestyleQuality.TryGetInt32FieldQuickly("lp", ref _intLP); objXmlLifestyleQuality.TryGetStringFieldQuickly("cost", ref _strCost); objXmlLifestyleQuality.TryGetInt32FieldQuickly("multiplier", ref _intMultiplier); objXmlLifestyleQuality.TryGetInt32FieldQuickly("multiplierbaseonly", ref _intBaseMultiplier); if (objXmlLifestyleQuality.TryGetStringFieldQuickly("category", ref _strCategory)) { Type = ConvertToLifestyleQualityType(_strCategory); } OriginSource = objLifestyleQualitySource; objXmlLifestyleQuality.TryGetInt32FieldQuickly("areamaximum", ref _intAreaMaximum); objXmlLifestyleQuality.TryGetInt32FieldQuickly("comfortsmaximum", ref _intComfortMaximum); objXmlLifestyleQuality.TryGetInt32FieldQuickly("securitymaximum", ref _intSecurityMaximum); objXmlLifestyleQuality.TryGetInt32FieldQuickly("area", ref _intArea); objXmlLifestyleQuality.TryGetInt32FieldQuickly("comforts", ref _intComfort); objXmlLifestyleQuality.TryGetInt32FieldQuickly("security", ref _intSecurity); objXmlLifestyleQuality.TryGetBoolFieldQuickly("print", ref _blnPrint); objXmlLifestyleQuality.TryGetBoolFieldQuickly("contributetolimit", ref _blnContributeToLP); if (!objXmlLifestyleQuality.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objXmlLifestyleQuality.TryGetStringFieldQuickly("notes", ref _strNotes); } objXmlLifestyleQuality.TryGetStringFieldQuickly("source", ref _strSource); objXmlLifestyleQuality.TryGetStringFieldQuickly("page", ref _strPage); var strAllowedFreeLifestyles = string.Empty; if (objXmlLifestyleQuality.TryGetStringFieldQuickly("allowed", ref strAllowedFreeLifestyles)) { _lstAllowedFreeLifestyles = strAllowedFreeLifestyles.Split(',', StringSplitOptions.RemoveEmptyEntries); } _strExtra = strExtra; if (!string.IsNullOrEmpty(_strExtra)) { var intParenthesesIndex = _strExtra.IndexOf('('); if (intParenthesesIndex != -1) { _strExtra = intParenthesesIndex + 1 < strExtra.Length ? strExtra.Substring(intParenthesesIndex + 1).TrimEndOnce(')') : string.Empty; } } if (string.IsNullOrEmpty(Notes)) { string strEnglishNameOnPage = Name; string strNameOnPage = string.Empty; // make sure we have something and not just an empty tag if (objXmlLifestyleQuality.TryGetStringFieldQuickly("nameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage)) { strEnglishNameOnPage = strNameOnPage; } string strGearNotes = CommonFunctions.GetTextFromPdf(Source + ' ' + Page, strEnglishNameOnPage); if (string.IsNullOrEmpty(strGearNotes) && GlobalOptions.Language != GlobalOptions.DefaultLanguage) { string strTranslatedNameOnPage = CurrentDisplayName; // don't check again it is not translated if (strTranslatedNameOnPage != _strName) { // if we found <altnameonpage>, and is not empty and not the same as english we must use that instead if (objXmlLifestyleQuality.TryGetStringFieldQuickly("altnameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage) && strNameOnPage != strEnglishNameOnPage) { strTranslatedNameOnPage = strNameOnPage; } Notes = CommonFunctions.GetTextFromPdf(Source + ' ' + DisplayPage(GlobalOptions.Language), strTranslatedNameOnPage); } } else { Notes = strGearNotes; } } // If the item grants a bonus, pass the information to the Improvement Manager. XmlNode xmlBonus = objXmlLifestyleQuality["bonus"]; if (xmlBonus != null) { var strOldForced = ImprovementManager.ForcedValue; if (!string.IsNullOrEmpty(_strExtra)) { ImprovementManager.ForcedValue = _strExtra; } if (!ImprovementManager.CreateImprovements(objCharacter, Improvement.ImprovementSource.Quality, InternalId, xmlBonus, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; ImprovementManager.ForcedValue = strOldForced; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldForced; } // Built-In Qualities appear as grey text to show that they cannot be removed. if (objLifestyleQualitySource == QualitySource.BuiltIn) { Free = true; } }
private void btnKnowledge_Click(object sender, EventArgs e) { if (_objCharacter.Created) { using (frmSelectItem form = new frmSelectItem { Description = LanguageManager.GetString("Label_Options_NewKnowledgeSkill") }) { form.SetDropdownItemsMode(KnowledgeSkill.DefaultKnowledgeSkills); if (form.ShowDialog(Program.MainForm) != DialogResult.OK) { return; } KnowledgeSkill skill = new KnowledgeSkill(_objCharacter) { WriteableName = form.SelectedItem }; if (_objCharacter.SkillsSection.HasAvailableNativeLanguageSlots && (skill.IsLanguage || string.IsNullOrEmpty(skill.Type))) { DialogResult eDialogResult = Program.MainForm.ShowMessageBox(this, string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("Message_NewNativeLanguageSkill"), 1 + ImprovementManager.ValueOf(_objCharacter, Improvement.ImprovementType.NativeLanguageLimit), skill.WriteableName), LanguageManager.GetString("Tip_Skill_NativeLanguage"), MessageBoxButtons.YesNoCancel); if (eDialogResult == DialogResult.Cancel) { return; } if (eDialogResult == DialogResult.Yes) { if (!skill.IsLanguage) { skill.Type = "Language"; } skill.IsNativeLanguage = true; } } _objCharacter.SkillsSection.KnowledgeSkills.Add(skill); } } else { _objCharacter.SkillsSection.KnowledgeSkills.Add(new KnowledgeSkill(_objCharacter)); } }
/// <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 void CreateCritter(string strCritterName, int intForce) { // The Critter should use the same settings file as the character. Character objCharacter = new Character(); objCharacter.SettingsFile = _objSpirit.CharacterObject.SettingsFile; // Override the defaults for the setting. objCharacter.IgnoreRules = true; objCharacter.IsCritter = true; objCharacter.BuildMethod = CharacterBuildMethod.Karma; objCharacter.BuildPoints = 0; if (!string.IsNullOrEmpty(txtCritterName.Text)) { objCharacter.Name = txtCritterName.Text; } // Ask the user to select a filename for the new character. string strForce = LanguageManager.Instance.GetString("String_Force"); if (_objSpirit.EntityType == SpiritType.Sprite) { strForce = LanguageManager.Instance.GetString("String_Rating"); } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Chummer5 Files (*.chum5)|*.chum5|All Files (*.*)|*.*"; saveFileDialog.FileName = strCritterName + " (" + strForce + " " + _objSpirit.Force.ToString() + ").chum5"; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { string strFileName = saveFileDialog.FileName; objCharacter.FileName = strFileName; } else { return; } // Code from frmMetatype. ImprovementManager objImprovementManager = new ImprovementManager(objCharacter); XmlDocument objXmlDocument = XmlManager.Instance.Load("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) { MessageBox.Show(LanguageManager.Instance.GetString("Message_UnknownCritterType").Replace("{0}", strCritterName), LanguageManager.Instance.GetString("MessageTitle_SelectCritterType"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Set Metatype information. if (strCritterName == "Ally Spirit") { objCharacter.BOD.AssignLimits(ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["bodmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["bodaug"].InnerText, intForce, 0)); objCharacter.AGI.AssignLimits(ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["agimax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["agiaug"].InnerText, intForce, 0)); objCharacter.REA.AssignLimits(ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["reamax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["reaaug"].InnerText, intForce, 0)); objCharacter.STR.AssignLimits(ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["strmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["straug"].InnerText, intForce, 0)); objCharacter.CHA.AssignLimits(ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["chamax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["chaaug"].InnerText, intForce, 0)); objCharacter.INT.AssignLimits(ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["intmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["intaug"].InnerText, intForce, 0)); objCharacter.LOG.AssignLimits(ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["logmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["logaug"].InnerText, intForce, 0)); objCharacter.WIL.AssignLimits(ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["wilmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["wilaug"].InnerText, intForce, 0)); objCharacter.MAG.AssignLimits(ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["magmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["magaug"].InnerText, intForce, 0)); objCharacter.RES.AssignLimits(ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["resmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["resaug"].InnerText, intForce, 0)); objCharacter.EDG.AssignLimits(ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["edgmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["edgaug"].InnerText, intForce, 0)); objCharacter.ESS.AssignLimits(ExpressionToString(objXmlMetatype["essmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essaug"].InnerText, intForce, 0)); } else { int intMinModifier = -3; objCharacter.BOD.AssignLimits(ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 3)); objCharacter.AGI.AssignLimits(ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 3)); objCharacter.REA.AssignLimits(ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 3)); objCharacter.STR.AssignLimits(ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 3)); objCharacter.CHA.AssignLimits(ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 3)); objCharacter.INT.AssignLimits(ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 3)); objCharacter.LOG.AssignLimits(ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 3)); objCharacter.WIL.AssignLimits(ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 3)); objCharacter.MAG.AssignLimits(ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 3)); objCharacter.RES.AssignLimits(ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 3)); objCharacter.EDG.AssignLimits(ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, intMinModifier), ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 3), ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 3)); objCharacter.ESS.AssignLimits(ExpressionToString(objXmlMetatype["essmin"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essmax"].InnerText, intForce, 0), ExpressionToString(objXmlMetatype["essaug"].InnerText, intForce, 0)); } // If we're working with a Critter, set the Attributes to their default values. objCharacter.BOD.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["bodmin"].InnerText, intForce, 0)); objCharacter.AGI.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["agimin"].InnerText, intForce, 0)); objCharacter.REA.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["reamin"].InnerText, intForce, 0)); objCharacter.STR.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["strmin"].InnerText, intForce, 0)); objCharacter.CHA.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["chamin"].InnerText, intForce, 0)); objCharacter.INT.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["intmin"].InnerText, intForce, 0)); objCharacter.LOG.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["logmin"].InnerText, intForce, 0)); objCharacter.WIL.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["wilmin"].InnerText, intForce, 0)); objCharacter.MAG.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["magmin"].InnerText, intForce, 0)); objCharacter.RES.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["resmin"].InnerText, intForce, 0)); objCharacter.EDG.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["edgmin"].InnerText, intForce, 0)); objCharacter.ESS.MetatypeMinimum = Convert.ToInt32(ExpressionToString(objXmlMetatype["essmax"].InnerText, intForce, 0)); // Sprites can never have Physical Attributes or WIL. if (objXmlMetatype["category"].InnerText.EndsWith("Sprite")) { 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.WIL.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 = XmlManager.Instance.Load("qualities.xml"); // Determine if the Metatype has any bonuses. if (objXmlMetatype.InnerXml.Contains("bonus")) { objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Metatype, strCritterName, objXmlMetatype.SelectSingleNode("bonus"), false, 1, strCritterName); } // Create the Qualities that come with the Metatype. foreach (XmlNode objXmlQualityItem in objXmlMetatype.SelectNodes("qualities/positive/quality")) { XmlNode objXmlQuality = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQualityItem.InnerText + "\"]"); TreeNode objNode = new TreeNode(); List <Weapon> objWeapons = new List <Weapon>(); List <TreeNode> objWeaponNodes = new List <TreeNode>(); Quality objQuality = new Quality(objCharacter); string strForceValue = string.Empty; if (objXmlQualityItem.Attributes["select"] != null) { strForceValue = objXmlQualityItem.Attributes["select"].InnerText; } QualitySource objSource = new QualitySource(); objSource = QualitySource.Metatype; if (objXmlQualityItem.Attributes["removable"] != null) { objSource = QualitySource.MetatypeRemovable; } objQuality.Create(objXmlQuality, objCharacter, objSource, objNode, objWeapons, objWeaponNodes, strForceValue); objCharacter.Qualities.Add(objQuality); // Add any created Weapons to the character. foreach (Weapon objWeapon in objWeapons) { objCharacter.Weapons.Add(objWeapon); } } foreach (XmlNode objXmlQualityItem in objXmlMetatype.SelectNodes("qualities/negative/quality")) { XmlNode objXmlQuality = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQualityItem.InnerText + "\"]"); TreeNode objNode = new TreeNode(); List <Weapon> objWeapons = new List <Weapon>(); List <TreeNode> objWeaponNodes = new List <TreeNode>(); Quality objQuality = new Quality(objCharacter); string strForceValue = string.Empty; if (objXmlQualityItem.Attributes["select"] != null) { strForceValue = objXmlQualityItem.Attributes["select"].InnerText; } QualitySource objSource = new QualitySource(); objSource = QualitySource.Metatype; if (objXmlQualityItem.Attributes["removable"] != null) { objSource = QualitySource.MetatypeRemovable; } objQuality.Create(objXmlQuality, objCharacter, objSource, objNode, objWeapons, objWeaponNodes, strForceValue); objCharacter.Qualities.Add(objQuality); // Add any created Weapons to the character. foreach (Weapon objWeapon in objWeapons) { objCharacter.Weapons.Add(objWeapon); } } // Add any Critter Powers the Metatype/Critter should have. XmlNode objXmlCritter = objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + objCharacter.Metatype + "\"]"); objXmlDocument = XmlManager.Instance.Load("critterpowers.xml"); foreach (XmlNode objXmlPower in objXmlCritter.SelectNodes("powers/power")) { XmlNode objXmlCritterPower = objXmlDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower.InnerText + "\"]"); TreeNode objNode = new TreeNode(); CritterPower objPower = new CritterPower(objCharacter); string strForcedValue = string.Empty; int intRating = 0; if (objXmlPower.Attributes["rating"] != null) { intRating = Convert.ToInt32(objXmlPower.Attributes["rating"].InnerText); } if (objXmlPower.Attributes["select"] != null) { strForcedValue = objXmlPower.Attributes["select"].InnerText; } objPower.Create(objXmlCritterPower, objCharacter, objNode, 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(); 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); objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Metatype, objCharacter.Metatype, bonusNode, false, 1, objCharacter.Metatype); } } // Add any Complex Forms the Critter comes with (typically Sprites) XmlDocument objXmlProgramDocument = XmlManager.Instance.Load("complexforms.xml"); foreach (XmlNode objXmlComplexForm in objXmlCritter.SelectNodes("complexforms/complexform")) { string strForceValue = string.Empty; if (objXmlComplexForm.Attributes["select"] != null) { strForceValue = objXmlComplexForm.Attributes["select"].InnerText; } XmlNode objXmlProgram = objXmlProgramDocument.SelectSingleNode("/chummer/complexforms/complexform[name = \"" + objXmlComplexForm.InnerText + "\"]"); TreeNode objNode = new TreeNode(); ComplexForm objProgram = new ComplexForm(objCharacter); objProgram.Create(objXmlProgram, objCharacter, objNode, strForceValue); objCharacter.ComplexForms.Add(objProgram); } // Add any Gear the Critter comes with (typically Programs for A.I.s) XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlCritter.SelectNodes("gears/gear")) { int intRating = 0; if (objXmlGear.Attributes["rating"] != null) { intRating = Convert.ToInt32(ExpressionToString(objXmlGear.Attributes["rating"].InnerText, Convert.ToInt32(nudForce.Value), 0)); } string strForceValue = string.Empty; if (objXmlGear.Attributes["select"] != null) { strForceValue = objXmlGear.Attributes["select"].InnerText; } XmlNode objXmlGearItem = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlGear.InnerText + "\"]"); TreeNode objNode = new TreeNode(); Gear objGear = new Gear(objCharacter); List <Weapon> lstWeapons = new List <Weapon>(); List <TreeNode> lstWeaponNodes = new List <TreeNode>(); objGear.Create(objXmlGearItem, objCharacter, objNode, intRating, lstWeapons, lstWeaponNodes, strForceValue); objGear.Cost = "0"; objGear.Cost3 = "0"; objGear.Cost6 = "0"; objGear.Cost10 = "0"; objCharacter.Gear.Add(objGear); } // Add the Unarmed Attack Weapon to the character. objXmlDocument = XmlManager.Instance.Load("weapons.xml"); XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"Unarmed Attack\"]"); if (objXmlWeapon != null) { TreeNode objDummy = new TreeNode(); Weapon objWeapon = new Weapon(objCharacter); objWeapon.Create(objXmlWeapon, objCharacter, objDummy, null, null); objCharacter.Weapons.Add(objWeapon); } objCharacter.Alias = strCritterName; objCharacter.Created = true; objCharacter.Save(); string strOpenFile = objCharacter.FileName; objCharacter = null; // Link the newly-created Critter to the Spirit. _objSpirit.FileName = strOpenFile; if (_objSpirit.EntityType == SpiritType.Spirit) { tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Spirit_OpenFile")); } else { tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Sprite_OpenFile")); } FileNameChanged(this); GlobalOptions.Instance.MainForm.LoadCharacter(strOpenFile, true); }
/// <summary> /// Calculate the LP value for the selected items. /// </summary> private decimal CalculateValues(bool blnIncludePercentage = true) { if (_blnSkipRefresh) { return(0); } decimal decBaseCost = 0; decimal decCost = 0; decimal baseMultiplier = 0; // Get the base cost of the lifestyle XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboLifestyle.SelectedValue + "\"]"); decBaseCost += Convert.ToDecimal(objXmlAspect["cost"].InnerText, GlobalOptions.InvariantCultureInfo); lblSource.Text = objXmlAspect["source"].InnerText + " " + objXmlAspect["page"].InnerText; // Add the flat costs from qualities foreach (TreeNode objNode in treQualities.Nodes) { if (objNode.Checked) { XmlNode objXmlQuality = _objXmlDocument.SelectSingleNode($"/chummer/qualities/quality[id = \"{objNode.Tag}\"]"); if (!string.IsNullOrEmpty(objXmlQuality["cost"]?.InnerText)) { if (!decimal.TryParse(objXmlQuality["cost"].InnerText, NumberStyles.Any, GlobalOptions.InvariantCultureInfo, out decimal decLoopCost)) { try { decLoopCost = Convert.ToDecimal(CommonFunctions.EvaluateInvariantXPath(objXmlQuality["cost"].InnerText), GlobalOptions.InvariantCultureInfo); } catch (XPathException) { decLoopCost = 0.0m; } } decCost += decLoopCost; } } } decimal decMod = 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 (!string.IsNullOrEmpty(objXmlAspect?["multiplier"]?.InnerText)) { decMod += Convert.ToDecimal(objXmlAspect["multiplier"].InnerText, GlobalOptions.InvariantCultureInfo) / 100.0m; } if (!string.IsNullOrEmpty(objXmlAspect?["multiplierbaseonly"]?.InnerText)) { baseMultiplier += Convert.ToDecimal(objXmlAspect["multiplierbaseonly"].InnerText, 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 * baseMultiplier; 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 += " (" + decDiscount.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥' + ")"; } return(decNuyen); }
/// <summary> /// Update the Modified Rating shown. /// </summary> public void RefreshControl() { bool blnSkillsoft = false; ImprovementManager objImprovementManager = new ImprovementManager(_objSkill.CharacterObject); int intRating = _objSkill.TotalRating; lblModifiedRating.Text = intRating.ToString(); int intSkillRating = _objSkill.Rating; foreach (Gear objGear in _objSkill.CharacterObject.Gear) { // Look for any Skillsoft that would conflict with the Skill's Rating. if (objGear.Equipped && objGear.Category == "Skillsofts" && (objGear.Extra == _objSkill.Name || objGear.Extra == _objSkill.Name + ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked"))) { if (objGear.Rating > _objSkill.Rating) { // Use the Skillsoft's Rating or Skillwire Rating, whichever is lower. // If this is a Knowsoft or Linguasoft, it is not limited to the Skillwire Rating. if (objGear.Name == "Activesoft") { intSkillRating = Math.Min(objGear.Rating, objImprovementManager.ValueOf(Improvement.ImprovementType.Skillwire)); } else { intSkillRating = objGear.Rating; } blnSkillsoft = true; break; } } foreach (Gear objChild in objGear.Children) { if (objChild.Equipped && objChild.Category == "Skillsofts" && (objChild.Extra == _objSkill.Name || objChild.Extra == _objSkill.Name + ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked"))) { if (objChild.Rating > _objSkill.Rating) { // Use the Skillsoft's Rating or Skillwire Rating, whichever is lower. // If this is a Knowsoft or Linguasoft, it is not limited to the Skillwire Rating. if (objChild.Name == "Activesoft") { intSkillRating = Math.Min(objChild.Rating, objImprovementManager.ValueOf(Improvement.ImprovementType.Skillwire)); } else { intSkillRating = objChild.Rating; } blnSkillsoft = true; break; } } } } if (_objSkill.FreeLevels > 0) { nudSkill.Minimum = _objSkill.FreeLevels; } else { nudSkill.Minimum = 0; } if (cboSpec.Text != "" && !_objSkill.ExoticSkill) { bool blnFound = false; if (this.SkillName == "Artisan") { // Look for the Inspired quality to see if we get a free specialization foreach (Quality objQuality in _objSkill.CharacterObject.Qualities) { if (objQuality.Name == "Inspired") { blnFound = true; } } } if (!blnFound) { lblModifiedRating.Text += " (" + (intRating + 2).ToString() + ")"; } else { lblModifiedRating.Text += " (" + (intRating + 3).ToString() + ")"; } } lblAttribute.Text = _objSkill.DisplayAttribute; // Build the Tooltip. string strTooltip = ""; if (blnSkillsoft) { strTooltip += LanguageManager.Instance.GetString("Tip_Skill_SkillsoftRating") + " (" + intSkillRating.ToString() + ")"; } else { strTooltip += LanguageManager.Instance.GetString("Tip_Skill_SkillRating") + " (" + _objSkill.Rating.ToString() + ")"; } if (_objSkill.Default && intSkillRating == 0) { strTooltip += " - " + LanguageManager.Instance.GetString("Tip_Skill_Defaulting") + " (1)"; } if ((!_objSkill.Default && intSkillRating > 0) || _objSkill.Default) { strTooltip += " + " + LanguageManager.Instance.GetString("String_Attribute" + _objSkill.Attribute + "Short") + " (" + _objSkill.AttributeModifiers.ToString() + ")"; } // Modifiers only apply when not Defaulting. if (intSkillRating > 0 || _objSkill.CharacterObject.Options.SkillDefaultingIncludesModifiers) { if (_objSkill.RatingModifiers != 0) { if (_objSkill.CharacterObject.Options.EnforceMaximumSkillRatingModifier) { int intModifier = _objSkill.RatingModifiers; if (intModifier > Convert.ToInt32(Math.Floor(Convert.ToDouble(intSkillRating, GlobalOptions.Instance.CultureInfo) * 0.5))) { int intMax = intModifier; intModifier = Convert.ToInt32(Math.Floor(Convert.ToDouble(intSkillRating, GlobalOptions.Instance.CultureInfo) * 0.5)); if (intModifier != 0) { strTooltip += " + " + LanguageManager.Instance.GetString("Tip_Skill_RatingModifiers") + " (" + intModifier.ToString() + " " + LanguageManager.Instance.GetString("String_Of") + " " + intMax.ToString() + ")"; } else { strTooltip += " + " + LanguageManager.Instance.GetString("Tip_Skill_RatingModifiers") + " (0 " + LanguageManager.Instance.GetString("String_Of") + " " + intMax.ToString() + ")"; } } else { strTooltip += " + " + LanguageManager.Instance.GetString("Tip_Skill_RatingModifiers") + " (" + _objSkill.RatingModifiers.ToString() + ")"; } } else { strTooltip += " + " + LanguageManager.Instance.GetString("Tip_Skill_RatingModifiers") + " (" + _objSkill.RatingModifiers.ToString() + ")"; } } // Dice Pool Modifiers. strTooltip += _objSkill.DicePoolModifiersTooltip; } if (_objSkill.SkillCategory == "Language" && _objSkill.KnowledgeSkill && intSkillRating == 0) { lblModifiedRating.Text = "N"; strTooltip = LanguageManager.Instance.GetString("Tip_Skill_NativeLanguage"); } // Condition Monitor Modifiers. if (objImprovementManager.ValueOf(Improvement.ImprovementType.ConditionMonitor) < 0) { strTooltip += " + " + LanguageManager.Instance.GetString("Tip_Skill_Wounds") + " (" + objImprovementManager.ValueOf(Improvement.ImprovementType.ConditionMonitor).ToString() + ")"; } tipTooltip.SetToolTip(lblModifiedRating, strTooltip); if (_objSkill.Rating > 0 && !_objSkill.KnowledgeSkill) { this.BackColor = SystemColors.ButtonHighlight; //lblSkillName.Font = new Font(lblSkillName.Font, FontStyle.Bold); lblModifiedRating.Font = new Font(lblModifiedRating.Font, FontStyle.Bold); } else { this.BackColor = SystemColors.Control; //lblSkillName.Font = new Font(lblSkillName.Font, FontStyle.Regular); lblModifiedRating.Font = new Font(lblModifiedRating.Font, FontStyle.Regular); } // Specializations should not be enabled for Active Skills in Create Mode if their Rating is 0. if (!_objSkill.KnowledgeSkill && !_objSkill.ExoticSkill && !_objSkill.CharacterObject.Created) { if (_objSkill.Rating > 0 && !_objSkill.IsGrouped) { cboSpec.Enabled = true; } else { cboSpec.Enabled = false; cboSpec.Text = ""; } } if (!_objSkill.KnowledgeSkill && !_objSkill.ExoticSkill && _objSkill.CharacterObject.Created) { if (_objSkill.Rating > 0) { cmdChangeSpec.Enabled = true; } else { cmdChangeSpec.Enabled = false; } } if (_objSkill.CharacterObject.Created) { lblSkillRating.Text = _objSkill.Rating.ToString(); // Enable or disable the Improve Skill button as necessary. if (_objSkill.Rating < _objSkill.RatingMaximum) { cmdImproveSkill.Enabled = true; } else { cmdImproveSkill.Enabled = false; } } }
/// Create a Commlink from an XmlNode and return the TreeNodes for it. /// <param name="objXmlGear">XmlNode to create the object from.</param> /// <param name="objCharacter">Character the Gear is being added to.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="intRating">Gear Rating.</param> /// <param name="blnAddImprovements">Whether or not Improvements should be added to the character.</param> /// <param name="blnCreateChildren">Whether or not child Gear should be created.</param> public void Create(XmlNode objXmlGear, Character objCharacter, TreeNode objNode, int intRating, bool blnAddImprovements = true, bool blnCreateChildren = true) { _strName = objXmlGear["name"].InnerText; _strCategory = objXmlGear["category"].InnerText; _strAvail = objXmlGear["avail"].InnerText; objXmlGear.TryGetField("cost", out _strCost); objXmlGear.TryGetField("cost3", out _strCost3, ""); objXmlGear.TryGetField("cost6", out _strCost6, ""); objXmlGear.TryGetField("cost10", out _strCost10, ""); objXmlGear.TryGetField("armorcapacity", out _strArmorCapacity); _nodBonus = objXmlGear["bonus"]; _intMaxRating = Convert.ToInt32(objXmlGear["rating"].InnerText); _intRating = intRating; _strSource = objXmlGear["source"].InnerText; _strPage = objXmlGear["page"].InnerText; _intDeviceRating = Convert.ToInt32(objXmlGear["devicerating"].InnerText); _intAttack = Convert.ToInt32(objXmlGear["attack"].InnerText); _intSleaze= Convert.ToInt32(objXmlGear["sleaze"].InnerText); _intDataProcessing = Convert.ToInt32(objXmlGear["dataprocessing"].InnerText); _intFirewall = Convert.ToInt32(objXmlGear["firewall"].InnerText); if (GlobalOptions.Instance.Language != "en-us") { XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml"); XmlNode objGearNode = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + _strName + "\"]"); if (objGearNode != null) { if (objGearNode["translate"] != null) _strAltName = objGearNode["translate"].InnerText; if (objGearNode["altpage"] != null) _strAltPage = objGearNode["altpage"].InnerText; } if (_strAltName.StartsWith("Stacked Focus")) _strAltName = _strAltName.Replace("Stacked Focus", LanguageManager.Instance.GetString("String_StackedFocus")); objGearNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]"); if (objGearNode != null) { if (objGearNode.Attributes["translate"] != null) _strAltCategory = objGearNode.Attributes["translate"].InnerText; } if (_strAltCategory.StartsWith("Stacked Focus")) _strAltCategory = _strAltCategory.Replace("Stacked Focus", LanguageManager.Instance.GetString("String_StackedFocus")); } string strSource = _guiID.ToString(); objNode.Text = DisplayNameShort; objNode.Tag = _guiID.ToString(); // If the item grants a bonus, pass the information to the Improvement Manager. if (objXmlGear["bonus"] != null) { ImprovementManager objImprovementManager; if (blnAddImprovements) objImprovementManager = new ImprovementManager(objCharacter); else objImprovementManager = new ImprovementManager(null); if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Gear, strSource, objXmlGear["bonus"], false, 1, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (objImprovementManager.SelectedValue != "") { _strExtra = objImprovementManager.SelectedValue; objNode.Text += " (" + objImprovementManager.SelectedValue + ")"; } } // Check to see if there are any child elements. if (objXmlGear.InnerXml.Contains("<gears>") && blnCreateChildren) { // Create Gear using whatever information we're given. foreach (XmlNode objXmlChild in objXmlGear.SelectNodes("gears/gear")) { Gear objChild = new Gear(_objCharacter); TreeNode objChildNode = new TreeNode(); objChild.Name = objXmlChild["name"].InnerText; objChild.Category = objXmlChild["category"].InnerText; objChild.Avail = "0"; objChild.Cost = "0"; objChild.Source = _strSource; objChild.Page = _strPage; objChild.Parent = this; _objChildren.Add(objChild); objChildNode.Text = objChild.DisplayName; objChildNode.Tag = objChild.InternalId; objNode.Nodes.Add(objChildNode); objNode.Expand(); } XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); CreateChildren(objXmlGearDocument, objXmlGear, this, objNode, objCharacter, blnCreateChildren); } // Add the Copy Protection and Registration plugins to the Matrix program. This does not apply if Unwired is not enabled, Hacked is selected, or this is a Suite being added (individual programs will add it to themselves). if (blnCreateChildren) { if ((_strCategory == "Matrix Programs" || _strCategory == "Skillsofts" || _strCategory == "Autosofts" || _strCategory == "Autosofts, Agent" || _strCategory == "Autosofts, Drone") && objCharacter.Options.BookEnabled("UN") && !_strName.StartsWith("Suite:")) { XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml"); if (_objCharacter.Options.AutomaticCopyProtection) { Gear objPlugin1 = new Gear(_objCharacter); TreeNode objPlugin1Node = new TreeNode(); objPlugin1.Create(objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"Copy Protection\"]"), objCharacter, objPlugin1Node, _intRating, null, null); if (_intRating == 0) objPlugin1.Rating = 1; objPlugin1.Avail = "0"; objPlugin1.Cost = "0"; objPlugin1.Cost3 = "0"; objPlugin1.Cost6 = "0"; objPlugin1.Cost10 = "0"; objPlugin1.Capacity = "[0]"; objPlugin1.Parent = this; _objChildren.Add(objPlugin1); objNode.Nodes.Add(objPlugin1Node); } if (_objCharacter.Options.AutomaticRegistration) { Gear objPlugin2 = new Gear(_objCharacter); TreeNode objPlugin2Node = new TreeNode(); objPlugin2.Create(objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"Registration\"]"), objCharacter, objPlugin2Node, 0, null, null); objPlugin2.Avail = "0"; objPlugin2.Cost = "0"; objPlugin2.Cost3 = "0"; objPlugin2.Cost6 = "0"; objPlugin2.Cost10 = "0"; objPlugin2.Capacity = "[0]"; objPlugin2.Parent = this; _objChildren.Add(objPlugin2); objNode.Nodes.Add(objPlugin2Node); objNode.Expand(); } if ((objCharacter.Metatype == "A.I." || objCharacter.MetatypeCategory == "Technocritters" || objCharacter.MetatypeCategory == "Protosapients")) { Gear objPlugin3 = new Gear(_objCharacter); TreeNode objPlugin3Node = new TreeNode(); objPlugin3.Create(objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"Ergonomic\"]"), objCharacter, objPlugin3Node, 0, null, null); objPlugin3.Avail = "0"; objPlugin3.Cost = "0"; objPlugin3.Cost3 = "0"; objPlugin3.Cost6 = "0"; objPlugin3.Cost10 = "0"; objPlugin3.Capacity = "[0]"; objPlugin3.Parent = this; _objChildren.Add(objPlugin3); objNode.Nodes.Add(objPlugin3Node); Gear objPlugin4 = new Gear(_objCharacter); TreeNode objPlugin4Node = new TreeNode(); objPlugin4.Create(objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"Optimization\" and category = \"Program Options\"]"), objCharacter, objPlugin4Node, _intRating, null, null); if (_intRating == 0) objPlugin4.Rating = 1; objPlugin4.Avail = "0"; objPlugin4.Cost = "0"; objPlugin4.Cost3 = "0"; objPlugin4.Cost6 = "0"; objPlugin4.Cost10 = "0"; objPlugin4.Capacity = "[0]"; objPlugin4.Parent = this; _objChildren.Add(objPlugin4); objNode.Nodes.Add(objPlugin4Node); objNode.Expand(); } } } }
private void SkillControl_Load(object sender, EventArgs e) { if (_objSkill.CharacterObject.BuildMethod == CharacterBuildMethod.Karma) { nudSkill.Enabled = false; nudSkill.Visible = false; } _blnSkipRefresh = true; if (_objSkill.KnowledgeSkill) { cboSkillName.Text = _objSkill.Name; } if (_objSkill.CharacterObject.Created) { string strTooltip = ""; int intNewRating = _objSkill.Rating + 1; int intKarmaCost = 0; chkKarma.Visible = false; if (_objSkill.Rating < _objSkill.RatingMaximum) { if (KnowledgeSkill == false) { if (_objSkill.Rating == 0) { intKarmaCost = _objSkill.CharacterObject.Options.KarmaNewActiveSkill; } else { intKarmaCost = (_objSkill.Rating + 1) * _objSkill.CharacterObject.Options.KarmaImproveActiveSkill; } } else { if (_objSkill.Rating == 0) { intKarmaCost = _objSkill.CharacterObject.Options.KarmaNewKnowledgeSkill; } else { intKarmaCost = (_objSkill.Rating + 1) * _objSkill.CharacterObject.Options.KarmaImproveKnowledgeSkill; } } // Double the Karma cost if the character is Uneducated and is a Technical Active, Academic, or Professional Skill. if (_objSkill.CharacterObject.Uneducated && (SkillCategory == "Technical Active" || SkillCategory == "Academic" || SkillCategory == "Professional")) { intKarmaCost *= 2; } //Double the Karma cost if the character is Uncouth and is a Social Active Skill. if (_objSkill.CharacterObject.Uncouth && (SkillCategory == "Social Active")) { intKarmaCost *= 2; } strTooltip = LanguageManager.Instance.GetString("Tip_ImproveItem").Replace("{0}", intNewRating.ToString()).Replace("{1}", intKarmaCost.ToString()); tipTooltip.SetToolTip(cmdImproveSkill, strTooltip); } ImprovementManager objImprovementManager = new ImprovementManager(_objSkill.CharacterObject); if (objImprovementManager.ValueOf(Improvement.ImprovementType.AdeptLinguistics) > 0 && SkillCategory == "Language" && SkillRating == 0) { strTooltip = LanguageManager.Instance.GetString("Tip_ImproveItem").Replace("{0}", "1").Replace("{1}", "0"); } tipTooltip.SetToolTip(cmdImproveSkill, strTooltip); nudSkill.Visible = false; nudKarma.Visible = false; lblSkillRating.Visible = true; cmdImproveSkill.Visible = true; if (_objSkill.FreeLevels > 0) { nudSkill.Minimum = _objSkill.FreeLevels; } else { nudSkill.Minimum = 0; } // Show the Dice Rolling button if the option is enabled. if (_objSkill.CharacterObject.Options.AllowSkillDiceRolling) { cmdRoll.Visible = true; this.Width += 30; cboSpec.Left += 30; lblSpec.Left += 30; cmdChangeSpec.Left += 30; cboKnowledgeSkillCategory.Left += 30; cmdDelete.Left += 30; tipTooltip.SetToolTip(cmdRoll, LanguageManager.Instance.GetString("Tip_DiceRoller")); } if (!_objSkill.ExoticSkill) { cboSpec.Visible = false; lblSpec.Visible = true; lblSpec.Text = _objSkill.Specialization; cmdChangeSpec.Visible = true; cboSpec.Enabled = false; } else { cboSpec.Text = _objSkill.Specialization; } string strTip = LanguageManager.Instance.GetString("Tip_Skill_AddSpecialization").Replace("{0}", _objSkill.CharacterObject.Options.KarmaSpecialization.ToString()); tipTooltip.SetToolTip(cmdChangeSpec, strTip); } if (KnowledgeSkill) { this.Width = cmdDelete.Left + cmdDelete.Width; } else { this.Width = cmdChangeSpec.Left + cmdChangeSpec.Width; } if (!_objSkill.CharacterObject.Created && _objSkill.SkillGroupObject != null && _objSkill.SkillGroupObject.Broken) { if (!_objSkill.CharacterObject.Options.UsePointsOnBrokenGroups) { nudSkill.Enabled = false; } cmdBreakGroup.Visible = false; } this.Height = lblSpec.Height + 10; chkKarma.Checked = _objSkill.BuyWithKarma; lblAttribute.Text = _objSkill.DisplayAttribute; RefreshControl(); _blnSkipRefresh = false; }
/// <summary> /// Calculate the LP value for the selected items. /// </summary> private int CalculateValues(bool blnIncludePercentage = true) { if (_blnSkipRefresh) { return(0); } decimal decBaseCost = 0; decimal decCost = 0; decimal baseMultiplier = 0; // Get the base cost of the lifestyle XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboLifestyle.SelectedValue + "\"]"); decBaseCost += Convert.ToDecimal(objXmlAspect["cost"].InnerText); lblSource.Text = objXmlAspect["source"].InnerText + " " + objXmlAspect["page"].InnerText; // Add the flat costs from qualities foreach (TreeNode objNode in treQualities.Nodes) { if (objNode.Checked) { XmlNode objXmlQuality = _objXmlDocument.SelectSingleNode($"/chummer/qualities/quality[id = \"{objNode.Tag}\"]"); if (!string.IsNullOrEmpty(objXmlQuality["cost"]?.InnerText)) { decCost += Convert.ToDecimal(objXmlQuality["cost"].InnerText); } } } decimal decMod = 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 (!string.IsNullOrEmpty(objXmlAspect?["multiplier"]?.InnerText)) { decMod += Convert.ToDecimal(objXmlAspect?["multiplier"]?.InnerText) / 100; } if (!string.IsNullOrEmpty(objXmlAspect?["multiplierbaseonly"]?.InnerText)) { baseMultiplier += Convert.ToDecimal(objXmlAspect?["multiplierbaseonly"]?.InnerText) / 100; } } // Check for modifiers in the improvements ImprovementManager objImprovementManager = new ImprovementManager(_objCharacter); decimal decModifier = Convert.ToDecimal(objImprovementManager.ValueOf(Improvement.ImprovementType.LifestyleCost), GlobalOptions.InvariantCultureInfo); decMod += decModifier / 100; } decBaseCost += decBaseCost * baseMultiplier; decimal decNuyen = decBaseCost + decBaseCost * decMod + decCost; if (nudPercentage.Value != 100) { decimal decDiscount = decNuyen; decDiscount = decDiscount * (nudPercentage.Value / 100); lblCost.Text += " (" + $"{Convert.ToInt32(decDiscount):###,###,##0¥}" + ")"; } int intNuyen = Convert.ToInt32(decNuyen); lblCost.Text = $"{intNuyen:###,###,##0¥}"; return(intNuyen); }
/// Create a Armor Modification from an XmlNode. /// <param name="objXmlArmorNode">XmlNode to create the object from.</param> /// <param name="intRating">Rating of the selected ArmorMod.</param> /// <param name="lstWeapons">List of Weapons that are created by the Armor.</param> /// <param name="blnSkipCost">Whether or not creating the ArmorMod should skip the Variable price dialogue (should only be used by frmSelectArmor).</param> /// <param name="blnSkipSelectForms">Whether or not to skip selection forms (related to improvements) when creating this ArmorMod.</param> public void Create(XmlNode objXmlArmorNode, int intRating, List <Weapon> lstWeapons, bool blnSkipCost = false, bool blnSkipSelectForms = false) { if (objXmlArmorNode.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } objXmlArmorNode.TryGetStringFieldQuickly("category", ref _strCategory); objXmlArmorNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity); objXmlArmorNode.TryGetStringFieldQuickly("gearcapacity", ref _strGearCapacity); _intRating = intRating; objXmlArmorNode.TryGetInt32FieldQuickly("armor", ref _intArmorValue); objXmlArmorNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating); objXmlArmorNode.TryGetStringFieldQuickly("avail", ref _strAvail); objXmlArmorNode.TryGetStringFieldQuickly("source", ref _strSource); objXmlArmorNode.TryGetStringFieldQuickly("page", ref _strPage); if (!objXmlArmorNode.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objXmlArmorNode.TryGetStringFieldQuickly("notes", ref _strNotes); } _nodBonus = objXmlArmorNode["bonus"]; _nodWirelessBonus = objXmlArmorNode["wirelessbonus"]; _blnWirelessOn = _nodWirelessBonus != null; objXmlArmorNode.TryGetStringFieldQuickly("cost", ref _strCost); // Check for a Variable Cost. if (!blnSkipCost && _strCost.StartsWith("Variable(")) { string strFirstHalf = _strCost.TrimStart("Variable(", true).TrimEnd(')'); string strSecondHalf = string.Empty; int intHyphenIndex = strFirstHalf.IndexOf('-'); if (intHyphenIndex != -1) { if (intHyphenIndex + 1 < strFirstHalf.Length) { strSecondHalf = strFirstHalf.Substring(intHyphenIndex + 1); } strFirstHalf = strFirstHalf.Substring(0, intHyphenIndex); } if (!blnSkipSelectForms) { decimal decMin; decimal decMax = decimal.MaxValue; if (intHyphenIndex != -1) { decMin = Convert.ToDecimal(strFirstHalf, GlobalOptions.InvariantCultureInfo); decMax = Convert.ToDecimal(strSecondHalf, GlobalOptions.InvariantCultureInfo); } else { decMin = Convert.ToDecimal(strFirstHalf.FastEscape('+'), GlobalOptions.InvariantCultureInfo); } if (decMin != decimal.MinValue || decMax != decimal.MaxValue) { string strNuyenFormat = _objCharacter.Options.NuyenFormat; int intDecimalPlaces = strNuyenFormat.IndexOf('.'); if (intDecimalPlaces == -1) { intDecimalPlaces = 0; } else { intDecimalPlaces = strNuyenFormat.Length - intDecimalPlaces - 1; } frmSelectNumber frmPickNumber = new frmSelectNumber(intDecimalPlaces); if (decMax > 1000000) { decMax = 1000000; } frmPickNumber.Minimum = decMin; frmPickNumber.Maximum = decMax; frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost", GlobalOptions.Language).Replace("{0}", DisplayNameShort(GlobalOptions.Language)); frmPickNumber.AllowCancel = false; frmPickNumber.ShowDialog(); _strCost = frmPickNumber.SelectedValue.ToString(GlobalOptions.InvariantCultureInfo); } else { _strCost = strFirstHalf; } } else { _strCost = strFirstHalf; } } if (objXmlArmorNode["bonus"] != null && !blnSkipSelectForms) { if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.ArmorMod, _guiID.ToString("D"), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; } } // Add any Gear that comes with the Armor. XmlNode xmlChildrenNode = objXmlArmorNode["gears"]; if (xmlChildrenNode != null) { XmlDocument objXmlGearDocument = XmlManager.Load("gear.xml"); using (XmlNodeList xmlUseGearList = xmlChildrenNode.SelectNodes("usegear")) if (xmlUseGearList != null) { foreach (XmlNode objXmlArmorGear in xmlUseGearList) { intRating = 0; string strForceValue = string.Empty; objXmlArmorGear.TryGetInt32FieldQuickly("rating", ref intRating); objXmlArmorGear.TryGetStringFieldQuickly("select", ref strForceValue); XmlNode objXmlGear = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlArmorGear.InnerText + "\"]"); Gear objGear = new Gear(_objCharacter); objGear.Create(objXmlGear, intRating, lstWeapons, strForceValue, !blnSkipSelectForms); objGear.Capacity = "[0]"; objGear.ArmorCapacity = "[0]"; objGear.Cost = "0"; objGear.MaxRating = objGear.Rating; objGear.MinRating = objGear.Rating; objGear.ParentID = InternalId; _lstGear.Add(objGear); } } } // Add Weapons if applicable. if (objXmlArmorNode.InnerXml.Contains("<addweapon>")) { XmlDocument objXmlWeaponDocument = XmlManager.Load("weapons.xml"); // More than one Weapon can be added, so loop through all occurrences. using (XmlNodeList xmlAddWeaponList = objXmlArmorNode.SelectNodes("addweapon")) if (xmlAddWeaponList != null) { foreach (XmlNode objXmlAddWeapon in xmlAddWeaponList) { string strLoopID = objXmlAddWeapon.InnerText; XmlNode objXmlWeapon = strLoopID.IsGuid() ? objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + strLoopID + "\"]") : objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + strLoopID + "\"]"); Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Create(objXmlWeapon, lstWeapons, true, !blnSkipSelectForms, blnSkipCost); objGearWeapon.ParentID = InternalId; objGearWeapon.Cost = "0"; lstWeapons.Add(objGearWeapon); Guid.TryParse(objGearWeapon.InternalId, out _guiWeaponID); } } } }
/// <summary> /// Create a Quality from an XmlNode. /// </summary> /// <param name="objXmlQuality">XmlNode to create the object from.</param> /// <param name="objQualitySource">Source of the Quality.</param> /// <param name="lstWeapons">List of Weapons that should be added to the Character.</param> /// <param name="strForceValue">Force a value to be selected for the Quality.</param> /// <param name="strSourceName">Friendly name for the improvement that added this quality.</param> public void Create(XmlNode objXmlQuality, QualitySource objQualitySource, IList <Weapon> lstWeapons, string strForceValue = "", string strSourceName = "") { _strSourceName = strSourceName; objXmlQuality.TryGetStringFieldQuickly("name", ref _strName); objXmlQuality.TryGetBoolFieldQuickly("metagenetic", ref _blnMetagenetic); if (!objXmlQuality.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objXmlQuality.TryGetStringFieldQuickly("notes", ref _strNotes); } objXmlQuality.TryGetInt32FieldQuickly("karma", ref _intBP); _eQualityType = ConvertToQualityType(objXmlQuality["category"]?.InnerText); _eQualitySource = objQualitySource; objXmlQuality.TryGetBoolFieldQuickly("doublecareer", ref _blnDoubleCostCareer); objXmlQuality.TryGetBoolFieldQuickly("canbuywithspellpoints", ref _blnCanBuyWithSpellPoints); objXmlQuality.TryGetBoolFieldQuickly("print", ref _blnPrint); objXmlQuality.TryGetBoolFieldQuickly("implemented", ref _blnImplemented); objXmlQuality.TryGetBoolFieldQuickly("contributetolimit", ref _blnContributeToLimit); objXmlQuality.TryGetStringFieldQuickly("source", ref _strSource); objXmlQuality.TryGetStringFieldQuickly("page", ref _strPage); _blnMutant = objXmlQuality["mutant"] != null; if (_eQualityType == QualityType.LifeModule) { objXmlQuality.TryGetStringFieldQuickly("stage", ref _strStage); } if (objXmlQuality.TryGetField("id", Guid.TryParse, out Guid guiTemp)) { _guiQualityId = guiTemp; _objCachedMyXmlNode = null; } // Add Weapons if applicable. // More than one Weapon can be added, so loop through all occurrences. using (XmlNodeList xmlAddWeaponList = objXmlQuality.SelectNodes("addweapon")) if (xmlAddWeaponList?.Count > 0) { XmlDocument objXmlWeaponDocument = XmlManager.Load("weapons.xml"); foreach (XmlNode objXmlAddWeapon in xmlAddWeaponList) { string strLoopID = objXmlAddWeapon.InnerText; XmlNode objXmlWeapon = strLoopID.IsGuid() ? objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + strLoopID + "\"]") : objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + strLoopID + "\"]"); Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Create(objXmlWeapon, lstWeapons); objGearWeapon.ParentID = InternalId; objGearWeapon.Cost = "0"; lstWeapons.Add(objGearWeapon); Guid.TryParse(objGearWeapon.InternalId, out _guiWeaponID); } } using (XmlNodeList xmlNaturalWeaponList = objXmlQuality.SelectNodes("naturalweapons/naturalweapon")) if (xmlNaturalWeaponList?.Count > 0) { foreach (XmlNode objXmlNaturalWeapon in xmlNaturalWeaponList) { Weapon objWeapon = new Weapon(_objCharacter); if (objXmlNaturalWeapon["name"] != null) { objWeapon.Name = objXmlNaturalWeapon["name"].InnerText; } objWeapon.Category = LanguageManager.GetString("Tab_Critter", GlobalOptions.Language); objWeapon.WeaponType = "Melee"; if (objXmlNaturalWeapon["reach"] != null) { objWeapon.Reach = Convert.ToInt32(objXmlNaturalWeapon["reach"].InnerText); } if (objXmlNaturalWeapon["accuracy"] != null) { objWeapon.Accuracy = objXmlNaturalWeapon["accuracy"].InnerText; } if (objXmlNaturalWeapon["damage"] != null) { objWeapon.Damage = objXmlNaturalWeapon["damage"].InnerText; } if (objXmlNaturalWeapon["ap"] != null) { objWeapon.AP = objXmlNaturalWeapon["ap"].InnerText; } objWeapon.Mode = "0"; objWeapon.RC = "0"; objWeapon.Concealability = 0; objWeapon.Avail = "0"; objWeapon.Cost = "0"; if (objXmlNaturalWeapon["useskill"] != null) { objWeapon.UseSkill = objXmlNaturalWeapon["useskill"].InnerText; } if (objXmlNaturalWeapon["source"] != null) { objWeapon.Source = objXmlNaturalWeapon["source"].InnerText; } if (objXmlNaturalWeapon["page"] != null) { objWeapon.Page = objXmlNaturalWeapon["page"].InnerText; } _objCharacter.Weapons.Add(objWeapon); } } _nodDiscounts = objXmlQuality["costdiscount"]; // If the item grants a bonus, pass the information to the Improvement Manager. _nodBonus = objXmlQuality["bonus"]; if (_nodBonus?.ChildNodes.Count > 0) { ImprovementManager.ForcedValue = strForceValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.Quality, InternalId, _nodBonus, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; } } else if (!string.IsNullOrEmpty(strForceValue)) { _strExtra = strForceValue; } _nodFirstLevelBonus = objXmlQuality["firstlevelbonus"]; if (_nodFirstLevelBonus?.ChildNodes.Count > 0 && Levels == 0) { ImprovementManager.ForcedValue = string.IsNullOrEmpty(strForceValue) ? Extra : strForceValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.Quality, InternalId, _nodFirstLevelBonus, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } } if (string.IsNullOrEmpty(Notes)) { string strEnglishNameOnPage = Name; string strNameOnPage = string.Empty; // make sure we have something and not just an empty tag if (objXmlQuality.TryGetStringFieldQuickly("nameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage)) { strEnglishNameOnPage = strNameOnPage; } string strQualityNotes = CommonFunctions.GetTextFromPDF($"{Source} {Page}", strEnglishNameOnPage); if (string.IsNullOrEmpty(strQualityNotes) && GlobalOptions.Language != GlobalOptions.DefaultLanguage) { string strTranslatedNameOnPage = DisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language); // don't check again it is not translated if (strTranslatedNameOnPage != _strName) { // if we found <altnameonpage>, and is not empty and not the same as english we must use that instead if (objXmlQuality.TryGetStringFieldQuickly("altnameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage) && strNameOnPage != strEnglishNameOnPage) { strTranslatedNameOnPage = strNameOnPage; } Notes = CommonFunctions.GetTextFromPDF($"{Source} {DisplayPage(GlobalOptions.Language)}", strTranslatedNameOnPage); } } else { Notes = strQualityNotes; } } SourceDetail = new SourceString(_strSource, _strPage); }
/// <summary> /// Accept the values on the Form and create the required XML data. /// </summary> private void AcceptForm() { // Make sure a value has been selected if necessary. if (txtSelect.Visible && string.IsNullOrEmpty(txtSelect.Text)) { MessageBox.Show(LanguageManager.GetString("Message_SelectItem"), LanguageManager.GetString("MessageTitle_SelectItem"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Make sure a value has been provided for the name. if (string.IsNullOrEmpty(txtName.Text)) { MessageBox.Show(LanguageManager.GetString("Message_ImprovementName"), LanguageManager.GetString("MessageTitle_ImprovementName"), MessageBoxButtons.OK, MessageBoxIcon.Error); txtName.Focus(); return; } MemoryStream objStream = new MemoryStream(); XmlWriter objWriter = XmlWriter.Create(objStream); // Build the XML for the Improvement. XmlNode objFetchNode = _objDocument.SelectSingleNode("/chummer/improvements/improvement[id = \"" + cboImprovemetType.SelectedValue + "\"]"); if (objFetchNode == null) { return; } objWriter.WriteStartDocument(); // <bonus> objWriter.WriteStartElement("bonus"); // <whatever element> objWriter.WriteStartElement(objFetchNode["internal"]?.InnerText); string strRating = string.Empty; if (chkApplyToRating.Checked) { strRating = "<applytorating>yes</applytorating>"; } // Retrieve the XML data from the document and replace the values as necessary. // ReSharper disable once PossibleNullReferenceException string strXml = objFetchNode["xml"].InnerText; strXml = strXml.Replace("{val}", nudVal.Value.ToString(GlobalOptions.InvariantCultureInfo)); strXml = strXml.Replace("{min}", nudMin.Value.ToString(GlobalOptions.InvariantCultureInfo)); strXml = strXml.Replace("{max}", nudMax.Value.ToString(GlobalOptions.InvariantCultureInfo)); strXml = strXml.Replace("{aug}", nudAug.Value.ToString(GlobalOptions.InvariantCultureInfo)); strXml = strXml.Replace("{free}", chkFree.Checked.ToString().ToLower()); strXml = strXml.Replace("{select}", txtSelect.Text); strXml = strXml.Replace("{applytorating}", strRating); objWriter.WriteRaw(strXml); // Write the rest of the document. // </whatever element> objWriter.WriteEndElement(); // </bonus> objWriter.WriteEndElement(); objWriter.WriteEndDocument(); objWriter.Flush(); objStream.Position = 0; // Read it back in as an XmlDocument. StreamReader objReader = new StreamReader(objStream); XmlDocument objBonusXml = new XmlDocument(); strXml = objReader.ReadToEnd(); objBonusXml.LoadXml(strXml); objWriter.Close(); // Pluck out the bonus information. XmlNode objNode = objBonusXml.SelectSingleNode("/bonus"); // Pass it to the Improvement Manager so that it can be added to the character. string strGuid = Guid.NewGuid().ToString(); ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.Custom, strGuid, objNode, false, 1, txtName.Text); // If an Improvement was passed in, remove it from the character. string strNotes = string.Empty; int intOrder = 0; if (_objEditImprovement != null) { // Copy the notes over to the new item. strNotes = _objEditImprovement.Notes; intOrder = _objEditImprovement.SortOrder; ImprovementManager.RemoveImprovements(_objCharacter, Improvement.ImprovementSource.Custom, _objEditImprovement.SourceName); } // Find the newly-created Improvement and attach its custom name. foreach (Improvement objImprovement in _objCharacter.Improvements) { if (objImprovement.SourceName == strGuid) { objImprovement.CustomName = txtName.Text; objImprovement.CustomId = cboImprovemetType.SelectedValue.ToString(); objImprovement.Custom = true; objImprovement.Notes = strNotes; objImprovement.SortOrder = intOrder; } } DialogResult = DialogResult.OK; }
private void frmSelectSpell_Load(object sender, EventArgs e) { // If a value is forced, set the name of the spell and accept the form. if (!string.IsNullOrEmpty(_strForceSpell)) { _strSelectedSpell = _strForceSpell; DialogResult = DialogResult.OK; } foreach (Label objLabel in Controls.OfType <Label>()) { if (objLabel.Text.StartsWith('[')) { objLabel.Text = string.Empty; } } //Free Spells (typically from Dedicated Spellslinger or custom Improvements) are only handled manually //in Career Mode. Create mode manages itself. int intFreeGenericSpells = ImprovementManager.ValueOf(_objCharacter, Improvement.ImprovementType.FreeSpells); int intFreeTouchOnlySpells = 0; foreach (Improvement imp in _objCharacter.Improvements.Where(i => i.ImproveType == Improvement.ImprovementType.FreeSpellsATT)) { if (imp.ImproveType == Improvement.ImprovementType.FreeSpellsATT) { int intAttValue = _objCharacter.GetAttribute(imp.ImprovedName).TotalValue; if (imp.UniqueName.Contains("half")) { intAttValue = (intAttValue + 1) / 2; } if (imp.UniqueName.Contains("touchonly")) { intFreeTouchOnlySpells += intAttValue; } else { intFreeGenericSpells += intAttValue; } } else if (imp.ImproveType == Improvement.ImprovementType.FreeSpellsSkill) { int intSkillValue = _objCharacter.SkillsSection.GetActiveSkill(imp.ImprovedName).TotalBaseRating; if (imp.UniqueName.Contains("half")) { intSkillValue = (intSkillValue + 1) / 2; } if (imp.UniqueName.Contains("touchonly")) { intFreeTouchOnlySpells += intSkillValue; } else { intFreeGenericSpells += intSkillValue; } } } int intTotalFreeNonTouchSpellsCount = _objCharacter.Spells.Count(spell => spell.FreeBonus && spell.Range != "T"); int intTotalFreeTouchOnlySpellsCount = _objCharacter.Spells.Count(spell => spell.FreeBonus && spell.Range == "T"); if (intFreeTouchOnlySpells > intTotalFreeTouchOnlySpellsCount) { _blnCanTouchOnlySpellBeFree = true; } if (intFreeGenericSpells > intTotalFreeNonTouchSpellsCount + Math.Max(intTotalFreeTouchOnlySpellsCount - intFreeTouchOnlySpells, 0)) { _blnCanGenericSpellBeFree = true; } txtSearch.Text = string.Empty; // Populate the Category list. XmlNodeList objXmlNodeList = _objXmlDocument.SelectNodes("/chummer/categories/category"); HashSet <string> limit = new HashSet <string>(); foreach (Improvement improvement in _objCharacter.Improvements.Where(improvement => improvement.ImproveType == Improvement.ImprovementType.LimitSpellCategory)) { limit.Add(improvement.ImprovedName); } foreach (XmlNode objXmlCategory in objXmlNodeList) { if (limit.Count != 0 && !limit.Contains(objXmlCategory.InnerText)) { continue; } if (!string.IsNullOrEmpty(_strLimitCategory) && _strLimitCategory != objXmlCategory.InnerText) { continue; } ListItem objItem = new ListItem(); objItem.Value = objXmlCategory.InnerText; objItem.Name = objXmlCategory.Attributes?["translate"]?.InnerText ?? objXmlCategory.InnerText; _lstCategory.Add(objItem); } SortListItem objSort = new SortListItem(); _lstCategory.Sort(objSort.Compare); if (_lstCategory.Count > 0) { ListItem objItem = new ListItem(); objItem.Value = "Show All"; objItem.Name = LanguageManager.GetString("String_ShowAll"); _lstCategory.Insert(0, objItem); } cboCategory.BeginUpdate(); cboCategory.DataSource = null; cboCategory.ValueMember = "Value"; cboCategory.DisplayMember = "Name"; cboCategory.DataSource = _lstCategory; // Select the first Category in the list. if (string.IsNullOrEmpty(_strSelectCategory)) { cboCategory.SelectedIndex = 0; } else { cboCategory.SelectedValue = _strSelectCategory; } if (cboCategory.SelectedIndex == -1) { cboCategory.SelectedIndex = 0; } cboCategory.EndUpdate(); // Don't show the Extended Spell checkbox if the option to Extend any Detection Spell is diabled. chkExtended.Visible = _objCharacter.Options.ExtendAnyDetectionSpell; BuildSpellList(); }
/// <summary> /// Create a Mentor Spirit from an XmlNode. /// </summary> /// <param name="xmlMentor">XmlNode to create the object from.</param> /// <param name="eMentorType">Whether this is a Mentor or a Paragon.</param> /// <param name="strForceValueChoice1">Name/Text for Choice 1.</param> /// <param name="strForceValueChoice2">Name/Text for Choice 2.</param> /// <param name="strForceValue">Force a value to be selected for the Mentor Spirit.</param> /// <param name="blnMentorMask">Whether the Mentor's Mask is enabled.</param> public void Create(XmlNode xmlMentor, Improvement.ImprovementType eMentorType, string strForceValue = "", string strForceValueChoice1 = "", string strForceValueChoice2 = "", bool blnMentorMask = false) { _blnMentorMask = blnMentorMask; _eMentorType = eMentorType; _objCachedMyXmlNode = null; xmlMentor.TryGetStringFieldQuickly("name", ref _strName); xmlMentor.TryGetStringFieldQuickly("source", ref _strSource); xmlMentor.TryGetStringFieldQuickly("page", ref _strPage); if (!xmlMentor.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { xmlMentor.TryGetStringFieldQuickly("notes", ref _strNotes); } if (xmlMentor.TryGetField("id", Guid.TryParse, out Guid guiTemp)) { _sourceID = guiTemp; } // Build the list of advantages gained through the Mentor Spirit. if (!xmlMentor.TryGetStringFieldQuickly("altadvantage", ref _strAdvantage)) { xmlMentor.TryGetStringFieldQuickly("advantage", ref _strAdvantage); } if (!xmlMentor.TryGetStringFieldQuickly("altdisadvantage", ref _strDisadvantage)) { xmlMentor.TryGetStringFieldQuickly("disadvantage", ref _strDisadvantage); } _nodBonus = xmlMentor["bonus"]; if (_nodBonus != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = strForceValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), _nodBonus, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } _strExtra = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (!string.IsNullOrEmpty(strForceValue)) { _strExtra = strForceValue; } _nodChoice1 = xmlMentor.SelectSingleNode("choices/choice[name = \"" + strForceValueChoice1 + "\"]/bonus"); if (_nodChoice1 != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; //ImprovementManager.ForcedValue = strForceValueChoice1; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), _nodChoice1, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (string.IsNullOrEmpty(_strExtra)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (string.IsNullOrEmpty(_strExtra) && !string.IsNullOrEmpty(strForceValueChoice1)) { _strExtra = strForceValueChoice1; } _nodChoice2 = xmlMentor.SelectSingleNode("choices/choice[name = \"" + strForceValueChoice2 + "\"]/bonus"); if (_nodChoice2 != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; //ImprovementManager.ForcedValue = strForceValueChoice2; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), _nodChoice2, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (string.IsNullOrEmpty(_strExtra)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (string.IsNullOrEmpty(_strExtra) && !string.IsNullOrEmpty(strForceValueChoice2)) { _strExtra = strForceValueChoice2; } if (_blnMentorMask) { ImprovementManager.CreateImprovement(_objCharacter, string.Empty, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), Improvement.ImprovementType.AdeptPowerPoints, string.Empty, 1); ImprovementManager.CreateImprovement(_objCharacter, string.Empty, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D"), Improvement.ImprovementType.DrainValue, string.Empty, -1); ImprovementManager.Commit(_objCharacter); } /* * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPDF($"{_strSource} {_strPage}", _strName); * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPDF($"{Source} {Page(GlobalOptions.Language)}", DisplayName(GlobalOptions.Language)); * } * }*/ }
/// <summary> /// Accept the values on the Form and create the required XML data. /// </summary> private void AcceptForm() { // Make sure a value has been selected if necessary. if (txtTranslateSelection.Visible && string.IsNullOrEmpty(txtSelect.Text)) { Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_SelectItem"), LanguageManager.GetString("MessageTitle_SelectItem"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Make sure a value has been provided for the name. if (string.IsNullOrEmpty(txtName.Text)) { Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_ImprovementName"), LanguageManager.GetString("MessageTitle_ImprovementName"), MessageBoxButtons.OK, MessageBoxIcon.Error); txtName.Focus(); return; } XmlDocument objBonusXml = new XmlDocument { XmlResolver = null }; using (MemoryStream objStream = new MemoryStream()) { // Here instead of later because objWriter.Close() needs Stream to not be disposed, but StreamReader.Close() will dispose the Stream. using (StreamReader objReader = new StreamReader(objStream, Encoding.UTF8, true)) { using (XmlWriter objWriter = XmlWriter.Create(objStream)) { // Build the XML for the Improvement. XmlNode objFetchNode = _objDocument.SelectSingleNode("/chummer/improvements/improvement[id = " + cboImprovemetType.SelectedValue.ToString().CleanXPath() + "]"); string strInternal = objFetchNode?["internal"]?.InnerText; if (string.IsNullOrEmpty(strInternal)) { return; } objWriter.WriteStartDocument(); // <bonus> objWriter.WriteStartElement("bonus"); // <whatever element> objWriter.WriteStartElement(strInternal); string strRating = string.Empty; if (chkApplyToRating.Checked) { strRating = "<applytorating>True</applytorating>"; } // Retrieve the XML data from the document and replace the values as necessary. XmlAttributeCollection xmlAttributeCollection = objFetchNode["xml"]?.Attributes; if (xmlAttributeCollection != null) { foreach (XmlAttribute xmlAttribute in xmlAttributeCollection) { objWriter.WriteAttributeString(xmlAttribute.LocalName, xmlAttribute.Value); } } // ReSharper disable once PossibleNullReferenceException string strXml = objFetchNode["xml"].InnerText .Replace("{val}", nudVal.Value.ToString(GlobalOptions.InvariantCultureInfo)) .Replace("{min}", nudMin.Value.ToString(GlobalOptions.InvariantCultureInfo)) .Replace("{max}", nudMax.Value.ToString(GlobalOptions.InvariantCultureInfo)) .Replace("{aug}", nudAug.Value.ToString(GlobalOptions.InvariantCultureInfo)) .Replace("{free}", chkFree.Checked.ToString(GlobalOptions.InvariantCultureInfo).ToLowerInvariant()) .Replace("{select}", txtSelect.Text) .Replace("{applytorating}", strRating); objWriter.WriteRaw(strXml); // Write the rest of the document. // </whatever element> objWriter.WriteEndElement(); // </bonus> objWriter.WriteEndElement(); objWriter.WriteEndDocument(); objWriter.Flush(); objStream.Position = 0; // Read it back in as an XmlDocument. using (XmlReader objXmlReader = XmlReader.Create(objReader, GlobalOptions.SafeXmlReaderSettings)) objBonusXml.Load(objXmlReader); } } } // Pluck out the bonus information. XmlNode objNode = objBonusXml.SelectSingleNode("/bonus"); // Pass it to the Improvement Manager so that it can be added to the character. string strGuid = Guid.NewGuid().ToString("D", GlobalOptions.InvariantCultureInfo); ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.Custom, strGuid, objNode, 1, txtName.Text); // If an Improvement was passed in, remove it from the character. string strNotes = string.Empty; int intOrder = 0; if (EditImprovementObject != null) { // Copy the notes over to the new item. strNotes = EditImprovementObject.Notes; intOrder = EditImprovementObject.SortOrder; ImprovementManager.RemoveImprovements(_objCharacter, Improvement.ImprovementSource.Custom, EditImprovementObject.SourceName); } // Find the newly-created Improvement and attach its custom name. Improvement objImprovement = _objCharacter.Improvements.FirstOrDefault(imp => imp.SourceName == strGuid); if (objImprovement != null) { objImprovement.CustomName = txtName.Text; objImprovement.CustomId = cboImprovemetType.SelectedValue.ToString(); objImprovement.Custom = true; objImprovement.Notes = strNotes; objImprovement.SortOrder = intOrder; objImprovement.CustomGroup = _strCustomGroup; NewImprovement = objImprovement; } else { Utils.BreakIfDebug(); } DialogResult = DialogResult.OK; }
/// <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); }
private void frmSelectSpell_Load(object sender, EventArgs e) { // If a value is forced, set the name of the spell and accept the form. if (!string.IsNullOrEmpty(_strForceSpell)) { _strSelectedSpell = _strForceSpell; DialogResult = DialogResult.OK; } //Free Spells (typically from Dedicated Spellslinger or custom Improvements) are only handled manually //in Career Mode. Create mode manages itself. int intFreeGenericSpells = ImprovementManager.ValueOf(_objCharacter, Improvement.ImprovementType.FreeSpells); int intFreeTouchOnlySpells = 0; foreach (Improvement imp in _objCharacter.Improvements.Where(i => i.ImproveType == Improvement.ImprovementType.FreeSpellsATT && i.Enabled)) { if (imp.ImproveType == Improvement.ImprovementType.FreeSpellsATT) { int intAttValue = _objCharacter.GetAttribute(imp.ImprovedName).TotalValue; if (imp.UniqueName.Contains("half")) { intAttValue = (intAttValue + 1) / 2; } if (imp.UniqueName.Contains("touchonly")) { intFreeTouchOnlySpells += intAttValue; } else { intFreeGenericSpells += intAttValue; } } else if (imp.ImproveType == Improvement.ImprovementType.FreeSpellsSkill) { Skill skill = _objCharacter.SkillsSection.GetActiveSkill(imp.ImprovedName); int intSkillValue = _objCharacter.SkillsSection.GetActiveSkill(imp.ImprovedName).TotalBaseRating; if (imp.UniqueName.Contains("half")) { intSkillValue = (intSkillValue + 1) / 2; } if (imp.UniqueName.Contains("touchonly")) { intFreeTouchOnlySpells += intSkillValue; } else { intFreeGenericSpells += intSkillValue; } //TODO: I don't like this being hardcoded, even though I know full well CGL are never going to reuse this. foreach (SkillSpecialization spec in skill.Specializations) { if (_objCharacter.Spells.Any(spell => spell.Category == spec.Name && !spell.FreeBonus)) { intFreeGenericSpells++; } } } } int intTotalFreeNonTouchSpellsCount = _objCharacter.Spells.Count(spell => spell.FreeBonus && spell.Range != "T"); int intTotalFreeTouchOnlySpellsCount = _objCharacter.Spells.Count(spell => spell.FreeBonus && spell.Range == "T"); if (intFreeTouchOnlySpells > intTotalFreeTouchOnlySpellsCount) { _blnCanTouchOnlySpellBeFree = true; } if (intFreeGenericSpells > intTotalFreeNonTouchSpellsCount + Math.Max(intTotalFreeTouchOnlySpellsCount - intFreeTouchOnlySpells, 0)) { _blnCanGenericSpellBeFree = true; } txtSearch.Text = string.Empty; // Populate the Category list. HashSet <string> limit = new HashSet <string>(); foreach (Improvement improvement in _objCharacter.Improvements.Where(x => x.ImproveType == Improvement.ImprovementType.LimitSpellCategory && x.Enabled)) { limit.Add(improvement.ImprovedName); } foreach (XPathNavigator objXmlCategory in _xmlBaseSpellDataNode.Select("categories/category")) { string strCategory = objXmlCategory.Value; if (limit.Count != 0 && !limit.Contains(strCategory)) { continue; } if (!string.IsNullOrEmpty(_strLimitCategory) && _strLimitCategory != strCategory) { continue; } _lstCategory.Add(new ListItem(strCategory, objXmlCategory.SelectSingleNode(@"translate")?.Value ?? strCategory)); } _lstCategory.Sort(CompareListItems.CompareNames); if (_lstCategory.Count > 0) { _lstCategory.Insert(0, new ListItem("Show All", LanguageManager.GetString("String_ShowAll", GlobalOptions.Language))); } cboCategory.BeginUpdate(); cboCategory.DataSource = null; cboCategory.ValueMember = "Value"; cboCategory.DisplayMember = "Name"; cboCategory.DataSource = _lstCategory; // Select the first Category in the list. if (string.IsNullOrEmpty(s_StrSelectCategory)) { cboCategory.SelectedIndex = 0; } else { cboCategory.SelectedValue = s_StrSelectCategory; } if (cboCategory.SelectedIndex == -1) { cboCategory.SelectedIndex = 0; } cboCategory.EndUpdate(); // Don't show the Extended Spell checkbox if the option to Extend any Detection Spell is diabled. chkExtended.Visible = _objCharacter.Options.ExtendAnyDetectionSpell; BuildSpellList(); }
/// Create a Critter Power from an XmlNode. /// <param name="objXmlPowerNode">XmlNode to create the object from.</param> /// <param name="intRating">Selected Rating for the Gear.</param> /// <param name="strForcedValue">Value to forcefully select for any ImprovementManager prompts.</param> public void Create(XmlNode objXmlPowerNode, int intRating = 0, string strForcedValue = "") { if (!objXmlPowerNode.TryGetField("id", Guid.TryParse, out _guiSourceID)) { Log.Warn(new object[] { "Missing id field for power xmlnode", objXmlPowerNode }); Utils.BreakIfDebug(); } if (objXmlPowerNode.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } _intRating = intRating; _nodBonus = objXmlPowerNode.SelectSingleNode("bonus"); if (!objXmlPowerNode.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objXmlPowerNode.TryGetStringFieldQuickly("notes", ref _strNotes); } // If the piece grants a bonus, pass the information to the Improvement Manager. if (_nodBonus != null) { ImprovementManager.ForcedValue = strForcedValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.CritterPower, _guiID.ToString("D", GlobalOptions.InvariantCultureInfo), _nodBonus, intRating, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; } else if (intRating != 0) { _strExtra = intRating.ToString(GlobalOptions.InvariantCultureInfo); } } else if (intRating != 0) { _strExtra = intRating.ToString(GlobalOptions.InvariantCultureInfo); } else { _strExtra = strForcedValue; } objXmlPowerNode.TryGetStringFieldQuickly("category", ref _strCategory); objXmlPowerNode.TryGetStringFieldQuickly("type", ref _strType); objXmlPowerNode.TryGetStringFieldQuickly("action", ref _strAction); objXmlPowerNode.TryGetStringFieldQuickly("range", ref _strRange); objXmlPowerNode.TryGetStringFieldQuickly("duration", ref _strDuration); objXmlPowerNode.TryGetStringFieldQuickly("source", ref _strSource); objXmlPowerNode.TryGetStringFieldQuickly("page", ref _strPage); objXmlPowerNode.TryGetInt32FieldQuickly("karma", ref _intKarma); /* * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPDF(_strSource + ' ' + _strPage, _strName); * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPDF(Source + ' ' + DisplayPage(GlobalOptions.Language), CurrentDisplayName); * } * } */ }
/// Create a Armor Modification from an XmlNode and return the TreeNodes for it. /// <param name="objXmlArmorNode">XmlNode to create the object from.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="intRating">Rating of the selected ArmorMod.</param> /// <param name="objWeapons">List of Weapons that are created by the Armor.</param> /// <param name="objWeaponNodes">List of Weapon Nodes that are created by the Armor.</param> /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param> public void Create(XmlNode objXmlArmorNode, TreeNode objNode, int intRating, List <Weapon> objWeapons, List <TreeNode> objWeaponNodes, bool blnSkipCost = false) { objXmlArmorNode.TryGetStringFieldQuickly("name", ref _strName); objXmlArmorNode.TryGetStringFieldQuickly("category", ref _strCategory); objXmlArmorNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity); _intRating = intRating; objXmlArmorNode.TryGetInt32FieldQuickly("armor", ref _intA); objXmlArmorNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating); objXmlArmorNode.TryGetStringFieldQuickly("avail", ref _strAvail); objXmlArmorNode.TryGetStringFieldQuickly("source", ref _strSource); objXmlArmorNode.TryGetStringFieldQuickly("page", ref _strPage); _nodBonus = objXmlArmorNode["bonus"]; if (GlobalOptions.Instance.Language != "en-us") { XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml"); XmlNode objArmorNode = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + _strName + "\"]"); if (objArmorNode != null) { objArmorNode.TryGetStringFieldQuickly("translate", ref _strAltName); objArmorNode.TryGetStringFieldQuickly("altpage", ref _strAltPage); } objArmorNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]"); if (objArmorNode != null) { if (objArmorNode.Attributes["translate"] != null) { _strAltCategory = objArmorNode.Attributes["translate"].InnerText; } } } // Check for a Variable Cost. if (blnSkipCost) { _strCost = "0"; } else if (objXmlArmorNode["cost"] != null) { XmlNode objXmlArmorCostNode = objXmlArmorNode["cost"]; if (objXmlArmorCostNode.InnerText.StartsWith("Variable")) { int intMin; int intMax = 0; char[] chrParentheses = { '(', ')' }; string strCost = objXmlArmorCostNode.InnerText.Replace("Variable", string.Empty).Trim(chrParentheses); if (strCost.Contains("-")) { string[] strValues = strCost.Split('-'); intMin = Convert.ToInt32(strValues[0]); intMax = Convert.ToInt32(strValues[1]); } else { intMin = Convert.ToInt32(strCost.Replace("+", string.Empty)); } if (intMin != 0 || intMax != 0) { frmSelectNumber frmPickNumber = new frmSelectNumber(); if (intMax == 0) { intMax = 1000000; } frmPickNumber.Minimum = intMin; frmPickNumber.Maximum = intMax; frmPickNumber.Description = LanguageManager.Instance.GetString("String_SelectVariableCost").Replace("{0}", DisplayNameShort); frmPickNumber.AllowCancel = false; frmPickNumber.ShowDialog(); _strCost = frmPickNumber.SelectedValue.ToString(); } } else { _strCost = objXmlArmorCostNode.InnerText; } } if (objXmlArmorNode["bonus"] != null && !blnSkipCost) { ImprovementManager objImprovementManager = new ImprovementManager(_objCharacter); if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.ArmorMod, _guiID.ToString(), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(objImprovementManager.SelectedValue)) { _strExtra = objImprovementManager.SelectedValue; objNode.Text += " (" + objImprovementManager.SelectedValue + ")"; } } // Add Weapons if applicable. if (objXmlArmorNode.InnerXml.Contains("<addweapon>")) { XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml"); // More than one Weapon can be added, so loop through all occurrences. foreach (XmlNode objXmlAddWeapon in objXmlArmorNode.SelectNodes("addweapon")) { var objXmlWeapon = helpers.Guid.IsGuid(objXmlAddWeapon.InnerText) ? objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + objXmlAddWeapon.InnerText + "\" and starts-with(category, \"Cyberware\")]") : objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlAddWeapon.InnerText + "\" and starts-with(category, \"Cyberware\")]"); TreeNode objGearWeaponNode = new TreeNode(); Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Create(objXmlWeapon, _objCharacter, objGearWeaponNode, null, null); objGearWeaponNode.ForeColor = SystemColors.GrayText; objWeaponNodes.Add(objGearWeaponNode); objWeapons.Add(objGearWeapon); _guiWeaponID = Guid.Parse(objGearWeapon.InternalId); } } objNode.Text = DisplayName; objNode.Tag = _guiID.ToString(); }
/// Create a Gear from an XmlNode and return the TreeNodes for it. /// <param name="objXmlGear">XmlNode to create the object from.</param> /// <param name="objCharacter">Character the Gear is being added to.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="intRating">Selected Rating for the Gear.</param> /// <param name="objWeapons">List of Weapons that should be added to the character.</param> /// <param name="objWeaponNodes">List of TreeNodes to represent the added Weapons</param> /// <param name="strForceValue">Value to forcefully select for any ImprovementManager prompts.</param> /// <param name="blnHacked">Whether or not a Matrix Program has been hacked (removing the Copy Protection and Registration plugins).</param> /// <param name="blnInherent">Whether or not a Program is Inherent to an A.I.</param> /// <param name="blnAddImprovements">Whether or not Improvements should be added to the character.</param> /// <param name="blnCreateChildren">Whether or not child Gear should be created.</param> /// <param name="blnAerodynamic">Whether or not Weapons should be created as Aerodynamic.</param> public void Create(XmlNode objXmlGear, Character objCharacter, TreeNode objNode, int intRating, List<Weapon> objWeapons, List<TreeNode> objWeaponNodes, string strForceValue = "", bool blnHacked = false, bool blnInherent = false, bool blnAddImprovements = true, bool blnCreateChildren = true, bool blnAerodynamic = false) { _strName = objXmlGear["name"].InnerText; _strCategory = objXmlGear["category"].InnerText; _strAvail = objXmlGear["avail"].InnerText; try { _strAvail3 = objXmlGear["avail3"].InnerText; } catch { } try { _strAvail6 = objXmlGear["avail6"].InnerText; } catch { } try { _strAvail10 = objXmlGear["avail10"].InnerText; } catch { } try { _strCapacity = objXmlGear["capacity"].InnerText; } catch { } try { _strArmorCapacity = objXmlGear["armorcapacity"].InnerText; } catch { } try { _intCostFor = Convert.ToInt32(objXmlGear["costfor"].InnerText); _intQty = Convert.ToInt32(objXmlGear["costfor"].InnerText); } catch { } try { _strCost = objXmlGear["cost"].InnerText; } catch { } try { _strCost3 = objXmlGear["cost3"].InnerText; } catch { } try { _strCost6 = objXmlGear["cost6"].InnerText; } catch { } try { _strCost10 = objXmlGear["cost10"].InnerText; } catch { } _nodBonus = objXmlGear["bonus"]; _intMaxRating = Convert.ToInt32(objXmlGear["rating"].InnerText); try { _intMinRating = Convert.ToInt32(objXmlGear["minrating"].InnerText); } catch { } _intRating = intRating; _strSource = objXmlGear["source"].InnerText; _strPage = objXmlGear["page"].InnerText; try { _intChildCostMultiplier = Convert.ToInt32(objXmlGear["childcostmultiplier"].InnerText); } catch { } try { _intChildAvailModifier = Convert.ToInt32(objXmlGear["childavailmodifier"].InnerText); } catch { } if (GlobalOptions.Instance.Language != "en-us") { XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml"); XmlNode objGearNode = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + _strName + "\"]"); if (objGearNode != null) { if (objGearNode["translate"] != null) _strAltName = objGearNode["translate"].InnerText; if (objGearNode["altpage"] != null) _strAltPage = objGearNode["altpage"].InnerText; } if (_strAltName.StartsWith("Stacked Focus")) _strAltName = _strAltName.Replace("Stacked Focus", LanguageManager.Instance.GetString("String_StackedFocus")); objGearNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]"); if (objGearNode != null) { if (objGearNode.Attributes["translate"] != null) _strAltCategory = objGearNode.Attributes["translate"].InnerText; } if (_strAltCategory.StartsWith("Stacked Focus")) _strAltCategory = _strAltCategory.Replace("Stacked Focus", LanguageManager.Instance.GetString("String_StackedFocus")); } // Check for a Custom name if (objXmlGear["name"].InnerText == "Custom Item") { frmSelectText frmPickText = new frmSelectText(); frmPickText.Description = LanguageManager.Instance.GetString("String_CustomItem_SelectText"); frmPickText.ShowDialog(); // Make sure the dialogue window was not canceled. if (frmPickText.DialogResult != DialogResult.Cancel) { _strName = frmPickText.SelectedValue; } } // Check for a Variable Cost. if (objXmlGear["cost"] != null) { if (objXmlGear["cost"].InnerText.StartsWith("Variable")) { int intMin = 0; int intMax = 0; string strCost = objXmlGear["cost"].InnerText.Replace("Variable(", string.Empty).Replace(")", string.Empty); if (strCost.Contains("-")) { string[] strValues = strCost.Split('-'); intMin = Convert.ToInt32(strValues[0]); intMax = Convert.ToInt32(strValues[1]); } else intMin = Convert.ToInt32(strCost.Replace("+", string.Empty)); if (intMin != 0 || intMax != 0) { frmSelectNumber frmPickNumber = new frmSelectNumber(); if (intMax == 0) intMax = 1000000; frmPickNumber.Minimum = intMin; frmPickNumber.Maximum = intMax; frmPickNumber.Description = LanguageManager.Instance.GetString("String_SelectVariableCost").Replace("{0}", DisplayNameShort); frmPickNumber.AllowCancel = false; frmPickNumber.ShowDialog(); _strCost = frmPickNumber.SelectedValue.ToString(); } } } string strSource = _guiID.ToString(); objNode.Text = _strName; objNode.Tag = _guiID.ToString(); // If the Gear is Ammunition, ask the user to select a Weapon Category for it to be limited to. if (_strCategory == "Ammunition" && (_strName.StartsWith("Ammo:") || _strName.StartsWith("Arrow:") || _strName.StartsWith("Bolt:"))) { frmSelectWeaponCategory frmPickWeaponCategory = new frmSelectWeaponCategory(); frmPickWeaponCategory.Description = LanguageManager.Instance.GetString("String_SelectWeaponCategoryAmmo"); if (strForceValue != "") frmPickWeaponCategory.OnlyCategory = strForceValue; //should really go in a data file if (_strName.StartsWith("Ammo:")) { if (_strName.StartsWith("Ammo: Assault Cannon") || _strName.StartsWith("Ammo: Gauss")) { frmPickWeaponCategory.WeaponType = "cannon"; } else if (_strName.StartsWith("Ammo: Taser Dart")) { frmPickWeaponCategory.WeaponType = "taser"; } else if(_strName.StartsWith("Ammo: Fuel Canister")) { frmPickWeaponCategory.WeaponType = "flame"; } else if (_strName.StartsWith("Ammo: Injection Dart") || _strName.StartsWith("Ammo: Peak-Discharge")) { frmPickWeaponCategory.WeaponType = "exotic"; } else { frmPickWeaponCategory.WeaponType = "gun"; } } else if (_strName.StartsWith("Arrow:")) { frmPickWeaponCategory.WeaponType = "bow"; } else if (_strName.StartsWith("Bolt:")) { frmPickWeaponCategory.WeaponType = "crossbow"; } frmPickWeaponCategory.ShowDialog(); _strExtra = frmPickWeaponCategory.SelectedCategory; objNode.Text += " (" + _strExtra + ")"; } // Add Gear Weapons if applicable. if (objXmlGear.InnerXml.Contains("<addweapon>")) { XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml"); // More than one Weapon can be added, so loop through all occurrences. foreach (XmlNode objXmlAddWeapon in objXmlGear.SelectNodes("addweapon")) { XmlNode objXmlWeapon = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlAddWeapon.InnerText + "\"]"); TreeNode objGearWeaponNode = new TreeNode(); Weapon objGearWeapon = new Weapon(objCharacter); objGearWeapon.Create(objXmlWeapon, objCharacter, objGearWeaponNode, null, null); objGearWeaponNode.ForeColor = SystemColors.GrayText; if (blnAerodynamic) { objGearWeapon.Name += " (" + LanguageManager.Instance.GetString("Checkbox_Aerodynamic") + ")"; objGearWeapon.SetRange("Aerodynamic Grenades"); objGearWeaponNode.Text = objGearWeapon.DisplayName; _strName += " (" + LanguageManager.Instance.GetString("Checkbox_Aerodynamic") + ")"; objNode.Text = DisplayName; } objWeaponNodes.Add(objGearWeaponNode); objWeapons.Add(objGearWeapon); _guiWeaponID = Guid.Parse(objGearWeapon.InternalId); } } // If the item grants a bonus, pass the information to the Improvement Manager. if (objXmlGear.InnerXml.Contains("<bonus>")) { // Do not apply the Improvements if this is a Focus, unless we're speicifically creating a Weapon Focus. This is to avoid creating the Foci's Improvements twice (once when it's first added // to the character which is incorrect, and once when the Focus is actually Bonded). bool blnApply = !((_strCategory == "Foci" || _strCategory == "Metamagic Foci") && !objXmlGear["bonus"].InnerXml.Contains("selecttext")); if (blnApply) { ImprovementManager objImprovementManager; if (blnAddImprovements) objImprovementManager = new ImprovementManager(objCharacter); else objImprovementManager = new ImprovementManager(null); objImprovementManager.ForcedValue = strForceValue; if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Gear, strSource, objXmlGear["bonus"], false, intRating, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (objImprovementManager.SelectedValue != "") { _strExtra = objImprovementManager.SelectedValue; objNode.Text += " (" + objImprovementManager.SelectedValue + ")"; } } } // Check to see if there are any child elements. if (objXmlGear.InnerXml.Contains("<gears>") && blnCreateChildren) { // Create Gear using whatever information we're given. foreach (XmlNode objXmlChild in objXmlGear.SelectNodes("gears/gear")) { Gear objChild = new Gear(_objCharacter); TreeNode objChildNode = new TreeNode(); objChild.Name = objXmlChild["name"].InnerText; objChild.Category = objXmlChild["category"].InnerText; objChild.Avail = "0"; objChild.Cost = "0"; objChild.Source = _strSource; objChild.Page = _strPage; objChild.Parent = this; objChild.IncludedInParent = true; _objChildren.Add(objChild); objChildNode.Text = objChild.DisplayName; objChildNode.Tag = objChild.InternalId; objNode.Nodes.Add(objChildNode); objNode.Expand(); } XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); CreateChildren(objXmlGearDocument, objXmlGear, this, objNode, objCharacter, blnHacked); } // Add the Copy Protection and Registration plugins to the Matrix program. This does not apply if Unwired is not enabled, Hacked is selected, or this is a Suite being added (individual programs will add it to themselves). if (blnCreateChildren) { if ((_strCategory == "Matrix Programs" || _strCategory == "Skillsofts" || _strCategory == "Autosofts" || _strCategory == "Autosofts, Agent" || _strCategory == "Autosofts, Drone") && objCharacter.Options.BookEnabled("UN") && !blnHacked && !_strName.StartsWith("Suite:")) { XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml"); if (_objCharacter.Options.AutomaticCopyProtection && !blnInherent) { Gear objPlugin1 = new Gear(_objCharacter); TreeNode objPlugin1Node = new TreeNode(); objPlugin1.Create(objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"Copy Protection\"]"), objCharacter, objPlugin1Node, _intRating, null, null); if (_intRating == 0) objPlugin1.Rating = 1; objPlugin1.Avail = "0"; objPlugin1.Cost = "0"; objPlugin1.Cost3 = "0"; objPlugin1.Cost6 = "0"; objPlugin1.Cost10 = "0"; objPlugin1.Capacity = "[0]"; objPlugin1.Parent = this; _objChildren.Add(objPlugin1); objNode.Nodes.Add(objPlugin1Node); } if (_objCharacter.Options.AutomaticRegistration && !blnInherent) { Gear objPlugin2 = new Gear(_objCharacter); TreeNode objPlugin2Node = new TreeNode(); objPlugin2.Create(objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"Registration\"]"), objCharacter, objPlugin2Node, 0, null, null); objPlugin2.Avail = "0"; objPlugin2.Cost = "0"; objPlugin2.Cost3 = "0"; objPlugin2.Cost6 = "0"; objPlugin2.Cost10 = "0"; objPlugin2.Capacity = "[0]"; objPlugin2.Parent = this; _objChildren.Add(objPlugin2); objNode.Nodes.Add(objPlugin2Node); objNode.Expand(); } if ((objCharacter.Metatype == "A.I." || objCharacter.MetatypeCategory == "Technocritters" || objCharacter.MetatypeCategory == "Protosapients") && blnInherent) { Gear objPlugin3 = new Gear(_objCharacter); TreeNode objPlugin3Node = new TreeNode(); objPlugin3.Create(objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"Ergonomic\"]"), objCharacter, objPlugin3Node, 0, null, null); objPlugin3.Avail = "0"; objPlugin3.Cost = "0"; objPlugin3.Cost3 = "0"; objPlugin3.Cost6 = "0"; objPlugin3.Cost10 = "0"; objPlugin3.Capacity = "[0]"; objPlugin3.Parent = this; _objChildren.Add(objPlugin3); objNode.Nodes.Add(objPlugin3Node); Gear objPlugin4 = new Gear(_objCharacter); TreeNode objPlugin4Node = new TreeNode(); objPlugin4.Create(objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"Optimization\" and category = \"Program Options\"]"), objCharacter, objPlugin4Node, _intRating, null, null); if (_intRating == 0) objPlugin4.Rating = 1; objPlugin4.Avail = "0"; objPlugin4.Cost = "0"; objPlugin4.Cost3 = "0"; objPlugin4.Cost6 = "0"; objPlugin4.Cost10 = "0"; objPlugin4.Capacity = "[0]"; objPlugin4.Parent = this; _objChildren.Add(objPlugin4); objNode.Nodes.Add(objPlugin4Node); objNode.Expand(); } } } // If the item grants a Weapon bonus (Ammunition), just fill the WeaponBonus XmlNode. if (objXmlGear.InnerXml.Contains("<weaponbonus>")) _nodWeaponBonus = objXmlGear["weaponbonus"]; objNode.Text = DisplayName; }
void OnEnable() { improvementManager = GameObject.FindObjectOfType <ImprovementManager>(); tileManager = GameObject.FindObjectOfType <TileManager>(); }
/// Create a Cyberware from an XmlNode and return the TreeNodes for it. /// <param name="objXmlArmorNode">XmlNode to create the object from.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="cmsArmorMod">ContextMenuStrip to apply to Armor Mode TreeNodes.</param> /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param> /// <param name="blnCreateChildren">Whether or not child items should be created.</param> public void Create(XmlNode objXmlArmorNode, TreeNode objNode, ContextMenuStrip cmsArmorMod, int intRating, bool blnSkipCost = false, bool blnCreateChildren = true) { _strName = objXmlArmorNode["name"].InnerText; _strCategory = objXmlArmorNode["category"].InnerText; _strA = objXmlArmorNode["armor"].InnerText; if (objXmlArmorNode["armoroverride"] != null) _strO = objXmlArmorNode["armoroverride"].InnerText; _intRating = intRating; if (objXmlArmorNode["rating"] != null) _intMaxRating = Convert.ToInt32(objXmlArmorNode["rating"].InnerText); _strArmorCapacity = objXmlArmorNode["armorcapacity"].InnerText; _strAvail = objXmlArmorNode["avail"].InnerText; _strSource = objXmlArmorNode["source"].InnerText; _strPage = objXmlArmorNode["page"].InnerText; _nodBonus = objXmlArmorNode["bonus"]; if (GlobalOptions.Instance.Language != "en-us") { XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml"); XmlNode objArmorNode = objXmlDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + _strName + "\"]"); if (objArmorNode != null) { if (objArmorNode["translate"] != null) _strAltName = objArmorNode["translate"].InnerText; if (objArmorNode["altpage"] != null) _strAltPage = objArmorNode["altpage"].InnerText; } objArmorNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]"); if (objNode != null) { if (objArmorNode.Attributes["translate"] != null) _strAltCategory = objArmorNode.Attributes["translate"].InnerText; } } // Check for a Variable Cost. if (objXmlArmorNode["cost"].InnerText.StartsWith("Variable")) { if (blnSkipCost) _strCost = "0"; else { int intMin = 0; int intMax = 0; string strCost = objXmlArmorNode["cost"].InnerText.Replace("Variable(", string.Empty).Replace(")", string.Empty); if (strCost.Contains("-")) { string[] strValues = strCost.Split('-'); intMin = Convert.ToInt32(strValues[0]); intMax = Convert.ToInt32(strValues[1]); } else intMin = Convert.ToInt32(strCost.Replace("+", string.Empty)); if (intMin != 0 || intMax != 0) { frmSelectNumber frmPickNumber = new frmSelectNumber(); if (intMax == 0) intMax = 1000000; frmPickNumber.Minimum = intMin; frmPickNumber.Maximum = intMax; frmPickNumber.Description = LanguageManager.Instance.GetString("String_SelectVariableCost").Replace("{0}", DisplayNameShort); frmPickNumber.AllowCancel = false; frmPickNumber.ShowDialog(); _strCost = frmPickNumber.SelectedValue.ToString(); } } } else if (objXmlArmorNode["cost"].InnerText.StartsWith("Rating")) { // If the cost is determined by the Rating, evaluate the expression. XmlDocument objXmlDocument = new XmlDocument(); XPathNavigator nav = objXmlDocument.CreateNavigator(); string strCost = ""; string strCostExpression = _strCost; strCost = strCostExpression.Replace("Rating", _intRating.ToString()); XPathExpression xprCost = nav.Compile(strCost); _strCost = nav.Evaluate(xprCost).ToString(); } else { _strCost = objXmlArmorNode["cost"].InnerText; } if (objXmlArmorNode["bonus"] != null && !blnSkipCost) { ImprovementManager objImprovementManager = new ImprovementManager(_objCharacter); if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Armor, _guiID.ToString(), objXmlArmorNode["bonus"], false, 1, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (objImprovementManager.SelectedValue != "") { _strExtra = objImprovementManager.SelectedValue; objNode.Text += " (" + objImprovementManager.SelectedValue + ")"; } } // Add any Armor Mods that come with the Armor. if (objXmlArmorNode["mods"] != null && blnCreateChildren) { XmlDocument objXmlArmorDocument = XmlManager.Instance.Load("armor.xml"); foreach (XmlNode objXmlArmorMod in objXmlArmorNode.SelectNodes("mods/name")) { intRating = 0; string strForceValue = ""; if (objXmlArmorMod.Attributes["rating"] != null) intRating = Convert.ToInt32(objXmlArmorMod.Attributes["rating"].InnerText); if (objXmlArmorMod.Attributes["select"] != null) strForceValue = objXmlArmorMod.Attributes["select"].ToString(); XmlNode objXmlMod = objXmlArmorDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlArmorMod.InnerText + "\"]"); if (objXmlMod != null) { ArmorMod objMod = new ArmorMod(_objCharacter); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); TreeNode objModNode = new TreeNode(); objMod.Create(objXmlMod, objModNode, intRating, lstWeapons, lstWeaponNodes, blnSkipCost); objMod.Parent = this; objMod.IncludedInArmor = true; objMod.ArmorCapacity = "[0]"; objMod.Cost = "0"; objMod.MaximumRating = objMod.Rating; _lstArmorMods.Add(objMod); objModNode.ContextMenuStrip = cmsArmorMod; objNode.Nodes.Add(objModNode); objNode.Expand(); } else { ArmorMod objMod = new ArmorMod(_objCharacter); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); TreeNode objModNode = new TreeNode(); objMod.Name = objXmlArmorNode["name"].InnerText; objMod.Category = "Features"; objMod.Avail = "0"; objMod.Source = _strSource; objMod.Page = _strPage; objMod.Parent = this; objMod.IncludedInArmor = true; objMod.ArmorCapacity = "[0]"; objMod.Cost = "0"; objMod.Rating = 0; objMod.MaximumRating = objMod.Rating; _lstArmorMods.Add(objMod); objModNode.ContextMenuStrip = cmsArmorMod; objNode.Nodes.Add(objModNode); objNode.Expand(); } } } // Add any Gear that comes with the Armor. if (objXmlArmorNode["gears"] != null && blnCreateChildren) { XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlArmorGear in objXmlArmorNode.SelectNodes("gears/usegear")) { intRating = 0; string strForceValue = ""; if (objXmlArmorGear.Attributes["rating"] != null) intRating = Convert.ToInt32(objXmlArmorGear.Attributes["rating"].InnerText); if (objXmlArmorGear.Attributes["select"] != null) strForceValue = objXmlArmorGear.Attributes["select"].InnerText; XmlNode objXmlGear = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlArmorGear.InnerText + "\"]"); Gear objGear = new Gear(_objCharacter); TreeNode objGearNode = new TreeNode(); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); objGear.Create(objXmlGear, _objCharacter, objGearNode, intRating, lstWeapons, lstWeaponNodes, strForceValue, false, false, !blnSkipCost); objGear.Capacity = "[0]"; objGear.ArmorCapacity = "[0]"; objGear.Cost = "0"; objGear.MaxRating = objGear.Rating; objGear.MinRating = objGear.Rating; objGear.IncludedInParent = true; _lstGear.Add(objGear); objNode.Nodes.Add(objGearNode); objNode.Expand(); } } objNode.Text = DisplayName; objNode.Tag = _guiID.ToString(); }
/// <summary> /// Calculate the LP value for the selected items. /// </summary> private int CalculateValues(bool blnIncludePercentage = true) { if (_blnSkipRefresh) { return(0); } int intNuyen = 0; decimal decBaseCost = 0; decimal decCost = 0; // Get the base cost of the lifestyle XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + cboLifestyle.SelectedValue + "\"]"); decBaseCost += Convert.ToDecimal(objXmlAspect["cost"].InnerText); _objLifestyle.Dice = Convert.ToInt32(objXmlAspect["dice"].InnerText); _objLifestyle.Multiplier = Convert.ToInt32(objXmlAspect["multiplier"].InnerText); // Add the flat costs from qualities foreach (TreeNode objNode in treQualities.Nodes) { if (objNode.Checked) { XmlNode objXmlQuality = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + GetQualityName(objNode.Tag.ToString()) + "\"]"); if (objXmlQuality["cost"] != null && objXmlQuality["cost"].InnerText != "") { decCost += Convert.ToDecimal(objXmlQuality["cost"].InnerText); } } } decimal decMod = 0; if (blnIncludePercentage) { // Add the modifiers from qualities foreach (TreeNode objNode in treQualities.Nodes) { if (objNode.Checked) { objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + GetQualityName(objNode.Tag.ToString()) + "\"]"); if (objXmlAspect["multiplier"] != null) { decMod += (Convert.ToDecimal(objXmlAspect["multiplier"].InnerText) / 100); } } } // Check for modifiers in the improvements ImprovementManager objImprovementManager = new ImprovementManager(_objCharacter); decimal decModifier = Convert.ToDecimal(objImprovementManager.ValueOf(Improvement.ImprovementType.LifestyleCost), GlobalOptions.Instance.CultureInfo); decMod += Convert.ToDecimal(decModifier / 100, GlobalOptions.Instance.CultureInfo); } intNuyen = Convert.ToInt32(decBaseCost + (decBaseCost * decMod)); intNuyen += Convert.ToInt32(decCost); lblCost.Text = String.Format("{0:###,###,##0¥}", intNuyen); if (nudPercentage.Value != 100) { decimal decDiscount = 0; decDiscount = decBaseCost + (decBaseCost * decMod); decDiscount += decCost; decDiscount = decDiscount * (nudPercentage.Value / 100); lblCost.Text += String.Format(" (" + "{0:###,###,##0¥}" + ")", Convert.ToInt32(decDiscount)); } return(intNuyen); }
/// <summary> /// Load the CharacterAttribute from the XmlNode. /// </summary> /// <param name="objNode">XmlNode to load.</param> /// <param name="blnCopy">Whether or not we are copying an existing node.</param> public void Load(XmlNode objNode, bool blnCopy = false) { if (blnCopy || !objNode.TryGetField("guid", Guid.TryParse, out _guiID)) { _guiID = Guid.NewGuid(); } if (objNode.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } objNode.TryGetStringFieldQuickly("category", ref _strCategory); objNode.TryGetInt32FieldQuickly("armor", ref _intArmorValue); objNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity); objNode.TryGetStringFieldQuickly("gearcapacity", ref _strGearCapacity); objNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating); objNode.TryGetInt32FieldQuickly("rating", ref _intRating); objNode.TryGetStringFieldQuickly("avail", ref _strAvail); objNode.TryGetStringFieldQuickly("cost", ref _strCost); _nodBonus = objNode["bonus"]; _nodWirelessBonus = objNode["wirelessbonus"]; objNode.TryGetStringFieldQuickly("source", ref _strSource); objNode.TryGetStringFieldQuickly("page", ref _strPage); objNode.TryGetBoolFieldQuickly("included", ref _blnIncludedInArmor); objNode.TryGetBoolFieldQuickly("equipped", ref _blnEquipped); if (!objNode.TryGetBoolFieldQuickly("wirelesson", ref _blnWirelessOn)) { _blnWirelessOn = _nodWirelessBonus != null; } objNode.TryGetStringFieldQuickly("extra", ref _strExtra); objNode.TryGetField("weaponguid", Guid.TryParse, out _guiWeaponID); objNode.TryGetStringFieldQuickly("notes", ref _strNotes); objNode.TryGetBoolFieldQuickly("discountedcost", ref _blnDiscountCost); XmlNode xmlChildrenNode = objNode["gears"]; if (xmlChildrenNode != null) { using (XmlNodeList nodGears = xmlChildrenNode.SelectNodes("gear")) if (nodGears != null) { foreach (XmlNode nodGear in nodGears) { Gear objGear = new Gear(_objCharacter); objGear.Load(nodGear, blnCopy); _lstGear.Add(objGear); } } } SourceDetail = new SourceString(_strSource, _strPage); if (!blnCopy) { return; } if (!string.IsNullOrEmpty(Extra)) { ImprovementManager.ForcedValue = Extra; } ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.ArmorMod, _guiID.ToString("D"), Bonus, false, 1, DisplayNameShort(GlobalOptions.Language)); if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { Extra = ImprovementManager.SelectedValue; } if (_blnEquipped) { return; } _blnEquipped = true; Equipped = false; }
/// <summary> /// Create a Mentor Spirit from an XmlNode. /// </summary> /// <param name="xmlMentor">XmlNode to create the object from.</param> /// <param name="eMentorType">Whether this is a Mentor or a Paragon.</param> /// <param name="strForceValueChoice1">Name/Text for Choice 1.</param> /// <param name="strForceValueChoice2">Name/Text for Choice 2.</param> /// <param name="strForceValue">Force a value to be selected for the Mentor Spirit.</param> public void Create(XmlNode xmlMentor, Improvement.ImprovementType eMentorType, string strForceValue = "", string strForceValueChoice1 = "", string strForceValueChoice2 = "") { _eMentorType = eMentorType; _objCachedMyXmlNode = null; _objCachedMyXPathNode = null; xmlMentor.TryGetStringFieldQuickly("name", ref _strName); xmlMentor.TryGetStringFieldQuickly("source", ref _strSource); xmlMentor.TryGetStringFieldQuickly("page", ref _strPage); if (!xmlMentor.TryGetMultiLineStringFieldQuickly("altnotes", ref _strNotes)) { xmlMentor.TryGetMultiLineStringFieldQuickly("notes", ref _strNotes); } if (string.IsNullOrEmpty(_strNotes)) { _strNotes = CommonFunctions.GetBookNotes(xmlMentor, Name, CurrentDisplayNameShort, Source, Page, DisplayPage(GlobalSettings.Language), _objCharacter); } if (!xmlMentor.TryGetField("id", Guid.TryParse, out _guiSourceID)) { Log.Warn(new object[] { "Missing id field for xmlnode", xmlMentor }); Utils.BreakIfDebug(); } // Cache the English list of advantages gained through the Mentor Spirit. xmlMentor.TryGetMultiLineStringFieldQuickly("advantage", ref _strAdvantage); xmlMentor.TryGetMultiLineStringFieldQuickly("disadvantage", ref _strDisadvantage); _nodBonus = xmlMentor["bonus"]; if (_nodBonus != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = strForceValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D", GlobalSettings.InvariantCultureInfo), _nodBonus, 1, CurrentDisplayNameShort)) { _guiID = Guid.Empty; return; } _strExtra = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (!string.IsNullOrEmpty(strForceValue)) { _strExtra = strForceValue; } _nodChoice1 = xmlMentor.SelectSingleNode("choices/choice[name = " + strForceValueChoice1.CleanXPath() + "]/bonus"); if (_nodChoice1 != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; //ImprovementManager.ForcedValue = strForceValueChoice1; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D", GlobalSettings.InvariantCultureInfo), _nodChoice1, 1, CurrentDisplayNameShort)) { _guiID = Guid.Empty; return; } if (string.IsNullOrEmpty(_strExtra)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (string.IsNullOrEmpty(_strExtra) && !string.IsNullOrEmpty(strForceValueChoice1)) { _strExtra = strForceValueChoice1; } _nodChoice2 = xmlMentor.SelectSingleNode("choices/choice[name = " + strForceValueChoice2.CleanXPath() + "]/bonus"); if (_nodChoice2 != null) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; //ImprovementManager.ForcedValue = strForceValueChoice2; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.MentorSpirit, _guiID.ToString("D", GlobalSettings.InvariantCultureInfo), _nodChoice2, 1, CurrentDisplayNameShort)) { _guiID = Guid.Empty; return; } if (string.IsNullOrEmpty(_strExtra)) { _strExtra = ImprovementManager.SelectedValue; } ImprovementManager.ForcedValue = strOldForce; ImprovementManager.SelectedValue = strOldSelected; } else if (string.IsNullOrEmpty(_strExtra) && !string.IsNullOrEmpty(strForceValueChoice2)) { _strExtra = strForceValueChoice2; } /* * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPdf(_strSource + ' ' + _strPage, _strName); * if (string.IsNullOrEmpty(_strNotes)) * { * _strNotes = CommonFunctions.GetTextFromPdf(Source + ' ' + DisplayPage(GlobalSettings.Language), CurrentDisplayName); * } * } */ }