コード例 #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (effectableLayers.value == (effectableLayers | 1 << collision.gameObject.layer))
        {
            Health health = collision.gameObject.GetComponent <Health>();
            collidedObjects.Add(collision.gameObject, health);

            if (fireAcidSpreadTimeToNextTick <= 0)
            {
                DamageEffectData newDamage = new DamageEffectData();
                if (onFire || inAcid)
                {
                    newDamage.Clear();
                    if (onFire)
                    {
                        newDamage.fire = originalEffects.fire;
                    }
                    if (inAcid)
                    {
                        newDamage.acid = originalEffects.acid;
                    }
                    collidedWith.Add(new ApplyEffectsTo(health, newDamage, gameObject));
                }
            }
        }
    }
コード例 #2
0
ファイル: Health.cs プロジェクト: DevJamesC/MadboyTools
 // Start is called before the first frame update
 void Start()
 {
     // healthData = new HealthData();
     healthData.isDamageable = true;
     healthData.isDead       = false;
     tookDamage        = false;
     persistantDamages = new DamageEffectData();
     blackListObjects  = new List <GameObject>();
     blackListReset    = 2;
     persistantDamages.Clear();
     nextTick = tickRate;
 }
コード例 #3
0
ファイル: Health.cs プロジェクト: DevJamesC/MadboyTools
    void ApplyPersistentDamages()
    {
        if (!healthData.isDamageable || healthData.isDead)
        {
            persistantDamages.Clear();
            return;
        }

        if (persistantDamages.isEmpty())
        {
            return;
        }

        if (nextTick > 0)
        {
            nextTick -= Time.deltaTime;
            return;
        }
        else
        {
            nextTick = tickRate;
        }


        float[] damageArray = persistantDamages.DamagePerSecondAsArray(tickRate);

        float[] damageModArray = persistantDamages.ShieldModAsArray();
        float[] damageTaken    = new float[4] {
            0, 0, 0, 0
        };                                                //order is fire, freeze, shock, acid. Prepend another float for regular damage if applicible

        int length = damageArray.Length;

        for (int i = 0; i < length; ++i)//appy damage to shield
        {
            if (healthData.currentShield > 0)
            {
                healthData.currentShield -= damageArray[i] * damageModArray[i];

                damageTaken[i] += damageArray[i] * damageModArray[i];
                if (damageArray[i] * damageArray[i] > 0)
                {
                    healthData.regenData.timeTillShieldRegenStart = healthData.regenData.shieldRegenDelay;
                }
                if (!tookDamage)
                {
                    tookDamage = (damageTaken[i] > 0) ? true : false;
                }
                if (healthData.currentShield <= 0)
                {
                    damageArray[i]           = healthData.currentShield / damageModArray[i];
                    damageTaken[i]          -= healthData.currentShield / damageModArray[i];
                    healthData.currentShield = 0;
                    break;
                }
                damageArray[i] = 0;
            }
        }
        healthData.currentShield = Mathf.Round(healthData.currentShield * 100) / 100;

        damageModArray = persistantDamages.HealthModAsArray();

        length = damageModArray.Length;
        for (int i = 0; i < length; ++i)//apply damage to health
        {
            if (healthData.currentHealth > 0)
            {
                healthData.currentHealth -= damageArray[i] * damageModArray[i];
                damageTaken[i]           += damageArray[i] * damageModArray[i];
                if (damageArray[i] * damageArray[i] > 0)
                {
                    healthData.regenData.timeTillShieldRegenStart = healthData.regenData.shieldRegenDelay;
                    healthData.regenData.timeTillHealthRegenStart = healthData.regenData.healthRegenDelay;
                }
                if (!tookDamage)
                {
                    tookDamage = (damageTaken[i] > 0) ? true : false;
                }
                if (healthData.currentHealth <= 0)
                {
                    healthData.currentHealth = 0;
                    healthData.isDead        = true;
                    break;
                }
            }
        }
        healthData.currentHealth = Mathf.Round(healthData.currentHealth * 100) / 100;
        healthData.recentDamage.SetElementDamage(damageTaken);
        persistantDamages.ApplyTickRateCountDown(tickRate);



        //Debug.Log("Took " + damageTaken[0] + " Fire," + damageTaken[1] + " Freeze, " + damageTaken[2] + " Shock, " + damageTaken[3] + " Acid Damage");
        //Debug.Log("Health: " + healthData.currentHealth + ". Shield: " + healthData.currentShield);
    }