Пример #1
0
    public void InstaKill()
    {
        if (PlayerPrefsController.DamagePopupsEnabled())
        {
            TextPopup.CreateDamagePopup(transform.position + new Vector3(Random.Range(-0.05f, 0.05f), Random.Range(0.05f, 0.15f)), currentHealth, false, defender != null);
        }

        currentHealth = 0;

        if (damageEffect != null)
        {
            StartCoroutine(TriggerDamageEffect());
        }

        FindNewTargetForOpponent();
        Die();
    }
Пример #2
0
    IEnumerator AttackEntity(Entity target)
    {
        if (target is Enemy)
        {
            while (target.GetIsAlive() == true)
            {
                yield return(new WaitForSeconds(thisEntity.GetAttackRate()));

                var dmg = RandomizeDamage();

                target.GetComponent <Enemy>().TakeDamage(dmg);

                PlayAnimation();

                UseSpecialAbility(target);

                TextPopup.CreateDamagePopup(target.transform.position, dmg);
            }

            gameObject.GetComponent <Human>().KillEnemy(target.GetComponent <Enemy>());

            yield return(null);
        }

        else if (target is Human)
        {
            yield return(new WaitForSeconds(Random.Range(0.05f, 0.1f)));

            while (target.GetIsAlive() == true)
            {
                yield return(new WaitForSeconds(thisEntity.GetAttackRate()));

                var dmg = RandomizeDamage();

                UseSpecialAbility(target);

                target.GetComponent <Human>().TakeDamage(dmg);

                enemyAnimController.AttackAnimation();

                //TextPopup.CreateDamagePopup(target.transform.position, dmg);
            }

            yield return(null);
        }
    }
Пример #3
0
    public void StrikeCurrentTarget()
    {
        if (currentTargetDefender == null && currentTargetObstacle == null && currentTargetNode == null && isAttackingCastle == false)
        {
            return;
        }

        if (currentTargetDefender != null)
        {
            if (transform.position.x <= currentTargetDefender.transform.position.x)
            {
                transform.localScale = new Vector2(-1, 1);
            }
            else
            {
                transform.localScale = new Vector2(1, 1);
            }

            if (currentTargetsHealth != null)
            {
                if (currentTargetsHealth.isDead)
                {
                    currentTargetDefender.FindNewTargetForAttackers(currentTargetDefender);
                    return;
                }

                // Deal damage to self if enemy has thorns active
                if (currentTargetsHealth.thornsActive && currentTargetsHealth.thornsDamageMultiplier > 0f)
                {
                    health.TakeDamage(bluntDamage * currentTargetsHealth.thornsDamageMultiplier, slashDamage * currentTargetsHealth.thornsDamageMultiplier, piercingDamage * currentTargetsHealth.thornsDamageMultiplier, fireDamage * currentTargetsHealth.thornsDamageMultiplier, true, false);
                }

                currentTargetsHealth.TakeDamage(bluntDamage, slashDamage, piercingDamage, fireDamage, false, shouldKnockback);
            }
        }
        else if (currentTargetObstacle != null)
        {
            currentTargetObstacle.TakeDamage(structuralAttackDamage);

            if (PlayerPrefsController.DamagePopupsEnabled())
            {
                TextPopup.CreateDamagePopup(transform.position + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(0f, 0.15f)), structuralAttackDamage, false, true);
            }
        }
        else if (currentTargetNode != null)
        {
            if (currentTargetResourceDeposit != null)
            {
                currentTargetResourceDeposit.TakeDamage(structuralAttackDamage);

                if (currentTargetResourceDeposit.currentHealth <= 0)
                {
                    FindNewTargetDeposit();
                }
            }

            if (PlayerPrefsController.DamagePopupsEnabled())
            {
                TextPopup.CreateDamagePopup(transform.position + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(0f, 0.15f)), structuralAttackDamage, false, true);
            }
        }
        else if (isAttackingCastle)
        {
            castleHealth.TakeHealth(structuralAttackDamage);

            if (PlayerPrefsController.DamagePopupsEnabled())
            {
                TextPopup.CreateDamagePopup(transform.position + new Vector3(Random.Range(-0.2f, -0.1f), Random.Range(0f, 0.15f)), structuralAttackDamage, false, true);
            }

            if (castleHealth.GetHealth() <= 0f)
            {
                StopAttacking();
                CastleCollider.instance.enabled = false;
            }
        }

        audioManager.PlayMeleeHitSound(meleeWeaponType);
    }
