public void acceptDamage(DamageAcceptorRegistry.DamageArgs argInArgs)
    {
        if (destructible)
        {
            float locDamage = argInArgs.dmg;

            if (locDamage > 0)
            {
                if (hitPoints > locDamage)
                {
                    hitPoints -= locDamage;
                    locDamage  = 0;
                }
                else
                {
                    hitPoints = 0;
                    Invoke("Destruct", 0.02f);
                    DamageProvider dp = argInArgs.source.GetComponent <DamageProvider>();
                    if (dp != null)
                    {
                        dp.ReportKill(this);
                    }
                }
            }
        }
        Push(argInArgs.knockback);
    }
Esempio n. 2
0
    public virtual void acceptDamage(DamageAcceptorRegistry.DamageArgs argInArgs)
    {
        //Debug.Log("AIAcceptDmg" + argInArgs.dmg);
        if (this.gameObject == null)
        {
            return;
        }
        if (stats.isDead)
        {
            return;
        }
        float locDamage = argInArgs.dmg;

        if (stats.currentArmorPoints > 0)
        {
            if (stats.currentArmorPoints > locDamage)
            {
                stats.currentArmorPoints -= locDamage;
                locDamage = 0;
            }
            else
            {
                stats.currentArmorPoints = 0;
                locDamage -= stats.currentArmorPoints;
            }
        }
        if (locDamage > 0)
        {
            if (stats.currentHitPoints > locDamage)
            {
                stats.currentHitPoints -= locDamage;
                locDamage = 0;
                Knockback(argInArgs.knockback);
            }
            else
            {
                stats.currentHitPoints = 0;
                stats.isDead           = true;
                DamageProvider dp = argInArgs.source.GetComponent <DamageProvider>();
                if (dp != null)
                {
                    dp.ReportKill(this);
                }
                Die(argInArgs);
            }
        }
        Transform healthbar = transform.Find("HealthBar");

        if (healthbar != null)
        {
            healthbar.transform.Find("Level").GetComponent <Image>().fillAmount = stats.currentHitPoints / stats.totalHitPoints;
        }
    }