Пример #1
0
        public void OnOpen(string name)
        {
            Player player = new Player(_config)
            {
                Name         = name,
                ConnectionId = Context.ConnectionId
            };

            SpawnService.SpawnPlayer(player);

            _gameEngine.AddPlayer(player);
            Console.WriteLine($"Registered player: {player.Name} ({player.Id})");
            // Confirmation status

            var connectionConfirmationResponse = new ConfirmConnectionResponse
            {
                Type     = "connected",
                PlayerId = player.Id,
                Config   = _config,
                MapState = _mapState,
                Weapons  = WeaponService.Weapons
            };

            Clients.Caller.SendAsync("connectConfirmation", connectionConfirmationResponse);

            Clients.All.SendAsync("newPlayerConnected", player.Name);
        }
Пример #2
0
        public override async Task OnConnectedAsync()
        {
            _logger.LogInformation($"New connection! Id = {Context.ConnectionId}");
            _engine.AddPlayer(new Player
            {
                Id   = Context.ConnectionId,
                Type = Player.GetRandomType()
            });
            await UpdateClients();

            await base.OnConnectedAsync();
        }
Пример #3
0
        public CGMessage JoinGame(PlayerGame playerGame)
        {
            _methodName = $"{ClassName}.JoinGame";
            CGMessage returnMessage = new();

            try
            {
                Game   game = _gameEngine.GetGames().First(ge => ge.Id.Equals(playerGame.Game.Id));
                Player p    = _gameEngine.GetPlayers().First(pl => pl.Id.Equals(playerGame.Player.Id));
                _gameEngine.AddPlayer(p, game);
                returnMessage.Status = true;
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, ex, $"{_methodName}; Error: {ex.Message}", returnMessage);
            }
            return(returnMessage);
        }
Пример #4
0
        public static void StartUp(TestContext ctx)
        {
            CultureInfo ci = new CultureInfo("en-US");

            Thread.CurrentThread.CurrentCulture = ci;

            Console.WriteLine("START UP");
            Engine = new GameEngine(new DiscordLogHelper(new ConsoleLogger()));
            Definer.Instance().Engine = Engine;
            BasePlayer = new MockEntity(Engine)
            {
                Name = "MOCK_PLAYER", Key = "MOCK_KEY"
            };
            Engine.AddPlayer(BasePlayer);
            DamageTypeTemplate trueDamage = new DamageTypeTemplate(Engine, null, null, null, null);

            trueDamage.Key = "T";
            Engine.AddDamageType(trueDamage);
        }