TakeDamage() public method

public TakeDamage ( float damageTaken ) : void
damageTaken float
return void
Esempio n. 1
0
    public void DoDamage(UnitStats targetStats, CharacterStats ownerStats, DamageType damageType, float attackDamage, bool isCritical, int ownerMastery, List <IAttackModifier> attackModifiers)
    {
        bool isEvaded  = false;
        bool isBlocked = false;

        attackDamage = targetStats.TakeDamage(ownerStats, damageType, attackDamage, ref isEvaded, ref isBlocked, isCritical: isCritical, displayPopup: true);

        if (!isEvaded)
        {
            if (!isBlocked) // Если урон не был полностью заблокирован
            {
                if (damageType is EffectDamage)
                {
                    new DamageTypeEffect((EffectDamage)damageType, targetStats, ownerStats, attackDamage / effectPowerConversionCoefficient);
                }
            }


            /*
             * Есть ли модификатор атаки?
             *
             * Если у цели есть модификатор атаки, который должен навесить дебафф, то сам модификатор проверяет, может ли он это сделать.
             */

            // Модификатор атаки накладывается даже если цель заблокировала урон (Например, если модификатор отталкивает)
            for (int i = 0; i < attackModifiers.Count; i++)
            {
                attackModifiers[i].ApplyAttackModifier(targetStats, damageType, attackDamage, ownerMastery, isCritical);
            }
        }
    }
Esempio n. 2
0
    protected override void onHit(GameObject g)
    {
        hitList.Add(g);
        UnitStats targetStats     = g.GetComponent <UnitStats>();
        float     increasedDamage = damage + damage * (1 - targetStats.PercentageHealth()); //deal increased damage equal to percentage missing health

        if (slowMulti > 1 && targetStats.isSlowed())
        {
            increasedDamage *= slowMulti;
        }
        targetStats.TakeDamage(increasedDamage);
        if (targetStats.CurrentHealth() <= 0)
        {
            owner.GetComponent <UnitStats>().GainArmor(armorOnKillAmount);
            owner.GetComponent <UnitStats>().Heal(healOnKillAmount);
        }
        if (bleed > 0)
        {
            targetStats.Bleed(bleed);
        }
        if (slow > 0)
        {
            targetStats.Slow(slow);
        }
        if (bleedConsumeMultiplier > 0)
        {
            targetStats.ConsumeBleed(bleedConsumeMultiplier);
        }
        WeaponCollisionEnterEvent.Invoke(g);
        OnHitEvent.Invoke();
        OnHitHeal.Invoke(heal);
    }
Esempio n. 3
0
    Ray shootRay; // A ray from the gun end forwards.

    #endregion Fields

    #region Methods

    public void Attack(UnitStats targetHealth)
    {
        if (targetHealth != null)
        {
            targetHealth.TakeDamage(damagePerHit);
        }
    }
Esempio n. 4
0
    protected IEnumerator Hit(BoardCreator board, UnitStats target, Tile source)
    {
        if (data.Damage > 0)
        {
            target.TakeDamage(unit.GetComponent <UnitStats>().GetAttack(board, data));
        }
        if (data.Heal > 0)
        {
            target.Heal(data.Heal);
        }

        if (!target.IsDead())
        {
            if (data.hasKnockback && target.GetComponent <Unit>().KnockbackAble())
            {
                Point direction = source.pos - target.GetComponent <Unit>().tile.pos;
                yield return(StartCoroutine(target.ApplyKnockback(board, direction)));
            }

            if (data.status != StatusEffects.NONE)
            {
                target.AddStatus(data.status);
            }
        }
    }
Esempio n. 5
0
    public void DoStatusEffectDamage(UnitStats targetStats, CharacterStats ownerStats)
    {
        bool isEvaded  = false;
        bool isBlocked = false;

        targetStats.TakeDamage(ownerStats, damageType, baseDamagePerSecond * effectPower * Time.deltaTime, ref isEvaded, ref isBlocked, false);
    }
