示例#1
0
    //La unidad ataca a una villa enemiga
    public void Attack(Village aldea)
    {
        hasAttacked = true;

        int enemyDamege = attackDamage - aldea.resistance;

        if (enemyDamege >= 1)
        {
            aldea.health -= enemyDamege;
            DamageIcon d = Instantiate(damageIcon, aldea.transform.position, Quaternion.identity);
            d.Setup(enemyDamege);
        }

        if (aldea.health <= 0)
        {
            if (deathEffect != null)
            {
                Instantiate(deathEffect, aldea.transform.position, Quaternion.identity);
                camAnim.SetTrigger("shake");
            }

            GetWalkableTiles(); // check for new walkable tiles (if enemy has died we can now walk on his tile)
            //Si el enemigo era de la IA, se ha de borrar de la lista del IAPlayer
            aldea.PintarInfluencia(false);
            //gm.RemoveInfoPanel(enemy);

            //Si el enemigo era del jugador, la IA debe de dejar de considerarlo como enemigo objetivo de la unidad
            //if(aldea.playerNumber==1)    gm.OlvidarEnemigoMatado(aldea);
            Destroy(aldea.gameObject);
        }
        gm.UpdateInfoStats();
    }
示例#2
0
    void Attack(Unit enemy)
    {
        cameraShakeAnimation.SetTrigger("shake");
        hasAttacked = true;

        int enemyDamage = attackDamage - enemy.armor;
        int myDamage    = enemy.counterAttackDamage - armor;

        if (enemyDamage >= 1)
        {
            DamageIcon instance = Instantiate(damageIcon, enemy.transform.position, Quaternion.identity);
            instance.Setup(enemyDamage);
            enemy.health -= enemyDamage;
        }
        if (myDamage >= 1)
        {
            DamageIcon instance = Instantiate(damageIcon, transform.position, Quaternion.identity);
            instance.Setup(myDamage);
            health -= myDamage;
        }

        if (enemy.health <= 0)
        {
            Destroy(enemy.gameObject);
            GetWalkableTiles();
        }
        if (health <= 0)
        {
            gameMaster.ResetTiles();
            Destroy(this.gameObject);
        }
    }
示例#3
0
    void Attack(Unit enemy)
    {
        camAnim.SetTrigger("shake");

        hasAttacked = true;

        int enemyDamage = attackDamage - enemy.armor;
        int myDamage    = enemy.defenseDamage - armor;

        if (enemyDamage >= 1)
        {
            DamageIcon instance = Instantiate(damageIcon, enemy.transform.position, Quaternion.identity);
            instance.Setup(enemyDamage);
            enemy.health -= enemyDamage;
        }
        if (myDamage >= 1)
        {
            health -= myDamage;
        }

        if (enemy.health <= 0)
        {
            Instantiate(deathEffect, enemy.transform.position, Quaternion.identity);
            Destroy(enemy.gameObject);
            GetWalkableTiles();
        }

        if (health <= 0)
        {
            Instantiate(deathEffect, transform.position, Quaternion.identity);
            gm.ResetTiles();
            Destroy(this.gameObject);
        }
    }
示例#4
0
    void Attack(Unit enemy)
    {
        hasAttacked = true;

        int enemyDamege = attackDamage - enemy.armor;
        int myDamage    = enemy.defenseDamage - armor;

        if (enemyDamege >= 1)
        {
            enemy.health -= enemyDamege;
        }

        if (myDamage >= 1)
        {
            DamageIcon instance = Instantiate(damageIcon, transform.position, Quaternion.identity);
            instance.Setup(myDamage);
            health -= myDamage;
        }

        if (enemy.health <= 0)
        {
            Destroy(enemy.gameObject);
            GetWalkableTiles();
        }

        if (health <= 0)
        {
            gm.ResetTiles();
            Destroy(this.gameObject);
        }
    }
示例#5
0
    void Attack(Unit enemy)
    {
        UnitHasAttacked = true;
        int enemyDamage = AttackDamage - enemy.Armor;
        //int unitDamage = enemy.DefenseDamage - Armor;
        Vector2 enemyPosition = new Vector2(enemy.transform.position.x, enemy.transform.position.y + 0.5f);

        if (enemyDamage >= 1)
        {
            DamageIcon instance = Instantiate(DIcon, enemyPosition, Quaternion.identity);
            instance.Setup(enemyDamage);
            enemy.Health -= enemyDamage;
        }

        //if(unitDamage >= 1)
        //{
        //    Health -= unitDamage;
        //}

        if (enemy.Health <= 0)
        {
            Destroy(enemy.gameObject);
            GetWalkableTiles();
        }

        //if(Health <= 0)
        //{
        //    Master.ResetTiles();
        //    Destroy(this.gameObject);
        //}
    }
