Exemple #1
0
    void Attack()
    {
        if (_postAttackCooldown < 0)
        {
            _toAttack -= Time.deltaTime;

            if (_toAttack < 0)
            {
                int playerDist      = PlayerController.Instance.position - position;
                int playerDirection = playerDist < 0 ? -1 : 1;

                position += playerDirection;

                _postAttackCooldown = attackCoolDown;
            }
        }

        else
        {
            _postAttackCooldown -= Time.deltaTime;

            if (_postAttackCooldown < 0)
            {
                _currentState = ChomperState.WALKING;
            }
        }
    }
Exemple #2
0
        private IEnumerator PauseChomper(float pauseSeconds)
        {
            yield return(new WaitForSeconds(pauseSeconds));

            anim.SetFloat(HASH_PARAM_WARN_DISTANCE, 1f);
            IsPenguinGrabbed = false;
            chomperState     = ChomperState.HUNGRY;
        }
Exemple #3
0
 public void OnSpitStart()
 {
     if (!playerResurfaced)
     {
         chomperState = ChomperState.LUNGE_SUCCESS_SPIT_COMPLETE;
     }
     playerResurfaced = false;
 }
Exemple #4
0
 public override void OnProximityEnter(ProximityListener other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         chomperState = ChomperState.HUNGRY;
         setAnimation(ChomperAnimation.ANIM_IDLE_HUNGRY);
         savedCollider    = penguinObj.GetComponent <Collider>();
         isPenguinGrabbed = false;
     }
 }
Exemple #5
0
 public override void Awake()
 {
     base.Awake();
     dispatcher = Service.Get <EventDispatcher>();
     dispatcher.AddListener <DivingEvents.PlayerResurfaced>(onPlayerResurfaced);
     anim         = GetComponent <Animator>();
     chomperState = ChomperState.IDLE;
     setAnimation(ChomperAnimation.ANIM_IDLE_DEFAULT);
     savedCollider    = null;
     isPenguinGrabbed = false;
 }
Exemple #6
0
 public void OnSuccessMissAnimationComplete(string result)
 {
     if (result.Equals("Success"))
     {
         chomperState = ChomperState.LUNGE_SUCCESS_ANIMATION_COMPLETE;
     }
     else
     {
         chomperState = ChomperState.LUNGE_MISS_ANIMATION_COMPLETE;
     }
 }
Exemple #7
0
 public override void OnProximityExit(ProximityListener other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         anim.SetFloat(HASH_PARAM_WARN_DISTANCE, 1f);
         savedCollider = null;
         chomperState  = ChomperState.IDLE;
         base.transform.LookAt(LookAtPlayer(chomperState));
         setAnimation(ChomperAnimation.ANIM_IDLE_DEFAULT);
     }
 }
Exemple #8
0
 public void OnLungeComplete()
 {
     if (chomperState == ChomperState.LUNGE)
     {
         if (IsPenguinGrabbed)
         {
             chomperState = ChomperState.LUNGE_SUCCESS;
         }
         else
         {
             chomperState = ChomperState.LUNGE_MISS;
         }
     }
 }
Exemple #9
0
 private Vector3 LookAtPlayer(ChomperState state)
 {
     return((state != ChomperState.LUNGE) ? new Vector3(penguinObj.transform.position.x, base.transform.position.y, penguinObj.transform.position.z) : new Vector3(penguinObj.transform.position.x, penguinObj.transform.position.y, base.transform.position.z));
 }