Esempio n. 6
0
 public void Attack(UnitStats targetStats)
 {
     //fighting the unit by getting own stats from stats class and getting stats from enemy stats class
     if (attackCooldown <= 0f)
     {
         targetStats.TakeDamage(myStats.damage.GetValue());
         attackCooldown = 1f / attackSpeed;
     }
 }
Esempio n. 7
0
    public bool Attack(UnitStats attackingUnit, UnitStats defendingUnit)
    {
        //Debug.Log(string.Format("attacking unit ad {0} , defending unit hp {1}", attackingUnit.attackDamage, defendingUnit.health));
        int damage = attackingUnit.CalculateDamageAgainst(defendingUnit.unitType);

        bool result = defendingUnit.TakeDamage(damage);

        // Debug.Log(string.Format("attacking unit ad {0} , defending unit hp {1}", attackingUnit.attackDamage, defendingUnit.health));
        return(result);
    }
Esempio n. 8
0
    public void Shoot(UnitStats targetHealth)
    {
        gameObject.transform.LookAt(targetHealth.gameObject.transform);

        if (targetHealth != null)
        {
            // ... the enemy should take damage.
            targetHealth.TakeDamage(damagePerHit);
        }
    }
Esempio n. 9
0
    public void AreaExplode(Vector3 center, float radius, float damage, GameObject source, int attackMask)
    {
        Collider[] hitColliders = Physics.OverlapSphere(center, radius, attackMask);

        for (int i = 0; i < hitColliders.Length; i++)
        {
            cache = hitColliders[i].gameObject.GetComponent<UnitStats>();
            cache.TakeDamage(damage);
        }
    }
Esempio n. 10
0
 public bool Attack(UnitStats targetStats)
 {
     if (!(_attackCooldown <= 0))
     {
         return(false);
     }
     targetStats.TakeDamage(_myStats.Damage.GetValue());
     EventOnAttack?.Invoke();
     _attackCooldown = 1f / _attackSpeed;
     return(true);
 }
Esempio n. 11
0
 void Attack(UnitStats targetStats)
 {
     if (targetStats.currentHealth <= 0)
     {
         RemoveTarget();
     }
     else
     {
         targetStats.TakeDamage(myStats.strength.GetValue());
         cooldown = 1f;
     }
 }
Esempio n. 12
0
    public void AreaStun(Vector3 center, float radius, float damage, float duration, GameObject source, int attackMask)
    {
        Collider[] hitColliders = Physics.OverlapSphere(center, radius, attackMask);

        for (int i = 0; i < hitColliders.Length; i++)
        {
            cache = hitColliders[i].gameObject.GetComponent<UnitStats>();
            cache.TakeDamage(damage);

            if (!cache.stunImmunity)
                cache.ApplyStatus(UnitStats.statusEffects.stun, duration);
        }
    }
Esempio n. 13
0
    public void AttackHit_AnimationEvent()
    {
        int attackValueOffset = Mathf.RoundToInt(stats.attack.getValue() * 0.2f);
        int attackValue       = stats.attack.getValue();
        int damage            = Mathf.RoundToInt(Random.Range(attackValue - attackValueOffset, attackValue + attackValueOffset));
        int hpLost            = enemyStats.TakeDamage(damage);

        if (stats.leech.getValue() != 0)
        {
            int hpGain = Mathf.RoundToInt(hpLost * (stats.leech.getValue() / 100f));
            stats.hp.GainHp(hpGain);
        }
        if (enemyStats.hp.getValue() <= 0)
        {
            OnUnitKilled();
        }
        if (FinishedAttacking != null)
        {
            FinishedAttacking();
        }
    }
Esempio n. 14
0
 public void TakeDamage(int damage)
 {
     playerStats.TakeDamage(damage);
 }
Esempio n. 15
0
    /// <summary>
    /// deals damage to target
    /// </summary>
    /// <param name="g"></param>
    /// <param name="amount"></param>
    public void DealDamage(GameObject g, float amount)
    {
        UnitStats u = g.GetComponent <UnitStats>();

        u.TakeDamage(amount);
    }
