Ejemplo n.º 1
0
    public void TakeDamage(int damageAmount)
    {
        //Ignore damage if already dead
        if (isDead)
        {
            return;
        }

        if (isInvulnerable)
        {
            OnHitWhileInvulnerable.Invoke();
            return;
        }

        //Finally take damage
        isInvulnerable = true;
        currentHP     -= damageAmount;

        if (currentHP <= 0)
        {
            OnDeath.Invoke();
            Death();
        }
        else
        {
            OnReceiveDamage.Invoke();
            Hit();
        }
    }
    public void TakeDamage(float amount)
    {
        if (amount < 0)
        {
            throw new System.Exception("You can't deal a negative damage value to the character health");
        }

        if (OnReceiveDamage != null)
        {
            OnReceiveDamage.Invoke(amount);
        }

        _health -= amount;
        _health  = Mathf.Clamp(_health, 0, maxHealth);

        if (OnHealthChange != null)
        {
            OnHealthChange.Invoke(_health);
        }

        if (_health == 0 && OnDie != null)
        {
            OnDie.Invoke();
        }
    }
    // Token: 0x0600191F RID: 6431 RVA: 0x0007E7E0 File Offset: 0x0007C9E0
    public void OnStomped()
    {
        OnReceiveDamage onReceiveDamage = (OnReceiveDamage)this.Controller.StateMachine.CurrentTrigger;

        this.PlatformMovement.WorldSpeed = onReceiveDamage.Damage.Force * 8f;
        if (this.PlatformMovement.IsOnGround && this.PlatformMovement.LocalSpeedY < 0f)
        {
            this.PlatformMovement.LocalSpeedY *= -0.5f;
        }
        this.m_thrownDirection = onReceiveDamage.Damage.Force.normalized;
        base.FaceLeft          = (this.PlatformMovement.LocalSpeedX < 0f);
    }
