private async Task <JoinGameResponse> JoinGameAsync(string gameId, Player player) { try { GameState gameState = serverState.GetGameState(gameId); GameState newState = gameLogic.AddPlayer(gameState, player); serverState.UpdateGameState(newState, addedSecondPlayer: true); // Notify opponent var notification = new GameNotification { NewGameState = newState }; await Clients.Client(newState.Player1.Id).ReceiveGameStateUpdate(notification).ConfigureAwait(false); return(new JoinGameResponse { State = JoinGameResponseType.SUCCESS, GameState = newState, }); } catch (GameNotFoundException) { return(new JoinGameResponse { State = JoinGameResponseType.GAME_NOT_FOUND, GameState = null }); } }
private void HandleAnswerInvite(Client client, string data) { var request = JsonConvert.DeserializeObject <AnswerInviteRequest>(data); if (request.PlayerId == client.Id) { Send(client, new AnswerInviteResponse(request.PlayerId, AnswerInviteStatus.InvalidPlayer)); return; } Client invitingClient; lock (_lock) { invitingClient = _clients.FirstOrDefault(c => c.Id == request.PlayerId); } if (invitingClient == null) { Send(client, new AnswerInviteResponse(request.PlayerId, AnswerInviteStatus.InvalidPlayer)); return; } if (invitingClient.Status != PlayerStatus.Joined) { Send(client, new AnswerInviteResponse(request.PlayerId, AnswerInviteStatus.AlreadyOnGame)); return; } if (!_invitations.Any(i => i.InvitedPlayer == client && i.InvitingPlayer == invitingClient && !i.Answer.HasValue)) { Send(client, new AnswerInviteResponse(request.PlayerId, AnswerInviteStatus.NotInvited)); return; } if (request.Answer == InviteAnswer.Accept) { var game = new Game(client, invitingClient); client.Game = game; client.Status = PlayerStatus.OnGame; NotifyClientChange(client); invitingClient.Game = game; invitingClient.Status = PlayerStatus.OnGame; NotifyClientChange(invitingClient); _games.Add(game); var notification = new GameNotification(game.Id, game.WhitePlayer.Id, game.BlackPlayer.Id); Send(invitingClient, notification); Send(client, notification); } else { Log($"{client.Nick} has rejected {invitingClient.Nick}'s invitation"); } Send(client, new AnswerInviteResponse(request.PlayerId, AnswerInviteStatus.Success)); }
public void Subscribe(GameNotification gameNotification, Action action) { if (!_registrations.TryGetValue(gameNotification, out var actions)) { actions = new List <Action>(); _registrations[gameNotification] = actions; } actions.Add(action); }
public void Publish(GameNotification gameNotification) { if (_registrations.TryGetValue(gameNotification, out var actions)) { foreach (var action in actions) { action(); } } }
public async Task AssertSingleNotificationFires(GameNotification gameNotification, Func <Task> action) { var numberOfNotificationsTriggered = 0; Game.Subscribe(gameNotification, () => numberOfNotificationsTriggered++); await action(); numberOfNotificationsTriggered.Should().Be(1); }
public void SimulateBannedFromGame() { GameNotification notification = new GameNotification() { MessageCode = "PG-0021", Type = "PLAYER_BANNED_FROM_GAME" }; MessageReceived(notification); }
public void SimulatePlayerLeftQueue() { GameNotification notification = new GameNotification() { MessageCode = "CG-0001", MessageArgument = "318908", Type = "PLAYER_QUIT" }; MessageReceived(notification); }
public async Task AssertSingleNotificationFires(GameNotification gameNotification, Func <Task> action) { var numberOfNotificationsTriggered = 0; Game.Subscribe(gameNotification, () => numberOfNotificationsTriggered++); await action(); //if (numberOfNotificationsTriggered != 1) //{ // throw new Exception($"A single {gameNotification} notifications should have been triggered but {numberOfNotificationsTriggered} were."); //} numberOfNotificationsTriggered.Should().Be(1); }
public override void LoadContent(object obj = null) { this.timer = new Timer(); this.background = new GameDynamicBackground(this.Game); this.menuButtonTexture = ContentHandler.Load <Texture2D>(GameResources.MenuButtonTextureName); this.tapButtonTexture = ContentHandler.Load <Texture2D>(GameResources.TapButtonTextureName); this.logo = ContentHandler.Load <Texture2D>(GameResources.LogoTextureName); this.font = ContentHandler.Load <SpriteFont>(GameResources.FontSpriteFontName); this.logoImage = new GameImage(this.Game, this.logo); this.logoImage.Position = new Vector2(this.Game.Window.ClientBounds.Width / 2 - this.logoImage.Texture.Width / 2, this.Game.Window.ClientBounds.Height / 4 - this.logoImage.Texture.Height / 2); this.playButton = new GameButton(this.Game, this.menuButtonTexture); this.playButton.Size = new Vector2(300, 100); this.playButton.Text = Resources.AppResources.ButtonPlayText; this.playButton.TextColor = Color.White; this.playButton.BackgroundColor = new Color(90, 235, 130); this.playButton.Position = new Vector2(Game.Window.ClientBounds.Width / 2 - this.playButton.Size.X / 2, Game.Window.ClientBounds.Height / 2 - this.playButton.Size.Y / 2); this.tutorialButton = new GameButton(this.Game, this.menuButtonTexture); this.tutorialButton.Size = new Vector2(300, 100); this.tutorialButton.Text = Resources.AppResources.ButtonTutorialText; this.tutorialButton.TextColor = new Color(150, 150, 150); this.tutorialButton.BackgroundColor = Color.Gray; this.tutorialButton.BorderColor = Color.Black; this.tutorialButton.Position = new Vector2(this.playButton.Position.X, this.playButton.Position.Y + this.tutorialButton.Size.Y + 20); this.leaveButton = new GameButton(this.Game, this.menuButtonTexture); this.leaveButton.Size = new Vector2(300, 100); this.leaveButton.Text = Resources.AppResources.ButtonLeaveText; this.leaveButton.TextColor = Color.White; this.leaveButton.BackgroundColor = Color.LightGray; this.leaveButton.BorderColor = Color.Black; this.leaveButton.Position = new Vector2(this.tutorialButton.Position.X, this.tutorialButton.Position.Y + this.leaveButton.Size.Y + 20); this.playButton.OnClick += playButton_OnClick; this.tutorialButton.OnClick += TutorialButton_OnClick; this.leaveButton.OnClick += LeaveButton_OnClick; #if DEBUG notif = new GameSlideNotification(this.Game, this.font); notif.Label.BorderThickness = 1; notif.Label.BorderColor = Color.Black; notif.Label.Color = Color.White; #endif }
public async Task <GameNotification> SendGameActionAsync(GameActionRequest actionRequest) { GameState gameState = serverState.GetGameState(actionRequest.GameId); if (!gameLogic.ValidateGameAction(actionRequest, gameState)) { // TODO: make error messages clearer throw new ArgumentException("Invalid move"); } GameState newState = gameLogic.ApplyAction(gameState, actionRequest.Action); Player player = GameLogicUtils.GetCurrentPlayer(newState); if (player.Type == PlayerType.COMPUTER) { if (newState.Stage == GameStage.GAME_OVER) { return(new GameNotification { NewGameState = newState }); } // Get computer's move and return new state to player GameAction computerAction = gameAI.CalculateComputerMove(newState.BoardState, newState.Difficulty); GameState afterComputerMove = gameLogic.ApplyAction(newState, computerAction); serverState.UpdateGameState(afterComputerMove); return(new GameNotification { LastAction = computerAction, NewGameState = afterComputerMove }); } else { serverState.UpdateGameState(newState); // Notify opponent var notification = new GameNotification { NewGameState = newState, LastAction = actionRequest.Action }; await Clients.Client(player.Id).ReceiveGameStateUpdate(notification).ConfigureAwait(false); return(notification); } }
// Update is called once per frame void Update() { if (hasPassanger == true && Vector3.Distance(transform.position, NavigationHandler.targetPosition) < 0.1f) { GameNotification.Reset(); GameNotification.Message = dropOffText; displayingNotification = true; GameNotification.ShowNotification(); } else if (!PickUp.displayingNotification) { displayingNotification = false; GameNotification.HideNotification(dropOffText); } else if (hasPassanger == true && Vector3.Distance(transform.position, NavigationHandler.targetPosition) > 0.1f) { displayingNotification = false; GameNotification.HideNotification(dropOffText); } if (DropOff.hasPassanger && Time.time - lastMoneyRemoval > 20.0f) { moneyToGive -= 1.0f; lastMoneyRemoval = Time.time; } if (Vector3.Distance(transform.position, NavigationHandler.targetPosition) < 0.1f && hasPassanger == true && (Time.time - PickUp.lastButtonPress) > InputConstants.MENU_ACTION_DELAY && (Input.GetKey(KeyCode.E) || theController.isButtonPressed(theController.STATE_OPTION1))) { hasPassanger = false; GameNotification.HideNotification(dropOffText); GameObject newHuman = Instantiate(human); newHuman.transform.position = PassengerSystem.NextPassengerDestination; newHuman.transform.rotation = Quaternion.Euler(0, 0, 0); PickUp.lastButtonPress = Time.time; PassengerSystem.PassengerIndex++; NavigationHandler.targetPosition = PassengerSystem.NextPassengerPosition; CashEarnedHandler.notifyCashEarned((int)moneyToGive); } }
public async Task RemoveGameNotification([Remainder] string game) { string opter = Context.User.Id.ToString(); using (var uow = _db.GetDbContext()) { GameNotification notification = await uow.GameNotifications.GetNotificationAsync(opter, game); if (notification == null) { await ReplyAsync("You're already not getting notifications for that game!"); return; } uow.GameNotifications.Remove(notification); await uow.SaveChangesAsync(); await ReplyAsync($"I'll no longer notify you when your friends play {game}."); } }
// Update is called once per frame void Update() { if (transform.position.Equals(PassengerSystem.NextPassengerPosition)) { anim.SetBool("inRange", Vector3.Distance(transform.position, target.position) < stopRange * 4); if (DropOff.hasPassanger == false && Vector3.Distance(transform.position, target.position) < stopRange) { GameNotification.Reset(); GameNotification.Message = pickUpText; displayingNotification = true; GameNotification.ShowNotification(); } else if (DropOff.displayingNotification) { displayingNotification = false; GameNotification.HideNotification(pickUpText); } else if (DropOff.hasPassanger == false && Vector3.Distance(transform.position, target.position) > stopRange) { displayingNotification = false; GameNotification.HideNotification(pickUpText); } if (DropOff.hasPassanger == false && (Time.time - lastButtonPress) > InputConstants.MENU_ACTION_DELAY && (Input.GetKeyDown(KeyCode.E) || theController.isButtonPressed(theController.STATE_OPTION1)) && (Vector3.Distance(transform.position, target.position) < stopRange)) { GameNotification.HideNotification(pickUpText); DropOff.hasPassanger = true; DropOff.moneyToGive = moneyToGive; print("passanger boarded"); Vector3 destination = PassengerSystem.NextPassengerDestination; NavigationHandler.targetPosition = new Vector3(destination.x, destination.y, destination.z); lastButtonPress = Time.time; Destroy(gameObject); } } }
public void Init() { AskForPermission(); RegisterLocalScheduler(() => { var list = new List <GameNotification>(); var utcNow = DateTime.UtcNow; foreach (var notificationData in LocalNotifications) { if (!notificationData.ShouldSchedule()) { continue; } var notification = new GameNotification(); notification.Message = notificationData.Message; notification.FireUtcDate = notificationData.GetFireUtcDate(utcNow); list.Add(notification); } return(list.ToArray()); }); RegisterCustomRetentationMessages(() => { var list = new List <GameNotification>(); foreach (var msg in RetentationMessages) { list.Add(new GameNotification { Title = GameTitle, Message = msg }); } return(list.ToArray()); }); }
//internal static Inviter CurrentInviter; #pragma warning disable 4014 internal static void OnMessageReceived(object sender, object message) { MainWin.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async() => { if (message is StoreAccountBalanceNotification) { StoreAccountBalanceNotification newBalance = (StoreAccountBalanceNotification)message; InfoLabel.Content = "IP: " + newBalance.Ip + " ∙ RP: " + newBalance.Rp; Client.LoginPacket.IpBalance = newBalance.Ip; Client.LoginPacket.RpBalance = newBalance.Rp; } else if (message is GameNotification) { GameNotification notification = (GameNotification)message; MessageOverlay messageOver = new MessageOverlay(); messageOver.MessageTitle.Content = notification.Type; switch (notification.Type) { case "PLAYER_BANNED_FROM_GAME": messageOver.MessageTitle.Content = "Banned from custom game"; messageOver.MessageTextBox.Text = "You have been banned from this custom game!"; break; default: messageOver.MessageTextBox.Text = notification.MessageCode + Environment.NewLine; messageOver.MessageTextBox.Text = Convert.ToString(notification.MessageArgument); break; } Client.OverlayContainer.Content = messageOver.Content; Client.OverlayContainer.Visibility = Visibility.Visible; Client.ClearPage(typeof(CustomGameLobbyPage)); if (messageOver.MessageTitle.Content.ToString() != "PLAYER_QUIT") { Client.SwitchPage(new MainPage()); } } else if (message is PVPNetConnect.RiotObjects.Platform.Statistics.EndOfGameStats) { PVPNetConnect.RiotObjects.Platform.Statistics.EndOfGameStats stats = message as PVPNetConnect.RiotObjects.Platform.Statistics.EndOfGameStats; EndOfGamePage EndOfGame = new EndOfGamePage(stats); Client.ClearPage(typeof(TeamQueuePage)); Client.OverlayContainer.Visibility = Visibility.Visible; Client.OverlayContainer.Content = EndOfGame.Content; } else if (message is StoreFulfillmentNotification) { PlayerChampions = await PVPNet.GetAvailableChampions(); } else if (message is Inviter) { Inviter stats = message as Inviter; //CurrentInviter = stats; } else if (message is InvitationRequest) { InvitationRequest stats = message as InvitationRequest; //TypedObject body = (TypedObject)to["body"]; if (stats.Inviter != null) { try { //Already existant popup. Do not create a new one var x = Client.InviteData[stats.InvitationId]; if (x.Inviter != null) { return; } } catch { } MainWin.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { GameInvitePopup pop = new GameInvitePopup(stats); pop.HorizontalAlignment = HorizontalAlignment.Right; pop.VerticalAlignment = VerticalAlignment.Bottom; pop.Height = 230; Client.NotificationGrid.Children.Add(pop); })); } } })); }
//internal static Inviter CurrentInviter; internal static void OnMessageReceived(object sender, object message) { MainWin.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async() => { if (message is StoreAccountBalanceNotification) { StoreAccountBalanceNotification newBalance = (StoreAccountBalanceNotification)message; InfoLabel.Content = "IP: " + newBalance.Ip + " ∙ RP: " + newBalance.Rp; Client.LoginPacket.IpBalance = newBalance.Ip; Client.LoginPacket.RpBalance = newBalance.Rp; } else if (message is GameNotification) { GameNotification notification = (GameNotification)message; MessageOverlay messageOver = new MessageOverlay(); messageOver.MessageTitle.Content = notification.Type; switch (notification.Type) { case "PLAYER_BANNED_FROM_GAME": messageOver.MessageTitle.Content = "Banned from custom game"; messageOver.MessageTextBox.Text = "You have been banned from this custom game!"; break; default: messageOver.MessageTextBox.Text = notification.MessageCode + Environment.NewLine; messageOver.MessageTextBox.Text = Convert.ToString(notification.MessageArgument); break; } Client.OverlayContainer.Content = messageOver.Content; Client.OverlayContainer.Visibility = Visibility.Visible; Client.ClearPage(new CustomGameLobbyPage()); Client.SwitchPage(new MainPage()); } else if (message is EndOfGameStats) { EndOfGameStats stats = message as EndOfGameStats; EndOfGamePage EndOfGame = new EndOfGamePage(stats); Client.OverlayContainer.Visibility = Visibility.Visible; Client.OverlayContainer.Content = EndOfGame.Content; } else if (message is StoreFulfillmentNotification) { PlayerChampions = await PVPNet.GetAvailableChampions(); } else if (message is Inviter) { Inviter stats = message as Inviter; //CurrentInviter = stats; } else if (message is InvitationRequest) { InvitationRequest stats = message as InvitationRequest; Inviter Inviterstats = message as Inviter; //TypedObject body = (TypedObject)to["body"]; MainWin.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { //Gameinvite stuff GameInvitePopup pop = new GameInvitePopup(stats); //await Invite.Callback; //Invite.InvitationRequest(body); pop.HorizontalAlignment = HorizontalAlignment.Right; pop.VerticalAlignment = VerticalAlignment.Bottom; pop.Height = 230; Client.NotificationGrid.Children.Add(pop); //Client.InviteJsonRequest = LegendaryClient.Logic.JSON.InvitationRequest.PopulateGameInviteJson(); //message.GetType() == typeof(GameInvitePopup) })); } })); }
private bool OnGameNotification(GameNotification arg) { OnAdvancedToLobby(); return(true); }
public void AddNotification(GameNotification notif) { notifications.Add(notif); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here Global.Content = Content; // Allow mouse //IsMouseVisible = true; cursor = CustomCusor.GetInstance(); // Initialize map gridMap = WordGrid.GetInstance(); //gridMap.Load(Content.Load<GridData>(Utils.GetMapFileName(Consts.DEFALT_MAP_NAME))); // Initialize dictionary dictionary = TrieDictionary.GetInstance(); dictionary.Load(Content.Load<string[]>(Utils.GetDictionaryFileName(Consts.DEFAULT_DICTIONARY_NAME))); // Initialize logo panel logoPanel = LogoPanel.GetInstance(); // Initialize menu menuContainer = MenuContainer.GetInstance(); // Initialize background background = new Sprite2D(0, 0, Utils.LoadTextures(Utils.GetImageFileName("Background"))); // Initialize notification notification = GameNotification.GetInstance(); // Initialize controller mouseController = MouseController.GetInstance(); keyboardController = KeyboardController.GetInstance(); // Initialize button backButton = new TileButton(25, 620, Utils.GetImageFileName("Back")); soundButton = new TileButton(70, 620, Utils.GetImageFileName("Sound")); // Load sound effects Global.clickSound = Content.Load<SoundEffect>(@"Sound\click"); Global.achieveSound = Content.Load<SoundEffect>(@"Sound\achieve"); Global.themeSong = Content.Load<Song>(@"Sound\theme"); Global.UpdatePhase(Phase.MENU_LOADING); }
public void SendNotification(GameNotification notification) { base.SendNotification(notification.ToString()); }
public void RegisterCommand(GameNotification notification, Type commandType) { base.RegisterCommand(notification.ToString(), commandType); }
public void SendNotification(GameNotification notification, object body) { base.SendNotification(notification.ToString(),body); }
public void SendNotification(GameNotification notification, object body, object body2 ) { base.SendNotification(notification.ToString(), new List<object> { body, body2 }); }
private bool OnGameNotification(GameNotification notify) { return(true); }
public Game Subscribe(GameNotification gameNotification, Action action) { _gameNotifications.Subscribe(gameNotification, action); return(this); }
public void SendNotification(GameNotification notification, object body, object body2, object body3, object body4, object body5, object body6) { base.SendNotification(notification.ToString(), new List<object> { body, body2, body3, body4, body5, body6 }); }
private void PushMessage(string receiver, GameNotification notification) { var serializedNotification = this.serializer.Serialize(notification); var client = connectedClients .Cast<TestGameHandler>() .FirstOrDefault(c => c.UserName == receiver); if (client != null) { client.Notification(this, new TestGameEventArgs(serializedNotification)); } }
internal static void OnMessageReceived(object sender, MessageReceivedEventArgs message) { MainWin.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async() => { if (message.Body is StoreAccountBalanceNotification) { StoreAccountBalanceNotification newBalance = (StoreAccountBalanceNotification)message.Body; InfoLabel.Content = "IP: " + newBalance.Ip + " ∙ RP: " + newBalance.Rp; LoginPacket.IpBalance = newBalance.Ip; LoginPacket.RpBalance = newBalance.Rp; } else if (message.Body is GameNotification) { GameNotification notification = (GameNotification)message.Body; MessageOverlay messageOver = new MessageOverlay(); messageOver.MessageTitle.Content = notification.Type; switch (notification.Type) { case "PLAYER_BANNED_FROM_GAME": messageOver.MessageTitle.Content = "Banned from custom game"; messageOver.MessageTextBox.Text = "You have been banned from this custom game!"; break; case "PLAYER_QUIT": string[] Name = await RiotCalls.GetSummonerNames(new double[1] { Convert.ToDouble((string)notification.MessageArgument) }); messageOver.MessageTitle.Content = "Player has left the queue"; messageOver.MessageTextBox.Text = Name[0] + " has left the queue"; break; default: messageOver.MessageTextBox.Text = notification.MessageCode + Environment.NewLine; messageOver.MessageTextBox.Text += Convert.ToString(notification.MessageArgument); break; } OverlayContainer.Content = messageOver.Content; OverlayContainer.Visibility = Visibility.Visible; QuitCurrentGame(); } else if (message.Body is EndOfGameStats) { EndOfGameStats stats = message.Body as EndOfGameStats; EndOfGamePage EndOfGame = new EndOfGamePage(stats); OverlayContainer.Visibility = Visibility.Visible; OverlayContainer.Content = EndOfGame.Content; } else if (message.Body is StoreFulfillmentNotification) { PlayerChampions = await RiotCalls.GetAvailableChampions(); } else if (message.Body is GameDTO) { GameDTO Queue = message.Body as GameDTO; if (!IsInGame && Queue.GameState != "TERMINATED" && Queue.GameState != "TERMINATED_IN_ERROR") { MainWin.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { Client.OverlayContainer.Content = new QueuePopOverlay(Queue).Content; Client.OverlayContainer.Visibility = Visibility.Visible; })); } } else if (message.Body is SearchingForMatchNotification) { SearchingForMatchNotification Notification = message.Body as SearchingForMatchNotification; if (Notification.PlayerJoinFailures != null && Notification.PlayerJoinFailures.Count > 0) { MessageOverlay messageOver = new MessageOverlay(); messageOver.MessageTitle.Content = "Could not join the queue"; foreach (QueueDodger x in Notification.PlayerJoinFailures) { messageOver.MessageTextBox.Text += x.Summoner.Name + " is unable to join the queue as they recently dodged a game." + Environment.NewLine; TimeSpan time = TimeSpan.FromMilliseconds(x.PenaltyRemainingTime); messageOver.MessageTextBox.Text += "You have " + string.Format("{0:D2}m:{1:D2}s", time.Minutes, time.Seconds) + " remaining until you may queue again"; } OverlayContainer.Content = messageOver.Content; OverlayContainer.Visibility = Visibility.Visible; } } })); }