Ejemplo n.º 1
0
        protected override void _StartAction(RPGCharacterController controller, bool?instant)
        {
            bool useInstant = instant.HasValue && instant.Value == true;

            RPGCharacterWeaponController weaponController = controller.GetComponent <RPGCharacterWeaponController>();

            if (weaponController == null)
            {
                EndAction(controller);
                return;
            }

            // If a weapon is equipped, we must sheathe it.
            if (controller.leftWeapon != (int)Weapon.Relax || controller.rightWeapon != (int)Weapon.Relax)
            {
                if (useInstant)
                {
                    weaponController.InstantWeaponSwitch((int)Weapon.Relax);
                }
                else
                {
                    weaponController.SheathWeapon(controller.rightWeapon, (int)Weapon.Relax, true);
                }
                weaponController.AddCallback(() => {
                    controller.leftWeapon  = (int)Weapon.Relax;
                    controller.rightWeapon = (int)Weapon.Relax;
                    weaponController.SyncWeaponVisibility();
                });
            }
        }
Ejemplo n.º 2
0
        protected override void _StartAction(RPGCharacterController controller, SwitchWeaponContext context)
        {
            RPGCharacterWeaponController weaponController = controller.GetComponent <RPGCharacterWeaponController>();

            if (weaponController == null)
            {
                EndAction(controller);
                return;
            }

            context.LowercaseStrings();

            bool changeRight   = false;
            bool sheathRight   = false;
            bool unsheathRight = false;
            int  fromRight     = controller.rightWeapon;
            int  toRight       = context.rightWeapon;

            int fromLeft = controller.leftWeapon;
            int toLeft   = context.leftWeapon;

            bool dualWielding = AnimationData.Is1HandedWeapon(fromRight) && AnimationData.Is1HandedWeapon(fromLeft);
            bool dualUnsheath = context.side == "dual";
            bool dualSheath   = false;

            int toAnimatorWeapon = 0;

            // Filter which side is changing.
            switch (context.side)
            {
            case "none":
            case "right":
                changeRight = true;
                if (AnimationData.Is2HandedWeapon(toRight) && !AnimationData.IsNoWeapon(fromLeft))
                {
                    toLeft     = (int)Weapon.Unarmed;
                    dualSheath = dualWielding;
                }
                break;

            case "dual":
                changeRight = true;
                dualSheath  = dualWielding;
                break;
            }

            // Force unarmed if sheathing weapons.
            if (context.type == "sheath")
            {
                if (context.side == "none" || context.side == "right" || context.side == "dual" || context.side == "both")
                {
                    toRight = (int)Weapon.Unarmed;
                }
            }

            // Sheath weapons first if our starting weapon is different from our desired weapon and we're
            // not starting from an unarmed position.
            if (context.type == "sheath" || context.type == "switch")
            {
                sheathRight      = changeRight && fromRight != toRight && !AnimationData.IsNoWeapon(fromRight);
                toAnimatorWeapon = AnimationData.ConvertToAnimatorWeapon(toLeft, toRight);
            }

            // Unsheath a weapon if our starting weapon is different from our desired weapon and we're
            // not ending on an unarmed position.
            if (context.type == "unsheath" || context.type == "switch")
            {
                unsheathRight = changeRight && fromRight != toRight && !AnimationData.IsNoWeapon(toRight);
            }

            ///
            /// Actually make changes to the weapon controller.
            ///

            if (context.type == "instant")
            {
                if (changeRight)
                {
                    weaponController.InstantWeaponSwitch(toRight);
                }
            }
            else
            {
                // Sheath weapons first if that's necessary.
                if (sheathRight)
                {
                    // Debug.Log("Sheath Right (dual: " + dualSheath + "): " + fromRight + " > " + toRight);
                    weaponController.SheathWeapon(fromRight, toAnimatorWeapon, dualSheath);
                }
                // Finally, unsheath the desired weapons!
                if (unsheathRight)
                {
                    // Debug.Log("Unsheath Right (dual: " + dualUnsheath + "): " + toRight);
                    weaponController.UnsheathWeapon(toRight, dualUnsheath);
                }
            }

            // This callback will update the weapons in character controller after all other
            // coroutines finish.
            weaponController.AddCallback(() => {
                if (changeRight)
                {
                    controller.rightWeapon = toRight;
                }

                // Turn off the isWeaponSwitching flag and sync weapon object visibility.
                weaponController.SyncWeaponVisibility();
                EndAction(controller);
            });
        }