Ejemplo n.º 4
0
        public void ApplyDamage(DamageMessage data)
        {
            if (currentHitPoints <= 0)
            {//ignore damage if already dead. TODO : may have to change that if we want to detect hit on death...
                return;
            }

            if (isInvulnerable)
            {
                OnHitWhileInvulnerable.Invoke();
                return;
            }

            Vector3 forward = transform.forward;

            forward = Quaternion.AngleAxis(hitForwardRotation, transform.up) * forward;

            //we project the direction to damager to the plane formed by the direction of damage
            Vector3 positionToDamager = data.damageSource - transform.position;

            positionToDamager -= transform.up * Vector3.Dot(transform.up, positionToDamager);

            if (Vector3.Angle(forward, positionToDamager) > hitAngle * 0.5f)
            {
                return;
            }

            isInvulnerable    = true;
            currentHitPoints -= data.amount;

            if (currentHitPoints <= 0)
            {
                schedule += OnDeath.Invoke; //This avoid race condition when objects kill each other.
                myOnDeath.Invoke(this, data);
            }
            else
            {
                OnReceiveDamage.Invoke();
                myOnDamageReceived?.Invoke(this, data);
            }

            var messageType = currentHitPoints <= 0 ? MessageType.DEAD : MessageType.DAMAGED;

            for (var i = 0; i < onDamageMessageReceivers.Count; ++i)
            {
                var receiver = onDamageMessageReceivers[i] as IMessageReceiver;
                receiver.OnReceiveMessage(messageType, this, data);
            }
        }
        public void ApplyDamage(DamageMessage data)
        {
            if (currentHitPoints <= 0)
            {
                return;
            }

            if (isInvulnerable)
            {
                OnHitWhileInvulnerable.Invoke();
                return;
            }

            Vector3 forward = transform.forward;

            forward = Quaternion.AngleAxis(hitForwardRotation, transform.up) * forward;
            //将受击方向投影到xz平面上
            Vector3 positionToDamager = data.damageSource - transform.position;

            positionToDamager -= transform.up * Vector3.Dot(transform.up, positionToDamager);
            //判断攻击是否在hitAngle范围内
            if (Vector3.Angle(positionToDamager, forward) > hitAngle * 0.5f)
            {
                return;
            }

            isInvulnerable    = true;
            currentHitPoints -= data.amount;

            if (currentHitPoints <= 0)
            {
                schedule += OnDeath.Invoke;
            }
            else
            {
                OnReceiveDamage.Invoke();
            }

            var message = currentHitPoints <= 0 ? MessageType.DEAD : MessageType.DAMAGED;

            for (var i = 0; i < onDamageMessageReceivers.Count; ++i)
            {
                var receiver = onDamageMessageReceivers[i] as IMessageReceiver;
                receiver.OnReceiveMessage(message, this, data);
            }
        }
        void Update()
        {
            m_currentHitPoints = (int)(dstManager.GetComponentData<AttributeValues>(this.attributeEntity).CurrentValue.Health);

            if (isInvulnerable)
            {
                m_timeSinceLastHit += Time.deltaTime;
                if (m_timeSinceLastHit > invulnerabiltyTime)
                {
                    m_timeSinceLastHit = 0.0f;
                    isInvulnerable = false;
                    OnBecomeVulnerable.Invoke();
                }
            }

            // This logic is to delay the processing of hp checks by a frame, since the
            // attribute update logic runs after one frame
            if (wasDamaged)
            {
                wasDamaged = false;
                for (var j = 0; j < damageMessagesToAction.Count; j++)
                {
                    var data = damageMessagesToAction[j];
                    if (currentHitPoints <= 0)
                        schedule += OnDeath.Invoke; //This avoid race condition when objects kill each other.
                    else
                        OnReceiveDamage.Invoke();

                    var messageType = currentHitPoints <= 0 ? MessageType.DEAD : MessageType.DAMAGED;

                    for (var i = 0; i < onDamageMessageReceivers.Count; ++i)
                    {
                        var receiver = onDamageMessageReceivers[i] as IMessageReceiver;
                        receiver.OnReceiveMessage(messageType, this, data);
                    }
                }
                damageMessagesToAction.Clear();
            }

            if (damageMessagesToAction.Count > 0)
            {
                wasDamaged = true;
            }

        }
Ejemplo n.º 7
0
        public void ApplyDamage(DamageMessage data)
        {
            if (currentHitPoints <= 0)
            {
                return;
            }

            currentHitPoints -= data.amount;

            if (currentHitPoints <= 0)
            {
                OnDeath.Invoke();
            }
            else
            {
                OnReceiveDamage.Invoke();
            }
        }
Ejemplo n.º 8
0
        public void TakeDamage(Damager damager, bool ignoreInvincible = false)
        {
            //ignore damage if already dead. TODO : may have to change that if we want to detect hit on death...
            if ((m_Invulnerable && !ignoreInvincible) || m_CurrentHealth <= 0)
            {
                return;
            }

            if (m_Invulnerable && !ignoreInvincible)
            {
                OnHitWhileInvulnerable.Invoke();
                return;
            }

            Vector3 forward = transform.forward;

            forward = Quaternion.AngleAxis(hitForwardRotation, transform.up) * forward;

            //we project the direction to damager to the plane formed by the direction of damage
            Vector3 positionToDamager = damager.transform.position - transform.position;

            positionToDamager -= transform.up * Vector3.Dot(transform.up, positionToDamager);

            if (Vector3.Angle(forward, positionToDamager) > hitAngle * 0.5f)
            {
                return;
            }

            m_Invulnerable   = true;
            m_CurrentHealth -= damager.damage;

            if (m_CurrentHealth <= 0)
            {
                schedule += OnDeath.Invoke;
            }
            else
            {
                OnReceiveDamage.Invoke();
                if (invulnerableAfterDamage)
                {
                    EnableInvulnerability();
                }
            }
        }
