Пример #1
0
    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);
    }