Пример #1
0
    public void FindNewTargetForOpponent()
    {
        // If this is an attacker who is dying
        if (attacker != null)
        {
            // Find a new target for each defender who was fighting the attacker who died:
            attacker.FindNewTargetForDefenders(attacker);
        }

        // If this is a defender who is dying
        if (defender != null)
        {
            // Find a new target for each attacker who was fighting the defender who died
            defender.FindNewTargetForAttackers(defender);

            // If there are no more units in the squad and the leader is dead, get rid of the Squad GameObject & free up the space so we can spawn in a new squad
            if (defender.squad != null && defender.squad.units.Count == 0 && defender.squad.leader == null)
            {
                DefenderSpawner.instance.RemoveCell(defender.squad.transform.position);
                Destroy(defender.squad.gameObject);
            }
        }
    }
Пример #2
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);
    }