Ejemplo n.º 9
0
        public void ApplyDamage(DamageMessage data)
        {
            if (currentHitPoints <= 0)
            {//ignore damage if already dead. TODO : may have to change that if we want to detect hit on death...
                return;
            }

            Vector3 forward = transform.forward;

            forward = Quaternion.AngleAxis(hitForwardRotation, transform.up) * forward;

            //we project the direction to damager to the plane formed by the direction of damage
            Vector3 positionToDamager = data.damageSource - transform.position;

            positionToDamager -= transform.up * Vector3.Dot(transform.up, positionToDamager);

            if (Vector3.Angle(forward, positionToDamager) > hitAngle * 0.5f)
            {
                return;
            }

            currentHitPoints -= data.amount;

            if (currentHitPoints <= 0)
            {
                //schedule += OnDeath.Invoke; //This avoid race condition when objects kill each other.
                // OnDeath can only be called once
                Debug.Log(string.Format("{0} die", gameObject.name));
            }
            else
            {
                OnReceiveDamage.Invoke();
            }

            var messageType = currentHitPoints <= 0 ? MsgType.DEAD : MsgType.DAMAGED;

            for (var i = 0; i < onDamageMessageReceivers.Count; ++i)
            {
                var receiver = onDamageMessageReceivers[i] as IMessageReceiver;
                receiver.OnReceiveMessage(messageType, this, data);
            }
        }
Ejemplo n.º 10
0
    protected override void Damaged(int dam)
    {
        int d = dam;

        if (dam > ShieldCurrent)
        {
            dam           = dam - ShieldCurrent;
            ShieldCurrent = 0;
        }
        else
        {
            ShieldCurrent -= dam;
            dam            = 0;
        }
        CurrentHeath -= dam;
        if (PlayerCurrent == this && d != 0)
        {
            OnReceiveDamage?.Invoke();
        }
        lastTimeReceivedamage = Time.time;
    }
Ejemplo n.º 11
0
    public void ApplyDamage(DamageInfo info)
    {
        if (currentHitPoints <= 0)
        {
            return;
        }

        if (isInvulnerable)
        {
            OnHitWhileInvulnerable.Invoke();
            return;
        }

        var forward = transform.forward;

        forward = Quaternion.AngleAxis(hitForwardRotation, transform.up) * forward;

        Vector3 positionToDamager = info.damageSource - transform.position;

        positionToDamager -= transform.up * Vector3.Dot(transform.up, positionToDamager);

        if (Vector3.Angle(forward, positionToDamager) > hitAngle * 0.5f)
        {
            return;
        }

        isInvulnerable    = true;
        currentHitPoints -= info.amount;

        if (currentHitPoints <= 0)
        {
            schedule += OnDeath.Invoke;
        }
        else
        {
            OnReceiveDamage.Invoke();
        }
    }
