Ejemplo n.º 1
0
 public override void AI(float elapsedTime, Omnitree <Unit, double> octree)
 {
     if (IsDead == false)
     {
         // Targeting
         if (near && (_target == null || _target.IsDead || _move > 20))
         {
             _move = 0;
             float nearest = float.MinValue;
             octree.Foreach
             (
                 (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 (Logic.Abs((Position - _target.Position).LengthSquared()) < _attackRangedSquared / 2)
         {
             Attack(octree);
             _move = 0;
         }
         // Moving
         else
         {
             Position += (_target.Position - Position).Normalize() * MoveSpeed;
             _move++;
         }
         StaticModel.Orientation.W += .1f;
         //StaticModel.Orientation.Z += .1f;
     }
 }
Ejemplo n.º 2
0
        public override void AI(float elapsedTime, Omnitree <Unit, double> 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.Foreach
                    (
                        (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 (Logic.Abs((Position - _target.Position).LengthSquared()) < _attackRangedSquared)
                {
                    Link <Vector <float>, Vector <float>, Color> link =
                        new Link <Vector <float>, Vector <float>, Color>(
                            new Vector <float>(Position.X, Position.Y, Position.Z),
                            new Vector <float>(_target.Position.X, _target.Position.Y, _target.Position.Z),
                            Color.Red);

                    if (!attack && !AiBattle.lines.Contains(link, AiBattle.Compare))
                    {
                        AiBattle.lines.Add(link);
                    }

                    if (Attack(_target))
                    {
                        _target = null;
                    }
                    move   = 0;
                    attack = !attack;
                }
                // Moving
                else if (_time > _delay)
                {
                    Position += (_target.Position - Position).Normalize() * MoveSpeed;
                    move++;
                    attack = false;
                }
                this.StaticModel.Orientation.W += .1f;
            }
        }