Exemple #10
0
        public override void OnProximityStay(ProximityListener other)
        {
            if (!other.gameObject.CompareTag("Player"))
            {
                return;
            }
            float num   = calcDistance();
            float value = num;

            value = 3f - Mathf.Clamp(value, 2.5f, 3f);
            value = 1f - value * 2f;
            anim.SetFloat(HASH_PARAM_WARN_DISTANCE, value);
            switch (chomperState)
            {
            case ChomperState.HUNGRY:
                if (num <= 2f)
                {
                    chomperState = ChomperState.LUNGE;
                    break;
                }
                setAnimation(ChomperAnimation.ANIM_IDLE_HUNGRY);
                base.transform.LookAt(LookAtPlayer(chomperState));
                break;

            case ChomperState.LUNGE:
                setAnimation(ChomperAnimation.ANIM_LUNGE);
                base.transform.LookAt(LookAtPlayer(chomperState));
                if (IsPenguinGrabbed)
                {
                    chomperState = ChomperState.LUNGE_SUCCESS;
                    dispatcher.DispatchEvent(new DivingEvents.CollisionEffects(penguinObj.tag));
                }
                break;

            case ChomperState.LUNGE_SUCCESS:
                enablePenguinSwallow(isEnabled: false);
                setAnimation(ChomperAnimation.ANIM_SUCCESS);
                chomperState = ChomperState.LUNGE_SUCCESS_SPIT_WAIT;
                break;

            case ChomperState.LUNGE_SUCCESS_SPIT_COMPLETE:
                anim.SetFloat(HASH_PARAM_WARN_DISTANCE, 1f);
                enablePenguinSwallow(isEnabled: true);
                if (savedCollider != null)
                {
                    Vector3   vector            = (penguinObj.transform.position - base.transform.position).normalized * SpitStrength;
                    Rigidbody attachedRigidbody = savedCollider.attachedRigidbody;
                    if (attachedRigidbody != null)
                    {
                        attachedRigidbody.AddForce(vector, ForceMode.Impulse);
                    }
                    else
                    {
                        LocomotionController currentController = LocomotionHelper.GetCurrentController(savedCollider.gameObject);
                        if (currentController != null)
                        {
                            currentController.SetForce(vector, base.gameObject);
                        }
                    }
                }
                isPenguinGrabbed = false;
                chomperState     = ChomperState.LUNGE_SUCCESS_ANIMATION_WAIT;
                break;

            case ChomperState.LUNGE_SUCCESS_ANIMATION_COMPLETE:
                StartCoroutine(PauseChomper(3f));
                chomperState = ChomperState.REVIVE_PAUSE_WAIT;
                break;

            case ChomperState.LUNGE_MISS:
                setAnimation(ChomperAnimation.ANIM_MISS);
                break;

            case ChomperState.LUNGE_MISS_ANIMATION_COMPLETE:
                StartCoroutine(PauseChomper(1f));
                chomperState = ChomperState.REVIVE_PAUSE_WAIT;
                break;

            default:
                Log.LogError(this, $"O_o\t ChomperController.OnTriggerStay: ERROR: illegal internalState {(int)chomperState}, defaulting to hungry");
                chomperState = ChomperState.HUNGRY;
                setAnimation(ChomperAnimation.ANIM_IDLE_HUNGRY);
                break;

            case ChomperState.LUNGE_SUCCESS_SPIT_WAIT:
            case ChomperState.LUNGE_SUCCESS_ANIMATION_WAIT:
            case ChomperState.LUNGE_MISS_ANIMATION_WAIT:
            case ChomperState.REVIVE_PAUSE_WAIT:
                break;
            }
            if (chomperState == ChomperState.LUNGE_SUCCESS_ANIMATION_WAIT)
            {
                return;
            }
            Vector3 eulerAngles = base.gameObject.transform.eulerAngles;

            if (chomperState == ChomperState.LUNGE)
            {
                eulerAngles.x = (eulerAngles.x + 90f) % 360f;
                if (eulerAngles.x > 90f && eulerAngles.x <= 180f)
                {
                    eulerAngles.x = 90f;
                }
                else if (eulerAngles.x > 180f && eulerAngles.x < 270f)
                {
                    eulerAngles.x = 270f;
                }
            }
            else
            {
                eulerAngles.x = 0f;
            }
            if (eulerAngles.y > 90f && eulerAngles.y <= 180f)
            {
                eulerAngles.y = 90f;
            }
            else if (eulerAngles.y > 180f && eulerAngles.y < 270f)
            {
                eulerAngles.y = 270f;
            }
            base.gameObject.transform.eulerAngles = eulerAngles;
        }
Exemple #11
0
 void Start()
 {
     _currentState = ChomperState.WALKING;
 }
Exemple #12
0
 void StartAttack()
 {
     _currentState       = ChomperState.ATTACKING;
     _toAttack           = attackDelay;
     _postAttackCooldown = -1;
 }
Exemple #13
0
 void StartPursuit()
 {
     _currentState = ChomperState.RUNNING;
 }
Exemple #14
0
    //=== State Change Functions

    void StartWalking()
    {
        _nextDirectionChange = Random.Range(2.0f, 5.0f);
        _walkingDirection    = Random.Range(0, 3) - 1;
        _currentState        = ChomperState.WALKING;
    }