示例#6
0
    public void AttackBase(House enemyBase)
    {
        hasAttacked = true;

        int enemyDamage = attackDamage;// - enemyBase.armor;

        if (enemyDamage >= 1)
        {
            enemyBase.health -= enemyDamage;
            if (enemyBase.health <= 0)
            {
                enemyBase.health = 0;
                camAnim.SetTrigger("shake");

                gm.ShowVictoryPanel(enemyBase.playerNumber);

                GetWalkableTiles(); // check for new walkable tiles (if enemy has died we can now walk on his tile)
                Destroy(enemyBase.gameObject);
            }
            enemyBase.UpdateHealthDisplay();
            DamageIcon d = Instantiate(damageIcon, enemyBase.transform.position, Quaternion.identity);
            d.Setup(enemyDamage);
        }
    }
示例#7
0
    // La unidad seleccionada por GM ataca a la seleccionada en OnMouseDown (enemy)
    public void Attack(Unit enemy)
    {
        hasAttacked = true;

        int enemyDamege = attackDamage - enemy.armor;
        int unitDamage  = enemy.defenseDamage - armor;

        if (enemyDamege >= 1)
        {
            enemy.health -= enemyDamege;
            enemy.UpdateHealthDisplay();
            DamageIcon d = Instantiate(damageIcon, enemy.transform.position, Quaternion.identity);
            d.Setup(enemyDamege);
        }

        if (transform.tag == "Archer" && enemy.tag != "Archer")
        {
            if (gm.calculaDistancia(this.transform, enemy.transform) <= 1) // check is the enemy is near enough to attack
            {
                if (unitDamage >= 1)
                {
                    health -= unitDamage;
                    UpdateHealthDisplay();
                    DamageIcon d = Instantiate(damageIcon, transform.position, Quaternion.identity);
                    d.Setup(unitDamage);
                }
            }
        }
        else
        {
            if (unitDamage >= 1)
            {
                health -= unitDamage;
                UpdateHealthDisplay();
                DamageIcon d = Instantiate(damageIcon, transform.position, Quaternion.identity);
                d.Setup(unitDamage);
            }
        }

        if (enemy.health <= 0)
        {
            if (deathEffect != null)
            {
                Instantiate(deathEffect, enemy.transform.position, Quaternion.identity);
                camAnim.SetTrigger("shake");
            }

            if (enemy.isKing)
            {
                gm.ShowVictoryPanel(enemy.playerNumber);
            }

            GetWalkableTiles(); // check for new walkable tiles (if enemy has died we can now walk on his tile)
            //Si el enemigo era de la IA, se ha de borrar de la lista del IAPlayer
            enemy.PintarInfluencia(false);
            gm.RemoveInfoPanel(enemy);

            //Si el enemigo era del jugador, la IA debe de dejar de considerarlo como enemigo objetivo de la unidad
            if (enemy.playerNumber == 1)
            {
                gm.OlvidarEnemigoMatado(enemy);
            }
            Destroy(enemy.gameObject);
        }

        if (health <= 0)
        {
            if (deathEffect != null)
            {
                Instantiate(deathEffect, enemy.transform.position, Quaternion.identity);
                camAnim.SetTrigger("shake");
            }

            if (isKing)
            {
                gm.ShowVictoryPanel(playerNumber);
            }

            gm.ResetTiles(); // reset tiles when we die
            gm.RemoveInfoPanel(this);
            PintarInfluencia(false);
            if (playerNumber == 2)
            {
                gm.AcabarAccionYMatarUnidadIA(this.gameObject);
            }
            else
            {
                Destroy(gameObject);
            }
        }

        else if (playerNumber == 2)
        {
            gm.AcabarAccionUnidadIA();
        }

        gm.UpdateInfoStats();
    }
