Esempio n. 1
0
 public override void AI(float elapsedTime, OctreeLinked<Unit, string> octree)
 {
     if (IsDead == false)
       {
     // Targeting
     if (near && (_target == null || _target.IsDead || _move > 20))
     {
       _move = 0;
       float nearest = float.MinValue;
       octree.Traverse
       (
     (Unit current) =>
     {
       if ((current is KillemKamakazi || current is KillemMelee || current is KillemRanged) && !current.IsDead)
       {
         float length = (current.Position - Position).LengthSquared();
         if (_target == null || _target.IsDead)
         {
           _target = current;
           nearest = length;
         }
         else if (length < nearest)
         {
           _target = current;
           nearest = length;
         }
       }
     }
       );
     }
     // Attacking
     else if (Calc.Abs((Position - _target.Position).LengthSquared()) < _attackRangedSquared / 2)
     {
       Attack(octree);
       _move = 0;
     }
     // Moving
     else
     {
       Position = Vector.MoveTowardsPosition(Position, _target.Position, MoveSpeed);
       _move++;
     }
     StaticModel.Orientation.W += .1f;
       }
 }
Esempio n. 2
0
 protected void Attack(OctreeLinked<Unit, string> octree)
 {
     octree.Traverse
       (
     (Unit unit) =>
     {
       if (!unit.IsDead)
       {
     unit.Health -= _damage;
     if (unit.Health <= 0)
     {
       unit.IsDead = true;
     }
       }
     },
     -_attackRange + Position.X, -_attackRange + Position.Y, -_attackRange + Position.Z, _attackRange + Position.X, _attackRange + Position.Y, _attackRange + Position.Z
       );
       IsDead = true;
 }
Esempio n. 3
0
 public override void AI(float elapsedTime, OctreeLinked<Unit, string> octree)
 {
     if (_time <= _delay)
     _time += elapsedTime;
       if (IsDead == false)
       {
     attack = false;
     // Targeting
     if (_target == null || _target.IsDead || move > 20)
     {
       move = 0;
       float shortest = float.MaxValue;
       octree.Traverse
       (
     (Unit current) =>
     {
       if (current is KillemKamakazi && !current.IsDead)
       {
         if (_target == null || _target.IsDead || !(_target is KillemKamakazi))
         {
           _target = current;
           shortest = (current.Position - Position).LengthSquared();
         }
         else
         {
           float length = (current.Position - Position).LengthSquared();
           if (length < shortest)
           {
             _target = current;
             shortest = length;
           }
         }
       }
       else if ((current is KillemMelee || current is KillemRanged) && !current.IsDead)
       {
         if (_target == null || _target.IsDead)
         {
           _target = current;
           shortest = (current.Position - Position).LengthSquared();
         }
         else
         {
           float length = (current.Position - Position).LengthSquared();
           if (length < shortest)
           {
             _target = current;
             shortest = length;
           }
         }
       }
     }
       );
     }
     // Attacking
     else if (Calc.Abs((Position - _target.Position).LengthSquared()) < _attackRangedSquared)
     {
       if (!attack)
     AiBattle.lines.TryAdd(new Link3<Vector, Vector, Color>(
       new Vector(Position.X, Position.Y, Position.Z),
       new Vector(_target.Position.X, _target.Position.Y, _target.Position.Z),
       Color.Yellow));
       if (Attack(_target))
     _target = null;
       move = 0;
       attack = !attack;
     }
     // Moving
     else if (_time > _delay)
     {
       Position = Vector.MoveTowardsPosition(Position, _target.Position, MoveSpeed);
       move++;
       attack = false;
     }
     this.StaticModel.Orientation.W+=.1f;
       }
 }