示例#1
0
 /// <summary>
 /// ExpenseLogEntry Comparer.
 /// </summary>
 public static int CompareDate(ExpenseLogEntry x, ExpenseLogEntry y)
 {
     if (x == null)
     {
         if (y == null)
         {
             return(0);
         }
         else
         {
             return(-1);
         }
     }
     else
     {
         if (y == null)
         {
             return(1);
         }
         else
         {
             int intReturn = y.Date.CompareTo(x.Date);
             return(intReturn);
         }
     }
 }
示例#2
0
        /// <summary>
        /// Save the character as Created and re-open it in Career Mode.
        /// </summary>
        private void SaveCharacterAsCreated()
        {
            // If the character was built with Karma, record their staring Karma amount (if any).
            if (_objCharacter.BuildMethod == CharacterBuildMethod.Karma)
            {
                if (_objCharacter.Karma > 0)
                {
                    ExpenseLogEntry objKarma = new ExpenseLogEntry();
                    objKarma.Create(_objCharacter.Karma, "Starting Karma", ExpenseType.Karma, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objKarma);

                    // Create an Undo entry so that the starting Karma amount can be modified if needed.
                    ExpenseUndo objKarmaUndo = new ExpenseUndo();
                    objKarmaUndo.CreateKarma(KarmaExpenseType.ManualAdd, "");
                    objKarma.Undo = objKarmaUndo;
                }
            }

            // Create an Expense Entry for Starting Nuyen.
            ExpenseLogEntry objNuyen = new ExpenseLogEntry();
            objNuyen.Create(_objCharacter.Nuyen, "Starting Nuyen", ExpenseType.Nuyen, DateTime.Now);
            _objCharacter.ExpenseEntries.Add(objNuyen);

            // Create an Undo entry so that the Starting Nuyen amount can be modified if needed.
            ExpenseUndo objNuyenUndo = new ExpenseUndo();
            objNuyenUndo.CreateNuyen(NuyenExpenseType.ManualAdd, "");
            objNuyen.Undo = objNuyenUndo;

            _blnSkipToolStripRevert = true;
            _objCharacter.Save();

            GlobalOptions.Instance.MainForm.LoadCharacter(_objCharacter.FileName, false);
            this.Close();
        }
示例#3
0
        private void cmdChangeSpec_Click(object sender, EventArgs e)
        {
            if (_objSkill.CharacterObject.Karma < _objSkill.CharacterObject.Options.KarmaSpecialization)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            XmlDocument objXmlDocument = new XmlDocument();

            objXmlDocument = XmlManager.Instance.Load("skills.xml");

            // When the selected Knowledge Skill is changed, check the Skill file and build the pre-defined list of its Specializations (if any).
            List <ListItem> lstSpecializations = new List <ListItem>();
            XmlNode         objXmlSkill;

            if (_objSkill.KnowledgeSkill)
            {
                objXmlSkill = objXmlDocument.SelectSingleNode("/chummer/knowledgeskills/skill[name = \"" + _objSkill.Name + "\"]");
                if (objXmlSkill == null)
                {
                    objXmlSkill = objXmlDocument.SelectSingleNode("/chummer/knowledgeskills/skill[translate = \"" + _objSkill.Name + "\"]");
                }
            }
            else
            {
                objXmlSkill = objXmlDocument.SelectSingleNode("/chummer/skills/skill[name = \"" + _objSkill.Name + "\"]");
                if (objXmlSkill == null)
                {
                    objXmlSkill = objXmlDocument.SelectSingleNode("/chummer/skills/skill[translate = \"" + _objSkill.Name + "\"]");
                }
            }
            if (objXmlSkill != null)
            {
                if (!_blnSkipRefresh)
                {
                    cboKnowledgeSkillCategory.SelectedValue = objXmlSkill["category"].InnerText;
                }
                cboSpec.Items.Clear();
                foreach (XmlNode objXmlSpecialization in objXmlSkill.SelectNodes("specs/spec"))
                {
                    bool blnFound = false;
                    foreach (SkillSpecialization objSpecialization in _objSkill.Specializations)
                    {
                        if (objSpecialization.Name == objXmlSpecialization.InnerText)
                        {
                            blnFound = true;
                            break;
                        }
                    }
                    if (!blnFound)
                    {
                        ListItem objItem = new ListItem();
                        if (objXmlSpecialization["translate"] != null)
                        {
                            objItem.Name = objXmlSpecialization["translate"].InnerText;
                        }
                        else
                        {
                            objItem.Name = objXmlSpecialization.InnerText;
                        }
                        objItem.Value = objItem.Name;
                        lstSpecializations.Add(objItem);
                    }
                }
            }

            if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseSkillSpecialization").Replace("{0}", _objSkill.CharacterObject.Options.KarmaSpecialization.ToString())))
            {
                return;
            }

            frmSelectItem frmPickItem = new frmSelectItem();

            frmPickItem.DropdownItems = lstSpecializations;
            frmPickItem.ShowDialog();

            if (frmPickItem.DialogResult == DialogResult.Cancel)
            {
                return;
            }

            string strSelectedValue = frmPickItem.SelectedItem;

            // charge the karma and add the spec
            SkillSpecialization objSpec = new SkillSpecialization(strSelectedValue);

            _objSkill.Specializations.Add(objSpec);

            // Create the Expense Log Entry.
            ExpenseLogEntry objEntry = new ExpenseLogEntry();

            objEntry.Create(_objSkill.CharacterObject.Options.KarmaSpecialization * -1, LanguageManager.Instance.GetString("String_ExpenseLearnSpecialization") + " " + _objSkill.Name + " (" + strSelectedValue + ")", ExpenseType.Karma, DateTime.Now);
            _objSkill.CharacterObject.ExpenseEntries.Add(objEntry);
            _objSkill.CharacterObject.Karma -= _objSkill.CharacterObject.Options.KarmaSpecialization;

            ExpenseUndo objUndo = new ExpenseUndo();

            objUndo.CreateKarma(KarmaExpenseType.AddSpecialization, objSpec.InternalId);
            objEntry.Undo = objUndo;

            lblSpec.Text = _objSkill.Specialization;

            this.Height = lblSpec.Height + 10;

            RatingChanged(this);
        }