Esempio n. 16
0
    public IEnumerator BossTurn3()
    {
        if (battleSystemFossil.enemyLightingEffects[0] != null)
        {
            battleSystemFossil.enemyLightingEffects[0].SetActive(true);
            battleSystemFossil.currentEnemies[0].GetComponent <Image>().enabled = false;
        }
        //Sets all lighting effects for the final boss

        if (battleSystemFossil.bossUnit[2].GetComponent <UnitStats>().currentHP < battleSystemFossil.bossUnit[2].GetComponent <UnitStats>().maxHP / 2)
        {
            isDead = playerStats.TakeDamage(battleSystemFossil.bossUnit[2].damage / PlayerStats.defendButton);
            playerStats.TakeDamage(battleSystemFossil.playerUnit.damage);
            battleSystemFossil.playerUnit.damage++;

            battleSystemFossil.playerColor.color = new Color(1, 0, 0);

            battleSystemFossil.CreatePlayerParticles();

            cameraShake.shake      = battleSystemFossil.playerPrefab;
            EnemyHolder.shakeEnemy = true;

            battleSystemFossil.playerHUD.SetHP(battleSystemFossil.playerUnit.currentHP);

            yield return(new WaitForSeconds(.2f));

            battleSystemFossil.playerColor.color = new Color(1, 1, 1);
            EnemyHolder.shakeEnemy = false;

            yield return(new WaitForSeconds(.2f));

            battleSystemFossil.enemyLightingEffects[0].SetActive(false);

            yield return(new WaitForSeconds(.55f));
        }
        else
        {
            isDead = playerStats.TakeDamage(battleSystemFossil.bossUnit[2].damage / PlayerStats.defendButton);

            battleSystemFossil.playerColor.color = new Color(1, 0, 0);

            battleSystemFossil.CreatePlayerParticles();

            cameraShake.shake      = battleSystemFossil.playerPrefab;
            EnemyHolder.shakeEnemy = true;

            battleSystemFossil.playerHUD.SetHP(battleSystemFossil.playerUnit.currentHP);

            yield return(new WaitForSeconds(.2f));

            battleSystemFossil.playerColor.color = new Color(1, 1, 1);
            EnemyHolder.shakeEnemy = false;

            yield return(new WaitForSeconds(.2f));

            battleSystemFossil.enemyLightingEffects[0].SetActive(false);

            yield return(new WaitForSeconds(.55f));
        }

        EnemyHolder.coroutinesRunning--;

        if (isDead)
        {
            battleSystemFossil.state = BattleStateFossil.LOST;
            battleSystemFossil.StartCoroutine("EndBattle");
        }
    } //Basic enemy turn that will look at which enemy the player is fighting, and start seperate scripts depending on the enemy.
Esempio n. 17
0
 public void TakeDamage(int damage)
 {
     enemyStats.TakeDamage(damage);
 }
Esempio n. 18
0
 public void TakeDamage(GameObject user, int damage)
 {
     _stats.TakeDamage(damage);
     DamageWithCombat(user);
 }