Пример #4
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        collision.TryGetComponent(out Attacker attacker);
        collision.TryGetComponent(out Defender defender);

        if (gameObject.activeInHierarchy)
        {
            if ((attacker != null && myShooter.defender != null && myShooter.isHealer == false && (attacker.myAttackerSpawner == myShooter.defender.squad.myLaneSpawner || myShooter.defender.squad.isCastleWallSquad)) || // If shooting an attacker
                (myShooter.isHealer && collision.transform == target) || // If healing
                (defender != null && myShooter.attacker != null && defender.squad.myLaneSpawner == myShooter.attacker.myAttackerSpawner))    // If shooting a defender
            {
                Health health = collision.GetComponent <Health>();

                if (health != null)
                {
                    StartCoroutine(HitTarget(health, false));
                }
                else
                {
                    Deactivate();
                }
            }
            else if (myShooter.attacker != null)                                                       // If this is an attacker
            {
                if (myShooter.attacker.canAttackNodes && myShooter.attacker.currentTargetNode != null) // If attacking a Resource Node
                {
                    if (myShooter.attacker.currentTargetResourceDeposit != null)                       // If attacking a Resource Deposit
                    {
                        collision.TryGetComponent(out ResourceDeposit resourceDeposit);
                        if (resourceDeposit != null && resourceDeposit.resourceNode.myLaneSpawner == myShooter.attacker.myAttackerSpawner && myShooter.attacker.currentTargetResourceDeposit == resourceDeposit)
                        {
                            StartCoroutine(HitTarget(null, true));

                            resourceDeposit.TakeDamage(myShooter.attacker.structuralAttackDamage);

                            // Retreat the laborers if the deposit is getting attacked
                            foreach (ResourceDeposit deposit in resourceDeposit.resourceNode.resourceDeposits)
                            {
                                if (deposit.myLaborer != null)
                                {
                                    if (deposit.myLaborer.isRetreating == false)
                                    {
                                        deposit.myLaborer.squad.Retreat();
                                    }

                                    deposit.myLaborer = null;
                                }
                            }

                            // If the resource deposit is destroyed, find new target deposits for each Attacker attacking this resource deposit
                            if (resourceDeposit.currentHealth <= 0)
                            {
                                myShooter.attacker.StopAttacking();

                                for (int i = 0; i < myShooter.attacker.myAttackerSpawner.transform.childCount; i++)
                                {
                                    Attacker attackerInLane = myShooter.attacker.myAttackerSpawner.transform.GetChild(i).GetComponent <Attacker>();
                                    if (attackerInLane.currentTargetResourceDeposit == resourceDeposit)
                                    {
                                        attackerInLane.FindNewTargetDeposit();
                                    }
                                }
                            }

                            if (PlayerPrefsController.DamagePopupsEnabled())
                            {
                                TextPopup.CreateDamagePopup(transform.position + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(0f, 0.15f)), myShooter.attacker.structuralAttackDamage, false, true);
                            }
                        }
                    }
                }
                else if (myShooter.attacker.currentTargetObstacle != null) // If attacking an Obstacle
                {
                    collision.TryGetComponent(out Obstacle obstacle);
                    if (obstacle != null)
                    {
                        StartCoroutine(HitTarget(null, true));

                        obstacle.TakeDamage(myShooter.attacker.structuralAttackDamage);

                        if (PlayerPrefsController.DamagePopupsEnabled())
                        {
                            TextPopup.CreateDamagePopup(transform.position + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(0f, 0.15f)), myShooter.attacker.structuralAttackDamage, false, true);
                        }
                    }
                }
                else // If attacking the castle
                {
                    collision.TryGetComponent(out CastleCollider castleCollider);
                    if (castleCollider != null)
                    {
                        StartCoroutine(HitTarget(null, true));

                        CastleHealth.instance.TakeHealth(myShooter.attacker.structuralAttackDamage);

                        if (PlayerPrefsController.DamagePopupsEnabled())
                        {
                            TextPopup.CreateDamagePopup(transform.position + new Vector3(Random.Range(-0.2f, -0.1f), Random.Range(0f, 0.15f)), myShooter.attacker.structuralAttackDamage, false, true);
                        }
                    }
                }
            }
        }
    }
Пример #5
0
    public void TakeDamage(float bluntDamage, float slashDamage, float piercingDamage, float fireDamage, bool ignoreResistances, bool knockback)
    {
        float finalDamageAmount = 0f;

        // If we shouldn't ignore damage resistances
        if (ignoreResistances == false)
        {
            if (bluntDamage > 0f)
            {
                finalDamageAmount += GetDamageAmount(bluntDamage, bluntResistance);
            }
            if (slashDamage > 0f)
            {
                finalDamageAmount += GetDamageAmount(slashDamage, slashResistance);
            }
            if (piercingDamage > 0f)
            {
                finalDamageAmount += GetDamageAmount(piercingDamage, piercingResistance);
            }
            if (fireDamage > 0f)
            {
                finalDamageAmount += GetDamageAmount(fireDamage, fireResistance);
            }
        }
        else // Ignore resistances
        {
            finalDamageAmount += bluntDamage;
            finalDamageAmount += slashDamage;
            finalDamageAmount += piercingDamage;
            finalDamageAmount += fireDamage;
        }

        // Adjust the damage based off of current difficulty settings
        if (defender != null)
        {
            finalDamageAmount *= PlayerPrefsController.GetDifficultyMultiplier_EnemyAttackDamage();
        }

        if (isBlessed)
        {
            finalDamageAmount *= 1f - gm.squadData.priestBlessPercentDamageReduction;
        }

        if (finalDamageAmount < 1f)
        {
            finalDamageAmount = 1f;
        }
        else
        {
            finalDamageAmount = Mathf.RoundToInt(finalDamageAmount);
        }

        currentHealth -= finalDamageAmount;

        if (PlayerPrefsController.DamagePopupsEnabled())
        {
            TextPopup.CreateDamagePopup(transform.position + new Vector3(Random.Range(-0.05f, 0.05f), Random.Range(0.05f, 0.15f)), finalDamageAmount, false, defender != null);
        }

        if (damageEffect != null)
        {
            StartCoroutine(TriggerDamageEffect());
        }

        // If the character is going to die
        if (currentHealth <= 0 && isDead == false)
        {
            FindNewTargetForOpponent();
            Die();
        }
        else if (knockback && currentHealth > 0f) // If being knocked back
        {
            if (defender != null && defender.isLarge == false)
            {
                StartCoroutine(defender.Knockback());
            }
            else if (attacker != null && attacker.isLarge == false)
            {
                StartCoroutine(attacker.Knockback());
            }
        }

        if (defender != null && defender.squad.squadType == SquadType.Laborers && defender.isRetreating == false && currentHealth > 0)
        {
            defender.squad.Retreat();
        }
    }