示例#4
0
        private void cmdQuickenSpell_Click(object sender, EventArgs e)
        {
            try
            {
                if (treSpells.SelectedNode.Level != 1)
                    return;
            }
            catch
            {
                return;
            }

            frmSelectNumber frmPickNumber = new frmSelectNumber();
            frmPickNumber.Description = LanguageManager.Instance.GetString("String_QuickeningKarma").Replace("{0}", treSpells.SelectedNode.Text);
            frmPickNumber.Minimum = 1;
            frmPickNumber.ShowDialog(this);

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

            // Make sure the character has enough Karma to improve the Attribute.
            int intKarmaCost = frmPickNumber.SelectedValue;
            if (intKarmaCost > _objCharacter.Karma)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseQuickeningMetamagic").Replace("{0}", intKarmaCost.ToString()).Replace("{1}", treSpells.SelectedNode.Text)))
                return;

            // Create the Karma expense.
            ExpenseLogEntry objExpense = new ExpenseLogEntry();
            objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseQuickenMetamagic") + " " + treSpells.SelectedNode.Text, ExpenseType.Karma, DateTime.Now);
            _objCharacter.ExpenseEntries.Add(objExpense);
            _objCharacter.Karma -= intKarmaCost;

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateKarma(KarmaExpenseType.QuickeningMetamagic, "");
            objExpense.Undo = objUndo;

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#5
0
        private void cmdNuyenGained_Click(object sender, EventArgs e)
        {
            frmExpense frmNewExpense = new frmExpense();
            frmNewExpense.Mode = ExpenseType.Nuyen;
            frmNewExpense.ShowDialog(this);

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

            // Create the Expense Log Entry.
            ExpenseLogEntry objEntry = new ExpenseLogEntry();
            objEntry.Create(frmNewExpense.Amount, frmNewExpense.strReason, ExpenseType.Nuyen, frmNewExpense.SelectedDate);
            objEntry.Refund = frmNewExpense.Refund;
            _objCharacter.ExpenseEntries.Add(objEntry);

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateNuyen(NuyenExpenseType.ManualAdd, "");
            objEntry.Undo = objUndo;

            // Adjust the character's Nuyen total.
            _objCharacter.Nuyen += frmNewExpense.Amount;

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#6
0
        private void cmdIncreaseLifestyleMonths_Click(object sender, EventArgs e)
        {
            try
            {
                if (treLifestyles.SelectedNode == null)
                    return;
            }
            catch
            {
                return;
            }

            // Locate the selected Lifestyle.
            Lifestyle objLifestyle = _objFunctions.FindLifestyle(treLifestyles.SelectedNode.Tag.ToString(), _objCharacter.Lifestyles);
            if (objLifestyle == null)
                return;

            // Create the Expense Log Entry.
            int intAmount = objLifestyle.TotalMonthlyCost;
            if (intAmount > _objCharacter.Nuyen)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            ExpenseLogEntry objExpense = new ExpenseLogEntry();
            objExpense.Create(intAmount * -1, LanguageManager.Instance.GetString("String_ExpenseLifestyle") + " " + objLifestyle.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
            _objCharacter.ExpenseEntries.Add(objExpense);
            _objCharacter.Nuyen -= intAmount;

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateNuyen(NuyenExpenseType.IncreaseLifestyle, objLifestyle.Name);
            objExpense.Undo = objUndo;

            objLifestyle.Months += 1;
            lblLifestyleMonths.Text = objLifestyle.Months.ToString();

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#7
0
        private void cmdImproveRES_Click(object sender, EventArgs e)
        {
            // Make sure the character has enough Karma to improve the Attribute.
            int intKarmaCost = 0;
            if (!_objOptions.SpecialKarmaCostBasedOnShownValue)
                intKarmaCost = (_objCharacter.RES.Value + _objCharacter.RES.AttributeValueModifiers + 1) * _objOptions.KarmaAttribute;
            else
                intKarmaCost = (_objCharacter.RES.Value - _objCharacter.EssencePenalty + 1) * _objOptions.KarmaAttribute;

            if (intKarmaCost > _objCharacter.Karma)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            int intFromValue = 0;
            if (!_objOptions.SpecialKarmaCostBasedOnShownValue)
                intFromValue = _objCharacter.RES.Value + _objCharacter.RES.AttributeValueModifiers;
            else
                intFromValue = _objCharacter.RES.Value - _objCharacter.EssencePenalty;

            if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpense").Replace("{0}", LanguageManager.Instance.GetString("String_AttributeRESShort")).Replace("{1}", (intFromValue + 1).ToString()).Replace("{2}", intKarmaCost.ToString())))
                return;

            // Create the Karma expense.
            ExpenseLogEntry objExpense = new ExpenseLogEntry();
            objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseAttribute") + " " + LanguageManager.Instance.GetString("String_AttributeRESShort") + " " + (intFromValue).ToString() + " -> " + (intFromValue + 1).ToString(), ExpenseType.Karma, DateTime.Now);
            _objCharacter.ExpenseEntries.Add(objExpense);
            _objCharacter.Karma -= intKarmaCost;

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateKarma(KarmaExpenseType.ImproveAttribute, "RES");
            objExpense.Undo = objUndo;

            _objCharacter.RES.Value += 1;

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#8
0
        private void cmdImproveComplexForm_Click(object sender, EventArgs e)
        {
            if (treComplexForms.SelectedNode.Level == 1)
            {
                // Locate the Program that is selected in the tree.
                ComplexForm objProgram = _objFunctions.FindComplexForm(treComplexForms.SelectedNode.Tag.ToString(), _objCharacter.ComplexForms);

                // Make sure the character has enough Karma.
                int intKarmaCost = _objOptions.KarmaImproveComplexForm;

                if (intKarmaCost > _objCharacter.Karma)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseSpend").Replace("{0}", intKarmaCost.ToString()).Replace("{1}", objProgram.DisplayNameShort)))
                    return;

                // Create the Expense Log Entry.
                ExpenseLogEntry objExpense = new ExpenseLogEntry();
                objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseComplexForm") + " " + objProgram.DisplayNameShort, ExpenseType.Karma, DateTime.Now);
                _objCharacter.ExpenseEntries.Add(objExpense);
                _objCharacter.Karma -= intKarmaCost;

                ExpenseUndo objUndo = new ExpenseUndo();
                objUndo.CreateKarma(KarmaExpenseType.ImproveComplexForm, objProgram.InternalId);
                objExpense.Undo = objUndo;

                treComplexForms.SelectedNode.Text = objProgram.DisplayName;
            }

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#9
0
        private void tsWeaponSell_Click(object sender, EventArgs e)
        {
            // Delete the selected Weapon.
            try
            {
                if (treWeapons.SelectedNode.Level == 1)
                {
                    Weapon objWeapon = new Weapon(_objCharacter);
                    // Locate the Weapon that is selected in the tree.
                    foreach (Weapon objCharacterWeapon in _objCharacter.Weapons)
                    {
                        if (objCharacterWeapon.InternalId == treWeapons.SelectedNode.Tag.ToString())
                        {
                            objWeapon = objCharacterWeapon;
                            break;
                        }
                    }

                    // Cyberweapons cannot be removed through here and must be done by removing the piece of Cyberware.
                    if (objWeapon.Cyberware)
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotRemoveCyberweapon"), LanguageManager.Instance.GetString("MessageTitle_CannotRemoveCyberweapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    if (objWeapon.Category == "Gear")
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotRemoveGearWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotRemoveGearWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    if (objWeapon.Category.StartsWith("Quality"))
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotRemoveQualityWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotRemoveQualityWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    frmSellItem frmSell = new frmSellItem();
                    frmSell.ShowDialog(this);

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

                    // Create the Expense Log Entry for the sale.
                    int intAmount = Convert.ToInt32(Convert.ToDouble(objWeapon.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldWeapon") + " " + objWeapon.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen += intAmount;

                    _objCharacter.Weapons.Remove(objWeapon);
                    treWeapons.SelectedNode.Remove();
                }
                else if (treWeapons.SelectedNode.Level > 1)
                {
                    Weapon objWeapon = new Weapon(_objCharacter);
                    // Locate the Weapon that is selected in the tree.
                    foreach (Weapon objCharacterWeapon in _objCharacter.Weapons)
                    {
                        if (objCharacterWeapon.InternalId == treWeapons.SelectedNode.Parent.Tag.ToString())
                        {
                            objWeapon = objCharacterWeapon;
                            break;
                        }
                    }

                    WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
                    // Locate the Accessory that is selected in the tree.
                    foreach (WeaponAccessory objCharacterAccessory in objWeapon.WeaponAccessories)
                    {
                        if (objCharacterAccessory.InternalId == treWeapons.SelectedNode.Tag.ToString())
                        {
                            objAccessory = objCharacterAccessory;
                            break;
                        }
                    }

                    if (objAccessory.Name != "")
                    {
                        frmSellItem frmSell = new frmSellItem();
                        frmSell.ShowDialog(this);

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

                        // Record the Weapon's original cost.
                        int intOriginal = objWeapon.TotalCost;

                        objWeapon.WeaponAccessories.Remove(objAccessory);
                        treWeapons.SelectedNode.Remove();

                        int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objWeapon.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                        objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldWeaponAccessory") + " " + objAccessory.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objExpense);
                        _objCharacter.Nuyen += intAmount;
                    }

                    WeaponMod objMod = new WeaponMod(_objCharacter);
                    // Locate the Mod that is selected in the tree.
                    foreach (WeaponMod objCharacterMod in objWeapon.WeaponMods)
                    {
                        if (objCharacterMod.InternalId == treWeapons.SelectedNode.Tag.ToString())
                        {
                            objMod = objCharacterMod;
                            break;
                        }
                    }

                    if (objMod.Name != "")
                    {
                        frmSellItem frmSell = new frmSellItem();
                        frmSell.ShowDialog(this);

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

                        // Record the Weapon's original cost.
                        int intOriginal = objWeapon.TotalCost;

                        objWeapon.WeaponMods.Remove(objMod);
                        treWeapons.SelectedNode.Remove();

                        int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objWeapon.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                        objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldWeaponMod") + " " + objMod.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objExpense);
                        _objCharacter.Nuyen += intAmount;
                    }
                    else
                    {
                        frmSellItem frmSell = new frmSellItem();
                        frmSell.ShowDialog(this);

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

                        // Find the selected Gear.
                        Gear objGear = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objAccessory);
                        _objFunctions.DeleteGear(objGear, treWeapons, _objImprovementManager);
                        if (objGear.Parent == null)
                            objAccessory.Gear.Remove(objGear);
                        else
                            objGear.Parent.Children.Remove(objGear);
                        treWeapons.SelectedNode.Remove();

                        int intAmount = Convert.ToInt32(Convert.ToDouble(objGear.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                        objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldWeaponGear") + " " + objGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objExpense);
                        _objCharacter.Nuyen += intAmount;
                    }
                }
                UpdateCharacterInfo();
                RefreshSelectedWeapon();

                _blnIsDirty = true;
                UpdateWindowTitle();
            }
            catch
            {
            }
        }
示例#10
0
        private void tsWeaponAddModification_Click(object sender, EventArgs e)
        {
            // Make sure a parent item is selected, then open the Select Accessory window.
            try
            {
                if (treWeapons.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectWeaponMod"), LanguageManager.Instance.GetString("MessageTitle_SelectWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectWeaponMod"), LanguageManager.Instance.GetString("MessageTitle_SelectWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Locate the Weapon that is selected in the Tree.
            Weapon objWeapon = _objFunctions.FindWeapon(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);

            frmSelectVehicleMod frmPickVehicleMod = new frmSelectVehicleMod(_objCharacter, true);

            // Make sure the Weapon allows Modifications to be added to it.
            // Open the Weapons XML file and locate the selected Weapon.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("weapons.xml");
            XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objWeapon.Name + "\"]");

            if (objXmlWeapon == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeaponMod"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (objXmlWeapon["allowmod"] != null)
            {
                if (objXmlWeapon["allowmod"].InnerText == "false")
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeaponMod"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }

            // Set the Weapon properties for the window.
            frmPickVehicleMod.WeaponCost = objWeapon.Cost;
            frmPickVehicleMod.TotalWeaponCost = objWeapon.TotalCost;
            frmPickVehicleMod.ModMultiplier = objWeapon.ModMultiplier;
            frmPickVehicleMod.InputFile = "weapons";

            frmPickVehicleMod.ShowDialog(this);

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

            // Locate the selected piece.
            XmlNode objXmlMod = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + frmPickVehicleMod.SelectedMod + "\"]");

            TreeNode objNode = new TreeNode();
            WeaponMod objMod = new WeaponMod(_objCharacter);
            objMod.Create(objXmlMod, objNode);
            objMod.Rating = frmPickVehicleMod.SelectedRating;
            objMod.Parent = objWeapon;

            // Do not allow the user to add a new Weapon Mod if the Weapon's Capacity has been reached.
            if (_objOptions.EnforceCapacity && objWeapon.SlotsRemaining - objMod.Slots < 0)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (frmPickVehicleMod.AddAgain)
                    tsWeaponAddModification_Click(sender, e);
                return;
            }

            // Check the item's Cost and make sure the character can afford it.
            int intOriginalCost = objWeapon.TotalCost;
            objWeapon.WeaponMods.Add(objMod);

            int intCost = objWeapon.TotalCost - intOriginalCost;
            // Apply a markup if applicable.
            if (frmPickVehicleMod.Markup != 0)
            {
                double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo);
                dblCost *= 1 + (Convert.ToDouble(frmPickVehicleMod.Markup, GlobalOptions.Instance.CultureInfo) / 100.0);
                intCost = Convert.ToInt32(dblCost);
            }

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

            if (!frmPickVehicleMod.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    objWeapon.WeaponMods.Remove(objMod);
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (frmPickVehicleMod.AddAgain)
                        tsWeaponAddModification_Click(sender, e);

                    return;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseWeaponMod") + " " + objMod.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddWeaponMod, objMod.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            objNode.Text = objMod.DisplayName;
            objNode.ContextMenuStrip = cmsWeaponMod;

            treWeapons.SelectedNode.Nodes.Add(objNode);
            treWeapons.SelectedNode.Expand();

            UpdateCharacterInfo();
            RefreshSelectedWeapon();

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickVehicleMod.AddAgain)
                tsWeaponAddModification_Click(sender, e);
        }
示例#11
0
        private void tsWeaponAddAccessory_Click(object sender, EventArgs e)
        {
            // Make sure a parent item is selected, then open the Select Accessory window.
            try
            {
                if (treWeapons.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectWeaponAccessory"), LanguageManager.Instance.GetString("MessageTitle_SelectWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectWeaponAccessory"), LanguageManager.Instance.GetString("MessageTitle_SelectWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Locate the Weapon that is selected in the Tree.
            Weapon objWeapon = _objFunctions.FindWeapon(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);

            // Accessories cannot be added to Cyberweapons.
            if (objWeapon.Cyberware)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CyberweaponNoAccessory"), LanguageManager.Instance.GetString("MessageTitle_CyberweaponNoAccessory"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Open the Weapons XML file and locate the selected Weapon.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("weapons.xml");

            XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objWeapon.Name + "\"]");

            frmSelectWeaponAccessory frmPickWeaponAccessory = new frmSelectWeaponAccessory(_objCharacter, true);

            if (objXmlWeapon == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Make sure the Weapon allows Accessories to be added to it.
            if (!Convert.ToBoolean(objXmlWeapon["allowaccessory"].InnerText))
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                XmlNodeList objXmlMountList = objXmlWeapon.SelectNodes("accessorymounts/mount");
                string strMounts = "";
                foreach (XmlNode objXmlMount in objXmlMountList)
                    strMounts += objXmlMount.InnerText + "/";

                frmPickWeaponAccessory.AllowedMounts = strMounts;
            }

            frmPickWeaponAccessory.WeaponCost = objWeapon.Cost;
            frmPickWeaponAccessory.AccessoryMultiplier = objWeapon.AccessoryMultiplier;
            frmPickWeaponAccessory.ShowDialog();

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

            // Locate the selected piece.
            objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + frmPickWeaponAccessory.SelectedAccessory + "\"]");

            TreeNode objNode = new TreeNode();
            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
            objAccessory.Create(objXmlWeapon, objNode, frmPickWeaponAccessory.SelectedMount);
            objAccessory.Parent = objWeapon;

            if (objAccessory.Cost.StartsWith("Variable"))
            {
                int intMin = 0;
                int intMax = 0;
                string strCost = objAccessory.Cost.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}", objAccessory.DisplayNameShort);
                    frmPickNumber.AllowCancel = false;
                    frmPickNumber.ShowDialog();
                    objAccessory.Cost = frmPickNumber.SelectedValue.ToString();
                }
            }

            // Check the item's Cost and make sure the character can afford it.
            int intOriginalCost = objWeapon.TotalCost;
            objWeapon.WeaponAccessories.Add(objAccessory);

            int intCost = objWeapon.TotalCost - intOriginalCost;
            // Apply a markup if applicable.
            if (frmPickWeaponAccessory.Markup != 0)
            {
                double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo);
                dblCost *= 1 + (Convert.ToDouble(frmPickWeaponAccessory.Markup, GlobalOptions.Instance.CultureInfo) / 100.0);
                intCost = Convert.ToInt32(dblCost);
            }

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

            if (!frmPickWeaponAccessory.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    objWeapon.WeaponAccessories.Remove(objAccessory);
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (frmPickWeaponAccessory.AddAgain)
                        tsWeaponAddAccessory_Click(sender, e);

                    return;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseWeaponAccessory") + " " + objAccessory.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddWeaponAccessory, objAccessory.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            objNode.ContextMenuStrip = cmsWeaponAccessory;
            treWeapons.SelectedNode.Nodes.Add(objNode);
            treWeapons.SelectedNode.Expand();

            UpdateCharacterInfo();
            RefreshSelectedWeapon();

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickWeaponAccessory.AddAgain)
                tsWeaponAddAccessory_Click(sender, e);
        }
示例#12
0
        private void tsWeaponAccessoryGearMenuAddAsPlugin_Click(object sender, EventArgs e)
        {
            // Locate the Vehicle Sensor Gear.
            bool blnFound = false;
            WeaponAccessory objFoundAccessory = new WeaponAccessory(_objCharacter);
            Gear objSensor = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objFoundAccessory);
            if (objSensor != null)
                blnFound = true;

            // Make sure the Gear was found.
            if (!blnFound)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_ModifyVehicleGear"), LanguageManager.Instance.GetString("MessageTitle_SelectGear"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");

            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objSensor.Name + "\" and category = \"" + objSensor.Category + "\"]");

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, true);
            //frmPickGear.ShowNegativeCapacityOnly = true;

            if (objXmlGear.InnerXml.Contains("<addoncategory>"))
            {
                string strCategories = "";
                foreach (XmlNode objXmlCategory in objXmlGear.SelectNodes("addoncategory"))
                    strCategories += objXmlCategory.InnerText + ",";
                // Remove the trailing comma.
                strCategories = strCategories.Substring(0, strCategories.Length - 1);
                frmPickGear.AddCategory(strCategories);
            }

            if (frmPickGear.AllowedCategories != "")
                frmPickGear.AllowedCategories += objSensor.Category + ",";

            frmPickGear.ShowDialog(this);

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

            // Open the Gear XML file and locate the selected piece.
            objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            TreeNode objNode = new TreeNode();
            Gear objGear = new Gear(_objCharacter);

            switch (frmPickGear.SelectedCategory)
            {
                case "Commlinks":
                case "Cyberdecks":
                case "Rigger Command Consoles":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objCommlink.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objCommlink.DisplayName;

                    objGear = objCommlink;
                    break;
                default:
                    Gear objNewGear = new Gear(_objCharacter);
                    objNewGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic);
                    objNewGear.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objNewGear.DisplayName;

                    objGear = objNewGear;
                    break;
            }

            if (objGear.InternalId == Guid.Empty.ToString())
                return;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objGear.Cost = (Convert.ToDouble(objGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objGear.Cost != "")
                    objGear.Cost = "(" + objGear.Cost + ") * 0.1";
                if (objGear.Cost3 != "")
                    objGear.Cost3 = "(" + objGear.Cost3 + ") * 0.1";
                if (objGear.Cost6 != "")
                    objGear.Cost6 = "(" + objGear.Cost6 + ") * 0.1";
                if (objGear.Cost10 != "")
                    objGear.Cost10 = "(" + objGear.Cost10 + ") * 0.1";
                if (objGear.Extra == "")
                    objGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objGear.Cost = "0";
                objGear.Cost3 = "0";
                objGear.Cost6 = "0";
                objGear.Cost10 = "0";
            }

            objNode.Text = objGear.DisplayName;

            int intCost = objGear.TotalCost;

            // Multiply the cost if applicable.
            if (objGear.TotalAvail().EndsWith(LanguageManager.Instance.GetString("String_AvailRestricted")) && _objOptions.MultiplyRestrictedCost)
                intCost *= _objOptions.RestrictedCostMultiplier;
            if (objGear.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 (!frmPickGear.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    _objFunctions.DeleteGear(objGear, treWeapons, _objImprovementManager);
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (frmPickGear.AddAgain)
                        tsVehicleSensorAddAsPlugin_Click(sender, e);

                    return;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseWeaponGear") + " " + objGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddWeaponGear, objGear.InternalId, frmPickGear.SelectedQty);
                    objExpense.Undo = objUndo;
                }
            }

            objNode.ContextMenuStrip = cmsCyberwareGear;

            treWeapons.SelectedNode.Nodes.Add(objNode);
            treWeapons.SelectedNode.Expand();

            objGear.Parent = objSensor;
            objSensor.Children.Add(objGear);

            if (frmPickGear.AddAgain)
                tsWeaponAccessoryGearMenuAddAsPlugin_Click(sender, e);

            UpdateCharacterInfo();
            RefreshSelectedWeapon();
        }
示例#13
0
        private void tsVehicleSell_Click(object sender, EventArgs e)
        {
            // Delete the selected Vehicle.
            try
            {
                if (treVehicles.SelectedNode.Level == 1)
                {
                    Vehicle objVehicle = new Vehicle(_objCharacter);
                    // Locate the Vehicle that is selected in the tree.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        if (objCharacterVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString())
                        {
                            objVehicle = objCharacterVehicle;
                            break;
                        }
                    }

                    frmSellItem frmSell = new frmSellItem();
                    frmSell.ShowDialog(this);

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

                    // Create the Expense Log Entry for the sale.
                    int intAmount = Convert.ToInt32(Convert.ToDouble(objVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicle") + " " + objVehicle.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen += intAmount;

                    _objCharacter.Vehicles.Remove(objVehicle);
                    treVehicles.SelectedNode.Remove();
                }
                else if (treVehicles.SelectedNode.Level == 2)
                {
                    // Locate the VehicleMod that is selected in the tree.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                        {
                            if (objMod.InternalId == treVehicles.SelectedNode.Tag.ToString())
                            {
                                // Do not allow VehicleMods that come with a Vehicle to be removed.
                                if (objMod.IncludedInVehicle)
                                {
                                    MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotRemoveVehicleMod"), LanguageManager.Instance.GetString("MessageTitle_CannotRemoveVehicleMod"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    return;
                                }
                                else
                                {
                                    frmSellItem frmSell = new frmSellItem();
                                    frmSell.ShowDialog(this);

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

                                    // Record the original value of the Vehicle.
                                    int intOriginal = objCharacterVehicle.TotalCost;

                                    // Check for Improved Sensor bonus.
                                    if (objMod.Bonus != null)
                                    {
                                        if (objMod.Bonus["improvesensor"] != null)
                                        {
                                            ChangeVehicleSensor(objCharacterVehicle, false);
                                        }
                                    }

                                    objCharacterVehicle.Mods.Remove(objMod);
                                    treVehicles.SelectedNode.Remove();

                                    // Create the Expense Log Entry for the sale.
                                    int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objCharacterVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                                    objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleMod") + " " + objMod.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                                    _objCharacter.ExpenseEntries.Add(objExpense);
                                    _objCharacter.Nuyen += intAmount;
                                }
                                break;
                            }
                        }
                    }

                    // Locate the Sensor or Ammunition that is selected in the tree.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (Gear objGear in objCharacterVehicle.Gear)
                        {
                            if (objGear.InternalId == treVehicles.SelectedNode.Tag.ToString())
                            {
                                frmSellItem frmSell = new frmSellItem();
                                frmSell.ShowDialog(this);

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

                                // Record the original value of the vehicle.
                                int intOriginal = objCharacterVehicle.TotalCost;

                                // Remove the Gear Weapon created by the Gear if applicable.
                                if (objGear.WeaponID != Guid.Empty.ToString())
                                {
                                    // Remove the Weapon from the TreeView.
                                    foreach (TreeNode objWeaponNode in treVehicles.SelectedNode.Parent.Nodes)
                                    {
                                        if (objWeaponNode.Tag.ToString() == objGear.WeaponID)
                                        {
                                            treVehicles.SelectedNode.Parent.Nodes.Remove(objWeaponNode);
                                            break;
                                        }
                                    }

                                    // Remove the Weapon from the Vehicle.
                                    Weapon objRemoveWeapon = new Weapon(_objCharacter);
                                    foreach (Weapon objWeapon in objCharacterVehicle.Weapons)
                                    {
                                        if (objWeapon.InternalId == objGear.WeaponID)
                                            objRemoveWeapon = objWeapon;
                                    }
                                    objCharacterVehicle.Weapons.Remove(objRemoveWeapon);
                                }

                                objCharacterVehicle.Gear.Remove(objGear);
                                treVehicles.SelectedNode.Remove();

                                // Create the Expense Log Entry for the sale.
                                int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objCharacterVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                                ExpenseLogEntry objExpense = new ExpenseLogEntry();
                                objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleGear") + " " + objGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                                _objCharacter.ExpenseEntries.Add(objExpense);
                                _objCharacter.Nuyen += intAmount;

                                break;
                            }
                        }
                    }

                    // Locate the Weapon that is selected in the tree.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (Weapon objWeapon in objCharacterVehicle.Weapons)
                        {
                            if (objWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                            {
                                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotRemoveGearWeaponVehicle"), LanguageManager.Instance.GetString("MessageTitle_CannotRemoveGearWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                                break;
                            }
                        }
                    }
                }
                else if (treVehicles.SelectedNode.Level == 3)
                {
                    // Locate the selected VehicleWeapon that is selected in the tree.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                        {
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                if (objWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    frmSellItem frmSell = new frmSellItem();
                                    frmSell.ShowDialog(this);

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

                                    // Record the original value of the Vehicle.
                                    int intOriginal = objCharacterVehicle.TotalCost;

                                    objMod.Weapons.Remove(objWeapon);
                                    treVehicles.SelectedNode.Remove();

                                    // Create the Expense Log Entry for the sale.
                                    int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objCharacterVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                                    objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleWeapon") + " " + objWeapon.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                                    _objCharacter.ExpenseEntries.Add(objExpense);
                                    _objCharacter.Nuyen += intAmount;

                                    break;
                                }
                            }
                        }
                    }

                    // Locate the selected Sensor Plugin.
                    // Locate the Sensor that is selected in the tree.
                    Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                    Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                    if (objGear != null)
                    {
                        frmSellItem frmSell = new frmSellItem();
                        frmSell.ShowDialog(this);

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

                        // Record the original value of the Vehicle.
                        int intOriginal = objFoundVehicle.TotalCost;

                        objGear.Parent.Children.Remove(objGear);
                        treVehicles.SelectedNode.Remove();

                        // Create the Expense Log Entry for the sale.
                        int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objFoundVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                        objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleGear") + " " + objGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objExpense);
                        _objCharacter.Nuyen += intAmount;
                    }

                    // Locate the selected Cyberware.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                        {
                            foreach (Cyberware objCyberware in objMod.Cyberware)
                            {
                                if (objCyberware.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    frmSellItem frmSell = new frmSellItem();
                                    frmSell.ShowDialog(this);

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

                                    // Record the original value of the Vehicle.
                                    int intOriginal = objCharacterVehicle.TotalCost;

                                    objMod.Cyberware.Remove(objCyberware);
                                    treVehicles.SelectedNode.Remove();

                                    // Create the Expense Log Entry for the sale.
                                    int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objCharacterVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                                    objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleCyberware") + " " + objCyberware.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                                    _objCharacter.ExpenseEntries.Add(objExpense);
                                    _objCharacter.Nuyen += intAmount;

                                    break;
                                }
                            }
                        }
                    }
                }
                else if (treVehicles.SelectedNode.Level == 4)
                {
                    // Locate the selected WeaponAccessory or VehicleWeaponMod that is selected in the tree.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                        {
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                                {
                                    if (objAccessory.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                    {
                                        frmSellItem frmSell = new frmSellItem();
                                        frmSell.ShowDialog(this);

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

                                        // Record the original value of the Vehicle.
                                        int intOriginal = objCharacterVehicle.TotalCost;

                                        objWeapon.WeaponAccessories.Remove(objAccessory);
                                        treVehicles.SelectedNode.Remove();

                                        // Create the Expense Log Entry for the sale.
                                        int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objCharacterVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                                        objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleWeaponAccessory") + " " + objAccessory.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                                        _objCharacter.ExpenseEntries.Add(objExpense);
                                        _objCharacter.Nuyen += intAmount;

                                        break;
                                    }
                                }
                                foreach (WeaponMod objWeaponMod in objWeapon.WeaponMods)
                                {
                                    if (objWeaponMod.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                    {
                                        frmSellItem frmSell = new frmSellItem();
                                        frmSell.ShowDialog(this);

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

                                        // Record tthe original value of the Vehicle.
                                        int intOriginal = objCharacterVehicle.TotalCost;

                                        objWeapon.WeaponMods.Remove(objWeaponMod);
                                        treVehicles.SelectedNode.Remove();

                                        // Create the Expense Log Entry for the sale.
                                        int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objCharacterVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                                        objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleWeaponMod") + " " + objMod.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                                        _objCharacter.ExpenseEntries.Add(objExpense);
                                        _objCharacter.Nuyen += intAmount;

                                        break;
                                    }
                                }
                                if (objWeapon.UnderbarrelWeapons.Count > 0)
                                {
                                    foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                    {
                                        if (objUnderbarrelWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                        {
                                            frmSellItem frmSell = new frmSellItem();
                                            frmSell.ShowDialog(this);

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

                                            // Record the original value of the Vehicle.
                                            int intOriginal = objCharacterVehicle.TotalCost;

                                            objWeapon.UnderbarrelWeapons.Remove(objUnderbarrelWeapon);
                                            treVehicles.SelectedNode.Remove();

                                            // Create the Expense Log Entry for the sale.
                                            int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objCharacterVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                                            ExpenseLogEntry objExpense = new ExpenseLogEntry();
                                            objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleWeapon") + " " + objMod.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                                            _objCharacter.ExpenseEntries.Add(objExpense);
                                            _objCharacter.Nuyen += intAmount;

                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Locate the selected Sensor Plugin.
                    // Locate the Sensor that is selected in the tree.
                    Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                    Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                    if (objGear != null)
                    {
                        frmSellItem frmSell = new frmSellItem();
                        frmSell.ShowDialog(this);

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

                        // Record the original value of the Vehicle.
                        int intOriginal = objFoundVehicle.TotalCost;

                        objGear.Parent.Children.Remove(objGear);
                        treVehicles.SelectedNode.Remove();
                        _objFunctions.DeleteVehicleGear(objGear, treVehicles, objFoundVehicle);

                        // Create the Expense Log Entry for the sale.
                        int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objFoundVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                        objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleGear") + " " + objGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objExpense);
                        _objCharacter.Nuyen += intAmount;
                    }
                }
                else if (treVehicles.SelectedNode.Level == 5)
                {
                    // Locate the selected WeaponAccessory or VehicleWeaponMod that is selected in the tree.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                        {
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                if (objWeapon.UnderbarrelWeapons.Count > 0)
                                {
                                    foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                    {
                                        foreach (WeaponAccessory objAccessory in objUnderbarrelWeapon.WeaponAccessories)
                                        {
                                            if (objAccessory.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                            {
                                                frmSellItem frmSell = new frmSellItem();
                                                frmSell.ShowDialog(this);

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

                                                // Record the original value of the Vehicle.
                                                int intOriginal = objCharacterVehicle.TotalCost;

                                                objUnderbarrelWeapon.WeaponAccessories.Remove(objAccessory);
                                                treVehicles.SelectedNode.Remove();

                                                // Create the Expense Log Entry for the sale.
                                                int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objCharacterVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                                                ExpenseLogEntry objExpense = new ExpenseLogEntry();
                                                objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleWeaponAccessory") + " " + objAccessory.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                                                _objCharacter.ExpenseEntries.Add(objExpense);
                                                _objCharacter.Nuyen += intAmount;

                                                break;
                                            }
                                        }
                                        foreach (WeaponMod objWeaponMod in objUnderbarrelWeapon.WeaponMods)
                                        {
                                            if (objWeaponMod.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                            {
                                                frmSellItem frmSell = new frmSellItem();
                                                frmSell.ShowDialog(this);

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

                                                // Record tthe original value of the Vehicle.
                                                int intOriginal = objCharacterVehicle.TotalCost;

                                                objUnderbarrelWeapon.WeaponMods.Remove(objWeaponMod);
                                                treVehicles.SelectedNode.Remove();

                                                // Create the Expense Log Entry for the sale.
                                                int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objCharacterVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                                                ExpenseLogEntry objExpense = new ExpenseLogEntry();
                                                objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleWeaponMod") + " " + objMod.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                                                _objCharacter.ExpenseEntries.Add(objExpense);
                                                _objCharacter.Nuyen += intAmount;

                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Locate the selected Sensor Plugin.
                    // Locate the Sensor that is selected in the tree.
                    Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                    Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                    if (objGear != null)
                    {
                        frmSellItem frmSell = new frmSellItem();
                        frmSell.ShowDialog(this);

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

                        // Record the original value of the Vehicle.
                        int intOriginal = objFoundVehicle.TotalCost;

                        objGear.Parent.Children.Remove(objGear);
                        treVehicles.SelectedNode.Remove();
                        _objFunctions.DeleteVehicleGear(objGear, treVehicles, objFoundVehicle);

                        // Create the Expense Log Entry for the sale.
                        int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objFoundVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                        objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleGear") + " " + objGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objExpense);
                        _objCharacter.Nuyen += intAmount;
                    }
                }
                else if (treVehicles.SelectedNode.Level > 5)
                {
                    // Locate the selected Sensor Plugin.
                    // Locate the Sensor that is selected in the tree.
                    Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                    Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                    if (objGear != null)
                    {
                        frmSellItem frmSell = new frmSellItem();
                        frmSell.ShowDialog(this);

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

                        // Record the original value of the Vehicle.
                        int intOriginal = objFoundVehicle.TotalCost;

                        objGear.Parent.Children.Remove(objGear);
                        treVehicles.SelectedNode.Remove();
                        _objFunctions.DeleteVehicleGear(objGear, treVehicles, objFoundVehicle);

                        // Create the Expense Log Entry for the sale.
                        int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objFoundVehicle.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                        objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldVehicleGear") + " " + objGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objExpense);
                        _objCharacter.Nuyen += intAmount;
                    }
                }
                UpdateCharacterInfo();
                RefreshSelectedVehicle();

                _blnIsDirty = true;
                UpdateWindowTitle();
            }
            catch
            {
            }
        }
示例#14
0
        private void tsVehicleAddWeaponAccessory_Click(object sender, EventArgs e)
        {
            // Attempt to locate the selected VehicleWeapon.
            bool blnWeaponFound = false;
            Vehicle objFoundVehicle = new Vehicle(_objCharacter);
            Weapon objWeapon = _objFunctions.FindVehicleWeapon(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
            if (objWeapon != null)
                blnWeaponFound = true;

            if (!blnWeaponFound)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_VehicleWeaponAccessories"), LanguageManager.Instance.GetString("MessageTitle_VehicleWeaponAccessories"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Open the Weapons XML file and locate the selected Weapon.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("weapons.xml");

            XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + treVehicles.SelectedNode.Text + "\"]");

            frmSelectWeaponAccessory frmPickWeaponAccessory = new frmSelectWeaponAccessory(_objCharacter, true);

            if (objXmlWeapon == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Make sure the Weapon allows Accessories to be added to it.
            if (!Convert.ToBoolean(objXmlWeapon["allowaccessory"].InnerText))
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                XmlNodeList objXmlMountList = objXmlWeapon.SelectNodes("accessorymounts/mount");
                string strMounts = "";
                foreach (XmlNode objXmlMount in objXmlMountList)
                {
                    // Run through the Weapon's currenct Accessories and filter out any used up Mount points.
                    bool blnFound = false;
                    foreach (WeaponAccessory objCurrentAccessory in objWeapon.WeaponAccessories)
                    {
                        if (objCurrentAccessory.Mount == objXmlMount.InnerText)
                            blnFound = true;
                    }
                    if (!blnFound)
                        strMounts += objXmlMount.InnerText + "/";
                }
                frmPickWeaponAccessory.AllowedMounts = strMounts;
            }

            frmPickWeaponAccessory.WeaponCost = objWeapon.Cost;
            frmPickWeaponAccessory.AccessoryMultiplier = objWeapon.AccessoryMultiplier;
            frmPickWeaponAccessory.ShowDialog();

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

            // Locate the selected piece.
            objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + frmPickWeaponAccessory.SelectedAccessory + "\"]");

            TreeNode objNode = new TreeNode();
            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
            objAccessory.Create(objXmlWeapon, objNode, frmPickWeaponAccessory.SelectedMount);
            objAccessory.Parent = objWeapon;

            // Check the item's Cost and make sure the character can afford it.
            int intOriginalCost = objWeapon.TotalCost;
            objWeapon.WeaponAccessories.Add(objAccessory);

            int intCost = objWeapon.TotalCost - intOriginalCost;
            // Apply a markup if applicable.
            if (frmPickWeaponAccessory.Markup != 0)
            {
                double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo);
                dblCost *= 1 + (Convert.ToDouble(frmPickWeaponAccessory.Markup, GlobalOptions.Instance.CultureInfo) / 100.0);
                intCost = Convert.ToInt32(dblCost);
            }

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

            if (!frmPickWeaponAccessory.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    objWeapon.WeaponAccessories.Remove(objAccessory);
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (frmPickWeaponAccessory.AddAgain)
                        tsVehicleAddWeaponAccessory_Click(sender, e);

                    return;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseVehicleWeaponAccessory") + " " + objAccessory.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddVehicleWeaponAccessory, objAccessory.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            objNode.ContextMenuStrip = cmsVehicleWeaponAccessory;
            treVehicles.SelectedNode.Nodes.Add(objNode);
            treVehicles.SelectedNode.Expand();

            if (frmPickWeaponAccessory.AddAgain)
                tsVehicleAddWeaponAccessory_Click(sender, e);

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#15
0
        /// <summary>
        /// Load the Character from an XML file.
        /// </summary>
        public bool Load()
        {
            XmlDocument objXmlDocument = new XmlDocument();
            objXmlDocument.Load(_strFileName);

            XmlNode objXmlCharacter = objXmlDocument.SelectSingleNode("/character");
            XmlNodeList objXmlNodeList;

            try
            {
                _blnIgnoreRules = Convert.ToBoolean(objXmlCharacter["ignorerules"].InnerText);
            }
            catch
            {
                _blnIgnoreRules = false;
            }
            try
            {
                _blnCreated = Convert.ToBoolean(objXmlCharacter["created"].InnerText);
            }
            catch
            {
            }

            ResetCharacter();

            // Get the game edition of the file if possible and make sure it's intended to be used with this version of the application.
            try
            {
                if (objXmlCharacter["gameedition"].InnerText != string.Empty && objXmlCharacter["gameedition"].InnerText != "SR5")
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_IncorrectGameVersion_SR4"), LanguageManager.Instance.GetString("MessageTitle_IncorrectGameVersion"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
            }
            catch
            {
            }

            // Get the name of the settings file in use if possible.
            try
            {
                _strSettingsFileName = objXmlCharacter["settings"].InnerText;
            }
            catch
            {
            }

            // Load the character's settings file.
            if (!_objOptions.Load(_strSettingsFileName))
                return false;

            try
            {
                _decEssenceAtSpecialStart = Convert.ToDecimal(objXmlCharacter["essenceatspecialstart"].InnerText, GlobalOptions.Instance.CultureInfo);
                // fix to work around a mistake made when saving decimal values in previous versions.
                if (_decEssenceAtSpecialStart > EssenceMaximum)
                    _decEssenceAtSpecialStart /= 10;
            }
            catch
            {
            }

            try
            {
                _strVersionCreated = objXmlCharacter["createdversion"].InnerText;
            }
            catch
            {
            }

            // Metatype information.
            _strMetatype = objXmlCharacter["metatype"].InnerText;
            try
            {
                _strWalk = objXmlCharacter["walk"].InnerText;
                _strRun = objXmlCharacter["run"].InnerText;
                _strSprint = objXmlCharacter["sprint"].InnerText;
            }
            catch
            {
            }
            _intMetatypeBP = Convert.ToInt32(objXmlCharacter["metatypebp"].InnerText);
            _strMetavariant = objXmlCharacter["metavariant"].InnerText;
            try
            {
                _strMetatypeCategory = objXmlCharacter["metatypecategory"].InnerText;
            }
            catch
            {
            }
            try
            {
                _intMutantCritterBaseSkills = Convert.ToInt32(objXmlCharacter["mutantcritterbaseskills"].InnerText);
            }
            catch
            {
            }

            // General character information.
            _strName = objXmlCharacter["name"].InnerText;
            try
            {
                _strMugshot = objXmlCharacter["mugshot"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strSex = objXmlCharacter["sex"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strAge = objXmlCharacter["age"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strEyes = objXmlCharacter["eyes"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strHeight = objXmlCharacter["height"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strWeight = objXmlCharacter["weight"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strSkin = objXmlCharacter["skin"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strHair = objXmlCharacter["hair"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strDescription = objXmlCharacter["description"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strBackground = objXmlCharacter["background"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strConcept = objXmlCharacter["concept"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strNotes = objXmlCharacter["notes"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strAlias = objXmlCharacter["alias"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strPlayerName = objXmlCharacter["playername"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strGameNotes = objXmlCharacter["gamenotes"].InnerText;
            }
            catch
            {
            }

            try
            {
                _strGameplayOption = objXmlCharacter["gameplayoption"].InnerText;
            }
            catch
            {
            }
            try
            {
                _intMaxNuyen = Convert.ToInt32(objXmlCharacter["maxnuyen"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intContactMultiplier = Convert.ToInt32(objXmlCharacter["contactmultiplier"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intMaxKarma = Convert.ToInt32(objXmlCharacter["maxkarma"].InnerText);
            }
            catch
            {
            }
            try
            {
                _strPriorityMetatype = objXmlCharacter["prioritymetatype"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strPriorityAttributes = objXmlCharacter["priorityattributes"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strPrioritySpecial = objXmlCharacter["priorityspecial"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strPrioritySkills = objXmlCharacter["priorityskills"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strPriorityResources = objXmlCharacter["priorityresources"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strSkill1 = objXmlCharacter["priorityskill1"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strSkill2 = objXmlCharacter["priorityskill2"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strSkillGroup = objXmlCharacter["priorityskillgroup"].InnerText;
            }
            catch
            {
            }

            try
            {
                _blnIsCritter = Convert.ToBoolean(objXmlCharacter["iscritter"].InnerText);
            }
            catch
            {
            }

            try
            {
                _blnPossessed = Convert.ToBoolean(objXmlCharacter["possessed"].InnerText);
            }
            catch
            {
            }

            try
            {
                _blnOverrideSpecialAttributeESSLoss = Convert.ToBoolean(objXmlCharacter["overridespecialattributeessloss"].InnerText);
            }
            catch
            {
            }

            try
            {
                _intContactPoints = Convert.ToInt32(objXmlCharacter["contactpoints"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intContactPointsUsed = Convert.ToInt32(objXmlCharacter["contactpointsused"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intCFPLimit = Convert.ToInt32(objXmlCharacter["cfplimit"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intSpellLimit = Convert.ToInt32(objXmlCharacter["spelllimit"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intKarma = Convert.ToInt32(objXmlCharacter["karma"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intTotalKarma = Convert.ToInt32(objXmlCharacter["totalkarma"].InnerText);
            }
            catch
            {
            }

            try
            {
                _intSpecial = Convert.ToInt32(objXmlCharacter["special"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intTotalSpecial = Convert.ToInt32(objXmlCharacter["totalspecial"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intAttributes = Convert.ToInt32(objXmlCharacter["attributes"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intTotalAttributes = Convert.ToInt32(objXmlCharacter["totalattributes"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intContactPoints = Convert.ToInt32(objXmlCharacter["contactpoints"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intContactPointsUsed = Convert.ToInt32(objXmlCharacter["contactpointsused"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intStreetCred = Convert.ToInt32(objXmlCharacter["streetcred"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intNotoriety = Convert.ToInt32(objXmlCharacter["notoriety"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intPublicAwareness = Convert.ToInt32(objXmlCharacter["publicawareness"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intBurntStreetCred = Convert.ToInt32(objXmlCharacter["burntstreetcred"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intMaxAvail = Convert.ToInt32(objXmlCharacter["maxavail"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intNuyen = Convert.ToInt32(objXmlCharacter["nuyen"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intStartingNuyen = Convert.ToInt32(objXmlCharacter["startingnuyen"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intAdeptWayDiscount = Convert.ToInt32(objXmlCharacter["adeptwaydiscount"].InnerText);
            }
            catch
            {
            }

            // Sum to X point value.
            try
            {
                _intSumtoTen = Convert.ToInt32(objXmlCharacter["sumtoten"].InnerText);
            }
            catch
            {
            }
            // Build Points/Karma.
            _intBuildPoints = Convert.ToInt32(objXmlCharacter["bp"].InnerText);
            try
            {
                _intBuildKarma = Convert.ToInt32(objXmlCharacter["buildkarma"].InnerText);
                if (_intMaxKarma == 0)
                    _intMaxKarma = _intBuildKarma;
                if (_intBuildKarma == 35 && _strGameplayOption == "")
                {
                    _strGameplayOption = "Prime Runner";
                }
                if (_intBuildKarma == 35 && _intMaxNuyen == 0)
                {
                    _intMaxNuyen = 25;
                }
            }
            catch
            {
            }
            //Maximum number of Karma that can be spent/gained on Qualities.
            try
            {
                _intGameplayOptionQualityLimit = Convert.ToInt32(objXmlCharacter["gameplayoptionqualitylimit"].InnerText);
            }
            catch
            {
            }
            try
            {
                _objBuildMethod = ConvertToCharacterBuildMethod(objXmlCharacter["buildmethod"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intKnowledgeSkills = Convert.ToInt32(objXmlCharacter["knowskillpts"].InnerText);

            }
            catch { }
            _intKnowledgeSkillPoints = Convert.ToInt32(objXmlCharacter["knowpts"].InnerText);
            _intSkillPoints = Convert.ToInt32(objXmlCharacter["skillpts"].InnerText);
            _intSkillPointsMaximum = Convert.ToInt32(objXmlCharacter["skillptsmax"].InnerText);
            _intSkillGroups = Convert.ToInt32(objXmlCharacter["skillgrps"].InnerText);
            _intSkillGroupsMaximum = Convert.ToInt32(objXmlCharacter["skillgrpsmax"].InnerText);
            _decNuyenBP = Convert.ToDecimal(objXmlCharacter["nuyenbp"].InnerText, GlobalOptions.Instance.CultureInfo);
            _decNuyenMaximumBP = Convert.ToDecimal(objXmlCharacter["nuyenmaxbp"].InnerText, GlobalOptions.Instance.CultureInfo);
            _blnAdeptEnabled = Convert.ToBoolean(objXmlCharacter["adept"].InnerText);
            _blnMagicianEnabled = Convert.ToBoolean(objXmlCharacter["magician"].InnerText);
            _blnTechnomancerEnabled = Convert.ToBoolean(objXmlCharacter["technomancer"].InnerText);
            try
            {
                _blnInitiationEnabled = Convert.ToBoolean(objXmlCharacter["initiationoverride"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnCritterEnabled = Convert.ToBoolean(objXmlCharacter["critter"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnUneducated = Convert.ToBoolean(objXmlCharacter["uneducated"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnUncouth = Convert.ToBoolean(objXmlCharacter["uncouth"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnSchoolOfHardKnocks = Convert.ToBoolean(objXmlCharacter["schoolofhardknocks"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnFriendsInHighPlaces = Convert.ToBoolean(objXmlCharacter["friendsinhighplaces"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnCollegeEducation = Convert.ToBoolean(objXmlCharacter["collegeeducation"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnJackOfAllTrades = Convert.ToBoolean(objXmlCharacter["jackofalltrades"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnInfirm = Convert.ToBoolean(objXmlCharacter["infirm"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnBlackMarket = Convert.ToBoolean(objXmlCharacter["blackmarket"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnExCon = Convert.ToBoolean(objXmlCharacter["excon"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnTrustFund = Convert.ToBoolean(objXmlCharacter["trustfund"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnTechSchool = Convert.ToBoolean(objXmlCharacter["techschool"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnRestrictedGear = Convert.ToBoolean(objXmlCharacter["restrictedgear"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnOverclocker = Convert.ToBoolean(objXmlCharacter["overclocker"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnMadeMan = Convert.ToBoolean(objXmlCharacter["mademan"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnLinguist = Convert.ToBoolean(objXmlCharacter["linguist"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnLightningReflexes = Convert.ToBoolean(objXmlCharacter["lightningreflexes"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnFame = Convert.ToBoolean(objXmlCharacter["fame"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnBornRich = Convert.ToBoolean(objXmlCharacter["bornrich"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnErased = Convert.ToBoolean(objXmlCharacter["erased"].InnerText);
            }
            catch
            {
            }
            _blnMAGEnabled = Convert.ToBoolean(objXmlCharacter["magenabled"].InnerText);
            try
            {
                _intInitiateGrade = Convert.ToInt32(objXmlCharacter["initiategrade"].InnerText);
            }
            catch
            {
            }
            _blnRESEnabled = Convert.ToBoolean(objXmlCharacter["resenabled"].InnerText);
            try
            {
                _intSubmersionGrade = Convert.ToInt32(objXmlCharacter["submersiongrade"].InnerText);
            }
            catch
            {
            }
            try
            {
                _blnGroupMember = Convert.ToBoolean(objXmlCharacter["groupmember"].InnerText);
            }
            catch
            {
            }
            try
            {
                _strGroupName = objXmlCharacter["groupname"].InnerText;
                _strGroupNotes = objXmlCharacter["groupnotes"].InnerText;
            }
            catch
            {
            }

            // Improvements.
            XmlNodeList objXmlImprovementList = objXmlDocument.SelectNodes("/character/improvements/improvement");
            foreach (XmlNode objXmlImprovement in objXmlImprovementList)
            {
                Improvement objImprovement = new Improvement();
                objImprovement.Load(objXmlImprovement);
                _lstImprovements.Add(objImprovement);
            }

            // Qualities
            objXmlNodeList = objXmlDocument.SelectNodes("/character/qualities/quality");
            bool blnHasOldQualities = false;
            foreach (XmlNode objXmlQuality in objXmlNodeList)
            {
                if (objXmlQuality["name"] != null)
                {
                    Quality objQuality = new Quality(this);
                    objQuality.Load(objXmlQuality);
                    _lstQualities.Add(objQuality);
                }
                else
                {
                    // If the Quality does not have a name tag, it is in the old format. Set the flag to show that old Qualities are in use.
                    blnHasOldQualities = true;
                }
            }
            // If old Qualities are in use, they need to be converted before we can continue.
            if (blnHasOldQualities)
                ConvertOldQualities(objXmlNodeList);

            // Attributes.
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"BOD\"]");
            _attBOD.Load(objXmlCharacter);
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"AGI\"]");
            _attAGI.Load(objXmlCharacter);
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"REA\"]");
            _attREA.Load(objXmlCharacter);
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"STR\"]");
            _attSTR.Load(objXmlCharacter);
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"CHA\"]");
            _attCHA.Load(objXmlCharacter);
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"INT\"]");
            _attINT.Load(objXmlCharacter);
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"LOG\"]");
            _attLOG.Load(objXmlCharacter);
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"WIL\"]");
            _attWIL.Load(objXmlCharacter);
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"INI\"]");
            _attINI.Load(objXmlCharacter);
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"EDG\"]");
            _attEDG.Load(objXmlCharacter);
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"MAG\"]");
            _attMAG.Load(objXmlCharacter);
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"RES\"]");
            _attRES.Load(objXmlCharacter);
            objXmlCharacter = objXmlDocument.SelectSingleNode("/character/attributes/attribute[name = \"ESS\"]");
            _attESS.Load(objXmlCharacter);

            // A.I. Attributes.
            try
            {
                _intSignal = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/attributes/signal").InnerText);
                _intResponse = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/attributes/response").InnerText);
            }
            catch
            {
            }

            // Force.
            try
            {
                _intMaxSkillRating = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/attributes/maxskillrating").InnerText);
            }
            catch
            {
            }

            // Attempt to load the split MAG Attribute information for Mystic Adepts.
            if (_blnAdeptEnabled && _blnMagicianEnabled)
            {
                try
                {
                    _intMAGAdept = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/magsplitadept").InnerText);
                    _intMAGMagician = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/magsplitmagician").InnerText);
                }
                catch
                {
                }
            }

            // Attempt to load the Magic Tradition.
            try
            {
                _strMagicTradition = objXmlDocument.SelectSingleNode("/character/tradition").InnerText;
            }
            catch
            {
            }
            // Attempt to load the Magic Tradition Drain Attributes.
            try
            {
                _strTraditionDrain = objXmlDocument.SelectSingleNode("/character/traditiondrain").InnerText;
            }
            catch
            {
            }
            // Attempt to load the Magic Tradition Name.
            try
            {
                _strTraditionName = objXmlDocument.SelectSingleNode("/character/traditionname").InnerText;
            }
            catch
            {
            }
            // Attempt to load the Spirit Combat Name.
            try
            {
                _strSpiritCombat = objXmlDocument.SelectSingleNode("/character/spiritcombat").InnerText;
            }
            catch
            {
            }
            // Attempt to load the Spirit Detection Name.
            try
            {
                _strSpiritDetection = objXmlDocument.SelectSingleNode("/character/spiritdetection").InnerText;
            }
            catch
            {
            }
            // Attempt to load the Spirit Health Name.
            try
            {
                _strSpiritHealth = objXmlDocument.SelectSingleNode("/character/spirithealth").InnerText;
            }
            catch
            {
            }
            // Attempt to load the Spirit Illusion Name.
            try
            {
                _strSpiritIllusion = objXmlDocument.SelectSingleNode("/character/spiritillusion").InnerText;
            }
            catch
            {
            }
            // Attempt to load the Spirit Manipulation Name.
            try
            {
                _strSpiritManipulation = objXmlDocument.SelectSingleNode("/character/spiritmanipulation").InnerText;
            }
            catch
            {
            }
            // Attempt to load the Technomancer Stream.
            try
            {
                _strTechnomancerStream = objXmlDocument.SelectSingleNode("/character/stream").InnerText;
            }
            catch
            {
            }

            // Attempt to load Condition Monitor Progress.
            try
            {
                _intPhysicalCMFilled = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/physicalcmfilled").InnerText);
                _intStunCMFilled = Convert.ToInt32(objXmlDocument.SelectSingleNode("/character/stuncmfilled").InnerText);
            }
            catch
            {
            }

            // Skills.
            foreach (Skill objSkill in _lstSkills)
            {
                XmlNode objXmlSkill = objXmlDocument.SelectSingleNode("/character/skills/skill[name = \"" + objSkill.Name + "\"]");
                if (objXmlSkill != null)
                {
                    objSkill.Load(objXmlSkill);
                }
            }

            // Exotic Skills.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/skills/skill[exotic = \"True\"]");
            foreach (XmlNode objXmlSkill in objXmlNodeList)
            {
                Skill objSkill = new Skill(this);
                objSkill.Load(objXmlSkill);
                _lstSkills.Add(objSkill);
            }

            // SkillGroups.
            foreach (SkillGroup objGroup in _lstSkillGroups)
            {
                XmlNode objXmlSkill = objXmlDocument.SelectSingleNode("/character/skillgroups/skillgroup[name = \"" + objGroup.Name + "\"]");
                if (objXmlSkill != null)
                {
                    objGroup.Load(objXmlSkill);
                    // If the character is set to ignore rules or is in Career Mode, Skill Groups should have a maximum Rating of 6 unless they have been given a higher maximum Rating already.
                    if ((_blnIgnoreRules || _blnCreated) && objGroup.RatingMaximum < 12)
                        objGroup.RatingMaximum = 12;
                }
            }

            // Apply the broken skill group fix
            foreach (Skill objSkill in _lstSkills)
            {
                foreach (SkillGroup objGroup in _lstSkillGroups)
                {
                    if (objGroup.Broken && objGroup.Name == objSkill.SkillGroup)
                    {
                        objSkill.FreeLevels = objGroup.Rating;
                        objSkill.Base = objGroup.Rating;
                        objSkill.Karma = objSkill.Rating - objSkill.Base;
                    }
                }
            }

            foreach (SkillGroup objGroup in _lstSkillGroups)
            {
                if (objGroup.Base == 0 && objGroup.Karma == 0 && objGroup.Rating > 0)
                    objGroup.Base = objGroup.Rating;
            }

            // Knowledge Skills.
            List<ListItem> lstKnowledgeSkillOrder = new List<ListItem>();
            objXmlNodeList = objXmlDocument.SelectNodes("/character/skills/skill[knowledge = \"True\"]");
            // Sort the Knowledge Skills in alphabetical order.
            foreach (XmlNode objXmlSkill in objXmlNodeList)
            {
                ListItem objGroup = new ListItem();
                objGroup.Value = objXmlSkill["name"].InnerText;
                objGroup.Name = objXmlSkill["name"].InnerText;
                lstKnowledgeSkillOrder.Add(objGroup);
            }
            SortListItem objSort = new SortListItem();
            lstKnowledgeSkillOrder.Sort(objSort.Compare);

            foreach (ListItem objItem in lstKnowledgeSkillOrder)
            {
                Skill objSkill = new Skill(this);
                XmlNode objNode = objXmlDocument.SelectSingleNode("/character/skills/skill[knowledge = \"True\" and name = " + CleanXPath(objItem.Value) + "]");
                objSkill.Load(objNode);
                _lstSkills.Add(objSkill);
            }

            // Contacts.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/contacts/contact");
            foreach (XmlNode objXmlContact in objXmlNodeList)
            {
                Contact objContact = new Contact(this);
                objContact.Load(objXmlContact);
                _lstContacts.Add(objContact);
            }

            // Armor.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/armors/armor");
            foreach (XmlNode objXmlArmor in objXmlNodeList)
            {
                Armor objArmor = new Armor(this);
                objArmor.Load(objXmlArmor);
                _lstArmor.Add(objArmor);
            }

            // Weapons.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/weapons/weapon");
            foreach (XmlNode objXmlWeapon in objXmlNodeList)
            {
                Weapon objWeapon = new Weapon(this);
                objWeapon.Load(objXmlWeapon);
                _lstWeapons.Add(objWeapon);
            }

            // Cyberware/Bioware.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/cyberwares/cyberware");
            foreach (XmlNode objXmlCyberware in objXmlNodeList)
            {
                Cyberware objCyberware = new Cyberware(this);
                objCyberware.Load(objXmlCyberware);
                _lstCyberware.Add(objCyberware);
            }

            // Spells.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/spells/spell");
            foreach (XmlNode objXmlSpell in objXmlNodeList)
            {
                Spell objSpell = new Spell(this);
                objSpell.Load(objXmlSpell);
                _lstSpells.Add(objSpell);
            }

            // Foci.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/foci/focus");
            foreach (XmlNode objXmlFocus in objXmlNodeList)
            {
                Focus objFocus = new Focus();
                objFocus.Load(objXmlFocus);
                _lstFoci.Add(objFocus);
            }

            // Stacked Foci.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/stackedfoci/stackedfocus");
            foreach (XmlNode objXmlStack in objXmlNodeList)
            {
                StackedFocus objStack = new StackedFocus(this);
                objStack.Load(objXmlStack);
                _lstStackedFoci.Add(objStack);
            }

            // Powers.
            List<ListItem> lstPowerOrder = new List<ListItem>();
            objXmlNodeList = objXmlDocument.SelectNodes("/character/powers/power");
            // Sort the Powers in alphabetical order.
            foreach (XmlNode objXmlPower in objXmlNodeList)
            {
                ListItem objGroup = new ListItem();
                objGroup.Value = objXmlPower["extra"].InnerText;
                objGroup.Name = objXmlPower["name"].InnerText;

                lstPowerOrder.Add(objGroup);
            }
            objSort = new SortListItem();
            lstPowerOrder.Sort(objSort.Compare);

            foreach (ListItem objItem in lstPowerOrder)
            {
                Power objPower = new Power(this);
                XmlNode objNode = objXmlDocument.SelectSingleNode("/character/powers/power[name = " + CleanXPath(objItem.Name) + " and extra = " + CleanXPath(objItem.Value) + "]");
                objPower.Load(objNode);
                _lstPowers.Add(objPower);
            }

            // Spirits/Sprites.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/spirits/spirit");
            foreach (XmlNode objXmlSpirit in objXmlNodeList)
            {
                Spirit objSpirit = new Spirit(this);
                objSpirit.Load(objXmlSpirit);
                _lstSpirits.Add(objSpirit);
            }

            // Compex Forms/Technomancer Programs.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/complexforms/complexform");
            foreach (XmlNode objXmlProgram in objXmlNodeList)
            {
                ComplexForm objProgram = new ComplexForm(this);
                objProgram.Load(objXmlProgram);
                _lstComplexForms.Add(objProgram);
            }

            // Martial Arts.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/martialarts/martialart");
            foreach (XmlNode objXmlArt in objXmlNodeList)
            {
                MartialArt objMartialArt = new MartialArt(this);
                objMartialArt.Load(objXmlArt);
                _lstMartialArts.Add(objMartialArt);
            }

            // Martial Art Maneuvers.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/martialartmaneuvers/martialartmaneuver");
            foreach (XmlNode objXmlManeuver in objXmlNodeList)
            {
                MartialArtManeuver objManeuver = new MartialArtManeuver(this);
                objManeuver.Load(objXmlManeuver);
                _lstMartialArtManeuvers.Add(objManeuver);
            }

            // Limit Modifiers.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/limitmodifiers/limitmodifier");
            foreach (XmlNode objXmlLimit in objXmlNodeList)
            {
                LimitModifier obLimitModifier = new LimitModifier(this);
                obLimitModifier.Load(objXmlLimit);
                _lstLimitModifiers.Add(obLimitModifier);
            }

            // Lifestyles.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/lifestyles/lifestyle");
            foreach (XmlNode objXmlLifestyle in objXmlNodeList)
            {
                Lifestyle objLifestyle = new Lifestyle(this);
                objLifestyle.Load(objXmlLifestyle);
                _lstLifestyles.Add(objLifestyle);
            }

            // <gears>
            objXmlNodeList = objXmlDocument.SelectNodes("/character/gears/gear");
            foreach (XmlNode objXmlGear in objXmlNodeList)
            {
                switch (objXmlGear["category"].InnerText)
                {
                    case "Commlinks":
                    case "Cyberdecks":
                    case "Rigger Command Consoles":
                        Commlink objCommlink = new Commlink(this);
                        objCommlink.Load(objXmlGear);
                        _lstGear.Add(objCommlink);
                        break;
                    default:
                        Gear objGear = new Gear(this);
                        objGear.Load(objXmlGear);
                        _lstGear.Add(objGear);
                        break;
                }
            }

            // Vehicles.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/vehicles/vehicle");
            foreach (XmlNode objXmlVehicle in objXmlNodeList)
            {
                Vehicle objVehicle = new Vehicle(this);
                objVehicle.Load(objXmlVehicle);
                _lstVehicles.Add(objVehicle);
            }

            // Metamagics/Echoes.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/metamagics/metamagic");
            foreach (XmlNode objXmlMetamagic in objXmlNodeList)
            {
                Metamagic objMetamagic = new Metamagic(this);
                objMetamagic.Load(objXmlMetamagic);
                _lstMetamagics.Add(objMetamagic);
            }

            // Arts
            objXmlNodeList = objXmlDocument.SelectNodes("/character/arts/art");
            foreach (XmlNode objXmlArt in objXmlNodeList)
            {
                Art objArt = new Art(this);
                objArt.Load(objXmlArt);
                _lstArts.Add(objArt);
            }

            // Enhancements
            objXmlNodeList = objXmlDocument.SelectNodes("/character/enhancements/enhancement");
            foreach (XmlNode objXmlEnhancement in objXmlNodeList)
            {
                Enhancement objEnhancement = new Enhancement(this);
                objEnhancement.Load(objXmlEnhancement);
                _lstEnhancements.Add(objEnhancement);
            }

            // Critter Powers.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/critterpowers/critterpower");
            foreach (XmlNode objXmlPower in objXmlNodeList)
            {
                CritterPower objPower = new CritterPower(this);
                objPower.Load(objXmlPower);
                _lstCritterPowers.Add(objPower);
            }

            // Initiation Grades.
            objXmlNodeList = objXmlDocument.SelectNodes("/character/initiationgrades/initiationgrade");
            foreach (XmlNode objXmlGrade in objXmlNodeList)
            {
                InitiationGrade objGrade = new InitiationGrade(this);
                objGrade.Load(objXmlGrade);
                _lstInitiationGrades.Add(objGrade);
            }

            // Expense Log Entries.
            XmlNodeList objXmlExpenseList = objXmlDocument.SelectNodes("/character/expenses/expense");
            foreach (XmlNode objXmlExpense in objXmlExpenseList)
            {
                ExpenseLogEntry objExpenseLogEntry = new ExpenseLogEntry();
                objExpenseLogEntry.Load(objXmlExpense);
                _lstExpenseLog.Add(objExpenseLogEntry);
            }

            // Locations.
            XmlNodeList objXmlLocationList = objXmlDocument.SelectNodes("/character/locations/location");
            foreach (XmlNode objXmlLocation in objXmlLocationList)
            {
                _lstLocations.Add(objXmlLocation.InnerText);
            }

            // Armor Bundles.
            XmlNodeList objXmlBundleList = objXmlDocument.SelectNodes("/character/armorbundles/armorbundle");
            foreach (XmlNode objXmlBundle in objXmlBundleList)
            {
                _lstArmorBundles.Add(objXmlBundle.InnerText);
            }

            // Weapon Locations.
            XmlNodeList objXmlWeaponLocationList = objXmlDocument.SelectNodes("/character/weaponlocations/weaponlocation");
            foreach (XmlNode objXmlLocation in objXmlWeaponLocationList)
            {
                _lstWeaponLocations.Add(objXmlLocation.InnerText);
            }

            // Improvement Groups.
            XmlNodeList objXmlGroupList = objXmlDocument.SelectNodes("/character/improvementgroups/improvementgroup");
            foreach (XmlNode objXmlGroup in objXmlGroupList)
            {
                _lstImprovementGroups.Add(objXmlGroup.InnerText);
            }

            // Calendar.
            XmlNodeList objXmlWeekList = objXmlDocument.SelectNodes("/character/calendar/week");
            foreach (XmlNode objXmlWeek in objXmlWeekList)
            {
                CalendarWeek objWeek = new CalendarWeek();
                objWeek.Load(objXmlWeek);
                _lstCalendar.Add(objWeek);
            }

            // Look for the unarmed attack
            bool blnFoundUnarmed = false;
            foreach (Weapon objWeapon in _lstWeapons)
            {
                if (objWeapon.Name == "Unarmed Attack")
                    blnFoundUnarmed = true;
            }

            if (!blnFoundUnarmed)
            {
                // Add the Unarmed Attack Weapon to the character.
                try
                {
                    XmlDocument objXmlWeaponDoc = XmlManager.Instance.Load("weapons.xml");
                    XmlNode objXmlWeapon = objXmlWeaponDoc.SelectSingleNode("/chummer/weapons/weapon[name = \"Unarmed Attack\"]");
                    TreeNode objGearWeaponNode = new TreeNode();
                    Weapon objWeapon = new Weapon(this);
                    objWeapon.Create(objXmlWeapon, this, objGearWeaponNode, null, null, null);
                    objGearWeaponNode.ForeColor = SystemColors.GrayText;
                    _lstWeapons.Add(objWeapon);
                }
                catch
                {
                }
            }

            // converting from old dwarven resistance to new dwarven resistance
            if (this.Metatype.ToLower().Equals("dwarf")
                && this.Qualities.Where(x => x.Name.Equals("Dwarf Resistance")).FirstOrDefault() == null
                && this.Qualities.Where(x => x.Name.Equals("Resistance to Pathogens and Toxins")).FirstOrDefault() != null)
            {
                this.Qualities.Remove(this.Qualities.Where(x => x.Name.Equals("Resistance to Pathogens and Toxins")).First());
                XmlNode objXmlDwarfQuality = XmlManager.Instance.Load("qualities.xml").SelectSingleNode("/chummer/qualities/quality[name = \"Dwarf Resistance\"]");

                TreeNode objNode = new TreeNode();
                List<Weapon> objWeapons = new List<Weapon>();
                List<TreeNode> objWeaponNodes = new List<TreeNode>();
                Quality objQuality = new Quality(this);

                objQuality.Create(objXmlDwarfQuality, this, QualitySource.Metatype, objNode, objWeapons, objWeaponNodes);
                this._lstQualities.Add(objQuality);
                blnHasOldQualities = true;
            }

            // load issue where the contact multiplier was set to 0
            if (_intContactMultiplier == 0 && _strGameplayOption != string.Empty)
            {
                XmlDocument objXmlDocumentPriority = XmlManager.Instance.Load("gameplayoptions.xml");
                XmlNode objXmlGameplayOption = objXmlDocumentPriority.SelectSingleNode("/chummer/gameplayoptions/gameplayoption[name = \"" + _strGameplayOption + "\"]");
                string strKarma = objXmlGameplayOption["karma"].InnerText;
                string strNuyen = objXmlGameplayOption["maxnuyen"].InnerText;
                string strContactMultiplier = "0";
                if (!_objOptions.FreeContactsMultiplierEnabled)
                {

                    strContactMultiplier = objXmlGameplayOption["contactmultiplier"].InnerText;
                }
                else
                {
                    strContactMultiplier = _objOptions.FreeContactsMultiplier.ToString();
                }
                _intMaxKarma = Convert.ToInt32(strKarma);
                _intMaxNuyen = Convert.ToInt32(strNuyen);
                _intContactMultiplier = Convert.ToInt32(strContactMultiplier);
                _intContactPoints = (CHA.Base + CHA.Karma) * _intContactMultiplier;
            }

            // If the character had old Qualities that were converted, immediately save the file so they are in the new format.
            if (blnHasOldQualities)
                Save();

            return true;
        }
示例#16
0
        private void tsVehicleAddNexus_Click(object sender, EventArgs e)
        {
            // Make sure a parent items is selected, then open the Select Gear window.
            try
            {
                if (treVehicles.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectGearVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectGearVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectGearVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectGearVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (treVehicles.SelectedNode.Level > 1)
                treVehicles.SelectedNode = treVehicles.SelectedNode.Parent;

            // Attempt to locate the selected Vehicle.
            Vehicle objSelectedVehicle = _objFunctions.FindVehicle(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles);

            frmSelectNexus frmPickNexus = new frmSelectNexus(_objCharacter, true);
            frmPickNexus.ShowDialog(this);

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

            Gear objGear = new Gear(_objCharacter);
            objGear = frmPickNexus.SelectedNexus;

            int intCost = objGear.TotalCost;

            // Multiply the cost if applicable.
            if (objGear.TotalAvail().EndsWith(LanguageManager.Instance.GetString("String_AvailRestricted")) && _objOptions.MultiplyRestrictedCost)
                intCost *= _objOptions.RestrictedCostMultiplier;
            if (objGear.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 (!frmPickNexus.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();
                    objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseVehicleGear") + " " + objGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddVehicleGear, objGear.InternalId, 1);
                    objExpense.Undo = objUndo;
                }
            }

            TreeNode nodNexus = new TreeNode();
            nodNexus.Text = objGear.Name;
            nodNexus.Tag = objGear.InternalId;
            nodNexus.ContextMenuStrip = cmsVehicleGear;

            foreach (Gear objChild in objGear.Children)
            {
                TreeNode nodModule = new TreeNode();
                nodModule.Text = objChild.Name;
                nodModule.Tag = objChild.InternalId;
                nodModule.ContextMenuStrip = cmsVehicleGear;
                nodNexus.Nodes.Add(nodModule);
                nodNexus.Expand();
            }

            treVehicles.SelectedNode.Nodes.Add(nodNexus);
            treVehicles.SelectedNode.Expand();

            objSelectedVehicle.Gear.Add(objGear);

            UpdateCharacterInfo();
            RefreshSelectedVehicle();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#17
0
        private void chkJoinGroup_CheckedChanged(object sender, EventArgs e)
        {
            if (_blnSkipRefresh || _blnLoading)
                return;

            // Joining a Network does not cost Karma for Technomancers, so this only applies to Magicians/Adepts.
            if (_objCharacter.MAGEnabled)
            {
                if (chkJoinGroup.Checked)
                {
                    int intKarmaExpense = _objOptions.KarmaJoinGroup;

                    if (intKarmaExpense > _objCharacter.Karma)
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        _blnSkipRefresh = true;
                        chkJoinGroup.Checked = false;
                        _blnSkipRefresh = false;
                        return;
                    }

                    string strMessage = "";
                    string strExpense = "";
                    if (_objCharacter.MAGEnabled)
                    {
                        strMessage = LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseJoinGroup");
                        strExpense = LanguageManager.Instance.GetString("String_ExpenseJoinGroup");
                    }
                    else
                    {
                        strMessage = LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseJoinNetwork");
                        strExpense = LanguageManager.Instance.GetString("String_ExpenseJoinNetwork");
                    }

                    if (!ConfirmKarmaExpense(strMessage.Replace("{0}", intKarmaExpense.ToString())))
                    {
                        _blnSkipRefresh = true;
                        chkJoinGroup.Checked = false;
                        _blnSkipRefresh = false;
                        return;
                    }

                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intKarmaExpense * -1, strExpense, ExpenseType.Karma, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Karma -= intKarmaExpense;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateKarma(KarmaExpenseType.JoinGroup, "");
                    objExpense.Undo = objUndo;

                    _objCharacter.GroupMember = chkJoinGroup.Checked;
                    UpdateCharacterInfo();
                }
                else
                {
                    int intKarmaExpense = _objOptions.KarmaLeaveGroup;

                    if (intKarmaExpense > _objCharacter.Karma)
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        _blnSkipRefresh = true;
                        chkJoinGroup.Checked = true;
                        _blnSkipRefresh = false;
                        return;
                    }

                    string strMessage = "";
                    string strExpense = "";
                    if (_objCharacter.MAGEnabled)
                    {
                        strMessage = LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseLeaveGroup");
                        strExpense = LanguageManager.Instance.GetString("String_ExpenseLeaveGroup");
                    }
                    else
                    {
                        strMessage = LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseLeaveNetwork");
                        strExpense = LanguageManager.Instance.GetString("String_ExpenseLeaveNetwork");
                    }

                    if (!ConfirmKarmaExpense(strMessage.Replace("{0}", intKarmaExpense.ToString())))
                    {
                        _blnSkipRefresh = true;
                        chkJoinGroup.Checked = true;
                        _blnSkipRefresh = false;
                        return;
                    }

                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intKarmaExpense * -1, strExpense, ExpenseType.Karma, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Karma -= intKarmaExpense;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateKarma(KarmaExpenseType.LeaveGroup, "");
                    objExpense.Undo = objUndo;

                    _objCharacter.GroupMember = chkJoinGroup.Checked;
                    UpdateCharacterInfo();
                }
            }
            else
            {
                _objCharacter.GroupMember = chkJoinGroup.Checked;
                UpdateCharacterInfo();
            }

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#18
0
        private void cmdImproveInitiation_Click(object sender, EventArgs e)
        {
            if (_objCharacter.MAGEnabled)
            {
                // Make sure that the Initiate Grade is not attempting to go above the character's MAG Attribute.
                if (_objCharacter.InitiateGrade + 1 > _objCharacter.MAG.TotalValue)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotIncreaseInitiateGrade"), LanguageManager.Instance.GetString("MessageTitle_CannotIncreaseInitiateGrade"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // Make sure the character has enough Karma.
                double dblMultiplier = 1.0;
                dblMultiplier = Math.Round(dblMultiplier, 2);

                int intKarmaExpense = Convert.ToInt32(Math.Ceiling(Convert.ToDouble((10 + ((_objCharacter.InitiateGrade + 1) * _objOptions.KarmaInitiation)), GlobalOptions.Instance.CultureInfo) * dblMultiplier));

                if (intKarmaExpense > _objCharacter.Karma)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpense").Replace("{0}", LanguageManager.Instance.GetString("String_InitiateGrade")).Replace("{1}", (_objCharacter.InitiateGrade + 1).ToString()).Replace("{2}", intKarmaExpense.ToString())))
                    return;

                // Create the Expense Log Entry.
                ExpenseLogEntry objExpense = new ExpenseLogEntry();
                objExpense.Create(intKarmaExpense * -1, LanguageManager.Instance.GetString("String_ExpenseInitiateGrade") + " " + _objCharacter.InitiateGrade.ToString() + " -> " + (_objCharacter.InitiateGrade + 1).ToString(), ExpenseType.Karma, DateTime.Now);
                _objCharacter.ExpenseEntries.Add(objExpense);
                _objCharacter.Karma -= intKarmaExpense;

                // Create the Initiate Grade object.
                InitiationGrade objGrade = new InitiationGrade(_objCharacter);
                objGrade.Create(_objCharacter.InitiateGrade + 1, _objCharacter.RESEnabled, chkInitiationGroup.Checked, chkInitiationOrdeal.Checked, chkInitiationSchooling.Checked);
                _objCharacter.InitiationGrades.Add(objGrade);

                ExpenseUndo objUndo = new ExpenseUndo();
                objUndo.CreateKarma(KarmaExpenseType.ImproveInitiateGrade, objGrade.InternalId);
                objExpense.Undo = objUndo;

                // Set the character's Initiate Grade.
                _objCharacter.InitiateGrade += 1;

                // Remove any existing Initiation Improvements.
                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Initiation, "Initiation");

                // Create the replacement Improvement.
                _objImprovementManager.CreateImprovement("MAG", Improvement.ImprovementSource.Initiation, "Initiation", Improvement.ImprovementType.Attribute, "", 0, 1, 0, _objCharacter.InitiateGrade);
                _objImprovementManager.Commit();

                // Update any Metamagic Improvements the character might have.
                foreach (Metamagic objMetamagic in _objCharacter.Metamagics)
                {
                    if (objMetamagic.Bonus != null)
                    {
                        // If the Bonus contains "Rating", remove the existing Improvement and create new ones.
                        if (objMetamagic.Bonus.InnerXml.Contains("Rating"))
                        {
                            _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Metamagic, objMetamagic.InternalId);
                            _objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Metamagic, objMetamagic.InternalId, objMetamagic.Bonus, false, _objCharacter.InitiateGrade, objMetamagic.DisplayNameShort);
                        }
                    }
                }

                int intAmount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble((10 + ((_objCharacter.InitiateGrade + 1) * _objOptions.KarmaInitiation)), GlobalOptions.Instance.CultureInfo) * dblMultiplier));

                string strInitTip = LanguageManager.Instance.GetString("Tip_ImproveInitiateGrade").Replace("{0}", (_objCharacter.InitiateGrade + 1).ToString()).Replace("{1}", intAmount.ToString());
                tipTooltip.SetToolTip(cmdAddMetamagic, strInitTip);
            }
            else if (_objCharacter.RESEnabled)
            {
                // Make sure that the Initiate Grade is not attempting to go above the character's RES Attribute.
                if (_objCharacter.SubmersionGrade + 1 > _objCharacter.RES.TotalValue)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotIncreaseSubmersionGrade"), LanguageManager.Instance.GetString("MessageTitle_CannotIncreaseSubmersionGrade"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // Make sure the character has enough Karma.
                double dblMultiplier = 1.0;
                dblMultiplier = Math.Round(dblMultiplier, 2);

                int intKarmaExpense = Convert.ToInt32(Math.Ceiling(Convert.ToDouble((10 + ((_objCharacter.SubmersionGrade + 1) * _objOptions.KarmaInitiation)), GlobalOptions.Instance.CultureInfo) * dblMultiplier));

                if (intKarmaExpense > _objCharacter.Karma)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpense").Replace("{0}", LanguageManager.Instance.GetString("String_SubmersionGrade")).Replace("{1}", (_objCharacter.SubmersionGrade + 1).ToString()).Replace("{2}", intKarmaExpense.ToString())))
                    return;

                // Create the Expense Log Entry.
                ExpenseLogEntry objExpense = new ExpenseLogEntry();
                objExpense.Create(intKarmaExpense * -1, LanguageManager.Instance.GetString("String_ExpenseSubmersionGrade") + " " + _objCharacter.SubmersionGrade.ToString() + " -> " + (_objCharacter.SubmersionGrade + 1).ToString(), ExpenseType.Karma, DateTime.Now);
                _objCharacter.ExpenseEntries.Add(objExpense);
                _objCharacter.Karma -= intKarmaExpense;

                // Create the Initiate Grade object.
                InitiationGrade objGrade = new InitiationGrade(_objCharacter);
                objGrade.Create(_objCharacter.SubmersionGrade + 1, _objCharacter.RESEnabled, chkInitiationGroup.Checked, chkInitiationOrdeal.Checked, chkInitiationSchooling.Checked);
                _objCharacter.InitiationGrades.Add(objGrade);

                ExpenseUndo objUndo = new ExpenseUndo();
                objUndo.CreateKarma(KarmaExpenseType.ImproveInitiateGrade, objGrade.InternalId);
                objExpense.Undo = objUndo;

                // Set the character's Submersion Grade.
                _objCharacter.SubmersionGrade += 1;

                // Remove any existing Initiation Improvements.
                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Submersion, "Submersion");

                // Create the replacement Improvement.
                _objImprovementManager.CreateImprovement("RES", Improvement.ImprovementSource.Submersion, "Submersion", Improvement.ImprovementType.Attribute, "", 0, 1, 0, _objCharacter.SubmersionGrade);
                _objImprovementManager.Commit();

                // Update any Echo Improvements the character might have.
                foreach (Metamagic objMetamagic in _objCharacter.Metamagics)
                {
                    if (objMetamagic.Bonus != null)
                    {
                        // If the Bonus contains "Rating", remove the existing Improvement and create new ones.
                        if (objMetamagic.Bonus.InnerXml.Contains("Rating"))
                        {
                            _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Echo, objMetamagic.InternalId);
                            _objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Echo, objMetamagic.InternalId, objMetamagic.Bonus, false, _objCharacter.SubmersionGrade, objMetamagic.DisplayNameShort);
                        }
                    }
                }

                int intAmount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble((10 + ((_objCharacter.SubmersionGrade + 1) * _objOptions.KarmaInitiation)), GlobalOptions.Instance.CultureInfo) * dblMultiplier));

                string strInitTip = LanguageManager.Instance.GetString("Tip_ImproveSubmersionGrade").Replace("{0}", (_objCharacter.SubmersionGrade + 1).ToString()).Replace("{1}", intAmount.ToString());
                tipTooltip.SetToolTip(cmdAddMetamagic, strInitTip);
            }

            UpdateInitiationGradeTree();
            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#19
0
        private void cmdAddComplexForm_Click(object sender, EventArgs e)
        {
            // The number of Complex Forms cannot exceed the character's LOG.
            if (_objCharacter.ComplexForms.Count >= ((_objCharacter.RES.Value * 2) + _objImprovementManager.ValueOf(Improvement.ImprovementType.ComplexFormLimit)))
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_ComplexFormLimitCareer"), LanguageManager.Instance.GetString("MessageTitle_ComplexFormLimit"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            // Let the user select a Program.
            frmSelectProgram frmPickProgram = new frmSelectProgram(_objCharacter);
            frmPickProgram.ShowDialog(this);

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

            int intKarmaCost = _objOptions.KarmaNewComplexForm;

            XmlDocument objXmlDocument = XmlManager.Instance.Load("complexforms.xml");

            XmlNode objXmlProgram = objXmlDocument.SelectSingleNode("/chummer/complexforms/complexform[name = \"" + frmPickProgram.SelectedProgram + "\"]");

            // Check for SelectText.
            string strExtra = "";
            if (objXmlProgram["bonus"] != null)
            {
                if (objXmlProgram["bonus"]["selecttext"] != null)
                {
                    frmSelectText frmPickText = new frmSelectText();
                    frmPickText.Description = LanguageManager.Instance.GetString("String_Improvement_SelectText").Replace("{0}", frmPickProgram.SelectedProgram);
                    frmPickText.ShowDialog(this);
                    strExtra = frmPickText.SelectedValue;
                }
            }

            TreeNode objNode = new TreeNode();
            ComplexForm objProgram = new ComplexForm(_objCharacter);
            objProgram.Create(objXmlProgram, _objCharacter, objNode, strExtra);
            if (objProgram.InternalId == Guid.Empty.ToString())
                return;

            _objCharacter.ComplexForms.Add(objProgram);

            // If using the optional rule for costing the same as Spells, change the Karma cost.
            if (_objOptions.AlternateComplexFormCost)
                intKarmaCost = _objOptions.KarmaSpell;

            // Make sure the character has enough Karma before letting them select a Complex Form.
            if (_objCharacter.Karma < intKarmaCost)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                // Remove the Improvements created by the Complex Form.
                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.ComplexForm, objProgram.InternalId);
                return;
            }

            if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseSpend").Replace("{0}", objProgram.DisplayNameShort).Replace("{1}", intKarmaCost.ToString())))
            {
                // Remove the Improvements created by the Complex Form.
                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.ComplexForm, objProgram.InternalId);
                return;
            }

            treComplexForms.Nodes[0].Nodes.Add(objNode);
            treComplexForms.Nodes[0].Expand();

            // Create the Expense Log Entry.
            ExpenseLogEntry objExpense = new ExpenseLogEntry();
            objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseLearnComplexForm") + " " + objProgram.DisplayNameShort, ExpenseType.Karma, DateTime.Now);
            _objCharacter.ExpenseEntries.Add(objExpense);
            _objCharacter.Karma -= intKarmaCost;

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateKarma(KarmaExpenseType.AddComplexForm, objProgram.InternalId);
            objExpense.Undo = objUndo;

            _objFunctions.SortTree(treComplexForms);
            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickProgram.AddAgain)
                cmdAddComplexForm_Click(sender, e);
        }
示例#20
0
        private void cmdImproveWIL_Click(object sender, EventArgs e)
        {
            // Make sure the character has enough Karma to improve the Attribute.
            int intKarmaCost = (_objCharacter.WIL.Value + _objCharacter.WIL.AttributeValueModifiers + 1) * _objOptions.KarmaAttribute;
            if (_objOptions.AlternateMetatypeAttributeKarma)
                intKarmaCost -= (_objCharacter.WIL.MetatypeMinimum - 1) * _objOptions.KarmaAttribute;
            if (intKarmaCost > _objCharacter.Karma)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpense").Replace("{0}", LanguageManager.Instance.GetString("String_AttributeWILShort")).Replace("{1}", (_objCharacter.WIL.Value + _objCharacter.WIL.AttributeValueModifiers + 1).ToString()).Replace("{2}", intKarmaCost.ToString())))
                return;

            // Create the Karma expense.
            ExpenseLogEntry objExpense = new ExpenseLogEntry();
            objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseAttribute") + " " + LanguageManager.Instance.GetString("String_AttributeWILShort") + " " + (_objCharacter.WIL.Value + _objCharacter.WIL.AttributeValueModifiers).ToString() + " -> " + (_objCharacter.WIL.Value + _objCharacter.WIL.AttributeValueModifiers + 1).ToString(), ExpenseType.Karma, DateTime.Now);
            _objCharacter.ExpenseEntries.Add(objExpense);
            _objCharacter.Karma -= intKarmaCost;

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateKarma(KarmaExpenseType.ImproveAttribute, "WIL");
            objExpense.Undo = objUndo;

            _objCharacter.WIL.Value += 1;

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#21
0
        private void cmdAddManeuver_Click(object sender, EventArgs e)
        {
            // Characters may only have 2 Maneuvers per Martial Art Rating.
            int intTotalRating = 0;
            foreach (MartialArt objMartialArt in _objCharacter.MartialArts)
                intTotalRating += objMartialArt.Rating * 2;

            if (treMartialArts.Nodes[1].Nodes.Count >= intTotalRating)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_MartialArtManeuverLimit"), LanguageManager.Instance.GetString("MessageTitle_MartialArtManeuverLimit"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Make sure the character has enough Karma.
            int intKarmaCost = _objOptions.KarmaManeuver;

            if (intKarmaCost > _objCharacter.Karma)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            frmSelectMartialArtManeuver frmPickMartialArtManeuver = new frmSelectMartialArtManeuver(_objCharacter);
            frmPickMartialArtManeuver.ShowDialog(this);

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

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

            XmlNode objXmlManeuver = objXmlDocument.SelectSingleNode("/chummer/maneuvers/maneuver[name = \"" + frmPickMartialArtManeuver.SelectedManeuver + "\"]");

            TreeNode objNode = new TreeNode();
            MartialArtManeuver objManeuver = new MartialArtManeuver(_objCharacter);
            objManeuver.Create(objXmlManeuver, objNode);
            objNode.ContextMenuStrip = cmsMartialArtManeuver;
            _objCharacter.MartialArtManeuvers.Add(objManeuver);

            treMartialArts.Nodes[1].Nodes.Add(objNode);
            treMartialArts.Nodes[1].Expand();

            treMartialArts.SelectedNode = objNode;

            // Create the Expense Log Entry.
            ExpenseLogEntry objExpense = new ExpenseLogEntry();
            objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseLearnManeuver") + " " + objManeuver.DisplayNameShort, ExpenseType.Karma, DateTime.Now);
            _objCharacter.ExpenseEntries.Add(objExpense);
            _objCharacter.Karma -= intKarmaCost;

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateKarma(KarmaExpenseType.AddMartialArtManeuver, objManeuver.InternalId);
            objExpense.Undo = objUndo;

            _objFunctions.SortTree(treMartialArts);
            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#22
0
        private void cmdIncreasePowerPoints_Click(object sender, EventArgs e)
        {
            // Make sure the character has enough Karma to improve the Attribute.
            int intKarmaCost = 5;
            if (intKarmaCost > _objCharacter.Karma)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (_objCharacter.MAGAdept + 1 > _objCharacter.MAG.TotalValue)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughMagic"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughMagic"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseSpend").Replace("{0}", LanguageManager.Instance.GetString("String_PowerPoint")).Replace("{1}", (intKarmaCost).ToString())))
                return;

            // Create the Karma expense.
            ExpenseLogEntry objExpense = new ExpenseLogEntry();
            objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_PowerPoint"), ExpenseType.Karma, DateTime.Now);
            _objCharacter.ExpenseEntries.Add(objExpense);
            _objCharacter.Karma -= intKarmaCost;

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateKarma(KarmaExpenseType.AddPowerPoint, "");
            objExpense.Undo = objUndo;

            _objCharacter.MAGAdept += 1;

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#23
0
        private void cmdAddMartialArt_Click(object sender, EventArgs e)
        {
            int intKarmaCost = 7 * _objOptions.KarmaQuality;
            if (intKarmaCost > _objCharacter.Karma)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            frmSelectMartialArt frmPickMartialArt = new frmSelectMartialArt(_objCharacter);
            frmPickMartialArt.ShowDialog(this);

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

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

            XmlNode objXmlArt = objXmlDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + frmPickMartialArt.SelectedMartialArt + "\"]");

            TreeNode objNode = new TreeNode();
            MartialArt objMartialArt = new MartialArt(_objCharacter);
            objMartialArt.Create(objXmlArt, objNode, _objCharacter);
            _objCharacter.MartialArts.Add(objMartialArt);

            objNode.ContextMenuStrip = cmsMartialArts;

            // Create the Expense Log Entry.
            ExpenseLogEntry objExpense = new ExpenseLogEntry();
            objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseLearnMartialArt") + " " + frmPickMartialArt.SelectedMartialArt, ExpenseType.Karma, DateTime.Now);
            _objCharacter.ExpenseEntries.Add(objExpense);
            _objCharacter.Karma -= intKarmaCost;

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateKarma(KarmaExpenseType.AddMartialArt, objMartialArt.Name);
            objExpense.Undo = objUndo;

            treMartialArts.Nodes[0].Nodes.Add(objNode);
            treMartialArts.Nodes[0].Expand();

            treMartialArts.SelectedNode = objNode;

            _objFunctions.SortTree(treMartialArts);
            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#24
0
        private void cmdNuyenSpent_Click(object sender, EventArgs e)
        {
            frmExpense frmNewExpense = new frmExpense();
            frmNewExpense.Mode = ExpenseType.Nuyen;
            frmNewExpense.ShowDialog(this);

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

            // Make sure the Nuyen expense would not put the character's remaining Nuyen amount below 0.
            if (_objCharacter.Nuyen - frmNewExpense.Amount < 0)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Create the Expense Log Entry.
            ExpenseLogEntry objEntry = new ExpenseLogEntry();
            objEntry.Create(frmNewExpense.Amount * -1, frmNewExpense.strReason, ExpenseType.Nuyen, frmNewExpense.SelectedDate);
            _objCharacter.ExpenseEntries.Add(objEntry);

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateNuyen(NuyenExpenseType.ManualSubtract, "");
            objEntry.Undo = objUndo;

            // Adjust the character's Nuyen total.
            _objCharacter.Nuyen += frmNewExpense.Amount * -1;

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#25
0
        private void cmdAddQuality_Click(object sender, EventArgs e)
        {
            frmSelectQuality frmPickQuality = new frmSelectQuality(_objCharacter);
            frmPickQuality.ShowDialog(this);

            // Don't do anything else if the form was canceled.
            if (frmPickQuality.DialogResult == DialogResult.Cancel)
                return;

            XmlDocument objXmlDocument = XmlManager.Instance.Load("qualities.xml");
            XmlNode objXmlQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + frmPickQuality.SelectedQuality + "\"]");

            TreeNode objNode = new TreeNode();
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            Quality objQuality = new Quality(_objCharacter);

            objQuality.Create(objXmlQuality, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes);
            objNode.ContextMenuStrip = cmsQuality;
            if (objQuality.InternalId == Guid.Empty.ToString())
                return;

            if (frmPickQuality.FreeCost)
                objQuality.BP = 0;

            bool blnAddItem = true;
            int intKarmaCost = objQuality.BP * _objOptions.KarmaQuality;
            if (!_objCharacter.Options.DontDoubleQualities)
                intKarmaCost *= 2;

            // Make sure the character has enough Karma to pay for the Quality.
            if (objQuality.Type == QualityType.Positive)
            {
                if (intKarmaCost > _objCharacter.Karma)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    blnAddItem = false;
                }

                if (blnAddItem && !frmPickQuality.FreeCost && objQuality.ContributeToBP)
                {
                    if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseSpend").Replace("{0}", objQuality.DisplayNameShort).Replace("{1}", intKarmaCost.ToString())))
                        blnAddItem = false;
                }

                if (blnAddItem && objQuality.ContributeToBP)
                {
                    // Create the Karma expense.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseAddPositiveQuality") + " " + objQuality.DisplayNameShort, ExpenseType.Karma, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Karma -= intKarmaCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateKarma(KarmaExpenseType.AddQuality, objQuality.InternalId);
                    objExpense.Undo = objUndo;
                }
            }
            else
            {
                if (MessageBox.Show(LanguageManager.Instance.GetString("Message_AddNegativeQuality"), LanguageManager.Instance.GetString("MessageTitle_AddNegativeQuality"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    blnAddItem = false;

                if (blnAddItem)
                {
                    // Create a Karma Expense for the Negative Quality.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(0, LanguageManager.Instance.GetString("String_ExpenseAddNegativeQuality") + " " + objQuality.DisplayNameShort, ExpenseType.Karma, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateKarma(KarmaExpenseType.AddQuality, objQuality.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            if (blnAddItem)
            {
                // Add the Quality to the appropriate parent node.
                if (objQuality.Type == QualityType.Positive)
                {
                    treQualities.Nodes[0].Nodes.Add(objNode);
                    treQualities.Nodes[0].Expand();
                }
                else
                {
                    treQualities.Nodes[1].Nodes.Add(objNode);
                    treQualities.Nodes[1].Expand();
                }
                _objCharacter.Qualities.Add(objQuality);

                // Add any created Weapons to the character.
                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 (objXmlQuality.SelectNodes("addqualities/addquality").Count > 0)
                {
                    foreach (XmlNode objXmlAddQuality in objXmlQuality.SelectNodes("addqualities/addquality"))
                    {
                        XmlNode objXmlSelectedQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlAddQuality.InnerText + "\"]");
                        string strForceValue = "";
                        if (objXmlAddQuality.Attributes["select"] != null)
                            strForceValue = objXmlAddQuality.Attributes["select"].InnerText;
                        bool blnAddQuality = true;

                        // Make sure the character does not yet have this Quality.
                        foreach (Quality objCharacterQuality in _objCharacter.Qualities)
                        {
                            if (objCharacterQuality.Name == objXmlAddQuality.InnerText && objCharacterQuality.Extra == strForceValue)
                            {
                                blnAddQuality = false;
                                break;
                            }
                        }

                        if (blnAddQuality)
                        {
                            TreeNode objAddQualityNode = new TreeNode();
                            List<Weapon> objAddWeapons = new List<Weapon>();
                            List<TreeNode> objAddWeaponNodes = new List<TreeNode>();
                            Quality objAddQuality = new Quality(_objCharacter);
                            objAddQuality.Create(objXmlSelectedQuality, _objCharacter, QualitySource.Selected, objAddQualityNode, objAddWeapons, objAddWeaponNodes, strForceValue);
                            objNode.Nodes.Add(objAddQualityNode);
                            objNode.Expand();
                            _objCharacter.Qualities.Add(objAddQuality);

                            // Add any created Weapons to the character.
                            foreach (Weapon objWeapon in objAddWeapons)
                                _objCharacter.Weapons.Add(objWeapon);

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

                // Add any Critter Powers that are gained through the Quality (Infected).
                if (objXmlQuality.SelectNodes("powers/power").Count > 0)
                {
                    objXmlDocument = XmlManager.Instance.Load("critterpowers.xml");
                    foreach (XmlNode objXmlPower in objXmlQuality.SelectNodes("powers/power"))
                    {
                        XmlNode objXmlCritterPower = objXmlDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower.InnerText + "\"]");
                        TreeNode objPowerNode = 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, objPowerNode, intRating, strForcedValue);
                        _objCharacter.CritterPowers.Add(objPower);

                        if (objPower.Category != "Weakness")
                        {
                            treCritterPowers.Nodes[0].Nodes.Add(objPowerNode);
                            treCritterPowers.Nodes[0].Expand();
                        }
                        else
                        {
                            treCritterPowers.Nodes[1].Nodes.Add(objPowerNode);
                            treCritterPowers.Nodes[1].Expand();
                        }
                    }
                }
            }
            else
            {
                // Remove the Improvements created by the Create method.
                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Quality, objQuality.InternalId);
            }

            // If the Quality is a mentor spirit, add any qualities particular to the mentor spirit.
            if (objQuality.Name == "Mentor Spirit")
            {
                XmlDocument objXmlMentors = XmlManager.Instance.Load("mentors.xml");
                XmlNode objXmlMentor = objXmlMentors.SelectSingleNode("/chummer/mentors/mentor[name = \"" + objQuality.Extra + "\"]");
                XmlNode objXmlAddQualities = objXmlMentor["addqualities"];

                // If there are additional qualities
                if (objXmlAddQualities != null)
                {
                    foreach (XmlNode objXmlAddQuality in objXmlAddQualities.ChildNodes)
                    {
                        XmlNode objXmlMentorQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlAddQuality.InnerText + "\"]");

                        TreeNode objMentorNode = new TreeNode();
                        List<Weapon> objMentorWeapons = new List<Weapon>();
                        List<TreeNode> objMentorWeaponNodes = new List<TreeNode>();
                        Quality objSpiritQuality = new Quality(_objCharacter);
                        string strExtra = "";
                        if (objXmlAddQuality.Attributes["select"].InnerText.ToString().Length > 0)
                        {
                            strExtra = objXmlAddQuality.Attributes["select"].InnerText.ToString();
                            objSpiritQuality.Create(objXmlMentorQuality, _objCharacter, QualitySource.Selected, objMentorNode, objMentorWeapons, objMentorWeaponNodes, strExtra);
                        }
                        else
                            objSpiritQuality.Create(objXmlMentorQuality, _objCharacter, QualitySource.Selected, objMentorNode, objMentorWeapons, objMentorWeaponNodes);

                        objSpiritQuality.BP = 0;

                        // Add the quality to the character
                        if (objSpiritQuality.Type == QualityType.Positive)
                        {
                            treQualities.Nodes[0].Nodes.Add(objMentorNode);
                            treQualities.Nodes[0].Expand();
                        }
                        else
                        {
                            treQualities.Nodes[1].Nodes.Add(objMentorNode);
                            treQualities.Nodes[1].Expand();
                        }
                        _objCharacter.Qualities.Add(objSpiritQuality);
                    }
                }
            }

            _objFunctions.SortTree(treQualities);
            UpdateMentorSpirits();
            UpdateCharacterInfo();
            RefreshPowers();
            RefreshContacts();

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickQuality.AddAgain)
                cmdAddQuality_Click(sender, e);
        }
示例#26
0
        private void cmdSwapQuality_Click(object sender, EventArgs e)
        {
            // Locate the selected Quality.
            try
            {
                if (treQualities.SelectedNode.Level == 0)
                    return;
            }
            catch
            {
                return;
            }

            Quality objQuality = _objFunctions.FindQuality(treQualities.SelectedNode.Tag.ToString(), _objCharacter.Qualities);

            // Qualities that come from a Metatype cannot be removed.
            if (objQuality.OriginSource == QualitySource.Metatype)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_MetavariantQualitySwap"), LanguageManager.Instance.GetString("MessageTitle_MetavariantQualitySwap"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            frmSelectQuality frmPickQuality = new frmSelectQuality(_objCharacter);
            frmPickQuality.ForceCategory = objQuality.Type.ToString();
            frmPickQuality.IgnoreQuality = objQuality.Name;
            frmPickQuality.ShowDialog(this);

            // Don't do anything else if the form was canceled.
            if (frmPickQuality.DialogResult == DialogResult.Cancel)
                return;

            XmlDocument objXmlDocument = XmlManager.Instance.Load("qualities.xml");
            XmlNode objXmlQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + frmPickQuality.SelectedQuality + "\"]");

            TreeNode objNode = new TreeNode();
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            Quality objNewQuality = new Quality(_objCharacter);

            objNewQuality.Create(objXmlQuality, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes);
            objNode.ContextMenuStrip = cmsQuality;
            if (objQuality.InternalId == Guid.Empty.ToString())
                return;

            bool blnAddItem = true;
            int intKarmaCost = (objNewQuality.BP - objQuality.BP) * _objOptions.KarmaQuality;

            // Make sure the character has enough Karma to pay for the Quality.
            if (objNewQuality.Type == QualityType.Positive)
            {
                if (intKarmaCost > _objCharacter.Karma)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    blnAddItem = false;
                }

                if (blnAddItem)
                {
                    if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_QualitySwap").Replace("{0}", objQuality.DisplayNameShort).Replace("{1}", objNewQuality.DisplayNameShort)))
                        blnAddItem = false;
                }

                if (blnAddItem)
                {
                    // Create the Karma expense.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseSwapPositiveQuality").Replace("{0}", objQuality.DisplayNameShort).Replace("{1}", objNewQuality.DisplayNameShort), ExpenseType.Karma, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Karma -= intKarmaCost;
                }
            }
            else
            {
                // This should only happen when a character is trading up to a less-costly Quality.
                if (intKarmaCost > 0)
                {
                    if (intKarmaCost > _objCharacter.Karma)
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        blnAddItem = false;
                    }

                    if (blnAddItem)
                    {
                        if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_QualitySwap").Replace("{0}", objQuality.Name).Replace("{1}", objNewQuality.Name)))
                            blnAddItem = false;
                    }

                    if (blnAddItem)
                    {
                        // Create the Karma expense.
                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                        objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseSwapNegativeQuality").Replace("{0}", objQuality.DisplayNameShort).Replace("{1}", objNewQuality.DisplayNameShort), ExpenseType.Karma, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objExpense);
                        _objCharacter.Karma -= intKarmaCost;
                    }
                }
            }

            if (blnAddItem)
            {
                // Add the Quality to the appropriate parent node.
                treQualities.SelectedNode.Remove();
                if (objNewQuality.Type == QualityType.Positive)
                {
                    treQualities.Nodes[0].Nodes.Add(objNode);
                    treQualities.Nodes[0].Expand();
                }
                else
                {
                    treQualities.Nodes[1].Nodes.Add(objNode);
                    treQualities.Nodes[1].Expand();
                }

                // Add any created Weapons to the character.
                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();
                }

                // If the new Quality is linked to a Latent source, see if the Quality that is being swapped out is the same as the one the new Quality is linked to.
                // If so, set the character's OverrideSpecialAttributeEssenceLoss to true so that they always start with a Special Attribute value of 1.
                if (objXmlQuality["latentsource"] != null)
                {
                    if (objXmlQuality["latentsource"].InnerText == objQuality.Name)
                        _objCharacter.OverrideSpecialAttributeEssenceLoss = true;
                }

                // Add any additional Qualities that are forced on the character.
                if (objXmlQuality.SelectNodes("addqualities/addquality").Count > 0)
                {
                    foreach (XmlNode objXmlAddQuality in objXmlQuality.SelectNodes("addqualities/addquality"))
                    {
                        XmlNode objXmlSelectedQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlAddQuality.InnerText + "\"]");
                        string strForceValue = "";
                        if (objXmlAddQuality.Attributes["select"] != null)
                            strForceValue = objXmlAddQuality.Attributes["select"].InnerText;
                        bool blnAddQuality = true;

                        // Make sure the character does not yet have this Quality.
                        foreach (Quality objCharacterQuality in _objCharacter.Qualities)
                        {
                            if (objCharacterQuality.Name == objXmlAddQuality.InnerText && objCharacterQuality.Extra == strForceValue)
                            {
                                blnAddQuality = false;
                                break;
                            }
                        }

                        if (blnAddQuality)
                        {
                            TreeNode objAddQualityNode = new TreeNode();
                            List<Weapon> objAddWeapons = new List<Weapon>();
                            List<TreeNode> objAddWeaponNodes = new List<TreeNode>();
                            Quality objAddQuality = new Quality(_objCharacter);
                            objAddQuality.Create(objXmlSelectedQuality, _objCharacter, QualitySource.Selected, objAddQualityNode, objWeapons, objWeaponNodes, strForceValue);
                            objNode.Nodes.Add(objAddQualityNode);
                            objNode.Expand();
                            _objCharacter.Qualities.Add(objAddQuality);

                            // Add any created Weapons to the character.
                            foreach (Weapon objWeapon in objAddWeapons)
                                _objCharacter.Weapons.Add(objWeapon);

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

                // Remove any Improvements for the old Quality.
                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Quality, objQuality.InternalId);
                _objCharacter.Qualities.Remove(objQuality);

                // Remove any Weapons created by the old Quality if applicable.
                if (objQuality.WeaponID != Guid.Empty.ToString())
                {
                    // Remove the Weapon from the TreeView.
                    TreeNode objRemoveNode = new TreeNode();
                    foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                    {
                        if (objWeaponNode.Tag.ToString() == objQuality.WeaponID)
                            objRemoveNode = objWeaponNode;
                    }
                    treWeapons.Nodes.Remove(objRemoveNode);

                    // Remove the Weapon from the Character.
                    Weapon objRemoveWeapon = new Weapon(_objCharacter);
                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                    {
                        if (objWeapon.InternalId == objQuality.WeaponID)
                            objRemoveWeapon = objWeapon;
                    }
                    _objCharacter.Weapons.Remove(objRemoveWeapon);
                }

                // Add the new Quality to the character.
                _objCharacter.Qualities.Add(objNewQuality);
            }

            UpdateMentorSpirits();
            UpdateCharacterInfo();
            RefreshContacts();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#27
0
        private void cmdAddSpell_Click(object sender, EventArgs e)
        {
            // Make sure the character has enough Karma before letting them select a Spell.
            if (_objCharacter.Karma < _objOptions.KarmaSpell)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Run through the list of Active Skills and pick out the two applicable ones.
            int intSkillValue = 0;
            foreach (SkillControl objSkillControl in panActiveSkills.Controls)
            {
                if ((objSkillControl.SkillName == "Spellcasting" || objSkillControl.SkillName == "Ritual Spellcasting") && objSkillControl.SkillRating > intSkillValue)
                    intSkillValue = objSkillControl.SkillRating;
            }

            frmSelectSpell frmPickSpell = new frmSelectSpell(_objCharacter);
            frmPickSpell.ShowDialog(this);
            // Make sure the dialogue window was not canceled.
            if (frmPickSpell.DialogResult == DialogResult.Cancel)
                return;

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

            XmlNode objXmlSpell = objXmlDocument.SelectSingleNode("/chummer/spells/spell[name = \"" + frmPickSpell.SelectedSpell + "\"]");

            Spell objSpell = new Spell(_objCharacter);
            TreeNode objNode = new TreeNode();
            objSpell.Create(objXmlSpell, _objCharacter, objNode, "", frmPickSpell.Limited, frmPickSpell.Extended, frmPickSpell.Alchemical);
            objNode.ContextMenuStrip = cmsSpell;
            if (objSpell.InternalId == Guid.Empty.ToString())
                return;

            if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseSpend").Replace("{0}", objSpell.DisplayName).Replace("{1}", _objOptions.KarmaSpell.ToString())))
                return;

            _objCharacter.Spells.Add(objSpell);

            switch (objSpell.Category)
            {
                case "Combat":
                    treSpells.Nodes[0].Nodes.Add(objNode);
                    treSpells.Nodes[0].Expand();
                    break;
                case "Detection":
                    treSpells.Nodes[1].Nodes.Add(objNode);
                    treSpells.Nodes[1].Expand();
                    break;
                case "Health":
                    treSpells.Nodes[2].Nodes.Add(objNode);
                    treSpells.Nodes[2].Expand();
                    break;
                case "Illusion":
                    treSpells.Nodes[3].Nodes.Add(objNode);
                    treSpells.Nodes[3].Expand();
                    break;
                case "Manipulation":
                    treSpells.Nodes[4].Nodes.Add(objNode);
                    treSpells.Nodes[4].Expand();
                    break;
                case "Rituals":
                    int intNode = 5;
                    if (_objCharacter.AdeptEnabled && !_objCharacter.MagicianEnabled)
                        intNode = 0;
                    treSpells.Nodes[intNode].Nodes.Add(objNode);
                    treSpells.Nodes[intNode].Expand();
                    break;
                case "Enchantments":
                    treSpells.Nodes[6].Nodes.Add(objNode);
                    treSpells.Nodes[6].Expand();
                    break;
            }

            treSpells.SelectedNode = objNode;

            // Create the Expense Log Entry.
            ExpenseLogEntry objEntry = new ExpenseLogEntry();
            objEntry.Create(_objOptions.KarmaSpell * -1, LanguageManager.Instance.GetString("String_ExpenseLearnSpell") + " " + objSpell.Name, ExpenseType.Karma, DateTime.Now);
            _objCharacter.ExpenseEntries.Add(objEntry);
            _objCharacter.Karma -= _objOptions.KarmaSpell;

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateKarma(KarmaExpenseType.AddSpell, objSpell.InternalId);
            objEntry.Undo = objUndo;

            _objFunctions.SortTree(treSpells);
            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickSpell.AddAgain)
                cmdAddSpell_Click(sender, e);
        }
示例#28
0
        private void cmdChangeSpec_Click(object sender, EventArgs e)
        {
            if (_objSkill.CharacterObject.Karma < _objSkill.CharacterObject.Options.KarmaSpecialization)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            XmlDocument objXmlDocument = new XmlDocument();
            objXmlDocument = XmlManager.Instance.Load("skills.xml");

            // When the selected Knowledge Skill is changed, check the Skill file and build the pre-defined list of its Specializations (if any).
            List<ListItem> lstSpecializations = new List<ListItem>();
            XmlNode objXmlSkill;
            if (_objSkill.KnowledgeSkill)
            {
                objXmlSkill = objXmlDocument.SelectSingleNode("/chummer/knowledgeskills/skill[name = \"" + _objSkill.Name + "\"]");
                if (objXmlSkill == null)
                    objXmlSkill = objXmlDocument.SelectSingleNode("/chummer/knowledgeskills/skill[translate = \"" + _objSkill.Name + "\"]");
            }
            else
            {
                objXmlSkill = objXmlDocument.SelectSingleNode("/chummer/skills/skill[name = \"" + _objSkill.Name + "\"]");
                if (objXmlSkill == null)
                    objXmlSkill = objXmlDocument.SelectSingleNode("/chummer/skills/skill[translate = \"" + _objSkill.Name + "\"]");
            }
            if (objXmlSkill != null)
            {
                if (!_blnSkipRefresh)
                    cboKnowledgeSkillCategory.SelectedValue = objXmlSkill["category"].InnerText;
                cboSpec.Items.Clear();
                foreach (XmlNode objXmlSpecialization in objXmlSkill.SelectNodes("specs/spec"))
                {
                    bool blnFound = false;
                    foreach(SkillSpecialization objSpecialization in _objSkill.Specializations)
                    {
                        if (objSpecialization.Name == objXmlSpecialization.InnerText)
                        {
                            blnFound = true;
                            break;
                        }
                    }
                    if (!blnFound)
                    {
                        ListItem objItem = new ListItem();
                        if (objXmlSpecialization["translate"] != null)
                            objItem.Name = objXmlSpecialization["translate"].InnerText;
                        else
                            objItem.Name = objXmlSpecialization.InnerText;
                        objItem.Value = objItem.Name;
                        lstSpecializations.Add(objItem);
                    }
                }
            }

            if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseSkillSpecialization").Replace("{0}", _objSkill.CharacterObject.Options.KarmaSpecialization.ToString())))
                return;

            frmSelectItem frmPickItem = new frmSelectItem();
            frmPickItem.DropdownItems = lstSpecializations;
            frmPickItem.ShowDialog();

            if (frmPickItem.DialogResult == DialogResult.Cancel)
            {
                return;
            }

            string strSelectedValue = frmPickItem.SelectedItem;

            // charge the karma and add the spec
            SkillSpecialization objSpec = new SkillSpecialization(strSelectedValue);
            _objSkill.Specializations.Add(objSpec);

            // Create the Expense Log Entry.
            ExpenseLogEntry objEntry = new ExpenseLogEntry();
            objEntry.Create(_objSkill.CharacterObject.Options.KarmaSpecialization * -1, LanguageManager.Instance.GetString("String_ExpenseLearnSpecialization") + " " + _objSkill.Name + " (" + strSelectedValue + ")", ExpenseType.Karma, DateTime.Now);
            _objSkill.CharacterObject.ExpenseEntries.Add(objEntry);
            _objSkill.CharacterObject.Karma -= _objSkill.CharacterObject.Options.KarmaSpecialization;

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateKarma(KarmaExpenseType.AddSpecialization, objSpec.InternalId);
            objEntry.Undo = objUndo;

            lblSpec.Text = _objSkill.Specialization;

            this.Height = lblSpec.Height + 10;

            RatingChanged(this);
        }
示例#29
0
        private void cmdAddWeapon_Click(object sender, EventArgs e)
        {
            frmSelectWeapon frmPickWeapon = new frmSelectWeapon(_objCharacter, true);
            frmPickWeapon.ShowDialog(this);

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

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

            XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + frmPickWeapon.SelectedWeapon + "\"]");

            TreeNode objNode = new TreeNode();
            Weapon objWeapon = new Weapon(_objCharacter);
            objWeapon.Create(objXmlWeapon, _objCharacter, objNode, cmsWeapon, cmsWeaponAccessory, cmsWeaponMod);

            int intCost = objWeapon.TotalCost;
            // Apply a markup if applicable.
            if (frmPickWeapon.Markup != 0)
            {
                double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo);
                dblCost *= 1 + (Convert.ToDouble(frmPickWeapon.Markup, GlobalOptions.Instance.CultureInfo) / 100.0);
                intCost = Convert.ToInt32(dblCost);
            }

            // Multiply the cost if applicable.
            if (objWeapon.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailRestricted")) && _objOptions.MultiplyRestrictedCost)
                intCost *= _objOptions.RestrictedCostMultiplier;
            if (objWeapon.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 (!frmPickWeapon.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (frmPickWeapon.AddAgain)
                        cmdAddWeapon_Click(sender, e);

                    return;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseWeapon") + " " + objWeapon.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddWeapon, objWeapon.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            _objCharacter.Weapons.Add(objWeapon);

            objNode.ContextMenuStrip = cmsWeapon;
            treWeapons.Nodes[0].Nodes.Add(objNode);
            treWeapons.Nodes[0].Expand();
            treWeapons.SelectedNode = objNode;

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickWeapon.AddAgain)
                cmdAddWeapon_Click(sender, e);
        }
示例#30
0
        private void cmdDeleteQuality_Click(object sender, EventArgs e)
        {
            bool blnMetatypeQuality = false;

            // Locate the selected Quality.
            try
            {
                if (treQualities.SelectedNode.Level == 0)
                    return;
            }
            catch
            {
                return;
            }

            Quality objQuality = _objFunctions.FindQuality(treQualities.SelectedNode.Tag.ToString(), _objCharacter.Qualities);

            XmlDocument objXmlDocument = XmlManager.Instance.Load("qualities.xml");

            // Qualities that come from a Metatype cannot be removed.
            if (objQuality.OriginSource == QualitySource.Metatype)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_MetavariantQuality"), LanguageManager.Instance.GetString("MessageTitle_MetavariantQuality"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else if (objQuality.OriginSource == QualitySource.MetatypeRemovable)
            {
                // Look up the cost of the Quality.
                XmlNode objXmlMetatypeQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objQuality.Name + "\"]");
                int intBP = Convert.ToInt32(objXmlMetatypeQuality["bp"].InnerText) * -2;
                int intShowBP = intBP * _objOptions.KarmaQuality;
                string strBP = intShowBP.ToString() + " " + LanguageManager.Instance.GetString("String_Karma");

                if (!_objFunctions.ConfirmDelete(LanguageManager.Instance.GetString("Message_DeleteMetatypeQuality").Replace("{0}", strBP)))
                    return;

                blnMetatypeQuality = true;
            }

            if (objQuality.Type == QualityType.Positive)
            {
                if (!blnMetatypeQuality)
                {
                    if (!_objFunctions.ConfirmDelete(LanguageManager.Instance.GetString("Message_DeletePositiveQualityCareer")))
                        return;
                }

                // Remove the Improvements that were created by the Quality.
                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Quality, objQuality.InternalId);

                if (objQuality.Name == "One Trick Pony")
                {
                    if (treMartialArts.Nodes[1].Nodes.Count > 0)
                    {
                        foreach (MartialArt objMartialArt in _objCharacter.MartialArts)
                        {
                            if (objMartialArt.Name == "One Trick Pony")
                            {
                                _objCharacter.MartialArts.Remove(objMartialArt);
                                treMartialArts.Nodes[1].Nodes[0].Remove();
                                break;
                            }
                        }
                    }
                }

                _objCharacter.Qualities.Remove(objQuality);
                treQualities.SelectedNode.Remove();
            }
            else
            {
                // Make sure the character has enough Karma to buy off the Quality.
                int intKarmaCost = (objQuality.BP * _objOptions.KarmaQuality) * -2;
                if (intKarmaCost > _objCharacter.Karma)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (!blnMetatypeQuality)
                {
                    if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseRemove").Replace("{0}", objQuality.DisplayNameShort).Replace("{1}", intKarmaCost.ToString())))
                        return;
                }

                // Create the Karma expense.
                ExpenseLogEntry objExpense = new ExpenseLogEntry();
                objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseRemoveNegativeQuality") + " " + objQuality.DisplayNameShort, ExpenseType.Karma, DateTime.Now);
                _objCharacter.ExpenseEntries.Add(objExpense);
                _objCharacter.Karma -= intKarmaCost;

                ExpenseUndo objUndo = new ExpenseUndo();
                objUndo.CreateKarma(KarmaExpenseType.RemoveQuality, objQuality.Name);
                objUndo.Extra = objQuality.Extra;
                objExpense.Undo = objUndo;

                // Remove the Improvements that were created by the Quality.
                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Quality, objQuality.InternalId);

                _objCharacter.Qualities.Remove(objQuality);
                treQualities.SelectedNode.Remove();
            }

                // Remove any Critter Powers that are gained through the Quality (Infected).
            XmlNode objXmlDeleteQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objQuality.Name + "\"]");
                if (objXmlDeleteQuality.SelectNodes("powers/power").Count > 0)
                {
                    objXmlDocument = XmlManager.Instance.Load("critterpowers.xml");
                foreach (XmlNode objXmlPower in objXmlDeleteQuality.SelectNodes("optionalpowers/optionalpower"))
                    {
                        string strExtra = "";
                        if (objXmlPower.Attributes["select"] != null)
                            strExtra = objXmlPower.Attributes["select"].InnerText;

                        foreach (CritterPower objPower in _objCharacter.CritterPowers)
                        {
                            if (objPower.Name == objXmlPower.InnerText && objPower.Extra == strExtra)
                            {
                                // Remove any Improvements created by the Critter Power.
                                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.CritterPower, objPower.InternalId);

                                // Remove the Critter Power from the character.
                                _objCharacter.CritterPowers.Remove(objPower);

                                // Remove the Critter Power from the Tree.
                                foreach (TreeNode objNode in treCritterPowers.Nodes[0].Nodes)
                                {
                                    if (objNode.Tag.ToString() == objPower.InternalId)
                                    {
                                        objNode.Remove();
                                        break;
                                    }
                                }
                                foreach (TreeNode objNode in treCritterPowers.Nodes[1].Nodes)
                                {
                                    if (objNode.Tag.ToString() == objPower.InternalId)
                                    {
                                        objNode.Remove();
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            // Remove any Critter Powers that are gained through the Quality (Infected).
            if (objXmlDeleteQuality.SelectNodes("addqualities/addquality").Count > 0)
            {
                objXmlDocument = XmlManager.Instance.Load("critterpowers.xml");
                foreach (XmlNode objXmlQuality in objXmlDeleteQuality.SelectNodes("addqualities/addquality"))
                {
                    string strExtra = "";
                    if (objXmlQuality.Attributes["select"] != null)
                        strExtra = objXmlQuality.Attributes["select"].InnerText;

                    foreach (Quality objDeleteQuality in _objCharacter.Qualities)
                    {
                        if (objDeleteQuality.Name == objXmlQuality.InnerText && objDeleteQuality.Extra == strExtra)
                        {
                            // Remove any Improvements created by the Critter Power.
                            _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.CritterPower, objDeleteQuality.InternalId);

                            // Remove the Critter Power from the character.
                            _objCharacter.Qualities.Remove(objDeleteQuality);
                            break;
                        }
                        // Remove the Critter Power from the Tree.
                        foreach (TreeNode objNode in treQualities.Nodes)
                        {
                            if (objNode.Nodes.Count > 0)
                            {
                                foreach (TreeNode objChildNode in objNode.Nodes)
                                {
                                    if (objNode.Tag.ToString() == objDeleteQuality.InternalId)
                                    {
                                        objNode.Remove();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Remove any Weapons created by the Quality if applicable.
            if (objQuality.WeaponID != Guid.Empty.ToString())
            {
                // Remove the Weapon from the TreeView.
                TreeNode objRemoveNode = new TreeNode();
                foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                {
                    if (objWeaponNode.Tag.ToString() == objQuality.WeaponID)
                        objRemoveNode = objWeaponNode;
                }
                treWeapons.Nodes.Remove(objRemoveNode);

                // Remove the Weapon from the Character.
                Weapon objRemoveWeapon = new Weapon(_objCharacter);
                foreach (Weapon objWeapon in _objCharacter.Weapons)
                {
                    if (objWeapon.InternalId == objQuality.WeaponID)
                        objRemoveWeapon = objWeapon;
                }
                _objCharacter.Weapons.Remove(objRemoveWeapon);
            }

            UpdateMentorSpirits();
            UpdateCharacterInfo();
            RefreshContacts();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#31
0
        private void cmdDeleteVehicle_Click(object sender, EventArgs e)
        {
            // Delete the selected Vehicle.
            try
            {
                if (treVehicles.SelectedNode.Level == 0)
                    return;
            }
            catch
            {
                return;
            }

            if (treVehicles.SelectedNode.Level != 2)
            {
                if (!_objFunctions.ConfirmDelete(LanguageManager.Instance.GetString("Message_DeleteVehicle")))
                    return;
            }

            if (treVehicles.SelectedNode.Level == 1)
            {
                // Locate the Vehicle that is selected in the tree.
                Vehicle objVehicle = _objFunctions.FindVehicle(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles);

                // Remove any Gear Improvements from the character (primarily those provided by an Emotitoy).
                foreach (Gear objGear in objVehicle.Gear)
                    _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objGear.InternalId);

                _objCharacter.Vehicles.Remove(objVehicle);
                treVehicles.SelectedNode.Remove();
            }
            else if (treVehicles.SelectedNode.Level == 2)
            {
                bool blnFound = false;
                // Locate the VehicleMod that is selected in the tree.
                Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                VehicleMod objMod = _objFunctions.FindVehicleMod(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                if (objMod != null)
                {
                    blnFound = true;

                    if (!_objFunctions.ConfirmDelete(LanguageManager.Instance.GetString("Message_DeleteVehicle")))
                        return;

                    // Check for Improved Sensor bonus.
                    if (objMod.Bonus != null)
                    {
                        if (objMod.Bonus["improvesensor"] != null)
                        {
                            ChangeVehicleSensor(objFoundVehicle, false);
                        }
                    }

                    // If this is the Obsolete Mod, the user must select a percentage. This will create an Expense that costs X% of the Vehicle's base cost to remove the special Obsolete Mod.
                    if (objMod.Name == "Obsolete" || (objMod.Name == "Obsolescent" && _objOptions.AllowObsolescentUpgrade))
                    {
                        frmSelectNumber frmModPercent = new frmSelectNumber();
                        frmModPercent.Minimum = 0;
                        frmModPercent.Maximum = 1000;
                        frmModPercent.Description = LanguageManager.Instance.GetString("String_Retrofit");
                        frmModPercent.ShowDialog(this);

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

                        int intPercentage = frmModPercent.SelectedValue;
                        int intVehicleCost = Convert.ToInt32(objFoundVehicle.Cost);

                        // Make sure the character has enough Nuyen for the expense.
                        int intCost = Convert.ToInt32(Convert.ToDouble(intVehicleCost, GlobalOptions.Instance.CultureInfo) * (Convert.ToDouble(intPercentage, GlobalOptions.Instance.CultureInfo) / 100.0), GlobalOptions.Instance.CultureInfo);
                        if (intCost > _objCharacter.Nuyen)
                        {
                            MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }

                        // Create a Vehicle Mod for the Retrofit.
                        VehicleMod objRetrofit = new VehicleMod(_objCharacter);

                        XmlDocument objVehiclesDoc = XmlManager.Instance.Load("vehicles.xml");
                        XmlNode objXmlNode = objVehiclesDoc.SelectSingleNode("/chummer/mods/mod[name = \"Retrofit\"]");
                        TreeNode objTreeNode = new TreeNode();
                        objRetrofit.Create(objXmlNode, objTreeNode, 0);
                        objRetrofit.Cost = intCost.ToString();
                        objFoundVehicle.Mods.Add(objRetrofit);
                        treVehicles.SelectedNode.Parent.Nodes.Add(objTreeNode);

                        // Create an Expense Log Entry for removing the Obsolete Mod.
                        ExpenseLogEntry objEntry = new ExpenseLogEntry();
                        objEntry.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpenseVehicleRetrofit").Replace("{0}", objFoundVehicle.DisplayName), ExpenseType.Nuyen, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objEntry);

                        // Adjust the character's Nuyen total.
                        _objCharacter.Nuyen += intCost * -1;
                    }

                    objFoundVehicle.Mods.Remove(objMod);
                    treVehicles.SelectedNode.Remove();
                }

                if (!blnFound)
                {
                    // Locate the Sensor or Ammunition that is selected in the tree.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (Gear objGear in objCharacterVehicle.Gear)
                        {
                            if (objGear.InternalId == treVehicles.SelectedNode.Tag.ToString())
                            {
                                if (!_objFunctions.ConfirmDelete(LanguageManager.Instance.GetString("Message_DeleteVehicle")))
                                    return;

                                // Remove the Gear Weapon created by the Gear if applicable.
                                if (objGear.WeaponID != Guid.Empty.ToString())
                                {
                                    // Remove the Weapon from the TreeView.
                                    foreach (TreeNode objWeaponNode in treVehicles.SelectedNode.Parent.Nodes)
                                    {
                                        if (objWeaponNode.Tag.ToString() == objGear.WeaponID)
                                        {
                                            treVehicles.SelectedNode.Parent.Nodes.Remove(objWeaponNode);
                                            break;
                                        }
                                    }

                                    // Remove the Weapon from the Vehicle.
                                    Weapon objRemoveWeapon = new Weapon(_objCharacter);
                                    foreach (Weapon objWeapon in objCharacterVehicle.Weapons)
                                    {
                                        if (objWeapon.InternalId == objGear.WeaponID)
                                            objRemoveWeapon = objWeapon;
                                    }
                                    objCharacterVehicle.Weapons.Remove(objRemoveWeapon);
                                }

                                objCharacterVehicle.Gear.Remove(objGear);
                                treVehicles.SelectedNode.Remove();
                                blnFound = true;
                                break;
                            }
                        }
                    }
                }

                if (!blnFound)
                {
                    // Locate the Weapon that is selected in the tree.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (Weapon objWeapon in objCharacterVehicle.Weapons)
                        {
                            if (objWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                            {
                                blnFound = true;
                                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotRemoveGearWeaponVehicle"), LanguageManager.Instance.GetString("MessageTitle_CannotRemoveGearWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                                break;
                            }
                        }
                    }
                }

                if (!blnFound)
                {
                    // This must be a Location, so find it.
                    TreeNode objVehicleNode = treVehicles.SelectedNode.Parent;
                    Vehicle objVehicle = _objFunctions.FindVehicle(objVehicleNode.Tag.ToString(), _objCharacter.Vehicles);

                    if (!_objFunctions.ConfirmDelete(LanguageManager.Instance.GetString("Message_DeleteVehicleLocation")))
                        return;

                    // Change the Location of the Gear.
                    foreach (Gear objGear in objVehicle.Gear)
                    {
                        if (objGear.Location == treVehicles.SelectedNode.Text)
                            objGear.Location = "";
                    }

                    // Move all of the child nodes in the current parent to the Vehicle.
                    List<TreeNode> lstMoveNodes = new List<TreeNode>();
                    foreach (TreeNode objNode in treVehicles.SelectedNode.Nodes)
                        lstMoveNodes.Add(objNode);

                    foreach (TreeNode objNode in lstMoveNodes)
                    {
                        treVehicles.SelectedNode.Nodes.Remove(objNode);
                        objVehicleNode.Nodes.Add(objNode);
                    }

                    // Remove the Location from the Vehicle, then remove the selected node.
                    objVehicle.Locations.Remove(treVehicles.SelectedNode.Text);
                    treVehicles.SelectedNode.Remove();
                }
            }
            else if (treVehicles.SelectedNode.Level == 3)
            {
                bool blnFound = false;
                // Locate the selected VehicleWeapon that is selected in the tree.
                foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                {
                    foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                    {
                        foreach (Weapon objWeapon in objMod.Weapons)
                        {
                            if (objWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                            {
                                objMod.Weapons.Remove(objWeapon);
                                treVehicles.SelectedNode.Remove();
                                blnFound = true;
                                break;
                            }
                        }
                    }
                }

                if (!blnFound)
                {
                    // Locate the selected Sensor Plugin.
                    // Locate the Sensor that is selected in the tree.
                    Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                    Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                    if (objGear != null)
                    {
                        blnFound = true;
                        objGear.Parent.Children.Remove(objGear);
                        treVehicles.SelectedNode.Remove();
                    }
                }

                if (!blnFound)
                {
                    // Locate the selected Cyberware.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                        {
                            foreach (Cyberware objCyberware in objMod.Cyberware)
                            {
                                if (objCyberware.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    // Remove the Cyberweapon created by the Cyberware if applicable.
                                    if (objCyberware.WeaponID != Guid.Empty.ToString())
                                    {
                                        // Remove the Weapon from the TreeView.
                                        TreeNode objRemoveNode = new TreeNode();
                                        foreach (TreeNode objWeaponNode in treVehicles.SelectedNode.Parent.Parent.Nodes)
                                        {
                                            if (objWeaponNode.Tag.ToString() == objCyberware.WeaponID)
                                                objRemoveNode = objWeaponNode;
                                        }
                                        treWeapons.Nodes.Remove(objRemoveNode);

                                        // Remove the Weapon from the Vehicle.
                                        Weapon objRemoveWeapon = new Weapon(_objCharacter);
                                        foreach (Weapon objWeapon in objCharacterVehicle.Weapons)
                                        {
                                            if (objWeapon.InternalId == objCyberware.WeaponID)
                                                objRemoveWeapon = objWeapon;
                                        }
                                        objCharacterVehicle.Weapons.Remove(objRemoveWeapon);
                                    }

                                    objMod.Cyberware.Remove(objCyberware);
                                    treVehicles.SelectedNode.Remove();
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else if (treVehicles.SelectedNode.Level == 4)
            {
                bool blnFound = false;
                // Locate the selected WeaponAccessory or VehicleWeaponMod that is selected in the tree.
                foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                {
                    foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                    {
                        foreach (Weapon objWeapon in objMod.Weapons)
                        {
                            foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                            {
                                if (objAccessory.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    objWeapon.WeaponAccessories.Remove(objAccessory);
                                    treVehicles.SelectedNode.Remove();
                                    blnFound = true;
                                    break;
                                }
                            }
                            if (!blnFound)
                            {
                                foreach (WeaponMod objWeaponMod in objWeapon.WeaponMods)
                                {
                                    if (objWeaponMod.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                    {
                                        objWeapon.WeaponMods.Remove(objWeaponMod);
                                        treVehicles.SelectedNode.Remove();
                                        blnFound = true;
                                        break;
                                    }
                                }
                            }
                            if (!blnFound)
                            {
                                // Remove the Underbarrel Weapon if the selected item it is one.
                                if (objWeapon.UnderbarrelWeapons.Count > 0)
                                {
                                    foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                    {
                                        if (objUnderbarrelWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                        {
                                            objWeapon.UnderbarrelWeapons.Remove(objUnderbarrelWeapon);
                                            treVehicles.SelectedNode.Remove();
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (!blnFound)
                {
                    // Locate the selected Sensor Plugin.
                    // Locate the Sensor that is selected in the tree.
                    Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                    Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                    if (objGear != null)
                    {
                        blnFound = true;
                        objGear.Parent.Children.Remove(objGear);
                        treVehicles.SelectedNode.Remove();

                        _objFunctions.DeleteVehicleGear(objGear, treVehicles, objFoundVehicle);
                    }
                }
            }
            else if (treVehicles.SelectedNode.Level == 5)
            {
                // Locate the selected WeaponAccessory or VehicleWeaponMod that is selected in the tree.
                bool blnFound = false;
                foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                {
                    foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                    {
                        foreach (Weapon objWeapon in objMod.Weapons)
                        {
                            if (objWeapon.UnderbarrelWeapons.Count > 0)
                            {
                                foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                {
                                    foreach (WeaponAccessory objAccessory in objUnderbarrelWeapon.WeaponAccessories)
                                    {
                                        if (objAccessory.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                        {
                                            objUnderbarrelWeapon.WeaponAccessories.Remove(objAccessory);
                                            treVehicles.SelectedNode.Remove();
                                            blnFound = true;
                                            break;
                                        }
                                    }
                                    if (!blnFound)
                                    {
                                        foreach (WeaponMod objWeaponMod in objUnderbarrelWeapon.WeaponMods)
                                        {
                                            if (objWeaponMod.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                            {
                                                objUnderbarrelWeapon.WeaponMods.Remove(objWeaponMod);
                                                treVehicles.SelectedNode.Remove();
                                                blnFound = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (!blnFound)
                {
                    Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                    Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                    if (objGear != null)
                    {
                        blnFound = true;
                        objGear.Parent.Children.Remove(objGear);
                        treVehicles.SelectedNode.Remove();

                        _objFunctions.DeleteVehicleGear(objGear, treVehicles, objFoundVehicle);
                    }
                }
            }
            else if (treVehicles.SelectedNode.Level > 5)
            {
                Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                if (objGear != null)
                {
                    objGear.Parent.Children.Remove(objGear);
                    treVehicles.SelectedNode.Remove();

                    _objFunctions.DeleteVehicleGear(objGear, treVehicles, objFoundVehicle);
                }
            }

            UpdateCharacterInfo();
            RefreshSelectedVehicle();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
示例#32
0
        /// <summary>
        /// Save the character as Created and re-open it in Career Mode.
        /// </summary>
        private void SaveCharacterAsCreated()
        {
            // If the character was built with Karma, record their staring Karma amount (if any).
            //if (_objCharacter.BuildMethod == CharacterBuildMethod.Karma)
            //{
            if (_objCharacter.Karma > 0)
            {
                ExpenseLogEntry objKarma = new ExpenseLogEntry();
                objKarma.Create(_objCharacter.Karma, "Starting Karma", ExpenseType.Karma, DateTime.Now);
                _objCharacter.ExpenseEntries.Add(objKarma);

                // Create an Undo entry so that the starting Karma amount can be modified if needed.
                ExpenseUndo objKarmaUndo = new ExpenseUndo();
                objKarmaUndo.CreateKarma(KarmaExpenseType.ManualAdd, "");
                objKarma.Undo = objKarmaUndo;
            }
            //}

            // If the character has an Essence Penalty, this needs to be added as a positive value to the character's MAG/RES so that it's correctly shown in Career Mode.
            if (_objCharacter.EssencePenalty > 0 && (_objCharacter.MAGEnabled || _objCharacter.RESEnabled))
            {
                if (_objCharacter.MAGEnabled)
                    _objCharacter.MAG.Value += _objCharacter.EssencePenalty;
                if (_objCharacter.RESEnabled)
                    _objCharacter.RES.Value += _objCharacter.EssencePenalty;
            }

            // Create an Expense Entry for Starting Nuyen.
            ExpenseLogEntry objNuyen = new ExpenseLogEntry();
            objNuyen.Create(_objCharacter.Nuyen, "Starting Nuyen", ExpenseType.Nuyen, DateTime.Now);
            _objCharacter.ExpenseEntries.Add(objNuyen);

            // Create an Undo entry so that the Starting Nuyen amount can be modified if needed.
            ExpenseUndo objNuyenUndo = new ExpenseUndo();
            objNuyenUndo.CreateNuyen(NuyenExpenseType.ManualAdd, "");
            objNuyen.Undo = objNuyenUndo;

            _blnSkipToolStripRevert = true;
            _objCharacter.Save();

            GlobalOptions.Instance.MainForm.LoadCharacter(_objCharacter.FileName, false);
            this.Close();
        }
示例#33
0
        private void cmdAddMod_Click(object sender, EventArgs e)
        {
            bool blnAddAgain;

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

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

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

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

            string   strSpaceCharacter = LanguageManager.GetString("String_Space", GlobalOptions.Language);
            TreeNode objModsParentNode = treMods.FindNode("Node_AdditionalMods");

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

                frmPickVehicleMod.ShowDialog(this);

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

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

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

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

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

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

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

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

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

                objModsParentNode.Nodes.Add(objNewNode);
                treMods.SelectedNode = objNewNode;
            }while (blnAddAgain);
        }