/// <summary>
        /// Cycle weapons using directional pad input. Up and Down cycle forward and backward through
        /// the list of two handed weapons. Left cycles through the left hand weapons. Right cycles through
        /// the right hand weapons.
        /// </summary>
        private void SwitchWeapons()
        {
            // Bail out if we can't switch weapons.
            if (!rpgCharacterController.CanStartAction("SwitchWeapon"))
            {
                return;
            }

            bool doSwitch = false;
            SwitchWeaponContext context = new SwitchWeaponContext();
            int weaponNumber            = 0;

            // Cycle through 2H weapons any input happens on the up-down axis.
            if (Mathf.Abs(inputSwitchUpDown) > 0.1f)
            {
                int[] twoHandedWeapons = new int[] {
                    (int)Weapon.TwoHandSword,
                };
                // If we're not wielding 2H weapon already, just switch to the first one in the list.
                if (System.Array.IndexOf(twoHandedWeapons, rpgCharacterController.rightWeapon) == -1)
                {
                    weaponNumber = twoHandedWeapons[0];
                }
                else
                {
                    weaponNumber = 0;
                }
                // Set up the context and flag that we actually want to perform the switch.
                doSwitch            = true;
                context.type        = "Switch";
                context.side        = "None";
                context.leftWeapon  = -1;
                context.rightWeapon = weaponNumber;
            }

            // If we've received input, then "doSwitch" is true, and the context is filled out,
            // so start the SwitchWeapon action.
            if (doSwitch)
            {
                rpgCharacterController.StartAction("SwitchWeapon", context);
            }
        }
