예제 #1
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);
            });
        }
예제 #2
0
파일: Attack.cs 프로젝트: Branco5/DV_Lab5
        protected override void _StartAction(RPGCharacterController controller, AttackContext context)
        {
            int   attackSide   = 0;
            int   attackNumber = context.number;
            int   weaponNumber = controller.rightWeapon;
            float duration     = 0f;

            if (context.side == (int)AttackSide.Right && AnimationData.Is2HandedWeapon(weaponNumber))
            {
                context.side = (int)AttackSide.None;
            }

            switch (context.side)
            {
            case (int)AttackSide.None:
                attackSide   = 0;
                weaponNumber = controller.rightWeapon;
                break;

            case (int)AttackSide.Left:
                attackSide   = 1;
                weaponNumber = controller.leftWeapon;
                break;

            case (int)AttackSide.Right:
                attackSide   = 2;
                weaponNumber = controller.rightWeapon;
                break;
            }

            if (attackNumber == -1)
            {
                switch (context.type)
                {
                case "Attack":
                    attackNumber = AnimationData.RandomAttackNumber(attackSide, weaponNumber);
                    break;

                case "Kick":
                    attackNumber = AnimationData.RandomKickNumber(attackSide);
                    break;
                }
            }

            duration = AnimationData.AttackDuration(attackSide, weaponNumber, attackNumber);

            if (controller.isMoving)
            {
                controller.RunningAttack(
                    attackSide,
                    controller.hasLeftWeapon,
                    controller.hasRightWeapon,
                    controller.hasTwoHandedWeapon
                    );
                EndAction(controller);
            }
            else if (context.type == "Attack")
            {
                controller.Attack(
                    attackNumber,
                    controller.leftWeapon,
                    controller.rightWeapon,
                    duration
                    );
                EndAction(controller);
            }
        }