private void cmdDeleteMod_Click(object sender, EventArgs e) { TreeNode objSelectedNode = treMods.SelectedNode; string strSelectedId = objSelectedNode?.Tag.ToString(); if (!string.IsNullOrEmpty(strSelectedId) && strSelectedId.IsGuid()) { VehicleMod objMod = _lstMods.FirstOrDefault(x => x.InternalId == strSelectedId); if (objMod != null && !objMod.IncludedInVehicle) { if (!_objCharacter.ConfirmDelete(LanguageManager.GetString("Message_DeleteVehicle", GlobalOptions.Language))) { return; } _lstMods.Remove(objMod); foreach (Weapon objLoopWeapon in objMod.Weapons) { objLoopWeapon.DeleteWeapon(); } foreach (Cyberware objLoopCyberware in objMod.Cyberware) { objLoopCyberware.DeleteCyberware(); } TreeNode objParentNode = objSelectedNode.Parent; objSelectedNode.Remove(); if (objParentNode.Nodes.Count == 0) { objParentNode.Remove(); } } } }
/// <summary> /// Locate a VehicleMod within the character's Vehicles. /// </summary> /// <param name="funcPredicate">Predicate to locate the VehicleMod.</param> /// <param name="lstVehicles">List of Vehicles to search.</param> /// <param name="objFoundVehicle">Vehicle that the VehicleMod was found in.</param> /// <param name="objFoundWeaponMount">Weapon Mount that the VehicleMod was found in.</param> public static VehicleMod FindVehicleMod([NotNull] this IEnumerable <Vehicle> lstVehicles, [NotNull] Func <VehicleMod, bool> funcPredicate, out Vehicle objFoundVehicle, out WeaponMount objFoundWeaponMount) { foreach (Vehicle objVehicle in lstVehicles) { VehicleMod objMod = objVehicle.FindVehicleMod(funcPredicate, out objFoundWeaponMount); if (objMod != null) { objFoundVehicle = objVehicle; return(objMod); } } objFoundVehicle = null; objFoundWeaponMount = null; return(null); }
public void CreateAllVehicleModsTest() { // Create a new Human character. Character objCharacter = new Character(); objCharacter.LoadMetatype(Guid.Parse("e28e7075-f635-4c02-937c-e4fc61c51602")); TreeNode objNode = new TreeNode(); XmlDocument objXmlDocument = XmlManager.Instance.Load("vehicles.xml"); foreach (XmlNode objXmlNode in objXmlDocument.SelectNodes("/chummer/mods/mod")) { VehicleMod objMod = new VehicleMod(objCharacter); objMod.Create(objXmlNode, objNode, 1); } }
/// <summary> /// Возвращает стоимость элемента тюнинга /// </summary> internal static int GetPrice(VehicleMod type) { switch (type) { case VehicleMod.Spoilers: return(800); case VehicleMod.FrontBumper: case VehicleMod.RearBumper: case VehicleMod.SideSkirt: case VehicleMod.Exhaust: case VehicleMod.Frame: case VehicleMod.Grille: return(600); case VehicleMod.Hood: case VehicleMod.Fender: case VehicleMod.Roof: return(700); case VehicleMod.Engine: return(2000); case VehicleMod.Suspension: case VehicleMod.Transmission: return(1300); case VehicleMod.Horns: return(500); case VehicleMod.Armor: return(1500); case VehicleMod.Brakes: case VehicleMod.Xenon: return(1000); case VehicleMod.FrontWheels: case VehicleMod.BackWheels: return(1500); default: return(0); } }
public override bool Run(string[] inputParams) { VehicleMod vehicleMod = VehicleMod.Aerials; if (inputParams.Length > 2) { int.TryParse(inputParams[2], out modIndex); } if (inputParams.Length > 3) { bool.TryParse(inputParams[3], out variations); } if (Enum.TryParse <VehicleMod>(inputParams[1], out vehicleMod)) { Game.Player.LastVehicle.SetMod(vehicleMod, modIndex, variations); return(true); } else { Game.Player.LastVehicle.SetMod((VehicleMod)int.Parse(inputParams[1]), modIndex, variations); return(true); } }
private void tsVehicleAddWeaponWeapon_Click(object sender, EventArgs e) { VehicleMod objMod = new VehicleMod(_objCharacter); // Make sure that a Weapon Mount has been selected. try { // Attempt to locate the selected VehicleMod. Vehicle objFoundVehicle = new Vehicle(_objCharacter); objMod = _objFunctions.FindVehicleMod(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle); if (!objMod.Name.StartsWith("Weapon Mount") && !objMod.Name.StartsWith("Heavy Weapon Mount") && !objMod.Name.StartsWith("Mechanical Arm")) { MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotAddWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotAddWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch { MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotAddWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotAddWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } frmSelectWeapon frmPickWeapon = new frmSelectWeapon(_objCharacter, true); frmPickWeapon.ShowDialog(); 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, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponMod); objWeapon.VehicleMounted = true; 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; if (!frmPickWeapon.FreeCost) { // Check the item's Cost and make sure the character can afford it. if (intCost > _objCharacter.Nuyen) { MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information); if (frmPickWeapon.AddAgain) tsVehicleAddWeaponWeapon_Click(sender, e); return; } else { // Create the Expense Log Entry. ExpenseLogEntry objExpense = new ExpenseLogEntry(); objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseVehicleWeapon") + " " + objWeapon.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now); _objCharacter.ExpenseEntries.Add(objExpense); _objCharacter.Nuyen -= intCost; ExpenseUndo objUndo = new ExpenseUndo(); objUndo.CreateNuyen(NuyenExpenseType.AddVehicleWeapon, objWeapon.InternalId); objExpense.Undo = objUndo; } } objMod.Weapons.Add(objWeapon); objNode.ContextMenuStrip = cmsVehicleWeapon; treVehicles.SelectedNode.Nodes.Add(objNode); treVehicles.SelectedNode.Expand(); if (frmPickWeapon.AddAgain) tsVehicleAddWeaponWeapon_Click(sender, e); UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); }
private void tsVehicleAddMod_Click(object sender, EventArgs e) { // Make sure a parent items is selected, then open the Select Vehicle Mod window. try { if (treVehicles.SelectedNode.Level == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (treVehicles.SelectedNode.Level > 1) treVehicles.SelectedNode = treVehicles.SelectedNode.Parent; Vehicle objSelectedVehicle = _objFunctions.FindVehicle(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles); frmSelectVehicleMod frmPickVehicleMod = new frmSelectVehicleMod(_objCharacter, true); // Set the Vehicle properties for the window. frmPickVehicleMod.VehicleCost = Convert.ToInt32(objSelectedVehicle.Cost); frmPickVehicleMod.Body = objSelectedVehicle.Body; frmPickVehicleMod.Speed = objSelectedVehicle.Speed; frmPickVehicleMod.Accel = objSelectedVehicle.Accel; frmPickVehicleMod.DeviceRating = objSelectedVehicle.DeviceRating; frmPickVehicleMod.HasModularElectronics = objSelectedVehicle.HasModularElectronics(); frmPickVehicleMod.ShowDialog(this); // Make sure the dialogue window was not canceled. if (frmPickVehicleMod.DialogResult == DialogResult.Cancel) return; // Open the Vehicles XML file and locate the selected piece. XmlDocument objXmlDocument = XmlManager.Instance.Load("vehicles.xml"); XmlNode objXmlMod = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + frmPickVehicleMod.SelectedMod + "\"]"); TreeNode objNode = new TreeNode(); VehicleMod objMod = new VehicleMod(_objCharacter); objMod.Create(objXmlMod, objNode, frmPickVehicleMod.SelectedRating); // Make sure that the Armor Rating does not exceed the maximum allowed by the Vehicle. if (objMod.Name.StartsWith("Armor")) { if (objMod.Rating > objSelectedVehicle.MaxArmor) { objMod.Rating = objSelectedVehicle.MaxArmor; objNode.Text = objMod.DisplayName; } } // Check the item's Cost and make sure the character can afford it. int intOriginalCost = objSelectedVehicle.TotalCost; objSelectedVehicle.Mods.Add(objMod); // Do not allow the user to add a new Vehicle Mod if the Vehicle's Capacity has been reached. if (_objOptions.EnforceCapacity && objSelectedVehicle.Slots < objSelectedVehicle.SlotsUsed) { MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information); objSelectedVehicle.Mods.Remove(objMod); if (frmPickVehicleMod.AddAgain) tsVehicleAddMod_Click(sender, e); return; } int intCost = objSelectedVehicle.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) { objSelectedVehicle.Mods.Remove(objMod); MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information); if (frmPickVehicleMod.AddAgain) tsVehicleAddMod_Click(sender, e); return; } else { // Create the Expense Log Entry. ExpenseLogEntry objExpense = new ExpenseLogEntry(); objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseVehicleMod") + " " + objMod.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now); _objCharacter.ExpenseEntries.Add(objExpense); _objCharacter.Nuyen -= intCost; ExpenseUndo objUndo = new ExpenseUndo(); objUndo.CreateNuyen(NuyenExpenseType.AddVehicleMod, objMod.InternalId); objExpense.Undo = objUndo; } } objNode.ContextMenuStrip = cmsVehicle; treVehicles.SelectedNode.Nodes.Add(objNode); treVehicles.SelectedNode.Expand(); RefreshSelectedVehicle(); // Check for Improved Sensor bonus. if (objMod.Bonus != null) { if (objMod.Bonus["selecttext"] != null) { frmSelectText frmPickText = new frmSelectText(); frmPickText.Description = LanguageManager.Instance.GetString("String_Improvement_SelectText").Replace("{0}", objMod.DisplayNameShort); frmPickText.ShowDialog(this); objMod.Extra = frmPickText.SelectedValue; objNode.Text = objMod.DisplayName; } if (objMod.Bonus["improvesensor"] != null) { ChangeVehicleSensor(objSelectedVehicle, true); } } _blnIsDirty = true; UpdateWindowTitle(); if (frmPickVehicleMod.AddAgain) tsVehicleAddMod_Click(sender, e); }
private void TestVehicles() { Character objCharacter = new Character(); XmlDocument objXmlDocument = XmlManager.Load("vehicles.xml"); pgbProgress.Minimum = 0; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlDocument.SelectNodes("/chummer/vehicles/vehicle")?.Count ?? 0; pgbProgress.Maximum += objXmlDocument.SelectNodes("/chummer/mods/mod")?.Count ?? 0; // Vehicles. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/vehicles/vehicle")) { pgbProgress.Value++; Application.DoEvents(); try { Vehicle objTemp = new Vehicle(objCharacter); objTemp.Create(objXmlGear); try { decimal objValue = objTemp.TotalCost; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\r\n"; } try { string objValue = objTemp.TotalAccel; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAccel\r\n"; } try { int objValue = objTemp.TotalArmor; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalArmor\r\n"; } try { int objValue = objTemp.TotalBody; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalBody\r\n"; } try { string objValue = objTemp.TotalHandling; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalHandling\r\n"; } try { string objValue = objTemp.TotalSpeed; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalSpeed\r\n"; } try { string objValue = objTemp.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.Language); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedAvail\r\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\r\n"; } } // Vehicle Mods. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/mods/mod")) { pgbProgress.Value++; Application.DoEvents(); try { VehicleMod objTemp = new VehicleMod(objCharacter); objTemp.Create(objXmlGear, 1, null); try { decimal objValue = objTemp.TotalCost; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\r\n"; } try { string objValue = objTemp.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.DefaultLanguage); } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\r\n"; } try { int objValue = objTemp.CalculatedSlots; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedSlots\r\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\r\n"; } } objCharacter.DeleteCharacter(); }
public static void RefreshChildrenCyberware(this IHasInternalId objParent, TreeView treCyberware, ContextMenuStrip cmsCyberware, ContextMenuStrip cmsCyberwareGear, Func <int> funcOffset, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs) { if (notifyCollectionChangedEventArgs == null || objParent == null || treCyberware == null) { return; } TreeNode nodParent = treCyberware.FindNodeByTag(objParent); if (nodParent == null) { return; } switch (notifyCollectionChangedEventArgs.Action) { case NotifyCollectionChangedAction.Add: { int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (Cyberware objCyberware in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objCyberware, intNewIndex); objCyberware.SetupChildrenCyberwareCollectionChanged(true, treCyberware, cmsCyberware, cmsCyberwareGear); ++intNewIndex; } } break; case NotifyCollectionChangedAction.Remove: { foreach (Cyberware objCyberware in notifyCollectionChangedEventArgs.OldItems) { objCyberware.SetupChildrenCyberwareCollectionChanged(false, treCyberware); nodParent.FindNodeByTag(objCyberware)?.Remove(); } } break; case NotifyCollectionChangedAction.Replace: { string strSelectedId = (treCyberware.SelectedNode?.Tag as IHasInternalId)?.InternalId ?? string.Empty; foreach (Cyberware objCyberware in notifyCollectionChangedEventArgs.OldItems) { objCyberware.SetupChildrenCyberwareCollectionChanged(false, treCyberware); nodParent.FindNodeByTag(objCyberware)?.Remove(); } int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (Cyberware objCyberware in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objCyberware, intNewIndex); objCyberware.SetupChildrenCyberwareCollectionChanged(true, treCyberware, cmsCyberware, cmsCyberwareGear); ++intNewIndex; } treCyberware.SelectedNode = treCyberware.FindNode(strSelectedId); } break; case NotifyCollectionChangedAction.Move: { string strSelectedId = (treCyberware.SelectedNode?.Tag as IHasInternalId)?.InternalId ?? string.Empty; foreach (Cyberware objCyberware in notifyCollectionChangedEventArgs.OldItems) { nodParent.FindNodeByTag(objCyberware)?.Remove(); } int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (Cyberware objCyberware in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objCyberware, intNewIndex); ++intNewIndex; } treCyberware.SelectedNode = treCyberware.FindNode(strSelectedId); } break; case NotifyCollectionChangedAction.Reset: { VehicleMod objParentAsVehicleMod = objParent as VehicleMod; for (int i = nodParent.Nodes.Count - 1; i >= 0; --i) { TreeNode objNode = nodParent.Nodes[i]; if (objNode.Tag is Cyberware objNodeCyberware && !ReferenceEquals(objNodeCyberware.Parent, objParent) && !ReferenceEquals(objNodeCyberware.ParentVehicle, objParent) && objParentAsVehicleMod?.Cyberware.Contains(objNodeCyberware) != true) { objNode.Remove(); } } } break; } void AddToTree(Cyberware objCyberware, int intIndex = -1, bool blnSingleAdd = true) { TreeNode objNode = objCyberware.CreateTreeNode(cmsCyberware, cmsCyberwareGear); if (objNode == null) { return; } if (intIndex >= 0) { nodParent.Nodes.Insert(intIndex, objNode); } else { nodParent.Nodes.Add(objNode); } nodParent.Expand(); if (blnSingleAdd) { treCyberware.SelectedNode = objNode; } } }
private void tsVehicleAddMod_Click(object sender, EventArgs e) { // Make sure a parent items is selected, then open the Select Vehicle Mod window. try { if (treVehicles.SelectedNode.Level == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (treVehicles.SelectedNode.Level > 1) treVehicles.SelectedNode = treVehicles.SelectedNode.Parent; Vehicle objSelectedVehicle = _objFunctions.FindVehicle(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles); frmSelectVehicleMod frmPickVehicleMod = new frmSelectVehicleMod(_objCharacter); // Set the Vehicle properties for the window. frmPickVehicleMod.VehicleCost = Convert.ToInt32(objSelectedVehicle.Cost); frmPickVehicleMod.Body = objSelectedVehicle.TotalBody; frmPickVehicleMod.Seats = objSelectedVehicle.Seats; frmPickVehicleMod.Handling = objSelectedVehicle.Handling; frmPickVehicleMod.Speed = objSelectedVehicle.Speed; frmPickVehicleMod.Accel = objSelectedVehicle.Accel; frmPickVehicleMod.DeviceRating = objSelectedVehicle.DeviceRating; frmPickVehicleMod.HasModularElectronics = objSelectedVehicle.HasModularElectronics(); frmPickVehicleMod.ShowDialog(this); // Make sure the dialogue window was not canceled. if (frmPickVehicleMod.DialogResult == DialogResult.Cancel) return; // Open the Vehicles XML file and locate the selected piece. XmlDocument objXmlDocument = XmlManager.Instance.Load("vehicles.xml"); XmlNode objXmlMod = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + frmPickVehicleMod.SelectedMod + "\"]"); TreeNode objNode = new TreeNode(); VehicleMod objMod = new VehicleMod(_objCharacter); objMod.Create(objXmlMod, objNode, frmPickVehicleMod.SelectedRating); // Make sure that the Armor Rating does not exceed the maximum allowed by the Vehicle. if (objMod.Name.StartsWith("Armor")) { if (objMod.Rating > objSelectedVehicle.MaxArmor) { objMod.Rating = objSelectedVehicle.MaxArmor; objNode.Text = objMod.DisplayName; } } objSelectedVehicle.Mods.Add(objMod); objNode.ContextMenuStrip = cmsVehicle; treVehicles.SelectedNode.Nodes.Add(objNode); treVehicles.SelectedNode.Expand(); RefreshSelectedVehicle(); // Check for Improved Sensor bonus. if (objMod.Bonus != null) { if (objMod.Bonus["selecttext"] != null) { frmSelectText frmPickText = new frmSelectText(); frmPickText.Description = LanguageManager.Instance.GetString("String_Improvement_SelectText").Replace("{0}", objMod.DisplayNameShort); frmPickText.ShowDialog(this); objMod.Extra = frmPickText.SelectedValue; objNode.Text = objMod.DisplayName; } if (objMod.Bonus["improvesensor"] != null) { ChangeVehicleSensor(objSelectedVehicle, true); } } _blnIsDirty = true; UpdateWindowTitle(); if (frmPickVehicleMod.AddAgain) tsVehicleAddMod_Click(sender, e); }
private void mnuEditPaste_Click(object sender, EventArgs e) { if (tabCharacterTabs.SelectedTab == tabStreetGear) { // Lifestyle Tab. if (tabStreetGearTabs.SelectedTab == tabLifestyle) { // Paste Lifestyle. Lifestyle objLifestyle = new Lifestyle(_objCharacter); XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/lifestyle"); if (objXmlNode != null) { objLifestyle.Load(objXmlNode, true); // Reset the number of months back to 1 since 0 isn't valid in Create Mode. objLifestyle.Months = 1; _objCharacter.Lifestyles.Add(objLifestyle); TreeNode objLifestyleNode = new TreeNode(); objLifestyleNode.Text = objLifestyle.DisplayName; objLifestyleNode.Tag = objLifestyle.InternalId; if (objLifestyle.StyleType.ToString() != "Standard") objLifestyleNode.ContextMenuStrip = cmsAdvancedLifestyle; else objLifestyleNode.ContextMenuStrip = cmsLifestyleNotes; if (objLifestyle.Notes != string.Empty) objLifestyleNode.ForeColor = Color.SaddleBrown; objLifestyleNode.ToolTipText = CommonFunctions.WordWrap(objLifestyle.Notes, 100); treLifestyles.Nodes[0].Nodes.Add(objLifestyleNode); UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); return; } } // Armor Tab. if (tabStreetGearTabs.SelectedTab == tabArmor) { // Paste Armor. Armor objArmor = new Armor(_objCharacter); XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/armor"); if (objXmlNode != null) { objArmor.Load(objXmlNode, true); _objCharacter.Armor.Add(objArmor); _objFunctions.CreateArmorTreeNode(objArmor, treArmor, cmsArmor, cmsArmorMod, cmsArmorGear); UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); return; } // Paste Gear. Gear objGear = new Gear(_objCharacter); objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/gear"); if (objXmlNode != null) { switch (objXmlNode["category"].InnerText) { case "Commlinks": case "Cyberdecks": case "Rigger Command Consoles": Commlink objCommlink = new Commlink(_objCharacter); objCommlink.Load(objXmlNode, true); objGear = objCommlink; break; default: Gear objNewGear = new Gear(_objCharacter); objNewGear.Load(objXmlNode, true); objGear = objNewGear; break; } foreach (Armor objCharacterArmor in _objCharacter.Armor) { if (objCharacterArmor.InternalId == treArmor.SelectedNode.Tag.ToString()) { objCharacterArmor.Gear.Add(objGear); TreeNode objNode = new TreeNode(); objNode.Text = objGear.DisplayName; objNode.Tag = objGear.InternalId; objNode.ContextMenuStrip = cmsArmorGear; _objFunctions.BuildGearTree(objGear, objNode, cmsArmorGear); treArmor.SelectedNode.Nodes.Add(objNode); treArmor.SelectedNode.Expand(); } } // Add any Weapons that come with the Gear. objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/weapon"); if (objXmlNode != null) { Weapon objWeapon = new Weapon(_objCharacter); objWeapon.Load(objXmlNode, true); _objCharacter.Weapons.Add(objWeapon); objGear.WeaponID = objWeapon.InternalId; _objFunctions.CreateWeaponTreeNode(objWeapon, treWeapons.Nodes[0], cmsWeapon, cmsWeaponMod, cmsWeaponAccessory, cmsWeaponAccessoryGear); } UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); return; } } // Weapons Tab. if (tabStreetGearTabs.SelectedTab == tabWeapons) { // Paste Gear into a Weapon Accessory. Gear objGear = new Gear(_objCharacter); XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/gear"); if (objXmlNode != null) { switch (objXmlNode["category"].InnerText) { case "Commlinks": case "Cyberdecks": case "Rigger Command Consoles": Commlink objCommlink = new Commlink(_objCharacter); objCommlink.Load(objXmlNode, true); objGear = objCommlink; break; default: Gear objNewGear = new Gear(_objCharacter); objNewGear.Load(objXmlNode, true); objGear = objNewGear; break; } objGear.Parent = null; // Make sure that a Weapon Accessory is selected and that it allows Gear of the item's Category. WeaponAccessory objAccessory = _objFunctions.FindWeaponAccessory(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons); bool blnAllowPaste = false; if (objAccessory.AllowGear != null) { foreach (XmlNode objAllowed in objAccessory.AllowGear.SelectNodes("gearcategory")) { if (objAllowed.InnerText == objGear.Category) { blnAllowPaste = true; break; } } } if (blnAllowPaste) { objAccessory.Gear.Add(objGear); TreeNode objNode = new TreeNode(); objNode.Text = objGear.DisplayName; objNode.Tag = objGear.InternalId; objNode.ContextMenuStrip = cmsWeaponAccessoryGear; _objFunctions.BuildGearTree(objGear, objNode, cmsWeaponAccessoryGear); treWeapons.SelectedNode.Nodes.Add(objNode); treWeapons.SelectedNode.Expand(); // Add any Weapons that come with the Gear. objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/weapon"); if (objXmlNode != null) { Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Load(objXmlNode, true); _objCharacter.Weapons.Add(objGearWeapon); objGear.WeaponID = objGearWeapon.InternalId; _objFunctions.CreateWeaponTreeNode(objGearWeapon, treWeapons.Nodes[0], cmsWeapon, cmsWeaponMod, cmsWeaponAccessory, cmsWeaponAccessoryGear); } UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); return; } } // Paste Weapon. Weapon objWeapon = new Weapon(_objCharacter); objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/weapon"); if (objXmlNode != null) { objWeapon.Load(objXmlNode, true); objWeapon.VehicleMounted = false; _objCharacter.Weapons.Add(objWeapon); _objFunctions.CreateWeaponTreeNode(objWeapon, treWeapons.Nodes[0], cmsWeapon, cmsWeaponMod, cmsWeaponAccessory, cmsWeaponAccessoryGear); UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); return; } } // Gear Tab. if (tabStreetGearTabs.SelectedTab == tabGear) { // Paste Gear. Gear objGear = new Gear(_objCharacter); XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/gear"); if (objXmlNode != null) { switch (objXmlNode["category"].InnerText) { case "Commlinks": case "Cyberdecks": case "Rigger Command Consoles": Commlink objCommlink = new Commlink(_objCharacter); objCommlink.Load(objXmlNode, true); _objCharacter.Gear.Add(objCommlink); objGear = objCommlink; break; default: Gear objNewGear = new Gear(_objCharacter); objNewGear.Load(objXmlNode, true); _objCharacter.Gear.Add(objNewGear); objGear = objNewGear; break; } objGear.Parent = null; TreeNode objNode = new TreeNode(); objNode.Text = objGear.DisplayName; objNode.Tag = objGear.InternalId; if (objGear.Notes != string.Empty) objNode.ForeColor = Color.SaddleBrown; objNode.ToolTipText = CommonFunctions.WordWrap(objGear.Notes, 100); _objFunctions.BuildGearTree(objGear, objNode, cmsGear); objNode.ContextMenuStrip = cmsGear; TreeNode objParent = new TreeNode(); if (objGear.Location == "") objParent = treGear.Nodes[0]; else { foreach (TreeNode objFind in treGear.Nodes) { if (objFind.Text == objGear.Location) { objParent = objFind; break; } } } objParent.Nodes.Add(objNode); objParent.Expand(); // Add any Weapons that come with the Gear. objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/weapon"); if (objXmlNode != null) { Weapon objWeapon = new Weapon(_objCharacter); objWeapon.Load(objXmlNode, true); _objCharacter.Weapons.Add(objWeapon); objGear.WeaponID = objWeapon.InternalId; _objFunctions.CreateWeaponTreeNode(objWeapon, treWeapons.Nodes[0], cmsWeapon, cmsWeaponMod, cmsWeaponAccessory, cmsWeaponAccessoryGear); } UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); return; } } } // Vehicles Tab. if (tabCharacterTabs.SelectedTab == tabVehicles) { // Paste Vehicle. Vehicle objVehicle = new Vehicle(_objCharacter); XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/vehicle"); if (objXmlNode != null) { objVehicle.Load(objXmlNode, true); _objCharacter.Vehicles.Add(objVehicle); _objFunctions.CreateVehicleTreeNode(objVehicle, treVehicles, cmsVehicle, cmsVehicleLocation, cmsVehicleWeapon, cmsVehicleWeaponMod, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear, cmsVehicleGear); UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); return; } // Paste Gear. Gear objGear = new Gear(_objCharacter); objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/gear"); if (objXmlNode != null) { switch (objXmlNode["category"].InnerText) { case "Commlinks": case "Cyberdecks": case "Rigger Command Consoles": Commlink objCommlink = new Commlink(_objCharacter); objCommlink.Load(objXmlNode, true); objGear = objCommlink; break; default: Gear objNewGear = new Gear(_objCharacter); objNewGear.Load(objXmlNode, true); objGear = objNewGear; break; } // Paste the Gear into a Vehicle. foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles) { if (objCharacterVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString()) { objCharacterVehicle.Gear.Add(objGear); TreeNode objNode = new TreeNode(); objNode.Text = objGear.DisplayName; objNode.Tag = objGear.InternalId; objNode.ContextMenuStrip = cmsVehicleGear; objVehicle = objCharacterVehicle; _objFunctions.BuildGearTree(objGear, objNode, cmsVehicleGear); treVehicles.SelectedNode.Nodes.Add(objNode); treVehicles.SelectedNode.Expand(); } } // Paste the Gear into a Vehicle's Gear. Vehicle objTempVehicle = objVehicle; Gear objVehicleGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objVehicle); if (objVehicle == null) objVehicle = objTempVehicle; if (objVehicleGear != null) { objVehicleGear.Children.Add(objGear); objGear.Parent = objVehicleGear; TreeNode objNode = new TreeNode(); objNode.Text = objGear.DisplayName; objNode.Tag = objGear.InternalId; objNode.ContextMenuStrip = cmsVehicleGear; _objFunctions.BuildGearTree(objGear, objNode, cmsVehicleGear); treVehicles.SelectedNode.Nodes.Add(objNode); treVehicles.SelectedNode.Expand(); } UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); return; } // Paste Weapon. Weapon objWeapon = new Weapon(_objCharacter); objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/weapon"); if (objXmlNode != null) { objWeapon.Load(objXmlNode, true); objWeapon.VehicleMounted = true; try { // Weapons can only be added to Vehicle Mods that support them (Weapon Mounts and Mechanical Arms). VehicleMod objMod = new VehicleMod(_objCharacter); foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles) { foreach (VehicleMod objVehicleMod in objCharacterVehicle.Mods) { if (objVehicleMod.InternalId == treVehicles.SelectedNode.Tag.ToString()) { if (objVehicleMod.Name.StartsWith("Weapon Mount") || objVehicleMod.Name.StartsWith("Heavy Weapon Mount") || objVehicleMod.Name.StartsWith("Mechanical Arm")) { objVehicleMod.Weapons.Add(objWeapon); _objFunctions.CreateWeaponTreeNode(objWeapon, treVehicles.SelectedNode, cmsVehicleWeapon, cmsVehicleWeaponMod, cmsVehicleWeaponAccessory, null); UpdateCharacterInfo(); _blnIsDirty = true; UpdateWindowTitle(); return; } } } } } catch { } } } }
/// <summary> /// Add a PACKS Kit to the character. /// </summary> public void AddPACKSKit() { frmSelectPACKSKit frmPickPACKSKit = new frmSelectPACKSKit(_objCharacter); frmPickPACKSKit.ShowDialog(this); bool blnCreateChildren = true; // If the form was canceled, don't do anything. if (frmPickPACKSKit.DialogResult == DialogResult.Cancel) return; XmlDocument objXmlDocument = XmlManager.Instance.Load("packs.xml"); // Do not create child items for Gear if the chosen Kit is in the Custom category since these items will contain the exact plugins desired. if (frmPickPACKSKit.SelectedCategory == "Custom") blnCreateChildren = false; XmlNode objXmlKit = objXmlDocument.SelectSingleNode("/chummer/packs/pack[name = \"" + frmPickPACKSKit.SelectedKit + "\" and category = \"" + frmPickPACKSKit.SelectedCategory + "\"]"); // Update Qualities. if (objXmlKit["qualities"] != null) { XmlDocument objXmlQualityDocument = XmlManager.Instance.Load("qualities.xml"); // Positive Qualities. foreach (XmlNode objXmlQuality in objXmlKit.SelectNodes("qualities/positive/quality")) { XmlNode objXmlQualityNode = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQuality.InnerText + "\"]"); TreeNode objNode = new TreeNode(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); Quality objQuality = new Quality(_objCharacter); string strForceValue = ""; if (objXmlQuality.Attributes["select"] != null) strForceValue = objXmlQuality.Attributes["select"].InnerText; objQuality.Create(objXmlQualityNode, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes, strForceValue); _objCharacter.Qualities.Add(objQuality); treQualities.Nodes[0].Nodes.Add(objNode); treQualities.Nodes[0].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(); } } // Negative Qualities. foreach (XmlNode objXmlQuality in objXmlKit.SelectNodes("qualities/negative/quality")) { XmlNode objXmlQualityNode = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQuality.InnerText + "\"]"); TreeNode objNode = new TreeNode(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); Quality objQuality = new Quality(_objCharacter); string strForceValue = ""; if (objXmlQuality.Attributes["select"] != null) strForceValue = objXmlQuality.Attributes["select"].InnerText; objQuality.Create(objXmlQualityNode, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes, strForceValue); _objCharacter.Qualities.Add(objQuality); 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(); } } } // Update Attributes. if (objXmlKit["attributes"] != null) { // Reset all Attributes back to 1 so we don't go over any BP limits. nudBOD.Value = nudBOD.Minimum; nudAGI.Value = nudAGI.Minimum; nudREA.Value = nudREA.Minimum; nudSTR.Value = nudSTR.Minimum; nudCHA.Value = nudCHA.Minimum; nudINT.Value = nudINT.Minimum; nudLOG.Value = nudLOG.Minimum; nudWIL.Value = nudWIL.Minimum; nudEDG.Value = nudEDG.Minimum; nudMAG.Value = nudMAG.Minimum; nudRES.Value = nudRES.Minimum; foreach (XmlNode objXmlAttribute in objXmlKit["attributes"]) { // The Attribute is calculated as given value - (6 - Metatype Maximum) so that each Metatype has the values from the file adjusted correctly. switch (objXmlAttribute.Name) { case "bod": nudBOD.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.BOD.MetatypeMaximum); break; case "agi": nudAGI.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.AGI.MetatypeMaximum); break; case "rea": nudREA.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.REA.MetatypeMaximum); break; case "str": nudSTR.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.STR.MetatypeMaximum); break; case "cha": nudCHA.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.CHA.MetatypeMaximum); break; case "int": nudINT.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.INT.MetatypeMaximum); break; case "log": nudLOG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.LOG.MetatypeMaximum); break; case "wil": nudWIL.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.WIL.MetatypeMaximum); break; case "mag": nudMAG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.MAG.MetatypeMaximum); break; case "res": nudRES.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.RES.MetatypeMaximum); break; default: nudEDG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.EDG.MetatypeMaximum); break; } } } // Update Skills. if (objXmlKit["skills"] != null) { // Active Skills. foreach (XmlNode objXmlSkill in objXmlKit.SelectNodes("skills/skill")) { if (objXmlSkill["name"].InnerText.Contains("Exotic")) { int i = panActiveSkills.Controls.Count; Skill objSkill = new Skill(_objCharacter); SkillControl objSkillControl = new SkillControl(_objCharacter); objSkillControl.SkillObject = objSkill; objSkillControl.Width = 510; // Attach an EventHandler for the RatingChanged and SpecializationChanged Events. objSkillControl.RatingChanged += objActiveSkill_RatingChanged; objSkillControl.SpecializationChanged += objSkill_SpecializationChanged; objSkillControl.SkillName = objXmlSkill["name"].InnerText; switch (objXmlSkill["name"].InnerText) { case "Exotic Ranged Weapon": case "Exotic Melee Weapon": objSkill.Attribute = "AGI"; objSkillControl.SkillCategory = "Combat Active"; objSkill.Default = true; break; default: objSkill.Attribute = "REA"; objSkillControl.SkillCategory = "Vehicle Active"; objSkill.Default = false; break; } objSkill.ExoticSkill = true; _objCharacter.Skills.Add(objSkill); if (_objCharacter.IgnoreRules) { objSkillControl.SkillRatingMaximum = 12; } else { objSkillControl.SkillRatingMaximum = 6; } // Make sure it's not going above the maximum number. if (Convert.ToInt32(objXmlSkill["rating"].InnerText) > objSkillControl.SkillRatingMaximum) objSkillControl.SkillRating = objSkillControl.SkillRatingMaximum; else objSkillControl.SkillRating = Convert.ToInt32(objXmlSkill["rating"].InnerText); if (objXmlSkill["spec"] != null) objSkillControl.SkillSpec = objXmlSkill["spec"].InnerText; else objSkillControl.SkillSpec = ""; // Set the SkillControl's Location since scrolling the Panel causes it to actually change the child Controls' Locations. objSkillControl.Location = new Point(0, objSkillControl.Height * i + panActiveSkills.AutoScrollPosition.Y); panActiveSkills.Controls.Add(objSkillControl); } else { // Find the correct Skill Control. SkillControl objSkillControl = new SkillControl(_objCharacter); foreach (SkillControl objControl in panActiveSkills.Controls) { if (objControl.SkillName == objXmlSkill["name"].InnerText) { objSkillControl = objControl; break; } } // Make sure it's not going above the maximum number. if (Convert.ToInt32(objXmlSkill["rating"].InnerText) > objSkillControl.SkillRatingMaximum) objSkillControl.SkillRating = objSkillControl.SkillRatingMaximum; else objSkillControl.SkillRating = Convert.ToInt32(objXmlSkill["rating"].InnerText); if (objXmlSkill["spec"] != null) objSkillControl.SkillSpec = objXmlSkill["spec"].InnerText; else objSkillControl.SkillSpec = ""; } } // Skill Groups. foreach (XmlNode objXmlGroup in objXmlKit.SelectNodes("skills/skillgroup")) { // Find the correct SkillGroupControl. SkillGroupControl objSkillGroupControl = new SkillGroupControl(_objCharacter.Options, _objCharacter); foreach (SkillGroupControl objControl in panSkillGroups.Controls) { if (objControl.GroupName == objXmlGroup["name"].InnerText) { objSkillGroupControl = objControl; break; } } // Make sure it's not going above the maximum number. if (Convert.ToInt32(objXmlGroup["base"].InnerText) > objSkillGroupControl.GroupRatingMaximum) { objSkillGroupControl.BaseRating = objSkillGroupControl.GroupRatingMaximum; objSkillGroupControl.KarmaRating = 0; } else if (Convert.ToInt32(objXmlGroup["base"].InnerText) + Convert.ToInt32(objXmlGroup["karma"].InnerText) > objSkillGroupControl.GroupRatingMaximum) { objSkillGroupControl.BaseRating = Convert.ToInt32(objXmlGroup["base"].InnerText); objSkillGroupControl.KarmaRating = objSkillGroupControl.GroupRatingMaximum - objSkillGroupControl.BaseRating; } else { objSkillGroupControl.BaseRating = Convert.ToInt32(objXmlGroup["base"].InnerText); objSkillGroupControl.KarmaRating = Convert.ToInt32(objXmlGroup["karma"].InnerText); } } } // Update Knowledge Skills. if (objXmlKit["knowledgeskills"] != null) { foreach (XmlNode objXmlSkill in objXmlKit.SelectNodes("knowledgeskills/skill")) { int i = panKnowledgeSkills.Controls.Count; Skill objSkill = new Skill(_objCharacter); objSkill.Name = objXmlSkill["name"].InnerText; SkillControl objSkillControl = new SkillControl(_objCharacter); objSkillControl.SkillObject = objSkill; // Attach an EventHandler for the RatingChanged and SpecializationChanged Events. objSkillControl.RatingChanged += objKnowledgeSkill_RatingChanged; objSkillControl.SpecializationChanged += objSkill_SpecializationChanged; objSkillControl.DeleteSkill += objKnowledgeSkill_DeleteSkill; objSkillControl.KnowledgeSkill = true; objSkillControl.AllowDelete = true; if (_objCharacter.IgnoreRules) { objSkillControl.SkillRatingMaximum = 12; } else { objSkillControl.SkillRatingMaximum = 6; } // Set the SkillControl's Location since scrolling the Panel causes it to actually change the child Controls' Locations. objSkillControl.Location = new Point(0, objSkillControl.Height * i + panKnowledgeSkills.AutoScrollPosition.Y); panKnowledgeSkills.Controls.Add(objSkillControl); objSkillControl.SkillName = objXmlSkill["name"].InnerText; // Make sure it's not going above the maximum number. if (Convert.ToInt32(objXmlSkill["rating"].InnerText) > objSkillControl.SkillRatingMaximum) objSkillControl.SkillRating = objSkillControl.SkillRatingMaximum; else objSkillControl.SkillRating = Convert.ToInt32(objXmlSkill["rating"].InnerText); if (objXmlSkill["spec"] != null) objSkillControl.SkillSpec = objXmlSkill["spec"].InnerText; else objSkillControl.SkillSpec = ""; if (objXmlSkill["category"] != null) objSkillControl.SkillCategory = objXmlSkill["category"].InnerText; _objCharacter.Skills.Add(objSkill); } } // Select a Martial Art. if (objXmlKit["selectmartialart"] != null) { string strForcedValue = ""; int intRating = 1; if (objXmlKit["selectmartialart"].Attributes["select"] != null) strForcedValue = objXmlKit["selectmartialart"].Attributes["select"].InnerText; if (objXmlKit["selectmartialart"].Attributes["rating"] != null) intRating = Convert.ToInt32(objXmlKit["selectmartialart"].Attributes["rating"].InnerText); frmSelectMartialArt frmPickMartialArt = new frmSelectMartialArt(_objCharacter); frmPickMartialArt.ForcedValue = strForcedValue; frmPickMartialArt.ShowDialog(this); if (frmPickMartialArt.DialogResult != DialogResult.Cancel) { // Open the Martial Arts XML file and locate the selected piece. XmlDocument objXmlMartialArtDocument = XmlManager.Instance.Load("martialarts.xml"); XmlNode objXmlArt = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + frmPickMartialArt.SelectedMartialArt + "\"]"); TreeNode objNode = new TreeNode(); MartialArt objMartialArt = new MartialArt(_objCharacter); objMartialArt.Create(objXmlArt, objNode, _objCharacter); objMartialArt.Rating = intRating; _objCharacter.MartialArts.Add(objMartialArt); objNode.ContextMenuStrip = cmsMartialArts; treMartialArts.Nodes[0].Nodes.Add(objNode); treMartialArts.Nodes[0].Expand(); treMartialArts.SelectedNode = objNode; } } // Update Martial Arts. if (objXmlKit["martialarts"] != null) { // Open the Martial Arts XML file and locate the selected art. XmlDocument objXmlMartialArtDocument = XmlManager.Instance.Load("martialarts.xml"); foreach (XmlNode objXmlArt in objXmlKit.SelectNodes("martialarts/martialart")) { TreeNode objNode = new TreeNode(); MartialArt objArt = new MartialArt(_objCharacter); XmlNode objXmlArtNode = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + objXmlArt["name"].InnerText + "\"]"); objArt.Create(objXmlArtNode, objNode, _objCharacter); objArt.Rating = Convert.ToInt32(objXmlArt["rating"].InnerText); _objCharacter.MartialArts.Add(objArt); // Check for Advantages. foreach (XmlNode objXmlAdvantage in objXmlArt.SelectNodes("techniques/technique")) { TreeNode objChildNode = new TreeNode(); MartialArtAdvantage objAdvantage = new MartialArtAdvantage(_objCharacter); XmlNode objXmlAdvantageNode = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + objXmlArt["name"].InnerText + "\"]/techniques/technique[. = \"" + objXmlAdvantage.InnerText + "\"]"); objAdvantage.Create(objXmlAdvantageNode, _objCharacter, objChildNode); objArt.Advantages.Add(objAdvantage); objNode.Nodes.Add(objChildNode); objNode.Expand(); } treMartialArts.Nodes[0].Nodes.Add(objNode); treMartialArts.Nodes[0].Expand(); } } // Update Adept Powers. if (objXmlKit["powers"] != null) { // Open the Powers XML file and locate the selected power. XmlDocument objXmlPowerDocument = XmlManager.Instance.Load("powers.xml"); foreach (XmlNode objXmlPower in objXmlKit.SelectNodes("powers/power")) { XmlNode objXmlPowerNode = objXmlPowerDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower["name"].InnerText + "\"]"); int i = panPowers.Controls.Count; Power objPower = new Power(_objCharacter); _objCharacter.Powers.Add(objPower); PowerControl objPowerControl = new PowerControl(); objPowerControl.PowerObject = objPower; // Attach an EventHandler for the PowerRatingChanged Event. objPowerControl.PowerRatingChanged += objPower_PowerRatingChanged; objPowerControl.DeletePower += objPower_DeletePower; objPowerControl.PowerName = objXmlPowerNode["name"].InnerText; objPowerControl.PointsPerLevel = Convert.ToDecimal(objXmlPowerNode["points"].InnerText, GlobalOptions.Instance.CultureInfo); objPowerControl.AdeptWayDiscount = Convert.ToDecimal(objXmlPowerNode["adeptway"].InnerText, GlobalOptions.Instance.CultureInfo); if (objXmlPowerNode["levels"].InnerText == "no") { objPowerControl.LevelEnabled = false; } else { objPowerControl.LevelEnabled = true; if (objXmlPowerNode["levels"].InnerText != "yes") objPower.MaxLevels = Convert.ToInt32(objXmlPowerNode["levels"].InnerText); } objPower.Source = objXmlPowerNode["source"].InnerText; objPower.Page = objXmlPowerNode["page"].InnerText; if (objXmlPowerNode["doublecost"] != null) objPower.DoubleCost = false; if (objXmlPowerNode.InnerXml.Contains("bonus")) { objPower.Bonus = objXmlPowerNode["bonus"]; if (objXmlPower["name"].Attributes["select"] != null) _objImprovementManager.ForcedValue = objXmlPower["name"].Attributes["select"].InnerText; _objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Power, objPower.InternalId, objPower.Bonus, false, Convert.ToInt32(objPower.Rating), objPower.DisplayNameShort); objPowerControl.Extra = _objImprovementManager.SelectedValue; } objPowerControl.Top = i * objPowerControl.Height; panPowers.Controls.Add(objPowerControl); // Set the Rating of the Power if applicable. if (objXmlPower["rating"] != null) objPowerControl.PowerLevel = Convert.ToInt32(objXmlPower["rating"].InnerText); } } // Update Complex Forms. if (objXmlKit["programs"] != null) { // Open the Programs XML file and locate the selected program. XmlDocument objXmlProgramDocument = XmlManager.Instance.Load("complexforms.xml"); foreach (XmlNode objXmlProgram in objXmlKit.SelectNodes("complexforms/complexform")) { XmlNode objXmlProgramNode = objXmlProgramDocument.SelectSingleNode("/chummer/complexforms/complexform[name = \"" + objXmlProgram["name"].InnerText + "\"]"); string strForceValue = ""; if (objXmlProgram.Attributes["select"] != null) strForceValue = objXmlProgram.Attributes["select"].InnerText; TreeNode objNode = new TreeNode(); ComplexForm objProgram = new ComplexForm(_objCharacter); objProgram.Create(objXmlProgramNode, _objCharacter, objNode, strForceValue); treComplexForms.Nodes[0].Nodes.Add(objNode); treComplexForms.Nodes[0].Expand(); _objCharacter.ComplexForms.Add(objProgram); treComplexForms.SortCustom(); } } // Update Spells. if (objXmlKit["spells"] != null) { XmlDocument objXmlSpellDocument = XmlManager.Instance.Load("spells.xml"); foreach (XmlNode objXmlSpell in objXmlKit.SelectNodes("spells/spell")) { // Make sure the Spell has not already been added to the character. bool blnFound = false; foreach (TreeNode nodSpell in treSpells.Nodes[0].Nodes) { if (nodSpell.Text == objXmlSpell.InnerText) { blnFound = true; break; } } // The Spell is not in the list, so add it. if (!blnFound) { string strForceValue = ""; if (objXmlSpell.Attributes["select"] != null) strForceValue = objXmlSpell.Attributes["select"].InnerText; XmlNode objXmlSpellNode = objXmlSpellDocument.SelectSingleNode("/chummer/spells/spell[name = \"" + objXmlSpell.InnerText + "\"]"); Spell objSpell = new Spell(_objCharacter); TreeNode objNode = new TreeNode(); objSpell.Create(objXmlSpellNode, _objCharacter, objNode, strForceValue); objNode.ContextMenuStrip = cmsSpell; _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; } treSpells.SortCustom(); } } } // Update Spirits. if (objXmlKit["spirits"] != null) { foreach (XmlNode objXmlSpirit in objXmlKit.SelectNodes("spirits/spirit")) { int i = panSpirits.Controls.Count; Spirit objSpirit = new Spirit(_objCharacter); _objCharacter.Spirits.Add(objSpirit); SpiritControl objSpiritControl = new SpiritControl(); objSpiritControl.SpiritObject = objSpirit; objSpiritControl.EntityType = SpiritType.Spirit; // Attach an EventHandler for the ServicesOwedChanged Event. objSpiritControl.ServicesOwedChanged += objSpirit_ServicesOwedChanged; objSpiritControl.ForceChanged += objSpirit_ForceChanged; objSpiritControl.BoundChanged += objSpirit_BoundChanged; objSpiritControl.DeleteSpirit += objSpirit_DeleteSpirit; objSpiritControl.Name = objXmlSpirit["name"].InnerText; objSpiritControl.Force = Convert.ToInt32(objXmlSpirit["force"].InnerText); objSpiritControl.ServicesOwed = Convert.ToInt32(objXmlSpirit["services"].InnerText); objSpiritControl.Top = i * objSpiritControl.Height; panSpirits.Controls.Add(objSpiritControl); } } // Update Lifestyles. if (objXmlKit["lifestyles"] != null) { XmlDocument objXmlLifestyleDocument = XmlManager.Instance.Load("lifestyles.xml"); foreach (XmlNode objXmlLifestyle in objXmlKit.SelectNodes("lifestyles/lifestyle")) { string strName = objXmlLifestyle["name"].InnerText; int intMonths = Convert.ToInt32(objXmlLifestyle["months"].InnerText); // Create the Lifestyle. TreeNode objNode = new TreeNode(); Lifestyle objLifestyle = new Lifestyle(_objCharacter); XmlNode objXmlLifestyleNode = objXmlLifestyleDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + strName + "\"]"); if (objXmlLifestyleNode != null) { // This is a standard Lifestyle, so just use the Create method. objLifestyle.Create(objXmlLifestyleNode, objNode); objLifestyle.Months = intMonths; } else { // This is an Advanced Lifestyle, so build it manually. objLifestyle.Name = strName; objLifestyle.Months = intMonths; objLifestyle.Cost = Convert.ToInt32(objXmlLifestyle["cost"].InnerText); objLifestyle.Dice = Convert.ToInt32(objXmlLifestyle["dice"].InnerText); objLifestyle.Multiplier = Convert.ToInt32(objXmlLifestyle["multiplier"].InnerText); objLifestyle.BaseLifestyle = objXmlLifestyle["baselifestyle"].InnerText; objLifestyle.Source = "SR5"; objLifestyle.Page = "373"; objLifestyle.Comforts = Convert.ToInt32(objXmlLifestyle["comforts"].InnerText); objLifestyle.ComfortsEntertainment = Convert.ToInt32(objXmlLifestyle["comfortsentertainment"].InnerText); objLifestyle.Security = Convert.ToInt32(objXmlLifestyle["security"].InnerText); objLifestyle.SecurityEntertainment = Convert.ToInt32(objXmlLifestyle["securityentertainment"].InnerText); objLifestyle.Area = Convert.ToInt32(objXmlLifestyle["area"].InnerText); objLifestyle.AreaEntertainment = Convert.ToInt32(objXmlLifestyle["areaentertainment"].InnerText); foreach (LifestyleQuality objXmlQuality in objXmlLifestyle.SelectNodes("lifestylequalities/lifestylequality")) objLifestyle.LifestyleQualities.Add(objXmlQuality); objNode.Text = strName; } // Add the Lifestyle to the character and Lifestyle Tree. if (objLifestyle.BaseLifestyle != "") objNode.ContextMenuStrip = cmsAdvancedLifestyle; else objNode.ContextMenuStrip = cmsLifestyleNotes; _objCharacter.Lifestyles.Add(objLifestyle); treLifestyles.Nodes[0].Nodes.Add(objNode); treLifestyles.Nodes[0].Expand(); } } // Update NuyenBP. if (objXmlKit["nuyenbp"] != null) { int intAmount = Convert.ToInt32(objXmlKit["nuyenbp"].InnerText); //if (_objCharacter.BuildMethod == CharacterBuildMethod.Karma) //intAmount *= 2; // Make sure we don't go over the field's maximum which would throw an Exception. if (nudNuyen.Value + intAmount > nudNuyen.Maximum) nudNuyen.Value = nudNuyen.Maximum; else nudNuyen.Value += intAmount; } // Update Armor. if (objXmlKit["armors"] != null) { XmlDocument objXmlArmorDocument = XmlManager.Instance.Load("armor.xml"); foreach (XmlNode objXmlArmor in objXmlKit.SelectNodes("armors/armor")) { XmlNode objXmlArmorNode = objXmlArmorDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + objXmlArmor["name"].InnerText + "\"]"); Armor objArmor = new Armor(_objCharacter); TreeNode objNode = new TreeNode(); objArmor.Create(objXmlArmorNode, objNode, cmsArmorMod, Convert.ToInt32(objXmlArmor["rating"].InnerText), false, blnCreateChildren); _objCharacter.Armor.Add(objArmor); // Look for Armor Mods. if (objXmlArmor["mods"] != null) { foreach (XmlNode objXmlMod in objXmlArmor.SelectNodes("mods/mod")) { List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); XmlNode objXmlModNode = objXmlArmorDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]"); ArmorMod objMod = new ArmorMod(_objCharacter); TreeNode objModNode = new TreeNode(); int intRating = 0; if (objXmlMod["rating"] != null) intRating = Convert.ToInt32(objXmlMod["rating"].InnerText); objMod.Create(objXmlModNode, objModNode, intRating, lstWeapons, lstWeaponNodes); objModNode.ContextMenuStrip = cmsArmorMod; objMod.Parent = objArmor; objArmor.ArmorMods.Add(objMod); objNode.Nodes.Add(objModNode); objNode.Expand(); // Add any Weapons created by the Mod. foreach (Weapon objWeapon in lstWeapons) _objCharacter.Weapons.Add(objWeapon); foreach (TreeNode objWeaponNode in lstWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } } } XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlArmor.SelectNodes("gears/gear")) AddPACKSGear(objXmlGearDocument, objXmlGear, objNode, objArmor, cmsArmorGear, blnCreateChildren); objNode.ContextMenuStrip = cmsArmor; treArmor.Nodes[0].Nodes.Add(objNode); treArmor.Nodes[0].Expand(); } } // Update Weapons. if (objXmlKit["weapons"] != null) { XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("weapons/weapon").Count; int i = 0; foreach (XmlNode objXmlWeapon in objXmlKit.SelectNodes("weapons/weapon")) { i++; pgbProgress.Value = i; Application.DoEvents(); XmlNode objXmlWeaponNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["name"].InnerText + "\"]"); Weapon objWeapon = new Weapon(_objCharacter); TreeNode objNode = new TreeNode(); objWeapon.Create(objXmlWeaponNode, _objCharacter, objNode, cmsWeapon, cmsWeaponAccessory, cmsWeaponMod, blnCreateChildren); _objCharacter.Weapons.Add(objWeapon); // Look for Weapon Accessories. if (objXmlWeapon["accessories"] != null) { foreach (XmlNode objXmlAccessory in objXmlWeapon.SelectNodes("accessories/accessory")) { XmlNode objXmlAccessoryNode = objXmlWeaponDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + objXmlAccessory["name"].InnerText + "\"]"); WeaponAccessory objMod = new WeaponAccessory(_objCharacter); TreeNode objModNode = new TreeNode(); string strMount = ""; int intRating = 0; if (objXmlAccessory["mount"] != null) strMount = objXmlAccessory["mount"].InnerText; objMod.Create(objXmlAccessoryNode, objModNode, strMount, intRating); objModNode.ContextMenuStrip = cmsWeaponAccessory; objMod.Parent = objWeapon; objWeapon.WeaponAccessories.Add(objMod); XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlAccessory.SelectNodes("gears/gear")) AddPACKSGear(objXmlGearDocument, objXmlGear, objModNode, objMod, cmsWeaponAccessoryGear, blnCreateChildren); objNode.Nodes.Add(objModNode); objNode.Expand(); } } // Look for Weapon Mods. if (objXmlWeapon["mods"] != null) { foreach (XmlNode objXmlMod in objXmlWeapon.SelectNodes("mods/mod")) { XmlNode objXmlModNode = objXmlWeaponDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]"); WeaponMod objMod = new WeaponMod(_objCharacter); TreeNode objModNode = new TreeNode(); objMod.Create(objXmlModNode, objModNode); objModNode.ContextMenuStrip = cmsWeaponMod; objMod.Parent = objWeapon; objWeapon.WeaponMods.Add(objMod); objNode.Nodes.Add(objModNode); objNode.Expand(); } } // Look for an Underbarrel Weapon. if (objXmlWeapon["underbarrel"] != null) { XmlNode objXmlUnderbarrelNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["underbarrel"].InnerText + "\"]"); Weapon objUnderbarrelWeapon = new Weapon(_objCharacter); TreeNode objUnderbarrelNode = new TreeNode(); objUnderbarrelWeapon.Create(objXmlUnderbarrelNode, _objCharacter, objUnderbarrelNode, cmsWeapon, cmsWeaponAccessory, cmsWeaponMod, blnCreateChildren); objWeapon.UnderbarrelWeapons.Add(objUnderbarrelWeapon); objNode.Nodes.Add(objUnderbarrelNode); objNode.Expand(); } objNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objNode); treWeapons.Nodes[0].Expand(); Application.DoEvents(); } } // Update Cyberware. if (objXmlKit["cyberwares"] != null) { XmlDocument objXmlCyberwareDocument = XmlManager.Instance.Load("cyberware.xml"); XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("cyberwares/cyberware").Count; int i = 0; foreach (XmlNode objXmlCyberware in objXmlKit.SelectNodes("cyberwares/cyberware")) { i++; pgbProgress.Value = i; Application.DoEvents(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); TreeNode objNode = new TreeNode(); Cyberware objCyberware = new Cyberware(_objCharacter); Grade objGrade = objCyberware.ConvertToCyberwareGrade(objXmlCyberware["grade"].InnerText, Improvement.ImprovementSource.Cyberware); int intRating = 0; if (objXmlCyberware["rating"] != null) intRating = Convert.ToInt32(objXmlCyberware["rating"].InnerText); XmlNode objXmlCyberwareNode = objXmlCyberwareDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + objXmlCyberware["name"].InnerText + "\"]"); objCyberware.Create(objXmlCyberwareNode, _objCharacter, objGrade, Improvement.ImprovementSource.Cyberware, intRating, objNode, objWeapons, objWeaponNodes, true, blnCreateChildren); _objCharacter.Cyberware.Add(objCyberware); // Add any children. if (objXmlCyberware["cyberwares"] != null) { foreach (XmlNode objXmlChild in objXmlCyberware.SelectNodes("cyberwares/cyberware")) { TreeNode objChildNode = new TreeNode(); Cyberware objChildCyberware = new Cyberware(_objCharacter); int intChildRating = 0; if (objXmlChild["rating"] != null) intChildRating = Convert.ToInt32(objXmlChild["rating"].InnerText); XmlNode objXmlChildNode = objXmlCyberwareDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + objXmlChild["name"].InnerText + "\"]"); objChildCyberware.Create(objXmlChildNode, _objCharacter, objGrade, Improvement.ImprovementSource.Cyberware, intChildRating, objChildNode, objWeapons, objWeaponNodes, true, blnCreateChildren); objCyberware.Children.Add(objChildCyberware); objChildNode.ContextMenuStrip = cmsCyberware; foreach (XmlNode objXmlGear in objXmlChild.SelectNodes("gears/gear")) AddPACKSGear(objXmlGearDocument, objXmlGear, objChildNode, objChildCyberware, cmsCyberwareGear, blnCreateChildren); objNode.Nodes.Add(objChildNode); objNode.Expand(); } } foreach (XmlNode objXmlGear in objXmlCyberware.SelectNodes("gears/gear")) AddPACKSGear(objXmlGearDocument, objXmlGear, objNode, objCyberware, cmsCyberwareGear, blnCreateChildren); objNode.ContextMenuStrip = cmsCyberware; treCyberware.Nodes[0].Nodes.Add(objNode); treCyberware.Nodes[0].Expand(); // Add any Weapons created by the Gear. foreach (Weapon objWeapon in objWeapons) _objCharacter.Weapons.Add(objWeapon); foreach (TreeNode objWeaponNode in objWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } Application.DoEvents(); } treCyberware.SortCustom(); } // Update Bioware. if (objXmlKit["biowares"] != null) { XmlDocument objXmlBiowareDocument = XmlManager.Instance.Load("bioware.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("biowares/bioware").Count; int i = 0; foreach (XmlNode objXmlBioware in objXmlKit.SelectNodes("biowares/bioware")) { i++; pgbProgress.Value = i; Application.DoEvents(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); TreeNode objNode = new TreeNode(); Cyberware objCyberware = new Cyberware(_objCharacter); Grade objGrade = objCyberware.ConvertToCyberwareGrade(objXmlBioware["grade"].InnerText, Improvement.ImprovementSource.Bioware); int intRating = 0; if (objXmlBioware["rating"] != null) intRating = Convert.ToInt32(objXmlBioware["rating"].InnerText); XmlNode objXmlBiowareNode = objXmlBiowareDocument.SelectSingleNode("/chummer/biowares/bioware[name = \"" + objXmlBioware["name"].InnerText + "\"]"); objCyberware.Create(objXmlBiowareNode, _objCharacter, objGrade, Improvement.ImprovementSource.Bioware, intRating, objNode, objWeapons, objWeaponNodes, true, blnCreateChildren); _objCharacter.Cyberware.Add(objCyberware); objNode.ContextMenuStrip = cmsBioware; treCyberware.Nodes[1].Nodes.Add(objNode); treCyberware.Nodes[1].Expand(); // Add any Weapons created by the Gear. foreach (Weapon objWeapon in objWeapons) _objCharacter.Weapons.Add(objWeapon); foreach (TreeNode objWeaponNode in objWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } Application.DoEvents(); } treCyberware.SortCustom(); } // Update Gear. if (objXmlKit["gears"] != null) { XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("gears/gear").Count; int i = 0; foreach (XmlNode objXmlGear in objXmlKit.SelectNodes("gears/gear")) { i++; pgbProgress.Value = i; Application.DoEvents(); AddPACKSGear(objXmlGearDocument, objXmlGear, treGear.Nodes[0], _objCharacter, cmsGear, blnCreateChildren); Application.DoEvents(); } } // Update Vehicles. if (objXmlKit["vehicles"] != null) { XmlDocument objXmlVehicleDocument = XmlManager.Instance.Load("vehicles.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("vehicles/vehicle").Count; int i = 0; foreach (XmlNode objXmlVehicle in objXmlKit.SelectNodes("vehicles/vehicle")) { i++; pgbProgress.Value = i; Application.DoEvents(); Gear objDefaultSensor = new Gear(_objCharacter); TreeNode objNode = new TreeNode(); Vehicle objVehicle = new Vehicle(_objCharacter); XmlNode objXmlVehicleNode = objXmlVehicleDocument.SelectSingleNode("/chummer/vehicles/vehicle[name = \"" + objXmlVehicle["name"].InnerText + "\"]"); objVehicle.Create(objXmlVehicleNode, objNode, cmsVehicle, cmsVehicleGear, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponMod, blnCreateChildren); _objCharacter.Vehicles.Add(objVehicle); // Grab the default Sensor that comes with the Vehicle. foreach (Gear objSensorGear in objVehicle.Gear) { if (objSensorGear.Category == "Sensors" && objSensorGear.Cost == "0" && objSensorGear.Rating == 0) { objDefaultSensor = objSensorGear; break; } } // Add any Vehicle Mods. if (objXmlVehicle["mods"] != null) { foreach (XmlNode objXmlMod in objXmlVehicle.SelectNodes("mods/mod")) { TreeNode objModNode = new TreeNode(); VehicleMod objMod = new VehicleMod(_objCharacter); int intRating = 0; if (objXmlMod["rating"] != null) intRating = Convert.ToInt32(objXmlMod["rating"].InnerText); XmlNode objXmlModNode = objXmlVehicleDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]"); objMod.Create(objXmlModNode, objModNode, intRating); objVehicle.Mods.Add(objMod); objNode.Nodes.Add(objModNode); objNode.Expand(); } } // Add any Vehicle Gear. if (objXmlVehicle["gears"] != null) { XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlVehicle.SelectNodes("gears/gear")) { List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); TreeNode objGearNode = new TreeNode(); Gear objGear = new Gear(_objCharacter); int intQty = 1; int intRating = 0; if (objXmlGear["rating"] != null) intRating = Convert.ToInt32(objXmlGear["rating"].InnerText); string strForceValue = ""; if (objXmlGear["name"].Attributes["select"] != null) strForceValue = objXmlGear["name"].Attributes["select"].InnerText; if (objXmlGear["qty"] != null) intQty = Convert.ToInt32(objXmlGear["qty"].InnerText); XmlNode objXmlGearNode = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlGear["name"].InnerText + "\"]"); objGear.Create(objXmlGearNode, _objCharacter, objGearNode, intRating, objWeapons, objWeaponNodes, strForceValue, false, false, false, blnCreateChildren, false); objGear.Quantity = intQty; objGearNode.Text = objGear.DisplayName; objVehicle.Gear.Add(objGear); // Look for child components. if (objXmlGear["gears"] != null) { foreach (XmlNode objXmlChild in objXmlGear.SelectNodes("gears/gear")) { AddPACKSGear(objXmlGearDocument, objXmlChild, objGearNode, objGear, cmsVehicleGear, blnCreateChildren); } } objGearNode.Expand(); objGearNode.ContextMenuStrip = cmsVehicleGear; objNode.Nodes.Add(objGearNode); objNode.Expand(); // If this is a Sensor, it will replace the Vehicle's base sensor, so remove it. if (objGear.Category == "Sensors" && objGear.Cost == "0" && objGear.Rating == 0) { objVehicle.Gear.Remove(objDefaultSensor); foreach (TreeNode objSensorNode in objNode.Nodes) { if (objSensorNode.Tag.ToString() == objDefaultSensor.InternalId) { objSensorNode.Remove(); break; } } } } } // Add any Vehicle Weapons. if (objXmlVehicle["weapons"] != null) { XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml"); foreach (XmlNode objXmlWeapon in objXmlVehicle.SelectNodes("weapons/weapon")) { TreeNode objWeaponNode = new TreeNode(); Weapon objWeapon = new Weapon(_objCharacter); XmlNode objXmlWeaponNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["name"].InnerText + "\"]"); objWeapon.Create(objXmlWeaponNode, _objCharacter, objWeaponNode, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponMod, blnCreateChildren); objWeapon.VehicleMounted = true; // Find the first Weapon Mount in the Vehicle. foreach (VehicleMod objMod in objVehicle.Mods) { if (objMod.Name.StartsWith("Weapon Mount") || objMod.Name.StartsWith("Heavy Weapon Mount")) { objMod.Weapons.Add(objWeapon); foreach (TreeNode objModNode in objNode.Nodes) { if (objModNode.Tag.ToString() == objMod.InternalId) { objWeaponNode.ContextMenuStrip = cmsVehicleWeapon; objModNode.Nodes.Add(objWeaponNode); objModNode.Expand(); break; } } break; } } // Look for Weapon Accessories. if (objXmlWeapon["accessories"] != null) { foreach (XmlNode objXmlAccessory in objXmlWeapon.SelectNodes("accessories/accessory")) { XmlNode objXmlAccessoryNode = objXmlWeaponDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + objXmlAccessory["name"].InnerText + "\"]"); WeaponAccessory objMod = new WeaponAccessory(_objCharacter); TreeNode objModNode = new TreeNode(); string strMount = ""; int intRating = 0; if (objXmlAccessory["mount"] != null) strMount = objXmlAccessory["mount"].InnerText; objMod.Create(objXmlAccessoryNode, objModNode, strMount,intRating); objModNode.ContextMenuStrip = cmsWeaponAccessory; objMod.Parent = objWeapon; objWeapon.WeaponAccessories.Add(objMod); objWeaponNode.Nodes.Add(objModNode); objWeaponNode.Expand(); } } // Look for Weapon Mods. if (objXmlWeapon["mods"] != null) { foreach (XmlNode objXmlMod in objXmlWeapon.SelectNodes("mods/mod")) { XmlNode objXmlModNode = objXmlWeaponDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]"); WeaponMod objMod = new WeaponMod(_objCharacter); TreeNode objModNode = new TreeNode(); objMod.Create(objXmlModNode, objModNode); objModNode.ContextMenuStrip = cmsVehicleWeaponMod; objMod.Parent = objWeapon; objWeapon.WeaponMods.Add(objMod); objWeaponNode.Nodes.Add(objModNode); objWeaponNode.Expand(); } } } } objNode.ContextMenuStrip = cmsVehicle; treVehicles.Nodes[0].Nodes.Add(objNode); treVehicles.Nodes[0].Expand(); Application.DoEvents(); } } pgbProgress.Visible = false; if (frmPickPACKSKit.AddAgain) AddPACKSKit(); PopulateGearList(); UpdateCharacterInfo(); }
private void cmdVehicleMoveToInventory_Click(object sender, EventArgs e) { // Locate the selected Weapon. bool blnFound = false; Weapon objWeapon = new Weapon(_objCharacter); Vehicle objVehicle = new Vehicle(_objCharacter); VehicleMod objMod = new VehicleMod(_objCharacter); foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles) { foreach (Weapon objVehicleWeapon in objCharacterVehicle.Weapons) { if (objVehicleWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString()) { objWeapon = objVehicleWeapon; objVehicle = objCharacterVehicle; blnFound = true; break; } } foreach (VehicleMod objVehicleMod in objCharacterVehicle.Mods) { foreach (Weapon objVehicleWeapon in objVehicleMod.Weapons) { if (objVehicleWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString()) { objWeapon = objVehicleWeapon; objVehicle = objCharacterVehicle; objMod = objVehicleMod; blnFound = true; break; } } } } if (blnFound){ // Move the Weapons from the Vehicle Mod (or Vehicle) to the character. if (objMod.InternalId != Guid.Empty.ToString()) objMod.Weapons.Remove(objWeapon); else objVehicle.Weapons.Remove(objWeapon); _objCharacter.Weapons.Add(objWeapon); TreeNode objNode = new TreeNode(); objNode = treVehicles.SelectedNode; treVehicles.SelectedNode.Remove(); treWeapons.Nodes[0].Nodes.Add(objNode); objWeapon.VehicleMounted = false; objNode.Expand(); } else { // Locate the selected Gear. Vehicle objSelectedVehicle = new Vehicle(_objCharacter); Gear objSelectedGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objSelectedVehicle); int intMove = 0; if (objSelectedGear.Quantity == 1) intMove = 1; else { frmSelectNumber frmPickNumber = new frmSelectNumber(); frmPickNumber.Minimum = 1; frmPickNumber.Maximum = objSelectedGear.Quantity; frmPickNumber.Description = LanguageManager.Instance.GetString("String_MoveGear"); frmPickNumber.ShowDialog(this); if (frmPickNumber.DialogResult == DialogResult.Cancel) return; intMove = frmPickNumber.SelectedValue; } // See if the character already has a matching piece of Gear. bool blnMatch = false; Gear objFoundGear = new Gear(_objCharacter); foreach (Gear objCharacterGear in _objCharacter.Gear) { if (objCharacterGear.Name == objSelectedGear.Name && objCharacterGear.Category == objSelectedGear.Category && objCharacterGear.Rating == objSelectedGear.Rating && objCharacterGear.Extra == objSelectedGear.Extra && objCharacterGear.GearName == objSelectedGear.GearName && objCharacterGear.Notes == objSelectedGear.Notes) { blnMatch = true; objFoundGear = objCharacterGear; if (objCharacterGear.Children.Count == objSelectedGear.Children.Count) { for (int i = 0; i <= objCharacterGear.Children.Count - 1; i++) { if (objCharacterGear.Children[i].Name != objSelectedGear.Children[i].Name || objCharacterGear.Children[i].Extra != objSelectedGear.Children[i].Extra || objCharacterGear.Children[i].Rating != objSelectedGear.Children[i].Rating) { blnMatch = false; break; } } } else blnMatch = false; } } if (!blnMatch) { // Create a new piece of Gear. TreeNode objGearNode = new TreeNode(); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); Gear objGear = new Gear(_objCharacter); if (objSelectedGear.GetType() == typeof(Commlink)) { Commlink objCommlink = new Commlink(_objCharacter); objCommlink.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes); objGear = objCommlink; } else objGear.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes); objGear.Parent = null; objGear.Quantity = intMove; objGearNode.Text = objGear.DisplayName; objGearNode.ContextMenuStrip = cmsGear; treGear.Nodes[0].Nodes.Add(objGearNode); _objCharacter.Gear.Add(objGear); // Create any Weapons that came with this Gear. foreach (Weapon objGearWeapon in lstWeapons) _objCharacter.Weapons.Add(objGearWeapon); foreach (TreeNode objWeaponNode in lstWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } AddGearImprovements(objGear); UpdateCharacterInfo(); } else { // Everything matches up, so just increase the quantity. objFoundGear.Quantity += intMove; foreach (TreeNode nodGear in treGear.Nodes[0].Nodes) { if (nodGear.Tag.ToString() == objFoundGear.InternalId) nodGear.Text = objFoundGear.DisplayName; } } // Update the selected item. objSelectedGear.Quantity -= intMove; if (objSelectedGear.Quantity == 0) { // The quantity has reached 0, so remove it entirely. treVehicles.SelectedNode.Remove(); foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles) objCharacterVehicle.Gear.Remove(objSelectedGear); } else treVehicles.SelectedNode.Text = objSelectedGear.DisplayName; } _blnIsDirty = true; UpdateWindowTitle(); }
/// <summary> /// Update the Mod's information based on the Mod selected and current Rating. /// </summary> private void UpdateGearInfo() { if (lstMod.Text != "") { // Retireve the information for the selected Mod. XmlNode objXmlMod = _objXmlDocument.SelectSingleNode("/chummer/mods/mod[id = \"" + lstMod.SelectedValue + "\"]"); string strAvail = ""; string strModBook = ""; string strModPage = ""; int intItemCost = 0; int intSlots = 0; if (_objMode == Mode.Vehicle) { TreeNode objTreeNode = new TreeNode(); VehicleMod objVehicleMod = new VehicleMod(_objCharacter); objVehicleMod.Create(objXmlMod, objTreeNode, Convert.ToInt32(nudRating.Value)); Vehicle objVehicle = new Vehicle(_objCharacter); objVehicleMod.Parent = objVehicle; if (_intVehicleCost != 0) { objVehicle.Cost = _intVehicleCost.ToString(); } string strAccel = _intAccelWalking.ToString() + "/" + _intAccelRunning.ToString(); objVehicle.Accel = strAccel; if (_intBody != 0) { objVehicle.Body = _intBody; } if (_intSpeed != 0) { objVehicle.Speed = _intSpeed; } strAvail = objVehicleMod.TotalAvail; intItemCost = objVehicleMod.TotalCost; intSlots = objVehicleMod.CalculatedSlots; strModBook = objVehicleMod.Source; strModPage = objVehicleMod.Page; } else if (_objMode == Mode.WeaponMod) { TreeNode objTreeNode = new TreeNode(); WeaponMod objWeaponMod = new WeaponMod(_objCharacter); objWeaponMod.Create(objXmlMod, objTreeNode); if (_intWeaponCost != 0) { Weapon objWeapon = new Weapon(_objCharacter); objWeapon.Cost = _intWeaponCost; objWeaponMod.Parent = objWeapon; } strAvail = objWeaponMod.TotalAvail; intItemCost = objWeaponMod.TotalCost; intSlots = objWeaponMod.Slots; strModBook = objWeaponMod.Source; strModPage = objWeaponMod.Page; } lblAvail.Text = strAvail; // Cost. if (objXmlMod["cost"].InnerText.StartsWith("Variable")) { int intMin = 0; int intMax = 0; string strCost = objXmlMod["cost"].InnerText.Replace("Variable(", string.Empty).Replace(")", string.Empty); if (strCost.Contains("-")) { string[] strValues = strCost.Split('-'); intMin = Convert.ToInt32(strValues[0]); intMax = Convert.ToInt32(strValues[1]); } else { intMin = Convert.ToInt32(strCost.Replace("+", string.Empty)); } if (intMax == 0) { intMax = 1000000; lblCost.Text = String.Format("{0:###,###,##0¥+}", intMin); } else { lblCost.Text = String.Format("{0:###,###,##0}", intMin) + "-" + String.Format("{0:###,###,##0¥}", intMax); } intItemCost = intMin; } else { int intCost = Convert.ToInt32(Convert.ToDouble(intItemCost, GlobalOptions.Instance.CultureInfo)); intCost *= _intModMultiplier; // Apply any markup. double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo); dblCost *= 1 + (Convert.ToDouble(nudMarkup.Value, GlobalOptions.Instance.CultureInfo) / 100.0); intCost = Convert.ToInt32(dblCost); lblCost.Text = String.Format("{0:###,###,##0¥}", intCost); intItemCost = intCost; } // Update the Avail Test Label. lblTest.Text = _objCharacter.AvailTest(intItemCost, lblAvail.Text); // If the rating is "qty", we're looking at Tires instead of actual Rating, so update the fields appropriately. if (objXmlMod["rating"].InnerText == "qty") { nudRating.Enabled = true; nudRating.Maximum = 20; nudRating.Minimum = 1; lblRatingLabel.Text = LanguageManager.Instance.GetString("Label_Qty"); } else { if (Convert.ToInt32(objXmlMod["rating"].InnerText) > 0) { nudRating.Maximum = Convert.ToInt32(objXmlMod["rating"].InnerText); nudRating.Minimum = 1; nudRating.Enabled = true; lblRatingLabel.Text = LanguageManager.Instance.GetString("Label_Rating"); } else { nudRating.Minimum = 0; nudRating.Maximum = 0; nudRating.Enabled = false; lblRatingLabel.Text = LanguageManager.Instance.GetString("Label_Rating"); } } // Slots. lblSlots.Text = intSlots.ToString(); try { if (objXmlMod["category"].InnerText == "Weapon Mod") { lblCategory.Text = LanguageManager.Instance.GetString("String_WeaponModification"); } else { // Translate the Category if possible. if (GlobalOptions.Instance.Language != "en-us") { XmlNode objXmlCategory = _objXmlDocument.SelectSingleNode("/chummer/modcategories/category[. = \"" + objXmlMod["category"].InnerText + "\"]"); if (objXmlCategory != null) { if (objXmlCategory.Attributes["translate"] != null) { lblCategory.Text = objXmlCategory.Attributes["translate"].InnerText; } else { lblCategory.Text = objXmlMod["category"].InnerText; } } else { lblCategory.Text = objXmlMod["category"].InnerText; } } else { lblCategory.Text = objXmlMod["category"].InnerText; } } } catch { lblCategory.Text = LanguageManager.Instance.GetString("String_WeaponModification"); } if (objXmlMod["limit"] != null) { // Translate the Limit if possible. if (GlobalOptions.Instance.Language != "en-us") { XmlNode objXmlLimit = _objXmlDocument.SelectSingleNode("/chummer/limits/limit[. = \"" + objXmlMod["limit"].InnerText + "\"]"); if (objXmlLimit != null) { if (objXmlLimit.Attributes["translate"] != null) { lblLimit.Text = " (" + objXmlLimit.Attributes["translate"].InnerText + ")"; } else { lblLimit.Text = " (" + objXmlMod["limit"].InnerText + ")"; } } else { lblLimit.Text = " (" + objXmlMod["limit"].InnerText + ")"; } } else { lblLimit.Text = " (" + objXmlMod["limit"].InnerText + ")"; } } else { lblLimit.Text = ""; } string strBook = _objCharacter.Options.LanguageBookShort(strModBook); string strPage = strModPage; lblSource.Text = strBook + " " + strPage; tipTooltip.SetToolTip(lblSource, _objCharacter.Options.LanguageBookLong(strModBook) + " " + LanguageManager.Instance.GetString("String_Page") + " " + strPage); } }
public void Handle(Chaos mod, String from, IEnumerable <String> rest) { var stringId = rest.GetEnumerator().NextOrDefault("random"); var id = ParseModId(stringId); var player = Game.Player.Character; if (player == null) { mod.ShowText($"{from} tried to open your parachute!"); return; } var vehicle = player.CurrentVehicle; if (vehicle == null) { mod.ShowText($"{from} tried to upgrade your vehicle!"); return; } vehicle.Mods.InstallModKit(); vehicle.RandomizeColors(mod.Rnd); vehicle.RandomizeLightsOn(mod.Rnd); var turbo = vehicle.Mods[VehicleToggleModType.XenonHeadlights]; vehicle.Mods[VehicleToggleModType.XenonHeadlights].IsInstalled = mod.Rnd.NextBoolean(); vehicle.Mods[VehicleToggleModType.TireSmoke].IsInstalled = mod.Rnd.NextBoolean(); switch (id) { case ModId.MidTier: // 50% chance of getting a turbo. turbo.IsInstalled = mod.Rnd.NextBoolean(); break; case ModId.HighTier: // 75% chance of getting a turbo. turbo.IsInstalled = mod.Rnd.Next(0, 4) != 0; break; default: turbo.IsInstalled = false; break; } foreach (var m in ALL_MOD_TYPES) { VehicleMod modType = vehicle.Mods[m]; var count = modType.ModCount; if (count == 0) { continue; } var bottom = 0; var ceiling = count + 1; switch (id) { case ModId.Random: break; case ModId.LowTier: bottom = 0; ceiling = Math.Max(1, count / 3); break; case ModId.MidTier: bottom = count / 3; ceiling = Math.Max(bottom + 1, 2 * (count / 3)); break; case ModId.HighTier: bottom = Math.Min(2 * (count / 3), count - 1); ceiling = count; break; } var index = mod.Rnd.Next(bottom, ceiling); modType.Index = index; } mod.ShowText($"{from} modded your vehicle ({id})!"); }
/// <summary> /// Locate a piece of Cyberware within the character's Vehicles. /// </summary> /// <param name="funcPredicate">Predicate to locate the Cyberware.</param> /// <param name="lstVehicles">List of Vehicles to search.</param> /// <param name="objFoundVehicleMod">Vehicle Mod to which the Cyberware belongs.</param> public static Cyberware FindVehicleCyberware([NotNull] this IEnumerable <Vehicle> lstVehicles, [NotNull] Func <Cyberware, bool> funcPredicate, out VehicleMod objFoundVehicleMod) { foreach (Vehicle objVehicle in lstVehicles) { Cyberware objReturn = objVehicle.FindVehicleCyberware(funcPredicate, out objFoundVehicleMod); if (objReturn != null) { return(objReturn); } } objFoundVehicleMod = null; return(null); }
/// <summary> /// Locate a Weapon within the character's Vehicles. /// </summary> /// <param name="strGuid">InteralId of the Weapon to find.</param> /// <param name="lstVehicles">List of Vehicles to search.</param> /// <param name="objFoundVehicle">Vehicle that the Weapon was found in.</param> /// <param name="objFoundVehicleMod">Vehicle mod that the Weapon was found in.</param> /// <param name="objFoundWeaponMount">Weapon Mount that the Weapon was found in.</param> public static Weapon FindVehicleWeapon(this IEnumerable <Vehicle> lstVehicles, string strGuid, out Vehicle objFoundVehicle, out WeaponMount objFoundWeaponMount, out VehicleMod objFoundVehicleMod) { if (!string.IsNullOrWhiteSpace(strGuid) && !strGuid.IsEmptyGuid()) { foreach (Vehicle objVehicle in lstVehicles) { Weapon objReturn = objVehicle.Weapons.DeepFindById(strGuid); if (objReturn != null) { objFoundVehicle = objVehicle; objFoundWeaponMount = null; objFoundVehicleMod = null; return(objReturn); } foreach (WeaponMount objWeaponMount in objVehicle.WeaponMounts) { objReturn = objWeaponMount.Weapons.DeepFindById(strGuid); if (objReturn != null) { objFoundVehicle = objVehicle; objFoundWeaponMount = objWeaponMount; objFoundVehicleMod = null; return(objReturn); } foreach (VehicleMod objMod in objWeaponMount.Mods) { objReturn = objMod.Weapons.DeepFindById(strGuid); if (objReturn != null) { objFoundVehicle = objVehicle; objFoundVehicleMod = objMod; objFoundWeaponMount = objWeaponMount; return(objReturn); } } } foreach (VehicleMod objMod in objVehicle.Mods) { objReturn = objMod.Weapons.DeepFindById(strGuid); if (objReturn != null) { objFoundVehicle = objVehicle; objFoundVehicleMod = objMod; objFoundWeaponMount = null; return(objReturn); } } } } objFoundVehicle = null; objFoundWeaponMount = null; objFoundVehicleMod = null; return(null); }
private void cmdWeaponMoveToVehicle_Click(object sender, EventArgs e) { // Locate the selected Weapon. Weapon objWeapon = new Weapon(_objCharacter); foreach (Weapon objCharacterWeapon in _objCharacter.Weapons) { if (objCharacterWeapon.InternalId == treWeapons.SelectedNode.Tag.ToString()) { objWeapon = objCharacterWeapon; break; } } List<Vehicle> lstVehicles = new List<Vehicle>(); foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles) { foreach (VehicleMod objVehicleMod in objCharacterVehicle.Mods) { // Only add a Vehicle to the list if it has a Weapon Mount or Mechanical Arm. if (objVehicleMod.Name.StartsWith("Weapon Mount") || objVehicleMod.Name.StartsWith("Heavy Weapon Mount") || objVehicleMod.Name.StartsWith("Mechanical Arm")) { lstVehicles.Add(objCharacterVehicle); break; } } } // Cannot continue if there are no Vehicles with a Weapon Mount or Mechanical Arm. if (lstVehicles.Count == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotMoveWeapons"), LanguageManager.Instance.GetString("MessageTitle_CannotMoveWeapons"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } frmSelectItem frmPickItem = new frmSelectItem(); frmPickItem.Vehicles = lstVehicles; frmPickItem.ShowDialog(this); if (frmPickItem.DialogResult == DialogResult.Cancel) return; // Locate the selected Vehicle. Vehicle objVehicle = new Vehicle(_objCharacter); foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles) { if (objCharacterVehicle.InternalId == frmPickItem.SelectedItem) { objVehicle = objCharacterVehicle; break; } } // Now display a list of the acceptable mounting points for the Weapon. List<VehicleMod> lstMods = new List<VehicleMod>(); foreach (VehicleMod objVehicleMod in objVehicle.Mods) { if (objVehicleMod.Name.StartsWith("Weapon Mount") || objVehicleMod.Name.StartsWith("Heavy Weapon Mount") || objVehicleMod.Name.StartsWith("Mechanical Arm")) lstMods.Add(objVehicleMod); } frmPickItem.VehicleMods = lstMods; frmPickItem.ShowDialog(this); if (frmPickItem.DialogResult == DialogResult.Cancel) return; // Locate the selected Vehicle Mod. VehicleMod objMod = new VehicleMod(_objCharacter); foreach (VehicleMod objCharacterMod in objVehicle.Mods) { if (objCharacterMod.InternalId == frmPickItem.SelectedItem) { objMod = objCharacterMod; break; } } // Remove the Weapon from the character and add it to the Vehicle Mod. _objCharacter.Weapons.Remove(objWeapon); objMod.Weapons.Add(objWeapon); objWeapon.VehicleMounted = true; objWeapon.Location = string.Empty; // Move the TreeNode to the Vehicle Mod. TreeNode objNode = new TreeNode(); objNode = treWeapons.SelectedNode; treWeapons.SelectedNode.Remove(); foreach (TreeNode objVehicleNode in treVehicles.Nodes[0].Nodes) { foreach (TreeNode objModNode in objVehicleNode.Nodes) { if (objModNode.Tag.ToString() == objMod.InternalId) { objModNode.Nodes.Add(objNode); objModNode.Expand(); objNode.Expand(); break; } } } // Remove any Improvements from the Character. foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories) { foreach (Gear objGear in objAccessory.Gear) _objFunctions.DeleteGear(objGear, treWeapons, _objImprovementManager); } if (objWeapon.UnderbarrelWeapons.Count > 0) { foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons) { foreach (WeaponAccessory objAccessory in objUnderbarrelWeapon.WeaponAccessories) { foreach (Gear objGear in objAccessory.Gear) _objFunctions.DeleteGear(objGear, treWeapons, _objImprovementManager); } } } _blnIsDirty = true; UpdateWindowTitle(); }
/// <summary> /// Update the Mod's information based on the Mod selected and current Rating. /// </summary> private void UpdateGearInfo() { if (lstMod.Text != "") { // Retireve the information for the selected Mod. XmlNode objXmlMod = _objXmlDocument.SelectSingleNode("/chummer/mods/mod[id = \"" + lstMod.SelectedValue + "\"]"); string strAvail = ""; string strModBook = ""; string strModPage = ""; int intItemCost = 0; int intSlots = 0; if (_objMode == Mode.Vehicle) { TreeNode objTreeNode = new TreeNode(); VehicleMod objVehicleMod = new VehicleMod(_objCharacter); objVehicleMod.Create(objXmlMod, objTreeNode, Convert.ToInt32(nudRating.Value)); Vehicle objVehicle = new Vehicle(_objCharacter); objVehicleMod.Parent = objVehicle; if (_intVehicleCost != 0) objVehicle.Cost = _intVehicleCost.ToString(); string strAccel = _intAccelWalking.ToString() + "/" + _intAccelRunning.ToString(); objVehicle.Accel = strAccel; if (_intBody != 0) objVehicle.Body = _intBody; if (_intSpeed != 0) objVehicle.Speed = _intSpeed; strAvail = objVehicleMod.TotalAvail; intItemCost = objVehicleMod.TotalCost; intSlots = objVehicleMod.CalculatedSlots; strModBook = objVehicleMod.Source; strModPage = objVehicleMod.Page; } else if (_objMode == Mode.WeaponMod) { TreeNode objTreeNode = new TreeNode(); WeaponMod objWeaponMod = new WeaponMod(_objCharacter); objWeaponMod.Create(objXmlMod, objTreeNode); if (_intWeaponCost != 0) { Weapon objWeapon = new Weapon(_objCharacter); objWeapon.Cost = _intWeaponCost; objWeaponMod.Parent = objWeapon; } strAvail = objWeaponMod.TotalAvail; intItemCost = objWeaponMod.TotalCost; intSlots = objWeaponMod.Slots; strModBook = objWeaponMod.Source; strModPage = objWeaponMod.Page; } lblAvail.Text = strAvail; // Cost. if (objXmlMod["cost"].InnerText.StartsWith("Variable")) { int intMin = 0; int intMax = 0; string strCost = objXmlMod["cost"].InnerText.Replace("Variable(", string.Empty).Replace(")", string.Empty); if (strCost.Contains("-")) { string[] strValues = strCost.Split('-'); intMin = Convert.ToInt32(strValues[0]); intMax = Convert.ToInt32(strValues[1]); } else intMin = Convert.ToInt32(strCost.Replace("+", string.Empty)); if (intMax == 0) { intMax = 1000000; lblCost.Text = String.Format("{0:###,###,##0¥+}", intMin); } else lblCost.Text = String.Format("{0:###,###,##0}", intMin) + "-" + String.Format("{0:###,###,##0¥}", intMax); intItemCost = intMin; } else { int intCost = Convert.ToInt32(Convert.ToDouble(intItemCost, GlobalOptions.Instance.CultureInfo)); intCost *= _intModMultiplier; // Apply any markup. double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo); dblCost *= 1 + (Convert.ToDouble(nudMarkup.Value, GlobalOptions.Instance.CultureInfo) / 100.0); intCost = Convert.ToInt32(dblCost); lblCost.Text = String.Format("{0:###,###,##0¥}", intCost); intItemCost = intCost; } // Update the Avail Test Label. lblTest.Text = _objCharacter.AvailTest(intItemCost, lblAvail.Text); // If the rating is "qty", we're looking at Tires instead of actual Rating, so update the fields appropriately. if (objXmlMod["rating"].InnerText == "qty") { nudRating.Enabled = true; nudRating.Maximum = 20; nudRating.Minimum = 1; lblRatingLabel.Text = LanguageManager.Instance.GetString("Label_Qty"); } else { if (Convert.ToInt32(objXmlMod["rating"].InnerText) > 0) { nudRating.Maximum = Convert.ToInt32(objXmlMod["rating"].InnerText); nudRating.Minimum = 1; nudRating.Enabled = true; lblRatingLabel.Text = LanguageManager.Instance.GetString("Label_Rating"); } else { nudRating.Minimum = 0; nudRating.Maximum = 0; nudRating.Enabled = false; lblRatingLabel.Text = LanguageManager.Instance.GetString("Label_Rating"); } } // Slots. lblSlots.Text = intSlots.ToString(); try { if (objXmlMod["category"].InnerText == "Weapon Mod") lblCategory.Text = LanguageManager.Instance.GetString("String_WeaponModification"); else { // Translate the Category if possible. if (GlobalOptions.Instance.Language != "en-us") { XmlNode objXmlCategory = _objXmlDocument.SelectSingleNode("/chummer/modcategories/category[. = \"" + objXmlMod["category"].InnerText + "\"]"); if (objXmlCategory != null) { if (objXmlCategory.Attributes["translate"] != null) lblCategory.Text = objXmlCategory.Attributes["translate"].InnerText; else lblCategory.Text = objXmlMod["category"].InnerText; } else lblCategory.Text = objXmlMod["category"].InnerText; } else lblCategory.Text = objXmlMod["category"].InnerText; } } catch { lblCategory.Text = LanguageManager.Instance.GetString("String_WeaponModification"); } if (objXmlMod["limit"] != null) { // Translate the Limit if possible. if (GlobalOptions.Instance.Language != "en-us") { XmlNode objXmlLimit = _objXmlDocument.SelectSingleNode("/chummer/limits/limit[. = \"" + objXmlMod["limit"].InnerText + "\"]"); if (objXmlLimit != null) { if (objXmlLimit.Attributes["translate"] != null) lblLimit.Text = " (" + objXmlLimit.Attributes["translate"].InnerText + ")"; else lblLimit.Text = " (" + objXmlMod["limit"].InnerText + ")"; } else lblLimit.Text = " (" + objXmlMod["limit"].InnerText + ")"; } else lblLimit.Text = " (" + objXmlMod["limit"].InnerText + ")"; } else lblLimit.Text = ""; string strBook = _objCharacter.Options.LanguageBookShort(strModBook); string strPage = strModPage; lblSource.Text = strBook + " " + strPage; tipTooltip.SetToolTip(lblSource, _objCharacter.Options.LanguageBookLong(strModBook) + " " + LanguageManager.Instance.GetString("String_Page") + " " + strPage); } }
private void tsVehicleNotes_Click(object sender, EventArgs e) { Vehicle objVehicle = new Vehicle(_objCharacter); VehicleMod objMod = new VehicleMod(_objCharacter); bool blnFoundVehicle = false; bool blnFoundMod = false; try { foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles) { if (objCharacterVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString()) { objVehicle = objCharacterVehicle; blnFoundVehicle = true; break; } foreach (VehicleMod objVehicleMod in objCharacterVehicle.Mods) { if (objVehicleMod.InternalId == treVehicles.SelectedNode.Tag.ToString()) { objMod = objVehicleMod; blnFoundMod = true; break; } } } if (blnFoundVehicle) { frmNotes frmItemNotes = new frmNotes(); frmItemNotes.Notes = objVehicle.Notes; string strOldValue = objVehicle.Notes; frmItemNotes.ShowDialog(this); if (frmItemNotes.DialogResult == DialogResult.OK) { objVehicle.Notes = frmItemNotes.Notes; if (objVehicle.Notes != strOldValue) { _blnIsDirty = true; UpdateWindowTitle(); } } if (objVehicle.Notes != string.Empty) treVehicles.SelectedNode.ForeColor = Color.SaddleBrown; else treVehicles.SelectedNode.ForeColor = SystemColors.WindowText; treVehicles.SelectedNode.ToolTipText = CommonFunctions.WordWrap(objVehicle.Notes, 100); } if (blnFoundMod) { frmNotes frmItemNotes = new frmNotes(); frmItemNotes.Notes = objMod.Notes; string strOldValue = objMod.Notes; frmItemNotes.ShowDialog(this); if (frmItemNotes.DialogResult == DialogResult.OK) { objMod.Notes = frmItemNotes.Notes; if (objMod.Notes != strOldValue) { _blnIsDirty = true; UpdateWindowTitle(); } } if (objMod.Notes != string.Empty) treVehicles.SelectedNode.ForeColor = Color.SaddleBrown; else { if (objMod.IncludedInVehicle) treVehicles.SelectedNode.ForeColor = SystemColors.GrayText; else treVehicles.SelectedNode.ForeColor = SystemColors.WindowText; } treVehicles.SelectedNode.ToolTipText = CommonFunctions.WordWrap(objMod.Notes, 100); } } catch { } }
private void TestVehicles() { Character objCharacter = new Character(); XmlDocument objXmlDocument = XmlManager.Instance.Load("vehicles.xml"); pgbProgress.Minimum = 0; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlDocument.SelectNodes("/chummer/vehicles/vehicle").Count; pgbProgress.Maximum += objXmlDocument.SelectNodes("/chummer/mods/mod").Count; // Vehicles. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/vehicles/vehicle")) { pgbProgress.Value++; Application.DoEvents(); try { TreeNode objTempNode = new TreeNode(); Vehicle objTemp = new Vehicle(objCharacter); objTemp.Create(objXmlGear, objTempNode, null, null, null, null, null); try { int objValue = objTemp.TotalCost; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\n"; } try { string objValue = objTemp.TotalAccel; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAccel\n"; } try { int objValue = objTemp.TotalArmor; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalArmor\n"; } try { int objValue = objTemp.TotalBody; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalBody\n"; } try { int objValue = objTemp.TotalHandling; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalHandling\n"; } try { int objValue = objTemp.TotalSpeed; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalSpeed\n"; } try { string objValue = objTemp.CalculatedAvail; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedAvail\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\n"; } } // Vehicle Mods. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/mods/mod")) { pgbProgress.Value++; Application.DoEvents(); try { TreeNode objTempNode = new TreeNode(); VehicleMod objTemp = new VehicleMod(objCharacter); objTemp.Create(objXmlGear, objTempNode, 1); try { int objValue = objTemp.TotalCost; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\n"; } try { string objValue = objTemp.TotalAvail; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\n"; } try { int objValue = objTemp.CalculatedSlots; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedSlots\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\n"; } } }
/// <summary> /// Enable/Disable the Paste Menu and ToolStrip items as appropriate. /// </summary> private void RefreshPasteStatus() { bool blnPasteEnabled = false; bool blnCopyEnabled = false; if (tabCharacterTabs.SelectedTab == tabStreetGear) { // Lifestyle Tab. if (tabStreetGearTabs.SelectedTab == tabLifestyle) { if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Lifestyle) blnPasteEnabled = true; try { foreach (Lifestyle objLifestyle in _objCharacter.Lifestyles) { if (objLifestyle.InternalId == treLifestyles.SelectedNode.Tag.ToString()) { blnCopyEnabled = true; break; } } } catch { } } // Armor Tab. if (tabStreetGearTabs.SelectedTab == tabArmor) { if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Armor) blnPasteEnabled = true; if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem) { // Gear can only be pasted into Armor, not Armor Mods. try { foreach (Armor objArmor in _objCharacter.Armor) { if (objArmor.InternalId == treArmor.SelectedNode.Tag.ToString()) { blnPasteEnabled = true; break; } } } catch { } } try { foreach (Armor objArmor in _objCharacter.Armor) { if (objArmor.InternalId == treArmor.SelectedNode.Tag.ToString()) { blnCopyEnabled = true; break; } } } catch { } try { Armor objArmor = new Armor(_objCharacter); Gear objGear = _objFunctions.FindArmorGear(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor, out objArmor); if (objGear != null) blnCopyEnabled = true; } catch { } } // Weapons Tab. if (tabStreetGearTabs.SelectedTab == tabWeapons) { if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Weapon) blnPasteEnabled = true; if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem) { // Check if the copied Gear can be pasted into the selected Weapon Accessory. Gear objGear = new Gear(_objCharacter); XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/gear"); if (objXmlNode != null) { switch (objXmlNode["category"].InnerText) { case "Commlinks": case "Cyberdecks": case "Rigger Command Consoles": Commlink objCommlink = new Commlink(_objCharacter); objCommlink.Load(objXmlNode, true); objGear = objCommlink; break; default: Gear objNewGear = new Gear(_objCharacter); objNewGear.Load(objXmlNode, true); objGear = objNewGear; break; } objGear.Parent = null; // Make sure that a Weapon Accessory is selected and that it allows Gear of the item's Category. WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter); try { foreach (Weapon objCharacterWeapon in _objCharacter.Weapons) { foreach (WeaponAccessory objWeaponAccessory in objCharacterWeapon.WeaponAccessories) { if (objWeaponAccessory.InternalId == treWeapons.SelectedNode.Tag.ToString()) { objAccessory = objWeaponAccessory; break; } } } if (objAccessory.AllowGear != null) { foreach (XmlNode objAllowed in objAccessory.AllowGear.SelectNodes("gearcategory")) { if (objAllowed.InnerText == objGear.Category) { blnPasteEnabled = true; break; } } } } catch { } } } try { foreach (Weapon objWeapon in _objCharacter.Weapons) { if (objWeapon.InternalId == treWeapons.SelectedNode.Tag.ToString()) { blnCopyEnabled = true; break; } } } catch { } try { WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter); Gear objGear = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objAccessory); if (objGear != null) blnCopyEnabled = true; } catch { } } // Gear Tab. if (tabStreetGearTabs.SelectedTab == tabGear) { if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem) blnPasteEnabled = true; try { Gear objGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear); if (objGear != null) blnCopyEnabled = true; } catch { } } } // Vehicles Tab. if (tabCharacterTabs.SelectedTab == tabVehicles) { if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Vehicle) blnPasteEnabled = true; if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem) { // Gear can only be pasted into Vehicles and Vehicle Gear. try { foreach (Vehicle objVehicle in _objCharacter.Vehicles) { if (objVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString()) { blnPasteEnabled = true; break; } } } catch { } try { Vehicle objVehicle = new Vehicle(_objCharacter); Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objVehicle); if (objGear != null) blnPasteEnabled = true; } catch { } } if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Weapon) { // Weapons can only be pasted into Vehicle Mods that allow them (Weapon Mounts and Mechanical Arms). try { VehicleMod objMod = new VehicleMod(_objCharacter); foreach (Vehicle objVehicle in _objCharacter.Vehicles) { foreach (VehicleMod objVehicleMod in objVehicle.Mods) { if (objVehicleMod.InternalId == treVehicles.SelectedNode.Tag.ToString()) { if (objVehicleMod.Name.StartsWith("Weapon Mount") || objVehicleMod.Name.StartsWith("Heavy Weapon Mount") || objVehicleMod.Name.StartsWith("Mechanical Arm")) { blnPasteEnabled = true; break; } } } } } catch { } } try { foreach (Vehicle objVehicle in _objCharacter.Vehicles) { if (objVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString()) { blnCopyEnabled = true; break; } } } catch { } try { Vehicle objVehicle = new Vehicle(_objCharacter); Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objVehicle); if (objGear != null) blnCopyEnabled = true; } catch { } try { foreach (Vehicle objVehicle in _objCharacter.Vehicles) { foreach (VehicleMod objMod in objVehicle.Mods) { foreach (Weapon objWeapon in objMod.Weapons) { if (objWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString()) { blnCopyEnabled = true; break; } } } } } catch { } } mnuEditPaste.Enabled = blnPasteEnabled; tsbPaste.Enabled = blnPasteEnabled; mnuEditCopy.Enabled = blnCopyEnabled; tsbCopy.Enabled = blnCopyEnabled; }
private void UpdateInfo() { if (_blnLoading) { return; } XmlNode xmlSelectedMount = null; string strSelectedMount = cboSize.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelectedMount)) { cmdOK.Enabled = false; } else { xmlSelectedMount = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedMount + "\"]"); if (xmlSelectedMount == null) { cmdOK.Enabled = false; } else { string strSelectedControl = cboControl.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelectedControl)) { cmdOK.Enabled = false; } else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedControl + "\"]") == null) { cmdOK.Enabled = false; } else { string strSelectedFlexibility = cboFlexibility.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelectedFlexibility)) { cmdOK.Enabled = false; } else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedFlexibility + "\"]") == null) { cmdOK.Enabled = false; } else { string strSelectedVisibility = cboVisibility.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelectedVisibility)) { cmdOK.Enabled = false; } else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedVisibility + "\"]") == null) { cmdOK.Enabled = false; } else { cmdOK.Enabled = true; } } } } } string[] astrSelectedValues = { cboVisibility.SelectedValue?.ToString(), cboFlexibility.SelectedValue?.ToString(), cboControl.SelectedValue?.ToString() }; cmdDeleteMod.Enabled = false; string strSelectedModId = treMods.SelectedNode?.Tag.ToString(); string strSpaceCharacter = LanguageManager.GetString("String_Space", GlobalOptions.Language); if (!string.IsNullOrEmpty(strSelectedModId) && strSelectedModId.IsGuid()) { VehicleMod objMod = _lstMods.FirstOrDefault(x => x.InternalId == strSelectedModId); if (objMod != null) { cmdDeleteMod.Enabled = !objMod.IncludedInVehicle; lblSlots.Text = objMod.CalculatedSlots.ToString(); lblAvailability.Text = objMod.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.Language); if (chkFreeItem.Checked) { lblCost.Text = (0.0m).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥'; } else { int intTotalSlots = Convert.ToInt32(xmlSelectedMount?["slots"]?.InnerText); 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) { intTotalSlots += Convert.ToInt32(xmlLoopNode["slots"]?.InnerText); } } } foreach (VehicleMod objLoopMod in _lstMods) { intTotalSlots += objLoopMod.CalculatedSlots; } lblCost.Text = (objMod.TotalCostInMountCreation(intTotalSlots) * (1 + (nudMarkup.Value / 100.0m))).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥'; } objMod.SetSourceDetail(lblSource); lblCostLabel.Visible = !string.IsNullOrEmpty(lblCost.Text); lblSlotsLabel.Visible = !string.IsNullOrEmpty(lblSlots.Text); lblAvailabilityLabel.Visible = !string.IsNullOrEmpty(lblAvailability.Text); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); return; } } if (xmlSelectedMount == null) { lblCost.Text = string.Empty; lblSlots.Text = string.Empty; lblAvailability.Text = string.Empty; lblCostLabel.Visible = false; lblSlotsLabel.Visible = false; lblAvailabilityLabel.Visible = false; return; } decimal decCost = !chkFreeItem.Checked ? Convert.ToDecimal(xmlSelectedMount["cost"]?.InnerText, GlobalOptions.InvariantCultureInfo) : 0; int intSlots = Convert.ToInt32(xmlSelectedMount["slots"]?.InnerText); string strAvail = xmlSelectedMount["avail"]?.InnerText ?? string.Empty; char chrAvailSuffix = strAvail.Length > 0 ? strAvail[strAvail.Length - 1] : ' '; if (chrAvailSuffix == 'F' || chrAvailSuffix == 'R') { strAvail = strAvail.Substring(0, strAvail.Length - 1); } else { chrAvailSuffix = ' '; } int intAvail = Convert.ToInt32(strAvail); 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) { if (!chkFreeItem.Checked) { decCost += Convert.ToInt32(xmlLoopNode["cost"]?.InnerText); } intSlots += Convert.ToInt32(xmlLoopNode["slots"]?.InnerText); string strLoopAvail = xmlLoopNode["avail"]?.InnerText ?? string.Empty; char chrLoopAvailSuffix = strLoopAvail.Length > 0 ? strLoopAvail[strLoopAvail.Length - 1] : ' '; if (chrLoopAvailSuffix == 'F') { strLoopAvail = strLoopAvail.Substring(0, strLoopAvail.Length - 1); chrAvailSuffix = 'F'; } else if (chrLoopAvailSuffix == 'R') { strLoopAvail = strLoopAvail.Substring(0, strLoopAvail.Length - 1); if (chrAvailSuffix == ' ') { chrAvailSuffix = 'R'; } } intAvail += Convert.ToInt32(strLoopAvail); } } } foreach (VehicleMod objMod in _lstMods) { intSlots += objMod.CalculatedSlots; AvailabilityValue objLoopAvail = objMod.TotalAvailTuple(); char chrLoopAvailSuffix = objLoopAvail.Suffix; if (chrLoopAvailSuffix == 'F') { chrAvailSuffix = 'F'; } else if (chrAvailSuffix != 'F' && chrLoopAvailSuffix == 'R') { chrAvailSuffix = 'R'; } intAvail += objLoopAvail.Value; } if (!chkFreeItem.Checked) { foreach (VehicleMod objMod in _lstMods) { decCost += objMod.TotalCostInMountCreation(intSlots); } } string strAvailText = intAvail.ToString(GlobalOptions.CultureInfo); if (chrAvailSuffix == 'F') { strAvailText += LanguageManager.GetString("String_AvailForbidden", GlobalOptions.Language); } else if (chrAvailSuffix == 'R') { strAvailText += LanguageManager.GetString("String_AvailRestricted", GlobalOptions.Language); } decCost *= 1 + (nudMarkup.Value / 100.0m); lblCost.Text = decCost.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥'; lblSlots.Text = intSlots.ToString(); lblAvailability.Text = strAvailText; lblCostLabel.Visible = !string.IsNullOrEmpty(lblCost.Text); lblSlotsLabel.Visible = !string.IsNullOrEmpty(lblSlots.Text); lblAvailabilityLabel.Visible = !string.IsNullOrEmpty(lblAvailability.Text); string strSource = xmlSelectedMount["source"]?.InnerText ?? LanguageManager.GetString("String_Unknown", GlobalOptions.Language); string strPage = xmlSelectedMount["altpage"]?.InnerText ?? xmlSelectedMount["page"]?.InnerText ?? LanguageManager.GetString("String_Unknown", GlobalOptions.Language); lblSource.Text = CommonFunctions.LanguageBookShort(strSource, GlobalOptions.Language) + strSpaceCharacter + strPage; lblSource.SetToolTip(CommonFunctions.LanguageBookLong(strSource, GlobalOptions.Language) + strSpaceCharacter + LanguageManager.GetString("String_Page", GlobalOptions.Language) + strSpaceCharacter + strPage); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); }
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); 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); } 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(); _objFunctions.DeleteVehicleGear(objGear, treVehicles, objFoundVehicle); } } 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(); }
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); }
private void tsVehicleAddWeaponWeapon_Click(object sender, EventArgs e) { VehicleMod objMod = new VehicleMod(_objCharacter); // Make sure that a Weapon Mount has been selected. try { // Attempt to locate the selected VehicleMod. Vehicle objFoundVehicle = new Vehicle(_objCharacter); objMod = _objFunctions.FindVehicleMod(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle); if (!objMod.Name.StartsWith("Weapon Mount") && !objMod.Name.StartsWith("Heavy Weapon Mount") && !objMod.Name.StartsWith("Mechanical Arm")) { MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotAddWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotAddWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch { MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotAddWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotAddWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } frmSelectWeapon frmPickWeapon = new frmSelectWeapon(_objCharacter); frmPickWeapon.ShowDialog(); 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, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponMod); objWeapon.VehicleMounted = true; objMod.Weapons.Add(objWeapon); objNode.ContextMenuStrip = cmsVehicleWeapon; treVehicles.SelectedNode.Nodes.Add(objNode); treVehicles.SelectedNode.Expand(); if (frmPickWeapon.AddAgain) tsVehicleAddWeaponWeapon_Click(sender, e); UpdateCharacterInfo(); }
public void CreateAllVehicleModsTest() { // Create a new Human character. Character objCharacter = new Character(); objCharacter.LoadMetatype(Guid.Parse("e28e7075-f635-4c02-937c-e4fc61c51602")); TreeNode objNode = new TreeNode(); XmlDocument objXmlDocument = XmlManager.Instance.Load("vehicles.xml"); foreach (XmlNode objXmlNode in objXmlDocument.SelectNodes("/chummer/mods/mod")) { VehicleMod objMod = new VehicleMod(objCharacter); objMod.Create(objXmlNode, objNode, 1); } }