Esempio n. 2
0
        private void WeaponSwitching()
        {
            if (!rpgCharacterController.CanStartAction("SwitchWeapon"))
            {
                return;
            }

            bool doSwitch = false;
            SwitchWeaponContext context = new SwitchWeaponContext();

            if (!rpgCharacterController.isRelaxed)
            {
                if (GUI.Button(new Rect(1115, 240, 100, 30), "Relax"))
                {
                    if (useInstant)
                    {
                        rpgCharacterController.StartAction("Relax", true);
                    }
                    else
                    {
                        rpgCharacterController.StartAction("Relax");
                    }
                }
            }
            if (rpgCharacterController.rightWeapon != (int)Weapon.Unarmed || rpgCharacterController.leftWeapon != (int)Weapon.Unarmed)
            {
                if (GUI.Button(new Rect(1115, 280, 100, 30), "Unarmed"))
                {
                    doSwitch            = true;
                    context.type        = "Switch";
                    context.side        = "Dual";
                    context.leftWeapon  = (int)Weapon.Unarmed;
                    context.rightWeapon = (int)Weapon.Unarmed;
                }
            }

            // Two-handed weapons.
            Weapon[] weapons = new Weapon[] {
                Weapon.TwoHandSword,
                Weapon.TwoHandSpear,
                Weapon.TwoHandAxe,
                Weapon.TwoHandStaff,
                Weapon.TwoHandBow,
                Weapon.TwoHandCrossbow,
                Weapon.Rifle,
            };
            int offset = 310;

            foreach (Weapon weapon in weapons)
            {
                if (rpgCharacterController.rightWeapon != (int)weapon)
                {
                    string label = weapon.ToString();
                    if (label.StartsWith("TwoHand"))
                    {
                        label = label.Replace("TwoHand", "2H ");
                    }
                    if (GUI.Button(new Rect(1115, offset, 100, 30), label))
                    {
                        doSwitch            = true;
                        context.type        = "Switch";
                        context.side        = "None";
                        context.leftWeapon  = -1;
                        context.rightWeapon = (int)weapon;
                    }
                }
                offset += 30;
            }

            // Left/Right weapon pairs.
            Tuple <Weapon, Weapon>[] leftRightPairs = new Tuple <Weapon, Weapon>[] {
                Tuple.Create(Weapon.LeftSword, Weapon.RightSword),
                Tuple.Create(Weapon.LeftMace, Weapon.RightMace),
                Tuple.Create(Weapon.LeftDagger, Weapon.RightDagger),
                Tuple.Create(Weapon.LeftItem, Weapon.RightItem),
                Tuple.Create(Weapon.LeftPistol, Weapon.RightPistol),
                Tuple.Create(Weapon.Shield, Weapon.RightSpear),
            };
            offset = 530;

            foreach (Tuple <Weapon, Weapon> pair in leftRightPairs)
            {
                bool missingOneSide = false;

                // Left weapons.
                if (rpgCharacterController.leftWeapon != (int)pair.Item1)
                {
                    missingOneSide = true;
                    if (GUI.Button(new Rect(1065, offset, 100, 30), pair.Item1.ToString()))
                    {
                        doSwitch            = true;
                        context.type        = "Switch";
                        context.side        = "Left";
                        context.leftWeapon  = (int)pair.Item1;
                        context.rightWeapon = -1;
                    }
                }
                // Right weapons.
                if (rpgCharacterController.rightWeapon != (int)pair.Item2)
                {
                    missingOneSide = true;
                    if (GUI.Button(new Rect(1165, offset, 100, 30), pair.Item2.ToString()))
                    {
                        doSwitch            = true;
                        context.type        = "Switch";
                        context.side        = "Right";
                        context.leftWeapon  = -1;
                        context.rightWeapon = (int)pair.Item2;
                    }
                }
                // If at least one side isn't carrying this weapon, show the Dual switch.
                if (missingOneSide)
                {
                    string label = pair.Item1.ToString();
                    if (!label.Contains("Shield"))
                    {
                        label = label.Replace("Left", "Dual ") + "s";
                        if (GUI.Button(new Rect(965, offset, 100, 30), label))
                        {
                            doSwitch            = true;
                            context.type        = "Switch";
                            context.side        = "Dual";
                            context.leftWeapon  = (int)pair.Item1;
                            context.rightWeapon = (int)pair.Item2;
                        }
                    }
                }
                offset += 30;
            }
            if (rpgCharacterController.leftWeapon > (int)Weapon.Unarmed)
            {
                if (GUI.Button(new Rect(750, offset - 150, 100, 30), "Sheath Left"))
                {
                    doSwitch            = true;
                    context.type        = "Sheath";
                    context.side        = "Left";
                    context.leftWeapon  = (int)Weapon.Unarmed;
                    context.rightWeapon = -1;
                }
            }
            if (rpgCharacterController.rightWeapon > (int)Weapon.Unarmed)
            {
                if (GUI.Button(new Rect(850, offset - 150, 100, 30), "Sheath Right"))
                {
                    doSwitch            = true;
                    context.type        = "Sheath";
                    context.side        = "Right";
                    context.leftWeapon  = -1;
                    context.rightWeapon = (int)Weapon.Unarmed;
                }
            }

            offset += 30;

            if (GUI.Button(new Rect(965, 680, 100, 30), "Shuffle"))
            {
                int lefty  = (int)leftRightPairs[UnityEngine.Random.Range(0, leftRightPairs.Length)].Item1;
                int righty = (int)leftRightPairs[UnityEngine.Random.Range(0, leftRightPairs.Length)].Item2;

                doSwitch            = true;
                context.type        = "Switch";
                context.side        = "Both";
                context.leftWeapon  = lefty;
                context.rightWeapon = righty;
            }
            // Hip Shooting.
            hipShooting = GUI.Toggle(new Rect(1000, 495, 100, 30), hipShooting, "Hip Shooting");
            if (hipShooting)
            {
                rpgCharacterController.StartAction("HipShoot");
            }
            else
            {
                rpgCharacterController.EndAction("HipShoot");
            }

            // Sheath/Unsheath Hips.
            useHips = GUI.Toggle(new Rect(1000, 260, 100, 30), useHips, "Hips");
            if (useHips)
            {
                context.sheathLocation = "Hips";
            }
            else
            {
                context.sheathLocation = "Back";
            }

            // Instant weapon toggle.
            useInstant = GUI.Toggle(new Rect(1000, 310, 100, 30), useInstant, "Instant");
            if (useInstant)
            {
                context.type = "Instant";
            }

            // Perform the weapon switch.
            if (doSwitch)
            {
                rpgCharacterController.StartAction("SwitchWeapon", context);
            }
        }
        /// <summary>
        /// Cycle weapons using directional pad input. Up and Down cycle forward and backward through
        /// the list of two handed weapons. Left cycles through the left hand weapons. Right cycles through
        /// the right hand weapons.
        /// </summary>
        private void SwitchWeapons()
        {
            // Bail out if we can't switch weapons.
            if (!rpgCharacterController.CanStartAction("SwitchWeapon"))
            {
                return;
            }

            // Switch to Relaxed state.
            if (inputRelax)
            {
                rpgCharacterController.StartAction("Relax");
                return;
            }

            bool doSwitch = false;
            SwitchWeaponContext context = new SwitchWeaponContext();
            int weaponNumber            = 0;

            // Switch to Shield.
            if (inputShield)
            {
                doSwitch            = true;
                context.side        = "Left";
                context.type        = "Switch";
                context.leftWeapon  = 7;
                context.rightWeapon = weaponNumber;
                rpgCharacterController.StartAction("SwitchWeapon", context);
                return;
            }

            // Cycle through 2H weapons any input happens on the up-down axis.
            if (inputSwitchUp || inputSwitchDown)
            {
                int[] twoHandedWeapons = new int[] {
                    (int)Weapon.TwoHandSword,
                    (int)Weapon.TwoHandSpear,
                    (int)Weapon.TwoHandAxe,
                    (int)Weapon.TwoHandBow,
                    (int)Weapon.TwoHandCrossbow,
                    (int)Weapon.TwoHandStaff,
                    (int)Weapon.Rifle,
                };

                // If we're not wielding 2H weapon already, just switch to the first one in the list.
                if (System.Array.IndexOf(twoHandedWeapons, rpgCharacterController.rightWeapon) == -1)
                {
                    weaponNumber = twoHandedWeapons[0];
                }
                // Otherwise, we should loop through them.
                else
                {
                    int index = System.Array.IndexOf(twoHandedWeapons, rpgCharacterController.rightWeapon);
                    if (inputSwitchUp)
                    {
                        index = (index - 1 + twoHandedWeapons.Length) % twoHandedWeapons.Length;
                    }
                    else if (inputSwitchDown)
                    {
                        index = (index + 1) % twoHandedWeapons.Length;
                    }
                    weaponNumber = twoHandedWeapons[index];
                }

                // Set up the context and flag that we actually want to perform the switch.
                doSwitch            = true;
                context.type        = "Switch";
                context.side        = "None";
                context.leftWeapon  = -1;
                context.rightWeapon = weaponNumber;
            }

            // Cycle through 1H weapons if any input happens on the left-right axis.
            if (inputSwitchLeft || inputSwitchRight)
            {
                doSwitch     = true;
                context.type = "Switch";

                // Left-handed weapons.
                if (inputSwitchLeft)
                {
                    int[] leftWeapons = new int[] {
                        (int)Weapon.Unarmed,
                        (int)Weapon.Shield,
                        (int)Weapon.LeftSword,
                        (int)Weapon.LeftMace,
                        (int)Weapon.LeftDagger,
                        (int)Weapon.LeftItem,
                        (int)Weapon.LeftPistol,
                    };

                    // If we are not wielding a left-handed weapon, switch to unarmed.
                    if (System.Array.IndexOf(leftWeapons, rpgCharacterController.leftWeapon) == -1)
                    {
                        weaponNumber = leftWeapons[0];
                    }

                    // Otherwise, cycle through the list.
                    else
                    {
                        int currentIndex = System.Array.IndexOf(leftWeapons, rpgCharacterController.leftWeapon);
                        weaponNumber = leftWeapons[(currentIndex + 1) % leftWeapons.Length];
                    }

                    context.side        = "Left";
                    context.leftWeapon  = weaponNumber;
                    context.rightWeapon = -1;
                }
                // Right-handed weapons.
                else if (inputSwitchRight)
                {
                    int[] rightWeapons = new int[] {
                        (int)Weapon.Unarmed,
                        (int)Weapon.RightSword,
                        (int)Weapon.RightMace,
                        (int)Weapon.RightDagger,
                        (int)Weapon.RightItem,
                        (int)Weapon.RightPistol,
                        (int)Weapon.RightSpear,
                    };
                    // If we are not wielding a right-handed weapon, switch to unarmed.
                    if (System.Array.IndexOf(rightWeapons, rpgCharacterController.rightWeapon) == -1)
                    {
                        weaponNumber = rightWeapons[0];
                    }
                    // Otherwise, cycle through the list.
                    else
                    {
                        int currentIndex = System.Array.IndexOf(rightWeapons, rpgCharacterController.rightWeapon);
                        weaponNumber = rightWeapons[(currentIndex + 1) % rightWeapons.Length];
                    }

                    context.side        = "Right";
                    context.leftWeapon  = -1;
                    context.rightWeapon = weaponNumber;
                }
            }
            // If we've received input, then "doSwitch" is true, and the context is filled out,
            // so start the SwitchWeapon action.
            if (doSwitch)
            {
                rpgCharacterController.StartAction("SwitchWeapon", context);
            }
        }
