public async Task AddPlayer(HubCallerContext context, IGroupManager groups, HttpContext httpContext) { if (IsGameRunning) { await Clients.Client(context.ConnectionId).InvokeAsync("Reject", players); await groups.RemoveAsync(context.ConnectionId, PlayingGroup); await groups.AddAsync(context.ConnectionId, WaitlistGroup); } else if (players.TrueForAll(p => p.ConnectionId != context.ConnectionId)) { await groups.RemoveAsync(context.ConnectionId, WaitlistGroup); await groups.AddAsync(context.ConnectionId, PlayingGroup); lock (playersLock) { players.Add(new Player { ConnectionId = context.ConnectionId, IpAddress = httpContext.Connection.RemoteIpAddress.ToString(), Username = DbContext.GetUsername(GopUser.GetCurrentUser(httpContext)), Run = true, IsWatching = true, StartLocation = DefaultStartingLocations[Math.Min(DefaultStartingLocations.Length - 1, players.Count)] }); } await Clients.Client(context.ConnectionId).InvokeAsync("SetGameParams", Altar, Seed); await PlayingClients.UpdatePlayers(players, true); await UpdatePlayerIndices(); } }
public async Task SetPlayerLocation(HubCallerContext context, int x, int y) { var player = players.Find(p => p.ConnectionId == context.ConnectionId); if (player != null) { player.StartLocation = new Point(x, y); await PlayingClients.UpdatePlayers(players, false); } }
public Task SendAction(HubCallerContext context, string action) { var player = GetPlayer(context); if (player != null && !(player.IsWatching && IsAttractOrbAction(action))) { player.Action = action; } return(PlayingClients.UpdatePlayers(players, false)); }
public async Task SetReady(HubCallerContext context, bool ready) { var player = GetPlayer(context); if (player != null) { player.IsReady = ready; } await PlayingClients.UpdatePlayers(players, false); StartGameIfReady(); }
public async Task SetWatching(HubCallerContext context, bool watching) { var player = GetPlayer(context); if (player != null) { player.IsWatching = watching; if (watching) { // Clear player's action if watching. player.Action = null; } } await PlayingClients.UpdatePlayers(players, false); StartGameIfReady(); }
public async Task SendNewGameSignal() { if (IsGameRunning) { await StopGame(); } HasSaved = false; await Clients.Group(WaitlistGroup).InvokeAsync("NotifyRejoin"); foreach (var p in players) { p.IsReady = false; } await PlayingClients.UpdatePlayers(players, false); await PlayingClients.NewGame(); }