Esempio n. 1
0
 public override void Execute()
 {
     if (Game.FrameCount % 9 != 0)
     {
         return;
     }
     MyCombatUnits.Where(IsOutsideOfBase).Where(IsOutnumbered).ForEach(RetreatToClosestReinforcement);
 }
Esempio n. 2
0
        public override void Execute()
        {
            var triggeringUnits = MyCombatUnits.Where(u => u.IsIdle).Where(IsOutsideOfBase).ToList();

            if (!triggeringUnits.Any())
            {
                return;
            }

            var visibleEnemyUnits = Game.Enemy.Units
                                    .Where(eu => eu.UnitType.Type != UnitType.Unknown)
                                    .Where(eu => !eu.IsCloaked)
                                    .ToList();

            if (visibleEnemyUnits.Any())
            {
                triggeringUnits.ForEach(u =>
                {
                    MyUnits.SetActivity(u, nameof(IdleFightersAttackClosestEnemy) + "Unit");
                    u.Attack(visibleEnemyUnits.ClosestTo(u).Position, false);
                });
                return;
            }

            if (!GameMemory.EnemyBuildings.Any())
            {
                triggeringUnits.ForEach(u =>
                {
                    MyUnits.SetActivity(u, nameof(IdleFightersAttackClosestEnemy) + "Searching");
                    u.Attack(RandomResourceSitePosition, false);
                });
                return;
            }

            triggeringUnits.ForEach(u =>
            {
                var closestEnemyBuilding = GameMemory.EnemyBuildings.MinBy(b => u.Position.CalcApproximateDistance(b));
                MyUnits.SetActivity(u, nameof(IdleFightersAttackClosestEnemy) + "Building");
                u.Attack(closestEnemyBuilding, false);
            });
        }