Пример #1
0
    void Shoot()
    {
        line.enabled = true;
        Vector3 point = target.Position;

        line.SetPosition(0, this.transform.position);
        line.SetPosition(1, point);
        target.Enemy.ApplyDamage(damagePerSecond * Time.deltaTime);

        //Trying for a second shoot
        if (TargetPoint.FillBuffer(point, targetingRange))
        {
            if (!(target2 == null || !target2.Enemy.IsValid))
            {
                target2       = TargetPoint.RandomBuffered;
                line2.enabled = true;
                Vector2 a = point;
                Vector2 b = target2.Position;
                if (Vector2.Distance(a, b) > targetingRange + 0.125f)
                {
                    target2 = null;
                }
                else
                {
                    line2.SetPosition(0, point);
                    line2.SetPosition(1, target2.Position);
                }
            }
        }
    }
Пример #2
0
    protected bool AcquireTarget(out TargetPoint target)
    {
        ////Collider[] targets = Physics.OverlapSphere(transform.localPosition, targetingRange, enemyLayerMask);
        //Vector3 a = transform.localPosition;
        //Vector3 b = a;
        //b.y += 2f;
        ////Collider[] targets = Physics.OverlapCapsule(a, b, targetingRange, enemyLayerMask);
        //int hits = Physics.OverlapCapsuleNonAlloc(a, b, targetingRange, targetsBuffer, enemyLayerMask);

        ////if(targets.Length > 0)
        //if(hits > 0)
        //{
        //    //target = targets[0].GetComponent<TargetPoint>();
        //    target = targetsBuffer[Random.Range(0, hits)].GetComponent<TargetPoint>();
        //    Debug.Assert(target != null, "Targeted non-enemy!", targetsBuffer[0]);
        //    return true;
        //}
        if (TargetPoint.FillBuffer(transform.localPosition, targetingRange))
        {
            target = TargetPoint.RandomBuffered;
            return(true);
        }

        target = null;
        return(false);
    }
Пример #3
0
    public override bool GameUpdate()
    {
        Vector3 d = launchVelocity;

        d.y -= 9.81f * age;
        transform.localRotation = Quaternion.LookRotation(d);

        age += Time.deltaTime;
        Vector3 p = launchPoint + launchVelocity * age;

        p.y -= 0.5f * 9.81f * age * age;

        if (p.y <= 0f)
        {
            TargetPoint.FillBuffer(targetPoint, blastRadius);
            for (int i = 0; i < TargetPoint.BufferedCount; i++)
            {
                TargetPoint.GetBuffered(i).Enemy.ApplyDamage(damage);
            }

            Game.SpawnExplosion().Initialize(targetPoint, blastRadius, damage);

            OriginFactory.Reclaim(this);
            return(false);
        }

        Game.SpawnExplosion().Initialize(p, 0.1f);

        transform.localPosition = p;
        return(true);
    }
    //获取目标
    protected bool AcquireTarget(out TargetPoint target)
    {
        // Vector3 a = transform.localPosition;
        // Vector3 b = a;
        // b.y += 2f;

        // //个人理解:在a,b,半径为targetingRange形成的Capsule中,在enemyLayerMask层所碰到的物体都缓存在targetsBuffer中
        // int hits = Physics.OverlapCapsuleNonAlloc(a, b, targetingRange, targetsBuffer, enemyLayerMask);

        // if (hits > 0)
        // {
        //     //获取碰撞到的目标
        //     target = targetsBuffer[Random.Range(0, hits)].GetComponent<TargetPoint>();
        //     Debug.Assert(target != null, "Targeted non-enemy!", targetsBuffer[0]);
        //     return true;
        // }

        if (TargetPoint.FillBuffer(transform.localPosition, targetingRange))
        {
            target = TargetPoint.RandomBuffered;
            return(true);
        }


        target = null;
        return(false);
    }
Пример #5
0
 protected bool AcquireTarget(out TargetPoint target)
 {
     if (TargetPoint.FillBuffer(transform.localPosition, targetingRange))
     {
         target = TargetPoint.RandomBuffered;
         return(true);
     }
     target = null;
     return(false);
 }
Пример #6
0
 public void Initialize(Vector3 position, float blastRadius, int damage)
 {
     TargetPoint.FillBuffer(position, blastRadius);
     for (int i = 0; i < TargetPoint.BufferedCount; i++)
     {
         TargetPoint.GetBuffered(i).Enemy.ApplyDamage(damage);
     }
     transform.localPosition = position;
     scale = blastRadius * 0.5f;
 }
