Exemplo n.º 1
0
    private void doAttack(DamageObject damageObject, UNITSTATE state, string inputAction)
    {
        animator.SetAnimatorTrigger(damageObject.animTrigger);
        playerState.SetState(state);

        //save attack data
        lastAttack           = damageObject;
        lastAttack.inflictor = gameObject;
        lastAttackTime       = Time.time;
        lastAttackInput      = inputAction;
        lastAttackDirection  = currentDirection;

        //turn towards current input direction
        TurnToDir(currentDirection);

        if (isGrounded)
        {
            SetVelocity(Vector3.zero);
        }
        if (damageObject.forwardForce > 0)
        {
            animator.AddForce(damageObject.forwardForce);
        }

        if (state == UNITSTATE.JUMPKICK)
        {
            return;
        }
        Invoke("Ready", damageObject.duration);
    }
Exemplo n.º 2
0
    //we are hit  被攻击
    public void Hit(DamageObject d)
    {
        //Camera Shake
        CamShake camShake = Camera.main.GetComponent <CamShake>();

        if (camShake != null)
        {
            camShake.Shake(.2f);
        }

        //check for hit
        anim.SetAnimatorTrigger("Hit1");
        enemyState = UNITSTATE.HIT;

        //add small force from the impact
        LookAtTarget(d.inflictor.transform);
        anim.AddForce(-knockbackForce);
    }
Exemplo n.º 3
0
    //we are hit
    public void Hit(DamageObject d)
    {
        //check if we can get hit again
        if (Time.time < LastHitTime + hitThreshold)
        {
            return;
        }

        //check if we are in a hittable state
        if (HitableStates.Contains(playerState.currentState))
        {
            CancelInvoke();

            //camera Shake
            CamShake camShake = Camera.main.GetComponent <CamShake>();
            if (camShake != null)
            {
                camShake.Shake(.1f);
            }

            //defend incoming attack
            if (playerState.currentState == UNITSTATE.DEFEND && !d.DefenceOverride && (isFacingTarget(d.inflictor) || blockAttacksFromBehind))
            {
                Defend(d);
                return;
            }
            else
            {
                animator.SetAnimatorBool("Defend", false);
            }

            //we are hit
            UpdateHitCounter();
            LastHitTime = Time.time;

            //show hit effect
            animator.ShowHitEffect();

            //substract health
            HealthSystem hs = GetComponent <HealthSystem> ();
            if (hs != null)
            {
                hs.SubstractHealth(d.damage);
                if (hs.CurrentHp == 0)
                {
                    return;
                }
            }

            //check for knockdown
            if ((hitKnockDownCount >= knockdownHitCount || !IsGrounded() || d.knockDown) && playerState.currentState != UNITSTATE.KNOCKDOWN)
            {
                hitKnockDownCount = 0;
                StopCoroutine("KnockDownSequence");
                StartCoroutine("KnockDownSequence", d.inflictor);
                GlobalAudioPlayer.PlaySFXAtPosition(d.hitSFX, transform.position + Vector3.up);
                GlobalAudioPlayer.PlaySFXAtPosition(knockdownVoiceSFX, transform.position + Vector3.up);
                return;
            }

            //default hit
            int i = Random.Range(1, 3);
            animator.SetAnimatorTrigger("Hit" + i);
            SetVelocity(Vector3.zero);
            playerState.SetState(UNITSTATE.HIT);

            //add a small force from the impact
            if (isFacingTarget(d.inflictor))
            {
                animator.AddForce(-1.5f);
            }
            else
            {
                animator.AddForce(1.5f);
            }

            //SFX
            GlobalAudioPlayer.PlaySFXAtPosition(d.hitSFX, transform.position + Vector3.up);
            GlobalAudioPlayer.PlaySFXAtPosition(hitVoiceSFX, transform.position + Vector3.up);

            Invoke("Ready", hitRecoveryTime);
        }
    }
