Beispiel #1
0
    public void DestroySpawendEnemies()
    {
        Damageable.DamageMessage data = new Damageable.DamageMessage();

        foreach (var spawendEnemy in _spawendEnemies)
        {
            if (spawendEnemy != null)
            {
                Damageable damageable = spawendEnemy.GetComponent <Damageable>();
                damageable.isInvulnerable = false;
                data.amount       = damageable.currentHitPoints;
                data.damageSource = Vector3.zero;
                damageable.ApplyDamage(data);
            }
        }
        _spawendEnemies.Clear();
        _canSpawn = true;
    }
Beispiel #2
0
        private void OnCollisionEnter(Collision collision)
        {
            Damageable damageable = collision.collider.GetComponentInChildren <Damageable>();

            if (damageable != null && !damageable.isInvulnerable)
            {
                Damageable.DamageMessage message = new Damageable.DamageMessage
                {
                    damageSource       = transform.position,
                    damager            = this,
                    amount             = damageAmount,
                    direction          = (collision.collider.transform.position - transform.position).normalized,
                    effect             = Magic.MagicEffect.Paralyze,
                    magicEffectLasting = 5
                };

                damageable.ApplyDamage(message);
            }
        }
    void SendDamageMessage(GameObject other)
    {
        var d = other.GetComponent <Damageable>();

        if (d == null)
        {
            return;
        }

        var msg = new Damageable.DamageMessage()
        {
            amount     = damageAmount,
            damager    = this,
            direction  = Vector3.up,
            stopCamera = false
        };

        d.ApplyDamage(msg);
    }
Beispiel #4
0
        void OnParticleCollision(GameObject other)
        {
            Damageable d = other.GetComponentInChildren <Damageable>();

            if (d != null && !d.isInvulnerable)
            {
                Damageable.DamageMessage message = new Damageable.DamageMessage
                {
                    damageSource       = transform.position,
                    damager            = this,
                    amount             = 1,
                    direction          = (other.transform.position - transform.position).normalized,
                    throwing           = false,
                    effect             = Magic.MagicEffect.Paralyze,
                    magicEffectLasting = 5
                };

                d.ApplyDamage(message);
            }
        }
Beispiel #5
0
        private void OnTriggerEnter(Collider other)
        {
            Damageable d = other.GetComponentInChildren <Damageable>();

            if (d != null && !d.isInvulnerable)
            {
                Damageable.DamageMessage message = new Damageable.DamageMessage
                {
                    damageSource       = transform.position,
                    damager            = this,
                    amount             = 1,
                    direction          = (other.transform.position - transform.position).normalized,
                    throwing           = false,
                    effect             = Magic.MagicEffect.Burn,
                    magicEffectLasting = 5
                };

                d.ApplyDamage(message);
            }
        }
Beispiel #6
0
        public override void Die(Damageable.DamageMessage msg)
        {
            Vector3 pushForce = transform.position - msg.damageSource;

            pushForce.y = 0;

            transform.forward = -pushForce.normalized;
            AddForce(pushForce.normalized * 7.0f - Physics.gravity * 0.6f);

            m_Animator.SetTrigger(hashHit);
            m_Animator.SetTrigger(hashThrown);

            //We unparent the hit source, as it would destroy it with the gameobject when it get replaced by the ragdol otherwise
            if (deathAudio != null)
            {
                deathAudio.transform.SetParent(null, true);
                deathAudio.PlayRandomClip();
                GameObject.Destroy(deathAudio, deathAudio.clip == null ? 0.0f : deathAudio.clip.length + 0.5f);
            }
        }
Beispiel #7
0
    private void ConditionAction(CommandPuzzle commandPuzzleMain)
    {
        if (commandPuzzleMain.commandCondition == "foundKey" && commandPuzzleMain.command == "getKey")
        {
            if (objectWithCrystalSamePosition != null && objectWithCrystalSamePosition.tag == "Key")
            {
                objectWithCrystalSamePosition.SetActive(false);
                keyFounded = true;
            }
            return;
        }

        if (commandPuzzleMain.commandCondition == "foundBox" && commandPuzzleMain.command == "destroyBox")
        {
            try
            {
                Damageable d = objectWithCrystalSamePosition.GetComponentInChildren <Damageable>() == null?
                               objectWithCrystalSamePosition.GetComponentInParent <Damageable>() : objectWithCrystalSamePosition.GetComponentInChildren <Damageable>();

                if (d == null)
                {
                    d = objectWithCrystalSamePosition.GetComponent <Damageable>();
                }

                if (d != null)
                {
                    Damageable.DamageMessage damage = new Damageable.DamageMessage()
                    {
                        amount    = 999,
                        damager   = this,
                        direction = Vector3.up,
                    };

                    d.ApplyDamage(damage);
                    boxesDesroyed--;
                }
            }
            catch (System.Exception ex) { }
        }
    }
    private void OnTriggerStay(Collider other)
    {
        if ((damagedLayers.value & 1 << other.gameObject.layer) == 0)
        {
            return;
        }

        Damageable d = other.GetComponentInChildren <Damageable>();

        if (d != null)
        {
            Damageable.DamageMessage message = new Damageable.DamageMessage
            {
                damageSource = transform.position, // The target who will be damaged
                damager      = this,               // Who is damaging the target
                amount       = damageAmount,       // Amount of damage inflicted on target
                direction    = (other.transform.position - transform.position).normalized,
            };

            d.ApplyDamage(message);
        }
    }
    protected virtual void damaged(Damageable.DamageMessage msg)
    {
        Vector3 direction = msg.damager.transform.position - transform.position;

        direction.y = 0f;

        var localDirection = transform.InverseTransformDirection(direction);

        Vector3 hitPos = Vector3.Lerp(msg.damageSource, transform.Find("CenterTarget").position, msg.radius);

        if (localDirection.z > 0f && inBlocking && !inAttacking)
        {
            animator.SetTrigger(blockStr);

            Damageable.DamageMessage damageMessage = new Damageable.DamageMessage();
            damageMessage.damageAmount = 0;
            damageMessage.damager      = gameObject;
            damageMessage.damageSource = transform.position;

            msg.damager.GetComponent <UnitController>().receiveMessage(MessageType.BLOCKED, this, damageMessage);

            damageable.playAudio(MessageType.BLOCKED);

            StartCoroutine(damageable.locateCrashParticle(hitPos, msg.damager.transform.position));
        }
        else
        {
            animator.SetTrigger(hurtStr);

            damageable.playAudio(MessageType.DAMAGED);

            StartCoroutine(damageable.locateHitParticle(hitPos, msg.damageSource));
        }

        animator.SetFloat(hurtFromXStr, localDirection.x);
        animator.SetFloat(hurtFromZStr, localDirection.z);
    }
Beispiel #10
0
 public void Damage(Damageable.DamageMessage damageMessage)
 {
     m_Health = Mathf.Clamp((m_Health - damageMessage.amount), 0, maxHealth);
 }
 protected virtual void blocked(Damageable.DamageMessage msg)
 {
     animator.SetTrigger(crashStr);
 }