Beispiel #1
0
        /// <summary>
        /// Perform a melee attack
        /// </summary>
        /// <param name="_foe">Unit</param>
        public void MeleeAttack(Unit _foe)
        {
            if (m_Animation)
            {
                m_Animation.PlayMeleeAttackAnimation();
            }
            for (int i = 0; i < m_UnitAttributes.attacks * m_UnitAttributes.troopSize && _foe.m_UnitAttributes.troopSize > 0; i++)
            {
                bool notFailed = true;
                // Allocate if unit hits the foe, uses weapon skill
                int roll = Random.Range(1, 6 + 1);
                //Debug.Log("Hit Roll: " + roll);
                if (m_UnitAttributes.weaponSkill > roll)
                {
                    Debug.Log(this.name + "'s attack has failed! (Hit)");
                    GameManager.s_Instance.DisplayMessage(this.name + "'s attack has failed! (Hit)");
                    notFailed = false;
                }
                // Allocate if unit hurts the foe
                if (notFailed)
                {
                    notFailed = HurtOppenent(this, _foe);
                }
                // Allocate if foes save value saves it
                // Melee does not support cover
                roll = Random.Range(1, 6 + 1);
                //Debug.Log("Save Roll: " + roll);
                if (notFailed && _foe.m_UnitAttributes.save <= roll)
                {
                    Debug.Log(this.name + "'s attack has failed! (Save)");
                    notFailed = false;
                }
                if (notFailed)
                {
                    _foe.ReceiveDamage(1);
                    Debug.Log(this.name + "'s attack was successfull!");
                }
            }

            // When opponent is still alive at end of attack, it performs a counter attack
            if (_foe.m_UnitAttributes.troopSize > 0)
            {
                if (_foe.m_Animation)
                {
                    _foe.m_Animation.PlayMeleeAttackAnimation();
                }
                for (int i = 0; i < _foe.m_UnitAttributes.troopSize; i++)
                {
                    bool notFailed = true;
                    // Allocate if unit hits the foe, uses weapon skill
                    int roll = Random.Range(1, 6 + 1);
                    //Debug.Log("Hit Roll: " + roll);
                    if (_foe.m_UnitAttributes.weaponSkill > roll)
                    {
                        Debug.Log(_foe + "'s counter attack has failed! (Hit)");
                        notFailed = false;
                    }
                    // Allocate if unit hurts the foe
                    if (notFailed)
                    {
                        notFailed = HurtOppenent(_foe, this);
                    }
                    // Allocate if foes save value saves it
                    // Melee does not support cover
                    roll = Random.Range(1, 6 + 1);
                    //Debug.Log("Save Roll: " + roll);
                    if (notFailed && this.m_UnitAttributes.save <= roll)
                    {
                        Debug.Log(_foe.name + "'s counter attack has failed! (Save)");

                        notFailed = false;
                    }
                    if (notFailed)
                    {
                        this.ReceiveDamage(1);
                        Debug.Log(_foe.name + "'s counter attack was successfull!");
                    }
                }
            }
        }