Exemplo n.º 1
0
        void DoTheMethod()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go == null)
            {
                return;
            }

            theScript.AddForce(force.Value);
        }
Exemplo n.º 2
0
    public void getHit(DamageObject d, int fixedDir = 0)
    {
        bool wasHit = true;

        if (playerState.currentState == PLAYERSTATE.KNOCKDOWN)
        {
            wasHit = false;
        }

        // HOTFIX for addForce making character not grounded.
        if (controller.isGrounded == false && playerState.currentState != PLAYERSTATE.HIT && playerState.currentState != PLAYERSTATE.DEFENDING)
        {
            d.attackType      = AttackType.KnockDown;
            HitKnockDownCount = 0;
        }

        //defend
        if (playerState.currentState == PLAYERSTATE.DEFENDING)
        {
            wasHit = false;
            UpdateDefenseCounter();

            if (d.attackType == AttackType.Stagger || d.attackType == AttackType.KnockDown)
            {
                wasHit = true;
                anim.Staggered();
                playerState.SetState(PLAYERSTATE.STAGGERED);
                anim.ShowStaggerEffect();
                anim.AddForce(0.005f, d.inflictor.GetComponent <Action>().facingRight);
                DefenseCount = 0;
                return;
            }
            else if (DefenseCount >= DefenseThreshold)
            {
                anim.Staggered();
                playerState.SetState(PLAYERSTATE.STAGGERED);
                anim.ShowStaggerEffect();
                anim.AddForce(0.005f, d.inflictor.GetComponent <Action>().facingRight);

                DefenseCount = 0;
                return;
            }
            else
            {
//			if(BlockAttacksFromBehind || isFacingTarget (d.inflictor)) wasHit = false;
//			if(!wasHit){
////				GlobalAudioPlayer.PlaySFX ("Defend");
////				anim.ShowDefendEffect();
//
                anim.ShowDefendEffect();
                anim.AddForce(0.005f, d.inflictor.GetComponent <Action>().facingRight);

//			}
            }
        }

        //parry //need to add math for different types of attack
        //if (playerState.currentState == PLAYERSTATE.ATTACK) {
        //          anim.ShowParryEffect();
        //	wasHit = false;
        //}

        if (wasHit)
        {
            UpdateHitCounter();
        }

        if (HitKnockDownCount >= HitKnockDownThreshold)
        {
            d.attackType      = AttackType.KnockDown;
            HitKnockDownCount = 0;
        }


        //start knockDown sequence
        if (wasHit && playerState.currentState != PLAYERSTATE.KNOCKDOWN)
        {
//			GetComponent<HealthSystem> ().SubstractHealth (d.damage);
            anim.ShowHitEffect();

            moveVector.x     = 0;
            moveVector.z     = 0;
            verticalVelocity = 0;

            if (d.attackType == AttackType.Paralyze)
            {
                playerState.SetState(PLAYERSTATE.PARALYZED);
                anim.Paralyzed();
            }
            else if (d.attackType == AttackType.KnockDown)
            {
                playerState.SetState(PLAYERSTATE.KNOCKBACK);
                KnockBack(d.inflictor);

                verticalVelocity = 5f;
                if (d.verticalForce != 0f)
                {
                    verticalVelocity = d.verticalForce;
                }

                anim.AddForce(d.force * 20, d.inflictor.GetComponent <Action>().facingRight);
            }
            else
            {
                playerState.SetState(PLAYERSTATE.HIT);
                anim.Hit();
                anim.AddForce(d.force, d.inflictor.GetComponent <Action>().facingRight);
            }
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// 我们被击中
    /// </summary>
    /// <param name="damage">伤害</param>
    public void Hit(DamageObject damage)
    {
        //判断是否可以再次被击中的时间间隔
        if (Time.time < LastHitTime + hitThreshold)
        {
            return;
        }
        //检查我们是否处于可被攻击状态
        if (HitableStates.Contains(playerState.currentState))
        {
            CancelInvoke();

            //被攻击时摄像机抖动
            CameraShake camShake = Camera.main.GetComponent <CameraShake>();
            if (camShake != null)
            {
                camShake.Shake(.1f);
            }

            //防御接下来的攻击
            if (playerState.currentState == PLAYERSTATE.DEFEND && !damage.DefenceOverride && (IsFacingTarget(damage.inflictor) || blockAttacksFromBehind))
            {
                Defend(damage);
                return;
            }
            else
            {
                playerAnimator.SetAnimatorBool("Defend", false);
            }

            UpdateHitCounter();
            LastHitTime = Time.time;

            //展示被击中特效
            playerAnimator.ShowHitEffect();

            //减少生命值
            HealthSystem healthSystem = GetComponent <HealthSystem>();
            if (healthSystem != null)
            {
                healthSystem.SubstractHealth(damage.damageCount);
                if (healthSystem.CurrentHp == 0)
                {
                    return;
                }
            }

            //检查是否被击倒在地
            if ((hitKnockDownCount >= knockdownHitCount || !IsGrounded() || damage.knockDown) && playerState.currentState != PLAYERSTATE.KNOCKDOWN)
            {
                hitKnockDownCount = 0;
                StopCoroutine("KnockDownSequence");
                StartCoroutine("KnockDownSequence", damage.inflictor);
                GlobalAudioPlayer.PlaySFXAtPosition(damage.hitSFX, transform.position + Vector3.up);
                GlobalAudioPlayer.PlaySFXAtPosition(knockdownVoiceSFX, transform.position + Vector3.up);
                return;
            }

            //默认被击
            int i = Random.Range(1, 3);
            playerAnimator.SetAnimatorTrigger("Hit" + i);
            SetVelocity(Vector3.zero);
            playerState.SetState(PLAYERSTATE.HIT);

            //从冲击中增加一点力
            if (IsFacingTarget(damage.inflictor))
            {
                playerAnimator.AddForce(-1.5f);
            }
            else
            {
                playerAnimator.AddForce(1.5f);
            }

            //音效
            GlobalAudioPlayer.PlaySFXAtPosition(damage.hitSFX, transform.position + Vector3.up);
            GlobalAudioPlayer.PlaySFXAtPosition(hitVoiceSFX, transform.position + Vector3.up);

            Invoke("Ready", hitRecoveryTime);
        }
    }
Exemplo n.º 4
0
    //we are hit
    private void Hit(DamageObject d)
    {
        if (!HitStates.Contains(playerState.currentState))
        {
            bool wasHit = true;
            UpdateHitCounter();

            //defend
            if (playerState.currentState == PLAYERSTATE.DEFENDING)
            {
                if (BlockAttacksFromBehind || isFacingTarget(d.inflictor))
                {
                    wasHit = false;
                }
                if (!wasHit)
                {
                    GlobalAudioPlayer.PlaySFX("Defend");
                    animator.ShowDefendEffect();
                    animator.CamShakeSmall();

                    if (isFacingTarget(d.inflictor))
                    {
                        animator.AddForce(-1.5f);
                    }
                    else
                    {
                        animator.AddForce(1.5f);
                    }
                }
            }

            //knockdown hit
            if (HitKnockDownCount >= HitKnockDownThreshold)
            {
                d.attackType      = AttackType.KnockDown;
                HitKnockDownCount = 0;
            }

            //getting hit while being in the air also causes a knockdown
            if (!GetComponent <PlayerMovement>().playerIsGrounded())
            {
                d.attackType      = AttackType.KnockDown;
                HitKnockDownCount = 0;
            }

            //we are dead
            if (GetComponent <HealthSystem>() != null && GetComponent <HealthSystem>().CurrentHp == 0)
            {
                gameObject.SendMessage("Death");
            }

            //play hit SFX
            if (wasHit)
            {
                GlobalAudioPlayer.PlaySFX("PunchHit");
            }

            //start knockDown sequence
            if (wasHit && playerState.currentState != PLAYERSTATE.KNOCKDOWN)
            {
                GetComponent <HealthSystem> ().SubstractHealth(d.damage);
                animator.ShowHitEffect();

                if (d.attackType == AttackType.KnockDown)
                {
                    playerState.SetState(PLAYERSTATE.KNOCKDOWN);
                    StartCoroutine(KnockDown(d.inflictor));
                }
                else
                {
                    playerState.SetState(PLAYERSTATE.HIT);
                    animator.Hit();
                }
            }
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// 被击中
    /// </summary>
    /// <param name="d"></param>
    public void Hit(DamageObject d)
    {
        if (HitableStates.Contains(enemyState))
        {
            //只在敌人被击倒时才允许地面攻击击中
            if (enemyState == PLAYERSTATE.KNOCKDOWNGROUNDED && !d.isGroundAttack)
            {
                return;
            }

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

            //增加攻击时间,使玩家被击中后无法立即攻击
            lastAttackTime = Time.time;

            //当敌人在空中时不能被击中
            if ((enemyState == PLAYERSTATE.KNOCKDOWNGROUNDED || enemyState == PLAYERSTATE.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));

            //相机抖动
            CameraShake camShake = Camera.main.GetComponent <CameraShake>();
            if (camShake != null)
            {
                camShake.Shake(0.1f);
            }

            //激活慢动作相机
            if (d.slowMotionEffect)
            {
                CameraSlowMotion cmd = Camera.main.GetComponent <CameraSlowMotion>();
                if (cmd != null)
                {
                    cmd.StartSlowMotionDelay(.2f);
                }
            }

            //减少生命值
            HealthSystem hs = GetComponent <HealthSystem>();
            if (hs != null)
            {
                hs.SubstractHealth(d.damageCount);
                if (hs.CurrentHp == 0)
                {
                    return;
                }
            }

            //地面攻击
            if (enemyState == PLAYERSTATE.KNOCKDOWNGROUNDED)
            {
                StopAllCoroutines();
                enemyState = PLAYERSTATE.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);
                playerAnimator.SetAnimatorTrigger("Hit" + rand);
                enemyState = PLAYERSTATE.HIT;

                //从冲击中增加很小的力量
                LookAtTarget(d.inflictor.transform);
                playerAnimator.AddForce(-KnockbackForce);

                //受到攻击时将敌人的状态从被动变为主动
                if (enemyTactic != ENEMYTACTIC.ENGAGE)
                {
                    EnemyManager.SetAgressive(gameObject);
                }

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