Beispiel #1
0
    protected override IEnumerator AnimateAttack(IEnumerable <ObjectDisplay> enemies)
    {
        if (!enemies.Any())
        {
            yield break;
        }
        var atkPwrVal = attackPower.GetValue();

        if (
            (_currentEnemy && enemies.Any(x => x.GetInstanceID() != _currentEnemy.GetInstanceID())) ||
            _currentEnemy == null ||
            _currentEnemy is Object && _currentEnemy.Equals(null))
        {
            var inx = Random.Range(0, enemies.Count());
            _currentEnemy = enemies.ElementAtOrDefault(inx);
        }
        if (_currentEnemy != null && _currentEnemy is Object && !_currentEnemy.Equals(null))
        {
            _currentEnemy.TakeDamage(atkPwrVal, this);
        }
        yield break;
    }
    protected override IEnumerator AnimateAttack(IEnumerable <ObjectDisplay> enemies)
    {
        var atkPwrVal = attackPower.GetValue();

        atkPwrVal = atkPwrVal * (1 + technologyManager.meleeDamageRate);
        if (attackType == AttackType.AOEMelee)
        {
            var enemyArray = GetMonstersByAttackType(enemies);
            foreach (var enemy in enemyArray)
            {
                if (enemy == null || enemy is Object && enemy.Equals(null))
                {
                    continue;
                }
                if (enemy.attackType == MonsterAttackType.Air)
                {
                    continue;
                }
                enemy.TakeDamage(atkPwrVal, this);
            }
        }
        else
        {
            var enemyArray = GetMonstersByAttackType(enemies);
            if (
                (currentEnemy && enemyArray.Any(x => x.GetInstanceID() != currentEnemy.GetInstanceID())) ||
                currentEnemy == null ||
                currentEnemy is Object && currentEnemy.Equals(null))
            {
                currentEnemy = enemyArray.ElementAtOrDefault(Random.Range(0, enemyArray.Count()));
            }
            if (currentEnemy != null && currentEnemy is Object && !currentEnemy.Equals(null))
            {
                currentEnemy.TakeDamage(atkPwrVal, this);
            }
        }
        yield break;
    }
    protected override IEnumerator AnimateAttack(IEnumerable <ObjectDisplay> enemies)
    {
        var arrowIns   = Instantiate <Arrow> (arrowPrefab, arrowLaunchPoint.position, Quaternion.identity);
        var enemyArray = enemies.ToArray();

        if (_currentEnemy == null || _currentEnemy is Object && _currentEnemy.Equals(null))
        {
            _currentEnemy = enemyArray.FirstOrDefault();
        }
        if (_currentEnemy != null && _currentEnemy is Object && !_currentEnemy.Equals(null))
        {
            var deltaDistance = _currentEnemy.isStopMove ? Vector3.zero : Vector3.right * (int)direction * _currentEnemy.speed.GetValue() * settings.deltaMoveStep;
            var stopPos       = new Vector3(transform.position.x + _currentEnemy.rangeAttack.GetValue(), transform.position.y, transform.position.z);
            arrowIns.Launch(_currentEnemy.transform.position, deltaDistance, stopPos, () =>
            {
                if (_currentEnemy != null && !_currentEnemy.Equals(null))
                {
                    var damage = towerObject.damage * (1 + _technologyManager.towerDamageRate);
                    _currentEnemy.TakeDamage(damage, this);
                }
            });
        }
        yield break;
    }