Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 135.76 KB | None | 0 0
  1. private bool ProcessBonus(Improvement.ImprovementSource objImprovementSource, ref string strSourceName,
  2.             bool blnConcatSelectedValue,
  3.             int intRating, string strFriendlyName, XmlNode bonusNode, string strUnique)
  4.         {
  5.             Log.Info("Has Child Nodes");
  6.             // Add an Attribute.
  7.             if (bonusNode.LocalName == ("addattribute"))
  8.             {
  9.                 Log.Info("addattribute");
  10.                 if (bonusNode["name"].InnerText == "MAG")
  11.                 {
  12.                     _objCharacter.MAGEnabled = true;
  13.                     Log.Info("Calling CreateImprovement for MAG");
  14.                     CreateImprovement("MAG", objImprovementSource, strSourceName, Improvement.ImprovementType.Attribute,
  15.                         "enableattribute", 0, 0);
  16.                 }
  17.                 else if (bonusNode["name"].InnerText == "RES")
  18.                 {
  19.                     _objCharacter.RESEnabled = true;
  20.                     Log.Info("Calling CreateImprovement for RES");
  21.                     CreateImprovement("RES", objImprovementSource, strSourceName, Improvement.ImprovementType.Attribute,
  22.                         "enableattribute", 0, 0);
  23.                 }
  24.             }
  25.             // Add an Attribute Replacement.
  26.             if (bonusNode.LocalName == ("replaceattributes"))
  27.             {
  28.                 XmlNodeList objXmlAttributes = bonusNode.SelectNodes("replaceattribute");
  29.                 if (objXmlAttributes != null)
  30.                     foreach (XmlNode objXmlAttribute in objXmlAttributes)
  31.                     {
  32.                         Log.Info("replaceattribute");
  33.                         Log.Info("replaceattribute = " + bonusNode.OuterXml.ToString());
  34.                         // Record the improvement.
  35.                         int intMin = 0;
  36.                         int intMax = 0;
  37.  
  38.                         // Extract the modifiers.
  39.                         if (objXmlAttribute.InnerXml.Contains("min"))
  40.                             intMin = Convert.ToInt32(objXmlAttribute["min"].InnerText);
  41.                         if (objXmlAttribute.InnerXml.Contains("max"))
  42.                             intMax = Convert.ToInt32(objXmlAttribute["max"].InnerText);
  43.                         string strAttribute = objXmlAttribute["name"].InnerText;
  44.  
  45.                         Log.Info("Calling CreateImprovement");
  46.                         CreateImprovement(strAttribute, objImprovementSource, strSourceName, Improvement.ImprovementType.ReplaceAttribute,
  47.                             strUnique,
  48.                             0, 1, intMin, intMax, 0, 0);
  49.                     }
  50.             }
  51.  
  52.             // Enable a special tab.
  53.             if (bonusNode.LocalName == ("enabletab"))
  54.             {
  55.                 Log.Info("enabletab");
  56.                 foreach (XmlNode objXmlEnable in bonusNode.ChildNodes)
  57.                 {
  58.                     switch (objXmlEnable.InnerText)
  59.                     {
  60.                         case "magician":
  61.                             _objCharacter.MagicianEnabled = true;
  62.                             Log.Info("magician");
  63.                             CreateImprovement("Magician", objImprovementSource, strSourceName, Improvement.ImprovementType.SpecialTab,
  64.                                 "enabletab", 0, 0);
  65.                             break;
  66.                         case "adept":
  67.                             _objCharacter.AdeptEnabled = true;
  68.                             Log.Info("adept");
  69.                             CreateImprovement("Adept", objImprovementSource, strSourceName, Improvement.ImprovementType.SpecialTab,
  70.                                 "enabletab",
  71.                                 0, 0);
  72.                             break;
  73.                         case "technomancer":
  74.                             _objCharacter.TechnomancerEnabled = true;
  75.                             Log.Info("technomancer");
  76.                             CreateImprovement("Technomancer", objImprovementSource, strSourceName, Improvement.ImprovementType.SpecialTab,
  77.                                 "enabletab", 0, 0);
  78.                             break;
  79.                         case "critter":
  80.                             _objCharacter.CritterEnabled = true;
  81.                             Log.Info("critter");
  82.                             CreateImprovement("Critter", objImprovementSource, strSourceName, Improvement.ImprovementType.SpecialTab,
  83.                                 "enabletab", 0, 0);
  84.                             break;
  85.                         case "initiation":
  86.                             _objCharacter.InitiationEnabled = true;
  87.                             Log.Info("initiation");
  88.                             CreateImprovement("Initiation", objImprovementSource, strSourceName, Improvement.ImprovementType.SpecialTab,
  89.                                 "enabletab", 0, 0);
  90.                             break;
  91.                     }
  92.                 }
  93.             }
  94.  
  95.             // Select Restricted (select Restricted items for Fake Licenses).
  96.             if (bonusNode.LocalName == ("selectrestricted"))
  97.             {
  98.                 Log.Info("selectrestricted");
  99.                 frmSelectItem frmPickItem = new frmSelectItem();
  100.                 frmPickItem.Character = _objCharacter;
  101.                 if (_strForcedValue != string.Empty)
  102.                     frmPickItem.ForceItem = _strForcedValue;
  103.                 frmPickItem.AllowAutoSelect = false;
  104.                 frmPickItem.ShowDialog();
  105.  
  106.                 // Make sure the dialogue window was not canceled.
  107.                 if (frmPickItem.DialogResult == DialogResult.Cancel)
  108.                 {
  109.                     Rollback();
  110.                     _strForcedValue = "";
  111.                     _strLimitSelection = "";
  112.                     return false;
  113.                 }
  114.  
  115.                 _strSelectedValue = frmPickItem.SelectedItem;
  116.                 if (blnConcatSelectedValue)
  117.                     strSourceName += " (" + _strSelectedValue + ")";
  118.  
  119.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  120.                 Log.Info("strSourceName = " + strSourceName);
  121.  
  122.                 // Create the Improvement.
  123.                 Log.Info("Calling CreateImprovement");
  124.                 CreateImprovement(frmPickItem.SelectedItem, objImprovementSource, strSourceName,
  125.                     Improvement.ImprovementType.Restricted, strUnique);
  126.             }
  127.  
  128.             if (bonusNode.LocalName == "cyberseeker")
  129.             {
  130.                 //Check if valid attrib
  131.                 if (new string[] {"BOD", "AGI", "STR", "REA", "LOG", "CHA", "INT", "WIL", "BOX"}.Any(x => x == bonusNode.InnerText))
  132.                 {
  133.                     CreateImprovement(bonusNode.InnerText, objImprovementSource, strSourceName, Improvement.ImprovementType.Seeker, strUnique,0,0,0,0,0,0);
  134.  
  135.                 }
  136.                 else
  137.                 {
  138.                     Utils.BreakIfDebug();
  139.                 }
  140.  
  141.             }
  142.  
  143.             // Select a Skill.
  144.             if (bonusNode.LocalName == ("selectskill"))
  145.             {
  146.                 //TODO this don't work
  147.                 Log.Info("selectskill");
  148.                 if (_strForcedValue == "+2 to a Combat Skill")
  149.                     _strForcedValue = "";
  150.  
  151.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  152.                 Log.Info("_strForcedValue = " + _strForcedValue);
  153.  
  154.                 // Display the Select Skill window and record which Skill was selected.
  155.                 frmSelectSkill frmPickSkill = new frmSelectSkill(_objCharacter);
  156.                 if (strFriendlyName != "")
  157.                     frmPickSkill.Description = LanguageManager.Instance.GetString("String_Improvement_SelectSkillNamed")
  158.                         .Replace("{0}", strFriendlyName);
  159.                 else
  160.                     frmPickSkill.Description = LanguageManager.Instance.GetString("String_Improvement_SelectSkill");
  161.  
  162.                 Log.Info("selectskill = " + bonusNode.OuterXml.ToString());
  163.                 if (bonusNode.OuterXml.Contains("skillgroup"))
  164.                     frmPickSkill.OnlySkillGroup = bonusNode.Attributes["skillgroup"].InnerText;
  165.                 else if (bonusNode.OuterXml.Contains("skillcategory"))
  166.                     frmPickSkill.OnlyCategory = bonusNode.Attributes["skillcategory"].InnerText;
  167.                 else if (bonusNode.OuterXml.Contains("excludecategory"))
  168.                     frmPickSkill.ExcludeCategory = bonusNode.Attributes["excludecategory"].InnerText;
  169.                 else if (bonusNode.OuterXml.Contains("limittoskill"))
  170.                     frmPickSkill.LimitToSkill = bonusNode.Attributes["limittoskill"].InnerText;
  171.                 else if (bonusNode.OuterXml.Contains("limittoattribute"))
  172.                     frmPickSkill.LinkedAttribute = bonusNode.Attributes["limittoattribute"].InnerText;
  173.  
  174.                 if (_strForcedValue != "")
  175.                 {
  176.                     frmPickSkill.OnlySkill = _strForcedValue;
  177.                     frmPickSkill.Opacity = 0;
  178.                 }
  179.                 frmPickSkill.ShowDialog();
  180.  
  181.                 // Make sure the dialogue window was not canceled.
  182.                 if (frmPickSkill.DialogResult == DialogResult.Cancel)
  183.                 {
  184.                     Rollback();
  185.                     _strForcedValue = "";
  186.                     _strLimitSelection = "";
  187.                     return false;
  188.                 }
  189.  
  190.                 bool blnAddToRating = false;
  191.                 if (bonusNode["applytorating"] != null)
  192.                 {
  193.                     if (bonusNode["applytorating"].InnerText == "yes")
  194.                         blnAddToRating = true;
  195.                 }
  196.  
  197.                 _strSelectedValue = frmPickSkill.SelectedSkill;
  198.                 if (blnConcatSelectedValue)
  199.                     strSourceName += " (" + _strSelectedValue + ")";
  200.  
  201.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  202.                 Log.Info("strSourceName = " + strSourceName);
  203.  
  204.                 // Find the selected Skill.
  205.                 foreach (Skill objSkill in _objCharacter.SkillsSection.Skills)
  206.                 {
  207.                     if (frmPickSkill.SelectedSkill.Contains("Exotic Melee Weapon") ||
  208.                         frmPickSkill.SelectedSkill.Contains("Exotic Ranged Weapon") ||
  209.                         frmPickSkill.SelectedSkill.Contains("Pilot Exotic Vehicle"))
  210.                     {
  211.                         if (objSkill.Name + " (" + objSkill.Specialization + ")" == frmPickSkill.SelectedSkill)
  212.                         {
  213.                             // We've found the selected Skill.
  214.                             if (bonusNode.InnerXml.Contains("val"))
  215.                             {
  216.                                 Log.Info("Calling CreateImprovement");
  217.                                 CreateImprovement(objSkill.Name + " (" + objSkill.Specialization + ")", objImprovementSource, strSourceName,
  218.                                     Improvement.ImprovementType.Skill, strUnique, ValueToInt(bonusNode["val"].InnerText, intRating), 1,
  219.                                     0, 0, 0, 0, "", blnAddToRating);
  220.                             }
  221.  
  222.                             if (bonusNode.InnerXml.Contains("max"))
  223.                             {
  224.                                 Log.Info("Calling CreateImprovement");
  225.                                 CreateImprovement(objSkill.Name + " (" + objSkill.Specialization + ")", objImprovementSource, strSourceName,
  226.                                     Improvement.ImprovementType.Skill, strUnique, 0, 1, 0,
  227.                                     ValueToInt(bonusNode["max"].InnerText, intRating), 0, 0, "", blnAddToRating);
  228.                             }
  229.                         }
  230.                     }
  231.                     else
  232.                     {
  233.                         if (objSkill.Name == frmPickSkill.SelectedSkill)
  234.                         {
  235.                             // We've found the selected Skill.
  236.                             if (bonusNode.InnerXml.Contains("val"))
  237.                             {
  238.                                 Log.Info("Calling CreateImprovement");
  239.                                 CreateImprovement(objSkill.Name, objImprovementSource, strSourceName, Improvement.ImprovementType.Skill,
  240.                                     strUnique,
  241.                                     ValueToInt(bonusNode["val"].InnerText, intRating), 1, 0, 0, 0, 0, "", blnAddToRating);
  242.                             }
  243.  
  244.                             if (bonusNode.InnerXml.Contains("max"))
  245.                             {
  246.                                 Log.Info("Calling CreateImprovement");
  247.                                 CreateImprovement(objSkill.Name, objImprovementSource, strSourceName, Improvement.ImprovementType.Skill,
  248.                                     strUnique,
  249.                                     0, 1, 0, ValueToInt(bonusNode["max"].InnerText, intRating), 0, 0, "", blnAddToRating);
  250.                             }
  251.                         }
  252.                     }
  253.                 }
  254.             }
  255.  
  256.             // Select a Skill Group.
  257.             if (bonusNode.LocalName == ("selectskillgroup"))
  258.             {
  259.                 Log.Info("selectskillgroup");
  260.                 string strExclude = "";
  261.                 if (bonusNode.Attributes["excludecategory"] != null)
  262.                     strExclude = bonusNode.Attributes["excludecategory"].InnerText;
  263.  
  264.                 frmSelectSkillGroup frmPickSkillGroup = new frmSelectSkillGroup();
  265.                 if (strFriendlyName != "")
  266.                     frmPickSkillGroup.Description =
  267.                         LanguageManager.Instance.GetString("String_Improvement_SelectSkillGroupName").Replace("{0}", strFriendlyName);
  268.                 else
  269.                     frmPickSkillGroup.Description = LanguageManager.Instance.GetString("String_Improvement_SelectSkillGroup");
  270.  
  271.                 Log.Info("_strForcedValue = " + _strForcedValue);
  272.                 Log.Info("_strLimitSelection = " + _strLimitSelection);
  273.  
  274.                 if (_strForcedValue != "")
  275.                 {
  276.                     frmPickSkillGroup.OnlyGroup = _strForcedValue;
  277.                     frmPickSkillGroup.Opacity = 0;
  278.                 }
  279.  
  280.                 if (strExclude != string.Empty)
  281.                     frmPickSkillGroup.ExcludeCategory = strExclude;
  282.  
  283.                 frmPickSkillGroup.ShowDialog();
  284.  
  285.                 // Make sure the dialogue window was not canceled.
  286.                 if (frmPickSkillGroup.DialogResult == DialogResult.Cancel)
  287.                 {
  288.                     Rollback();
  289.  
  290.                     _strForcedValue = "";
  291.                     _strLimitSelection = "";
  292.                     return false;
  293.                 }
  294.  
  295.                 bool blnAddToRating = false;
  296.                 if (bonusNode["applytorating"] != null)
  297.                 {
  298.                     if (bonusNode["applytorating"].InnerText == "yes")
  299.                         blnAddToRating = true;
  300.                 }
  301.  
  302.                 _strSelectedValue = frmPickSkillGroup.SelectedSkillGroup;
  303.  
  304.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  305.                 Log.Info("strSourceName = " + strSourceName);
  306.  
  307.                 if (bonusNode.SelectSingleNode("bonus") != null)
  308.                 {
  309.                     Log.Info("Calling CreateImprovement");
  310.                     CreateImprovement(_strSelectedValue, objImprovementSource, strSourceName, Improvement.ImprovementType.SkillGroup,
  311.                         strUnique, ValueToInt(bonusNode["bonus"].InnerText, intRating), 1, 0, 0, 0, 0, strExclude,
  312.                         blnAddToRating);
  313.                 }
  314.                 else
  315.                 {
  316.                     Log.Info("Calling CreateImprovement");
  317.                     CreateImprovement(_strSelectedValue, objImprovementSource, strSourceName, Improvement.ImprovementType.SkillGroup,
  318.                         strUnique, 0, 0, 0, 1, 0, 0, strExclude,
  319.                         blnAddToRating);
  320.                 }
  321.             }
  322.  
  323.             if (bonusNode.LocalName == ("selectattributes"))
  324.             {
  325.                 foreach (XmlNode objXmlAttribute in bonusNode.SelectNodes("selectattribute"))
  326.                 {
  327.                     Log.Info("selectattribute");
  328.                     // Display the Select Attribute window and record which Skill was selected.
  329.                     frmSelectAttribute frmPickAttribute = new frmSelectAttribute();
  330.                     if (strFriendlyName != "")
  331.                         frmPickAttribute.Description =
  332.                             LanguageManager.Instance.GetString("String_Improvement_SelectAttributeNamed").Replace("{0}", strFriendlyName);
  333.                     else
  334.                         frmPickAttribute.Description = LanguageManager.Instance.GetString("String_Improvement_SelectAttribute");
  335.  
  336.                     // Add MAG and/or RES to the list of Attributes if they are enabled on the form.
  337.                     if (_objCharacter.MAGEnabled)
  338.                         frmPickAttribute.AddMAG();
  339.                     if (_objCharacter.RESEnabled)
  340.                         frmPickAttribute.AddRES();
  341.  
  342.                     Log.Info("selectattribute = " + bonusNode.OuterXml.ToString());
  343.  
  344.                     if (objXmlAttribute.InnerXml.Contains("<attribute>"))
  345.                     {
  346.                         List<string> strValue = new List<string>();
  347.                         foreach (XmlNode objSubNode in objXmlAttribute.SelectNodes("attribute"))
  348.                             strValue.Add(objSubNode.InnerText);
  349.                         frmPickAttribute.LimitToList(strValue);
  350.                     }
  351.  
  352.                     if (bonusNode.InnerXml.Contains("<excludeattribute>"))
  353.                     {
  354.                         List<string> strValue = new List<string>();
  355.                         foreach (XmlNode objSubNode in objXmlAttribute.SelectNodes("excludeattribute"))
  356.                             strValue.Add(objSubNode.InnerText);
  357.                         frmPickAttribute.RemoveFromList(strValue);
  358.                     }
  359.  
  360.                     // Check to see if there is only one possible selection because of _strLimitSelection.
  361.                     if (_strForcedValue != "")
  362.                         _strLimitSelection = _strForcedValue;
  363.  
  364.                     Log.Info("_strForcedValue = " + _strForcedValue);
  365.                     Log.Info("_strLimitSelection = " + _strLimitSelection);
  366.  
  367.                     if (_strLimitSelection != "")
  368.                     {
  369.                         frmPickAttribute.SingleAttribute(_strLimitSelection);
  370.                         frmPickAttribute.Opacity = 0;
  371.                     }
  372.  
  373.                     frmPickAttribute.ShowDialog();
  374.  
  375.                     // Make sure the dialogue window was not canceled.
  376.                     if (frmPickAttribute.DialogResult == DialogResult.Cancel)
  377.                     {
  378.                         Rollback();
  379.                         _strForcedValue = "";
  380.                         return false;
  381.                     }
  382.  
  383.                     _strSelectedValue = frmPickAttribute.SelectedAttribute;
  384.                     if (blnConcatSelectedValue)
  385.                         strSourceName += " (" + _strSelectedValue + ")";
  386.  
  387.                     Log.Info("_strSelectedValue = " + _strSelectedValue);
  388.                     Log.Info("strSourceName = " + strSourceName);
  389.  
  390.                     // Record the improvement.
  391.                     int intMin = 0;
  392.                     int intAug = 0;
  393.                     int intMax = 0;
  394.                     int intAugMax = 0;
  395.  
  396.                     // Extract the modifiers.
  397.                     if (objXmlAttribute.InnerXml.Contains("min"))
  398.                         intMin = Convert.ToInt32(objXmlAttribute["min"].InnerText);
  399.                     if (objXmlAttribute.InnerXml.Contains("val"))
  400.                         intAug = Convert.ToInt32(objXmlAttribute["val"].InnerText);
  401.                     if (objXmlAttribute.InnerXml.Contains("max"))
  402.                         intMax = Convert.ToInt32(objXmlAttribute["max"].InnerText);
  403.                     if (objXmlAttribute.InnerXml.Contains("aug"))
  404.                         intAugMax = Convert.ToInt32(objXmlAttribute["aug"].InnerText);
  405.  
  406.                     string strAttribute = frmPickAttribute.SelectedAttribute;
  407.  
  408. if (objXmlAttribute["affectbase"] != null)
  409.                         strAttribute += "Base";
  410.  
  411.                     Log.Info("Calling CreateImprovement");
  412.                     CreateImprovement(strAttribute, objImprovementSource, strSourceName, Improvement.ImprovementType.Attribute,
  413.                         strUnique,
  414.                         0, 1, intMin, intMax, intAug, intAugMax);
  415.                 }
  416.             }
  417.  
  418.             // Select an CharacterAttribute.
  419.             if (bonusNode.LocalName == ("selectattribute"))
  420.             {
  421.                 Log.Info("selectattribute");
  422.                 // Display the Select Attribute window and record which Skill was selected.
  423.                 frmSelectAttribute frmPickAttribute = new frmSelectAttribute();
  424.                 if (strFriendlyName != "")
  425.                     frmPickAttribute.Description =
  426.                         LanguageManager.Instance.GetString("String_Improvement_SelectAttributeNamed").Replace("{0}", strFriendlyName);
  427.                 else
  428.                     frmPickAttribute.Description = LanguageManager.Instance.GetString("String_Improvement_SelectAttribute");
  429.  
  430.                 // Add MAG and/or RES to the list of Attributes if they are enabled on the form.
  431.                 if (_objCharacter.MAGEnabled)
  432.                     frmPickAttribute.AddMAG();
  433.                 if (_objCharacter.RESEnabled)
  434.                     frmPickAttribute.AddRES();
  435.  
  436.                 Log.Info("selectattribute = " + bonusNode.OuterXml.ToString());
  437.  
  438.                 if (bonusNode.InnerXml.Contains("<attribute>"))
  439.                 {
  440.                     List<string> strValue = new List<string>();
  441.                     foreach (XmlNode objXmlAttribute in bonusNode.SelectNodes("attribute"))
  442.                         strValue.Add(objXmlAttribute.InnerText);
  443.                     frmPickAttribute.LimitToList(strValue);
  444.                 }
  445.  
  446.                 if (bonusNode.InnerXml.Contains("<excludeattribute>"))
  447.                 {
  448.                     List<string> strValue = new List<string>();
  449.                     foreach (XmlNode objXmlAttribute in bonusNode.SelectNodes("excludeattribute"))
  450.                         strValue.Add(objXmlAttribute.InnerText);
  451.                     frmPickAttribute.RemoveFromList(strValue);
  452.                 }
  453.  
  454.                 // Check to see if there is only one possible selection because of _strLimitSelection.
  455.                 if (_strForcedValue != "")
  456.                     _strLimitSelection = _strForcedValue;
  457.  
  458.                 Log.Info("_strForcedValue = " + _strForcedValue);
  459.                 Log.Info("_strLimitSelection = " + _strLimitSelection);
  460.  
  461.                 if (_strLimitSelection != "")
  462.                 {
  463.                     frmPickAttribute.SingleAttribute(_strLimitSelection);
  464.                     frmPickAttribute.Opacity = 0;
  465.                 }
  466.  
  467.                 frmPickAttribute.ShowDialog();
  468.  
  469.                 // Make sure the dialogue window was not canceled.
  470.                 if (frmPickAttribute.DialogResult == DialogResult.Cancel)
  471.                 {
  472.                     Rollback();
  473.                     _strForcedValue = "";
  474.                     return false;
  475.                 }
  476.  
  477.                 _strSelectedValue = frmPickAttribute.SelectedAttribute;
  478.                 if (blnConcatSelectedValue)
  479.                     strSourceName += " (" + _strSelectedValue + ")";
  480.  
  481.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  482.                 Log.Info("strSourceName = " + strSourceName);
  483.  
  484.                 // Record the improvement.
  485.                 int intMin = 0;
  486.                 int intAug = 0;
  487.                 int intMax = 0;
  488.                 int intAugMax = 0;
  489.  
  490.                 // Extract the modifiers.
  491.                 if (bonusNode.InnerXml.Contains("min"))
  492.                     intMin = ValueToInt(bonusNode["min"].InnerXml, intRating);
  493.                 if (bonusNode.InnerXml.Contains("val"))
  494.                     intAug = ValueToInt(bonusNode["val"].InnerXml, intRating);
  495.                 if (bonusNode.InnerXml.Contains("max"))
  496.                     intMax = ValueToInt(bonusNode["max"].InnerXml, intRating);
  497.                 if (bonusNode.InnerXml.Contains("aug"))
  498.                     intAugMax = ValueToInt(bonusNode["aug"].InnerXml, intRating);
  499.  
  500.                 string strAttribute = frmPickAttribute.SelectedAttribute;
  501.  
  502.                 if (bonusNode["affectbase"] != null)
  503.                     strAttribute += "Base";
  504.  
  505.                 Log.Info("Calling CreateImprovement");
  506.                 CreateImprovement(strAttribute, objImprovementSource, strSourceName, Improvement.ImprovementType.Attribute,
  507.                     strUnique,
  508.                     0, 1, intMin, intMax, intAug, intAugMax);
  509.             }
  510.  
  511.             // Select a Limit.
  512.             if (bonusNode.LocalName == ("selectlimit"))
  513.             {
  514.                 Log.Info("selectlimit");
  515.                 // Display the Select Limit window and record which Limit was selected.
  516.                 frmSelectLimit frmPickLimit = new frmSelectLimit();
  517.                 if (strFriendlyName != "")
  518.                     frmPickLimit.Description = LanguageManager.Instance.GetString("String_Improvement_SelectLimitNamed")
  519.                         .Replace("{0}", strFriendlyName);
  520.                 else
  521.                     frmPickLimit.Description = LanguageManager.Instance.GetString("String_Improvement_SelectLimit");
  522.  
  523.                 Log.Info("selectlimit = " + bonusNode.OuterXml.ToString());
  524.  
  525.                 if (bonusNode.InnerXml.Contains("<limit>"))
  526.                 {
  527.                     List<string> strValue = new List<string>();
  528.                     foreach (XmlNode objXmlAttribute in bonusNode.SelectNodes("limit"))
  529.                         strValue.Add(objXmlAttribute.InnerText);
  530.                     frmPickLimit.LimitToList(strValue);
  531.                 }
  532.  
  533.                 if (bonusNode.InnerXml.Contains("<excludelimit>"))
  534.                 {
  535.                     List<string> strValue = new List<string>();
  536.                     foreach (XmlNode objXmlAttribute in bonusNode.SelectNodes("excludelimit"))
  537.                         strValue.Add(objXmlAttribute.InnerText);
  538.                     frmPickLimit.RemoveFromList(strValue);
  539.                 }
  540.  
  541.                 // Check to see if there is only one possible selection because of _strLimitSelection.
  542.                 if (_strForcedValue != "")
  543.                     _strLimitSelection = _strForcedValue;
  544.  
  545.                 Log.Info("_strForcedValue = " + _strForcedValue);
  546.                 Log.Info("_strLimitSelection = " + _strLimitSelection);
  547.  
  548.                 if (_strLimitSelection != "")
  549.                 {
  550.                     frmPickLimit.SingleLimit(_strLimitSelection);
  551.                     frmPickLimit.Opacity = 0;
  552.                 }
  553.  
  554.                 frmPickLimit.ShowDialog();
  555.  
  556.                 // Make sure the dialogue window was not canceled.
  557.                 if (frmPickLimit.DialogResult == DialogResult.Cancel)
  558.                 {
  559.                     Rollback();
  560.                     _strForcedValue = "";
  561.                     return false;
  562.                 }
  563.  
  564.                 _strSelectedValue = frmPickLimit.SelectedLimit;
  565.                 if (blnConcatSelectedValue)
  566.                     strSourceName += " (" + _strSelectedValue + ")";
  567.  
  568.                 // Record the improvement.
  569.                 int intMin = 0;
  570.                 int intAug = 0;
  571.                 int intMax = 0;
  572.                 int intAugMax = 0;
  573.  
  574.                 // Extract the modifiers.
  575.                 if (bonusNode.InnerXml.Contains("min"))
  576.                     intMin = ValueToInt(bonusNode["min"].InnerXml, intRating);
  577.                 if (bonusNode.InnerXml.Contains("val"))
  578.                     intAug = ValueToInt(bonusNode["val"].InnerXml, intRating);
  579.                 if (bonusNode.InnerXml.Contains("max"))
  580.                     intMax = ValueToInt(bonusNode["max"].InnerXml, intRating);
  581.                 if (bonusNode.InnerXml.Contains("aug"))
  582.                     intAugMax = ValueToInt(bonusNode["aug"].InnerXml, intRating);
  583.  
  584.                 string strLimit = frmPickLimit.SelectedLimit;
  585.  
  586.                 if (bonusNode["affectbase"] != null)
  587.                     strLimit += "Base";
  588.  
  589.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  590.                 Log.Info("strSourceName = " + strSourceName);
  591.  
  592.                 LimitModifier objLimitMod = new LimitModifier(_objCharacter);
  593.                 // string strBonus = bonusNode["value"].InnerText;
  594.                 int intBonus = intAug;
  595.                 string strName = strFriendlyName;
  596.                 TreeNode nodTemp = new TreeNode();
  597.                 Improvement.ImprovementType objType = Improvement.ImprovementType.PhysicalLimit;
  598.  
  599.                 switch (strLimit)
  600.                 {
  601.                     case "Mental":
  602.                         {
  603.                             objType = Improvement.ImprovementType.MentalLimit;
  604.                             break;
  605.                         }
  606.                     case "Social":
  607.                         {
  608.                             objType = Improvement.ImprovementType.SocialLimit;
  609.                             break;
  610.                         }
  611.                     default:
  612.                         {
  613.                             objType = Improvement.ImprovementType.PhysicalLimit;
  614.                             break;
  615.                         }
  616.                 }
  617.  
  618.                 Log.Info("Calling CreateImprovement");
  619.                 CreateImprovement(strLimit, objImprovementSource, strSourceName, objType, strFriendlyName, intBonus, 0, intMin,
  620.                     intMax,
  621.                     intAug, intAugMax);
  622.             }
  623.  
  624.             // Select an CharacterAttribute to use instead of the default on a skill.
  625.             if (bonusNode.LocalName == ("swapskillattribute"))
  626.             {
  627.                 Log.Info("swapskillattribute");
  628.                 // Display the Select Attribute window and record which Skill was selected.
  629.                 frmSelectAttribute frmPickAttribute = new frmSelectAttribute();
  630.                 if (strFriendlyName != "")
  631.                     frmPickAttribute.Description =
  632.                         LanguageManager.Instance.GetString("String_Improvement_SelectAttributeNamed").Replace("{0}", strFriendlyName);
  633.                 else
  634.                     frmPickAttribute.Description = LanguageManager.Instance.GetString("String_Improvement_SelectAttribute");
  635.  
  636.                 List<string> strValue = new List<string>();
  637.                 strValue.Add("LOG");
  638.                 strValue.Add("WIL");
  639.                 strValue.Add("INT");
  640.                 strValue.Add("CHA");
  641.                 strValue.Add("EDG");
  642.                 strValue.Add("MAG");
  643.                 strValue.Add("RES");
  644.                 frmPickAttribute.RemoveFromList(strValue);
  645.  
  646.                 Log.Info("swapskillattribute = " + bonusNode.OuterXml.ToString());
  647.  
  648.                 if (bonusNode.InnerXml.Contains("<attribute>"))
  649.                 {
  650.                     List<string> strLimitValue = new List<string>();
  651.                     foreach (XmlNode objXmlAttribute in bonusNode.SelectNodes("attribute"))
  652.                         strLimitValue.Add(objXmlAttribute.InnerText);
  653.                     frmPickAttribute.LimitToList(strLimitValue);
  654.                 }
  655.  
  656.                 // Check to see if there is only one possible selection because of _strLimitSelection.
  657.                 if (_strForcedValue != "")
  658.                     _strLimitSelection = _strForcedValue;
  659.  
  660.                 Log.Info("_strForcedValue = " + _strForcedValue);
  661.                 Log.Info("_strLimitSelection = " + _strLimitSelection);
  662.  
  663.                 if (_strLimitSelection != "")
  664.                 {
  665.                     frmPickAttribute.SingleAttribute(_strLimitSelection);
  666.                     frmPickAttribute.Opacity = 0;
  667.                 }
  668.  
  669.                 frmPickAttribute.ShowDialog();
  670.  
  671.                 // Make sure the dialogue window was not canceled.
  672.                 if (frmPickAttribute.DialogResult == DialogResult.Cancel)
  673.                 {
  674.                     Rollback();
  675.                     _strForcedValue = "";
  676.                     _strLimitSelection = "";
  677.                     return false;
  678.                 }
  679.  
  680.                 _strSelectedValue = frmPickAttribute.SelectedAttribute;
  681.                 if (blnConcatSelectedValue)
  682.                     strSourceName += " (" + _strSelectedValue + ")";
  683.  
  684.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  685.                 Log.Info("strSourceName = " + strSourceName);
  686.  
  687.                 Log.Info("Calling CreateImprovement");
  688.                 CreateImprovement(frmPickAttribute.SelectedAttribute, objImprovementSource, strSourceName,
  689.                     Improvement.ImprovementType.SwapSkillAttribute, strUnique);
  690.             }
  691.  
  692.             // Select a Spell.
  693.             if (bonusNode.LocalName == ("selectspell"))
  694.             {
  695.                 Log.Info("selectspell");
  696.                 // Display the Select Spell window.
  697.                 frmSelectSpell frmPickSpell = new frmSelectSpell(_objCharacter);
  698.  
  699.                 if (bonusNode.Attributes["category"] != null)
  700.                     frmPickSpell.LimitCategory = bonusNode.Attributes["category"].InnerText;
  701.  
  702.                 Log.Info("selectspell = " + bonusNode.OuterXml.ToString());
  703.                 Log.Info("_strForcedValue = " + _strForcedValue);
  704.                 Log.Info("_strLimitSelection = " + _strLimitSelection);
  705.  
  706.                 if (_strForcedValue != "")
  707.                 {
  708.                     frmPickSpell.ForceSpellName = _strForcedValue;
  709.                     frmPickSpell.Opacity = 0;
  710.                 }
  711.  
  712.                 if (bonusNode.Attributes["ignorerequirements"] != null)
  713.                 {
  714.                     frmPickSpell.IgnoreRequirements = Convert.ToBoolean(bonusNode.Attributes["ignorerequirements"].InnerText);
  715.                 }
  716.  
  717.                 frmPickSpell.ShowDialog();
  718.  
  719.                 // Make sure the dialogue window was not canceled.
  720.                 if (frmPickSpell.DialogResult == DialogResult.Cancel)
  721.                 {
  722.                     Rollback();
  723.                     _strForcedValue = "";
  724.                     _strLimitSelection = "";
  725.                     return false;
  726.                 }
  727.  
  728.                 _strSelectedValue = frmPickSpell.SelectedSpell;
  729.                 if (blnConcatSelectedValue)
  730.                     strSourceName += " (" + _strSelectedValue + ")";
  731.  
  732.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  733.                 Log.Info("strSourceName = " + strSourceName);
  734.  
  735.                 Log.Info("Calling CreateImprovement");
  736.                 CreateImprovement(frmPickSpell.SelectedSpell, objImprovementSource, strSourceName, Improvement.ImprovementType.Text,
  737.                     strUnique);
  738.             }
  739.  
  740.             // Select a Contact
  741.             if (bonusNode.LocalName == ("selectcontact"))
  742.             {
  743.                 Log.Info("selectcontact");
  744.                 XmlNode nodSelect = bonusNode;
  745.  
  746.                 frmSelectItem frmSelect = new frmSelectItem();
  747.  
  748.                 String strMode = NodeExists(nodSelect, "type")
  749.                     ? nodSelect["type"].InnerText
  750.                     : "all";
  751.  
  752.                 List<Contact> selectedContactsList;
  753.                 if (strMode == "all")
  754.                 {
  755.                     selectedContactsList = new List<Contact>(_objCharacter.Contacts);
  756.                 }
  757.                 else if (strMode == "group" || strMode == "nongroup")
  758.                 {
  759.                     bool blnGroup = strMode == "group";
  760.  
  761.  
  762.                     //Select any contact where IsGroup equals blnGroup
  763.                     //and add to a list
  764.                     selectedContactsList =
  765.                         new List<Contact>(from contact in _objCharacter.Contacts
  766.                             where contact.IsGroup == blnGroup
  767.                             select contact);
  768.                 }
  769.                 else
  770.                 {
  771.                     Rollback();
  772.                     return false;
  773.                 }
  774.  
  775.                 if (selectedContactsList.Count == 0)
  776.                 {
  777.                     MessageBox.Show(LanguageManager.Instance.GetString("Message_NoContactFound"),
  778.                         LanguageManager.Instance.GetString("MessageTitle_NoContactFound"), MessageBoxButtons.OK, MessageBoxIcon.Error);
  779.                     Rollback();
  780.                     return false;
  781.                 }
  782.  
  783.                 int count = 0;
  784.                 //Black magic LINQ to cast content of list to another type
  785.                 List<ListItem> contacts = new List<ListItem>(from x in selectedContactsList
  786.                     select new ListItem() {Name = x.Name, Value = (count++).ToString()});
  787.  
  788.                 String strPrice = NodeExists(nodSelect, "cost")
  789.                     ? nodSelect["cost"].InnerText
  790.                     : "";
  791.  
  792.                 frmSelect.GeneralItems = contacts;
  793.                 frmSelect.ShowDialog();
  794.  
  795.                 int index = int.Parse(frmSelect.SelectedItem);
  796.                 if (frmSelect.DialogResult != DialogResult.Cancel)
  797.                 {
  798.                     Contact selectedContact = selectedContactsList[index];
  799.  
  800.                     if (nodSelect["mademan"] != null)
  801.                     {
  802.                         selectedContact.MadeMan = true;
  803.                         CreateImprovement(selectedContact.GUID, Improvement.ImprovementSource.Quality, strSourceName,
  804.                             Improvement.ImprovementType.ContactMadeMan, selectedContact.GUID);
  805.                     }
  806.  
  807.                     if (String.IsNullOrWhiteSpace(_strSelectedValue))
  808.                     {
  809.                         _strSelectedValue = selectedContact.Name;
  810.                     }
  811.                     else
  812.                     {
  813.                         _strSelectedValue += (", " + selectedContact.Name);
  814.                     }
  815.                 }
  816.                 else
  817.                 {
  818.                     Rollback();
  819.                     return false;
  820.                 }
  821.             }
  822.  
  823.             if (bonusNode.LocalName == "addcontact")
  824.             {
  825.                 Log.Info("addcontact");
  826.  
  827.                 int loyalty, connection;
  828.                
  829.                 bonusNode.TryGetField("loyalty", out loyalty, 1);
  830.                 bonusNode.TryGetField("connection", out connection, 1);
  831.                 bool group = bonusNode["group"] != null;
  832.                 bool free = bonusNode["free"] != null;
  833.  
  834.                 Contact contact = new Contact(_objCharacter);
  835.                 contact.Free = free;
  836.                 contact.IsGroup = group;
  837.                 contact.Loyalty = loyalty;
  838.                 contact.Connection = connection;
  839.                 contact.ReadOnly = true;
  840.                 _objCharacter.Contacts.Add(contact);
  841.  
  842.                 CreateImprovement(contact.GUID, Improvement.ImprovementSource.Quality, strSourceName,
  843.                             Improvement.ImprovementType.AddContact, contact.GUID);
  844.             }
  845.  
  846.             // Affect a Specific CharacterAttribute.
  847.             if (bonusNode.LocalName == ("specificattribute"))
  848.             {
  849.                 Log.Info("specificattribute");
  850.  
  851.                 if (bonusNode["name"].InnerText != "ESS")
  852.                 {
  853.                     // Display the Select CharacterAttribute window and record which CharacterAttribute was selected.
  854.                     // Record the improvement.
  855.                     int intMin = 0;
  856.                     int intAug = 0;
  857.                     int intMax = 0;
  858.                     int intAugMax = 0;
  859.  
  860.                     // Extract the modifiers.
  861.                     if (bonusNode.InnerXml.Contains("min"))
  862.                         intMin = ValueToInt(bonusNode["min"].InnerXml, intRating);
  863.                     if (bonusNode.InnerXml.Contains("val"))
  864.                         intAug = ValueToInt(bonusNode["val"].InnerXml, intRating);
  865.                     if (bonusNode.InnerXml.Contains("max"))
  866.                     {
  867.                         if (bonusNode["max"].InnerText.Contains("-natural"))
  868.                         {
  869.                             intMax = Convert.ToInt32(bonusNode["max"].InnerText.Replace("-natural", string.Empty)) -
  870.                                      _objCharacter.GetAttribute(bonusNode["name"].InnerText).MetatypeMaximum;
  871.                         }
  872.                         else
  873.                             intMax = ValueToInt(bonusNode["max"].InnerXml, intRating);
  874.                     }
  875.                     if (bonusNode.InnerXml.Contains("aug"))
  876.                         intAugMax = ValueToInt(bonusNode["aug"].InnerXml, intRating);
  877.  
  878.                     string strUseUnique = strUnique;
  879.                     if (bonusNode["name"].Attributes["precedence"] != null)
  880.                         strUseUnique = "precedence" + bonusNode["name"].Attributes["precedence"].InnerText;
  881.  
  882.                     string strAttribute = bonusNode["name"].InnerText;
  883.  
  884.                     if (bonusNode["affectbase"] != null)
  885.                         strAttribute += "Base";
  886.                    
  887.                     CreateImprovement(strAttribute, objImprovementSource, strSourceName, Improvement.ImprovementType.Attribute,
  888.                         strUseUnique, 0, 1, intMin, intMax, intAug, intAugMax);
  889.                 }
  890.                 else
  891.                 {
  892.                     CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Essence, "",
  893.                         Convert.ToInt32(bonusNode["val"].InnerText));
  894.                 }
  895.             }
  896.  
  897.             // Add a paid increase to an attribute
  898.             if (bonusNode.LocalName == ("attributelevel"))
  899.             {
  900.                 Log.Info(new object[] {"attributelevel", bonusNode.OuterXml});
  901.                 String strAttrib;
  902.                 int value;
  903.                 bonusNode.TryGetField("val", out value, 1);
  904.  
  905.                 if (bonusNode.TryGetField("name", out strAttrib))
  906.                 {
  907.                     CreateImprovement(strAttrib, objImprovementSource, strSourceName,
  908.                         Improvement.ImprovementType.Attributelevel, "", value);
  909.                 }
  910.                 else
  911.                 {
  912.                     Log.Error(new object[] {"attributelevel", bonusNode.OuterXml});
  913.                 }
  914.             }
  915.  
  916.             if (bonusNode.LocalName == ("skilllevel"))
  917.             {
  918.                 Log.Info(new object[] {"skilllevel", bonusNode.OuterXml});
  919.                 String strSkill;
  920.                 int value;
  921.                 bonusNode.TryGetField("val", out value, 1);
  922.                 if (bonusNode.TryGetField("name", out strSkill))
  923.                 {
  924.                     CreateImprovement(strSkill, objImprovementSource, strSourceName,
  925.                         Improvement.ImprovementType.SkillLevel, "", value);
  926.  
  927.  
  928.                 }
  929.                 else
  930.                 {
  931.                     Log.Error(new object[] {"skilllevel", bonusNode.OuterXml});
  932.                 }
  933.             }
  934.  
  935.             if (bonusNode.LocalName == "pushtext")
  936.             {
  937.  
  938.                 String push = bonusNode.InnerText;
  939.                 if (!String.IsNullOrWhiteSpace(push))
  940.                 {
  941.                     _objCharacter.Pushtext.Push(push);
  942.                 }
  943.             }
  944.  
  945.            
  946.  
  947.             if (bonusNode.LocalName == "knowsoft")
  948.             {
  949.                 int val = bonusNode["val"] != null ? ValueToInt(bonusNode["val"].InnerText, intRating) : 1;
  950.  
  951.                 string name;
  952.                 if (!string.IsNullOrWhiteSpace(_strForcedValue))
  953.                 {
  954.                     name = _strForcedValue;
  955.                 }
  956.                 else if (bonusNode["pick"] != null)
  957.                 {
  958.                     List<ListItem> types;
  959.                     if (bonusNode["group"] != null)
  960.                     {
  961.                         var v = bonusNode.SelectNodes($"./group");
  962.                         types =
  963.                             KnowledgeSkill.KnowledgeTypes.Where(x => bonusNode.SelectNodes($"group[. = '{x.Value}']").Count > 0).ToList();
  964.  
  965.                     }
  966.                     else if (bonusNode["notgroup"] != null)
  967.                     {
  968.                         types =
  969.                             KnowledgeSkill.KnowledgeTypes.Where(x => bonusNode.SelectNodes($"notgroup[. = '{x.Value}']").Count == 0).ToList();
  970.                     }
  971.                     else
  972.                     {
  973.                         types = KnowledgeSkill.KnowledgeTypes;
  974.                     }
  975.  
  976.                     frmSelectItem select = new frmSelectItem();
  977.                     select.DropdownItems = KnowledgeSkill.KnowledgeSkillsWithCategory(types.Select(x => x.Value).ToArray());
  978.  
  979.                     select.ShowDialog();
  980.                     if (select.DialogResult == DialogResult.Cancel)
  981.                     {
  982.                         return false;
  983.                     }
  984.  
  985.                     name = select.SelectedItem;
  986.                 }
  987.                 else if (bonusNode["name"] != null)
  988.                 {
  989.                     name = bonusNode["name"].InnerText;
  990.                 }
  991.                 else
  992.                 {
  993.                     //TODO some kind of error handling
  994.                     Log.Error(new[] {bonusNode.OuterXml, "Missing pick or name"});
  995.                     return false;
  996.                 }
  997.                 _strSelectedValue = name;
  998.  
  999.  
  1000.                 KnowledgeSkill skill = new KnowledgeSkill(_objCharacter, name);
  1001.  
  1002.                 bool knowsoft = bonusNode.TryCheckValue("require", "skilljack");
  1003.  
  1004.                 if (knowsoft)
  1005.                 {
  1006.                     _objCharacter.SkillsSection.KnowsoftSkills.Add(skill);
  1007.                     if (_objCharacter.SkillsoftAccess)
  1008.                     {
  1009.                         _objCharacter.SkillsSection.KnowledgeSkills.Add(skill);
  1010.                     }
  1011.                 }
  1012.                 else
  1013.                 {
  1014.                     _objCharacter.SkillsSection.KnowledgeSkills.Add(skill);
  1015.                 }
  1016.  
  1017.                 CreateImprovement(name, objImprovementSource, strSourceName, Improvement.ImprovementType.SkillBase, strUnique, val);
  1018.                 CreateImprovement(skill.Id.ToString(), objImprovementSource, strSourceName,
  1019.                     Improvement.ImprovementType.SkillKnowledgeForced, strUnique);
  1020.  
  1021.             }
  1022.  
  1023.             if (bonusNode.LocalName == "knowledgeskilllevel")
  1024.             {
  1025.                 //Theoretically life modules, right now we just give out free points and let people sort it out themselves.
  1026.                 //Going to be fun to do the real way, from a computer science perspective, but i don't feel like using 2 weeks on that now
  1027.  
  1028.                 int val = bonusNode["val"] != null ? ValueToInt(bonusNode["val"].InnerText, intRating) : 1;
  1029.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.FreeKnowledgeSkills, "", val);
  1030.             }
  1031.  
  1032.             if (bonusNode.LocalName == "knowledgeskillpoints")
  1033.             {
  1034.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.FreeKnowledgeSkills, "", ValueToInt(bonusNode.InnerText,Convert.ToInt32(bonusNode.Value)));
  1035.             }
  1036.  
  1037.             if (bonusNode.LocalName == ("skillgrouplevel"))
  1038.             {
  1039.                 Log.Info(new object[] {"skillgrouplevel", bonusNode.OuterXml});
  1040.                 String strSkillGroup;
  1041.                 int value;
  1042.                 if (bonusNode.TryGetField("name", out strSkillGroup) &&
  1043.                     bonusNode.TryGetField("val", out value))
  1044.                 {
  1045.                     CreateImprovement(strSkillGroup, objImprovementSource, strSourceName,
  1046.                         Improvement.ImprovementType.SkillGroupLevel, "", value);
  1047.                 }
  1048.                 else
  1049.                 {
  1050.                     Log.Error(new object[] {"skillgrouplevel", bonusNode.OuterXml});
  1051.                 }
  1052.             }
  1053.  
  1054.             // Change the maximum number of BP that can be spent on Nuyen.
  1055.             if (bonusNode.LocalName == ("nuyenmaxbp"))
  1056.             {
  1057.                 Log.Info("nuyenmaxbp");
  1058.                 Log.Info("nuyenmaxbp = " + bonusNode.OuterXml.ToString());
  1059.                 Log.Info("Calling CreateImprovement");
  1060.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.NuyenMaxBP, "",
  1061.                     ValueToInt(bonusNode.InnerText, intRating));
  1062.             }
  1063.  
  1064.             // Apply a bonus/penalty to physical limit.
  1065.             if (bonusNode.LocalName == ("physicallimit"))
  1066.             {
  1067.                 Log.Info("physicallimit");
  1068.                 Log.Info("physicallimit = " + bonusNode.OuterXml.ToString());
  1069.                 Log.Info("Calling CreateImprovement");
  1070.                 CreateImprovement("Physical", objImprovementSource, strSourceName, Improvement.ImprovementType.PhysicalLimit, strFriendlyName,
  1071.                     ValueToInt(bonusNode.InnerText, intRating));
  1072.             }
  1073.  
  1074.             // Apply a bonus/penalty to mental limit.
  1075.             if (bonusNode.LocalName == ("mentallimit"))
  1076.             {
  1077.                 Log.Info("mentallimit");
  1078.                 Log.Info("mentallimit = " + bonusNode.OuterXml.ToString());
  1079.                 Log.Info("Calling CreateImprovement");
  1080.                 CreateImprovement("Mental", objImprovementSource, strSourceName, Improvement.ImprovementType.MentalLimit, strFriendlyName,
  1081.                     ValueToInt(bonusNode.InnerText, intRating));
  1082.             }
  1083.  
  1084.             // Apply a bonus/penalty to social limit.
  1085.             if (bonusNode.LocalName == ("sociallimit"))
  1086.             {
  1087.                 Log.Info("sociallimit");
  1088.                 Log.Info("sociallimit = " + bonusNode.OuterXml.ToString());
  1089.                 Log.Info("Calling CreateImprovement");
  1090.                 CreateImprovement("Social", objImprovementSource, strSourceName, Improvement.ImprovementType.SocialLimit, strFriendlyName,
  1091.                     ValueToInt(bonusNode.InnerText, intRating));
  1092.             }
  1093.  
  1094.             // Change the amount of Nuyen the character has at creation time (this can put the character over the amount they're normally allowed).
  1095.             if (bonusNode.LocalName == ("nuyenamt"))
  1096.             {
  1097.                 Log.Info("nuyenamt");
  1098.                 Log.Info("nuyenamt = " + bonusNode.OuterXml.ToString());
  1099.                 Log.Info("Calling CreateImprovement");
  1100.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Nuyen, strUnique,
  1101.                     ValueToInt(bonusNode.InnerText, intRating));
  1102.             }
  1103.  
  1104.             // Improve Condition Monitors.
  1105.             if (bonusNode.LocalName == ("conditionmonitor"))
  1106.             {
  1107.                 Log.Info("conditionmonitor");
  1108.                 Log.Info("conditionmonitor = " + bonusNode.OuterXml.ToString());
  1109.                 // Physical Condition.
  1110.                 if (bonusNode.InnerXml.Contains("physical"))
  1111.                 {
  1112.                     Log.Info("Calling CreateImprovement for Physical");
  1113.                     CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.PhysicalCM, strUnique,
  1114.                         ValueToInt(bonusNode["physical"].InnerText, intRating));
  1115.                 }
  1116.  
  1117.                 // Stun Condition.
  1118.                 if (bonusNode.InnerXml.Contains("stun"))
  1119.                 {
  1120.                     Log.Info("Calling CreateImprovement for Stun");
  1121.                     CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.StunCM, strUnique,
  1122.                         ValueToInt(bonusNode["stun"].InnerText, intRating));
  1123.                 }
  1124.  
  1125.                 // Condition Monitor Threshold.
  1126.                 if (NodeExists(bonusNode, "threshold"))
  1127.                 {
  1128.                     string strUseUnique = strUnique;
  1129.                     if (bonusNode["threshold"].Attributes["precedence"] != null)
  1130.                         strUseUnique = "precedence" + bonusNode["threshold"].Attributes["precedence"].InnerText;
  1131.  
  1132.                     Log.Info("Calling CreateImprovement for Threshold");
  1133.                     CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.CMThreshold, strUseUnique,
  1134.                         ValueToInt(bonusNode["threshold"].InnerText, intRating));
  1135.                 }
  1136.  
  1137.                 // Condition Monitor Threshold Offset. (Additioal boxes appear before the FIRST Condition Monitor penalty)
  1138.                 if (NodeExists(bonusNode, "thresholdoffset"))
  1139.                 {
  1140.                     string strUseUnique = strUnique;
  1141.                     if (bonusNode["thresholdoffset"].Attributes["precedence"] != null)
  1142.                         strUseUnique = "precedence" + bonusNode["thresholdoffset"].Attributes["precedence"].InnerText;
  1143.  
  1144.                     Log.Info("Calling CreateImprovement for Threshold Offset");
  1145.                     CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.CMThresholdOffset,
  1146.                         strUseUnique, ValueToInt(bonusNode["thresholdoffset"].InnerText, intRating));
  1147.                 }
  1148.  
  1149.                 // Condition Monitor Overflow.
  1150.                 if (bonusNode.InnerXml.Contains("overflow"))
  1151.                 {
  1152.                     Log.Info("Calling CreateImprovement for Overflow");
  1153.                     CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.CMOverflow, strUnique,
  1154.                         ValueToInt(bonusNode["overflow"].InnerText, intRating));
  1155.                 }
  1156.             }
  1157.  
  1158.             // Improve Living Personal Attributes.
  1159.             if (bonusNode.LocalName == ("livingpersona"))
  1160.             {
  1161.                 Log.Info("livingpersona");
  1162.                 Log.Info("livingpersona = " + bonusNode.OuterXml.ToString());
  1163.                 // Response.
  1164.                 if (bonusNode.InnerXml.Contains("response"))
  1165.                 {
  1166.                     Log.Info("Calling CreateImprovement for response");
  1167.                     CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.LivingPersonaResponse,
  1168.                         strUnique, ValueToInt(bonusNode["response"].InnerText, intRating));
  1169.                 }
  1170.  
  1171.                 // Signal.
  1172.                 if (bonusNode.InnerXml.Contains("signal"))
  1173.                 {
  1174.                     Log.Info("Calling CreateImprovement for signal");
  1175.                     CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.LivingPersonaSignal,
  1176.                         strUnique,
  1177.                         ValueToInt(bonusNode["signal"].InnerText, intRating));
  1178.                 }
  1179.  
  1180.                 // Firewall.
  1181.                 if (bonusNode.InnerXml.Contains("firewall"))
  1182.                 {
  1183.                     Log.Info("Calling CreateImprovement for firewall");
  1184.                     CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.LivingPersonaFirewall,
  1185.                         strUnique, ValueToInt(bonusNode["firewall"].InnerText, intRating));
  1186.                 }
  1187.  
  1188.                 // System.
  1189.                 if (bonusNode.InnerXml.Contains("system"))
  1190.                 {
  1191.                     Log.Info("Calling CreateImprovement for system");
  1192.                     CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.LivingPersonaSystem,
  1193.                         strUnique,
  1194.                         ValueToInt(bonusNode["system"].InnerText, intRating));
  1195.                 }
  1196.  
  1197.                 // Biofeedback Filter.
  1198.                 if (bonusNode.InnerXml.Contains("biofeedback"))
  1199.                 {
  1200.                     Log.Info("Calling CreateImprovement for biofeedback");
  1201.                     CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.LivingPersonaBiofeedback,
  1202.                         strUnique, ValueToInt(bonusNode["biofeedback"].InnerText, intRating));
  1203.                 }
  1204.             }
  1205.  
  1206.             // The Improvement adjusts a specific Skill.
  1207.             if (bonusNode.LocalName == ("specificskill"))
  1208.             {
  1209.                 Log.Info("specificskill");
  1210.                 Log.Info("specificskill = " + bonusNode.OuterXml.ToString());
  1211.                 bool blnAddToRating = false;
  1212.                 if (bonusNode["applytorating"] != null)
  1213.                 {
  1214.                     if (bonusNode["applytorating"].InnerText == "yes")
  1215.                         blnAddToRating = true;
  1216.                 }
  1217.  
  1218.                 string strUseUnique = strUnique;
  1219.                 if (bonusNode.Attributes["precedence"] != null)
  1220.                     strUseUnique = "precedence" + bonusNode.Attributes["precedence"].InnerText;
  1221.  
  1222.                 // Record the improvement.
  1223.                 if (bonusNode["bonus"] != null)
  1224.                 {
  1225.                     Log.Info("Calling CreateImprovement for bonus");
  1226.                     CreateImprovement(bonusNode["name"].InnerText, objImprovementSource, strSourceName,
  1227.                         Improvement.ImprovementType.Skill, strUseUnique, ValueToInt(bonusNode["bonus"].InnerXml, intRating), 1, 0, 0, 0,
  1228.                         0, "", blnAddToRating);
  1229.                 }
  1230.                 if (bonusNode["max"] != null)
  1231.                 {
  1232.                     Log.Info("Calling CreateImprovement for max");
  1233.                     CreateImprovement(bonusNode["name"].InnerText, objImprovementSource, strSourceName,
  1234.                         Improvement.ImprovementType.Skill, strUseUnique, 0, 1, 0, ValueToInt(bonusNode["max"].InnerText, intRating), 0,
  1235.                         0,
  1236.                         "", blnAddToRating);
  1237.                 }
  1238.             }
  1239.  
  1240.             if (bonusNode.LocalName == "reflexrecorderoptimization")
  1241.             {
  1242.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.ReflexRecorderOptimization, strUnique);
  1243.             }
  1244.  
  1245.             // The Improvement adds a martial art
  1246.             if (bonusNode.LocalName == ("martialart"))
  1247.             {
  1248.                 Log.Info("martialart");
  1249.                 Log.Info("martialart = " + bonusNode.OuterXml.ToString());
  1250.                 XmlDocument _objXmlDocument = XmlManager.Instance.Load("martialarts.xml");
  1251.                 XmlNode objXmlArt =
  1252.                     _objXmlDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + bonusNode.InnerText +
  1253.                                                      "\"]");
  1254.  
  1255.                 TreeNode objNode = new TreeNode();
  1256.                 MartialArt objMartialArt = new MartialArt(_objCharacter);
  1257.                 objMartialArt.Create(objXmlArt, objNode, _objCharacter);
  1258.                 objMartialArt.IsQuality = true;
  1259.                 _objCharacter.MartialArts.Add(objMartialArt);
  1260.             }
  1261.  
  1262.             // The Improvement adds a limit modifier
  1263.             if (bonusNode.LocalName == ("limitmodifier"))
  1264.             {
  1265.                 Log.Info("limitmodifier");
  1266.                 Log.Info("limitmodifier = " + bonusNode.OuterXml.ToString());
  1267.                 LimitModifier objLimitMod = new LimitModifier(_objCharacter);
  1268.                 string strLimit = bonusNode["limit"].InnerText;
  1269.                 string strBonus = bonusNode["value"].InnerText;
  1270.                 if (strBonus == "Rating")
  1271.                 {
  1272.                     strBonus = intRating.ToString();
  1273.                 }
  1274.                 string strCondition = "";
  1275.                 try
  1276.                 {
  1277.                     strCondition = bonusNode["condition"].InnerText;
  1278.                 }
  1279.                 catch
  1280.                 {
  1281.                 }
  1282.                 int intBonus = 0;
  1283.                 if (strBonus == "Rating")
  1284.                     intBonus = intRating;
  1285.                 else
  1286.                     intBonus = Convert.ToInt32(strBonus);
  1287.                 string strName = strFriendlyName;
  1288.                 TreeNode nodTemp = new TreeNode();
  1289.                 Log.Info("Calling CreateImprovement");
  1290.                 CreateImprovement(strLimit, objImprovementSource, strSourceName, Improvement.ImprovementType.LimitModifier,
  1291.                     strFriendlyName, intBonus, 0, 0, 0, 0, 0, strCondition);
  1292.             }
  1293.  
  1294.             // The Improvement adjusts a Skill Category.
  1295.             if (bonusNode.LocalName == ("skillcategory"))
  1296.             {
  1297.                 Log.Info("skillcategory");
  1298.                 Log.Info("skillcategory = " + bonusNode.OuterXml.ToString());
  1299.  
  1300.                 bool blnAddToRating = false;
  1301.                 if (bonusNode["applytorating"] != null)
  1302.                 {
  1303.                     if (bonusNode["applytorating"].InnerText == "yes")
  1304.                         blnAddToRating = true;
  1305.                 }
  1306.                 if (bonusNode.InnerXml.Contains("exclude"))
  1307.                 {
  1308.                     Log.Info("Calling CreateImprovement - exclude");
  1309.                     CreateImprovement(bonusNode["name"].InnerText, objImprovementSource, strSourceName,
  1310.                         Improvement.ImprovementType.SkillCategory, strUnique, ValueToInt(bonusNode["bonus"].InnerXml, intRating), 1, 0,
  1311.                         0,
  1312.                         0, 0, bonusNode["exclude"].InnerText, blnAddToRating);
  1313.                 }
  1314.                 else
  1315.                 {
  1316.                     Log.Info("Calling CreateImprovement");
  1317.                     CreateImprovement(bonusNode["name"].InnerText, objImprovementSource, strSourceName,
  1318.                         Improvement.ImprovementType.SkillCategory, strUnique, ValueToInt(bonusNode["bonus"].InnerXml, intRating), 1, 0,
  1319.                         0,
  1320.                         0, 0, "", blnAddToRating);
  1321.                 }
  1322.             }
  1323.  
  1324.             // The Improvement adjusts a Skill Group.
  1325.             if (bonusNode.LocalName == ("skillgroup"))
  1326.             {
  1327.                 Log.Info("skillgroup");
  1328.                 Log.Info("skillgroup = " + bonusNode.OuterXml.ToString());
  1329.  
  1330.                 bool blnAddToRating = false;
  1331.                 if (bonusNode["applytorating"] != null)
  1332.                 {
  1333.                     if (bonusNode["applytorating"].InnerText == "yes")
  1334.                         blnAddToRating = true;
  1335.                 }
  1336.                 if (bonusNode.InnerXml.Contains("exclude"))
  1337.                 {
  1338.                     Log.Info("Calling CreateImprovement - exclude");
  1339.                     CreateImprovement(bonusNode["name"].InnerText, objImprovementSource, strSourceName,
  1340.                         Improvement.ImprovementType.SkillGroup, strUnique, ValueToInt(bonusNode["bonus"].InnerXml, intRating), 1, 0, 0, 0,
  1341.                         0, bonusNode["exclude"].InnerText, blnAddToRating);
  1342.                 }
  1343.                 else
  1344.                 {
  1345.                     Log.Info("Calling CreateImprovement");
  1346.                     CreateImprovement(bonusNode["name"].InnerText, objImprovementSource, strSourceName,
  1347.                         Improvement.ImprovementType.SkillGroup, strUnique, ValueToInt(bonusNode["bonus"].InnerXml, intRating), 1, 0, 0, 0,
  1348.                         0, "", blnAddToRating);
  1349.                 }
  1350.             }
  1351.  
  1352.             // The Improvement adjust Skills with the given CharacterAttribute.
  1353.             if (bonusNode.LocalName == ("skillattribute"))
  1354.             {
  1355.                 Log.Info("skillattribute");
  1356.                 Log.Info("skillattribute = " + bonusNode.OuterXml.ToString());
  1357.  
  1358.                 string strUseUnique = strUnique;
  1359.                 if (bonusNode["name"].Attributes["precedence"] != null)
  1360.                     strUseUnique = "precedence" + bonusNode["name"].Attributes["precedence"].InnerText;
  1361.  
  1362.                 bool blnAddToRating = false;
  1363.                 if (bonusNode["applytorating"] != null)
  1364.                 {
  1365.                     if (bonusNode["applytorating"].InnerText == "yes")
  1366.                         blnAddToRating = true;
  1367.                 }
  1368.                 if (bonusNode.InnerXml.Contains("exclude"))
  1369.                 {
  1370.                     Log.Info("Calling CreateImprovement - exclude");
  1371.                     CreateImprovement(bonusNode["name"].InnerText, objImprovementSource, strSourceName,
  1372.                         Improvement.ImprovementType.SkillAttribute, strUseUnique, ValueToInt(bonusNode["bonus"].InnerXml, intRating), 1,
  1373.                         0, 0, 0, 0, bonusNode["exclude"].InnerText, blnAddToRating);
  1374.                 }
  1375.                 else
  1376.                 {
  1377.                     Log.Info("Calling CreateImprovement");
  1378.                     CreateImprovement(bonusNode["name"].InnerText, objImprovementSource, strSourceName,
  1379.                         Improvement.ImprovementType.SkillAttribute, strUseUnique, ValueToInt(bonusNode["bonus"].InnerXml, intRating), 1,
  1380.                         0, 0, 0, 0, "", blnAddToRating);
  1381.                 }
  1382.             }
  1383.  
  1384.             // The Improvement comes from Enhanced Articulation (improves Physical Active Skills linked to a Physical CharacterAttribute).
  1385.             if (bonusNode.LocalName == ("skillarticulation"))
  1386.             {
  1387.                 Log.Info("skillarticulation");
  1388.                 Log.Info("skillarticulation = " + bonusNode.OuterXml.ToString());
  1389.  
  1390.                 Log.Info("Calling CreateImprovement");
  1391.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.EnhancedArticulation,
  1392.                     strUnique,
  1393.                     ValueToInt(bonusNode["bonus"].InnerText, intRating));
  1394.             }
  1395.  
  1396.             // Check for Armor modifiers.
  1397.             if (bonusNode.LocalName == ("armor"))
  1398.             {
  1399.                 Log.Info("armor");
  1400.                 Log.Info("armor = " + bonusNode.OuterXml.ToString());
  1401.                 Log.Info("Calling CreateImprovement");
  1402.                 string strUseUnique = strUnique;
  1403.                 if (bonusNode.Attributes["precedence"] != null)
  1404.                 {
  1405.                     strUseUnique = "precedence" + bonusNode.Attributes["precedence"].InnerText;
  1406.                 }
  1407.                 else if (bonusNode.Attributes["group"] != null)
  1408.                 {
  1409.                     strUseUnique = "group" + bonusNode.Attributes["group"].InnerText;
  1410.                 }
  1411.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Armor, strUseUnique,
  1412.                     ValueToInt(bonusNode.InnerText, intRating));
  1413.             }
  1414.  
  1415.             // Check for Reach modifiers.
  1416.             if (bonusNode.LocalName == ("reach"))
  1417.             {
  1418.                 Log.Info("reach");
  1419.                 Log.Info("reach = " + bonusNode.OuterXml.ToString());
  1420.                 Log.Info("Calling CreateImprovement");
  1421.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Reach, strUnique,
  1422.                     ValueToInt(bonusNode.InnerText, intRating));
  1423.             }
  1424.  
  1425.             // Check for Unarmed Damage Value modifiers.
  1426.             if (bonusNode.LocalName == ("unarmeddv"))
  1427.             {
  1428.                 Log.Info("unarmeddv");
  1429.                 Log.Info("unarmeddv = " + bonusNode.OuterXml.ToString());
  1430.                 Log.Info("Calling CreateImprovement");
  1431.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.UnarmedDV, strUnique,
  1432.                     ValueToInt(bonusNode.InnerText, intRating));
  1433.             }
  1434.  
  1435.             // Check for Unarmed Damage Value Physical.
  1436.             if (bonusNode.LocalName == ("unarmeddvphysical"))
  1437.             {
  1438.                 Log.Info("unarmeddvphysical");
  1439.                 Log.Info("unarmeddvphysical = " + bonusNode.OuterXml.ToString());
  1440.                 Log.Info("Calling CreateImprovement");
  1441.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.UnarmedDVPhysical, "");
  1442.             }
  1443.  
  1444.             // Check for Unarmed Armor Penetration.
  1445.             if (bonusNode.LocalName == ("unarmedap"))
  1446.             {
  1447.                 Log.Info("unarmedap");
  1448.                 Log.Info("unarmedap = " + bonusNode.OuterXml.ToString());
  1449.                 Log.Info("Calling CreateImprovement");
  1450.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.UnarmedAP, strUnique,
  1451.                     ValueToInt(bonusNode.InnerText, intRating));
  1452.             }
  1453.  
  1454.             // Check for Initiative modifiers.
  1455.             if (bonusNode.LocalName == ("initiative"))
  1456.             {
  1457.                 Log.Info("initiative");
  1458.                 Log.Info("initiative = " + bonusNode.OuterXml.ToString());
  1459.                 Log.Info("Calling CreateImprovement");
  1460.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Initiative, strUnique,
  1461.                     ValueToInt(bonusNode.InnerText, intRating));
  1462.             }
  1463.  
  1464.             // Check for Initiative Pass modifiers. Only the highest one ever applies.
  1465.             if (bonusNode.LocalName == ("initiativepass"))
  1466.             {
  1467.                 Log.Info("initiativepass");
  1468.                 Log.Info("initiativepass = " + bonusNode.OuterXml.ToString());
  1469.                 Log.Info("Calling CreateImprovement");
  1470.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.InitiativePass,
  1471.                     "initiativepass", ValueToInt(bonusNode.InnerText, intRating));
  1472.             }
  1473.  
  1474.             // Check for Initiative Pass modifiers. Only the highest one ever applies.
  1475.             if (bonusNode.LocalName == ("initiativepassadd"))
  1476.             {
  1477.                 Log.Info("initiativepassadd");
  1478.                 Log.Info("initiativepassadd = " + bonusNode.OuterXml.ToString());
  1479.                 Log.Info("Calling CreateImprovement");
  1480.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.InitiativePassAdd, strUnique,
  1481.                     ValueToInt(bonusNode.InnerText, intRating));
  1482.             }
  1483.  
  1484.             // Check for Matrix Initiative modifiers.
  1485.             if (bonusNode.LocalName == ("matrixinitiative"))
  1486.             {
  1487.                 Log.Info("matrixinitiative");
  1488.                 Log.Info("matrixinitiative = " + bonusNode.OuterXml.ToString());
  1489.                 Log.Info("Calling CreateImprovement");
  1490.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.MatrixInitiative, strUnique,
  1491.                     ValueToInt(bonusNode.InnerText, intRating));
  1492.             }
  1493.  
  1494.             // Check for Matrix Initiative Pass modifiers.
  1495.             if (bonusNode.LocalName == ("matrixinitiativepass"))
  1496.             {
  1497.                 Log.Info("matrixinitiativepass");
  1498.                 Log.Info("matrixinitiativepass = " + bonusNode.OuterXml.ToString());
  1499.                 Log.Info("Calling CreateImprovement");
  1500.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.MatrixInitiativePass,
  1501.                     "matrixinitiativepass", ValueToInt(bonusNode.InnerText, intRating));
  1502.             }
  1503.  
  1504.             // Check for Matrix Initiative Pass modifiers.
  1505.             if (bonusNode.LocalName == ("matrixinitiativepassadd"))
  1506.             {
  1507.                 Log.Info("matrixinitiativepassadd");
  1508.                 Log.Info("matrixinitiativepassadd = " + bonusNode.OuterXml.ToString());
  1509.                 Log.Info("Calling CreateImprovement");
  1510.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.MatrixInitiativePass,
  1511.                     strUnique,
  1512.                     ValueToInt(bonusNode.InnerText, intRating));
  1513.             }
  1514.  
  1515.             // Check for Lifestyle cost modifiers.
  1516.             if (bonusNode.LocalName == ("lifestylecost"))
  1517.             {
  1518.                 Log.Info("lifestylecost");
  1519.                 Log.Info("lifestylecost = " + bonusNode.OuterXml.ToString());
  1520.                 Log.Info("Calling CreateImprovement");
  1521.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.LifestyleCost, strUnique,
  1522.                     ValueToInt(bonusNode.InnerText, intRating));
  1523.             }
  1524.  
  1525.             // Check for basic Lifestyle cost modifiers.
  1526.             if (bonusNode.LocalName == ("basiclifestylecost"))
  1527.             {
  1528.                 Log.Info("basiclifestylecost");
  1529.                 Log.Info("basiclifestylecost = " + bonusNode.OuterXml.ToString());
  1530.                 Log.Info("Calling CreateImprovement");
  1531.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.BasicLifestyleCost, strUnique,
  1532.                     ValueToInt(bonusNode.InnerText, intRating));
  1533.             }
  1534.  
  1535.             // Check for Genetech Cost modifiers.
  1536.             if (bonusNode.LocalName == ("genetechcostmultiplier"))
  1537.             {
  1538.                 Log.Info("genetechcostmultiplier");
  1539.                 Log.Info("genetechcostmultiplier = " + bonusNode.OuterXml.ToString());
  1540.                 Log.Info("Calling CreateImprovement");
  1541.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.GenetechCostMultiplier,
  1542.                     strUnique, ValueToInt(bonusNode.InnerText, intRating));
  1543.             }
  1544.  
  1545.             // Check for Genetech: Transgenics Cost modifiers.
  1546.             if (bonusNode.LocalName == ("transgenicsgenetechcost"))
  1547.             {
  1548.                 Log.Info("transgenicsgenetechcost");
  1549.                 Log.Info("transgenicsgenetechcost = " + bonusNode.OuterXml.ToString());
  1550.                 Log.Info("Calling CreateImprovement");
  1551.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.TransgenicsBiowareCost,
  1552.                     strUnique, ValueToInt(bonusNode.InnerText, intRating));
  1553.             }
  1554.  
  1555.             // Check for Basic Bioware Essence Cost modifiers.
  1556.             if (bonusNode.LocalName == ("basicbiowareessmultiplier"))
  1557.             {
  1558.                 Log.Info("basicbiowareessmultiplier");
  1559.                 Log.Info("basicbiowareessmultiplier = " + bonusNode.OuterXml.ToString());
  1560.                 Log.Info("Calling CreateImprovement");
  1561.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.BasicBiowareEssCost,
  1562.                     strUnique,
  1563.                     ValueToInt(bonusNode.InnerText, intRating));
  1564.             }
  1565.  
  1566.             // Check for Bioware Essence Cost modifiers.
  1567.             if (bonusNode.LocalName == ("biowareessmultiplier"))
  1568.             {
  1569.                 Log.Info("biowareessmultiplier");
  1570.                 Log.Info("biowareessmultiplier = " + bonusNode.OuterXml.ToString());
  1571.                 Log.Info("Calling CreateImprovement");
  1572.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.BiowareEssCost, strUnique,
  1573.                     ValueToInt(bonusNode.InnerText, intRating));
  1574.             }
  1575.  
  1576.             // Check for Cybeware Essence Cost modifiers.
  1577.             if (bonusNode.LocalName == ("cyberwareessmultiplier"))
  1578.             {
  1579.                 Log.Info("cyberwareessmultiplier");
  1580.                 Log.Info("cyberwareessmultiplier = " + bonusNode.OuterXml.ToString());
  1581.                 Log.Info("Calling CreateImprovement");
  1582.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.CyberwareEssCost, strUnique,
  1583.                     ValueToInt(bonusNode.InnerText, intRating));
  1584.             }
  1585.  
  1586.             // Check for Uneducated modifiers.
  1587.             if (bonusNode.LocalName == ("uneducated"))
  1588.             {
  1589.                 Log.Info("uneducated");
  1590.                 Log.Info("uneducated = " + bonusNode.OuterXml.ToString());
  1591.                 Log.Info("Calling CreateImprovement");
  1592.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Uneducated, strUnique);
  1593.                 _objCharacter.SkillsSection.Uneducated = true;
  1594.             }
  1595.  
  1596.             // Check for College Education modifiers.
  1597.             if (bonusNode.LocalName == ("collegeeducation"))
  1598.             {
  1599.                 Log.Info("collegeeducation");
  1600.                 Log.Info("collegeeducation = " + bonusNode.OuterXml.ToString());
  1601.                 Log.Info("Calling CreateImprovement");
  1602.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.CollegeEducation, strUnique);
  1603.                 _objCharacter.SkillsSection.CollegeEducation = true;
  1604.             }
  1605.  
  1606.             // Check for Jack Of All Trades modifiers.
  1607.             if (bonusNode.LocalName == ("jackofalltrades"))
  1608.             {
  1609.                 Log.Info("jackofalltrades");
  1610.                 Log.Info("jackofalltrades = " + bonusNode.OuterXml.ToString());
  1611.                 Log.Info("Calling CreateImprovement");
  1612.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.JackOfAllTrades, strUnique);
  1613.                 _objCharacter.SkillsSection.JackOfAllTrades = true;
  1614.             }
  1615.  
  1616.             // Check for Prototype Transhuman modifiers.
  1617.             if (bonusNode.LocalName == ("prototypetranshuman"))
  1618.             {
  1619.                 Log.Info("prototypetranshuman");
  1620.                 Log.Info("prototypetranshuman = " + bonusNode.OuterXml.ToString());
  1621.                 Log.Info("Calling CreateImprovement");
  1622.  
  1623.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.PrototypeTranshuman, strUnique);
  1624.                 _objCharacter.PrototypeTranshuman = Convert.ToDecimal(bonusNode.InnerText);
  1625.  
  1626.             }
  1627.             // Check for Uncouth modifiers.
  1628.             if (bonusNode.LocalName == ("uncouth"))
  1629.             {
  1630.                 Log.Info("uncouth");
  1631.                 Log.Info("uncouth = " + bonusNode.OuterXml.ToString());
  1632.                 Log.Info("Calling CreateImprovement");
  1633.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Uncouth, strUnique);
  1634.                 _objCharacter.SkillsSection.Uncouth = true;
  1635.             }
  1636.  
  1637.             // Check for Friends In High Places modifiers.
  1638.             if (bonusNode.LocalName == ("friendsinhighplaces"))
  1639.             {
  1640.                 Log.Info("friendsinhighplaces");
  1641.                 Log.Info("friendsinhighplaces = " + bonusNode.OuterXml.ToString());
  1642.                 Log.Info("Calling CreateImprovement");
  1643.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.FriendsInHighPlaces,
  1644.                     strUnique);
  1645.                 _objCharacter.FriendsInHighPlaces = true;
  1646.             }
  1647.             // Check for School of Hard Knocks modifiers.
  1648.             if (bonusNode.LocalName == ("schoolofhardknocks"))
  1649.             {
  1650.                 Log.Info("schoolofhardknocks");
  1651.                 Log.Info("schoolofhardknocks = " + bonusNode.OuterXml.ToString());
  1652.                 Log.Info("Calling CreateImprovement");
  1653.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.SchoolOfHardKnocks, strUnique);
  1654.                 _objCharacter.SkillsSection.SchoolOfHardKnocks = true;
  1655.             }
  1656.             // Check for ExCon modifiers.
  1657.             if (bonusNode.LocalName == ("excon"))
  1658.             {
  1659.                 Log.Info("ExCon");
  1660.                 Log.Info("ExCon = " + bonusNode.OuterXml.ToString());
  1661.                 Log.Info("Calling CreateImprovement");
  1662.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.ExCon, strUnique);
  1663.                 _objCharacter.ExCon = true;
  1664.             }
  1665.  
  1666.             // Check for TrustFund modifiers.
  1667.             if (bonusNode.LocalName == ("trustfund"))
  1668.             {
  1669.                 Log.Info("TrustFund");
  1670.                 Log.Info("TrustFund = " + bonusNode.OuterXml.ToString());
  1671.                 Log.Info("Calling CreateImprovement");
  1672.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.TrustFund,
  1673.                     strUnique,
  1674.                     ValueToInt(bonusNode.InnerText, intRating));
  1675.                 _objCharacter.TrustFund = ValueToInt(bonusNode.InnerText, intRating);
  1676.             }
  1677.  
  1678.             // Check for Tech School modifiers.
  1679.             if (bonusNode.LocalName == ("techschool"))
  1680.             {
  1681.                 Log.Info("techschool");
  1682.                 Log.Info("techschool = " + bonusNode.OuterXml.ToString());
  1683.                 Log.Info("Calling CreateImprovement");
  1684.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.TechSchool, strUnique);
  1685.                 _objCharacter.SkillsSection.TechSchool = true;
  1686.             }
  1687.             // Check for MadeMan modifiers.
  1688.             if (bonusNode.LocalName == ("mademan"))
  1689.             {
  1690.                 Log.Info("MadeMan");
  1691.                 Log.Info("MadeMan = " + bonusNode.OuterXml.ToString());
  1692.                 Log.Info("Calling CreateImprovement");
  1693.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.MadeMan, strUnique);
  1694.                 _objCharacter.MadeMan = true;
  1695.             }
  1696.  
  1697.             // Check for Linguist modifiers.
  1698.             if (bonusNode.LocalName == ("linguist"))
  1699.             {
  1700.                 Log.Info("Linguist");
  1701.                 Log.Info("Linguist = " + bonusNode.OuterXml.ToString());
  1702.                 Log.Info("Calling CreateImprovement");
  1703.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Linguist, strUnique);
  1704.                 _objCharacter.SkillsSection.Linguist = true;
  1705.             }
  1706.  
  1707.             // Check for LightningReflexes modifiers.
  1708.             if (bonusNode.LocalName == ("lightningreflexes"))
  1709.             {
  1710.                 Log.Info("LightningReflexes");
  1711.                 Log.Info("LightningReflexes = " + bonusNode.OuterXml.ToString());
  1712.                 Log.Info("Calling CreateImprovement");
  1713.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.LightningReflexes, strUnique);
  1714.                 _objCharacter.LightningReflexes = true;
  1715.             }
  1716.  
  1717.             // Check for Fame modifiers.
  1718.             if (bonusNode.LocalName == ("fame"))
  1719.             {
  1720.                 Log.Info("Fame");
  1721.                 Log.Info("Fame = " + bonusNode.OuterXml.ToString());
  1722.                 Log.Info("Calling CreateImprovement");
  1723.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Fame, strUnique);
  1724.                 _objCharacter.Fame = true;
  1725.             }
  1726.             // Check for BornRich modifiers.
  1727.             if (bonusNode.LocalName == ("bornrich"))
  1728.             {
  1729.                 Log.Info("BornRich");
  1730.                 Log.Info("BornRich = " + bonusNode.OuterXml.ToString());
  1731.                 Log.Info("Calling CreateImprovement");
  1732.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.BornRich, strUnique);
  1733.                 _objCharacter.BornRich = true;
  1734.             }
  1735.             // Check for Erased modifiers.
  1736.             if (bonusNode.LocalName == ("erased"))
  1737.             {
  1738.                 Log.Info("Erased");
  1739.                 Log.Info("Erased = " + bonusNode.OuterXml.ToString());
  1740.                 Log.Info("Calling CreateImprovement");
  1741.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Erased, strUnique);
  1742.                 _objCharacter.Erased = true;
  1743.             }
  1744.             // Check for Erased modifiers.
  1745.             if (bonusNode.LocalName == ("overclocker"))
  1746.             {
  1747.                 Log.Info("OverClocker");
  1748.                 Log.Info("Overclocker = " + bonusNode.OuterXml.ToString());
  1749.                 Log.Info("Calling CreateImprovement");
  1750.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Overclocker, strUnique);
  1751.                 _objCharacter.Overclocker = true;
  1752.             }
  1753.  
  1754.             // Check for Restricted Gear modifiers.
  1755.             if (bonusNode.LocalName == ("restrictedgear"))
  1756.             {
  1757.                 Log.Info("restrictedgear");
  1758.                 Log.Info("restrictedgear = " + bonusNode.OuterXml.ToString());
  1759.                 Log.Info("Calling CreateImprovement");
  1760.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.RestrictedGear, strUnique);
  1761.                 _objCharacter.RestrictedGear = true;
  1762.             }
  1763.  
  1764.             // Check for Adept Linguistics.
  1765.             if (bonusNode.LocalName == ("adeptlinguistics"))
  1766.             {
  1767.                 Log.Info("adeptlinguistics");
  1768.                 Log.Info("adeptlinguistics = " + bonusNode.OuterXml.ToString());
  1769.                 Log.Info("Calling CreateImprovement");
  1770.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.AdeptLinguistics, strUnique,
  1771.                     1);
  1772.             }
  1773.  
  1774.             // Check for Weapon Category DV modifiers.
  1775.             if (bonusNode.LocalName == ("weaponcategorydv"))
  1776.             {
  1777.                 //TODO: FIX THIS
  1778.                 /*
  1779.                  * I feel like talking a little bit about improvementmanager at
  1780.                  * this point. It is an intresting class. First of all, it
  1781.                  * manages to throw out everything we ever learned about OOP
  1782.                  * and create a class based on functional programming.
  1783.                  *
  1784.                  * That is true, it is a class, based on manipulating a single
  1785.                  * list on another class.
  1786.                  *
  1787.                  * But atleast there is a reference to it somewhere right?
  1788.                  *
  1789.                  * No, you create one wherever you need it, meaning there are
  1790.                  * tens of instances of this class, all operating on the same
  1791.                  * list
  1792.                  *
  1793.                  * After that, it is just plain stupid.
  1794.                  * If you have an list of xmlNodes and some might be the same
  1795.                  * it checks if a specific node exists (sometimes even by text
  1796.                  * comparison on .OuterXml) and then runs specific code for
  1797.                  * each. If it is there multiple times either of those 2 things
  1798.                  * happen.
  1799.                  *
  1800.                  * 1. Sad, nothing we can do, guess you have to survive
  1801.                  * 2. Lets create a foreach in that specific part of the code
  1802.                  *
  1803.                  * Fuck ImprovementManager, kill it with fire, burn the ashes
  1804.                  * and feed what remains to a dragon that eats unholy
  1805.                  * abominations
  1806.                  */
  1807.  
  1808.  
  1809.                 Log.Info("weaponcategorydv");
  1810.                 Log.Info("weaponcategorydv = " + bonusNode.OuterXml.ToString());
  1811.                 XmlNodeList objXmlCategoryList = bonusNode.SelectNodes("weaponcategorydv");
  1812.                 XmlNode nodWeapon = bonusNode;
  1813.  
  1814.                 if (NodeExists(nodWeapon, "selectskill"))
  1815.                 {
  1816.                     // Display the Select Skill window and record which Skill was selected.
  1817.                     frmSelectItem frmPickCategory = new frmSelectItem();
  1818.                     List<ListItem> lstGeneralItems = new List<ListItem>();
  1819.  
  1820.                     ListItem liBlades = new ListItem();
  1821.                     liBlades.Name = "Blades";
  1822.                     liBlades.Value = "Blades";
  1823.  
  1824.                     ListItem liClubs = new ListItem();
  1825.                     liClubs.Name = "Clubs";
  1826.                     liClubs.Value = "Clubs";
  1827.  
  1828.                     ListItem liUnarmed = new ListItem();
  1829.                     liUnarmed.Name = "Unarmed";
  1830.                     liUnarmed.Value = "Unarmed";
  1831.  
  1832.                     ListItem liAstral = new ListItem();
  1833.                     liAstral.Name = "Astral Combat";
  1834.                     liAstral.Value = "Astral Combat";
  1835.  
  1836.                     ListItem liExotic = new ListItem();
  1837.                     liExotic.Name = "Exotic Melee Weapons";
  1838.                     liExotic.Value = "Exotic Melee Weapons";
  1839.  
  1840.                     lstGeneralItems.Add(liAstral);
  1841.                     lstGeneralItems.Add(liBlades);
  1842.                     lstGeneralItems.Add(liClubs);
  1843.                     lstGeneralItems.Add(liExotic);
  1844.                     lstGeneralItems.Add(liUnarmed);
  1845.                     frmPickCategory.GeneralItems = lstGeneralItems;
  1846.  
  1847.                     if (strFriendlyName != "")
  1848.                         frmPickCategory.Description =
  1849.                             LanguageManager.Instance.GetString("String_Improvement_SelectSkillNamed").Replace("{0}", strFriendlyName);
  1850.                     else
  1851.                         frmPickCategory.Description = LanguageManager.Instance.GetString("Title_SelectWeaponCategory");
  1852.  
  1853.                     Log.Info("_strForcedValue = " + _strForcedValue);
  1854.  
  1855.                     if (_strForcedValue.StartsWith("Adept:") || _strForcedValue.StartsWith("Magician:"))
  1856.                         _strForcedValue = "";
  1857.  
  1858.                     if (_strForcedValue != "")
  1859.                     {
  1860.                         frmPickCategory.Opacity = 0;
  1861.                     }
  1862.                     frmPickCategory.ShowDialog();
  1863.  
  1864.                     // Make sure the dialogue window was not canceled.
  1865.                     if (frmPickCategory.DialogResult == DialogResult.Cancel)
  1866.                     {
  1867.                         Rollback();
  1868.                         _strForcedValue = "";
  1869.                         _strLimitSelection = "";
  1870.                         return false;
  1871.                     }
  1872.  
  1873.                     _strSelectedValue = frmPickCategory.SelectedItem;
  1874.  
  1875.                     Log.Info("strSelected = " + _strSelectedValue);
  1876.  
  1877.                     foreach (Power objPower in _objCharacter.Powers)
  1878.                     {
  1879.                         if (objPower.InternalId == strSourceName)
  1880.                         {
  1881.                             objPower.Extra = _strSelectedValue;
  1882.                         }
  1883.                     }
  1884.  
  1885.                     Log.Info("Calling CreateImprovement");
  1886.                     CreateImprovement(_strSelectedValue, objImprovementSource, strSourceName,
  1887.                         Improvement.ImprovementType.WeaponCategoryDV, strUnique, ValueToInt(nodWeapon["bonus"].InnerXml, intRating));
  1888.                 }
  1889.                 else
  1890.                 {
  1891.                     // Run through each of the Skill Groups since there may be more than one affected.
  1892.                     foreach (XmlNode objXmlCategory in objXmlCategoryList)
  1893.                     {
  1894.                         Log.Info("Calling CreateImprovement");
  1895.                         CreateImprovement(objXmlCategory["name"].InnerText, objImprovementSource, strSourceName,
  1896.                             Improvement.ImprovementType.WeaponCategoryDV, strUnique, ValueToInt(objXmlCategory["bonus"].InnerXml, intRating));
  1897.                     }
  1898.                 }
  1899.             }
  1900.  
  1901.             // Check for Mentor Spirit bonuses.
  1902.             if (bonusNode.LocalName == ("selectmentorspirit"))
  1903.             {
  1904.                 Log.Info("selectmentorspirit");
  1905.                 Log.Info("selectmentorspirit = " + bonusNode.OuterXml.ToString());
  1906.                 frmSelectMentorSpirit frmPickMentorSpirit = new frmSelectMentorSpirit(_objCharacter);
  1907.                 frmPickMentorSpirit.ShowDialog();
  1908.  
  1909.                 // Make sure the dialogue window was not canceled.
  1910.                 if (frmPickMentorSpirit.DialogResult == DialogResult.Cancel)
  1911.                 {
  1912.                     Rollback();
  1913.                     _strForcedValue = "";
  1914.                     _strLimitSelection = "";
  1915.                     return false;
  1916.                 }
  1917.  
  1918.                 _strSelectedValue = frmPickMentorSpirit.SelectedMentor;
  1919.  
  1920.                 string strHoldValue = _strSelectedValue;
  1921.                 if (blnConcatSelectedValue)
  1922.                     strSourceName += " (" + _strSelectedValue + ")";
  1923.  
  1924.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  1925.                 Log.Info("strSourceName = " + strSourceName);
  1926.  
  1927.                 if (frmPickMentorSpirit.BonusNode != null)
  1928.                 {
  1929.                     if (!CreateImprovements(objImprovementSource, strSourceName, frmPickMentorSpirit.BonusNode,
  1930.                         blnConcatSelectedValue, intRating, strFriendlyName))
  1931.                     {
  1932.                         Rollback();
  1933.                         _strForcedValue = "";
  1934.                         _strLimitSelection = "";
  1935.                         return false;
  1936.                     }
  1937.                 }
  1938.  
  1939.                 if (frmPickMentorSpirit.Choice1BonusNode != null)
  1940.                 {
  1941.                     Log.Info("frmPickMentorSpirit.Choice1BonusNode = " + frmPickMentorSpirit.Choice1BonusNode.OuterXml.ToString());
  1942.                     string strForce = _strForcedValue;
  1943.                     if (!frmPickMentorSpirit.Choice1.StartsWith("Adept:") && !frmPickMentorSpirit.Choice1.StartsWith("Magician:"))
  1944.                         _strForcedValue = frmPickMentorSpirit.Choice1;
  1945.                     else
  1946.                         _strForcedValue = "";
  1947.                     Log.Info("Calling CreateImprovement");
  1948.                     bool blnSuccess = CreateImprovements(objImprovementSource, strSourceName, frmPickMentorSpirit.Choice1BonusNode,
  1949.                         blnConcatSelectedValue, intRating, strFriendlyName);
  1950.                     if (!blnSuccess)
  1951.                     {
  1952.                         Rollback();
  1953.                         _strForcedValue = "";
  1954.                         _strLimitSelection = "";
  1955.                         return false;
  1956.                     }
  1957.                     _strForcedValue = strForce;
  1958.                     _objCharacter.Improvements.Last().Notes = frmPickMentorSpirit.Choice1;
  1959.                 }
  1960.  
  1961.                 if (frmPickMentorSpirit.Choice2BonusNode != null)
  1962.                 {
  1963.                     Log.Info("frmPickMentorSpirit.Choice2BonusNode = " + frmPickMentorSpirit.Choice2BonusNode.OuterXml.ToString());
  1964.                     string strForce = _strForcedValue;
  1965.                     if (!frmPickMentorSpirit.Choice2.StartsWith("Adept:") && !frmPickMentorSpirit.Choice2.StartsWith("Magician:"))
  1966.                         _strForcedValue = frmPickMentorSpirit.Choice2;
  1967.                     else
  1968.                         _strForcedValue = "";
  1969.                     Log.Info("Calling CreateImprovement");
  1970.                     bool blnSuccess = CreateImprovements(objImprovementSource, strSourceName, frmPickMentorSpirit.Choice2BonusNode,
  1971.                         blnConcatSelectedValue, intRating, strFriendlyName);
  1972.                     if (!blnSuccess)
  1973.                     {
  1974.                         Rollback();
  1975.                         _strForcedValue = "";
  1976.                         _strLimitSelection = "";
  1977.                         return false;
  1978.                     }
  1979.                     _strForcedValue = strForce;
  1980.                     _objCharacter.Improvements.Last().Notes = frmPickMentorSpirit.Choice2;
  1981.                 }
  1982.  
  1983.                 _strSelectedValue = strHoldValue;
  1984.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  1985.                 Log.Info("_strForcedValue = " + _strForcedValue);
  1986.             }
  1987.  
  1988.             // Check for Paragon bonuses.
  1989.             if (bonusNode.LocalName == ("selectparagon"))
  1990.             {
  1991.                 Log.Info("selectparagon");
  1992.                 Log.Info("selectparagon = " + bonusNode.OuterXml.ToString());
  1993.                 frmSelectMentorSpirit frmPickMentorSpirit = new frmSelectMentorSpirit(_objCharacter);
  1994.                 frmPickMentorSpirit.XmlFile = "paragons.xml";
  1995.                 frmPickMentorSpirit.ShowDialog();
  1996.  
  1997.                 // Make sure the dialogue window was not canceled.
  1998.                 if (frmPickMentorSpirit.DialogResult == DialogResult.Cancel)
  1999.                 {
  2000.                     Rollback();
  2001.                     _strForcedValue = "";
  2002.                     _strLimitSelection = "";
  2003.                     return false;
  2004.                 }
  2005.  
  2006.                 _strSelectedValue = frmPickMentorSpirit.SelectedMentor;
  2007.                 string strHoldValue = _strSelectedValue;
  2008.                 if (blnConcatSelectedValue)
  2009.                     strSourceName += " (" + _strSelectedValue + ")";
  2010.  
  2011.                 if (frmPickMentorSpirit.BonusNode != null)
  2012.                 {
  2013.                     bool blnSuccess = CreateImprovements(objImprovementSource, strSourceName, frmPickMentorSpirit.BonusNode,
  2014.                         blnConcatSelectedValue, intRating, strFriendlyName);
  2015.                     if (!blnSuccess)
  2016.                     {
  2017.                         Rollback();
  2018.                         _strForcedValue = "";
  2019.                         _strLimitSelection = "";
  2020.                         return false;
  2021.                     }
  2022.                 }
  2023.  
  2024.                 if (frmPickMentorSpirit.Choice1BonusNode != null)
  2025.                 {
  2026.                     string strForce = _strForcedValue;
  2027.                     _strForcedValue = frmPickMentorSpirit.Choice1;
  2028.                     bool blnSuccess = CreateImprovements(objImprovementSource, strSourceName, frmPickMentorSpirit.Choice1BonusNode,
  2029.                         blnConcatSelectedValue, intRating, strFriendlyName);
  2030.                     if (!blnSuccess)
  2031.                     {
  2032.                         Rollback();
  2033.                         _strForcedValue = "";
  2034.                         _strLimitSelection = "";
  2035.                         return false;
  2036.                     }
  2037.                     _strForcedValue = strForce;
  2038.                     _objCharacter.Improvements.Last().Notes = frmPickMentorSpirit.Choice1;
  2039.                 }
  2040.  
  2041.                 if (frmPickMentorSpirit.Choice2BonusNode != null)
  2042.                 {
  2043.                     string strForce = _strForcedValue;
  2044.                     _strForcedValue = frmPickMentorSpirit.Choice2;
  2045.                     bool blnSuccess = CreateImprovements(objImprovementSource, strSourceName, frmPickMentorSpirit.Choice2BonusNode,
  2046.                         blnConcatSelectedValue, intRating, strFriendlyName);
  2047.                     if (!blnSuccess)
  2048.                     {
  2049.                         Rollback();
  2050.                         _strForcedValue = "";
  2051.                         _strLimitSelection = "";
  2052.                         return false;
  2053.                     }
  2054.                     _strForcedValue = strForce;
  2055.                     _objCharacter.Improvements.Last().Notes = frmPickMentorSpirit.Choice2;
  2056.                 }
  2057.  
  2058.                 _strSelectedValue = strHoldValue;
  2059.             }
  2060.  
  2061.             // Check for Smartlink bonus.
  2062.             if (bonusNode.LocalName == ("smartlink"))
  2063.             {
  2064.                 Log.Info("smartlink");
  2065.                 Log.Info("smartlink = " + bonusNode.OuterXml.ToString());
  2066.                 Log.Info("Calling CreateImprovement");
  2067.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Smartlink, "smartlink");
  2068.             }
  2069.  
  2070.             // Check for Adapsin bonus.
  2071.             if (bonusNode.LocalName == ("adapsin"))
  2072.             {
  2073.                 Log.Info("adapsin");
  2074.                 Log.Info("adapsin = " + bonusNode.OuterXml.ToString());
  2075.                 Log.Info("Calling CreateImprovement");
  2076.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Adapsin, "adapsin");
  2077.             }
  2078.  
  2079.             // Check for SoftWeave bonus.
  2080.             if (bonusNode.LocalName == ("softweave"))
  2081.             {
  2082.                 Log.Info("softweave");
  2083.                 Log.Info("softweave = " + bonusNode.OuterXml.ToString());
  2084.                 Log.Info("Calling CreateImprovement");
  2085.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.SoftWeave, "softweave");
  2086.             }
  2087.  
  2088.             // Check for Sensitive System.
  2089.             if (bonusNode.LocalName == ("sensitivesystem"))
  2090.             {
  2091.                 Log.Info("sensitivesystem");
  2092.                 Log.Info("sensitivesystem = " + bonusNode.OuterXml.ToString());
  2093.                 Log.Info("Calling CreateImprovement");
  2094.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.SensitiveSystem,
  2095.                     "sensitivesystem");
  2096.             }
  2097.  
  2098.             // Check for Movement Percent.
  2099.             if (bonusNode.LocalName == ("movementpercent"))
  2100.             {
  2101.                 Log.Info("movementpercent");
  2102.                 Log.Info("movementpercent = " + bonusNode.OuterXml.ToString());
  2103.                 Log.Info("Calling CreateImprovement");
  2104.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.MovementPercent, "",
  2105.                     ValueToInt(bonusNode.InnerText, intRating));
  2106.             }
  2107.  
  2108.             // Check for Swim Percent.
  2109.             if (bonusNode.LocalName == ("swimpercent"))
  2110.             {
  2111.                 Log.Info("swimpercent");
  2112.                 Log.Info("swimpercent = " + bonusNode.OuterXml.ToString());
  2113.                 Log.Info("Calling CreateImprovement");
  2114.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.SwimPercent, "",
  2115.                     ValueToInt(bonusNode.InnerText, intRating));
  2116.             }
  2117.  
  2118.             // Check for Fly Percent.
  2119.             if (bonusNode.LocalName == ("flypercent"))
  2120.             {
  2121.                 Log.Info("flypercent");
  2122.                 Log.Info("flypercent = " + bonusNode.OuterXml.ToString());
  2123.                 Log.Info("Calling CreateImprovement");
  2124.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.FlyPercent, "",
  2125.                     ValueToInt(bonusNode.InnerText, intRating));
  2126.             }
  2127.  
  2128.             // Check for Fly Speed.
  2129.             if (bonusNode.LocalName == ("flyspeed"))
  2130.             {
  2131.                 Log.Info("flyspeed");
  2132.                 Log.Info("flyspeed = " + bonusNode.OuterXml.ToString());
  2133.                 Log.Info("Calling CreateImprovement");
  2134.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.FlySpeed, "",
  2135.                     ValueToInt(bonusNode.InnerText, intRating));
  2136.             }
  2137.  
  2138.             // Check for free Positive Qualities.
  2139.             if (bonusNode.LocalName == ("freepositivequalities"))
  2140.             {
  2141.                 Log.Info("freepositivequalities");
  2142.                 Log.Info("freepositivequalities = " + bonusNode.OuterXml.ToString());
  2143.                 Log.Info("Calling CreateImprovement");
  2144.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.FreePositiveQualities, "",
  2145.                     ValueToInt(bonusNode.InnerText, intRating));
  2146.             }
  2147.  
  2148.             // Check for free Negative Qualities.
  2149.             if (bonusNode.LocalName == ("freenegativequalities"))
  2150.             {
  2151.                 Log.Info("freenegativequalities");
  2152.                 Log.Info("freenegativequalities = " + bonusNode.OuterXml.ToString());
  2153.                 Log.Info("Calling CreateImprovement");
  2154.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.FreeNegativeQualities, "",
  2155.                     ValueToInt(bonusNode.InnerText, intRating));
  2156.             }
  2157.  
  2158.             // Check for Select Side.
  2159.             if (bonusNode.LocalName == ("selectside"))
  2160.             {
  2161.                 Log.Info("selectside");
  2162.                 Log.Info("selectside = " + bonusNode.OuterXml.ToString());
  2163.                 frmSelectSide frmPickSide = new frmSelectSide();
  2164.                 frmPickSide.Description = LanguageManager.Instance.GetString("Label_SelectSide").Replace("{0}", strFriendlyName);
  2165.                 if (_strForcedValue != "")
  2166.                     frmPickSide.ForceValue(_strForcedValue);
  2167.                 else
  2168.                     frmPickSide.ShowDialog();
  2169.  
  2170.                 // Make sure the dialogue window was not canceled.
  2171.                 if (frmPickSide.DialogResult == DialogResult.Cancel)
  2172.                 {
  2173.                     Rollback();
  2174.                     _strForcedValue = "";
  2175.                     _strLimitSelection = "";
  2176.                     return false;
  2177.                 }
  2178.  
  2179.                 _strSelectedValue = frmPickSide.SelectedSide;
  2180.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  2181.             }
  2182.  
  2183.             // Check for Free Spirit Power Points.
  2184.             if (bonusNode.LocalName == ("freespiritpowerpoints"))
  2185.             {
  2186.                 Log.Info("freespiritpowerpoints");
  2187.                 Log.Info("freespiritpowerpoints = " + bonusNode.OuterXml.ToString());
  2188.                 Log.Info("Calling CreateImprovement");
  2189.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.FreeSpiritPowerPoints, "",
  2190.                     ValueToInt(bonusNode.InnerText, intRating));
  2191.             }
  2192.  
  2193.             // Check for Adept Power Points.
  2194.             if (bonusNode.LocalName == ("adeptpowerpoints"))
  2195.             {
  2196.                 Log.Info("adeptpowerpoints");
  2197.                 Log.Info("adeptpowerpoints = " + bonusNode.OuterXml.ToString());
  2198.                 Log.Info("Calling CreateImprovement");
  2199.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.AdeptPowerPoints, "",
  2200.                     ValueToInt(bonusNode.InnerText, intRating));
  2201.             }
  2202.  
  2203.             // Check for Adept Powers
  2204.             if (bonusNode.LocalName == ("specificpower"))
  2205.             {
  2206.                 //TODO: Probably broken
  2207.                 Log.Info("specificpower");
  2208.                 Log.Info("specificpower = " + bonusNode.OuterXml.ToString());
  2209.                 // If the character isn't an adept or mystic adept, skip the rest of this.
  2210.                 if (_objCharacter.AdeptEnabled)
  2211.                 {
  2212.                     string strSelection = "";
  2213.                     _strForcedValue = "";
  2214.  
  2215.  
  2216.                     Log.Info("objXmlSpecificPower = " + bonusNode.OuterXml.ToString());
  2217.  
  2218.                     string strPowerName = bonusNode["name"].InnerText;
  2219.                     int intLevels = 0;
  2220.                     if (bonusNode["val"] != null)
  2221.                         intLevels = Convert.ToInt32(bonusNode["val"].InnerText);
  2222.                     bool blnFree = false;
  2223.                     if (bonusNode["free"] != null)
  2224.                         blnFree = (bonusNode["free"].InnerText == "yes");
  2225.  
  2226.                     string strPowerNameLimit = strPowerName;
  2227.                     if (bonusNode["selectlimit"] != null)
  2228.                     {
  2229.                         Log.Info("selectlimit = " + bonusNode["selectlimit"].OuterXml.ToString());
  2230.                         _strForcedValue = "";
  2231.                         // Display the Select Limit window and record which Limit was selected.
  2232.                         frmSelectLimit frmPickLimit = new frmSelectLimit();
  2233.                         if (strFriendlyName != "")
  2234.                             frmPickLimit.Description = LanguageManager.Instance.GetString("String_Improvement_SelectLimitNamed")
  2235.                                 .Replace("{0}", strFriendlyName);
  2236.                         else
  2237.                             frmPickLimit.Description = LanguageManager.Instance.GetString("String_Improvement_SelectLimit");
  2238.  
  2239.                         if (bonusNode["selectlimit"].InnerXml.Contains("<limit>"))
  2240.                         {
  2241.                             List<string> strValue = new List<string>();
  2242.                             foreach (XmlNode objXmlAttribute in bonusNode["selectlimit"].SelectNodes("limit"))
  2243.                                 strValue.Add(objXmlAttribute.InnerText);
  2244.                             frmPickLimit.LimitToList(strValue);
  2245.                         }
  2246.  
  2247.                         if (bonusNode["selectlimit"].InnerXml.Contains("<excludelimit>"))
  2248.                         {
  2249.                             List<string> strValue = new List<string>();
  2250.                             foreach (XmlNode objXmlAttribute in bonusNode["selectlimit"].SelectNodes("excludelimit"))
  2251.                                 strValue.Add(objXmlAttribute.InnerText);
  2252.                             frmPickLimit.RemoveFromList(strValue);
  2253.                         }
  2254.  
  2255.                         // Check to see if there is only one possible selection because of _strLimitSelection.
  2256.                         if (_strForcedValue != "")
  2257.                             _strLimitSelection = _strForcedValue;
  2258.  
  2259.                         Log.Info("_strForcedValue = " + _strForcedValue);
  2260.                         Log.Info("_strLimitSelection = " + _strLimitSelection);
  2261.  
  2262.                         if (_strLimitSelection != "")
  2263.                         {
  2264.                             frmPickLimit.SingleLimit(_strLimitSelection);
  2265.                             frmPickLimit.Opacity = 0;
  2266.                         }
  2267.  
  2268.                         frmPickLimit.ShowDialog();
  2269.  
  2270.                         // Make sure the dialogue window was not canceled.
  2271.                         if (frmPickLimit.DialogResult == DialogResult.Cancel)
  2272.                         {
  2273.                             Rollback();
  2274.                             _strForcedValue = "";
  2275.                             _strLimitSelection = "";
  2276.                             return false;
  2277.                         }
  2278.  
  2279.                         _strSelectedValue = frmPickLimit.SelectedLimit;
  2280.                         strSelection = _strSelectedValue;
  2281.                         _strForcedValue = _strSelectedValue;
  2282.  
  2283.                         Log.Info("_strForcedValue = " + _strForcedValue);
  2284.                         Log.Info("_strLimitSelection = " + _strLimitSelection);
  2285.                     }
  2286.  
  2287.                     if (bonusNode["selectskill"] != null)
  2288.                     {
  2289.                         Log.Info("selectskill = " + bonusNode["selectskill"].OuterXml.ToString());
  2290.                         XmlNode nodSkill = bonusNode;
  2291.                         // Display the Select Skill window and record which Skill was selected.
  2292.                         frmSelectSkill frmPickSkill = new frmSelectSkill(_objCharacter);
  2293.                         if (strFriendlyName != "")
  2294.                             frmPickSkill.Description = LanguageManager.Instance.GetString("String_Improvement_SelectSkillNamed")
  2295.                                 .Replace("{0}", strFriendlyName);
  2296.                         else
  2297.                             frmPickSkill.Description = LanguageManager.Instance.GetString("String_Improvement_SelectSkill");
  2298.  
  2299.                         if (nodSkill.SelectSingleNode("selectskill").OuterXml.Contains("skillgroup"))
  2300.                             frmPickSkill.OnlySkillGroup = nodSkill.SelectSingleNode("selectskill").Attributes["skillgroup"].InnerText;
  2301.                         else if (nodSkill.SelectSingleNode("selectskill").OuterXml.Contains("skillcategory"))
  2302.                             frmPickSkill.OnlyCategory = nodSkill.SelectSingleNode("selectskill").Attributes["skillcategory"].InnerText;
  2303.                         else if (nodSkill.SelectSingleNode("selectskill").OuterXml.Contains("excludecategory"))
  2304.                             frmPickSkill.ExcludeCategory = nodSkill.SelectSingleNode("selectskill").Attributes["excludecategory"].InnerText;
  2305.                         else if (nodSkill.SelectSingleNode("selectskill").OuterXml.Contains("limittoskill"))
  2306.                             frmPickSkill.LimitToSkill = nodSkill.SelectSingleNode("selectskill").Attributes["limittoskill"].InnerText;
  2307.  
  2308.                         if (_strForcedValue.StartsWith("Adept:") || _strForcedValue.StartsWith("Magician:"))
  2309.                             _strForcedValue = "";
  2310.  
  2311.                         Log.Info("_strForcedValue = " + _strForcedValue);
  2312.                         Log.Info("_strLimitSelection = " + _strLimitSelection);
  2313.  
  2314.                         if (_strForcedValue != "")
  2315.                         {
  2316.                             frmPickSkill.OnlySkill = _strForcedValue;
  2317.                             frmPickSkill.Opacity = 0;
  2318.                         }
  2319.                         frmPickSkill.ShowDialog();
  2320.  
  2321.                         // Make sure the dialogue window was not canceled.
  2322.                         if (frmPickSkill.DialogResult == DialogResult.Cancel)
  2323.                         {
  2324.                             Rollback();
  2325.                             _strForcedValue = "";
  2326.                             _strLimitSelection = "";
  2327.                             return false;
  2328.                         }
  2329.  
  2330.                         _strSelectedValue = frmPickSkill.SelectedSkill;
  2331.                         _strForcedValue = _strSelectedValue;
  2332.                         strSelection = _strSelectedValue;
  2333.  
  2334.                         Log.Info("_strForcedValue = " + _strForcedValue);
  2335.                         Log.Info("_strSelectedValue = " + _strSelectedValue);
  2336.                         Log.Info("strSelection = " + strSelection);
  2337.                     }
  2338.  
  2339.                     if (bonusNode["selecttext"] != null)
  2340.                     {
  2341.                         Log.Info("selecttext = " + bonusNode["selecttext"].OuterXml.ToString());
  2342.                         frmSelectText frmPickText = new frmSelectText();
  2343.  
  2344.  
  2345.                         if (_objCharacter.Pushtext.Count > 0)
  2346.                         {
  2347.                             strSelection = _objCharacter.Pushtext.Pop();
  2348.                         }
  2349.                         else
  2350.                         {
  2351.                             frmPickText.Description = LanguageManager.Instance.GetString("String_Improvement_SelectText")
  2352.                                 .Replace("{0}", strFriendlyName);
  2353.  
  2354.                             Log.Info("_strForcedValue = " + _strForcedValue);
  2355.                             Log.Info("_strLimitSelection = " + _strLimitSelection);
  2356.  
  2357.                             if (_strLimitSelection != "")
  2358.                             {
  2359.                                 frmPickText.SelectedValue = _strLimitSelection;
  2360.                                 frmPickText.Opacity = 0;
  2361.                             }
  2362.  
  2363.                             frmPickText.ShowDialog();
  2364.  
  2365.                             // Make sure the dialogue window was not canceled.
  2366.                             if (frmPickText.DialogResult == DialogResult.Cancel)
  2367.                             {
  2368.                                 Rollback();
  2369.                                 _strForcedValue = "";
  2370.                                 _strLimitSelection = "";
  2371.                                 return false;
  2372.                             }
  2373.  
  2374.                             strSelection = frmPickText.SelectedValue;
  2375.                             _strLimitSelection = strSelection;
  2376.                         }
  2377.                         Log.Info("_strLimitSelection = " + _strLimitSelection);
  2378.                         Log.Info("strSelection = " + strSelection);
  2379.                     }
  2380.  
  2381.                     if (bonusNode["specificattribute"] != null)
  2382.                     {
  2383.                         Log.Info("specificattribute = " + bonusNode["specificattribute"].OuterXml.ToString());
  2384.                         strSelection = bonusNode["specificattribute"]["name"].InnerText.ToString();
  2385.                         Log.Info(
  2386.                             "strSelection = " + strSelection);
  2387.                     }
  2388.  
  2389.                     if (bonusNode["selectattribute"] != null)
  2390.                     {
  2391.                         Log.Info("selectattribute = " + bonusNode["selectattribute"].OuterXml.ToString());
  2392.                         XmlNode nodSkill = bonusNode;
  2393.                         if (_strForcedValue.StartsWith("Adept"))
  2394.                             _strForcedValue = "";
  2395.  
  2396.                         // Display the Select CharacterAttribute window and record which CharacterAttribute was selected.
  2397.                         frmSelectAttribute frmPickAttribute = new frmSelectAttribute();
  2398.                         if (strFriendlyName != "")
  2399.                             frmPickAttribute.Description =
  2400.                                 LanguageManager.Instance.GetString("String_Improvement_SelectAttributeNamed").Replace("{0}", strFriendlyName);
  2401.                         else
  2402.                             frmPickAttribute.Description = LanguageManager.Instance.GetString("String_Improvement_SelectAttribute");
  2403.  
  2404.                         // Add MAG and/or RES to the list of Attributes if they are enabled on the form.
  2405.                         if (_objCharacter.MAGEnabled)
  2406.                             frmPickAttribute.AddMAG();
  2407.                         if (_objCharacter.RESEnabled)
  2408.                             frmPickAttribute.AddRES();
  2409.  
  2410.                         if (nodSkill["selectattribute"].InnerXml.Contains("<attribute>"))
  2411.                         {
  2412.                             List<string> strValue = new List<string>();
  2413.                             foreach (XmlNode objXmlAttribute in nodSkill["selectattribute"].SelectNodes("attribute"))
  2414.                                 strValue.Add(objXmlAttribute.InnerText);
  2415.                             frmPickAttribute.LimitToList(strValue);
  2416.                         }
  2417.  
  2418.                         if (nodSkill["selectattribute"].InnerXml.Contains("<excludeattribute>"))
  2419.                         {
  2420.                             List<string> strValue = new List<string>();
  2421.                             foreach (XmlNode objXmlAttribute in nodSkill["selectattribute"].SelectNodes("excludeattribute"))
  2422.                                 strValue.Add(objXmlAttribute.InnerText);
  2423.                             frmPickAttribute.RemoveFromList(strValue);
  2424.                         }
  2425.  
  2426.                         // Check to see if there is only one possible selection because of _strLimitSelection.
  2427.                         if (_strForcedValue != "")
  2428.                             _strLimitSelection = _strForcedValue;
  2429.  
  2430.                         Log.Info("_strForcedValue = " + _strForcedValue);
  2431.                         Log.Info("_strLimitSelection = " + _strLimitSelection);
  2432.  
  2433.                         if (_strLimitSelection != "")
  2434.                         {
  2435.                             frmPickAttribute.SingleAttribute(_strLimitSelection);
  2436.                             frmPickAttribute.Opacity = 0;
  2437.                         }
  2438.  
  2439.                         frmPickAttribute.ShowDialog();
  2440.  
  2441.                         // Make sure the dialogue window was not canceled.
  2442.                         if (frmPickAttribute.DialogResult == DialogResult.Cancel)
  2443.                         {
  2444.                             Rollback();
  2445.                             _strForcedValue = "";
  2446.                             _strLimitSelection = "";
  2447.                             return false;
  2448.                         }
  2449.  
  2450.                         _strSelectedValue = frmPickAttribute.SelectedAttribute;
  2451.                         if (blnConcatSelectedValue)
  2452.                             strSourceName += " (" + _strSelectedValue + ")";
  2453.                         strSelection = _strSelectedValue;
  2454.                         _strForcedValue = _strSelectedValue;
  2455.  
  2456.                         Log.Info("_strSelectedValue = " + _strSelectedValue);
  2457.                         Log.Info("strSourceName = " + strSourceName);
  2458.                         Log.Info("_strForcedValue = " + _strForcedValue);
  2459.                     }
  2460.  
  2461.                     // Check if the character already has this power
  2462.                     Log.Info("strSelection = " + strSelection);
  2463.                     bool blnHasPower = false;
  2464.                     Power objPower = new Power(_objCharacter);
  2465.                     foreach (Power power in _objCharacter.Powers)
  2466.                     {
  2467.                         if (power.Name == strPowerNameLimit)
  2468.                         {
  2469.                             if (power.Extra != "" && power.Extra == strSelection)
  2470.                             {
  2471.                                 blnHasPower = true;
  2472.                                 objPower = power;
  2473.                             }
  2474.                             else if (power.Extra == "")
  2475.                             {
  2476.                                 blnHasPower = true;
  2477.                                 objPower = power;
  2478.                             }
  2479.                         }
  2480.                     }
  2481.  
  2482.                     Log.Info("blnHasPower = " + blnHasPower);
  2483.  
  2484.                     if (blnHasPower)
  2485.                     {
  2486.                         // If yes, mark it free or give it free levels
  2487.                         if (blnFree)
  2488.                         {
  2489.                             objPower.Free = true;
  2490.                         }
  2491.                         else
  2492.                         {
  2493.                             objPower.FreeLevels += intLevels;
  2494.                             if (objPower.Rating < objPower.FreeLevels)
  2495.                                 objPower.Rating = objPower.FreeLevels;
  2496.                         }
  2497.                     }
  2498.                     else
  2499.                     {
  2500.                         Log.Info("Adding Power " + strPowerName);
  2501.                         // If no, add the power and mark it free or give it free levels
  2502.                         objPower = new Power(_objCharacter);
  2503.                         _objCharacter.Powers.Add(objPower);
  2504.  
  2505.                         // Get the Power information
  2506.                         XmlDocument objXmlDocument = new XmlDocument();
  2507.                         objXmlDocument = XmlManager.Instance.Load("powers.xml");
  2508.                         XmlNode objXmlPower = objXmlDocument.SelectSingleNode("/chummer/powers/power[name = \"" + strPowerName + "\"]");
  2509.                         Log.Info("objXmlPower = " + objXmlPower.OuterXml.ToString());
  2510.  
  2511.                         bool blnLevels = false;
  2512.                         if (objXmlPower["levels"] != null)
  2513.                             blnLevels = (objXmlPower["levels"].InnerText != "no");
  2514.                         objPower.LevelsEnabled = blnLevels;
  2515.                         objPower.Name = strPowerNameLimit;
  2516.                         if (strSelection != string.Empty)
  2517.                             objPower.Extra = strSelection;
  2518.                         if (objXmlPower["doublecost"] != null)
  2519.                             objPower.DoubleCost = false;
  2520.                         objPower.PointsPerLevel = Convert.ToDecimal(objXmlPower["points"].InnerText, GlobalOptions.Instance.CultureInfo);
  2521.                         objPower.Source = objXmlPower["source"].InnerText;
  2522.                         objPower.Page = objXmlPower["page"].InnerText;
  2523.  
  2524.                         if (objPower.LevelsEnabled)
  2525.                         {
  2526.                             if (objPower.Name == "Improved Ability (skill)")
  2527.                             {
  2528.                                     foreach (Skill objSkill in _objCharacter.SkillsSection.Skills)
  2529.                                     {
  2530.                                         if (objPower.Extra == objSkill.Name ||
  2531.                                             (objSkill.IsExoticSkill &&
  2532.                                              objPower.Extra == (objSkill.DisplayName + " (" + (objSkill as ExoticSkill).Specific + ")")))
  2533.                                         {
  2534.                                             int intImprovedAbilityMaximum = objSkill.Rating + (objSkill.Rating/2);
  2535.                                             if (intImprovedAbilityMaximum == 0)
  2536.                                             {
  2537.                                                 intImprovedAbilityMaximum = 1;
  2538.                                             }
  2539.                                             objPower.MaxLevels = intImprovedAbilityMaximum;
  2540.                                         }
  2541.                                     }
  2542.                             }
  2543.                             else if(objXmlPower["levels"].InnerText == "yes")
  2544.                             {
  2545.                                 objPower.MaxLevels = Convert.ToInt32(objXmlPower["levels"].InnerText);
  2546.                             }
  2547.                         }
  2548.  
  2549.                         if (blnFree && objPower.MaxLevels == 0)
  2550.                         {
  2551.                             objPower.Free = true;
  2552.                         }
  2553.                         else
  2554.                         {
  2555.                             objPower.FreeLevels += intLevels;
  2556.                             if (objPower.Rating < intLevels)
  2557.                                 objPower.Rating = objPower.FreeLevels;
  2558.                         }
  2559.  
  2560.                         if (objXmlPower.InnerXml.Contains("bonus"))
  2561.                         {
  2562.                             objPower.Bonus = objXmlPower["bonus"];
  2563.                             Log.Info("Calling CreateImprovements");
  2564.                             if (
  2565.                                 !CreateImprovements(Improvement.ImprovementSource.Power, objPower.InternalId, objPower.Bonus, false,
  2566.                                     Convert.ToInt32(objPower.Rating), objPower.DisplayNameShort))
  2567.                             {
  2568.                                 _objCharacter.Powers.Remove(objPower);
  2569.                             }
  2570.                         }
  2571.                     }
  2572.                     _strSelectedValue = "";
  2573.                     _strForcedValue = "";
  2574.                     strSelection = "";
  2575.                 }
  2576.                 Log.Info("Calling CreateImprovement");
  2577.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.AdeptPower, "");
  2578.             }
  2579.  
  2580.             // Select a Power.
  2581.             if (bonusNode.LocalName == ("selectpowers"))
  2582.             {
  2583.                 XmlNodeList objXmlPowerList = bonusNode.SelectNodes("selectpower");
  2584.                 foreach (XmlNode objNode in objXmlPowerList)
  2585.                 {
  2586.                     Log.Info("selectpower");
  2587.                     Log.Info("_strSelectedValue = " + _strSelectedValue);
  2588.                     Log.Info("_strForcedValue = " + _strForcedValue);
  2589.  
  2590.                     //Gerry: These unfortunately did not work in any case of multiple bonuses
  2591.                     // Switched the setting of powerpoints and levels to ADDING them
  2592.                     // Remove resetting powerpoints.
  2593.                     bool blnExistingPower = false;
  2594.                     foreach (Power objExistingPower in _objCharacter.Powers)
  2595.                     {
  2596.                         if (objExistingPower.Name.StartsWith("Improved Reflexes"))
  2597.                         {
  2598.                             if (objExistingPower.Name.EndsWith("1"))
  2599.                             {
  2600.                                 if (objExistingPower.Name.EndsWith("1"))
  2601.                                 {
  2602.                                     if (intRating >= 6)
  2603.                                         objExistingPower.FreePoints += 1.5M;
  2604.                                     //else
  2605.                                     //  objExistingPower.FreePoints = 0;
  2606.                                 }
  2607.                                 else if (objExistingPower.Name.EndsWith("2"))
  2608.                                 {
  2609.                                     if (intRating >= 10)
  2610.                                         objExistingPower.FreePoints += 2.5M;
  2611.                                     else if (intRating >= 4)
  2612.                                         objExistingPower.FreePoints += 1.0M;
  2613.                                     //else
  2614.                                     //  objExistingPower.FreePoints = 0;
  2615.                                 }
  2616.                                 else
  2617.                                 {
  2618.                                     if (intRating >= 14)
  2619.                                         objExistingPower.FreePoints += 3.5M;
  2620.                                     else if (intRating >= 8)
  2621.                                         objExistingPower.FreePoints += 2.0M;
  2622.                                     else if (intRating >= 4)
  2623.                                         objExistingPower.FreePoints += 1.0M;
  2624.                                     //else
  2625.                                     //  objExistingPower.FreePoints = 0;
  2626.                                 }
  2627.                             }
  2628.                             else
  2629.                             {
  2630.                                 // we have to adjust the number of free levels.
  2631.                                 decimal decLevels = Convert.ToDecimal(intRating)/4;
  2632.                                 decLevels = Math.Floor(decLevels/objExistingPower.PointsPerLevel);
  2633.                                 objExistingPower.FreeLevels += Convert.ToInt32(decLevels);
  2634.                                 if (objExistingPower.Rating < intRating)
  2635.                                     objExistingPower.Rating = objExistingPower.FreeLevels;
  2636.                                 break;
  2637.                             }
  2638.                         }
  2639.                         else
  2640.                         {
  2641.                             // we have to adjust the number of free levels.
  2642.                             decimal decLevels = Convert.ToDecimal(intRating)/4;
  2643.                             decLevels = Math.Floor(decLevels/objExistingPower.PointsPerLevel);
  2644.                             objExistingPower.FreeLevels = Convert.ToInt32(decLevels);
  2645.                             if (objExistingPower.Rating < intRating)
  2646.                                 objExistingPower.Rating = objExistingPower.FreeLevels;
  2647.                             break;
  2648.                         }
  2649.                         //}
  2650.                     }
  2651.  
  2652.                     if (!blnExistingPower)
  2653.                     {
  2654.                         // Display the Select Skill window and record which Skill was selected.
  2655.                         frmSelectPower frmPickPower = new frmSelectPower(_objCharacter);
  2656.                         Log.Info("selectpower = " + objNode.OuterXml.ToString());
  2657.  
  2658.                         if (objNode.OuterXml.Contains("limittopowers"))
  2659.                             frmPickPower.LimitToPowers = objNode.Attributes["limittopowers"].InnerText;
  2660.                         frmPickPower.ShowDialog();
  2661.  
  2662.                         // Make sure the dialogue window was not canceled.
  2663.                         if (frmPickPower.DialogResult == DialogResult.Cancel)
  2664.                         {
  2665.                             Rollback();
  2666.                             _strForcedValue = "";
  2667.                             _strLimitSelection = "";
  2668.                             return false;
  2669.                         }
  2670.  
  2671.                         _strSelectedValue = frmPickPower.SelectedPower;
  2672.                         if (blnConcatSelectedValue)
  2673.                             strSourceName += " (" + _strSelectedValue + ")";
  2674.  
  2675.                         XmlDocument objXmlDocument = XmlManager.Instance.Load("powers.xml");
  2676.                         XmlNode objXmlPower =
  2677.                             objXmlDocument.SelectSingleNode("/chummer/powers/power[name = \"" + _strSelectedValue + "\"]");
  2678.                         string strSelection = "";
  2679.  
  2680.                         Log.Info("_strSelectedValue = " + _strSelectedValue);
  2681.                         Log.Info("strSourceName = " + strSourceName);
  2682.  
  2683.                         XmlNode objBonus = objXmlPower["bonus"];
  2684.  
  2685.                         string strPowerNameLimit = _strSelectedValue;
  2686.                         if (objBonus != null)
  2687.                         {
  2688.                             if (objBonus["selectlimit"] != null)
  2689.                             {
  2690.                                 Log.Info("selectlimit = " + objBonus["selectlimit"].OuterXml.ToString());
  2691.                                 _strForcedValue = "";
  2692.                                 // Display the Select Limit window and record which Limit was selected.
  2693.                                 frmSelectLimit frmPickLimit = new frmSelectLimit();
  2694.                                 if (strFriendlyName != "")
  2695.                                     frmPickLimit.Description = LanguageManager.Instance.GetString("String_Improvement_SelectLimitNamed")
  2696.                                         .Replace("{0}", strFriendlyName);
  2697.                                 else
  2698.                                     frmPickLimit.Description = LanguageManager.Instance.GetString("String_Improvement_SelectLimit");
  2699.  
  2700.                                 if (objBonus["selectlimit"].InnerXml.Contains("<limit>"))
  2701.                                 {
  2702.                                     List<string> strValue = new List<string>();
  2703.                                     foreach (XmlNode objXmlAttribute in objBonus["selectlimit"].SelectNodes("limit"))
  2704.                                         strValue.Add(objXmlAttribute.InnerText);
  2705.                                     frmPickLimit.LimitToList(strValue);
  2706.                                 }
  2707.  
  2708.                                 if (objBonus["selectlimit"].InnerXml.Contains("<excludelimit>"))
  2709.                                 {
  2710.                                     List<string> strValue = new List<string>();
  2711.                                     foreach (XmlNode objXmlAttribute in objBonus["selectlimit"].SelectNodes("excludelimit"))
  2712.                                         strValue.Add(objXmlAttribute.InnerText);
  2713.                                     frmPickLimit.RemoveFromList(strValue);
  2714.                                 }
  2715.  
  2716.                                 // Check to see if there is only one possible selection because of _strLimitSelection.
  2717.                                 if (_strForcedValue != "")
  2718.                                     _strLimitSelection = _strForcedValue;
  2719.  
  2720.                                 Log.Info("_strForcedValue = " + _strForcedValue);
  2721.                                 Log.Info("_strLimitSelection = " + _strLimitSelection);
  2722.  
  2723.                                 if (_strLimitSelection != "")
  2724.                                 {
  2725.                                     frmPickLimit.SingleLimit(_strLimitSelection);
  2726.                                     frmPickLimit.Opacity = 0;
  2727.                                 }
  2728.  
  2729.                                 frmPickLimit.ShowDialog();
  2730.  
  2731.                                 // Make sure the dialogue window was not canceled.
  2732.                                 if (frmPickLimit.DialogResult == DialogResult.Cancel)
  2733.                                 {
  2734.                                     Rollback();
  2735.                                     _strForcedValue = "";
  2736.                                     _strLimitSelection = "";
  2737.                                     return false;
  2738.                                 }
  2739.  
  2740.                                 _strSelectedValue = frmPickLimit.SelectedLimit;
  2741.                                 strSelection = _strSelectedValue;
  2742.                                 _strForcedValue = _strSelectedValue;
  2743.  
  2744.                                 Log.Info("_strForcedValue = " + _strForcedValue);
  2745.                                 Log.Info("_strLimitSelection = " + _strLimitSelection);
  2746.                             }
  2747.  
  2748.                             if (objBonus["selectskill"] != null)
  2749.                             {
  2750.                                 Log.Info("selectskill = " + objBonus["selectskill"].OuterXml.ToString());
  2751.                                 XmlNode nodSkill = objBonus;
  2752.                                 // Display the Select Skill window and record which Skill was selected.
  2753.                                 frmSelectSkill frmPickSkill = new frmSelectSkill(_objCharacter);
  2754.                                 if (strFriendlyName != "")
  2755.                                     frmPickSkill.Description = LanguageManager.Instance.GetString("String_Improvement_SelectSkillNamed")
  2756.                                         .Replace("{0}", strFriendlyName);
  2757.                                 else
  2758.                                     frmPickSkill.Description = LanguageManager.Instance.GetString("String_Improvement_SelectSkill");
  2759.  
  2760.                                 if (nodSkill.SelectSingleNode("selectskill").OuterXml.Contains("skillgroup"))
  2761.                                     frmPickSkill.OnlySkillGroup = nodSkill.SelectSingleNode("selectskill").Attributes["skillgroup"].InnerText;
  2762.                                 else if (nodSkill.SelectSingleNode("selectskill").OuterXml.Contains("skillcategory"))
  2763.                                     frmPickSkill.OnlyCategory = nodSkill.SelectSingleNode("selectskill").Attributes["skillcategory"].InnerText;
  2764.                                 else if (nodSkill.SelectSingleNode("selectskill").OuterXml.Contains("excludecategory"))
  2765.                                     frmPickSkill.ExcludeCategory = nodSkill.SelectSingleNode("selectskill").Attributes["excludecategory"].InnerText;
  2766.                                 else if (nodSkill.SelectSingleNode("selectskill").OuterXml.Contains("limittoskill"))
  2767.                                     frmPickSkill.LimitToSkill = nodSkill.SelectSingleNode("selectskill").Attributes["limittoskill"].InnerText;
  2768.  
  2769.                                 if (_strForcedValue.StartsWith("Adept:") || _strForcedValue.StartsWith("Magician:"))
  2770.                                     _strForcedValue = "";
  2771.  
  2772.                                 Log.Info("_strForcedValue = " + _strForcedValue);
  2773.                                 Log.Info("_strLimitSelection = " + _strLimitSelection);
  2774.  
  2775.                                 if (_strForcedValue != "")
  2776.                                 {
  2777.                                     frmPickSkill.OnlySkill = _strForcedValue;
  2778.                                     frmPickSkill.Opacity = 0;
  2779.                                 }
  2780.                                 frmPickSkill.ShowDialog();
  2781.  
  2782.                                 // Make sure the dialogue window was not canceled.
  2783.                                 if (frmPickSkill.DialogResult == DialogResult.Cancel)
  2784.                                 {
  2785.                                     Rollback();
  2786.                                     _strForcedValue = "";
  2787.                                     _strLimitSelection = "";
  2788.                                     return false;
  2789.                                 }
  2790.  
  2791.                                 _strSelectedValue = frmPickSkill.SelectedSkill;
  2792.                                 _strForcedValue = _strSelectedValue;
  2793.                                 strSelection = _strSelectedValue;
  2794.  
  2795.                                 Log.Info("_strForcedValue = " + _strForcedValue);
  2796.                                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  2797.                                 Log.Info("strSelection = " + strSelection);
  2798.                             }
  2799.  
  2800.                             if (objBonus["selecttext"] != null)
  2801.                             {
  2802.                                 Log.Info("selecttext = " + objBonus["selecttext"].OuterXml.ToString());
  2803.                                 frmSelectText frmPickText = new frmSelectText();
  2804.                                 frmPickText.Description = LanguageManager.Instance.GetString("String_Improvement_SelectText")
  2805.                                     .Replace("{0}", strFriendlyName);
  2806.  
  2807.                                 Log.Info("_strForcedValue = " + _strForcedValue);
  2808.                                 Log.Info("_strLimitSelection = " + _strLimitSelection);
  2809.  
  2810.                                 if (_strLimitSelection != "")
  2811.                                 {
  2812.                                     frmPickText.SelectedValue = _strLimitSelection;
  2813.                                     frmPickText.Opacity = 0;
  2814.                                 }
  2815.  
  2816.                                 frmPickText.ShowDialog();
  2817.  
  2818.                                 // Make sure the dialogue window was not canceled.
  2819.                                 if (frmPickText.DialogResult == DialogResult.Cancel)
  2820.                                 {
  2821.                                     Rollback();
  2822.                                     _strForcedValue = "";
  2823.                                     _strLimitSelection = "";
  2824.                                     return false;
  2825.                                 }
  2826.  
  2827.                                 strSelection = frmPickText.SelectedValue;
  2828.                                 _strLimitSelection = strSelection;
  2829.  
  2830.                                 Log.Info("_strLimitSelection = " + _strLimitSelection);
  2831.                                 Log.Info("strSelection = " + strSelection);
  2832.                             }
  2833.  
  2834.                             if (objBonus["specificattribute"] != null)
  2835.                             {
  2836.                                 Log.Info("specificattribute = " + objBonus["specificattribute"].OuterXml.ToString());
  2837.                                 strSelection = objBonus["specificattribute"]["name"].InnerText.ToString();
  2838.                                 Log.Info("strSelection = " + strSelection);
  2839.                             }
  2840.  
  2841.                             if (objBonus["selectattribute"] != null)
  2842.                             {
  2843.                                 Log.Info("selectattribute = " + objBonus["selectattribute"].OuterXml.ToString());
  2844.                                 XmlNode nodSkill = objBonus;
  2845.                                 if (_strForcedValue.StartsWith("Adept"))
  2846.                                     _strForcedValue = "";
  2847.  
  2848.                                 // Display the Select CharacterAttribute window and record which CharacterAttribute was selected.
  2849.                                 frmSelectAttribute frmPickAttribute = new frmSelectAttribute();
  2850.                                 if (strFriendlyName != "")
  2851.                                     frmPickAttribute.Description =
  2852.                                         LanguageManager.Instance.GetString("String_Improvement_SelectAttributeNamed").Replace("{0}", strFriendlyName);
  2853.                                 else
  2854.                                     frmPickAttribute.Description = LanguageManager.Instance.GetString("String_Improvement_SelectAttribute");
  2855.  
  2856.                                 // Add MAG and/or RES to the list of Attributes if they are enabled on the form.
  2857.                                 if (_objCharacter.MAGEnabled)
  2858.                                     frmPickAttribute.AddMAG();
  2859.                                 if (_objCharacter.RESEnabled)
  2860.                                     frmPickAttribute.AddRES();
  2861.  
  2862.                                 if (nodSkill["selectattribute"].InnerXml.Contains("<attribute>"))
  2863.                                 {
  2864.                                     List<string> strValue = new List<string>();
  2865.                                     foreach (XmlNode objXmlAttribute in nodSkill["selectattribute"].SelectNodes("attribute"))
  2866.                                         strValue.Add(objXmlAttribute.InnerText);
  2867.                                     frmPickAttribute.LimitToList(strValue);
  2868.                                 }
  2869.  
  2870.                                 if (nodSkill["selectattribute"].InnerXml.Contains("<excludeattribute>"))
  2871.                                 {
  2872.                                     List<string> strValue = new List<string>();
  2873.                                     foreach (XmlNode objXmlAttribute in nodSkill["selectattribute"].SelectNodes("excludeattribute"))
  2874.                                         strValue.Add(objXmlAttribute.InnerText);
  2875.                                     frmPickAttribute.RemoveFromList(strValue);
  2876.                                 }
  2877.  
  2878.                                 // Check to see if there is only one possible selection because of _strLimitSelection.
  2879.                                 if (_strForcedValue != "")
  2880.                                     _strLimitSelection = _strForcedValue;
  2881.  
  2882.                                 Log.Info("_strForcedValue = " + _strForcedValue);
  2883.                                 Log.Info("_strLimitSelection = " + _strLimitSelection);
  2884.  
  2885.                                 if (_strLimitSelection != "")
  2886.                                 {
  2887.                                     frmPickAttribute.SingleAttribute(_strLimitSelection);
  2888.                                     frmPickAttribute.Opacity = 0;
  2889.                                 }
  2890.  
  2891.                                 frmPickAttribute.ShowDialog();
  2892.  
  2893.                                 // Make sure the dialogue window was not canceled.
  2894.                                 if (frmPickAttribute.DialogResult == DialogResult.Cancel)
  2895.                                 {
  2896.                                     Rollback();
  2897.                                     _strForcedValue = "";
  2898.                                     _strLimitSelection = "";
  2899.                                     return false;
  2900.                                 }
  2901.  
  2902.                                 _strSelectedValue = frmPickAttribute.SelectedAttribute;
  2903.                                 if (blnConcatSelectedValue)
  2904.                                     strSourceName += " (" + _strSelectedValue + ")";
  2905.                                 strSelection = _strSelectedValue;
  2906.                                 _strForcedValue = _strSelectedValue;
  2907.  
  2908.                                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  2909.                                 Log.Info("strSourceName = " + strSourceName);
  2910.                                 Log.Info("_strForcedValue = " + _strForcedValue);
  2911.                             }
  2912.                         }
  2913.  
  2914.                         // If no, add the power and mark it free or give it free levels
  2915.                         Power objPower = new Power(_objCharacter);
  2916.                         bool blnHasPower = false;
  2917.  
  2918.                         foreach (Power power in _objCharacter.Powers)
  2919.                         {
  2920.                             if (power.Name == objXmlPower["name"].InnerText)
  2921.                             {
  2922.                                 if (power.Extra != "" && power.Extra == strSelection)
  2923.                                 {
  2924.                                     blnHasPower = true;
  2925.                                     objPower = power;
  2926.                                 }
  2927.                                 else if (power.Extra == "")
  2928.                                 {
  2929.                                     blnHasPower = true;
  2930.                                     objPower = power;
  2931.                                 }
  2932.                             }
  2933.                         }
  2934.  
  2935.                         Log.Info("blnHasPower = " + blnHasPower);
  2936.  
  2937.                         if (blnHasPower)
  2938.                         {
  2939.                             // If yes, mark it free or give it free levels
  2940.                             if (objXmlPower["levels"].InnerText == "no")
  2941.                             {
  2942.                                 if (objPower.Name.StartsWith("Improved Reflexes"))
  2943.                                 {
  2944.                                     if (objPower.Name.EndsWith("1"))
  2945.                                     {
  2946.                                         if (intRating >= 6)
  2947.                                             objPower.FreePoints = 1.5M;
  2948.                                         else
  2949.                                             objPower.FreePoints = 0;
  2950.                                     }
  2951.                                     else if (objPower.Name.EndsWith("2"))
  2952.                                     {
  2953.                                         if (intRating >= 10)
  2954.                                             objPower.FreePoints = 2.5M;
  2955.                                         else if (intRating >= 4)
  2956.                                             objPower.FreePoints = 1.0M;
  2957.                                         else
  2958.                                             objPower.FreePoints = 0;
  2959.                                     }
  2960.                                     else
  2961.                                     {
  2962.                                         if (intRating >= 14)
  2963.                                             objPower.FreePoints = 3.5M;
  2964.                                         else if (intRating >= 8)
  2965.                                             objPower.FreePoints = 2.0M;
  2966.                                         else if (intRating >= 4)
  2967.                                             objPower.FreePoints = 1.0M;
  2968.                                         else
  2969.                                             objPower.FreePoints = 0;
  2970.                                     }
  2971.                                 }
  2972.                                 else
  2973.                                 {
  2974.                                     objPower.Free = true;
  2975.                                 }
  2976.                             }
  2977.                             else
  2978.                             {
  2979.                                 decimal decLevels = Convert.ToDecimal(intRating)/4;
  2980.                                 decLevels = Math.Floor(decLevels/objPower.PointsPerLevel);
  2981.                                 objPower.FreeLevels += Convert.ToInt32(decLevels);
  2982.                                 objPower.Rating += Convert.ToInt32(decLevels);
  2983.                             }
  2984.                             objPower.BonusSource = strSourceName;
  2985.                         }
  2986.                         else
  2987.                         {
  2988.                             Log.Info("Adding Power " + _strSelectedValue);
  2989.                             // Get the Power information
  2990.                             _objCharacter.Powers.Add(objPower);
  2991.                             Log.Info("objXmlPower = " + objXmlPower.OuterXml.ToString());
  2992.  
  2993.                             bool blnLevels = false;
  2994.                             if (objXmlPower["levels"] != null)
  2995.                                 blnLevels = (objXmlPower["levels"].InnerText == "yes");
  2996.                             objPower.LevelsEnabled = blnLevels;
  2997.                             objPower.Name = objXmlPower["name"].InnerText;
  2998.                             objPower.PointsPerLevel = Convert.ToDecimal(objXmlPower["points"].InnerText, GlobalOptions.Instance.CultureInfo);
  2999.                             objPower.Source = objXmlPower["source"].InnerText;
  3000.                             objPower.Page = objXmlPower["page"].InnerText;
  3001.                             objPower.BonusSource = strSourceName;
  3002.                             if (strSelection != string.Empty)
  3003.                                 objPower.Extra = strSelection;
  3004.                             if (objXmlPower["doublecost"] != null)
  3005.                                 objPower.DoubleCost = false;
  3006.  
  3007.                             if (objXmlPower["levels"].InnerText == "no")
  3008.                             {
  3009.                                 if (objPower.Name.StartsWith("Improved Reflexes"))
  3010.                                 {
  3011.                                     if (objPower.Name.EndsWith("1"))
  3012.                                     {
  3013.                                         if (intRating >= 6)
  3014.                                             objPower.FreePoints = 1.5M;
  3015.                                         else
  3016.                                             objPower.FreePoints = 0;
  3017.                                     }
  3018.                                     else if (objPower.Name.EndsWith("2"))
  3019.                                     {
  3020.                                         if (intRating >= 10)
  3021.                                             objPower.FreePoints = 2.5M;
  3022.                                         else if (intRating >= 4)
  3023.                                             objPower.FreePoints = 1.0M;
  3024.                                         else
  3025.                                             objPower.FreePoints = 0;
  3026.                                     }
  3027.                                     else
  3028.                                     {
  3029.                                         if (intRating >= 14)
  3030.                                             objPower.FreePoints = 3.5M;
  3031.                                         else if (intRating >= 8)
  3032.                                             objPower.FreePoints = 2.0M;
  3033.                                         else if (intRating >= 4)
  3034.                                             objPower.FreePoints = 1.0M;
  3035.                                         else
  3036.                                             objPower.FreePoints = 0;
  3037.                                     }
  3038.                                 }
  3039.                                 else
  3040.                                 {
  3041.                                     objPower.Free = true;
  3042.                                 }
  3043.                             }
  3044.                             else
  3045.                             {
  3046.                                 decimal decLevels = Convert.ToDecimal(intRating)/4;
  3047.                                 decLevels = Math.Floor(decLevels/objPower.PointsPerLevel);
  3048.                                 objPower.FreeLevels += Convert.ToInt32(decLevels);
  3049.                                 if (objPower.Rating < intRating)
  3050.                                     objPower.Rating = objPower.FreeLevels;
  3051.                             }
  3052.  
  3053.                             if (objXmlPower.InnerXml.Contains("bonus"))
  3054.                             {
  3055.                                 objPower.Bonus = objXmlPower["bonus"];
  3056.                                 Log.Info("Calling CreateImprovements");
  3057.                                 if (
  3058.                                     !CreateImprovements(Improvement.ImprovementSource.Power, objPower.InternalId, objPower.Bonus, false,
  3059.                                         Convert.ToInt32(objPower.Rating), objPower.DisplayNameShort))
  3060.                                 {
  3061.                                     _objCharacter.Powers.Remove(objPower);
  3062.                                 }
  3063.                             }
  3064.                         }
  3065.                     }
  3066.                 }
  3067.             }
  3068.  
  3069.             // Check for Armor Encumbrance Penalty.
  3070.             if (bonusNode.LocalName == ("armorencumbrancepenalty"))
  3071.             {
  3072.                 Log.Info("armorencumbrancepenalty");
  3073.                 Log.Info("armorencumbrancepenalty = " + bonusNode.OuterXml.ToString());
  3074.                 Log.Info("Calling CreateImprovement");
  3075.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.ArmorEncumbrancePenalty, "",
  3076.                     ValueToInt(bonusNode.InnerText, intRating));
  3077.             }
  3078.  
  3079.             // Check for Initiation.
  3080.             if (bonusNode.LocalName == ("initiation"))
  3081.             {
  3082.                 Log.Info("initiation");
  3083.                 Log.Info("initiation = " + bonusNode.OuterXml.ToString());
  3084.                 Log.Info("Calling CreateImprovement");
  3085.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Initiation, "",
  3086.                     ValueToInt(bonusNode.InnerText, intRating));
  3087.                 _objCharacter.InitiateGrade += ValueToInt(bonusNode.InnerText, intRating);
  3088.             }
  3089.  
  3090.             // Check for Submersion.
  3091.             if (bonusNode.LocalName == ("submersion"))
  3092.             {
  3093.                 Log.Info("submersion");
  3094.                 Log.Info("submersion = " + bonusNode.OuterXml.ToString());
  3095.                 Log.Info("Calling CreateImprovement");
  3096.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Submersion, "",
  3097.                     ValueToInt(bonusNode.InnerText, intRating));
  3098.                 _objCharacter.SubmersionGrade += ValueToInt(bonusNode.InnerText, intRating);
  3099.             }
  3100.  
  3101.             // Check for Skillwires.
  3102.             if (bonusNode.LocalName == ("skillwire"))
  3103.             {
  3104.                 Log.Info("skillwire");
  3105.                 Log.Info("skillwire = " + bonusNode.OuterXml.ToString());
  3106.                 Log.Info("Calling CreateImprovement");
  3107.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Skillwire, "",
  3108.                     ValueToInt(bonusNode.InnerText, intRating));
  3109.             }
  3110.  
  3111.             // Check for Hardwires.
  3112.             if (bonusNode.LocalName == ("hardwires"))
  3113.             {
  3114.                 Log.Info("hardwire");
  3115.                 Log.Info("hardwire = " + bonusNode.OuterXml.ToString());
  3116.                 Log.Info("Calling CreateImprovement");
  3117.                 Cyberware objCyberware = new Cyberware(_objCharacter);
  3118.                 CommonFunctions _objFunctions = new CommonFunctions();
  3119.                 objCyberware = _objFunctions.FindCyberware(strSourceName, _objCharacter.Cyberware);
  3120.                 if (objCyberware == null)
  3121.                 {
  3122.                     Log.Info("_strSelectedValue = " + _strSelectedValue);
  3123.                     Log.Info("_strForcedValue = " + _strForcedValue);
  3124.  
  3125.                     // Display the Select Skill window and record which Skill was selected.
  3126.                     frmSelectSkill frmPickSkill = new frmSelectSkill(_objCharacter);
  3127.                     if (strFriendlyName != "")
  3128.                         frmPickSkill.Description = LanguageManager.Instance.GetString("String_Improvement_SelectSkillNamed")
  3129.                             .Replace("{0}", strFriendlyName);
  3130.                     else
  3131.                         frmPickSkill.Description = LanguageManager.Instance.GetString("String_Improvement_SelectSkill");
  3132.  
  3133.                     Log.Info("selectskill = " + bonusNode.OuterXml.ToString());
  3134.                     if (bonusNode.OuterXml.Contains("skillgroup"))
  3135.                         frmPickSkill.OnlySkillGroup = bonusNode.Attributes["skillgroup"].InnerText;
  3136.                     else if (bonusNode.OuterXml.Contains("skillcategory"))
  3137.                         frmPickSkill.OnlyCategory = bonusNode.Attributes["skillcategory"].InnerText;
  3138.                     else if (bonusNode.OuterXml.Contains("excludecategory"))
  3139.                         frmPickSkill.ExcludeCategory = bonusNode.Attributes["excludecategory"].InnerText;
  3140.                     else if (bonusNode.OuterXml.Contains("limittoskill"))
  3141.                         frmPickSkill.LimitToSkill = bonusNode.Attributes["limittoskill"].InnerText;
  3142.                     else if (bonusNode.OuterXml.Contains("limittoattribute"))
  3143.                         frmPickSkill.LinkedAttribute = bonusNode.Attributes["limittoattribute"].InnerText;
  3144.  
  3145.                     if (_strForcedValue != "")
  3146.                     {
  3147.                         frmPickSkill.OnlySkill = _strForcedValue;
  3148.                         frmPickSkill.Opacity = 0;
  3149.                     }
  3150.                     frmPickSkill.ShowDialog();
  3151.  
  3152.                     // Make sure the dialogue window was not canceled.
  3153.                     if (frmPickSkill.DialogResult == DialogResult.Cancel)
  3154.                     {
  3155.                         Rollback();
  3156.                         _strForcedValue = "";
  3157.                         _strLimitSelection = "";
  3158.                         return false;
  3159.                     }
  3160.  
  3161.                     _strSelectedValue = frmPickSkill.SelectedSkill;
  3162.                 }
  3163.                 else
  3164.                 {
  3165.                     _strSelectedValue = objCyberware.Location;
  3166.                 }
  3167.                 if (blnConcatSelectedValue)
  3168.                     strSourceName += " (" + _strSelectedValue + ")";
  3169.  
  3170.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  3171.                 Log.Info("strSourceName = " + strSourceName);
  3172.                 CreateImprovement(_strSelectedValue, objImprovementSource, strSourceName, Improvement.ImprovementType.Hardwire, _strSelectedValue,
  3173.                     ValueToInt(bonusNode.InnerText, intRating));
  3174.             }
  3175.  
  3176.             // Check for Damage Resistance.
  3177.             if (bonusNode.LocalName == ("damageresistance"))
  3178.             {
  3179.                 Log.Info("damageresistance");
  3180.                 Log.Info("damageresistance = " + bonusNode.OuterXml.ToString());
  3181.                 Log.Info("Calling CreateImprovement");
  3182.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.DamageResistance,"",
  3183.                     ValueToInt(bonusNode.InnerText, intRating));
  3184.             }
  3185.  
  3186.             // Check for Restricted Item Count.
  3187.             if (bonusNode.LocalName == ("restricteditemcount"))
  3188.             {
  3189.                 Log.Info("restricteditemcount");
  3190.                 Log.Info("restricteditemcount = " + bonusNode.OuterXml.ToString());
  3191.                 Log.Info("Calling CreateImprovement");
  3192.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.RestrictedItemCount, "",
  3193.                     ValueToInt(bonusNode.InnerText, intRating));
  3194.             }
  3195.  
  3196.             // Check for Judge Intentions.
  3197.             if (bonusNode.LocalName == ("judgeintentions"))
  3198.             {
  3199.                 Log.Info("judgeintentions");
  3200.                 Log.Info("judgeintentions = " + bonusNode.OuterXml.ToString());
  3201.                 Log.Info("Calling CreateImprovement");
  3202.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.JudgeIntentions, "",
  3203.                     ValueToInt(bonusNode.InnerText, intRating));
  3204.             }
  3205.  
  3206.             // Check for Composure.
  3207.             if (bonusNode.LocalName == ("composure"))
  3208.             {
  3209.                 Log.Info("composure");
  3210.                 Log.Info("composure = " + bonusNode.OuterXml.ToString());
  3211.                 Log.Info("Calling CreateImprovement");
  3212.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Composure, "",
  3213.                     ValueToInt(bonusNode.InnerText, intRating));
  3214.             }
  3215.  
  3216.             // Check for Lift and Carry.
  3217.             if (bonusNode.LocalName == ("liftandcarry"))
  3218.             {
  3219.                 Log.Info("liftandcarry");
  3220.                 Log.Info("liftandcarry = " + bonusNode.OuterXml.ToString());
  3221.                 Log.Info("Calling CreateImprovement");
  3222.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.LiftAndCarry, "",
  3223.                     ValueToInt(bonusNode.InnerText, intRating));
  3224.             }
  3225.  
  3226.             // Check for Memory.
  3227.             if (bonusNode.LocalName == ("memory"))
  3228.             {
  3229.                 Log.Info("memory");
  3230.                 Log.Info("memory = " + bonusNode.OuterXml.ToString());
  3231.                 Log.Info("Calling CreateImprovement");
  3232.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Memory, "",
  3233.                     ValueToInt(bonusNode.InnerText, intRating));
  3234.             }
  3235.  
  3236.             // Check for Concealability.
  3237.             if (bonusNode.LocalName == ("concealability"))
  3238.             {
  3239.                 Log.Info("concealability");
  3240.                 Log.Info("concealability = " + bonusNode.OuterXml.ToString());
  3241.                 Log.Info("Calling CreateImprovement");
  3242.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Concealability, "",
  3243.                     ValueToInt(bonusNode.InnerText, intRating));
  3244.             }
  3245.  
  3246.             // Check for Drain Resistance.
  3247.             if (bonusNode.LocalName == ("drainresist"))
  3248.             {
  3249.                 Log.Info("drainresist");
  3250.                 Log.Info("drainresist = " + bonusNode.OuterXml.ToString());
  3251.                 Log.Info("Calling CreateImprovement");
  3252.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.DrainResistance, "",
  3253.                     ValueToInt(bonusNode.InnerText, intRating));
  3254.             }
  3255.  
  3256.             // Check for Fading Resistance.
  3257.             if (bonusNode.LocalName == ("fadingresist"))
  3258.             {
  3259.                 Log.Info("fadingresist");
  3260.                 Log.Info("fadingresist = " + bonusNode.OuterXml.ToString());
  3261.                 Log.Info("Calling CreateImprovement");
  3262.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.FadingResistance, "",
  3263.                     ValueToInt(bonusNode.InnerText, intRating));
  3264.             }
  3265.  
  3266.             // Check for Notoriety.
  3267.             if (bonusNode.LocalName == ("notoriety"))
  3268.             {
  3269.                 Log.Info("notoriety");
  3270.                 Log.Info("notoriety = " + bonusNode.OuterXml.ToString());
  3271.                 Log.Info("Calling CreateImprovement");
  3272.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.Notoriety, "",
  3273.                     ValueToInt(bonusNode.InnerText, intRating));
  3274.             }
  3275.  
  3276.             // Check for Complex Form Limit.
  3277.             if (bonusNode.LocalName == ("complexformlimit"))
  3278.             {
  3279.                 Log.Info("complexformlimit");
  3280.                 Log.Info("complexformlimit = " + bonusNode.OuterXml.ToString());
  3281.                 Log.Info("Calling CreateImprovement");
  3282.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.ComplexFormLimit, "",
  3283.                     ValueToInt(bonusNode.InnerText, intRating));
  3284.             }
  3285.  
  3286.             // Check for Spell Limit.
  3287.             if (bonusNode.LocalName == ("spelllimit"))
  3288.             {
  3289.                 Log.Info("spelllimit");
  3290.                 Log.Info("spelllimit = " + bonusNode.OuterXml.ToString());
  3291.                 Log.Info("Calling CreateImprovement");
  3292.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.SpellLimit, "",
  3293.                     ValueToInt(bonusNode.InnerText, intRating));
  3294.             }
  3295.  
  3296.             // Check for Spell Category bonuses.
  3297.             if (bonusNode.LocalName == ("spellcategory"))
  3298.             {
  3299.                 Log.Info("spellcategory");
  3300.                 Log.Info("spellcategory = " + bonusNode.OuterXml.ToString());
  3301.  
  3302.                 string strUseUnique = strUnique;
  3303.                 if (bonusNode["name"].Attributes["precedence"] != null)
  3304.                     strUseUnique = "precedence" + bonusNode["name"].Attributes["precedence"].InnerText;
  3305.  
  3306.                 Log.Info("Calling CreateImprovement");
  3307.                 CreateImprovement(bonusNode["name"].InnerText, objImprovementSource, strSourceName,
  3308.                     Improvement.ImprovementType.SpellCategory, strUseUnique, ValueToInt(bonusNode["val"].InnerText, intRating));
  3309.             }
  3310.  
  3311.             // Check for Throwing Range bonuses.
  3312.             if (bonusNode.LocalName == ("throwrange"))
  3313.             {
  3314.                 Log.Info("throwrange");
  3315.                 Log.Info("throwrange = " + bonusNode.OuterXml.ToString());
  3316.                 Log.Info("Calling CreateImprovement");
  3317.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.ThrowRange, strUnique,
  3318.                     ValueToInt(bonusNode.InnerText, intRating));
  3319.             }
  3320.  
  3321.             // Check for Throwing STR bonuses.
  3322.             if (bonusNode.LocalName == ("throwstr"))
  3323.             {
  3324.                 Log.Info("throwstr");
  3325.                 Log.Info("throwstr = " + bonusNode.OuterXml.ToString());
  3326.                 Log.Info("Calling CreateImprovement");
  3327.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.ThrowSTR, strUnique,
  3328.                     ValueToInt(bonusNode.InnerText, intRating));
  3329.             }
  3330.  
  3331.             // Check for Skillsoft access.
  3332.             if (bonusNode.LocalName == ("skillsoftaccess"))
  3333.             {
  3334.                 Log.Info("skillsoftaccess");
  3335.                 Log.Info("skillsoftaccess = " + bonusNode.OuterXml.ToString());
  3336.                 Log.Info("Calling CreateImprovement");
  3337.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.SkillsoftAccess, "");
  3338.                 _objCharacter.SkillsSection.KnowledgeSkills.AddRange(_objCharacter.SkillsSection.KnowsoftSkills);
  3339.             }
  3340.  
  3341.             // Check for Quickening Metamagic.
  3342.             if (bonusNode.LocalName == ("quickeningmetamagic"))
  3343.             {
  3344.                 Log.Info("quickeningmetamagic");
  3345.                 Log.Info("quickeningmetamagic = " + bonusNode.OuterXml.ToString());
  3346.                 Log.Info("Calling CreateImprovement");
  3347.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.QuickeningMetamagic, "");
  3348.             }
  3349.  
  3350.             // Check for ignore Stun CM Penalty.
  3351.             if (bonusNode.LocalName == ("ignorecmpenaltystun"))
  3352.             {
  3353.                 Log.Info("ignorecmpenaltystun");
  3354.                 Log.Info("ignorecmpenaltystun = " + bonusNode.OuterXml.ToString());
  3355.                 Log.Info("Calling CreateImprovement");
  3356.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.IgnoreCMPenaltyStun, "");
  3357.             }
  3358.  
  3359.             // Check for ignore Physical CM Penalty.
  3360.             if (bonusNode.LocalName == ("ignorecmpenaltyphysical"))
  3361.             {
  3362.                 Log.Info("ignorecmpenaltyphysical");
  3363.                 Log.Info("ignorecmpenaltyphysical = " + bonusNode.OuterXml.ToString());
  3364.                 Log.Info("Calling CreateImprovement");
  3365.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.IgnoreCMPenaltyPhysical, "");
  3366.             }
  3367.  
  3368.             // Check for a Cyborg Essence which will permanently set the character's ESS to 0.1.
  3369.             if (bonusNode.LocalName == ("cyborgessence"))
  3370.             {
  3371.                 Log.Info("cyborgessence");
  3372.                 Log.Info("cyborgessence = " + bonusNode.OuterXml.ToString());
  3373.                 Log.Info("Calling CreateImprovement");
  3374.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.CyborgEssence, "");
  3375.             }
  3376.  
  3377.             // Check for Maximum Essence which will permanently modify the character's Maximum Essence value.
  3378.             if (bonusNode.LocalName == ("essencemax"))
  3379.             {
  3380.                 Log.Info("essencemax");
  3381.                 Log.Info("essencemax = " + bonusNode.OuterXml.ToString());
  3382.                 Log.Info("Calling CreateImprovement");
  3383.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.EssenceMax, "",
  3384.                     ValueToInt(bonusNode.InnerText, intRating));
  3385.             }
  3386.  
  3387.             // Check for Select Sprite.
  3388.             if (bonusNode.LocalName == ("selectsprite"))
  3389.             {
  3390.                 Log.Info("selectsprite");
  3391.                 Log.Info("selectsprite = " + bonusNode.OuterXml.ToString());
  3392.                 XmlDocument objXmlDocument = XmlManager.Instance.Load("critters.xml");
  3393.                 XmlNodeList objXmlNodeList =
  3394.                     objXmlDocument.SelectNodes("/chummer/metatypes/metatype[contains(category, \"Sprites\")]");
  3395.                 List<ListItem> lstCritters = new List<ListItem>();
  3396.                 foreach (XmlNode objXmlNode in objXmlNodeList)
  3397.                 {
  3398.                     ListItem objItem = new ListItem();
  3399.                     if (objXmlNode["translate"] != null)
  3400.                         objItem.Name = objXmlNode["translate"].InnerText;
  3401.                     else
  3402.                         objItem.Name = objXmlNode["name"].InnerText;
  3403.                     objItem.Value = objItem.Name;
  3404.                     lstCritters.Add(objItem);
  3405.                 }
  3406.  
  3407.                 frmSelectItem frmPickItem = new frmSelectItem();
  3408.                 frmPickItem.GeneralItems = lstCritters;
  3409.                 frmPickItem.ShowDialog();
  3410.  
  3411.                 if (frmPickItem.DialogResult == DialogResult.Cancel)
  3412.                 {
  3413.                     Rollback();
  3414.                     _strForcedValue = "";
  3415.                     _strLimitSelection = "";
  3416.                     return false;
  3417.                 }
  3418.  
  3419.                 _strSelectedValue = frmPickItem.SelectedItem;
  3420.  
  3421.                 Log.Info("Calling CreateImprovement");
  3422.                 CreateImprovement(frmPickItem.SelectedItem, objImprovementSource, strSourceName,
  3423.                     Improvement.ImprovementType.AddSprite,
  3424.                     "");
  3425.             }
  3426.  
  3427.             // Check for Black Market Discount.
  3428.             if (bonusNode.LocalName == ("blackmarketdiscount"))
  3429.             {
  3430.                 Log.Info("blackmarketdiscount");
  3431.                 Log.Info("blackmarketdiscount = " + bonusNode.OuterXml.ToString());
  3432.                 Log.Info("Calling CreateImprovement");
  3433.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.BlackMarketDiscount,
  3434.                     strUnique);
  3435.                 _objCharacter.BlackMarketDiscount = true;
  3436.             }
  3437.             // Select Armor (Mostly used for Custom Fit (Stack)).
  3438.             if (bonusNode.LocalName == ("selectarmor"))
  3439.             {
  3440.                 Log.Info("selectarmor");
  3441.                 Log.Info("selectarmor = " + bonusNode.OuterXml.ToString());
  3442.                 string strSelectedValue = "";
  3443.                 if (_strForcedValue != "")
  3444.                     _strLimitSelection = _strForcedValue;
  3445.  
  3446.                 // Display the Select Item window and record the value that was entered.
  3447.  
  3448.                 List<ListItem> lstArmors = new List<ListItem>();
  3449.                 foreach (Armor objArmor in _objCharacter.Armor)
  3450.                 {
  3451.                     foreach (ArmorMod objMod in objArmor.ArmorMods)
  3452.                     {
  3453.                         if (objMod.Name.StartsWith("Custom Fit"))
  3454.                         {
  3455.                             ListItem objItem = new ListItem();
  3456.                             objItem.Value = objArmor.Name;
  3457.                             objItem.Name = objArmor.DisplayName;
  3458.                             lstArmors.Add(objItem);
  3459.                         }
  3460.                     }
  3461.                 }
  3462.  
  3463.                 if (lstArmors.Count > 0)
  3464.                 {
  3465.  
  3466.                     frmSelectItem frmPickItem = new frmSelectItem();
  3467.                     frmPickItem.Description = LanguageManager.Instance.GetString("String_Improvement_SelectText").Replace("{0}", strFriendlyName);
  3468.                     frmPickItem.GeneralItems = lstArmors;
  3469.  
  3470.                     Log.Info( "_strLimitSelection = " + _strLimitSelection);
  3471.                     Log.Info( "_strForcedValue = " + _strForcedValue);
  3472.  
  3473.                     if (_strLimitSelection != "")
  3474.                     {
  3475.                         frmPickItem.ForceItem = _strLimitSelection;
  3476.                         frmPickItem.Opacity = 0;
  3477.                     }
  3478.  
  3479.                     frmPickItem.ShowDialog();
  3480.  
  3481.                     // Make sure the dialogue window was not canceled.
  3482.                     if (frmPickItem.DialogResult == DialogResult.Cancel)
  3483.                     {
  3484.                         Rollback();
  3485.                         _strForcedValue = "";
  3486.                         _strLimitSelection = "";
  3487.                         return false;
  3488.                     }
  3489.  
  3490.                     _strSelectedValue = frmPickItem.SelectedItem;
  3491.                     if (blnConcatSelectedValue)
  3492.                         strSourceName += " (" + _strSelectedValue + ")";
  3493.  
  3494.                     strSelectedValue = frmPickItem.SelectedItem;
  3495.                     Log.Info( "_strSelectedValue = " + _strSelectedValue);
  3496.                     Log.Info( "strSelectedValue = " + strSelectedValue);
  3497.                 }
  3498.  
  3499.             }
  3500.  
  3501.             // Select Weapon (custom entry for things like Spare Clip).
  3502.             if (bonusNode.LocalName == ("selectweapon"))
  3503.             {
  3504.                 Log.Info("selectweapon");
  3505.                 Log.Info("selectweapon = " + bonusNode.OuterXml.ToString());
  3506.                 string strSelectedValue = "";
  3507.                 if (_strForcedValue != "")
  3508.                     _strLimitSelection = _strForcedValue;
  3509.  
  3510.                 if (_objCharacter == null)
  3511.                 {
  3512.                     // If the character is null (this is a Vehicle), the user must enter their own string.
  3513.                     // Display the Select Item window and record the value that was entered.
  3514.                     frmSelectText frmPickText = new frmSelectText();
  3515.                     frmPickText.Description = LanguageManager.Instance.GetString("String_Improvement_SelectText")
  3516.                         .Replace("{0}", strFriendlyName);
  3517.  
  3518.                     Log.Info("_strLimitSelection = " + _strLimitSelection);
  3519.                     Log.Info("_strForcedValue = " + _strForcedValue);
  3520.  
  3521.                     if (_strLimitSelection != "")
  3522.                     {
  3523.                         frmPickText.SelectedValue = _strLimitSelection;
  3524.                         frmPickText.Opacity = 0;
  3525.                     }
  3526.  
  3527.                     frmPickText.ShowDialog();
  3528.  
  3529.                     // Make sure the dialogue window was not canceled.
  3530.                     if (frmPickText.DialogResult == DialogResult.Cancel)
  3531.                     {
  3532.                         Rollback();
  3533.                         _strForcedValue = "";
  3534.                         _strLimitSelection = "";
  3535.                         return false;
  3536.                     }
  3537.  
  3538.                     _strSelectedValue = frmPickText.SelectedValue;
  3539.                     if (blnConcatSelectedValue)
  3540.                         strSourceName += " (" + _strSelectedValue + ")";
  3541.  
  3542.                     strSelectedValue = frmPickText.SelectedValue;
  3543.                     Log.Info("_strSelectedValue = " + _strSelectedValue);
  3544.                     Log.Info("strSelectedValue = " + strSelectedValue);
  3545.                 }
  3546.                 else
  3547.                 {
  3548.                     List<ListItem> lstWeapons = new List<ListItem>();
  3549.                     foreach (Weapon objWeapon in _objCharacter.Weapons)
  3550.                     {
  3551.                         ListItem objItem = new ListItem();
  3552.                         objItem.Value = objWeapon.Name;
  3553.                         objItem.Name = objWeapon.DisplayName;
  3554.                         lstWeapons.Add(objItem);
  3555.                     }
  3556.  
  3557.                     frmSelectItem frmPickItem = new frmSelectItem();
  3558.                     frmPickItem.Description = LanguageManager.Instance.GetString("String_Improvement_SelectText")
  3559.                         .Replace("{0}", strFriendlyName);
  3560.                     frmPickItem.GeneralItems = lstWeapons;
  3561.  
  3562.                     Log.Info("_strLimitSelection = " + _strLimitSelection);
  3563.                     Log.Info("_strForcedValue = " + _strForcedValue);
  3564.  
  3565.                     if (_strLimitSelection != "")
  3566.                     {
  3567.                         frmPickItem.ForceItem = _strLimitSelection;
  3568.                         frmPickItem.Opacity = 0;
  3569.                     }
  3570.  
  3571.                     frmPickItem.ShowDialog();
  3572.  
  3573.                     // Make sure the dialogue window was not canceled.
  3574.                     if (frmPickItem.DialogResult == DialogResult.Cancel)
  3575.                     {
  3576.                         Rollback();
  3577.                         _strForcedValue = "";
  3578.                         _strLimitSelection = "";
  3579.                         return false;
  3580.                     }
  3581.  
  3582.                     _strSelectedValue = frmPickItem.SelectedItem;
  3583.                     if (blnConcatSelectedValue)
  3584.                         strSourceName += " (" + _strSelectedValue + ")";
  3585.  
  3586.                     strSelectedValue = frmPickItem.SelectedItem;
  3587.                     Log.Info("_strSelectedValue = " + _strSelectedValue);
  3588.                     Log.Info("strSelectedValue = " + strSelectedValue);
  3589.                 }
  3590.  
  3591.                 // Create the Improvement.
  3592.                 Log.Info("Calling CreateImprovement");
  3593.                 CreateImprovement(strSelectedValue, objImprovementSource, strSourceName, Improvement.ImprovementType.Text, strUnique);
  3594.             }
  3595.  
  3596.             // Select an Optional Power.
  3597.             if (bonusNode.LocalName == ("optionalpowers"))
  3598.             {
  3599.                 XmlNodeList objXmlPowerList = bonusNode.SelectNodes("optionalpower");
  3600.                 //Log.Info("selectoptionalpower");
  3601.                 // Display the Select Attribute window and record which Skill was selected.
  3602.                 frmSelectOptionalPower frmPickPower = new frmSelectOptionalPower();
  3603.                 frmPickPower.Description = LanguageManager.Instance.GetString("String_Improvement_SelectOptionalPower");
  3604.                 string strForcedValue = "";
  3605.  
  3606.                 List<KeyValuePair<string, string>> lstValue = new List<KeyValuePair<string,string>>();
  3607.                 foreach (XmlNode objXmlOptionalPower in objXmlPowerList)
  3608.                 {
  3609.                     string strQuality = objXmlOptionalPower.InnerText;
  3610.                     if (objXmlOptionalPower.Attributes["select"] != null)
  3611.                     {
  3612.                         strForcedValue = objXmlOptionalPower.Attributes["select"].InnerText;
  3613.                     }
  3614.                     lstValue.Add(new KeyValuePair<string, string>(strQuality,strForcedValue));
  3615.                 }
  3616.                 frmPickPower.LimitToList(lstValue);
  3617.  
  3618.  
  3619.                 // Check to see if there is only one possible selection because of _strLimitSelection.
  3620.                 if (_strForcedValue != "")
  3621.                     _strLimitSelection = _strForcedValue;
  3622.  
  3623.                 Log.Info( "_strForcedValue = " + _strForcedValue);
  3624.                 Log.Info( "_strLimitSelection = " + _strLimitSelection);
  3625.  
  3626.                 if (_strLimitSelection != "")
  3627.                 {
  3628.                     frmPickPower.SinglePower(_strLimitSelection);
  3629.                     frmPickPower.Opacity = 0;
  3630.                 }
  3631.  
  3632.                 frmPickPower.ShowDialog();
  3633.  
  3634.                 // Make sure the dialogue window was not canceled.
  3635.                 if (frmPickPower.DialogResult == DialogResult.Cancel)
  3636.                 {
  3637.                     Rollback();
  3638.                     _strForcedValue = "";
  3639.                     _strLimitSelection = "";
  3640.                     return false;
  3641.                 }
  3642.  
  3643.                 _strSelectedValue = frmPickPower.SelectedPower;
  3644.                 // Record the improvement.
  3645.                 XmlDocument objXmlDocument = XmlManager.Instance.Load("critterpowers.xml");
  3646.                 XmlNode objXmlPowerNode = objXmlDocument.SelectSingleNode("/chummer/powers/power[name = \"" + _strSelectedValue + "\"]");
  3647.                 TreeNode objPowerNode = new TreeNode();
  3648.                 CritterPower objPower = new CritterPower(_objCharacter);
  3649.                
  3650.                 objPower.Create(objXmlPowerNode, _objCharacter, objPowerNode, 0, strForcedValue);
  3651.                 _objCharacter.CritterPowers.Add(objPower);
  3652.             }
  3653.  
  3654.             if (bonusNode.LocalName == "publicawareness")
  3655.             {
  3656.                 CreateImprovement("", objImprovementSource, strSourceName, Improvement.ImprovementType.PublicAwareness, strUnique, ValueToInt(bonusNode.InnerText,1));
  3657.             }
  3658.  
  3659.             if (bonusNode.LocalName == "dealerconnection")
  3660.             {
  3661.                 Log.Info("dealerconnection");
  3662.                 frmSelectItem frmPickItem = new frmSelectItem();
  3663.                 List<ListItem> lstItems = new List<ListItem>();
  3664.                 XmlNodeList objXmlList = bonusNode.SelectNodes("category");
  3665.                 foreach (XmlNode objNode in objXmlList)
  3666.                 {
  3667.                     ListItem objItem = new ListItem();
  3668.                     objItem.Value = objNode.InnerText;
  3669.                     objItem.Name = objNode.InnerText;
  3670.                     lstItems.Add(objItem);
  3671.                 }
  3672.                 frmPickItem.GeneralItems = lstItems;
  3673.                 frmPickItem.AllowAutoSelect = false;
  3674.                 frmPickItem.ShowDialog();
  3675.                 // Make sure the dialogue window was not canceled.
  3676.                 if (frmPickItem.DialogResult == DialogResult.Cancel)
  3677.                 {
  3678.                     Rollback();
  3679.                     _strForcedValue = "";
  3680.                     _strLimitSelection = "";
  3681.                     return false;
  3682.                 }
  3683.  
  3684.                 _strSelectedValue = frmPickItem.SelectedItem;
  3685.                 if (blnConcatSelectedValue)
  3686.                     strSourceName += " (" + _strSelectedValue + ")";
  3687.  
  3688.                 Log.Info("_strSelectedValue = " + _strSelectedValue);
  3689.                 Log.Info("strSourceName = " + strSourceName);
  3690.  
  3691.                 // Create the Improvement.
  3692.                 Log.Info("Calling CreateImprovement");
  3693.                 CreateImprovement(frmPickItem.SelectedItem, objImprovementSource, strSourceName,
  3694.                     Improvement.ImprovementType.DealerConnection, strUnique);
  3695.             }
  3696.  
  3697.             if (bonusNode.LocalName == "unlockskills")
  3698.             {
  3699.                 List<string> options = bonusNode.InnerText.Split(',').Select(x => x.Trim()).ToList();
  3700.                 string final;
  3701.                 if (options.Count == 0)
  3702.                 {
  3703.                     Utils.BreakIfDebug();
  3704.                     return false;
  3705.                 }
  3706.                 else if (options.Count == 1)
  3707.                 {
  3708.                     final = options[0];
  3709.                 }
  3710.                 else
  3711.                 {
  3712.                     frmSelectItem frmSelect = new frmSelectItem
  3713.                     {
  3714.                         AllowAutoSelect = true,
  3715.                         GeneralItems = options.Select(x => new ListItem(x, x)).ToList()
  3716.                     };
  3717.                    
  3718.                     if (_objCharacter.Pushtext.Count > 0)
  3719.                     {
  3720.                         frmSelect.ForceItem = _objCharacter.Pushtext.Pop();
  3721.                     }
  3722.  
  3723.                     if (frmSelect.ShowDialog() == DialogResult.Cancel)
  3724.                     {
  3725.                         return false;
  3726.                     }
  3727.  
  3728.                     final = frmSelect.SelectedItem;
  3729.                 }
  3730.                
  3731.                 SkillsSection.FilterOptions skills;
  3732.                 if (Enum.TryParse(final, out skills))
  3733.                 {
  3734.                     _objCharacter.SkillsSection.AddSkills(skills);
  3735.                     CreateImprovement(skills.ToString(), Improvement.ImprovementSource.Quality, strSourceName,
  3736.                         Improvement.ImprovementType.SpecialSkills, strUnique);
  3737.                 }
  3738.                 else
  3739.                 {
  3740.                     Utils.BreakIfDebug();
  3741.                     Log.Info(new[] {"Failed to parse", "specialskills", bonusNode.OuterXml});
  3742.                 }
  3743.             }
  3744.  
  3745.             //nothing went wrong, so return true
  3746.             return true;
  3747. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement