예제 #1
0
파일: frmCareer.cs 프로젝트: Nebual/chummer
        private void cmdGearSplitQty_Click(object sender, EventArgs e)
        {
            // This can only be done with the first level of Nodes.
            try
            {
                if (treGear.SelectedNode.Level != 1)
                    return;
            }
            catch
            {
                return;
            }

            Gear objSelectedGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);

            // Cannot split a stack of 1 item.
            if (objSelectedGear.Quantity == 1)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotSplitGear"), LanguageManager.Instance.GetString("MessageTitle_CannotSplitGear"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            frmSelectNumber frmPickNumber = new frmSelectNumber();
            frmPickNumber.Minimum = 1;
            frmPickNumber.Maximum = objSelectedGear.Quantity - 1;
            frmPickNumber.Description = LanguageManager.Instance.GetString("String_SplitGear");
            frmPickNumber.ShowDialog(this);

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

            // Create a new piece of Gear.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");
            XmlNode objNode = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objSelectedGear.Name + "\" and category = \"" + objSelectedGear.Category + "\"]");

            TreeNode objGearNode = new TreeNode();
            List<Weapon> lstWeapons = new List<Weapon>();
            List<TreeNode> lstWeaponNodes = new List<TreeNode>();
            Gear objGear = new Gear(_objCharacter);
            if (objSelectedGear.GetType() == typeof(Commlink))
            {
                Commlink objCommlink = new Commlink(_objCharacter);
                objCommlink.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);
                objGear = objCommlink;
            }
            else if (objSelectedGear.GetType() == typeof(OperatingSystem))
            {
                OperatingSystem objOS = new OperatingSystem(_objCharacter);
                objOS.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);
                objGear = objOS;
            }
            else
                objGear.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);

            objGear.Quantity = frmPickNumber.SelectedValue;
            objGear.Equipped = objSelectedGear.Equipped;
            objGear.Location = objSelectedGear.Location;
            objGear.Notes = objSelectedGear.Notes;
            objGearNode.Text = objGear.DisplayName;
            objGearNode.ContextMenuStrip = treGear.SelectedNode.ContextMenuStrip;

            // Update the selected item.
            objSelectedGear.Quantity -= frmPickNumber.SelectedValue;
            treGear.SelectedNode.Text = objSelectedGear.DisplayName;

            treGear.SelectedNode.Parent.Nodes.Add(objGearNode);
            _objCharacter.Gear.Add(objGear);

            // Create any Weapons that came with this Gear.
            foreach (Weapon objWeapon in lstWeapons)
                _objCharacter.Weapons.Add(objWeapon);

            foreach (TreeNode objWeaponNode in lstWeaponNodes)
            {
                objWeaponNode.ContextMenuStrip = cmsWeapon;
                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                treWeapons.Nodes[0].Expand();
            }

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
예제 #2
0
파일: frmCareer.cs 프로젝트: Nebual/chummer
        private void cmdVehicleMoveToInventory_Click(object sender, EventArgs e)
        {
            // Locate the selected Weapon.
            bool blnFound = false;
            Weapon objWeapon = new Weapon(_objCharacter);
            Vehicle objVehicle = new Vehicle(_objCharacter);
            VehicleMod objMod = new VehicleMod(_objCharacter);

            foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
            {
                foreach (Weapon objVehicleWeapon in objCharacterVehicle.Weapons)
                {
                    if (objVehicleWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                    {
                        objWeapon = objVehicleWeapon;
                        objVehicle = objCharacterVehicle;
                        blnFound = true;
                        break;
                    }
                }
                foreach (VehicleMod objVehicleMod in objCharacterVehicle.Mods)
                {
                    foreach (Weapon objVehicleWeapon in objVehicleMod.Weapons)
                    {
                        if (objVehicleWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                        {
                            objWeapon = objVehicleWeapon;
                            objVehicle = objCharacterVehicle;
                            objMod = objVehicleMod;
                            blnFound = true;
                            break;
                        }
                    }
                }
            }

            if (blnFound){
                // Move the Weapons from the Vehicle Mod (or Vehicle) to the character.
                if (objMod.InternalId != Guid.Empty.ToString())
                    objMod.Weapons.Remove(objWeapon);
                else
                    objVehicle.Weapons.Remove(objWeapon);

                _objCharacter.Weapons.Add(objWeapon);

                TreeNode objNode = new TreeNode();
                objNode = treVehicles.SelectedNode;

                treVehicles.SelectedNode.Remove();
                treWeapons.Nodes[0].Nodes.Add(objNode);
                objWeapon.VehicleMounted = false;
                objNode.Expand();
            }
            else
            {
                // Locate the selected Gear.
                Vehicle objSelectedVehicle = new Vehicle(_objCharacter);
                Gear objSelectedGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objSelectedVehicle);

                int intMove = 0;
                if (objSelectedGear.Quantity == 1)
                    intMove = 1;
                else
                {
                    frmSelectNumber frmPickNumber = new frmSelectNumber();
                    frmPickNumber.Minimum = 1;
                    frmPickNumber.Maximum = objSelectedGear.Quantity;
                    frmPickNumber.Description = LanguageManager.Instance.GetString("String_MoveGear");
                    frmPickNumber.ShowDialog(this);

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

                    intMove = frmPickNumber.SelectedValue;
                }

                // See if the character already has a matching piece of Gear.
                bool blnMatch = false;
                Gear objFoundGear = new Gear(_objCharacter);
                foreach (Gear objCharacterGear in _objCharacter.Gear)
                {
                    if (objCharacterGear.Name == objSelectedGear.Name && objCharacterGear.Category == objSelectedGear.Category && objCharacterGear.Rating == objSelectedGear.Rating && objCharacterGear.Extra == objSelectedGear.Extra && objCharacterGear.GearName == objSelectedGear.GearName && objCharacterGear.Notes == objSelectedGear.Notes)
                    {
                        blnMatch = true;
                        objFoundGear = objCharacterGear;
                        if (objCharacterGear.Children.Count == objSelectedGear.Children.Count)
                        {
                            for (int i = 0; i <= objCharacterGear.Children.Count - 1; i++)
                            {
                                if (objCharacterGear.Children[i].Name != objSelectedGear.Children[i].Name || objCharacterGear.Children[i].Extra != objSelectedGear.Children[i].Extra || objCharacterGear.Children[i].Rating != objSelectedGear.Children[i].Rating)
                                {
                                    blnMatch = false;
                                    break;
                                }
                            }
                        }
                        else
                            blnMatch = false;
                    }
                }

                if (!blnMatch)
                {
                    // Create a new piece of Gear.
                    TreeNode objGearNode = new TreeNode();
                    List<Weapon> lstWeapons = new List<Weapon>();
                    List<TreeNode> lstWeaponNodes = new List<TreeNode>();
                    Gear objGear = new Gear(_objCharacter);
                    if (objSelectedGear.GetType() == typeof(Commlink))
                    {
                        Commlink objCommlink = new Commlink(_objCharacter);
                        objCommlink.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);
                        objGear = objCommlink;
                    }
                    else if (objSelectedGear.GetType() == typeof(OperatingSystem))
                    {
                        OperatingSystem objOS = new OperatingSystem(_objCharacter);
                        objOS.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);
                        objGear = objOS;
                    }
                    else
                        objGear.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);

                    objGear.Parent = null;
                    objGear.Quantity = intMove;
                    objGearNode.Text = objGear.DisplayName;
                    objGearNode.ContextMenuStrip = cmsGear;

                    treGear.Nodes[0].Nodes.Add(objGearNode);
                    _objCharacter.Gear.Add(objGear);

                    // Create any Weapons that came with this Gear.
                    foreach (Weapon objGearWeapon in lstWeapons)
                        _objCharacter.Weapons.Add(objGearWeapon);

                    foreach (TreeNode objWeaponNode in lstWeaponNodes)
                    {
                        objWeaponNode.ContextMenuStrip = cmsWeapon;
                        treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                        treWeapons.Nodes[0].Expand();
                    }

                    AddGearImprovements(objGear);
                    UpdateCharacterInfo();
                }
                else
                {
                    // Everything matches up, so just increase the quantity.
                    objFoundGear.Quantity += intMove;
                    foreach (TreeNode nodGear in treGear.Nodes[0].Nodes)
                    {
                        if (nodGear.Tag.ToString() == objFoundGear.InternalId)
                            nodGear.Text = objFoundGear.DisplayName;
                    }
                }

                // Update the selected item.
                objSelectedGear.Quantity -= intMove;
                if (objSelectedGear.Quantity == 0)
                {
                    // The quantity has reached 0, so remove it entirely.
                    treVehicles.SelectedNode.Remove();
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                        objCharacterVehicle.Gear.Remove(objSelectedGear);
                }
                else
                    treVehicles.SelectedNode.Text = objSelectedGear.DisplayName;
            }

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
예제 #3
0
파일: frmCareer.cs 프로젝트: Nebual/chummer
        private void cmdGearMoveToVehicle_Click(object sender, EventArgs e)
        {
            frmSelectItem frmPickItem = new frmSelectItem();
            frmPickItem.Vehicles = _objCharacter.Vehicles;
            frmPickItem.ShowDialog(this);

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

            // Locate the selected Vehicle.
            Vehicle objVehicle = new Vehicle(_objCharacter);
            foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
            {
                if (objCharacterVehicle.InternalId == frmPickItem.SelectedItem)
                {
                    objVehicle = objCharacterVehicle;
                    break;
                }
            }

            Gear objSelectedGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);
            int intMove = 0;
            if (objSelectedGear.Quantity == 1)
                intMove = 1;
            else
            {
                frmSelectNumber frmPickNumber = new frmSelectNumber();
                frmPickNumber.Minimum = 1;
                frmPickNumber.Maximum = objSelectedGear.Quantity;
                frmPickNumber.Description = LanguageManager.Instance.GetString("String_MoveGear");
                frmPickNumber.ShowDialog(this);

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

                intMove = frmPickNumber.SelectedValue;
            }

            // See if the Vehicle already has a matching piece of Gear.
            bool blnMatch = false;
            Gear objFoundGear = new Gear(_objCharacter);
            foreach (Gear objVehicleGear in objVehicle.Gear)
            {
                if (objVehicleGear.Name == objSelectedGear.Name && objVehicleGear.Category == objSelectedGear.Category && objVehicleGear.Rating == objSelectedGear.Rating && objVehicleGear.Extra == objSelectedGear.Extra && objVehicleGear.GearName == objSelectedGear.GearName && objVehicleGear.Notes == objSelectedGear.Notes)
                {
                    blnMatch = true;
                    objFoundGear = objVehicleGear;
                    if (objVehicleGear.Children.Count == objSelectedGear.Children.Count)
                    {
                        for (int i = 0; i <= objVehicleGear.Children.Count - 1; i++)
                        {
                            if (objVehicleGear.Children[i].Name != objSelectedGear.Children[i].Name || objVehicleGear.Children[i].Extra != objSelectedGear.Children[i].Extra || objVehicleGear.Children[i].Rating != objSelectedGear.Children[i].Rating)
                            {
                                blnMatch = false;
                                break;
                            }
                        }
                    }
                    else
                        blnMatch = false;
                }
            }

            if (!blnMatch)
            {
                // Create a new piece of Gear.
                TreeNode objGearNode = new TreeNode();
                List<Weapon> lstWeapons = new List<Weapon>();
                List<TreeNode> lstWeaponNodes = new List<TreeNode>();
                Gear objGear = new Gear(_objCharacter);
                if (objSelectedGear.GetType() == typeof(Commlink))
                {
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);
                    objGear = objCommlink;
                }
                else if (objSelectedGear.GetType() == typeof(OperatingSystem))
                {
                    OperatingSystem objOS = new OperatingSystem(_objCharacter);
                    objOS.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);
                    objGear = objOS;
                }
                else
                    objGear.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);

                objGear.Parent = null;
                objGear.Quantity = intMove;
                objGear.Location = string.Empty;
                objGearNode.Text = objGear.DisplayName;
                objGearNode.ContextMenuStrip = cmsVehicleGear;

                // Locate the Node for the selected Vehicle.
                TreeNode nodParent = new TreeNode();
                foreach (TreeNode nodNode in treVehicles.Nodes[0].Nodes)
                {
                    if (nodNode.Tag.ToString() == objVehicle.InternalId)
                    {
                        nodParent = nodNode;
                        break;
                    }
                }

                nodParent.Nodes.Add(objGearNode);
                objVehicle.Gear.Add(objGear);
            }
            else
            {
                // Everything matches up, so just increase the quantity.
                objFoundGear.Quantity += intMove;
                foreach (TreeNode nodVehicle in treVehicles.Nodes[0].Nodes)
                {
                    if (nodVehicle.Tag.ToString() == objVehicle.InternalId)
                    {
                        foreach (TreeNode nodGear in nodVehicle.Nodes)
                        {
                            if (nodGear.Tag.ToString() == objFoundGear.InternalId)
                                nodGear.Text = objFoundGear.DisplayName;
                        }
                    }
                }
            }

            // Update the selected item.
            objSelectedGear.Quantity -= intMove;
            if (objSelectedGear.Quantity == 0)
            {
                if (objSelectedGear.Parent != null)
                    objSelectedGear.Parent.Children.Remove(objSelectedGear);
                else
                    _objCharacter.Gear.Remove(objSelectedGear);
                _objFunctions.DeleteGear(objSelectedGear, treWeapons, _objImprovementManager);
                treGear.SelectedNode.Remove();
                UpdateCharacterInfo();
            }
            else
            {
                treGear.SelectedNode.Text = objSelectedGear.DisplayName;
            }

            _blnIsDirty = true;
            UpdateWindowTitle();
        }