Exemple #1
0
        /// <summary>
        /// Open the Select Cyberware window and handle adding to the Tree and Character.
        /// </summary>
        private bool PickCyberware(Improvement.ImprovementSource objSource = Improvement.ImprovementSource.Cyberware)
        {
            Cyberware objSelectedCyberware = new Cyberware(_objCharacter);
            int intNode = 0;
            if (objSource == Improvement.ImprovementSource.Bioware)
                intNode = 1;

            // Attempt to locate the selected piece of Cyberware.
            try
            {
                if (treCyberware.SelectedNode.Level > 0)
                    objSelectedCyberware = _objFunctions.FindCyberware(treCyberware.SelectedNode.Tag.ToString(), _objCharacter.Cyberware);
            }
            catch
            {
            }

            frmSelectCyberware frmPickCyberware = new frmSelectCyberware(_objCharacter);
            double dblMultiplier = 1;
            // Apply the character's Cyberware Essence cost multiplier if applicable.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.CyberwareEssCost) != 0 && objSource == Improvement.ImprovementSource.Cyberware)
            {
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.CyberwareEssCost && objImprovement.Enabled)
                        dblMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.CharacterESSMultiplier = dblMultiplier;
            }

            // Apply the character's Bioware Essence cost multiplier if applicable.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.BiowareEssCost) != 0 && objSource == Improvement.ImprovementSource.Bioware)
            {
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.BiowareEssCost && objImprovement.Enabled)
                        dblMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.CharacterESSMultiplier = dblMultiplier;
            }

            // Apply the character's Basic Bioware Essence cost multiplier if applicable.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.BasicBiowareEssCost) != 0 && objSource == Improvement.ImprovementSource.Bioware)
            {
                double dblBasicMultiplier = 1;
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.BasicBiowareEssCost && objImprovement.Enabled)
                        dblBasicMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.BasicBiowareESSMultiplier = dblBasicMultiplier;
            }

            // Genetech Cost multiplier.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.GenetechCostMultiplier) != 0 && objSource == Improvement.ImprovementSource.Bioware)
            {
                dblMultiplier = 1;
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.GenetechCostMultiplier && objImprovement.Enabled)
                        dblMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.GenetechCostMultiplier = dblMultiplier;
            }

            // Transgenics Cost multiplier.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.TransgenicsBiowareCost) != 0 && objSource == Improvement.ImprovementSource.Bioware)
            {
                dblMultiplier = 1;
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.TransgenicsBiowareCost && objImprovement.Enabled)
                        dblMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.TransgenicsBiowareCostMultiplier = dblMultiplier;
            }

            try
            {
                if (treCyberware.SelectedNode.Level > 0)
                {
                    frmPickCyberware.SetGrade = cboCyberwareGrade.SelectedValue.ToString();
                    frmPickCyberware.LockGrade();
                    // If the Cyberware has a Capacity with no brackets (meaning it grants Capacity), show only Subsystems (those that conume Capacity).
                    if (!objSelectedCyberware.Capacity.Contains('['))
                    {
                        frmPickCyberware.ShowOnlySubsystems = true;
                        frmPickCyberware.Subsystems = objSelectedCyberware.Subsytems;
                        frmPickCyberware.MaximumCapacity = objSelectedCyberware.CapacityRemaining;
                    }
                }
            }
            catch
            {
            }

            if (objSource == Improvement.ImprovementSource.Bioware)
                frmPickCyberware.WindowMode = frmSelectCyberware.Mode.Bioware;

            frmPickCyberware.AllowModularPlugins = objSelectedCyberware.AllowModularPlugins;

            frmPickCyberware.ShowDialog(this);

            // Make sure the dialogue window was not canceled.
            if (frmPickCyberware.DialogResult == DialogResult.Cancel)
                return false;

            // Open the Cyberware XML file and locate the selected piece.
            XmlDocument objXmlDocument = new XmlDocument();
            if (objSource == Improvement.ImprovementSource.Bioware)
                objXmlDocument = XmlManager.Instance.Load("bioware.xml");
            else
                objXmlDocument = XmlManager.Instance.Load("cyberware.xml");

            XmlNode objXmlCyberware;
            if (objSource == Improvement.ImprovementSource.Bioware)
                objXmlCyberware = objXmlDocument.SelectSingleNode("/chummer/biowares/bioware[name = \"" + frmPickCyberware.SelectedCyberware + "\"]");
            else
                objXmlCyberware = objXmlDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + frmPickCyberware.SelectedCyberware + "\"]");

            // Create the Cyberware object.
            Cyberware objCyberware = new Cyberware(_objCharacter);
            List<Weapon> objWeapons = new List<Weapon>();
            TreeNode objNode = new TreeNode();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            objCyberware.Create(objXmlCyberware, _objCharacter, frmPickCyberware.SelectedGrade, objSource, frmPickCyberware.SelectedRating, objNode, objWeapons, objWeaponNodes);
            if (objCyberware.InternalId == Guid.Empty.ToString())
                return false;

            // Force the item to be Transgenic if selected.
            if (frmPickCyberware.ForceTransgenic)
                objCyberware.Category = "Genetech: Transgenics";

            // Apply the ESS discount if applicable.
            if (_objOptions.AllowCyberwareESSDiscounts)
                objCyberware.ESSDiscount = frmPickCyberware.SelectedESSDiscount;

            if (frmPickCyberware.FreeCost)
                objCyberware.Cost = "0";

            try
            {
                if (treCyberware.SelectedNode.Level > 0)
                {
                    treCyberware.SelectedNode.Nodes.Add(objNode);
                    treCyberware.SelectedNode.Expand();
                    objSelectedCyberware.Children.Add(objCyberware);
                    objCyberware.Parent = objSelectedCyberware;
                }
                else
                {
                    treCyberware.Nodes[intNode].Nodes.Add(objNode);
                    treCyberware.Nodes[intNode].Expand();
                    _objCharacter.Cyberware.Add(objCyberware);
                }
            }
            catch
            {
                treCyberware.Nodes[intNode].Nodes.Add(objNode);
                treCyberware.Nodes[intNode].Expand();
                _objCharacter.Cyberware.Add(objCyberware);
            }

            // Select the node that was just added.
            _blnSkipRefresh = true;
            if (objSource == Improvement.ImprovementSource.Cyberware)
                objNode.ContextMenuStrip = cmsCyberware;
            else if (objSource == Improvement.ImprovementSource.Bioware)
                objNode.ContextMenuStrip = cmsBioware;
            _blnSkipRefresh = true;

            foreach (Weapon objWeapon in objWeapons)
                _objCharacter.Weapons.Add(objWeapon);

            // Create the Weapon Node if one exists.
            foreach (TreeNode objWeaponNode in objWeaponNodes)
            {
                objWeaponNode.ContextMenuStrip = cmsWeapon;
                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                treWeapons.Nodes[0].Expand();
            }

			// Add any additional Qualities that are forced on the character.
			if (objXmlCyberware.SelectNodes("addqualities/addquality").Count > 0)
			{
				XmlDocument objXmlQuality = XmlManager.Instance.Load("qualities.xml");
				foreach (XmlNode objXmlAddQuality in objXmlCyberware.SelectNodes("addqualities/addquality"))
				{
					XmlNode objXmlSelectedQuality = objXmlQuality.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlAddQuality.InnerText + "\"]");
					Quality objQuality = new Quality(_objCharacter);
					objQuality = AddQuality(objXmlAddQuality, objXmlSelectedQuality, objWeapons, objWeaponNodes);
					objQuality.BP = 0;
					objQuality.ContributeToLimit = false;
					objQuality.OriginSource = QualitySource.BuiltIn;
					if (objQuality != null)
					{
						_objCharacter.Qualities.Add(objQuality);
					}
				}
			}

			treCyberware.SortCustom();
            treCyberware.SelectedNode = objNode;
            _blnSkipRefresh = true;
            PopulateCyberwareGradeList();
            UpdateCharacterInfo();
            RefreshSelectedCyberware();
            _blnSkipRefresh = false;

            _blnIsDirty = true;
            PopulateGearList();
            UpdateWindowTitle();

            return frmPickCyberware.AddAgain;
        }
