Beispiel #1
0
        /// <summary>
        /// Perform a ranged attack
        /// </summary>
        /// <param name="_foe">Unit</param>
        public void RangedAttack(Unit _foe)
        {
            RaycastHit[] allHits = Physics.RaycastAll(transform.position, transform.TransformDirection(Vector3.forward), m_AttackRange * 0.5f);
            RaycastHit   directHit;

            if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out directHit, m_AttackRange * 0.5f, RotaryHeart.Lib.PhysicsExtension.PreviewCondition.Game, 80f, Color.cyan, Color.red))
            {
                Debug.Log(directHit.collider.tag);
            }

            if (m_Animation)
            {
                m_Animation.PlayRangedAttackAnimation(m_UnitAttributes.attacks);
            }
            for (int j = 0; j < m_UnitAttributes.troopSize && _foe.m_UnitAttributes.troopSize > 0; j++)
            {
                bool notFailed = false;
                foreach (RaycastHit hit in allHits)
                {
                    if (hit.transform.parent.name == _foe.transform.name)
                    {
                        notFailed = true;
                    }
                }

                // Allocate if unit hits the foe, uses ballistic skill
                if (notFailed && directHit.collider != null && directHit.collider.tag == "FullCover")
                {
                    notFailed = false;
                }
                int roll = Random.Range(1, 6 + 1);
                //Debug.Log("Hit Roll: " + roll);
                if (notFailed && 6 - m_UnitAttributes.ballisticSkill > roll)
                {
                    Debug.Log(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
                // TODO: Will be extended to support cover values of terrain
                roll = Random.Range(1, 6 + 1);
                if (directHit.collider != null && directHit.collider.tag == "Cover")
                {
                    roll += 2;
                }
                //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!");
                }
            }
        }