Example #1
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();
                }
            }
        }
    }