Example #1
0
        public static Strategy Build(Unit player, Cache cache, Game game, Nearest nearest)
        {
            if (player.Health < 89 && game.LootBoxes.Where(x => x.Item is Item.HealthPack).Any())
            {
                return new Strategy {
                           Type = StrategyType.Heal
                }
            }
            ;

            if (player.Weapon.HasValue == false)
            {
                return new Strategy {
                           Type = StrategyType.Seek
                }
            }
            ;

            if (cache.EqualDistanceTicks > 10 || cache.PrevStrategy.Type == StrategyType.GettinCloser && Helpers.DistanceSqr(player.Position, nearest.Enemy.Value.Position) > 4)
            {
                return(new Strategy {
                    Type = StrategyType.GettinCloser
                });
            }

            return(new Strategy {
                Type = StrategyType.Kill
            });
        }
    }
}
Example #2
0
        public static Vec2Double Build(Strategy strategy, Nearest nearest, Cache cache, Unit player)
        {
            if (nearest.Weapon.HasValue && strategy.Type == StrategyType.Seek)
            {
                return(new Vec2Double(nearest.Weapon.Value.Position.X, nearest.Weapon.Value.Position.Y));
            }

            if (nearest.HealthPack.HasValue && strategy.Type == StrategyType.Heal)
            {
                return(new Vec2Double(nearest.HealthPack.Value.Position.X, nearest.HealthPack.Value.Position.Y));
            }

            if (strategy.Type == StrategyType.Climb)
            {
                return(cache.Peak);
            }

            var addition = 0;

            if (strategy.Type == StrategyType.GettinCloser)
            {
                return(new Vec2Double(nearest.Enemy.Value.Position.X + addition, nearest.Enemy.Value.Position.Y));
            }

            if (nearest.Enemy.HasValue)
            {
                if (player.Position.X > nearest.Enemy.Value.Position.X)
                {
                    addition = 6;
                }
                else
                {
                    addition = -6;
                }

                if (nearest.Enemy.Value.Weapon.HasValue && nearest.Enemy.Value.Weapon.Value.Typ == WeaponType.RocketLauncher)
                {
                    addition = addition * 2;
                }

                if (Helpers.DistanceSqr(player.Position, nearest.Enemy.Value.Position) < addition * addition)
                {
                    addition = addition * -1;
                }

                if (Helpers.DistanceSqr(player.Position, nearest.Enemy.Value.Position) < 16)
                {
                    addition = addition * -1;
                }

                return(new Vec2Double(nearest.Enemy.Value.Position.X + addition, nearest.Enemy.Value.Position.Y));
            }

            return(new Vec2Double(nearest.Enemy.Value.Position.X, nearest.Enemy.Value.Position.Y));
        }
Example #3
0
        public UnitAction GetAction(Unit unit, Game game, Debug debug)
        {
            if (_cache == null)
            {
                _cache = new Cache(unit, game);
            }

            var nearest = new Nearest(unit, game);

            _cache.UpdateDistance(unit, nearest.Enemy.Value);

            var strategy = StrategyBuilder.Build(unit, _cache, game, nearest);

            _cache.PrevStrategy = strategy;
            UnitAction action = ActionBuilder.Build(strategy, unit, game, _cache, nearest);

            action.Log(debug, unit, strategy);
            return(action);
        }
Example #4
0
        public static bool CanShoot(this Unit player, Unit target, Tile[][] tiles, Nearest nearest)
        {
            var tan = ((nearest.Enemy.Value.Position.Y - player.Position.Y) / (nearest.Enemy.Value.Position.X - player.Position.X));

            var isRightSide = nearest.Enemy.Value.Position.X < player.Position.X;
            var increment   = isRightSide ? -0.3 : 0.3;

            double x1 = player.Position.X;
            double y1 = player.Position.Y + 1;
            double x2 = nearest.Enemy.Value.Position.X;
            double y2 = nearest.Enemy.Value.Position.Y + 1;
            double x  = x1;
            double y  = y1;

            try
            {
                while ((int)x != (int)(x2))
                {
                    x = x + increment;
                    y = (x * y2 - x * y1 - x1 * y2 + x2 * y1) / (x2 - x1);
                    if ((int)x == (int)(x2) && ((int)y == (int)y2 || (int)y == (int)(y2 + 1) || (int)y == (int)(y2 - 1)))
                    {
                        break;
                    }

                    if (tiles[(int)x][(int)y] == Tile.Wall)
                    {
                        return(false);
                    }
                }
            }
            catch (Exception e) {
                return(true);
            }

            return(true);
        }
Example #5
0
        public static UnitAction Build(Strategy strategy, Unit player, Game game, Cache cache, Nearest nearest)
        {
            var target   = TargetBuilder.Build(strategy, nearest, cache, player);
            var aim      = AimBuilder.Build(player, nearest.Enemy);
            var jump     = JumpBuilder.Build(player, target, game, strategy, nearest);
            var velocity = VelocityBuilder.Build(strategy, player, target, game.Level.Tiles);
            var action   = new UnitAction();


            action.Velocity   = velocity;
            action.Jump       = jump;
            action.JumpDown   = jump == false;
            action.Aim        = aim;
            action.Shoot      = player.CanShoot(nearest.Enemy.Value, game.Level.Tiles, nearest);
            action.SwapWeapon = ChangeWeaponBuilder.Build(player, strategy, nearest.Weapon);
            action.PlantMine  = false;
            action.Reload     = false;
            return(action);
        }