예제 #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();
                });
            }
        }
예제 #2
0
        protected override void _StartAction(RPGCharacterController controller, EmptyContext context)
        {
            Collider ladder = controller.ladder;
            SuperCharacterController superCharacterController = movement.GetComponent <SuperCharacterController>();

            float   threshold          = 1f;
            Vector3 ladderTop          = new Vector3(ladder.transform.position.x, ladder.bounds.max.y, ladder.transform.position.z);
            Vector3 ladderBottom       = new Vector3(ladder.transform.position.x, ladder.bounds.min.y, ladder.transform.position.z);
            float   distanceFromTop    = (controller.transform.position - ladderTop).magnitude;
            float   distanceFromBottom = (controller.transform.position - ladderBottom).magnitude;

            // If the top of the ladder is below the character's head, climb onto the top of the ladder.
            if (distanceFromTop < distanceFromBottom && distanceFromTop < threshold)
            {
                movement.ClimbLadder(false);
                controller.ClimbLadder(5);
                movement.currentState = RPGCharacterState.ClimbLadder;
            }
            else if (distanceFromBottom < distanceFromTop && distanceFromBottom < threshold)
            {
                movement.ClimbLadder(true);
                controller.ClimbLadder(6);
                movement.currentState = RPGCharacterState.ClimbLadder;
            }
        }
예제 #3
0
        protected override void _StartAction(RPGCharacterController controller, HitContext context)
        {
            int     hitNumber     = context.number;
            Vector3 direction     = context.direction;
            float   force         = context.force;
            float   variableForce = context.variableForce;

            if (hitNumber == -1)
            {
                hitNumber = AnimationData.RandomHitNumber("Knockback");
                direction = AnimationData.HitDirection("Knockback", hitNumber);
                direction = controller.transform.rotation * direction;
            }
            else
            {
                if (context.relative)
                {
                    direction = controller.transform.rotation * direction;
                }
            }

            controller.GetAngry();
            controller.Knockback(hitNumber);
            movement.KnockbackForce(direction, force, variableForce);
            movement.currentState = RPGCharacterState.Knockback;
        }
예제 #4
0
 public override bool CanStartAction(RPGCharacterController controller)
 {
     if (controller.isMoving)
     {
         return(controller.moveInput.magnitude < 0.2f);
     }
     return(controller.maintainingGround || controller.acquiringGround);
 }
예제 #5
0
 public override bool CanStartAction(RPGCharacterController controller)
 {
     return(!controller.isRelaxed &&
            (controller.rightWeapon == (int)Weapon.TwoHandCrossbow ||
             controller.rightWeapon == (int)Weapon.Rifle ||
             controller.rightWeapon == (int)Weapon.RightPistol ||
             controller.leftWeapon == (int)Weapon.LeftPistol));
 }
예제 #6
0
 protected override void _EndAction(RPGCharacterController controller)
 {
     if (controller.isSpecial)
     {
         controller.isSpecial = false;
         controller.EndSpecial();
     }
 }
예제 #7
0
 protected override void _EndAction(RPGCharacterController controller)
 {
     // If switching directly from the relaxed state, switch to unarmed.
     if (controller.leftWeapon == (int)Weapon.Relax || controller.rightWeapon == (int)Weapon.Relax)
     {
         controller.StartAction("SwitchWeapon", new SwitchWeaponContext("Unsheath", "Dual", "Hips", (int)Weapon.Unarmed, (int)Weapon.Unarmed));
     }
 }
예제 #8
0
 protected override void _StartAction(RPGCharacterController controller, EmptyContext context)
 {
     movement.currentState = RPGCharacterState.Idle;
     if (randomIdleCoroutine != null)
     {
         controller.StopCoroutine(randomIdleCoroutine);
     }
     StartRandomIdleCountdown(controller);
 }
예제 #9
0
 /// <summary>
 /// Actually end the action handler. This method unsets the active flag, calls the
 /// _EndAction method, and notifies event listeners. It won't end the action unless
 /// CanEndAction returns true.
 /// </summary>
 /// <param name="controller">RPGCharacterController instance.</param>
 public virtual void EndAction(RPGCharacterController controller)
 {
     if (CanEndAction(controller))
     {
         active = false;
         _EndAction(controller);
         OnEnd();
     }
 }
예제 #10
0
 /// <summary>
 /// Actually start the action handler. This method sets the active flag, calls the
 /// _StartAction method with object context cast into the type you want, and notifies event
 /// listeners. It won't start the action unless CanStartAction returns true.
 /// </summary>
 /// <param name="controller">RPGCharacterController instance.</param>
 /// <param name="context">Plain old context object.</param>
 public virtual void StartAction(RPGCharacterController controller, object context)
 {
     if (CanStartAction(controller))
     {
         active = true;
         _StartAction(controller, (TContext)context);
         OnStart();
     }
 }