示例#8
0
    void Attack(Unit enemy)
    {
        hasAttacked = true;

        int enemyDamege = attackDamage - enemy.armor;
        int unitDamage  = enemy.defenseDamage - armor;

        if (enemyDamege >= 1)
        {
            enemy.health -= enemyDamege;
            enemy.UpdateHealthDisplay();
            DamageIcon d = Instantiate(damageIcon, enemy.transform.position, Quaternion.identity);
            d.Setup(enemyDamege);
        }

        if (transform.tag == "Archer" && enemy.tag != "Archer")
        {
            if (Mathf.Abs(transform.position.x - enemy.transform.position.x) + Mathf.Abs(transform.position.y - enemy.transform.position.y) <= 1) // check is the enemy is near enough to attack
            {
                if (unitDamage >= 1)
                {
                    health -= unitDamage;
                    UpdateHealthDisplay();
                    DamageIcon d = Instantiate(damageIcon, transform.position, Quaternion.identity);
                    d.Setup(unitDamage);
                }
            }
        }
        else
        {
            if (unitDamage >= 1)
            {
                health -= unitDamage;
                UpdateHealthDisplay();
                DamageIcon d = Instantiate(damageIcon, transform.position, Quaternion.identity);
                d.Setup(unitDamage);
            }
        }

        if (enemy.health <= 0)
        {
            if (deathEffect != null)
            {
                Instantiate(deathEffect, enemy.transform.position, Quaternion.identity);
                camAnim.SetTrigger("shake");
            }

            if (enemy.isKing)
            {
                gm.ShowVictoryPanel(enemy.playerNumber);
            }

            GetWalkableTiles(); // check for new walkable tiles (if enemy has died we can now walk on his tile)
            gm.RemoveInfoPanel(enemy);
            Destroy(enemy.gameObject);
        }

        if (health <= 0)
        {
            if (deathEffect != null)
            {
                Instantiate(deathEffect, enemy.transform.position, Quaternion.identity);
                camAnim.SetTrigger("shake");
            }

            if (isKing)
            {
                gm.ShowVictoryPanel(playerNumber);
            }

            gm.ResetTiles(); // reset tiles when we die
            gm.RemoveInfoPanel(this);
            Destroy(gameObject);
        }

        gm.UpdateInfoStats();
    }
示例#9
0
    //Method called to begin combat in the game.
    void Attack(Unit enemy)
    {
        //Shake the camera in the game.
        camAnim.SetTrigger("Shake");

        //Deals the attack damage to both the units. The one the player is selecting and the one he chooses to attack.
        hasAttacked = true;
        int enemyDamage = attackDamage - enemy.armor;
        int myDamage    = enemy.defenseDamage - armor;

        //If the attack is effective, updating the visuals and the right values to the UI.
        if (enemyDamage >= 1)
        {
            DamageIcon instance = Instantiate(damageIcon, enemy.transform.position, Quaternion.identity);
            instance.Setup(enemyDamage);
            enemy.health -= enemyDamage;
            enemy.UpdateKingHealth();
        }

        //Calculations made to deal with units that can attack from a distance and units that cannot.
        if (transform.tag == "Ranged" && enemy.tag != "Ranged")
        {
            if (Mathf.Abs(transform.position.x - enemy.transform.position.x) + Mathf.Abs(transform.position.y - enemy.transform.position.y) <= 1)
            {
                if (myDamage >= 1)
                {
                    DamageIcon instance = Instantiate(damageIcon, transform.position, Quaternion.identity);
                    instance.Setup(myDamage);
                    health -= myDamage;
                    UpdateKingHealth();
                }
            }
        }
        else
        {
            if (myDamage >= 1)
            {
                DamageIcon instance = Instantiate(damageIcon, transform.position, Quaternion.identity);
                instance.Setup(myDamage);
                health -= myDamage;
                UpdateKingHealth();
            }
        }

        //Checking if the enemy`s unit is dead.
        if (enemy.health <= 0)
        {
            Instantiate(deathEffect, enemy.transform.position, Quaternion.identity);
            Destroy(enemy.gameObject);
            GetWalkableTiles();
            gm.RemoveStatsPanel(enemy);
        }

        //Checking if the player`s unit is dead.
        if (health <= 0)
        {
            Instantiate(deathEffect, transform.position, Quaternion.identity);
            gm.ResetTiles();
            gm.RemoveStatsPanel(this);
            Destroy(this.gameObject);
        }

        gm.UpdateStatsPanel();
    }