Esempio n. 19
0
    public IEnumerator EnemyTurn1()
    {
        switch (EnemyHolder.coroutinesRunning)
        {
        case 0:
            if (battleSystemFossil.enemyLightingEffects[0] != null)
            {
                battleSystemFossil.enemyLightingEffects[0].SetActive(true);
                battleSystemFossil.currentEnemies[0].GetComponent <Image>().enabled = false;

                thisEnemy = battleSystemFossil.currentEnemies[0];

                if (EnemyHolder.enemyDowned[0] != null && EnemyHolder.enemyDowned[0].GetComponent <UnitStats>().isDowned == true)
                {
                    battleSystemFossil.enemyLightingEffects[0].SetActive(false);
                    battleSystemFossil.currentEnemies[0].GetComponent <Image>().enabled = true;
                }
            }
            if (EnemyHolder.enemyDowned[0] != null)
            {
                if (EnemyHolder.enemyDowned[0].GetComponent <UnitStats>().isDowned == true)
                {
                    EnemyHolder.isDowned = true;
                }
            }
            break;

        case 1:
            yield return(new WaitForSeconds(1f));

            if (battleSystemFossil.enemyLightingEffects[1] != null)
            {
                battleSystemFossil.enemyLightingEffects[1].SetActive(true);
                battleSystemFossil.currentEnemies[1].GetComponent <Image>().enabled = false;

                thisEnemy = battleSystemFossil.currentEnemies[1];

                if (EnemyHolder.enemyDowned[1] != null && EnemyHolder.enemyDowned[1].GetComponent <UnitStats>().isDowned == true)
                {
                    battleSystemFossil.enemyLightingEffects[1].SetActive(false);
                    battleSystemFossil.currentEnemies[1].GetComponent <Image>().enabled = true;
                }
            }
            if (EnemyHolder.enemyDowned[1] != null)
            {
                if (EnemyHolder.enemyDowned[1].GetComponent <UnitStats>().isDowned == true)
                {
                    EnemyHolder.isDowned = true;
                }
            }
            break;

        case 2:
            yield return(new WaitForSeconds(2f));

            if (battleSystemFossil.enemyLightingEffects[2] != null)
            {
                battleSystemFossil.enemyLightingEffects[2].SetActive(true);
                battleSystemFossil.currentEnemies[2].GetComponent <Image>().enabled = false;

                thisEnemy = battleSystemFossil.currentEnemies[2];

                if (EnemyHolder.enemyDowned[2] != null && EnemyHolder.enemyDowned[2].GetComponent <UnitStats>().isDowned == true)
                {
                    battleSystemFossil.enemyLightingEffects[2].SetActive(false);
                    battleSystemFossil.currentEnemies[2].GetComponent <Image>().enabled = true;
                }
            }
            if (EnemyHolder.enemyDowned[2] != null)
            {
                if (EnemyHolder.enemyDowned[2].GetComponent <UnitStats>().isDowned == true)
                {
                    EnemyHolder.isDowned = true;
                }
            }
            break;

        case 3:
            yield return(new WaitForSeconds(3f));

            if (battleSystemFossil.enemyLightingEffects[3] != null)
            {
                battleSystemFossil.enemyLightingEffects[3].SetActive(true);
                battleSystemFossil.currentEnemies[3].GetComponent <Image>().enabled = false;

                thisEnemy = battleSystemFossil.currentEnemies[3];

                if (EnemyHolder.enemyDowned[3] != null && EnemyHolder.enemyDowned[3].GetComponent <UnitStats>().isDowned == true)
                {
                    battleSystemFossil.enemyLightingEffects[3].SetActive(false);
                    battleSystemFossil.currentEnemies[3].GetComponent <Image>().enabled = true;
                }
            }
            if (EnemyHolder.enemyDowned[3] != null)
            {
                if (EnemyHolder.enemyDowned[3].GetComponent <UnitStats>().isDowned == true)
                {
                    EnemyHolder.isDowned = true;
                }
            }
            break;
        }// Delays the coroutines activation depending on how many enemies you are fighting and disables specific lighting effects depending on downed enemies

        if (thisEnemy != null)
        {
            if (EnemyHolder.isDowned == false && thisEnemy.GetComponent <UnitStats>().currentHP > thisEnemy.GetComponent <UnitStats>().maxHP / 2)
            {
                isDead = playerStats.TakeDamage(GameObject.FindGameObjectWithTag("Enemy1").GetComponent <UnitStats>().damage / PlayerStats.defendButton);

                battleSystemFossil.playerColor.color = new Color(1, 0, 0); //Sets the player color to red

                battleSystemFossil.CreatePlayerParticles();                //Generates feedback particles that shooot out of player

                cameraShake.shake      = battleSystemFossil.playerPrefab;
                EnemyHolder.shakeEnemy = true;
                //Shakes the player for more feedback

                battleSystemFossil.playerHUD.SetHP(battleSystemFossil.playerUnit.currentHP); //Sets the HP of the player in the HUD

                yield return(new WaitForSeconds(.2f));

                battleSystemFossil.playerColor.color = new Color(1, 1, 1);
                EnemyHolder.shakeEnemy = false;
                //Turns color and shaking back to normal

                yield return(new WaitForSeconds(.2f));

                for (int j = 0; j <= EnemyHolder.enemyAmount; j++)
                {
                    if (battleSystemFossil.enemyLightingEffects[j] != null)
                    {
                        battleSystemFossil.enemyLightingEffects[j].SetActive(false);
                        battleSystemFossil.currentEnemies[j].GetComponent <Image>().enabled = true;
                    }
                }
                //Depending on how many enemies you are fighting, turns off respecitve lights

                yield return(new WaitForSeconds(.55f));
            }
            else if (EnemyHolder.isDowned == false && thisEnemy.GetComponent <UnitStats>().currentHP < thisEnemy.GetComponent <UnitStats>().maxHP / 2)
            {
                if (isCharging == true)
                {
                    isDead = playerStats.TakeDamage((GameObject.FindGameObjectWithTag("Enemy1").GetComponent <UnitStats>().damage * 2) / PlayerStats.defendButton);

                    battleSystemFossil.playerColor.color = new Color(1, 0, 0); //Sets the player color to red

                    battleSystemFossil.CreatePlayerParticles();                //Generates feedback particles that shooot out of player

                    cameraShake.shake      = battleSystemFossil.playerPrefab;
                    EnemyHolder.shakeEnemy = true;
                    //Shakes the player for more feedback

                    battleSystemFossil.playerHUD.SetHP(battleSystemFossil.playerUnit.currentHP); //Sets the HP of the player in the HUD

                    yield return(new WaitForSeconds(.15f));

                    battleSystemFossil.playerColor.color = new Color(1, 1, 1);
                    EnemyHolder.shakeEnemy = false;
                    //Turns color and shaking back to normal

                    yield return(new WaitForSeconds(.15f));

                    for (int j = 0; j <= EnemyHolder.enemyAmount; j++)
                    {
                        if (battleSystemFossil.enemyLightingEffects[j] != null)
                        {
                            battleSystemFossil.enemyLightingEffects[j].SetActive(false);
                            battleSystemFossil.currentEnemies[j].GetComponent <Image>().enabled = true;
                        }
                    }
                    //Depending on how many enemies you are fighting, turns off respecitve lights

                    isCharging = false;
                }
                else if (isCharging == false)
                {
                    infoBar.GetComponent <Animator>().SetBool("isOpen", true);

                    infoBar.transform.GetChild(0).gameObject.GetComponent <Text>().text = "The enemy is charging up an attack";

                    yield return(new WaitForSeconds(.55f));

                    for (int j = 0; j <= EnemyHolder.enemyAmount; j++)
                    {
                        if (battleSystemFossil.enemyLightingEffects[j] != null)
                        {
                            battleSystemFossil.enemyLightingEffects[j].SetActive(false);
                            battleSystemFossil.currentEnemies[j].GetComponent <Image>().enabled = true;
                        }
                    }

                    infoBar.GetComponent <Animator>().SetBool("isOpen", false);

                    yield return(new WaitForSeconds(.2f));

                    infoBar.transform.GetChild(0).gameObject.GetComponent <Text>().text = "Select an enemy";

                    isCharging = true;
                } //If it is the first time the enemy is attacking, it will say that the enemy is charging an attack
            }
        }         //Special attack that only occurs when the enemy has less than half health, attacks the player 5 times in quick succession

        if (EnemyHolder.isDowned == true)
        {
            yield return(new WaitForSeconds(.95f));

            EnemyHolder.isDowned = false;

            for (int j = 0; j <= EnemyHolder.enemyAmount; j++)
            {
                if (battleSystemFossil.enemyLightingEffects[j] != null)
                {
                    battleSystemFossil.enemyLightingEffects[j].SetActive(false);
                    battleSystemFossil.currentEnemies[j].GetComponent <Image>().enabled = true;
                }
            }
        }

        EnemyHolder.coroutinesRunning--;

        if (isDead)
        {
            battleSystemFossil.state = BattleStateFossil.LOST;
            battleSystemFossil.StartCoroutine("EndBattle");
        }
    } //Basic enemy turn that will look at which enemy the player is fighting, and start seperate scripts depending on the enemy.