Beispiel #1
0
    public void Attack()
    {
        // Reset dmg queues
        for (int i = 0; i < 5; i++)
        {
            playerDamageArray[i] = 0;
            enemyDamageArray[i]  = 0;
        }

        for (int i = 0; i < 5; i++)
        {
            var playerSlot = playerSlots.slots[i];
            var enemySlot  = enemySlots.slots[i];

            GameObject playerCard = playerSlot.occupied ? playerSlot.objectInSlot : null;
            GameObject enemyCard  = enemySlot.occupied ? enemySlot.objectInSlot : null;

            if (playerCard == null && enemyCard == null)
            {
                continue;
            }
            if (playerCard != null)
            {
                CardInLane card = playerCard.GetComponent <CardInLane>();
                if (card.cardType == Card.CardType.Spell)
                {
                    SpellInLane spell = playerCard.GetComponent <SpellInLane>();
                    spell.CountdownSpell(i, true);
                    if (spell.timeToCast == 0)
                    {
                        Remove(spell);
                    }
                }
                else
                {
                    enemyDamageArray[i] += card.GetAttackDamage();
                }
            }
            if (enemyCard != null)
            {
                CardInLane card = enemyCard.GetComponent <CardInLane>();
                if (card.cardType == Card.CardType.Spell)
                {
                    SpellInLane spell = enemyCard.GetComponent <SpellInLane>();
                    spell.CountdownSpell(i, false);
                    if (spell.timeToCast == 0)
                    {
                        Remove(spell);
                    }
                }
                else
                {
                    playerDamageArray[i] += card.GetAttackDamage();
                }
            }
        }
        // Resolve damage queues
        for (int i = 0; i < 5; i++)
        {
            AttackSlot(i, enemySlots, enemyDamageArray[i], enemyHp);
            AttackSlot(i, playerSlots, playerDamageArray[i], playerHp);
        }

        // track a victory!
        if (enemyHp.current <= 0 && playerHp.current <= 0)
        {
            GameManager.instance.Draw();
        }
        else if (playerHp.current <= 0)
        {
            GameManager.instance.Lose();
        }
        //TODO this should do... something else for the boss capture scene
        else if (enemyHp.current <= 0)
        {
            GameManager.instance.Win();
        }
    }