2023-04-12 22:34:15 +00:00
using System.Collections ;
using System.Collections.Generic ;
using UnityEngine ;
using HeavenStudio.Util ;
2023-10-29 19:44:47 +00:00
using HeavenStudio.InputSystem ;
2023-04-12 22:34:15 +00:00
using System.Diagnostics.CodeAnalysis ;
namespace HeavenStudio.Games.Loaders
{
using static Minigames ;
public static class AgbQuizShowLoader
{
public static Minigame AddGame ( EventCaller eventCaller )
{
2023-04-23 20:17:21 +00:00
return new Minigame ( "quizShow" , "Quiz Show" , "c96efa" , false , false , new List < GameAction > ( )
2023-04-12 22:34:15 +00:00
{
new GameAction ( "intervalStart" , "Start Interval" )
{
2023-07-19 01:09:02 +00:00
preFunction = delegate { var e = eventCaller . currentEntity ; QuizShow . PreInterval ( e . beat , e . length ,
e [ "auto" ] , e [ "sound" ] , e [ "con" ] , e [ "visual" ] , e [ "audio" ] ) ; } ,
2023-09-08 14:27:07 +00:00
defaultLength = 7f ,
2023-07-19 01:09:02 +00:00
resizable = true ,
parameters = new List < Param > ( )
{
2024-01-15 02:04:10 +00:00
new Param ( "auto" , true , "Auto Pass Turn" , "Toggle if the turn should be passed automatically at the end of the start interval." , new List < Param . CollapseParam > ( )
2023-09-08 14:27:07 +00:00
{
2023-10-27 20:19:11 +00:00
new Param . CollapseParam ( ( x , _ ) = > ( bool ) x , new string [ ] { "sound" , "con" , "visual" , "audio" } )
2023-09-08 14:27:07 +00:00
} ) ,
2024-01-15 02:04:10 +00:00
new Param ( "sound" , true , "Time-Up Sound" , "Toggle if the time-up sound should play at the end of the interval." ) ,
new Param ( "con" , false , "Consecutive" , "Toggle if everything that happens at the end of the interval should be disabled. This should only be used when you're having two intervals back-to-back." ) ,
new Param ( "visual" , true , "Stopwatch (Visual)" , "Toggle if the stopwatch should visually appear." ) ,
new Param ( "audio" , QuizShow . ClockAudio . Both , "Stopwatch (Audio)" , "Toggle if the sounds of the stopwatch should play." )
2023-07-19 01:09:02 +00:00
}
2023-04-12 22:34:15 +00:00
} ,
2023-04-15 13:42:04 +00:00
new GameAction ( "prepare" , "Prepare Host Hands" )
{
function = delegate { QuizShow . instance . HostPrepareHands ( ) ; }
} ,
2023-04-12 22:34:15 +00:00
new GameAction ( "dPad" , "DPad Press" )
{
defaultLength = 0.5f
} ,
new GameAction ( "aButton" , "A Button Press" )
{
defaultLength = 0.5f
} ,
new GameAction ( "randomPresses" , "Random Presses" )
{
parameters = new List < Param > ( )
{
2024-01-15 02:04:10 +00:00
new Param ( "min" , new EntityTypes . Integer ( 0 , 666 , 0 ) , "Minimum" , "Set the minimum number of presses this event will do." ) ,
new Param ( "max" , new EntityTypes . Integer ( 0 , 666 , 1 ) , "Maximum" , "Set the maximum number of presses this event will do." ) ,
new Param ( "random" , QuizShow . WhichButtonRandom . Random , "Buttons" , "Set the buttons to be pressed randomly." ) ,
new Param ( "con" , true , "Consecutive Presses" , "Toggle if the presses will be consecutive? This means that if the first press doesn't trigger, the ones proceeding will not either." )
2023-04-12 22:34:15 +00:00
} ,
resizable = true
} ,
new GameAction ( "passTurn" , "Pass Turn" )
{
2023-07-19 01:09:02 +00:00
preFunction = delegate { var e = eventCaller . currentEntity ; QuizShow . PrePassTurn ( e . beat , e [ "sound" ] , e [ "con" ] , e [ "visual" ] , e [ "audio" ] ) ; } ,
2023-04-12 22:34:15 +00:00
parameters = new List < Param > ( )
{
2024-01-15 02:04:10 +00:00
new Param ( "sound" , true , "Time-Up Sound" , "Toggle if the time-up sound should play at the end of the interval." ) ,
new Param ( "con" , false , "Consecutive" , "Toggle if everything that happens at the end of the interval should be disabled. This should only be used when you're having two intervals back-to-back." ) ,
new Param ( "visual" , true , "Stopwatch (Visual)" , "Toggle if the stopwatch should visually appear." ) ,
new Param ( "audio" , QuizShow . ClockAudio . Both , "Stopwatch (Audio)" , "Toggle if the sounds of the stopwatch should play." )
2023-09-08 14:27:07 +00:00
} ,
resizable = true
2023-04-12 22:34:15 +00:00
} ,
new GameAction ( "revealAnswer" , "Reveal Answer" )
{
function = delegate { var e = eventCaller . currentEntity ; QuizShow . instance . RevealAnswer ( e . beat , e . length ) ; } ,
defaultLength = 4f ,
resizable = true
} ,
new GameAction ( "answerReaction" , "Answer Reaction" )
{
2023-04-15 13:42:04 +00:00
function = delegate { var e = eventCaller . currentEntity ; QuizShow . instance . AnswerReaction ( e [ "audience" ] , e [ "jingle" ] , e [ "reveal" ] ) ; } ,
2023-04-12 22:34:15 +00:00
parameters = new List < Param > ( )
{
2024-01-15 02:04:10 +00:00
new Param ( "audience" , true , "Audience Reaction" , "Toggle if there should be an audience reaction.." ) ,
new Param ( "jingle" , false , "Jingle" , "Toggle if the quiz show jingle should." ) ,
new Param ( "reveal" , false , "Instant" , "Toggle if the answer should be revealed insantly when this event starts." )
2023-04-12 22:34:15 +00:00
}
} ,
2024-01-15 02:04:10 +00:00
new GameAction ( "changeStage" , "Change Expression" )
2023-04-12 22:34:15 +00:00
{
function = delegate { QuizShow . instance . ChangeStage ( eventCaller . currentEntity [ "value" ] ) ; } ,
defaultLength = 0.5f ,
parameters = new List < Param > ( )
{
2024-01-15 02:04:10 +00:00
new Param ( "value" , QuizShow . HeadStage . Stage1 , "Stage" , "Set the current stage of the expressions." )
2023-04-12 22:34:15 +00:00
}
} ,
new GameAction ( "countMod" , "Count Modifier" )
{
function = delegate { QuizShow . instance . CountModifier ( eventCaller . currentEntity [ "value" ] ) ; } ,
defaultLength = 0.5f ,
parameters = new List < Param > ( )
{
2024-01-15 02:04:10 +00:00
new Param ( "value" , true , "Auto Reset Count" , "Toggle if the contestant's counter will reset to 0 each time it hits 100 instead of exploding." )
2023-04-12 22:34:15 +00:00
}
} ,
new GameAction ( "forceExplode" , "Force Explode" )
{
function = delegate { QuizShow . instance . ForceExplode ( eventCaller . currentEntity [ "value" ] ) ; } ,
defaultLength = 0.5f ,
parameters = new List < Param > ( )
{
2024-01-15 02:04:10 +00:00
new Param ( "value" , QuizShow . ShouldExplode . Contestant , "Target" , "Set the object to explode." )
2023-04-12 22:34:15 +00:00
}
}
2023-05-28 17:34:44 +00:00
} ,
new List < string > ( ) { "agb" , "repeat" } ,
"agbquiz" , "en" ,
2024-03-29 02:35:07 +00:00
new List < string > ( ) { } ,
chronologicalSortKey : 19
2023-05-28 17:34:44 +00:00
) ;
2023-04-12 22:34:15 +00:00
}
}
}
namespace HeavenStudio.Games
{
2023-07-19 01:09:02 +00:00
using Jukebox ;
using Scripts_QuizShow ;
2023-04-12 22:34:15 +00:00
public class QuizShow : Minigame
{
2023-04-26 12:43:35 +00:00
public enum ClockAudio
{
Both ,
Start ,
End ,
Neither
}
2023-04-12 22:34:15 +00:00
public enum HeadStage
{
Stage0 = 0 ,
Stage1 = 1 ,
Stage2 = 2 ,
Stage3 = 3 ,
Stage4 = 4 ,
}
2023-04-15 13:42:04 +00:00
public enum WhichButtonRandom
{
Random = 0 ,
DpadOnly = 1 ,
AOnly = 2 ,
AlternatingDpad = 3 ,
AlternatingA = 4
}
2023-04-12 22:34:15 +00:00
public enum ShouldExplode
{
Contestant = 0 ,
Host = 1 ,
Sign = 2
}
[Header("Components")]
[SerializeField] Animator contesteeLeftArmAnim ;
[SerializeField] Animator contesteeRightArmAnim ;
[SerializeField] Animator contesteeHead ;
[SerializeField] Animator hostLeftArmAnim ;
[SerializeField] Animator hostRightArmAnim ;
[SerializeField] Animator hostHead ;
[SerializeField] Animator signAnim ;
[SerializeField] Transform timerTransform ;
2023-07-19 01:09:02 +00:00
[SerializeField] QSTimer stopWatchRef ;
2023-04-12 22:34:15 +00:00
[SerializeField] GameObject blackOut ;
[SerializeField] SpriteRenderer firstDigitSr ;
[SerializeField] SpriteRenderer secondDigitSr ;
[SerializeField] SpriteRenderer hostFirstDigitSr ;
[SerializeField] SpriteRenderer hostSecondDigitSr ;
[SerializeField] SpriteRenderer contCounter ;
[SerializeField] SpriteRenderer hostCounter ;
[SerializeField] ParticleSystem contExplosion ;
[SerializeField] ParticleSystem hostExplosion ;
[SerializeField] ParticleSystem signExplosion ;
[Header("Properties")]
[SerializeField] List < Sprite > contestantNumberSprites = new List < Sprite > ( ) ;
[SerializeField] List < Sprite > hostNumberSprites = new List < Sprite > ( ) ;
[SerializeField] Sprite explodedCounter ;
bool shouldResetCount ;
bool doingConsectiveIntervals ;
int currentStage ;
bool shouldPrepareArms = true ;
bool contExploded ;
bool hostExploded ;
bool signExploded ;
int pressCount ;
int countToMatch ;
2023-07-19 01:09:02 +00:00
private double playerStartBeat = - 1 ;
private float playerLength ;
2023-04-12 22:34:15 +00:00
public static QuizShow instance ;
2023-07-19 01:09:02 +00:00
private struct RandomPress
2023-04-12 22:34:15 +00:00
{
2023-07-19 01:09:02 +00:00
public List < RiqEntity > randomPresses ;
public double beat ;
2023-04-12 22:34:15 +00:00
}
2023-07-19 01:09:02 +00:00
private List < RandomPress > randomPresses = new ( ) ;
2023-10-29 19:44:47 +00:00
const int IALeft = 0 ;
const int IARight = 1 ;
protected static bool IA_PadLeft ( out double dt )
{
return PlayerInput . GetPadDown ( InputController . ActionsPad . Up , out dt )
| | PlayerInput . GetPadDown ( InputController . ActionsPad . Down , out dt )
| | PlayerInput . GetPadDown ( InputController . ActionsPad . Left , out dt )
| | PlayerInput . GetPadDown ( InputController . ActionsPad . Right , out dt ) ;
}
protected static bool IA_TouchLeft ( out double dt )
{
return PlayerInput . GetTouchDown ( InputController . ActionsTouch . Left , out dt ) ;
}
protected static bool IA_PadRight ( out double dt )
{
return PlayerInput . GetPadDown ( InputController . ActionsPad . East , out dt ) ;
}
protected static bool IA_TouchRight ( out double dt )
{
return PlayerInput . GetTouchDown ( InputController . ActionsTouch . Right , out dt ) ;
}
public static PlayerInput . InputAction InputAction_Left =
new ( "AgbQuizLeft" , new int [ ] { IALeft , IALeft , IALeft } ,
IA_PadLeft , IA_TouchLeft , IA_BatonBasicPress ) ;
// Baton Style only has one button
public static PlayerInput . InputAction InputAction_Right =
new ( "AgbQuizRight" , new int [ ] { IARight , IARight , IAEmptyCat } ,
IA_PadRight , IA_TouchRight , IA_Empty ) ;
2023-04-12 22:34:15 +00:00
void Awake ( )
{
instance = this ;
}
2023-07-19 01:09:02 +00:00
public override void OnPlay ( double beat )
{
var allRandomEvents = EventCaller . GetAllInGameManagerList ( "quizShow" , new string [ ] { "randomPresses" } ) ;
foreach ( var randomEvent in allRandomEvents )
{
randomPresses . Add ( new RandomPress ( )
{
beat = randomEvent . beat ,
randomPresses = GetRandomPress ( randomEvent . beat , randomEvent . length ,
randomEvent [ "min" ] , randomEvent [ "max" ] , randomEvent [ "random" ] , randomEvent [ "con" ] )
} ) ;
}
}
2023-04-12 22:34:15 +00:00
void Update ( )
{
var cond = Conductor . instance ;
if ( cond . isPlaying & & ! cond . isPaused )
{
2023-07-19 01:09:02 +00:00
float normalizedBeat = cond . GetPositionFromBeat ( playerStartBeat , playerLength ) ;
if ( normalizedBeat > = 0f & & normalizedBeat < = 1f )
2023-04-12 22:34:15 +00:00
{
2023-10-29 19:44:47 +00:00
if ( PlayerInput . GetIsAction ( InputAction_Right ) )
2023-04-12 22:34:15 +00:00
{
ContesteePressButton ( false ) ;
}
2023-10-29 19:44:47 +00:00
if ( PlayerInput . GetIsAction ( InputAction_Left ) )
2023-04-12 22:34:15 +00:00
{
ContesteePressButton ( true ) ;
}
}
}
2023-07-19 01:09:02 +00:00
if ( passedTurns . Count > 0 )
{
foreach ( var pass in passedTurns )
{
PassTurnStandalone ( pass . beat , pass . timeUpSound , pass . consecutive , pass . visualClock , pass . audioClock ) ;
}
passedTurns . Clear ( ) ;
}
}
private List < RiqEntity > GetInputsBetweenBeat ( double beat , double endBeat )
{
List < RiqEntity > allEvents = new ( ) ;
List < RiqEntity > nonRandoms = EventCaller . GetAllInGameManagerList ( "quizShow" , new string [ ] { "dPad" , "aButton" } ) . FindAll ( x = > x . beat > = beat & & x . beat < endBeat ) ;
List < RiqEntity > randoms = new ( ) ;
foreach ( var rand in randomPresses )
{
if ( rand . beat > = beat & & rand . beat < endBeat )
{
randoms . AddRange ( rand . randomPresses ) ;
}
}
allEvents . AddRange ( nonRandoms ) ;
allEvents . AddRange ( randoms ) ;
return allEvents ;
}
private RiqEntity GetLastIntervalBeforeBeat ( double beat )
{
return EventCaller . GetAllInGameManagerList ( "quizShow" , new string [ ] { "intervalStart" } ) . FindLast ( x = > x . beat < = beat ) ;
2023-04-12 22:34:15 +00:00
}
public void CountModifier ( bool shouldReset )
{
shouldResetCount = shouldReset ;
}
public void ChangeStage ( int stage )
{
currentStage = stage ;
}
2023-07-19 01:09:02 +00:00
private List < RiqEntity > GetRandomPress ( double beat , float length , int min , int max , int whichButtons , bool consecutive )
2023-04-12 22:34:15 +00:00
{
2023-07-19 01:09:02 +00:00
if ( min > max ) return new ( ) ;
2023-04-12 22:34:15 +00:00
int pressAmount = UnityEngine . Random . Range ( min , max + 1 ) ;
2023-07-19 01:09:02 +00:00
if ( pressAmount < 1 ) return new ( ) ;
List < RiqEntity > buttonEntities = new ( ) ;
2023-04-26 12:43:35 +00:00
if ( consecutive )
2023-04-12 22:34:15 +00:00
{
2023-04-26 12:43:35 +00:00
for ( int i = 0 ; i < pressAmount ; i + + )
2023-04-15 13:42:04 +00:00
{
2023-04-26 12:43:35 +00:00
bool dpad = UnityEngine . Random . Range ( 0 , 2 ) = = 1 ;
switch ( whichButtons )
{
case ( int ) WhichButtonRandom . Random :
break ;
case ( int ) WhichButtonRandom . DpadOnly :
dpad = true ;
break ;
case ( int ) WhichButtonRandom . AOnly :
dpad = false ;
break ;
case ( int ) WhichButtonRandom . AlternatingDpad :
dpad = i % 2 = = 0 ;
break ;
case ( int ) WhichButtonRandom . AlternatingA :
dpad = i % 2 ! = 0 ;
break ;
}
2023-06-10 19:13:29 +00:00
double spawnBeat = beat + i * length ;
2023-07-19 01:09:02 +00:00
buttonEntities . Add ( new RiqEntity ( new RiqEntityData ( )
{
beat = spawnBeat ,
datamodel = dpad ? "dPad" : "aButton"
} ) ) ;
2023-04-15 13:42:04 +00:00
}
2023-04-12 22:34:15 +00:00
}
2023-04-26 12:43:35 +00:00
else
{
for ( int i = 0 ; i < max ; i + + )
{
if ( pressAmount = = 0 ) break ;
if ( UnityEngine . Random . Range ( 0 , 2 ) = = 1 & & Mathf . Abs ( i - max ) ! = pressAmount ) continue ;
bool dpad = UnityEngine . Random . Range ( 0 , 2 ) = = 1 ;
switch ( whichButtons )
{
case ( int ) WhichButtonRandom . Random :
break ;
case ( int ) WhichButtonRandom . DpadOnly :
dpad = true ;
break ;
case ( int ) WhichButtonRandom . AOnly :
dpad = false ;
break ;
case ( int ) WhichButtonRandom . AlternatingDpad :
dpad = i % 2 = = 0 ;
break ;
case ( int ) WhichButtonRandom . AlternatingA :
dpad = i % 2 ! = 0 ;
break ;
}
2023-06-10 19:13:29 +00:00
double spawnBeat = beat + i * length ;
2023-07-19 01:09:02 +00:00
buttonEntities . Add ( new RiqEntity ( new RiqEntityData ( )
{
beat = spawnBeat ,
datamodel = dpad ? "dPad" : "aButton"
} ) ) ;
2023-04-26 12:43:35 +00:00
pressAmount - - ;
}
}
2023-07-19 01:09:02 +00:00
return buttonEntities ;
2023-04-12 22:34:15 +00:00
}
2023-06-10 19:13:29 +00:00
public void HostPressButton ( double beat , bool dpad )
2023-04-12 22:34:15 +00:00
{
if ( currentStage = = 0 )
{
contesteeHead . Play ( "ContesteeHeadIdle" , - 1 , 0 ) ;
hostHead . Play ( "HostIdleHead" , - 1 , 0 ) ;
}
else
{
hostHead . DoScaledAnimationAsync ( "HostStage" + currentStage . ToString ( ) , 0.5f ) ;
}
2023-07-19 01:09:02 +00:00
SoundByte . PlayOneShotGame ( dpad ? "quizShow/hostDPad" : "quizShow/hostA" ) ;
2023-04-12 22:34:15 +00:00
if ( dpad )
{
hostRightArmAnim . DoScaledAnimationAsync ( "HostRightHit" , 0.5f ) ;
}
else
{
hostLeftArmAnim . DoScaledAnimationAsync ( "HostLeftHit" , 0.5f ) ;
}
}
2023-04-15 13:42:04 +00:00
public void HostPrepareHands ( )
2023-04-12 22:34:15 +00:00
{
2023-04-15 13:42:04 +00:00
instance . hostLeftArmAnim . DoScaledAnimationAsync ( "HostLeftPrepare" , 0.5f ) ;
instance . hostRightArmAnim . DoScaledAnimationAsync ( "HostPrepare" , 0.5f ) ;
2023-04-12 22:34:15 +00:00
}
2023-07-19 01:09:02 +00:00
public static void PreInterval ( double beat , float interval ,
bool autoPassTurn , bool timeUpSound , bool consecutive , bool visualClock , int audioClock )
2023-04-12 22:34:15 +00:00
{
2023-07-19 01:09:02 +00:00
if ( GameManager . instance . currentGame = = "quizShow" )
2023-04-12 22:34:15 +00:00
{
2023-07-19 01:09:02 +00:00
instance . StartInterval ( beat , interval , beat , autoPassTurn , timeUpSound , consecutive , visualClock , audioClock ) ;
}
else
{
queuedIntervals . Add ( new QueuedInterval ( )
2023-04-12 22:34:15 +00:00
{
2023-07-19 01:09:02 +00:00
beat = beat ,
interval = interval ,
autoPassTurn = autoPassTurn ,
timeUpSound = timeUpSound ,
consecutive = consecutive ,
visualClock = visualClock ,
audioClock = audioClock
} ) ;
}
}
private struct QueuedInterval
{
public double beat ;
public float interval ;
public bool autoPassTurn ;
public bool timeUpSound ;
public bool consecutive ;
public bool visualClock ;
public int audioClock ;
}
private static List < QueuedInterval > queuedIntervals = new ( ) ;
public override void OnGameSwitch ( double beat )
{
if ( queuedIntervals . Count > 0 )
{
foreach ( var interval in queuedIntervals )
{
StartInterval ( interval . beat , interval . interval , beat , interval . autoPassTurn ,
interval . timeUpSound , interval . consecutive , interval . visualClock , interval . audioClock ) ;
2023-04-12 22:34:15 +00:00
}
2023-07-19 01:09:02 +00:00
queuedIntervals . Clear ( ) ;
}
var allRandomEvents = EventCaller . GetAllInGameManagerList ( "quizShow" , new string [ ] { "randomPresses" } ) ;
foreach ( var randomEvent in allRandomEvents )
{
randomPresses . Add ( new RandomPress ( )
{
beat = randomEvent . beat ,
randomPresses = GetRandomPress ( randomEvent . beat , randomEvent . length ,
randomEvent [ "min" ] , randomEvent [ "max" ] , randomEvent [ "random" ] , randomEvent [ "con" ] )
} ) ;
2023-04-12 22:34:15 +00:00
}
}
2023-07-19 01:09:02 +00:00
private void StartInterval ( double beat , float interval ,
double gameSwitchBeat , bool autoPassTurn , bool timeUpSound , bool consecutive , bool visualClock , int audioClock )
{
List < BeatAction . Action > actions = new ( )
{
new BeatAction . Action ( beat , delegate
{
if ( shouldPrepareArms )
{
hostLeftArmAnim . DoNormalizedAnimation ( "HostLeftPrepare" , 1 ) ;
hostRightArmAnim . DoNormalizedAnimation ( "HostPrepare" , 1 ) ;
contesteeHead . Play ( "ContesteeHeadIdle" , 0 , 0 ) ;
}
if ( ! doingConsectiveIntervals ) pressCount = 0 ;
firstDigitSr . sprite = contestantNumberSprites [ 0 ] ;
secondDigitSr . sprite = contestantNumberSprites [ 0 ] ;
hostFirstDigitSr . sprite = hostNumberSprites [ 10 ] ;
hostSecondDigitSr . sprite = hostNumberSprites [ 10 ] ;
} )
} ;
var relevantInputs = GetInputsBetweenBeat ( beat , beat + interval ) ;
relevantInputs . Sort ( ( x , y ) = > x . beat . CompareTo ( y . beat ) ) ;
for ( int i = 0 ; i < relevantInputs . Count ; i + + )
{
var input = relevantInputs [ i ] ;
double inputBeat = input . beat ;
if ( inputBeat < gameSwitchBeat ) continue ;
bool isDpad = input . datamodel = = "quizShow/dPad" ;
bool isRandom = input . datamodel = = "quizShow/randomPresses" ;
actions . Add ( new BeatAction . Action ( inputBeat , delegate
{
HostPressButton ( inputBeat , isDpad ) ;
} ) ) ;
}
2023-09-11 22:28:04 +00:00
BeatAction . New ( this , actions ) ;
2023-07-19 01:09:02 +00:00
if ( autoPassTurn )
{
2023-09-08 14:27:07 +00:00
PassTurn ( beat + interval , beat , interval , timeUpSound , consecutive , visualClock , audioClock , 1 ) ;
2023-07-19 01:09:02 +00:00
}
}
public static void PrePassTurn ( double beat , bool timeUpSound , bool consecutive , bool visualClock , int audioClock )
{
if ( GameManager . instance . currentGame = = "quizShow" )
{
instance . PassTurnStandalone ( beat , timeUpSound , consecutive , visualClock , audioClock ) ;
}
else
{
passedTurns . Add ( new PassedTurn ( )
{
beat = beat ,
timeUpSound = timeUpSound ,
consecutive = consecutive ,
visualClock = visualClock ,
audioClock = audioClock
} ) ;
}
}
private struct PassedTurn
{
public double beat ;
public bool timeUpSound ;
public bool consecutive ;
public bool visualClock ;
public int audioClock ;
}
private static List < PassedTurn > passedTurns = new ( ) ;
private void PassTurnStandalone ( double beat , bool timeUpSound , bool consecutive , bool visualClock , int audioClock )
2023-04-12 22:34:15 +00:00
{
2023-07-19 01:09:02 +00:00
var lastInterval = GetLastIntervalBeforeBeat ( beat ) ;
2023-09-08 14:27:07 +00:00
float length = EventCaller . GetAllInGameManagerList ( "quizShow" , new string [ ] { "passTurn" } ) . Find ( x = > x . beat = = beat ) . length ;
2023-07-19 01:09:02 +00:00
if ( lastInterval ! = null )
2023-04-12 22:34:15 +00:00
{
2023-09-08 14:27:07 +00:00
PassTurn ( beat , lastInterval . beat , lastInterval . length , timeUpSound , consecutive , visualClock , audioClock , length ) ;
2023-04-12 22:34:15 +00:00
}
2023-07-19 01:09:02 +00:00
}
2023-09-08 14:27:07 +00:00
private void PassTurn ( double beat , double intervalBeat , float intervalLength , bool timeUpSound , bool consecutive , bool visualClock , int audioClock , float length )
2023-07-19 01:09:02 +00:00
{
2023-09-08 14:27:07 +00:00
playerStartBeat = beat + length - Conductor . instance . SecsToBeats ( ngEarlyTime , Conductor . instance . GetBpmAtBeat ( beat + length ) ) ;
playerLength = intervalLength + ( float ) Conductor . instance . SecsToBeats ( ngEarlyTime , Conductor . instance . GetBpmAtBeat ( beat + length ) ) ;
2023-07-19 01:09:02 +00:00
var relevantInputs = GetInputsBetweenBeat ( intervalBeat , intervalBeat + intervalLength ) ;
relevantInputs . Sort ( ( x , y ) = > x . beat . CompareTo ( y . beat ) ) ;
for ( int i = 0 ; i < relevantInputs . Count ; i + + )
2023-04-12 22:34:15 +00:00
{
2023-07-19 01:09:02 +00:00
double inputBeat = relevantInputs [ i ] . beat - intervalBeat ;
bool isDpad = relevantInputs [ i ] . datamodel = = "quizShow/dPad" ;
if ( isDpad )
{
2023-10-29 19:44:47 +00:00
ScheduleAutoplayInput ( beat , length + inputBeat , InputAction_Left , AutoplayDPad , Nothing , Nothing ) ;
2023-07-19 01:09:02 +00:00
}
else
{
2023-10-29 19:44:47 +00:00
ScheduleAutoplayInput ( beat , length + inputBeat , InputAction_Right , AutoplayAButton , Nothing , Nothing ) ;
2023-07-19 01:09:02 +00:00
}
2023-04-12 22:34:15 +00:00
}
2023-11-24 22:49:59 +00:00
int hundredLoops = Mathf . FloorToInt ( ( float ) countToMatch / 100f ) ;
2023-04-12 22:34:15 +00:00
countToMatch - = hundredLoops * 100 ;
doingConsectiveIntervals = consecutive ;
2023-04-15 13:42:04 +00:00
float timeUpBeat = 0f ;
2023-04-26 12:43:35 +00:00
if ( audioClock = = ( int ) ClockAudio . Both | | audioClock = = ( int ) ClockAudio . Start )
2023-04-15 13:42:04 +00:00
{
2023-07-19 01:09:02 +00:00
SoundByte . PlayOneShotGame ( "quizShow/timerStart" , beat ) ;
2023-04-15 13:42:04 +00:00
timeUpBeat = 0.5f ;
2023-04-26 12:43:35 +00:00
}
if ( audioClock = = ( int ) ClockAudio . End ) timeUpBeat = 0.5f ;
2023-07-19 01:09:02 +00:00
QSTimer spawnedTimer = Instantiate ( stopWatchRef , transform ) ;
if ( ! visualClock ) Destroy ( spawnedTimer . gameObject ) ;
List < BeatAction . Action > actions = new ( )
2023-04-12 22:34:15 +00:00
{
2023-07-19 01:09:02 +00:00
new BeatAction . Action ( beat , delegate
{
2023-11-24 22:49:59 +00:00
if ( doingConsectiveIntervals )
{
countToMatch + = relevantInputs . Count ;
}
else
{
countToMatch = relevantInputs . Count ;
}
2023-07-19 01:09:02 +00:00
if ( shouldPrepareArms )
2023-04-12 22:34:15 +00:00
{
2023-07-19 01:09:02 +00:00
contesteeLeftArmAnim . DoScaledAnimationAsync ( "LeftPrepare" , 0.5f ) ;
contesteeRightArmAnim . DoScaledAnimationAsync ( "RIghtPrepare" , 0.5f ) ;
}
if ( ! consecutive )
{
hostLeftArmAnim . DoScaledAnimationAsync ( "HostLeftRest" , 0.5f ) ;
hostRightArmAnim . DoScaledAnimationAsync ( "HostRightRest" , 0.5f ) ;
}
shouldPrepareArms = false ;
if ( visualClock )
{
spawnedTimer . gameObject . SetActive ( true ) ;
2023-09-08 14:27:07 +00:00
spawnedTimer . Init ( beat + length , intervalLength ) ;
2023-07-19 01:09:02 +00:00
}
} ) ,
2023-09-08 14:27:07 +00:00
new BeatAction . Action ( beat + length + intervalLength , delegate
2023-07-19 01:09:02 +00:00
{
if ( ! consecutive )
{
if ( audioClock = = ( int ) ClockAudio . Both | | audioClock = = ( int ) ClockAudio . End ) SoundByte . PlayOneShotGame ( "quizShow/timerStop" ) ;
2023-04-12 22:34:15 +00:00
contesteeLeftArmAnim . DoScaledAnimationAsync ( "LeftRest" , 0.5f ) ;
contesteeRightArmAnim . DoScaledAnimationAsync ( "RightRest" , 0.5f ) ;
shouldPrepareArms = true ;
}
2023-07-19 01:09:02 +00:00
if ( visualClock ) Destroy ( spawnedTimer . gameObject ) ;
2023-04-12 22:34:15 +00:00
}
2023-07-19 01:09:02 +00:00
) ,
2023-09-08 14:27:07 +00:00
new BeatAction . Action ( beat + length + intervalLength + timeUpBeat , delegate { if ( timeUpSound & & ! consecutive ) SoundByte . PlayOneShotGame ( "quizShow/timeUp" ) ; } ) ,
2023-07-19 01:09:02 +00:00
} ;
2023-09-11 22:28:04 +00:00
BeatAction . New ( instance , actions ) ;
2023-04-12 22:34:15 +00:00
}
void ContesteePressButton ( bool dpad )
{
if ( currentStage = = 0 )
{
contesteeHead . Play ( "ContesteeHeadIdle" , - 1 , 0 ) ;
}
else
{
if ( currentStage ! = 4 ) contesteeHead . DoScaledAnimationAsync ( "ContesteeHeadStage" + currentStage . ToString ( ) , 0.5f ) ;
else
{
contesteeHead . DoScaledAnimationAsync ( "ContesteeHeadStage3" , 0.5f ) ;
}
}
if ( dpad )
{
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "quizShow/contestantDPad" ) ;
2023-04-12 22:34:15 +00:00
contesteeLeftArmAnim . DoScaledAnimationAsync ( "LeftArmPress" , 0.5f ) ;
}
else
{
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "quizShow/contestantA" ) ;
2023-04-12 22:34:15 +00:00
contesteeRightArmAnim . DoScaledAnimationAsync ( "RightArmHit" , 0.5f ) ;
}
pressCount + + ;
if ( shouldResetCount & & pressCount > 99 ) pressCount = 0 ;
switch ( pressCount )
{
case int x when x < 100 :
firstDigitSr . sprite = contestantNumberSprites [ GetSpecificDigit ( pressCount , 1 ) ] ;
secondDigitSr . sprite = contestantNumberSprites [ GetSpecificDigit ( pressCount , 2 ) ] ;
break ;
case 100 :
ForceExplode ( ( int ) ShouldExplode . Contestant ) ;
break ;
case 120 :
ForceExplode ( ( int ) ShouldExplode . Host ) ;
break ;
case 150 :
ForceExplode ( ( int ) ShouldExplode . Sign ) ;
break ;
}
}
public void ForceExplode ( int whoToExplode )
{
switch ( whoToExplode )
{
case ( int ) ShouldExplode . Contestant :
if ( contExploded ) return ;
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "quizShow/contestantExplode" ) ;
2023-04-12 22:34:15 +00:00
firstDigitSr . color = new Color ( 1 , 1 , 1 , 0 ) ;
secondDigitSr . color = new Color ( 1 , 1 , 1 , 0 ) ;
contCounter . sprite = explodedCounter ;
contExploded = true ;
contExplosion . Play ( ) ;
break ;
case ( int ) ShouldExplode . Host :
if ( hostExploded ) return ;
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "quizShow/hostExplode" ) ;
2023-04-12 22:34:15 +00:00
hostFirstDigitSr . color = new Color ( 1 , 1 , 1 , 0 ) ;
hostSecondDigitSr . color = new Color ( 1 , 1 , 1 , 0 ) ;
hostCounter . sprite = explodedCounter ;
hostExploded = true ;
hostExplosion . Play ( ) ;
break ;
case ( int ) ShouldExplode . Sign :
if ( signExploded ) return ;
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "quizShow/signExplode" ) ;
2023-04-12 22:34:15 +00:00
signExploded = true ;
signExplosion . Play ( ) ;
signAnim . Play ( "Exploded" , 0 , 0 ) ;
break ;
}
}
2023-06-10 19:13:29 +00:00
public void RevealAnswer ( double beat , float length )
2023-04-12 22:34:15 +00:00
{
blackOut . SetActive ( true ) ;
2023-09-11 22:28:04 +00:00
BeatAction . New ( instance , new List < BeatAction . Action > ( )
2023-04-12 22:34:15 +00:00
{
new BeatAction . Action ( beat + length , delegate
{
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "quizShow/answerReveal" ) ;
2023-04-12 22:34:15 +00:00
hostFirstDigitSr . sprite = hostNumberSprites [ GetSpecificDigit ( countToMatch , 1 ) ] ;
hostSecondDigitSr . sprite = hostNumberSprites [ GetSpecificDigit ( countToMatch , 2 ) ] ;
} )
} ) ;
}
2023-04-15 13:42:04 +00:00
public void AnswerReaction ( bool audience , bool jingle , bool revealAnswer )
2023-04-12 22:34:15 +00:00
{
//In the future make this a prefunction that makes skill stars compatible
blackOut . SetActive ( false ) ;
2023-04-15 13:42:04 +00:00
if ( revealAnswer )
{
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "quizShow/answerReveal" ) ;
2023-04-15 13:42:04 +00:00
hostFirstDigitSr . sprite = hostNumberSprites [ GetSpecificDigit ( countToMatch , 1 ) ] ;
hostSecondDigitSr . sprite = hostNumberSprites [ GetSpecificDigit ( countToMatch , 2 ) ] ;
}
2023-04-12 22:34:15 +00:00
if ( pressCount = = countToMatch )
{
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "quizShow/correct" ) ;
2023-04-12 22:34:15 +00:00
contesteeHead . Play ( "ContesteeSmile" , - 1 , 0 ) ;
hostHead . Play ( "HostSmile" , - 1 , 0 ) ;
2023-06-10 19:13:29 +00:00
if ( audience ) SoundByte . PlayOneShotGame ( "quizShow/audienceCheer" ) ;
if ( jingle ) SoundByte . PlayOneShotGame ( "quizShow/correctJingle" ) ;
2023-04-12 22:34:15 +00:00
}
else
{
ScoreMiss ( ) ;
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "quizShow/incorrect" ) ;
2023-04-12 22:34:15 +00:00
contesteeHead . Play ( "ContesteeSad" , - 1 , 0 ) ;
hostHead . Play ( "HostSad" , - 1 , 0 ) ;
2023-06-10 19:13:29 +00:00
if ( audience ) SoundByte . PlayOneShotGame ( "quizShow/audienceSad" ) ;
if ( jingle ) SoundByte . PlayOneShotGame ( "quizShow/incorrectJingle" ) ;
2023-04-12 22:34:15 +00:00
}
}
void AutoplayAButton ( PlayerActionEvent caller , float state )
{
ContesteePressButton ( false ) ;
}
void AutoplayDPad ( PlayerActionEvent caller , float state )
{
ContesteePressButton ( true ) ;
}
void Nothing ( PlayerActionEvent caller ) { }
int GetSpecificDigit ( int num , int nth )
{
return ( num / ( int ) Mathf . Pow ( 10 , nth - 1 ) ) % 10 ;
}
}
}