Ejemplo n.º 12
0
        public void ApplyDamage(DamageMessage data)
        {
            if (currentHitPoints <= 0)
            {//ignore damage if already dead. TODO : may have to change that if we want to detect hit on death...
                return;
            }

            if (isInvulnerable)
            {
                OnHitWhileInvulnerable.Invoke();
                return;
            }

            Vector3 forward = transform.forward;

            forward = Quaternion.AngleAxis(hitForwardRotation, transform.up) * forward;

            //we project the direction to damager to the plane formed by the direction of damage
            Vector3 positionToDamager = data.damageSource - transform.position;

            positionToDamager -= transform.up * Vector3.Dot(transform.up, positionToDamager);

            if (Vector3.Angle(forward, positionToDamager) > hitAngle * 0.5f)
            {
                return;
            }

            isInvulnerable    = true;
            currentHitPoints -= data.amount;

            if (currentHitPoints <= 0)
            {
                schedule += OnDeath.Invoke;     //This avoid race condition when objects kill each other.
                if (this.gameObject.layer == 9) //Player
                {
                    if (data.damager.gameObject.name == "BodyDamager")
                    {
                        PlayerDeathEvent?.Invoke(ENEMY_TYPE.CHOMPER);
                    }

                    else if (data.damager.gameObject.name == "Spit(Clone)")
                    {
                        PlayerDeathEvent?.Invoke(ENEMY_TYPE.SPITTER);
                    }
                }

                else if (this.gameObject.layer == 23) // Enemy
                {
                    if (gameObject.name == "Chomper")
                    {
                        EnemyDeathEvent?.Invoke(gameObject, ENEMY_TYPE.CHOMPER);
                    }

                    else if (gameObject.name == "Spitter")
                    {
                        EnemyDeathEvent?.Invoke(gameObject, ENEMY_TYPE.SPITTER);
                    }
                }
            }

            else
            {
                if (data.damager.gameObject.name == "BodyDamager")
                {
                    PlayerHurtEvent?.Invoke(ENEMY_TYPE.CHOMPER);
                }

                else if (data.damager.gameObject.name == "Spit(Clone)")
                {
                    PlayerHurtEvent?.Invoke(ENEMY_TYPE.SPITTER);
                }

                OnReceiveDamage.Invoke();
            }

            var messageType = currentHitPoints <= 0 ? MessageType.DEAD : MessageType.DAMAGED;

            for (var i = 0; i < onDamageMessageReceivers.Count; ++i)
            {
                var receiver = onDamageMessageReceivers[i] as IMessageReceiver;
                receiver.OnReceiveMessage(messageType, this, data);
            }
        }
    // Token: 0x0600191D RID: 6429 RVA: 0x0007E6F4 File Offset: 0x0007C8F4
    public bool ShouldStomped()
    {
        OnReceiveDamage onReceiveDamage = (OnReceiveDamage)this.Controller.StateMachine.CurrentTrigger;

        return(onReceiveDamage.Damage.Type == DamageType.StompBlast);
    }
    // Token: 0x0600191C RID: 6428 RVA: 0x00079B78 File Offset: 0x00077D78
    public bool ShouldThrow()
    {
        OnReceiveDamage onReceiveDamage = (OnReceiveDamage)this.Controller.StateMachine.CurrentTrigger;

        return(onReceiveDamage.Damage.Type == DamageType.Bash);
    }
Ejemplo n.º 15
0
    public void TakeHit(Damager damager)
    {
        //for hit angle and stuff
        Vector3 forward = transform.forward;

        forward = Quaternion.AngleAxis(hitForwardRotation, transform.up) * forward;

        //we project the direction to damager to the plane formed by the direction of damage
        Vector3 positionToDamager = damager.transform.position - transform.position;

        positionToDamager -= transform.up * Vector3.Dot(transform.up, positionToDamager);

        if (Vector3.Angle(forward, positionToDamager) > hitAngle * 0.5f)
        {
            return;
        }

        //check invulnerability
        if (m_Invulnerable)
        {
            return;
        }

        //damage
        currentHealth -= damager.damage;

        if (currentHealth > 0)
        {
            actor.Damaged(damager);
            OnReceiveDamage.Invoke();

            //status
            if (damager.appliedStatus > 0)
            {
                actor.ApplyStatus(damager.appliedStatus, damager.statusDuration);
            }

            //physical impact
            knockOutBuildUp += damager.hitPower;
            if (knockOutLimit > 0 && knockOutThreshold > 0 && knockOutBuildUp >= knockOutLimit && damager.hitPower >= knockOutThreshold)
            {
                knockOutBuildUp = 0;
                actor.ApplyImpact(damager, "KnockOut");
            }
            else if (knockBackThreshold > 0 && damager.hitPower >= knockBackThreshold)
            {
                actor.ApplyImpact(damager, "KnockBack");
            }
            else if (flinchThreshold > 0 && damager.hitPower >= flinchThreshold)
            {
                actor.ApplyImpact(damager, "Flinch");
            }

            if (invulnerableAfterDamage)
            {
                StartCoroutine(AfterHitInvulnerability(invulnerabilityDuration));
            }
        }
        else
        {
            schedule += OnDeath.Invoke;
        }
    }