protected override async Task GameConnectedInternal() { this.Dispatcher.Invoke(() => { this.MapComboBox.IsEnabled = false; this.MaxTimeTextBox.IsEnabled = false; this.SparkCostTextBox.IsEnabled = false; this.TimerStackPanel.Visibility = Visibility.Collapsed; this.DropLocationStackPanel.Visibility = Visibility.Collapsed; this.WinnerStackPanel.Visibility = Visibility.Collapsed; this.TimerTextBlock.Text = string.Empty; this.DropLocationTextBlock.Text = string.Empty; this.WinnerAvatar.SetSize(80); this.WinnerTextBlock.Text = string.Empty; }); JObject settings = this.GetCustomSettings(); settings[MapSelectionSettingProperty] = this.MapComboBox.SelectedIndex; this.SaveCustomSettings(settings); await base.GameConnectedInternal(); PUBGMap map = (PUBGMap)this.MapComboBox.SelectedItem; InteractiveConnectedButtonControlModel control = new InteractiveConnectedButtonControlModel() { controlID = this.positionButton.controlID }; control.meta["map"] = map.Map; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); }
private static void InteractiveClient_OnGiveInput(object sender, InteractiveGiveInputModel e) { System.Console.WriteLine("Input Received: " + e.participantID + " - " + e.input.eventType + " - " + e.input.controlID); if (e.input.eventType.Equals("mousedown") && e.transactionID != null) { InteractiveConnectedButtonControlModel button = Program.buttons.FirstOrDefault(b => b.controlID.Equals(e.input.controlID)); if (button != null) { InteractiveConnectedSceneModel scene = Program.scenes.FirstOrDefault(s => s.buttons.Contains(button)); if (scene != null) { button.cooldown = DateTimeHelper.DateTimeOffsetToUnixTimestamp(DateTimeOffset.Now.AddSeconds(10)); Program.interactiveClient.UpdateControls(scene, new List <InteractiveConnectedButtonControlModel>() { button }).Wait(); System.Console.WriteLine("Sent 10 second cooldown to button: " + e.input.controlID); } } Program.interactiveClient.CaptureSparkTransaction(e.transactionID).Wait(); System.Console.WriteLine("Spark Transaction Captured: " + e.participantID + " - " + e.input.eventType + " - " + e.input.controlID); } }
public static void SetCooldownTimestamp(this InteractiveConnectedButtonControlModel button, long cooldown) { if (ChannelSession.Settings.PreventSmallerCooldowns) { button.cooldown = Math.Max(button.cooldown, cooldown); } else { button.cooldown = cooldown; } }
protected override async Task OnInteractiveControlUsed(UserViewModel user, InteractiveGiveInputModel input, InteractiveConnectedControlCommand command) { try { if (input.input.controlID.Equals("position") && user != null && input.input.meta.ContainsKey("x") && input.input.meta.ContainsKey("y")) { if (this.scene != null && this.positionButton != null && input.input.meta["x"] != null && input.input.meta["y"] != null) { Point point = new Point() { X = (double)input.input.meta["x"], Y = (double)input.input.meta["y"] }; this.userPoints[user.ID] = point; InteractiveConnectedButtonControlModel control = new InteractiveConnectedButtonControlModel() { controlID = this.positionButton.controlID }; control.meta["userID"] = user.ID; control.meta["x"] = point.X; control.meta["y"] = point.Y; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); await this.Dispatcher.InvokeAsync(async() => { UserProfileAvatarControl avatarControl = null; if (!this.userAvatars.ContainsKey(user.ID)) { avatarControl = new UserProfileAvatarControl(); await avatarControl.SetUserAvatarUrl(user); avatarControl.SetSize(20); this.canvas.Children.Add(avatarControl); this.userAvatars[user.ID] = avatarControl; } avatarControl = this.userAvatars[user.ID]; double canvasX = ((point.X / 100.0) * this.canvas.Width); double canvasY = ((point.Y / 100.0) * this.canvas.Height); Canvas.SetLeft(avatarControl, canvasX - 10); Canvas.SetTop(avatarControl, canvasY - 10); }); } } } catch (Exception ex) { Logger.Log(ex); } }
protected override async Task GameConnectedInternal() { InteractiveConnectedSceneGroupCollectionModel sceneGroups = await ChannelSession.Interactive.GetScenes(); if (sceneGroups != null) { this.scene = sceneGroups.scenes.FirstOrDefault(); if (this.scene != null) { this.drawButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("draw")); } } }
private async void ShowButton_Click(object sender, System.Windows.RoutedEventArgs e) { if (this.selectedUserImage != null) { InteractiveConnectedButtonControlModel control = new InteractiveConnectedButtonControlModel() { controlID = this.presentButton.controlID }; control.meta["username"] = this.selectedUserImage.User.UserName; control.meta["useravatar"] = this.selectedUserImage.User.AvatarLink; control.meta["image"] = this.selectedUserImage.ImageData; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); this.SelectedImageGrid.DataContext = null; this.ShowButton.IsEnabled = false; } }
protected override async Task <bool> GameConnectedInternal() { InteractiveConnectedSceneGroupCollectionModel sceneGroups = await ChannelSession.Interactive.GetScenes(); if (sceneGroups != null) { this.scene = sceneGroups.scenes.FirstOrDefault(); if (this.scene != null) { this.sendButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("send")); this.presentButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("present")); if (this.sendButton != null && this.presentButton != null) { return(true); } } } return(false); }
private async void InteractiveClient_OnGiveInput(object sender, InteractiveGiveInputModel e) { this.InteractiveDataTextBlock.Text += "Input Received: " + e.participantID + " - " + e.input.eventType + " - " + e.input.controlID + Environment.NewLine; if (e.input.eventType.Equals("mousedown")) { this.ProcessVote(sender, e); if (e.transactionID != null) { InteractiveConnectedButtonControlModel button = this.buttons.FirstOrDefault(b => b.controlID.Equals(e.input.controlID)); if (button != null) { InteractiveConnectedSceneModel scene = this.scenes.FirstOrDefault(s => s.buttons.Contains(button)); if (scene != null) { button.cooldown = DateTimeHelper.DateTimeOffsetToUnixTimestamp(DateTimeOffset.Now.AddSeconds(10)); await this.interactiveClient.UpdateControls(scene, new List <InteractiveConnectedButtonControlModel>() { button }); this.InteractiveDataTextBlock.Text += "Sent 10 second cooldown to button: " + e.input.controlID + Environment.NewLine; } } await this.interactiveClient.CaptureSparkTransaction(e.transactionID); this.InteractiveDataTextBlock.Text += "Spark Transaction Captured: " + e.participantID + " - " + e.input.eventType + " - " + e.input.controlID + Environment.NewLine; } } }
protected override async Task <bool> GameConnectedInternal() { this.Dispatcher.Invoke(() => { this.MapComboBox.IsEnabled = false; this.MaxTimeTextBox.IsEnabled = false; this.SparkCostTextBox.IsEnabled = false; this.TimerStackPanel.Visibility = Visibility.Hidden; this.DropLocationStackPanel.Visibility = Visibility.Hidden; this.WinnerStackPanel.Visibility = Visibility.Hidden; this.TimerTextBlock.Text = string.Empty; this.DropLocationTextBlock.Text = string.Empty; this.WinnerAvatar.SetSize(80); this.WinnerTextBlock.Text = string.Empty; }); this.SaveSettings(); InteractiveConnectedSceneGroupCollectionModel sceneGroups = await ChannelSession.Interactive.GetScenes(); if (sceneGroups != null) { this.scene = sceneGroups.scenes.FirstOrDefault(); if (this.scene != null) { this.positionButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("position")); this.winnerButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("winner")); } } if (this.positionButton == null || this.winnerButton == null) { Logger.Log("Could not get position or winner buttons"); return(false); } if (this.sparkCost > 0) { this.positionButton.cost = this.sparkCost; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { this.positionButton }); await ChannelSession.Interactive.RefreshCachedControls(); } if (this.dropMapType == DropMapTypeEnum.PUBG) { JObject settings = this.GetCustomSettings(); settings[MapSelectionSettingProperty] = this.MapComboBox.SelectedIndex; this.SaveCustomSettings(settings); PUBGMap map = (PUBGMap)this.MapComboBox.SelectedItem; InteractiveConnectedButtonControlModel control = new InteractiveConnectedButtonControlModel() { controlID = this.positionButton.controlID }; control.meta["map"] = map.Map; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); } this.userAvatars.Clear(); this.userPoints.Clear(); if (this.canvas != null) { this.canvas.Children.Clear(); } #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { if (this.scene != null && this.winnerButton != null) { InteractiveConnectedButtonControlModel control = null; for (int i = 0; i < (maxTime + 1); i++) { await Task.Delay(1000); int timeLeft = maxTime - i; this.Dispatcher.Invoke(() => { this.UpdateTimerUI(timeLeft); }); control = new InteractiveConnectedButtonControlModel() { controlID = this.winnerButton.controlID }; control.meta["timeleft"] = timeLeft; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); } if (this.userPoints.Count > 0) { var users = this.userPoints.Keys.ToList(); int index = RandomHelper.GenerateRandomNumber(users.Count); uint winner = users[index]; Point point = this.userPoints[winner]; UserProfileAvatarControl avatar = this.userAvatars[winner]; UserModel user = await ChannelSession.Connection.GetUser(winner); string username = (user != null) ? user.username : "******"; string location = this.ComputeLocation(point); this.Dispatcher.InvokeAsync(async() => { await this.UpdateWinnerUI(winner, username, location); this.canvas.Children.Clear(); this.canvas.Children.Add(avatar); }); control = new InteractiveConnectedButtonControlModel() { controlID = this.winnerButton.controlID }; control.meta["userID"] = winner; control.meta["username"] = username; control.meta["location"] = location; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); await ChannelSession.Chat.SendMessage(string.Format("Winner: @{0}, Drop Location: {1}", username, location)); } } }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(await base.GameConnectedInternal()); }
public InteractiveConnectedButtonCommand(InteractiveConnectedSceneModel scene, InteractiveConnectedButtonControlModel button, InteractiveCommand command) : base(scene, button, command) { this.ButtonCommand.OnCommandStart += ButtonCommand_OnCommandStart; }
protected override async Task GameConnectedInternal() { this.SaveDropMapSettings(); InteractiveConnectedSceneGroupCollectionModel sceneGroups = await ChannelSession.Interactive.GetScenes(); if (sceneGroups != null) { this.scene = sceneGroups.scenes.FirstOrDefault(); if (this.scene != null) { this.positionButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("position")); this.winnerButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("winner")); } } if (this.positionButton == null || this.winnerButton == null) { throw new InvalidOperationException("Could not get position or winner buttons"); } if (this.sparkCost > 0) { this.positionButton.cost = this.sparkCost; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { this.positionButton }); await ChannelSession.Interactive.RefreshCachedControls(); } this.userAvatars.Clear(); this.userPoints.Clear(); this.canvas.Children.Clear(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { if (this.scene != null && this.winnerButton != null) { InteractiveConnectedButtonControlModel control = null; for (int i = 0; i < (maxTime + 1); i++) { await Task.Delay(1000); int timeLeft = maxTime - i; this.Dispatcher.Invoke(() => { this.UpdateTimerUI(timeLeft); }); control = new InteractiveConnectedButtonControlModel() { controlID = this.winnerButton.controlID }; control.meta["timeleft"] = timeLeft; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); } if (this.userPoints.Count > 0) { var users = this.userPoints.Keys.ToList(); int index = RandomHelper.GenerateRandomNumber(users.Count); uint winner = users[index]; Point point = this.userPoints[winner]; UserProfileAvatarControl avatar = this.userAvatars[winner]; UserModel user = await ChannelSession.Connection.GetUser(winner); string username = (user != null) ? user.username : "******"; string location = this.ComputeLocation(point); this.Dispatcher.InvokeAsync(async() => { await this.UpdateWinnerUI(winner, username, location); this.canvas.Children.Clear(); this.canvas.Children.Add(avatar); }); control = new InteractiveConnectedButtonControlModel() { controlID = this.winnerButton.controlID }; control.meta["userID"] = winner; control.meta["username"] = username; control.meta["location"] = location; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); await ChannelSession.Chat.SendMessage(string.Format("Winner: @{0}, Drop Location: {1}", username, location)); } } }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed }
public InteractiveConnectedButtonCommand(InteractiveConnectedSceneModel scene, InteractiveConnectedButtonControlModel button, InteractiveCommand command) : base(scene, button, command) { }
protected override async Task <bool> GameConnectedInternal() { InteractiveConnectedSceneGroupCollectionModel sceneGroups = await ChannelSession.Interactive.GetScenes(); if (sceneGroups != null) { this.scene = sceneGroups.scenes.FirstOrDefault(); if (this.scene != null) { this.gameStartButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("gameStart")); this.timeLeftButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("timeLeft")); this.flyHitButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("flyHit")); this.gameEndButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("gameEnd")); this.resultsButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("results")); if (this.gameStartButton != null && this.timeLeftButton != null && this.flyHitButton != null && this.gameEndButton != null && this.resultsButton != null) { this.WinnerGrid.DataContext = null; this.userCollection.Clear(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { try { userTotals.Clear(); winner = null; this.gameStartButton.meta["timeLeft"] = this.maxTime; await ChannelSession.Interactive.UpdateControls(scene, new List <InteractiveControlModel>() { this.gameStartButton }); for (int i = this.maxTime; i >= 0; i--) { this.timeLeftButton.meta["timeLeft"] = i; await ChannelSession.Interactive.UpdateControls(scene, new List <InteractiveControlModel>() { this.timeLeftButton }); await this.Dispatcher.InvokeAsync(() => { this.TimeLeftTextBlock.Text = i.ToString(); }); await Task.Delay(1000); } await Task.Delay(2000); winner = userTotals.Values.OrderBy(user => user.Total).FirstOrDefault(); if (winner != null && winner.User.GetParticipantModels().Count() > 0) { this.resultsButton.meta["winner"] = JObject.FromObject(winner.User.GetParticipantModels().FirstOrDefault()); await ChannelSession.Interactive.UpdateControls(scene, new List <InteractiveControlModel>() { this.resultsButton }); this.Dispatcher.InvokeAsync(() => { this.WinnerGrid.DataContext = this.winner; }); ChannelSession.Chat.SendMessage(string.Format("Winner: @{0}, Total Flies: {1}", winner.User.UserName, winner.Total)); } } catch (Exception ex) { Logger.Log(ex.ToString()); } }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(true); } } } return(false); }
public static void Main(string[] args) { Task.Run(async() => { List <OAuthClientScopeEnum> scopes = new List <OAuthClientScopeEnum>() { OAuthClientScopeEnum.channel__details__self, OAuthClientScopeEnum.channel__update__self, OAuthClientScopeEnum.interactive__manage__self, OAuthClientScopeEnum.interactive__robot__self, OAuthClientScopeEnum.user__details__self, OAuthClientScopeEnum.user__log__self, OAuthClientScopeEnum.user__notification__self, OAuthClientScopeEnum.user__update__self, }; MixerConnection connection = await MixerConnection.ConnectViaLocalhostOAuthBrowser("ba911f5e09c2d3a87b715e0371f1e9ba96d476b5a7b26ba0", scopes); if (connection != null) { System.Console.WriteLine("Mixer connection successful!"); UserModel user = await connection.Users.GetCurrentUser(); ExpandedChannelModel channel = await connection.Channels.GetChannel(user.username); System.Console.WriteLine(string.Format("Logged in as: {0}", user.username)); InteractiveGameVersionModel version = await connection.Interactive.GetInteractiveGameVersion(Program.GameVersionID); if (version != null) { InteractiveGameModel game = await connection.Interactive.GetInteractiveGame(version.gameId); if (game != null) { System.Console.WriteLine(); System.Console.WriteLine(string.Format("Connecting to channel interactive using game {0}...", game.name)); Program.interactiveClient = await InteractiveClient.CreateFromChannel(connection, channel, game, version, Program.GameShareCode); Program.interactiveClient.OnDisconnectOccurred += InteractiveClient_OnDisconnectOccurred; Program.interactiveClient.OnParticipantJoin += InteractiveClient_OnParticipantJoin; Program.interactiveClient.OnParticipantLeave += InteractiveClient_OnParticipantLeave; Program.interactiveClient.OnGiveInput += InteractiveClient_OnGiveInput; if (await Program.interactiveClient.Connect() && await Program.interactiveClient.Ready()) { InteractiveConnectedSceneGroupCollectionModel scenes = await Program.interactiveClient.GetScenes(); if (scenes != null) { InteractiveConnectedSceneModel scene = scenes.scenes.First(); InteractiveConnectedButtonControlModel gameStartButton = scene.buttons.First(b => b.controlID.Equals("gameStart")); InteractiveConnectedButtonControlModel timeLeftButton = scene.buttons.First(b => b.controlID.Equals("timeLeft")); InteractiveConnectedButtonControlModel flyHitButton = scene.buttons.First(b => b.controlID.Equals("flyHit")); InteractiveConnectedButtonControlModel gameEndButton = scene.buttons.First(b => b.controlID.Equals("gameEnd")); InteractiveConnectedButtonControlModel resultsButton = scene.buttons.First(b => b.controlID.Equals("results")); InteractiveParticipantCollectionModel participantCollection = await Program.interactiveClient.GetAllParticipants(DateTimeOffset.Now.Subtract(TimeSpan.FromMinutes(5))); if (participantCollection != null && participantCollection.participants != null) { foreach (InteractiveParticipantModel participant in participantCollection.participants) { Program.participants[participant.sessionID] = participant; } } while (true) { try { System.Console.WriteLine("Starting new game..."); userTotals.Clear(); gameStartButton.meta["timeLeft"] = 30; await Program.interactiveClient.UpdateControls(scene, new List <InteractiveControlModel>() { gameStartButton }); for (int i = 30; i >= 0; i--) { timeLeftButton.meta["timeLeft"] = i; await Program.interactiveClient.UpdateControls(scene, new List <InteractiveControlModel>() { timeLeftButton }); await Task.Delay(1000); } await Task.Delay(2000); System.Console.WriteLine("Game completed, selecting winner..."); InteractiveParticipantModel winner = null; foreach (var kvp in userTotals.OrderByDescending(kvp => kvp.Value)) { if (Program.participants.TryGetValue(kvp.Key, out winner)) { resultsButton.meta["winner"] = JObject.FromObject(winner); await Program.interactiveClient.UpdateControls(scene, new List <InteractiveControlModel>() { resultsButton }); break; } } if (winner != null) { System.Console.WriteLine("Winner: " + winner.username); } await Task.Delay(5000); } catch (Exception ex) { System.Console.WriteLine(ex.ToString()); } } } } } } } }).Wait(); }