Exemplo n.º 4
0
    //Unit was hit
    public void Hit(DamageObject d)
    {
        if (HitableStates.Contains(enemyState))
        {
            //only allow ground attacks to hit us when we are knocked down
            if (enemyState == UNITSTATE.KNOCKDOWNGROUNDED && !d.isGroundAttack)
            {
                return;
            }

            CancelInvoke();
            StopAllCoroutines();
            animator.StopAllCoroutines();
            Move(Vector3.zero, 0f);

            //add attack time out so this enemy cannot attack instantly after a hit
            lastAttackTime = Time.time;

            //don't hit this unit when it's allready down
            if ((enemyState == UNITSTATE.KNOCKDOWNGROUNDED || enemyState == UNITSTATE.GROUNDHIT) && !d.isGroundAttack)
            {
                return;
            }

            //defend an incoming attack
            if (!d.DefenceOverride && defendableStates.Contains(enemyState))
            {
                int rand = Random.Range(0, 100);
                if (rand < defendChance)
                {
                    Defend();
                    return;
                }
            }

            //hit sfx
            GlobalAudioPlayer.PlaySFXAtPosition(d.hitSFX, transform.position);

            //hit particle effect
            ShowHitEffectAtPosition(new Vector3(transform.position.x, d.inflictor.transform.position.y + d.collHeight, transform.position.z));

            //camera Shake
            CamShake camShake = Camera.main.GetComponent <CamShake>();
            if (camShake != null)
            {
                camShake.Shake(.1f);
            }

            //activate slow motion camera
            if (d.slowMotionEffect)
            {
                CamSlowMotionDelay cmd = Camera.main.GetComponent <CamSlowMotionDelay>();
                if (cmd != null)
                {
                    cmd.StartSlowMotionDelay(.2f);
                }
            }

            //substract health
            HealthSystem hs = GetComponent <HealthSystem>();
            if (hs != null)
            {
                hs.SubstractHealth(d.damage);
                if (hs.CurrentHp == 0)
                {
                    return;
                }
            }

            //ground attack
            if (enemyState == UNITSTATE.KNOCKDOWNGROUNDED)
            {
                StopAllCoroutines();
                enemyState = UNITSTATE.GROUNDHIT;
                StartCoroutine(GroundHit());
                return;
            }

            //turn towards the direction of the incoming attack
            int dir = d.inflictor.transform.position.x > transform.position.x? 1 : -1;
            TurnToDir((DIRECTION)dir);

            //check for a knockdown
            if (d.knockDown)
            {
                StartCoroutine(KnockDownSequence(d.inflictor));
                return;
            }
            else
            {
                //default hit
                int rand = Random.Range(1, 3);
                animator.SetAnimatorTrigger("Hit" + rand);
                enemyState = UNITSTATE.HIT;

                //add small force from the impact
                LookAtTarget(d.inflictor.transform);
                animator.AddForce(-KnockbackForce);

                //switch  enemy state from passive to aggressive when attacked
                if (enemyTactic != ENEMYTACTIC.ENGAGE)
                {
                    EnemyManager.setAgressive(gameObject);
                }

                Invoke("Ready", hitRecoveryTime);
                return;
            }
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// 被攻击
    /// </summary>
    /// <param name="d"></param>
    public void Hit(DamageObject d)
    {
        if (HitableStates.Contains(enemyState))
        {
            //只有在第一次被击倒时才能进行地面攻击
            if (enemyState == UNITSTATE.KNOCKDOWNGROUNDED && !d.isGroundAttack)
            {
                return;
            }

            CancelInvoke();
            StopAllCoroutines();
            animator.StopAllCoroutines();
            Move(Vector3.zero, 0f);

            //给敌人添加硬直时间
            lastAttackTime = Time.time;

            //在倒地状态只能被攻击一次
            if ((enemyState == UNITSTATE.KNOCKDOWNGROUNDED || enemyState == UNITSTATE.GROUNDHIT) && !d.isGroundAttack)
            {
                return;
            }

            //防御状态能够攻击
            if (!d.DefenceOverride && defendableStates.Contains(enemyState))
            {
                int rand = Random.Range(0, 100);
                if (rand < defendChance)
                {
                    Defend();
                    return;
                }
            }

            //攻击声音播放
            GlobalAudioPlayer.PlaySFXAtPosition(d.hitSFX, transform.position);

            //攻击特效
            ShowHitEffectAtPosition(new Vector3(transform.position.x, d.inflictor.transform.position.y + d.collHeight, transform.position.z));

            //相机震动
            CamShake camShake = Camera.main.GetComponent <CamShake>();
            if (camShake != null)
            {
                camShake.Shake(.1f);
            }

            //摄像机慢动作
            if (d.slowMotionEffect)
            {
                CamSlowMotionDelay cmd = Camera.main.GetComponent <CamSlowMotionDelay>();
                if (cmd != null)
                {
                    cmd.StartSlowMotionDelay(.2f);
                }
            }

            //减少HP
            HealthSystem hs = GetComponent <HealthSystem>();
            if (hs != null)
            {
                hs.SubstractHealth(d.damage);
                if (hs.CurrentHp == 0)
                {
                    return;
                }
            }

            //地面攻击
            if (enemyState == UNITSTATE.KNOCKDOWNGROUNDED)
            {
                StopAllCoroutines();
                enemyState = UNITSTATE.GROUNDHIT;
                StartCoroutine(GroundHit());
                return;
            }

            //转向攻击的方向
            int dir = d.inflictor.transform.position.x > transform.position.x? 1 : -1;
            TurnToDir((DIRECTION)dir);

            //检测是否倒地
            if (d.knockDown)
            {
                StartCoroutine(KnockDownSequence(d.inflictor));
                return;
            }
            else
            {
                //默认攻击
                int rand = Random.Range(1, 3);
                animator.SetAnimatorTrigger("Hit" + rand);
                enemyState = UNITSTATE.HIT;

                //对攻击对象施加力
                LookAtTarget(d.inflictor.transform);
                animator.AddForce(-KnockbackForce);

                //当收到攻击的时候将敌人的状态从被动切换到主动
                if (enemyTactic != ENEMYTACTIC.ENGAGE)
                {
                    EnemyManager.setAgressive(gameObject);
                }

                Invoke("Ready", hitRecoveryTime);
                return;
            }
        }
    }