Пример #1
0
 protected bool Attack(Unit defending)
 {
     defending.Health -= _damage;
       if (defending.Health <= 0)
       {
     defending.IsDead = true;
     return true;
       }
       return false;
 }
Пример #2
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;
       }
 }
Пример #3
0
 /// <summary>
 /// Creates a new BattleUnit
 /// </summary>
 /// <param name="unit">The unit that is battling</param>
 public BattleUnit(Unit unit)
     : base(unit)
 {
     _unit = unit;
     Stats = new Stats(this, _unit.Stats);
 }
Пример #4
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;
       }
 }
Пример #5
0
 public static int CompareTo(Unit left, string right)
 {
     return left.Id.CompareTo(right);
 }
Пример #6
0
 public static int CompareTo(Unit left, Unit right)
 {
     return left.Id.CompareTo(right.Id);
 }