Beispiel #1
0
    public void Attack(float deltaTime, IAttackable target)
    {
        if (target == null || !AttackReady(deltaTime))
        {
            return;
        }

        float damage = tower.AttackDamage;

        target.ApplyDamage(damage);
        attackAbility.Apply(target);

        int count = UnitScanner.ScanFor(target.Position, tower.CurrentLevel.aoeRadius, buffer);

        for (int i = 0; i < count; ++i)
        {
            float distance = Vector3.Distance(target.Position, buffer[i].Position);
            buffer[i].ApplyDamage(damage / (distance + 1.0f));
            attackAbility.Apply(buffer[i]);
        }
    }
Beispiel #2
0
    private IAttackable GetClosest(Vector3 position, float radius)
    {
        int inRange = UnitScanner.ScanFor(position, radius, buffer);

        if (inRange == 0)
        {
            return(null);
        }

        int   closest = 0;
        float minDist = (position - buffer[0].Position).sqrMagnitude;

        for (int i = 1; i < inRange; ++i)
        {
            float dist = (position - buffer[i].Position).sqrMagnitude;
            if (dist < minDist)
            {
                minDist = dist;
                closest = i;
            }
        }

        return(buffer[closest]);
    }