예제 #1
0
        private void DoingDamageLogic()
        {
            _attackTimer -= GameTime.DeltaTime;
            if (_attackTimer > 0)
            {
                return;                   //keep waiting...
            }
            //ready to attack...
            _attackTimer = AttackSpeed;

            //deal ranged or melee damage
            if (_opponentDistanceSquared < ReachMelee * ReachMelee) //if close do melee...
            {
                SetUpWeapon(true, UnitWeapon.WeaponClasses.Melee);
                _opponent.TakeDamage(MeleeDamageDone);
                if (_opponent.GetType() == typeof(Unit))
                {
                    AddExperience(1);                                      //give experience if attacking a Unit only
                }
                CurrentWeapon.GetComponent <WeaponMeleeMotion>()?.StartStabMotion();
                //DEBUG
                Debug.DrawLine(transform.position, _opponent.transform.position, Color.blue, 0.5f);
                if (TEXT_DEBUG_ENABLED)
                {
                    TestDebugOutput += " Melee";
                }
            }
            else //...try ranged
            {
                if (_opponentDistanceSquared > ReachRangedMin * ReachRangedMin &&
                    _opponentDistanceSquared < ReachRanged * ReachRanged &&
                    GetLineOfSightClear(this.transform, _opponent))
                {
                    SetUpWeapon(true, UnitWeapon.WeaponClasses.Ranged);
                    if (_opponent != null)
                    {
                        _opponent.TakeDamage(RangedDamageDone);
                        if (_opponent.GetType() == typeof(Unit))
                        {
                            AddExperience(1);                                      //give experience if attacking a Unit only
                        }
                        //visuals
                        if (_closeToPlayer)
                        {
                            AmmoDepot depot;
                            if (Profession == Professions.Sorcerer)
                            {
                                depot = WeaponMgr.Lightning;
                                depot.FireBeamAmmo(CurrentWeapon.transform, Vector3.zero, _opponent.transform,
                                                   _opponent.GetCenterOfMassOffset());
                            }
                            else
                            {
                                depot = WeaponMgr.Arrows;
                                depot.FireAmmo(CurrentWeapon.transform.position,
                                               _opponent.transform.position + _opponent.GetCenterOfMassOffset(),
                                               _opponent.transform);
                            }

                            Debug.DrawLine(transform.position, _opponent.transform.position, Color.cyan, 0.5f);
                        }
                    }

                    if (TEXT_DEBUG_ENABLED)
                    {
                        TestDebugOutput += " Range";
                    }
                }
            }
        }