Exemple #1
0
        static async Task Main(string[] args)
        {
            var scoreFilePreffix = ArgumentHelper.GetProgramArgument(args, SCORE_PREFFIX_ARG);

            var serviceCollection = new ServiceCollection();

            _startUp = new Startup();
            _startUp.RegisterServices(serviceCollection);

            var botSettings = new BotSettings
            {
                Mode = ArgumentHelper.GetProgramArgument(args, BOT_MODE_ARG)
            };

            var autoPlayEngine = new AutoplayEngine(_startUp, botSettings, scoreFilePreffix);

            var serviceProvider = serviceCollection.BuildServiceProvider();

            LoadBotAssembly("cdt", "Zilon.Bot.Players.NetCore.dll", serviceCollection, serviceProvider);

            serviceProvider = serviceCollection.BuildServiceProvider();

            var startPerson = PersonCreateHelper.CreateStartPerson(serviceProvider);

            await autoPlayEngine.StartAsync(startPerson, serviceProvider);

            Console.WriteLine(autoPlayEngine.LogOutput);

            if (!ArgumentHelper.HasProgramArgument(args, SERVER_RUN_ARG))
            {
                Console.ReadLine();
            }
        }
Exemple #2
0
        public void Run(params string[] args)
        {
            _logger.LogTrace("[x] START");

            AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

            _pathToEnv   = ArgumentHelper.GetProgramArgument(args, "env");
            _launchCount = int.Parse(ArgumentHelper.GetProgramArgument(args, "launchCount"));
            _scorePrefix = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)
                           .Replace(":", "_")
                           .Replace(".", "_");

            var parallel = ArgumentHelper.GetProgramArgument(args, "parallel");

            _isInfinite = ArgumentHelper.HasProgramArgument(args, "infinite");
            _botMode    = ArgumentHelper.GetProgramArgument(args, "mode");
            _scorePath  = ArgumentHelper.GetProgramArgument(args, "output");

            _botCatalog  = ArgumentHelper.GetProgramArgument(args, "botCatalog");
            _botAssembly = ArgumentHelper.GetProgramArgument(args, "botAssembly");

            _schemeCatalogPath = ArgumentHelper.GetProgramArgument(args, "schemeCatalogPath");

            _shutdownTokenSource = new CancellationTokenSource();
            _shutdownToken       = _shutdownTokenSource.Token;

            do
            {
                if (_isInfinite)
                {
                    _logger.LogTrace($"[x] INFINITE COUNTER {_infiniteCounter}");
                }

                if (!string.IsNullOrWhiteSpace(parallel))
                {
                    RunParallel(int.Parse(parallel), _logger);
                }
                else
                {
                    RunLinear(_logger);
                }

                _infiniteCounter++;
                if (_infiniteCounter == ulong.MaxValue)
                {
                    _infiniteCounter = 0;
                }
            } while (_isInfinite);

            _logger.LogTrace("[x] COMPLETE");
        }
Exemple #3
0
        private static async Task Main(string[] args)
        {
            var scoreFilePreffix = ArgumentHelper.GetProgramArgument(args, SCORE_PREFFIX_ARG);

            var serviceCollection = new ServiceCollection();

            _startUp = new Startup();
            _startUp.RegisterServices(serviceCollection);

            var botSettings = new BotSettings
            {
                Mode = ArgumentHelper.GetProgramArgument(args, BOT_MODE_ARG)
            };

            var serviceProvider = serviceCollection.BuildServiceProvider();

            LoadBotAssembly("cdt", "Zilon.Bot.Players.NetCore.dll", serviceCollection, serviceProvider);
            var serviceProviderWithDynamicBotServices = serviceCollection.BuildServiceProvider();

            var globeInitializer = serviceProviderWithDynamicBotServices.GetRequiredService <IGlobeInitializer>();

            var autoPlayEngine = new AutoplayEngine(_startUp, botSettings, scoreFilePreffix, globeInitializer);

            var player      = serviceProvider.GetRequiredService <IPlayer>();
            var startPerson = player.MainPerson;

            var globe = await autoPlayEngine.CreateGlobeAsync();

            var autoplayContext = new FollowSinglePersonAutoplayContext(startPerson);

            await autoPlayEngine.StartAsync(globe, autoplayContext);

            Console.WriteLine(autoPlayEngine.LogOutput);

            if (!ArgumentHelper.HasProgramArgument(args, SERVER_RUN_ARG))
            {
                Console.ReadLine();
            }
        }
Exemple #4
0
        static async Task Main(string[] args)
        {
            var scoreFilePreffix = ArgumentHelper.GetProgramArgument(args, SCORE_PREFFIX_ARG);

            _globalServiceContainer = new ServiceContainer();
            _startUp = new Startup();
            _startUp.RegisterServices(_globalServiceContainer);

            LoadBotAssembly("cdt", "Zilon.Bot.Players.LightInject.dll", _globalServiceContainer, _globalServiceContainer);

            var humanActor = await CreateSectorAsync();

            var gameLoop           = _sectorServiceContainer.GetInstance <IGameLoop>();
            var botActorTaskSource = _sectorServiceContainer.GetInstance <ISectorActorTaskSource>("bot");

            ConfigureBot(args, botActorTaskSource);

            var botExceptionCount = 0;
            var envExceptionCount = 0;
            var iterationCounter  = 1;

            while (!humanActor.Person.Survival.IsDead && iterationCounter <= ITERATION_LIMIT)
            {
                try
                {
                    var humanPersonHp = humanActor.Person
                                        .Survival
                                        .Stats
                                        .Single(x => x.Type == SurvivalStatType.Health)
                                        .Value;

                    Console.WriteLine($"Current HP: {humanPersonHp} Node {humanActor.Node}");

                    gameLoop.Update();
                }
                catch (ActorTaskExecutionException exception)
                {
                    AppendException(exception, scoreFilePreffix);

                    var monsterActorTaskSource = _sectorServiceContainer.GetInstance <IActorTaskSource>("monster");
                    if (exception.ActorTaskSource != monsterActorTaskSource)
                    {
                        botExceptionCount++;

                        if (botExceptionCount >= BOT_EXCEPTION_LIMIT)
                        {
                            AppendFail(_globalServiceContainer, scoreFilePreffix);
                            throw;
                        }
                    }
                    else
                    {
                        envExceptionCount++;
                        CheckEnvExceptions(envExceptionCount, exception);
                        Console.WriteLine($"[.] {exception.Message}");
                    }
                }
                catch (Exception exception)
                {
                    AppendException(exception, scoreFilePreffix);

                    envExceptionCount++;
                    CheckEnvExceptions(envExceptionCount, exception);
                    Console.WriteLine($"[.] {exception.Message}");
                }

                if (_changeSector)
                {
                    humanActor = await CreateSectorAsync();

                    gameLoop = _sectorServiceContainer.GetInstance <IGameLoop>();

                    _changeSector = false;
                }

                iterationCounter++;
            }
            ;

            var mode         = ArgumentHelper.GetProgramArgument(args, BOT_MODE_ARG);
            var scoreManager = _globalServiceContainer.GetInstance <IScoreManager>();

            WriteScores(_globalServiceContainer, scoreManager, mode, scoreFilePreffix);

            if (!ArgumentHelper.HasProgramArgument(args, SERVER_RUN_ARG))
            {
                Console.ReadLine();
            }
        }