22
33namespace App \Livewire ;
44
5+ use App \Events \BuzzerPressed ;
56use App \Events \ClueRevealed ;
67use App \Events \DailyDoubleTriggered ;
78use App \Events \GameStateChanged ;
1011use App \Models \Game ;
1112use App \Models \Team ;
1213use App \Services \BuzzerService ;
14+ use App \Services \GameService ;
1315use App \Services \ScoringService ;
1416use Livewire \Attributes \On ;
1517use Livewire \Component ;
@@ -26,6 +28,9 @@ class HostControl extends Component
2628 public ?Team $ currentTeam = null ;
2729
2830 public $ teams = [];
31+
32+ // Lightning Round state
33+ public ?Team $ lightningAnsweringTeam = null ;
2934
3035 // Daily Double
3136 public bool $ showDailyDoubleWager = false ;
@@ -120,28 +125,44 @@ public function selectCurrentTeam($teamId)
120125 public function triggerBuzzer ($ teamId )
121126 {
122127 $ team = Team::find ($ teamId );
123-
124- if (!$ team ) {
128+
129+ if (! $ team ) {
125130 return ;
126131 }
127132
128- // Set the team as active
129- $ this ->currentTeam = $ team ;
130- $ this -> game -> current_team_id = $ teamId ;
131- $ this ->game ->save ( );
133+ // Check if we're in lightning round
134+ if ( $ this ->game -> status === ' lightning_round ' ) {
135+ // For lightning round, dispatch the buzzer event to the lightning round component
136+ broadcast ( new GameStateChanged ( $ this ->game ->id , ' buzzer-pressed ' , [ ' teamId ' => $ teamId ]) );
132137
133- // Broadcast team selection to all clients
134- broadcast (new GameStateChanged ( $ this -> game -> id , ' team-selected ' , [ ' teamId ' => $ teamId ] ));
138+ // Also broadcast the buzzer sound
139+ broadcast (new BuzzerPressed ( $ team ));
135140
136- // Broadcast buzzer event to trigger sound on game board
137- broadcast (new \App \Events \BuzzerPressed ($ team ));
138-
139- Log::info ('Buzzer triggered manually from host control ' , [
140- 'game_id ' => $ this ->game ->id ,
141- 'team_id ' => $ teamId ,
142- 'team_name ' => $ team ->name ,
143- 'set_as_active ' => true ,
144- ]);
141+ Log::info ('Lightning round buzzer triggered manually from host control ' , [
142+ 'game_id ' => $ this ->game ->id ,
143+ 'team_id ' => $ teamId ,
144+ 'team_name ' => $ team ->name ,
145+ ]);
146+ } else {
147+ // Regular game mode
148+ // Set the team as active
149+ $ this ->currentTeam = $ team ;
150+ $ this ->game ->current_team_id = $ teamId ;
151+ $ this ->game ->save ();
152+
153+ // Broadcast team selection to all clients
154+ broadcast (new GameStateChanged ($ this ->game ->id , 'team-selected ' , ['teamId ' => $ teamId ]));
155+
156+ // Broadcast buzzer event to trigger sound on game board
157+ broadcast (new BuzzerPressed ($ team ));
158+
159+ Log::info ('Buzzer triggered manually from host control ' , [
160+ 'game_id ' => $ this ->game ->id ,
161+ 'team_id ' => $ teamId ,
162+ 'team_name ' => $ team ->name ,
163+ 'set_as_active ' => true ,
164+ ]);
165+ }
145166 }
146167
147168 // Clue Control
@@ -241,27 +262,7 @@ private function calculateWagerOptions()
241262 // Sort options
242263 sort ($ options );
243264
244- // Limit to 8 options for UI consistency
245- if (count ($ options ) > 8 ) {
246- // Keep first few, some middle values, and the max
247- $ filtered = [];
248- $ filtered [] = $ options [0 ]; // minimum
249-
250- // Add evenly distributed values
251- $ step = (count ($ options ) - 2 ) / 6 ; // We want 6 middle values
252- for ($ i = 1 ; $ i <= 6 ; $ i ++) {
253- $ index = min (round ($ i * $ step ), count ($ options ) - 2 );
254- if (! in_array ($ options [$ index ], $ filtered )) {
255- $ filtered [] = $ options [$ index ];
256- }
257- }
258-
259- $ filtered [] = $ options [count ($ options ) - 1 ]; // maximum
260-
261- $ this ->wagerOptions = $ filtered ;
262- } else {
263- $ this ->wagerOptions = $ options ;
264- }
265+ $ this ->wagerOptions = $ options ;
265266 }
266267
267268 public function markCorrect ($ teamId = null )
@@ -435,11 +436,42 @@ public function startLightningRound()
435436 return ;
436437 }
437438
438- $ this ->game ->update (['status ' => 'lightning_round ' ]);
439+ // Transition to lightning round
440+ $ gameService = app (GameService::class);
441+ $ gameService ->transitionToLightningRound ($ this ->game ->id );
442+
439443 $ this ->game ->refresh ();
440444
441- // Redirect to lightning round
442- return redirect ()->route ('game.lightning ' , ['gameId ' => $ this ->game ->id ]);
445+ // Broadcast event to tell game board to navigate to lightning round
446+ broadcast (new GameStateChanged ($ this ->game ->id , 'lightning-round-started ' ));
447+
448+ // Host stays on the control page, no redirect
449+ $ this ->refreshGame ();
450+ }
451+
452+ // Lightning Round Question Controls
453+ public function markLightningCorrect ()
454+ {
455+ $ this ->dispatch ('lightning-mark-correct ' )->to (LightningRound::class);
456+ $ this ->lightningAnsweringTeam = null ; // Reset after marking
457+ }
458+
459+ public function markLightningIncorrect ()
460+ {
461+ $ this ->dispatch ('lightning-mark-incorrect ' )->to (LightningRound::class);
462+ // Don't reset here as another team might buzz in
463+ }
464+
465+ public function skipLightningQuestion ()
466+ {
467+ $ this ->dispatch ('lightning-skip-question ' )->to (LightningRound::class);
468+ $ this ->lightningAnsweringTeam = null ; // Reset when skipping
469+ }
470+
471+ public function nextLightningQuestion ()
472+ {
473+ $ this ->dispatch ('lightning-next-question ' )->to (LightningRound::class);
474+ $ this ->lightningAnsweringTeam = null ; // Reset for next question
443475 }
444476
445477 // Listen for buzzer events from main display
@@ -450,6 +482,15 @@ public function handleBuzzerWebhook($teamId)
450482 $ this ->currentTeam = Team::find ($ teamId );
451483 }
452484 }
485+
486+ #[On('buzzer-pressed ' )]
487+ public function handleBuzzerPressed ($ teamId )
488+ {
489+ // Track which team buzzed in during lightning round
490+ if ($ this ->game ->status === 'lightning_round ' ) {
491+ $ this ->lightningAnsweringTeam = Team::find ($ teamId );
492+ }
493+ }
453494
454495 private function refreshGame ()
455496 {
0 commit comments