Пример #7
0
 protected bool AcquireTarget(out TargetPoint target)
 {
     if (TargetPoint.FillBuffer(transform.localPosition, targetingRange))
     {
         target = TargetPoint.RandomBuffered;
         Debug.Assert(target != null, "targeted non-enemy !", targetsBuffer[0]);
         return(true);
     }
     target = null;
     return(false);
 }
Пример #8
0
    public override void OnAreaDamage(Vector3 centerPosition)
    {
        base.OnAreaDamage(centerPosition);

        // here implement aoe damage
        TargetPoint.FillBuffer(centerPosition, explodeRadius);
        for (int i = 0; i < TargetPoint.BufferedCount; i++)
        {
            TargetPoint.GetBuffered(i).Enemy.TakeDamage(Damage);
        }
    }
Пример #9
0
 public void Modify(Tower tower, float damage)
 {
     TargetPoint.FillBuffer(tower.transform.localPosition, 3.5f, Game.enemyLayerMask);
     for (int i = 0; i < TargetPoint.BufferedCount; i++)
     {
         TargetPoint localTarget = TargetPoint.GetBuffered(i);
         localTarget.Enemy.ApplyDamage(40f, false);
         Explosion explosion = Game.SpawnExplosion(true);
         explosion.Initialize(localTarget, this.GetType().Name + level);
         // localTarget.Enemy.Effects.Add(explosion);
     }
 }
Пример #10
0
 public void Initialize(Vector3 position, float blastRange, float demage = 0f)
 {
     if (demage > 0f)
     {
         TargetPoint.FillBuffer(position, blastRange);
         for (int i = 0; i < TargetPoint.BufferedCount; i++)
         {
             TargetPoint.GetBuffered(i).Enemy.ApplyDemage(demage);
         }
     }
     transform.localPosition = position;
     scale = 2f * blastRange;
 }
Пример #11
0
 public void Initialize(Vector3 position, float blastRadius, float damage = 0f)
 {
     if (damage > 0f)
     {
         TargetPoint.FillBuffer(position, blastRadius);
         for (int i = 0; i < TargetPoint.BufferedCount; i++)
         {
             TargetPoint.GetBuffered(i).Enemy.ApplyDamage(damage);
         }
     }
     transform.localPosition = position;
     // transform.localScale = Vector3.one * (2f * blastRadius);
     scale = 2f * blastRadius;
 }
Пример #12
0
 public override void Modify(TargetPoint enemy, float damage)
 {
     TargetPoint.FillBuffer(enemy.Position, 3.5f, Game.enemyLayerMask);
     for (int i = 0; i < TargetPoint.BufferedCount; i++)
     {
         TargetPoint localTarget = TargetPoint.GetBuffered(i);
         if (localTarget != enemy)
         {
             localTarget.Enemy.ApplyDamage(damage / 2f, false);
             Explosion explosion = Game.SpawnExplosion(false);
             explosion.Initialize(localTarget, this.GetType().Name + level);
             localTarget.Enemy.Effects.Add(explosion);
         }
     }
 }
Пример #13
0
 public void Modify(Tower tower)
 {
     buff.level = level;
     buff.name1 = buff.GetType().Name + level;
     TargetPoint.FillBuffer(tower.transform.localPosition, 3.5f, Game.towerLayerMask);
     Debug.Log(TargetPoint.BufferedCount);
     for (int i = 0; i < TargetPoint.BufferedCount; i++)
     {
         TargetPoint localTarget = TargetPoint.GetBuffered(i);
         Debug.Log("LT: " + localTarget);
         Debug.Log("Tower: " + localTarget.Tower);
         if (localTarget != null && !localTarget.Tower.StatusEffects.Any(effect => effect.name1 == buff.name1))
         {
             localTarget.Tower.StatusEffects.Add(buff);
         }
     }
 }
Пример #14
0
    private TargetPoint GetTarget()
    {
        if (!TargetPoint.FillBuffer(Position, range))
        {
            target = null;
            return(target);
        }

        if (target && target.isActiveAndEnabled && !target.Enemy.IsDead)
        {
            float colliderRadius = target.ColliderRadius * target.LocalScaleX;
            if (Vector3.Distance(transform.localPosition, target.Position) > range + colliderRadius)
            {
                target = null;
            }
        }
        else
        {
            target = TargetPoint.GetBuffered(0);
        }

        return(target);
    }