コード例 #1
0
        public async Task RunPlayground(CreateTestRangeParameters parameters)
        {
            // check possibility to run a game
            var possibleToRun = _IsAlreadyHasRunGame();

            if (!possibleToRun || !_canRunNewGame)
            {
                _OnCreationError("You already have an active game");
            }
            else
            {
                // set service state
                _canRunNewGame = false;

                // get game setting
                var settings = _GetGameSettings(parameters.Game);

                // create run params
                var runParams = new ZTestRangeParams
                {
                    Game = parameters.Game,
                    PreferredArchitecture = settings.PreferredArchitecture
                };

                try
                {
                    // create game to run
                    var gameProcess = await _gameFactory.CreateTestRangeAsync(runParams);

                    // create worker
                    var worker = _kernel.Get <TestRangeGameWorker>();
                    worker.Complete += (sender, e) =>
                    {
                        _canRunNewGame = true;
                    };

                    // pass game created event
                    _OnCreated(worker, "Singleplayer", "Playground");

                    // run game
                    await worker.Begin(gameProcess, settings, parameters);
                }
                catch (Exception exc)
                {
                    // raise error event
                    _OnCreationError(exc.Message);

                    // reset service state
                    _canRunNewGame = true;
                }
            }
        }
コード例 #2
0
        public async Task <IZGameProcess> CreateTestRangeAsync(ZTestRangeParams args)
        {
            ZConnectionHelper.MakeSureConnection();

            if (args.Game == ZGame.BF3)
            {
                throw new NotSupportedException("Battlefield 3 TestRange play mode not supported.");
            }

            if (args.Game == ZGame.BFH)
            {
                throw new NotImplementedException("Battlefield Hardline TestRange not implemented in ZLOEmu.");
            }

            var installedGames = await _installedGamesService.GetInstalledGamesAsync();

            if (installedGames == null)
            {
                throw new Exception("Installed games not received. Check your ZClient connection.");
            }

            var architecture = args.PreferredArchitecture ??
                               (installedGames.IsX64 ? ZGameArchitecture.x64 : ZGameArchitecture.x32);
            var compatibleGames = installedGames.InstalledGames
                                  .Where(insGame => insGame.EnumGame == args.Game)
                                  .ToArray();
            var targetGame = compatibleGames.Length > 1
                ? compatibleGames.FirstOrDefault(insGame => insGame.RunnableName.EndsWith(architecture.ToString()))
                : compatibleGames.FirstOrDefault();

            if (targetGame == null)
            {
                throw new Exception($"The target game {args.Game} not found.");
            }

            var commandRun = __runStrings[_TestRangeKey].ToObject <string>();

            commandRun = commandRun.Replace(_personaRefReplaceable, __userContext.UserId.ToString());

            var runGame = _createRunGame(targetGame, commandRun, args.Game, architecture);

            return(runGame);
        }