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(); }
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); }