public override void DeathBehavior(float timeSpentInCurrentState)
    {
        if (timeSpentInCurrentState < Time.fixedDeltaTime)
        {
            _enemyAnimator.Stop();
            _enemyAnimator.Play("OrbiterDeath");

            //ignore all collision
            _rigidbody.detectCollisions = false;

            //move to DontHit layer (so that dying enemy doesn't get hit by projectiles)
            gameObject.layer = LayerMask.NameToLayer("DontHit");
            _hitbox.layer    = LayerMask.NameToLayer("DontHit");

            if (_deathClip)
            {
                AudioUtility.CreateSFX(_deathClip, transform.position, AudioUtility.AudioGroups.EnemySpawn, 0.6f, 5f, 500f, 1f);
            }
        }

        //fade out idle audio during deathDuration (idle audio starts at volume 0.1)
        _mainAudioSource.volume = Mathf.Lerp(0.1f, 0f, (Time.time - timeSpentInCurrentState) / _deathDuration);

        if (timeSpentInCurrentState >= _deathDuration)
        {
            OnDeathComplete.Invoke();
        }
    }
Exemplo n.º 2
0
    void DetectHitReactions()
    {
        if (!isAlive)
        {
            SetToMagicCameraAngle();

            if (animator.onAnimationComplete("Hit Reaction", 0.9f))
            {
                animator.Play("Death");
            }

            if (animator.onAnimationComplete("Critical Hit Reaction", 0.9f))
            {
                animator.Play("Death");
            }

            if (animator.onAnimationComplete("Death", 0.95f))
            {
                this.gameObject.SetActive(false);

                OnAttackComplete.Invoke();
                OnDeathComplete.Invoke();
            }
            return;
        }

        if (animator.onAnimationComplete("Hit Reaction", 0.95f))
        {
            timesHit += 1;

            OnHitReactionComplete.Invoke();
        }

        if (animator.onAnimationComplete("Critical Hit Reaction", 0.95f))
        {
            timesHit += 1;

            OnHitReactionComplete.Invoke();
        }

        if (animator.onAnimationComplete("Dodge", 0.95f))
        {
            OnHitReactionComplete.Invoke();
        }

        if (animator.onAnimationComplete("Critical Hit Dodge", 0.95f))
        {
            OnHitReactionComplete.Invoke();
        }
    }