예제 #11
0
        protected override void _StartAction(RPGCharacterController controller, EmptyContext context)
        {
            int attackNumber = 1;

            if (controller.rightWeapon == (int)Weapon.Rifle && controller.isHipShooting)
            {
                attackNumber = 2;
            }
            controller.Shoot(attackNumber);
        }
예제 #12
0
        protected override void _StartAction(RPGCharacterController controller, CastContext context)
        {
            int number = context.number;

            if (number == -1)
            {
                number = AnimationData.RandomCastNumber(context.type);
            }
            controller.StartCast(number, context.side, context.type);
        }
예제 #13
0
 protected override void _EndAction(RPGCharacterController controller)
 {
     if (controller.isSitting)
     {
         controller.isSitting = false;
         controller.Stand();
     }
     if (controller.isTalking)
     {
         controller.isTalking = false;
         controller.EndConversation();
     }
 }
예제 #14
0
        protected override void _StartAction(RPGCharacterController controller, string context)
        {
            switch (context)
            {
            case "Pickup":
                controller.Pickup();
                break;

            case "Activate":
                controller.Activate();
                break;

            case "Boost":
                controller.Boost();
                break;
            }
        }
예제 #15
0
        protected override void _StartAction(RPGCharacterController controller, string context)
        {
            switch (context)
            {
            // Sit, Sleep and Talk all stay "on", until turned off.
            case "Sit":
                controller.isSitting = true;
                controller.Sit();
                break;

            case "Sleep":
                controller.isSitting = true;
                controller.Sleep();
                break;

            case "Talk":
                controller.isTalking = true;
                controller.StartConversation();
                break;

            // Drink, Bow, Yes, and No run once and exit immediately.
            case "Drink":
                controller.Drink();
                EndAction(controller);
                break;

            case "Bow":
                controller.Bow();
                EndAction(controller);
                break;

            case "Yes":
                controller.Yes();
                EndAction(controller);
                break;

            case "No":
                controller.No();
                EndAction(controller);
                break;
            }
        }
예제 #16
0
        private IEnumerator RandomIdle(RPGCharacterController controller)
        {
            float waitTime = Random.Range(15f, 25f);

            yield return(new WaitForSeconds(waitTime));

            // If we're not still idling, stop here.
            if (!IsActive())
            {
                randomIdleCoroutine = null;
                yield break;
            }

            if (controller.canMove)
            {
                controller.RandomIdle();
            }

            StartRandomIdleCountdown(controller);
        }
예제 #17
0
 void Awake()
 {
     //set the animator component
     _instance   = this;
     animator    = GetComponentInChildren <Animator>();
     rb          = GetComponent <Rigidbody>();
     capCollider = GetComponent <CapsuleCollider>();
     FXSplash    = transform.GetChild(2).GetComponent <ParticleSystem>();
     //hide all weapons
     if (twoHandBow != null)
     {
         twoHandBow.SetActive(false);
     }
     if (swordL != null)
     {
         swordL.SetActive(false);
     }
     if (swordR != null)
     {
         swordR.SetActive(false);
     }
 }
예제 #18
0
 public override bool CanStartAction(RPGCharacterController controller)
 {
     return(controller.canAction && !controller.isRelaxed);
 }
예제 #19
0
 public override bool CanEndAction(RPGCharacterController controller)
 {
     return(IsActive());
 }
예제 #20
0
 public override bool CanStartAction(RPGCharacterController controller)
 {
     return(!IsActive());
 }
예제 #21
0
 public override bool CanStartAction(RPGCharacterController controller)
 {
     return(false);
 }
예제 #22
0
 protected override void _StartAction(RPGCharacterController controller, Vector3 context)
 {
     navigation.MeshNavToPoint(context);
 }
예제 #23
0
 public override bool CanEndAction(RPGCharacterController controller)
 {
     return(navigation != null && navigation.isNavigating);
 }
예제 #24
0
 public override bool CanStartAction(RPGCharacterController controller)
 {
     return(navigation != null && controller.canMove);
 }
예제 #25
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);
            });
        }
예제 #26
0
 private void StartRandomIdleCountdown(RPGCharacterController controller)
 {
     randomIdleCoroutine = RandomIdle(controller);
     controller.StartCoroutine(randomIdleCoroutine);
 }
예제 #27
0
 protected override void _StartAction(RPGCharacterController controller, EmptyContext context)
 {
 }
예제 #28
0
 public override bool CanStartAction(RPGCharacterController controller)
 {
     return(!controller.isKnockback);
 }
예제 #29
0
 protected override void _EndAction(RPGCharacterController controller)
 {
 }
예제 #30
0
 protected override void _EndAction(RPGCharacterController controller)
 {
     navigation.StopNavigating();
 }