Exemple #2
0
        private void tsVehicleAddCyberware_Click(object sender, EventArgs e)
        {
            Vehicle objVehicle = new Vehicle(_objCharacter);
            VehicleMod objMod = _objFunctions.FindVehicleMod(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objVehicle);

            if (objMod == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_VehicleCyberwarePlugin"), LanguageManager.Instance.GetString("MessageTitle_NoCyberware"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!objMod.AllowCyberware)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_VehicleCyberwarePlugin"), LanguageManager.Instance.GetString("MessageTitle_NoCyberware"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            frmSelectCyberware frmPickCyberware = new frmSelectCyberware(_objCharacter);
            frmPickCyberware.SetGrade = "Standard";
            frmPickCyberware.LockGrade();
            frmPickCyberware.ShowOnlySubsystems = true;
            frmPickCyberware.Subsystems = objMod.Subsystems;
            frmPickCyberware.AllowModularPlugins = objMod.AllowModularPlugins;
            frmPickCyberware.ShowDialog(this);

            if (frmPickCyberware.DialogResult == DialogResult.Cancel)
                return;

            // Open the Cyberware XML file and locate the selected piece.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("cyberware.xml");

            XmlNode objXmlCyberware = objXmlDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + frmPickCyberware.SelectedCyberware + "\"]");

            // Create the Cyberware object.
            Cyberware objCyberware = new Cyberware(_objCharacter);
            List<Weapon> objWeapons = new List<Weapon>();
            TreeNode objNode = new TreeNode();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            objCyberware.Create(objXmlCyberware, _objCharacter, frmPickCyberware.SelectedGrade, Improvement.ImprovementSource.Cyberware, frmPickCyberware.SelectedRating, objNode, objWeapons, objWeaponNodes, false);
            if (objCyberware.InternalId == Guid.Empty.ToString())
                return;

            if (frmPickCyberware.FreeCost)
                objCyberware.Cost = "0";

            treVehicles.SelectedNode.Nodes.Add(objNode);
            treVehicles.SelectedNode.Expand();
            objMod.Cyberware.Add(objCyberware);

            foreach (Weapon objWeapon in objWeapons)
            {
                objWeapon.VehicleMounted = true;
                objVehicle.Weapons.Add(objWeapon);
            }

            // Create the Weapon Node if one exists.
            foreach (TreeNode objWeaponNode in objWeaponNodes)
            {
                objWeaponNode.ContextMenuStrip = cmsVehicleWeapon;
                treVehicles.SelectedNode.Parent.Nodes.Add(objWeaponNode);
                treVehicles.SelectedNode.Parent.Expand();
            }

            UpdateCharacterInfo();

            if (frmPickCyberware.AddAgain)
                tsVehicleAddCyberware_Click(sender, e);
        }