Esempio n. 4
0
        private void WeaponSwitching()
        {
            if (!rpgCharacterController.CanStartAction("SwitchWeapon"))
            {
                return;
            }

            bool doSwitch = false;
            SwitchWeaponContext context = new SwitchWeaponContext();

            if (rpgCharacterController.rightWeapon != (int)Weapon.Unarmed || rpgCharacterController.leftWeapon != (int)Weapon.Unarmed)
            {
                if (GUI.Button(new Rect(1115, 280, 100, 30), "Unarmed"))
                {
                    doSwitch            = true;
                    context.type        = "Switch";
                    context.side        = "Dual";
                    context.leftWeapon  = (int)Weapon.Unarmed;
                    context.rightWeapon = (int)Weapon.Unarmed;
                }
            }

            // Two-handed weapons.
            Weapon[] weapons = new Weapon[] {
                Weapon.TwoHandSword,
            };
            int offset = 310;

            foreach (Weapon weapon in weapons)
            {
                if (rpgCharacterController.rightWeapon != (int)weapon)
                {
                    string label = weapon.ToString();
                    if (label.StartsWith("TwoHand"))
                    {
                        label = label.Replace("TwoHand", "2H ");
                    }
                    if (GUI.Button(new Rect(1115, offset, 100, 30), label))
                    {
                        doSwitch            = true;
                        context.type        = "Switch";
                        context.side        = "None";
                        context.leftWeapon  = -1;
                        context.rightWeapon = (int)weapon;
                    }
                }
                offset += 30;
            }

            // Instant weapon toggle.
            useInstant = GUI.Toggle(new Rect(1130, 350, 100, 30), useInstant, "Instant");
            if (useInstant)
            {
                context.type = "Instant";
            }

            // Perform the weapon switch.
            if (doSwitch)
            {
                rpgCharacterController.StartAction("SwitchWeapon", context);
            }
        }