示例#10
0
    void Attack(Unit enemy) //attack function, takes in enemy as an argument
    {
        camAnim.SetTrigger("shake");

        hasAttacked = true;
        int enemyDamage = attackDamage - enemy.armor;  //stores the amount of damage that you should do to an enemy, equal to your attacks strength minus the enemy armor stat
        int myDamage    = enemy.defenseDamage - armor; //stores how much damage a defending unit should inflict on the attacking unit

        if (enemyDamage >= 1)
        {
            DamageIcon instance = Instantiate(damageIcon, enemy.transform.position, Quaternion.identity); //create a damage icon at the enemies position, no rotation
            //variable is used so a specific amount of damage can be displayed
            instance.Setup(enemyDamage);
            enemy.health -= enemyDamage; //if the attack value after the armor stat is subtracted is at least, do that amount of damage to the enemy
            enemy.UpdateLeaderHealth();
        }

        if (transform.tag == "Ranged Fighter" && enemy.tag != "Ranged Fighter")                                                                   //if a mage attacks a non mage enemy
        {
            if (Mathf.Abs(transform.position.x - enemy.transform.position.x) + Mathf.Abs(transform.position.y - enemy.transform.position.y) <= 1) //if the two are fighting at close range, then do damage like normal
            {
                if (myDamage >= 1)
                {
                    DamageIcon instance = Instantiate(damageIcon, transform.position, Quaternion.identity);
                    instance.Setup(myDamage);
                    health -= myDamage;
                    UpdateLeaderHealth();
                }
            }
        }
        else //if the attack is not a melee vs a mage
        {
            if (myDamage >= 1)
            {
                DamageIcon instance = Instantiate(damageIcon, transform.position, Quaternion.identity);
                instance.Setup(myDamage);
                health -= myDamage;
                UpdateLeaderHealth();
            }
        }



        //now check if either unit is dead
        if (enemy.health <= 0)
        {
            if (isLeader == true) //for some reason this if statement and the matching one in line 172 do not seem to work despite not throwing errors and being coded the same way
            //as the rest of my ui, the death of the leader units was supposed to determine the win/lose state and display the restart button,
            //however since I cant seem to fix this or even figure out whats causing the problem, the restart button will always be visible
            {
                enemy.victoryPanel.SetActive(true);
            }
            Instantiate(deathEffect, enemy.transform.position, Quaternion.identity);
            Destroy(enemy.gameObject);
            gm.RemoveStatsPanel(enemy);
            GetWalkableTiles(); //destory that enemy, you can now move on the place where the enemy was killed
        }

        if (health <= 0)
        {
            //check if unit is the team Leader
            if (isLeader == true)
            {
                victoryPanel.SetActive(true);
            }
            Instantiate(deathEffect, transform.position, Quaternion.identity);
            gm.ResetTiles(); //reset tiles if the unit is dead
            gm.RemoveStatsPanel(this);
            Destroy(this.gameObject);
        }

        gm.UpdateStatsPanel();
    }
示例#11
0
    void Attack(Units enemy)
    {
        camAnim.SetTrigger("shake");
        hasAttack = true;

        int enemyDamage = attackDamage - enemy.armor;
        int myDamage    = enemy.defenseDamage - armor;

        if (enemyDamage >= 1)
        {
            enemy.health -= enemyDamage;
            DamageIcon d = Instantiate(damageIcon, enemy.transform.position, Quaternion.identity);
            d.Setup(enemyDamage);
            enemy.UpdateGeneralHealth();
        }

        if (transform.tag == "Range" && enemy.tag != "Range")
        {
            if (Math.Round(Mathf.Abs(transform.position.x - enemy.transform.position.x)) + Math.Round(Mathf.Abs(transform.position.y - enemy.transform.position.y)) <= 1) // check is the enemy is near enough to attack
            {
                if (myDamage >= 1)
                {
                    health -= myDamage;
                    DamageIcon d = Instantiate(damageIcon, transform.position, Quaternion.identity);
                    d.Setup(myDamage);
                    UpdateGeneralHealth();
                }
            }
        }
        else
        {
            if (myDamage >= 1)
            {
                health -= myDamage;
                DamageIcon d = Instantiate(damageIcon, transform.position, Quaternion.identity);
                d.Setup(myDamage);
                UpdateGeneralHealth();
            }
        }

        if (enemy.health <= 0)
        {
            if (enemy.isGeneral)
            {
                enemy.victoryPanel.SetActive(true);
            }
            Instantiate(deathEffect, enemy.transform.position, Quaternion.identity);
            gm.removeStatsPanel(enemy);
            Destroy(enemy.gameObject);
            GetWalkableTiles();
        }

        if (health <= 0)
        {
            if (isGeneral)
            {
                victoryPanel.SetActive(true);
            }
            Instantiate(deathEffect, transform.position, Quaternion.identity);
            gm.removeStatsPanel(this);
            gm.ResetTiles();
            GetWalkableTiles();
            Destroy(this.gameObject);
        }
        gm.UpdateStatsPanel();
    }