Exemple #3
0
        /// <summary>
        /// Open the Select Cyberware window and handle adding to the Tree and Character.
        /// </summary>
        private bool PickCyberware(Improvement.ImprovementSource objSource = Improvement.ImprovementSource.Cyberware)
        {
            // Determine the lowest whole number for the character's current Essence.
            decimal decStartingESS = Math.Floor(_objCharacter.Essence);

            Cyberware objSelectedCyberware = new Cyberware(_objCharacter);
            int intNode = 0;
            if (objSource == Improvement.ImprovementSource.Bioware)
                intNode = 1;

            // Attempt to locate the selected piece of Cyberware.
            try
            {
                if (treCyberware.SelectedNode.Level > 0)
                    objSelectedCyberware = _objFunctions.FindCyberware(treCyberware.SelectedNode.Tag.ToString(), _objCharacter.Cyberware);
            }
            catch
            {
            }

            frmSelectCyberware frmPickCyberware = new frmSelectCyberware(_objCharacter, true);
            double dblMultiplier = 1;
            // Apply the character's Cyberware Essence cost multiplier if applicable.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.CyberwareEssCost) != 0 && objSource == Improvement.ImprovementSource.Cyberware)
            {
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.CyberwareEssCost && objImprovement.Enabled)
                        dblMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.CharacterESSMultiplier = dblMultiplier;
            }

            // Apply the character's Bioware Essence cost multiplier if applicable.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.BiowareEssCost) != 0 && objSource == Improvement.ImprovementSource.Bioware)
            {
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.BiowareEssCost && objImprovement.Enabled)
                        dblMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.CharacterESSMultiplier = dblMultiplier;
            }

            // Apply the character's Basic Bioware Essence cost multiplier if applicable.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.BasicBiowareEssCost) != 0 && objSource == Improvement.ImprovementSource.Bioware)
            {
                double dblBasicMultiplier = 1;
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.BasicBiowareEssCost && objImprovement.Enabled)
                        dblBasicMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.BasicBiowareESSMultiplier = dblBasicMultiplier;
            }

            // Genetech Cost multiplier.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.GenetechCostMultiplier) != 0 && objSource == Improvement.ImprovementSource.Bioware)
            {
                dblMultiplier = 1;
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.GenetechCostMultiplier && objImprovement.Enabled)
                        dblMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.GenetechCostMultiplier = dblMultiplier;
            }

            // Transgenics Cost multiplier.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.TransgenicsBiowareCost) != 0 && objSource == Improvement.ImprovementSource.Bioware)
            {
                dblMultiplier = 1;
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.TransgenicsBiowareCost && objImprovement.Enabled)
                        dblMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.TransgenicsBiowareCostMultiplier = dblMultiplier;
            }

            try
            {
                if (treCyberware.SelectedNode.Level > 0)
                {
                    frmPickCyberware.SetGrade = lblCyberwareGrade.Text;
                    frmPickCyberware.LockGrade();
                    // If the Cyberware has a Capacity with no brackets (meaning it grants Capacity), show only Subsystems (those that conume Capacity).
                    if (!objSelectedCyberware.Capacity.Contains('['))
                    {
                        frmPickCyberware.ShowOnlySubsystems = true;
                        frmPickCyberware.Subsystems = objSelectedCyberware.Subsytems;
                        frmPickCyberware.MaximumCapacity = objSelectedCyberware.CapacityRemaining;

                        // Do not allow the user to add a new piece of Cyberware if its Capacity has been reached.
                        if (_objOptions.EnforceCapacity && objSelectedCyberware.CapacityRemaining < 0)
                        {
                            MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return false;
                        }
                    }
                }
            }
            catch
            {
            }

            if (objSource == Improvement.ImprovementSource.Bioware)
                frmPickCyberware.WindowMode = frmSelectCyberware.Mode.Bioware;

            frmPickCyberware.AllowModularPlugins = objSelectedCyberware.AllowModularPlugins;

            frmPickCyberware.ShowDialog(this);

            // Make sure the dialogue window was not canceled.
            if (frmPickCyberware.DialogResult == DialogResult.Cancel)
                return false;

            // Open the Cyberware XML file and locate the selected piece.
            XmlDocument objXmlDocument = new XmlDocument();
            if (objSource == Improvement.ImprovementSource.Bioware)
                objXmlDocument = XmlManager.Instance.Load("bioware.xml");
            else
                objXmlDocument = XmlManager.Instance.Load("cyberware.xml");

            XmlNode objXmlCyberware;
            if (objSource == Improvement.ImprovementSource.Bioware)
                objXmlCyberware = objXmlDocument.SelectSingleNode("/chummer/biowares/bioware[name = \"" + frmPickCyberware.SelectedCyberware + "\"]");
            else
                objXmlCyberware = objXmlDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + frmPickCyberware.SelectedCyberware + "\"]");

            // Create the Cyberware object.
            Cyberware objCyberware = new Cyberware(_objCharacter);
            List<Weapon> objWeapons = new List<Weapon>();
            TreeNode objNode = new TreeNode();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            objCyberware.Create(objXmlCyberware, _objCharacter, frmPickCyberware.SelectedGrade, objSource, frmPickCyberware.SelectedRating, objNode, objWeapons, objWeaponNodes);
            if (objCyberware.InternalId == Guid.Empty.ToString())
                return false;

            // Force the item to be Transgenic if selected.
            if (frmPickCyberware.ForceTransgenic)
                objCyberware.Category = "Genetech: Transgenics";

            // Apply the ESS discount if applicable.
            if (_objOptions.AllowCyberwareESSDiscounts)
                objCyberware.ESSDiscount = frmPickCyberware.SelectedESSDiscount;

            int intCost = objCyberware.TotalCost;

            // Multiply the cost if applicable.
            if (objCyberware.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailRestricted")) && _objOptions.MultiplyRestrictedCost)
                intCost *= _objOptions.RestrictedCostMultiplier;
            if (objCyberware.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailForbidden")) && _objOptions.MultiplyForbiddenCost)
                intCost *= _objOptions.ForbiddenCostMultiplier;

            // Check the item's Cost and make sure the character can afford it.
            if (!frmPickCyberware.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    // Remove any Improvements created by the Cyberware.
                    _objImprovementManager.RemoveImprovements(objCyberware.SourceType, objCyberware.InternalId);
                    return frmPickCyberware.AddAgain;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    string strEntry = "";
                    if (objCyberware.SourceType == Improvement.ImprovementSource.Cyberware)
                        strEntry = LanguageManager.Instance.GetString("String_ExpensePurchaseCyberware");
                    else
                        strEntry = LanguageManager.Instance.GetString("String_ExpensePurchaseBioware");
                    objExpense.Create(intCost * -1, strEntry + " " + objCyberware.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddCyberware, objCyberware.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            try
            {
                if (treCyberware.SelectedNode.Level > 0)
                {
                    treCyberware.SelectedNode.Nodes.Add(objNode);
                    treCyberware.SelectedNode.Expand();
                    objSelectedCyberware.Children.Add(objCyberware);
                    objCyberware.Parent = objSelectedCyberware;
                }
                else
                {
                    treCyberware.Nodes[intNode].Nodes.Add(objNode);
                    treCyberware.Nodes[intNode].Expand();
                    _objCharacter.Cyberware.Add(objCyberware);
                }
            }
            catch
            {
                treCyberware.Nodes[intNode].Nodes.Add(objNode);
                treCyberware.Nodes[intNode].Expand();
                _objCharacter.Cyberware.Add(objCyberware);
            }

            // Select the node that was just added.
            if (objSource == Improvement.ImprovementSource.Cyberware)
                objNode.ContextMenuStrip = cmsCyberware;
            else if (objSource == Improvement.ImprovementSource.Bioware)
                objNode.ContextMenuStrip = cmsBioware;

            foreach (Weapon objWeapon in objWeapons)
                _objCharacter.Weapons.Add(objWeapon);

            // Create the Weapon Node if one exists.
            foreach (TreeNode objWeaponNode in objWeaponNodes)
            {
                objWeaponNode.ContextMenuStrip = cmsWeapon;
                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                treWeapons.Nodes[0].Expand();
            }

            _objFunctions.SortTree(treCyberware);
            treCyberware.SelectedNode = objNode;
            UpdateCharacterInfo();
            RefreshSelectedCyberware();
            PopulateGearList();

            if (frmPickCyberware.DialogResult != DialogResult.Cancel)
            {
                _blnIsDirty = true;
                UpdateWindowTitle();
            }

            return frmPickCyberware.AddAgain;
        }
Exemple #4
0
        private void tsVehicleAddCyberware_Click(object sender, EventArgs e)
        {
            Vehicle objVehicle = new Vehicle(_objCharacter);
            VehicleMod objMod = _objFunctions.FindVehicleMod(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objVehicle);

            if (objMod == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_VehicleCyberwarePlugin"), LanguageManager.Instance.GetString("MessageTitle_NoCyberware"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!objMod.AllowCyberware)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_VehicleCyberwarePlugin"), LanguageManager.Instance.GetString("MessageTitle_NoCyberware"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            frmSelectCyberware frmPickCyberware = new frmSelectCyberware(_objCharacter);
            frmPickCyberware.SetGrade = "Standard";
            frmPickCyberware.LockGrade();
            frmPickCyberware.ShowOnlySubsystems = true;
            frmPickCyberware.Subsystems = objMod.Subsystems;
            frmPickCyberware.AllowModularPlugins = objMod.AllowModularPlugins;
            frmPickCyberware.ShowDialog(this);

            if (frmPickCyberware.DialogResult == DialogResult.Cancel)
                return;

            // Open the Cyberware XML file and locate the selected piece.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("cyberware.xml");

            XmlNode objXmlCyberware = objXmlDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + frmPickCyberware.SelectedCyberware + "\"]");

            // Create the Cyberware object.
            Cyberware objCyberware = new Cyberware(_objCharacter);
            List<Weapon> objWeapons = new List<Weapon>();
            TreeNode objNode = new TreeNode();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            objCyberware.Create(objXmlCyberware, _objCharacter, frmPickCyberware.SelectedGrade, Improvement.ImprovementSource.Cyberware, frmPickCyberware.SelectedRating, objNode, objWeapons, objWeaponNodes, false);
            if (objCyberware.InternalId == Guid.Empty.ToString())
                return;

            if (frmPickCyberware.FreeCost)
                objCyberware.Cost = "0";

            int intCost = objCyberware.TotalCost;

            // Multiply the cost if applicable.
            if (objCyberware.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailRestricted")) && _objOptions.MultiplyRestrictedCost)
                intCost *= _objOptions.RestrictedCostMultiplier;
            if (objCyberware.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailForbidden")) && _objOptions.MultiplyForbiddenCost)
                intCost *= _objOptions.ForbiddenCostMultiplier;

            // Check the item's Cost and make sure the character can afford it.
            if (!frmPickCyberware.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    string strEntry = "";
                    strEntry = LanguageManager.Instance.GetString("String_ExpensePurchaseVehicleCyberware");
                    objExpense.Create(intCost * -1, strEntry + " " + objCyberware.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddVehicleModCyberware, objCyberware.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            treVehicles.SelectedNode.Nodes.Add(objNode);
            treVehicles.SelectedNode.Expand();
            objMod.Cyberware.Add(objCyberware);

            foreach (Weapon objWeapon in objWeapons)
            {
                objWeapon.VehicleMounted = true;
                objVehicle.Weapons.Add(objWeapon);
            }

            // Create the Weapon Node if one exists.
            foreach (TreeNode objWeaponNode in objWeaponNodes)
            {
                objWeaponNode.ContextMenuStrip = cmsVehicleWeapon;
                treVehicles.SelectedNode.Parent.Nodes.Add(objWeaponNode);
                treVehicles.SelectedNode.Parent.Expand();
            }

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickCyberware.AddAgain)
                tsVehicleAddCyberware_Click(sender, e);
        }
Exemple #5
0
        /// <summary>
        /// Open the Select Cyberware window and handle adding to the Tree and Character.
        /// </summary>
        private bool PickCyberware(Improvement.ImprovementSource objSource = Improvement.ImprovementSource.Cyberware)
        {
            // Determine the lowest whole number for the character's current Essence.
            decimal decStartingESS = Math.Floor(_objCharacter.Essence);

            Cyberware objSelectedCyberware = new Cyberware(_objCharacter);
            int intNode = 0;
            if (objSource == Improvement.ImprovementSource.Bioware)
                intNode = 1;

            // Attempt to locate the selected piece of Cyberware.
            try
            {
                if (treCyberware.SelectedNode.Level > 0)
                    objSelectedCyberware = (Cyberware)_objFunctions.FindEquipment(treCyberware.SelectedNode.Tag.ToString(), _objCharacter.Cyberware, typeof(Cyberware));
            }
            catch
            {
            }

            frmSelectCyberware frmPickCyberware = new frmSelectCyberware(_objCharacter, true);
            double dblMultiplier = 1;
            // Apply the character's Cyberware Essence cost multiplier if applicable.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.CyberwareEssCost) != 0 && objSource == Improvement.ImprovementSource.Cyberware)
            {
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.CyberwareEssCost && objImprovement.Enabled)
                        dblMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.CharacterESSMultiplier = dblMultiplier;
            }

            // Apply the character's Bioware Essence cost multiplier if applicable.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.BiowareEssCost) != 0 && objSource == Improvement.ImprovementSource.Bioware)
            {
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.BiowareEssCost && objImprovement.Enabled)
                        dblMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.CharacterESSMultiplier = dblMultiplier;
            }

            // Apply the character's Basic Bioware Essence cost multiplier if applicable.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.BasicBiowareEssCost) != 0 && objSource == Improvement.ImprovementSource.Bioware)
            {
                double dblBasicMultiplier = 1;
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.BasicBiowareEssCost && objImprovement.Enabled)
                        dblBasicMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.BasicBiowareESSMultiplier = dblBasicMultiplier;
            }

            // Genetech Cost multiplier.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.GenetechCostMultiplier) != 0 && objSource == Improvement.ImprovementSource.Bioware)
            {
                dblMultiplier = 1;
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.GenetechCostMultiplier && objImprovement.Enabled)
                        dblMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.GenetechCostMultiplier = dblMultiplier;
            }

            // Transgenics Cost multiplier.
            if (_objImprovementManager.ValueOf(Improvement.ImprovementType.TransgenicsBiowareCost) != 0 && objSource == Improvement.ImprovementSource.Bioware)
            {
                dblMultiplier = 1;
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType == Improvement.ImprovementType.TransgenicsBiowareCost && objImprovement.Enabled)
                        dblMultiplier -= (1 - (Convert.ToDouble(objImprovement.Value, GlobalOptions.Instance.CultureInfo) / 100));
                }
                frmPickCyberware.TransgenicsBiowareCostMultiplier = dblMultiplier;
            }

            try
            {
                if (treCyberware.SelectedNode.Level > 0)
                {
                    frmPickCyberware.SetGrade = lblCyberwareGrade.Text;
                    frmPickCyberware.LockGrade();
                    // If the Cyberware has a Capacity with no brackets (meaning it grants Capacity), show only Subsystems (those that conume Capacity).
                    if (!objSelectedCyberware.Capacity.Contains('['))
                    {
                        frmPickCyberware.ShowOnlySubsystems = true;
                        frmPickCyberware.Subsystems = objSelectedCyberware.Subsytems;
                        frmPickCyberware.MaximumCapacity = objSelectedCyberware.CapacityRemaining;

                        // Do not allow the user to add a new piece of Cyberware if its Capacity has been reached.
                        if (_objOptions.EnforceCapacity && objSelectedCyberware.CapacityRemaining < 0)
                        {
                            MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return false;
                        }
                    }
                }
            }
            catch
            {
            }

            if (objSource == Improvement.ImprovementSource.Bioware)
                frmPickCyberware.WindowMode = frmSelectCyberware.Mode.Bioware;

            frmPickCyberware.AllowModularPlugins = objSelectedCyberware.AllowModularPlugins;

            frmPickCyberware.ShowDialog(this);

            // Make sure the dialogue window was not canceled.
            if (frmPickCyberware.DialogResult == DialogResult.Cancel)
                return false;

            // Open the Cyberware XML file and locate the selected piece.
            XmlDocument objXmlDocument = new XmlDocument();
            if (objSource == Improvement.ImprovementSource.Bioware)
                objXmlDocument = XmlManager.Instance.Load("bioware.xml");
            else
                objXmlDocument = XmlManager.Instance.Load("cyberware.xml");

            XmlNode objXmlCyberware;
            if (objSource == Improvement.ImprovementSource.Bioware)
                objXmlCyberware = objXmlDocument.SelectSingleNode("/chummer/biowares/bioware[id = \"" + frmPickCyberware.SelectedCyberware + "\"]");
            else
                objXmlCyberware = objXmlDocument.SelectSingleNode("/chummer/cyberwares/cyberware[id = \"" + frmPickCyberware.SelectedCyberware + "\"]");

            // Create the Cyberware object.
            Cyberware objCyberware = new Cyberware(_objCharacter);
            List<Weapon> objWeapons = new List<Weapon>();
            TreeNode objNode = new TreeNode();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            objCyberware.Create(objXmlCyberware, _objCharacter, frmPickCyberware.SelectedGrade, objSource, frmPickCyberware.SelectedRating, objNode, objWeapons, objWeaponNodes);
            if (objCyberware.InternalId == Guid.Empty.ToString())
                return false;

            // Force the item to be Transgenic if selected.
            if (frmPickCyberware.ForceTransgenic)
                objCyberware.Category = "Genetech: Transgenics";

            int intCost = objCyberware.TotalCost;

            // Check the item's Cost and make sure the character can afford it.
            if (!frmPickCyberware.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    // Remove any Improvements created by the Cyberware.
                    _objImprovementManager.RemoveImprovements(objCyberware.SourceType, objCyberware.InternalId);
                    return frmPickCyberware.AddAgain;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    string strEntry = "";
                    if (objCyberware.SourceType == Improvement.ImprovementSource.Cyberware)
                        strEntry = LanguageManager.Instance.GetString("String_ExpensePurchaseCyberware");
                    else
                        strEntry = LanguageManager.Instance.GetString("String_ExpensePurchaseBioware");
                    objExpense.Create(intCost * -1, strEntry + " " + objCyberware.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddCyberware, objCyberware.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            try
            {
                if (treCyberware.SelectedNode.Level > 0)
                {
                    treCyberware.SelectedNode.Nodes.Add(objNode);
                    treCyberware.SelectedNode.Expand();
                    objSelectedCyberware.Cyberwares.Add(objCyberware);
                    objCyberware.Parent = objSelectedCyberware;
                }
                else
                {
                    treCyberware.Nodes[intNode].Nodes.Add(objNode);
                    treCyberware.Nodes[intNode].Expand();
                    _objCharacter.Cyberware.Add(objCyberware);
                }
            }
            catch
            {
                treCyberware.Nodes[intNode].Nodes.Add(objNode);
                treCyberware.Nodes[intNode].Expand();
                _objCharacter.Cyberware.Add(objCyberware);
            }

            // Select the node that was just added.
            if (objSource == Improvement.ImprovementSource.Cyberware)
                objNode.ContextMenuStrip = cmsCyberware;
            else if (objSource == Improvement.ImprovementSource.Bioware)
                objNode.ContextMenuStrip = cmsBioware;

            foreach (Weapon objWeapon in objWeapons)
                _objCharacter.Weapons.Add(objWeapon);

            // Create the Weapon Node if one exists.
            foreach (TreeNode objWeaponNode in objWeaponNodes)
            {
                objWeaponNode.ContextMenuStrip = cmsWeapon;
                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                treWeapons.Nodes[0].Expand();
            }

            // Determine the lowest whole number for the character's Essence after adding the 'Ware.
            decimal decEndingESS = Math.Floor(_objCharacter.Essence);
            decimal decDifferent = decStartingESS - decEndingESS;

            if (decDifferent > 0.0m)
            {
                // Permanently reduce the character's MAG/RES Attributes.
                _objCharacter.MAG.Value -= Convert.ToInt32(decDifferent);
                _objCharacter.RES.Value -= Convert.ToInt32(decDifferent);

                // If the Attribute reaches 0, the character has burned out.
                if (_objCharacter.MAG.Value < 1)
                {
                    _objCharacter.MAG.Value = 0;
                    _objCharacter.MAG.MetatypeMinimum = 0;
                    _objCharacter.MAG.MetatypeMaximum = 0;
                    _objCharacter.MAG.MetatypeAugmentedMaximum = 0;

                    if (_objCharacter.MAGEnabled)
                    {
                        // Move all MAG-linked Active Skills to Knowledge Skills.
                        List<Skill> lstNewSkills = new List<Skill>();
                        foreach (Skill objSkill in _objCharacter.Skills)
                        {
                            if (objSkill.Attribute == "MAG" && objSkill.Rating > 0)
                            {
                                int i = panKnowledgeSkills.Controls.Count;
                                Skill objKnowledge = new Skill(_objCharacter);

                                SkillControl objSkillControl = new SkillControl();
                                objKnowledge.Name = objSkill.Name;
                                objSkillControl.SkillObject = objKnowledge;

                                // Attach an EventHandler for the RatingChanged and SpecializationChanged Events.
                                objSkillControl.RatingChanged += objKnowledgeSkill_RatingChanged;
                                objSkillControl.SpecializationChanged += objSkill_SpecializationChanged;
                                objSkillControl.DeleteSkill += objKnowledgeSkill_DeleteSkill;
                                objSkillControl.SkillKarmaClicked += objKnowledgeSkill_KarmaClicked;
                                objSkillControl.DiceRollerClicked += objSkill_DiceRollerClicked;

                                objSkillControl.KnowledgeSkill = true;
                                objSkillControl.AllowDelete = true;
                                if (objSkill.Rating > 7)
                                    objSkillControl.SkillRatingMaximum = objSkill.Rating;
                                else
                                    objSkillControl.SkillRatingMaximum = 6;
                                objSkillControl.SkillRating = objSkill.Rating;
                                objSkillControl.SkillCategory = "Professional";
                                // Set the SkillControl's Location since scrolling the Panel causes it to actually change the child Controls' Locations.
                                objSkillControl.Location = new Point(0, objSkillControl.Height * i + panKnowledgeSkills.AutoScrollPosition.Y);
                                panKnowledgeSkills.Controls.Add(objSkillControl);

                                lstNewSkills.Add(objKnowledge);
                            }
                        }
                        foreach (Skill objSkill in lstNewSkills)
                            _objCharacter.Skills.Add(objSkill);
                    }

                    _objCharacter.MAGEnabled = false;
                    _objCharacter.MagicianEnabled = false;
                    _objCharacter.AdeptEnabled = false;
                }
                if (_objCharacter.RES.Value < 1)
                {
                    _objCharacter.RES.Value = 0;
                    _objCharacter.RES.MetatypeMinimum = 0;
                    _objCharacter.RES.MetatypeMinimum = 0;
                    _objCharacter.RES.MetatypeAugmentedMaximum = 0;

                    if (_objCharacter.RESEnabled)
                    {
                        // Move all RES-linked Active Skills to Knowledge Skills.
                        List<Skill> lstNewSkills = new List<Skill>();
                        foreach (Skill objSkill in _objCharacter.Skills)
                        {
                            if (objSkill.Attribute == "RES" && objSkill.Rating > 0)
                            {
                                int i = panKnowledgeSkills.Controls.Count;
                                Skill objKnowledge = new Skill(_objCharacter);

                                SkillControl objSkillControl = new SkillControl();
                                objKnowledge.Name = objSkill.Name;
                                objSkillControl.SkillObject = objKnowledge;

                                // Attach an EventHandler for the RatingChanged and SpecializationChanged Events.
                                objSkillControl.RatingChanged += objKnowledgeSkill_RatingChanged;
                                objSkillControl.SpecializationChanged += objSkill_SpecializationChanged;
                                objSkillControl.DeleteSkill += objKnowledgeSkill_DeleteSkill;
                                objSkillControl.SkillKarmaClicked += objKnowledgeSkill_KarmaClicked;
                                objSkillControl.DiceRollerClicked += objSkill_DiceRollerClicked;

                                objSkillControl.KnowledgeSkill = true;
                                objSkillControl.AllowDelete = true;
                                if (objSkill.Rating > 7)
                                    objSkillControl.SkillRatingMaximum = objSkill.Rating;
                                else
                                    objSkillControl.SkillRatingMaximum = 6;
                                objSkillControl.SkillRating = objSkill.Rating;
                                objSkillControl.SkillCategory = "Professional";
                                // Set the SkillControl's Location since scrolling the Panel causes it to actually change the child Controls' Locations.
                                objSkillControl.Location = new Point(0, objSkillControl.Height * i + panKnowledgeSkills.AutoScrollPosition.Y);
                                panKnowledgeSkills.Controls.Add(objSkillControl);

                                lstNewSkills.Add(objKnowledge);
                            }
                        }
                        foreach (Skill objSkill in lstNewSkills)
                            _objCharacter.Skills.Add(objSkill);
                    }

                    _objCharacter.RESEnabled = false;
                    _objCharacter.TechnomancerEnabled = false;
                }
            }

            _objFunctions.SortTree(treCyberware);
            treCyberware.SelectedNode = objNode;
            UpdateCharacterInfo();
            RefreshSelectedCyberware();
            PopulateGearList();

            if (frmPickCyberware.DialogResult != DialogResult.Cancel)
            {
                _blnIsDirty = true;
                UpdateWindowTitle();
            }

            return frmPickCyberware.AddAgain;
        }