@@ -73,7 +73,7 @@ public function loadGame($gameId)
7373 }
7474
7575 // If game just started and no team is selected, select Team Illuminate
76- if ($ this ->game ->status === 'main_game ' && ! $ this ->currentTeam ) {
76+ if ($ this ->game ->status === 'main_game ' && !$ this ->currentTeam ) {
7777 $ teamIlluminate = $ this ->teams ->where ('name ' , 'Team Illuminate ' )->first ();
7878 if ($ teamIlluminate ) {
7979 $ this ->selectCurrentTeam ($ teamIlluminate ->id );
@@ -122,7 +122,7 @@ public function triggerBuzzer($teamId)
122122 {
123123 $ team = Team::find ($ teamId );
124124
125- if (! $ team ) {
125+ if (!$ team ) {
126126 return ;
127127 }
128128
@@ -183,7 +183,7 @@ public function setDailyDoubleWager($amount)
183183
184184 private function getMaximumWager ()
185185 {
186- if (! $ this ->currentTeam ) {
186+ if (!$ this ->currentTeam ) {
187187 return 400 ; // Default max if no team selected
188188 }
189189
@@ -202,7 +202,7 @@ private function getMaximumWager()
202202
203203 private function calculateWagerOptions ()
204204 {
205- if (! $ this ->currentTeam ) {
205+ if (!$ this ->currentTeam ) {
206206 $ this ->wagerOptions = [];
207207
208208 return ;
@@ -218,13 +218,13 @@ private function calculateWagerOptions()
218218 $ increments = [200 , 300 , 400 , 500 , 600 , 800 , 1000 , 1200 , 1500 , 2000 ];
219219
220220 foreach ($ increments as $ amount ) {
221- if ($ amount <= $ maxWager && ! in_array ($ amount , $ options )) {
221+ if ($ amount <= $ maxWager && !in_array ($ amount , $ options )) {
222222 $ options [] = $ amount ;
223223 }
224224 }
225225
226226 // If team score is positive and not already in options, add it as "True Daily Double"
227- if ($ this ->currentTeam ->score > 0 && ! in_array ($ this ->currentTeam ->score , $ options )) {
227+ if ($ this ->currentTeam ->score > 0 && !in_array ($ this ->currentTeam ->score , $ options )) {
228228 $ options [] = $ this ->currentTeam ->score ;
229229 }
230230
@@ -238,7 +238,7 @@ public function markCorrect($teamId = null)
238238 {
239239 $ team = $ teamId ? Team::find ($ teamId ) : $ this ->currentTeam ;
240240
241- if (! $ team || ! $ this ->selectedClue ) {
241+ if (!$ team || !$ this ->selectedClue ) {
242242 return ;
243243 }
244244
@@ -302,7 +302,7 @@ public function markIncorrect($teamId = null)
302302 {
303303 $ team = $ teamId ? Team::find ($ teamId ) : $ this ->currentTeam ;
304304
305- if (! $ team || ! $ this ->selectedClue ) {
305+ if (!$ team || !$ this ->selectedClue ) {
306306 return ;
307307 }
308308
@@ -319,7 +319,7 @@ public function markIncorrect($teamId = null)
319319 }
320320
321321 // Clear current team to open buzzers for others (unless Daily Double)
322- if (! $ this ->selectedClue ->is_daily_double ) {
322+ if (!$ this ->selectedClue ->is_daily_double ) {
323323 $ this ->currentTeam = null ;
324324 $ this ->game ->current_team_id = null ;
325325 $ this ->game ->save ();
@@ -384,7 +384,7 @@ public function closeClue()
384384 public function adjustScore ($ teamId , $ amount )
385385 {
386386 $ team = Team::find ($ teamId );
387- if (! $ team ) {
387+ if (!$ team ) {
388388 return ;
389389 }
390390
@@ -409,7 +409,7 @@ public function startLightningRound()
409409 $ gameService = app (GameService::class);
410410 $ gameService ->transitionToLightningRound ($ this ->game ->id );
411411
412- $ this ->game -> refresh ();
412+ $ this ->currentTeam = null ; // Clear current team
413413
414414 // Broadcast event to tell game board to navigate to lightning round
415415 broadcast (new GameStateChanged ($ this ->game ->id , 'lightning-round-started ' ));
@@ -457,16 +457,7 @@ public function markLightningCorrect()
457457 ));
458458
459459 // Get next question
460- $ nextQuestion = $ this ->game ->lightningQuestions
461- ->where ('is_answered ' , false )
462- ->sortBy ('order_position ' )
463- ->first ();
464-
465- if ($ nextQuestion ) {
466- $ nextQuestion ->update (['is_current ' => true ]);
467- // Broadcast that we've moved to the next question
468- broadcast (new GameStateChanged ($ this ->game ->id , 'lightning-next-question ' ));
469- }
460+ $ this ->nextLightningQuestion ();
470461 }
471462 }
472463
@@ -511,27 +502,11 @@ public function markLightningIncorrect()
511502 }
512503 }
513504
514- public function skipLightningQuestion ()
515- {
516- $ this ->dispatch ('lightning-skip-question ' )->to (LightningRound::class);
517- $ this ->currentTeam = null ; // Reset when skipping
518- $ this ->game ->current_team_id = null ;
519- $ this ->game ->save ();
520- }
521-
522- public function nextLightningQuestion ()
523- {
524- $ this ->dispatch ('lightning-next-question ' )->to (LightningRound::class);
525- $ this ->currentTeam = null ; // Reset for next question
526- $ this ->game ->current_team_id = null ;
527- $ this ->game ->save ();
528- }
529-
530505 // Listen for buzzer events from main display
531506 #[On('buzzer-webhook-received ' )]
532507 public function handleBuzzerWebhook ($ teamId )
533508 {
534- if ($ this ->showClueModal && ! $ this ->currentTeam && ! $ this ->selectedClue ->is_daily_double ) {
509+ if ($ this ->showClueModal && !$ this ->currentTeam && !$ this ->selectedClue ->is_daily_double ) {
535510 $ this ->currentTeam = Team::find ($ teamId );
536511 }
537512 }
@@ -551,7 +526,7 @@ public function handleBuzzerPressed($teamId)
551526 public function handleGameStateChanged ($ state , $ data = [])
552527 {
553528 // Handle team selection events from both manual triggers and buzzer API
554- if (in_array ($ state , ['team-selected ' , 'buzzer-pressed ' ]) && isset ($ data ['teamId ' ])) {
529+ if (in_array ($ state , ['team-selected ' , 'buzzer-pressed ' , ' lightning-round-started ' ]) && isset ($ data ['teamId ' ])) {
555530 $ this ->currentTeam = Team::find ($ data ['teamId ' ]);
556531 $ this ->game ->current_team_id = $ data ['teamId ' ];
557532 $ this ->refreshGame ();
@@ -582,4 +557,31 @@ public function render()
582557 return view ('livewire.host-control ' )
583558 ->layout ('layouts.game ' );
584559 }
560+
561+ /**
562+ * @return void
563+ */
564+ public function nextLightningQuestion (): void
565+ {
566+ $ nextQuestion = $ this ->game ->lightningQuestions
567+ ->where ('is_answered ' , false )
568+ ->sortBy ('order_position ' )
569+ ->first ();
570+
571+ if ($ nextQuestion ) {
572+ $ nextQuestion ->update (['is_current ' => true ]);
573+ // Broadcast that we've moved to the next question
574+ broadcast (new GameStateChanged ($ this ->game ->id , 'lightning-next-question ' ));
575+ } else {
576+ // Lightning round complete
577+ $ this ->game ->update (['status ' => 'finished ' , 'current_team_id ' => null ]);
578+ $ this ->game ->refresh ();
579+
580+ // Dispatch to browser for redirect - this will trigger the JavaScript listener
581+ $ this ->dispatch ('lightning-round-complete ' );
582+
583+ // Also broadcast to all clients
584+ broadcast (new GameStateChanged ($ this ->game ->id , 'lightning-round-complete ' , []));
585+ }
586+ }
585587}
0 commit comments