Exemplo n.º 3
0
    public override void DeathBehavior(float timeSpentInCurrentState)
    {
        if (timeSpentInCurrentState < Time.fixedDeltaTime)
        {
            _enemyAnimator.Stop();
            _enemyAnimator.Play("GolemDeath");

            //ignore all collision
            _bodyRigidbody.detectCollisions = false;

            //move to DontHit layer (so that dying enemy doesn't get hit by projectiles)
            gameObject.layer = LayerMask.NameToLayer("DontHit");
            _hitbox.layer    = LayerMask.NameToLayer("DontHit");
            _hurtbox.layer   = LayerMask.NameToLayer("DontHit");

            //stop moving
            ChangeVelocity(new Vector3(0, 0, 0));

            //turn off lasers
            _aimLaser.gameObject.SetActive(false);
            _attackLaser.gameObject.SetActive(false);
            _laserHum.gameObject.SetActive(false);

            //spawn pickup
            PickupManager.Instance.ChooseDeathPickup(_eyeTransform.position);


            if (_deathClip)
            {
                AudioUtility.CreateSFX(_deathClip, transform.position, AudioUtility.AudioGroups.EnemySpawn, 0.6f, 5f, 500f, 1f);
            }
        }

        _mainAudioSource.volume = Mathf.Lerp(0.3f, 0f, (Time.time - timeSpentInCurrentState) / _deathDuration);

        if (timeSpentInCurrentState >= _deathDuration)
        {
            OnDeathComplete.Invoke();
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        DetectHitReactions();

        if (!isAlive)
        {
            SetToMagicCameraAngle();

            if (animator.onAnimationComplete("Hit Reaction", 0.9f))
            {
                animator.Play("Death");
            }

            if (animator.onAnimationComplete("Critical Hit Reaction", 0.9f))
            {
                animator.Play("Death");
            }

            if (animator.onAnimationComplete("Death", 0.95f))
            {
                this.gameObject.SetActive(false);

                OnAttackComplete.Invoke();
                OnDeathComplete.Invoke();
            }
        }

        if (attacking && isAlive)
        {
            Battler opposingBattler = attackTarget.GetComponent <Battler>();
            if (!targetsLocked)
            {
                foreach (Transform child in opposingBattler.GetComponentsInChildren <Transform>())
                {
                    if (child.tag == "Projectile Target")
                    {
                        projectileTarget = child;
                        targetsLocked    = true;
                    }
                }
            }

            opposingBattler.OnHitReactionComplete.AddListener(delegate {
                attacking       = false;
                completedAttack = true;
                // enemyWeaponCollider.SetActive(false);

                OnAttackComplete.Invoke();
            });

            opposingBattler.OnDeathComplete.AddListener(delegate {
                attacking       = false;
                completedAttack = true;

                OnAttackComplete.Invoke();
            });

            if (!attacked)
            {
                mainCamera.transform.position = opposingBattler.magicTargetCameraAngle.transform.position;
                mainCamera.transform.rotation = opposingBattler.magicTargetCameraAngle.transform.rotation;

                if (!windingUp)
                {
                    windingUp = true;

                    bool isAttackCritical = AttackIsCritical();
                    transform.LookAt(attackTarget.transform);

                    if (isAttackCritical)
                    {
                        animator.Play("Critical Attack");
                    }
                    else
                    {
                        animator.Play("Attack");
                    }
                }


                if (animator.onAnimationComplete("Attack", 0.19f))
                {
                    if (!spawnedArrow)
                    {
                        arrowInstance = bow.SpawnArrow(arrowSpawnPoint);
                        spawnedArrow  = true;
                    }
                }

                if (animator.onAnimationComplete("Attack", 0.7f))
                {
                    arrowInstance.OnArrowFired.AddListener(delegate {
                        attacked = true;
                    });

                    arrowInstance.HalfwayToTarget.AddListener(delegate {
                        SetToMagicTargetCameraAngle();
                        opposingBattler.OnDodgeComplete.AddListener(delegate {
                            arrowInstance.Reset();

                            attacking       = false;
                            completedAttack = true;

                            OnAttackComplete.Invoke();
                        });

                        // dodgedArrow = opposingBattler.AttemptDodgeArrow(arrowInstance);
                    });

                    arrowInstance.ReachedTarget.AddListener(delegate {
                        reachedEnemy = true;
                    });

                    if (!firedArrow)
                    {
                        arrowInstance.Shoot(projectileTarget, projectileLaunchPoint);
                        firedArrow = true;
                    }
                }

                if (animator.onAnimationComplete("Critical Attack", 0.3f))
                {
                    if (!spawnedArrow)
                    {
                        arrowInstance = bow.SpawnArrow(arrowSpawnPoint);
                        spawnedArrow  = true;
                    }
                }

                if (animator.onAnimationComplete("Shoot Arrow", 0.3f))
                {
                    arrowInstance.OnArrowFired.AddListener(delegate {
                        attacked = true;
                    });

                    arrowInstance.HalfwayToTarget.AddListener(delegate {
                        SetToMagicTargetCameraAngle();
                        opposingBattler.OnDodgeComplete.AddListener(delegate {
                            arrowInstance.Reset();

                            attacking       = false;
                            completedAttack = true;

                            OnAttackComplete.Invoke();
                        });

                        // dodgedArrow = opposingBattler.AttemptDodgeArrow(arrowInstance);
                    });

                    arrowInstance.ReachedTarget.AddListener(delegate {
                        reachedEnemy = true;
                    });

                    if (!firedArrow)
                    {
                        arrowInstance.Shoot(projectileTarget, projectileLaunchPoint);
                        firedArrow = true;
                    }
                }

                return;
            }

            if (!reachedEnemy)
            {
                bool finishedAttacking =
                    animator.onAnimationComplete("Attack", 1f) ||
                    animator.onAnimationComplete("Shoot Arrow", 1f);

                if (finishedAttacking)
                {
                    animator.Play("Idle");
                }
            }
            else
            {
                if (!dodgedArrow)
                {
                    SetCameraToDefault();
                }
            }
        }
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        DetectHitReactions();

        if (!isAlive)
        {
            SetToMagicCameraAngle();

            if (animator.onAnimationComplete("Hit Reaction", 0.9f))
            {
                animator.Play("Death");
            }

            if (animator.onAnimationComplete("Critical Hit Reaction", 0.9f))
            {
                animator.Play("Death");
            }


            if (animator.onAnimationComplete("Death", 0.95f))
            {
                this.gameObject.SetActive(false);

                OnAttackComplete.Invoke();
                OnDeathComplete.Invoke();
            }
        }

        if (attacking && isAlive)
        {
            Battler opposingBattler = attackTarget.GetComponent <Battler>();

            GameObject enemyWeaponCollider = null;
            if (opposingBattler.BattlerType == "Swordsman")
            {
                enemyWeaponCollider = attackTarget.GetComponent <SwordsmanBattler>().weaponColliderObject;
            }

            opposingBattler.OnHitReactionComplete.AddListener(delegate {
                attacking       = false;
                completedAttack = true;

                if (enemyWeaponCollider != null)
                {
                    enemyWeaponCollider.SetActive(false);
                }

                OnAttackComplete.Invoke();
            });

            opposingBattler.OnDeathComplete.AddListener(delegate {
                attacking       = false;
                completedAttack = true;

                OnAttackComplete.Invoke();
            });

            if (!attacked)
            {
                SetToMagicCameraAngle();

                transform.LookAt(attackTarget.transform);
                animator.Play("Standing 2H Magic Attack 3");

                if (animator.onAnimationComplete("Standing 2H Magic Attack 3", .3f) && !circleSpawned)
                {
                    grimiore.OnCastingCircleSpawn.AddListener(delegate {
                        circleSpawned = true;
                    });

                    grimiore.SpawnCastingCircle(castingCircleTarget);
                }

                if (animator.onAnimationComplete("Standing 2H Magic Attack 3", .8f))
                {
                    grimiore.OnParticleEffectSpawn.AddListener(delegate {
                        attacked = true;
                    });

                    grimiore.OnParticleEffectHalfway.AddListener(delegate {
                        if (!reachedEnemy)
                        {
                            grimiore.DestroyCastingCircle();

                            SetToMagicTargetCameraAngle();
                            opposingBattler.OnDodgeComplete.AddListener(delegate {
                                projectileInstance.Reset();

                                attacking       = false;
                                completedAttack = true;
                                entity.HasMoved = true;

                                if (enemyWeaponCollider != null)
                                {
                                    enemyWeaponCollider.SetActive(false);
                                }

                                OnAttackComplete.Invoke();
                            });

                            dodgedAttack = opposingBattler.AttemptMagicDodge(projectileInstance);

                            if (enemyWeaponCollider != null)
                            {
                                enemyWeaponCollider.SetActive(true);   // Prevent bouncing off weapon's mesh...
                            }
                        }
                    });

                    grimiore.OnParticleEffectLanded.AddListener(delegate {
                        reachedEnemy = true;
                    });

                    if (grimiore.magicEffect.particleType == "Magic Projectile")
                    {
                        LaunchMagicProjectile();
                    }
                }
                return;
            }

            if (!reachedEnemy)
            {
                if (animator.onAnimationComplete("Standing 2H Magic Attack 3", 1f))
                {
                    animator.Play("Idle");
                }
            }
            else
            {
                if (!dodgedAttack)
                {
                    SetCameraToDefault();
                }
            }
        }
    }