2022-06-29 05:37:14 +00:00
using System.Collections.Generic ;
using UnityEngine ;
using HeavenStudio.Util ;
namespace HeavenStudio.Games.Loaders
{
using static Minigames ;
public static class CtrFirstContact
{
public static Minigame AddGame ( EventCaller eventCaller )
{
return new Minigame ( "firstContact" , "First Contact" , "008c97" , false , false , new List < GameAction > ( )
{
new GameAction ( "beat intervals" , delegate { FirstContact . instance . SetIntervalStart ( eventCaller . currentEntity . beat , eventCaller . currentEntity . length ) ; } , 4f , true ) ,
new GameAction ( "alien speak" , delegate { FirstContact . instance . alienSpeak ( eventCaller . currentEntity . beat ) ; } , 0.5f , false ) ,
new GameAction ( "alien turnover" , delegate { FirstContact . instance . alienTurnOver ( eventCaller . currentEntity . beat ) ; } , 0.5f , false ) ,
new GameAction ( "alien success" , delegate { FirstContact . instance . alienSuccess ( eventCaller . currentEntity . beat ) ; } , 1f , false ) ,
new GameAction ( "mission control" , delegate { FirstContact . instance . missionControlDisplay ( eventCaller . currentEntity . beat , eventCaller . currentEntity . toggle ) ; } , 1f , false , new List < Param >
{
new Param ( "toggle" , false , "Stay" , "If it's the end of the remix/song" )
} ) ,
new GameAction ( "look at" , delegate { FirstContact . instance . lookAtDirection ( eventCaller . currentEntity . type , eventCaller . currentEntity . type2 ) ; } , . 5f , false , new List < Param > ( )
{
new Param ( "type" , FirstContact . alienLookAt . lookAtTranslator , "alien look at what" , "[Alien] will look at what" ) ,
new Param ( "type" , FirstContact . translatorLookAt . lookAtAlien , "translator look at what" , "[Translator] will look at what" ) ,
} ) ,
//new GameAction("Version of First Contact", delegate { FirstContact.instance.versionOfFirstContact(eventCaller.currentEntity.type); }, .5f, false, new List<Param>
//{
// new Param("type", FirstContact.VersionOfContact.FirstContact, "Version", "Version of First Contact to play"),
//}),
} ) ;
}
}
}
namespace HeavenStudio.Games
{
2022-07-03 08:42:18 +00:00
//using Scripts_FirstContact;
2022-06-29 05:37:14 +00:00
public class FirstContact : Minigame
{
public static FirstContact instance { get ; private set ; }
[Header("Properties")]
public int alienSpeakCount ;
public int translatorSpeakCount ;
public bool hasMissed ;
private float lastReportedBeat = 0f ;
[Header("Components")]
[SerializeField] GameObject alien ;
2022-07-03 08:42:18 +00:00
[SerializeField] GameObject translator ;
//[SerializeField] GameObject alienSpeech;
2022-06-29 05:37:14 +00:00
[SerializeField] GameObject dummyHolder ;
[SerializeField] GameObject missionControl ;
[SerializeField] GameObject liveBar ;
[Header("Variables")]
public bool intervalStarted ;
//float intervalStartBeat;
public float beatInterval = 4f ;
public bool isCorrect , noHitOnce , isSpeaking ;
//public int version;
public float lookAtLength = 1f ;
2022-07-03 08:42:18 +00:00
2022-06-29 05:37:14 +00:00
//public enum VersionOfContact
//{
// FirstContact,
// CitrusRemix,
// SecondContact
//}
public enum alienLookAt
{
lookAtTranslator ,
idle
}
public enum translatorLookAt
{
lookAtAlien ,
idle
}
private void Awake ( )
{
instance = this ;
2022-07-03 08:42:18 +00:00
}
public void SetIntervalStart ( float beat , float interval = 4f )
{
if ( ! intervalStarted )
{
//alienSpeakCount = 0;
//translatorSpeakCount = 0;
intervalStarted = true ;
}
//intervalStartBeat = beat;
beatInterval = interval ;
2022-06-29 05:37:14 +00:00
}
private void Update ( )
{
//This is taken from the conductor script
if ( Conductor . instance . ReportBeat ( ref lastReportedBeat ) )
{
liveBar . GetComponent < Animator > ( ) . Play ( "liveBar" , 0 , 0 ) ;
}
else if ( Conductor . instance . songPositionInBeats < lastReportedBeat )
{
lastReportedBeat = Mathf . Round ( Conductor . instance . songPositionInBeats ) ;
}
2022-07-03 08:42:18 +00:00
if ( PlayerInput . Pressed ( ) & & ! IsExpectingInputNow ( ) & & ! noHitOnce & & ! isSpeaking )
{
Jukebox . PlayOneShotGame ( "firstContact/" + randomizerLines ( ) ) ;
BeatAction . New ( this . gameObject , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( . 5f , delegate { translator . GetComponent < Animator > ( ) . Play ( "translator_speak" , 0 , 0 ) ; } ) ,
} ) ;
}
if ( ( PlayerInput . Pressed ( ) & & ! IsExpectingInputNow ( ) & & isSpeaking ) )
{
hasMissed = true ;
}
2022-06-29 05:37:14 +00:00
}
//public void versionOfFirstContact(int type)
//{
// version = type;
//}
public void lookAtDirection ( int alienLookAt , int translatorLookAt )
{
switch ( alienLookAt )
{
case 0 :
alien . GetComponent < Animator > ( ) . Play ( "alien_lookAt" , 0 , 0 ) ;
break ;
case 1 :
alien . GetComponent < Animator > ( ) . Play ( "alien_idle" , 0 , 0 ) ;
break ;
}
switch ( translatorLookAt )
{
case 0 :
translator . GetComponent < Animator > ( ) . Play ( "translator_lookAtAlien" , 0 , 0 ) ;
break ;
case 1 :
translator . GetComponent < Animator > ( ) . Play ( "translator_idle" , 0 , 0 ) ;
break ;
}
}
public void alienSpeak ( float beat )
{
//if (!intervalStarted)
//{
// SetIntervalStart(beat, beatInterval);
//}
//missionControl.SetActive(false);
Jukebox . PlayOneShotGame ( "firstContact/alien" ) ;
2022-07-03 08:42:18 +00:00
+ + alienSpeakCount ;
2022-06-29 05:37:14 +00:00
var random = Random . Range ( 0 , 2 ) ;
string textToPut = "" ;
if ( random = = 0 )
{
textToPut = "translator_lookAtAlien" ;
}
else
{
textToPut = "translator_lookAtAlien_nod" ;
}
2022-07-03 08:42:18 +00:00
ScheduleInput ( beat , beatInterval , InputType . STANDARD_DOWN , alienTapping , alienOnMiss , AlienEmpty ) ;
2022-06-29 05:37:14 +00:00
BeatAction . New ( alien , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( beat , delegate { alien . GetComponent < Animator > ( ) . Play ( "alien_talk" , 0 , 0 ) ; } ) ,
new BeatAction . Action ( beat , delegate { translator . GetComponent < Animator > ( ) . Play ( textToPut , 0 , 0 ) ; } ) ,
} ) ;
}
public void alienTurnOver ( float beat )
{
2022-07-03 08:42:18 +00:00
if ( ! intervalStarted )
{
SetIntervalStart ( beat , beatInterval ) ;
}
if ( intervalStarted )
{
SetIntervalStart ( beat , beatInterval ) ;
}
2022-06-29 05:37:14 +00:00
Jukebox . PlayOneShotGame ( "firstContact/turnover" ) ;
BeatAction . New ( alien , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( beat , delegate { alien . GetComponent < Animator > ( ) . Play ( "alien_point" , 0 , 0 ) ; } ) ,
new BeatAction . Action ( beat + . 5f , delegate { alien . GetComponent < Animator > ( ) . Play ( "alien_idle" , 0 , 0 ) ; } ) ,
new BeatAction . Action ( beat + . 5f , delegate { translator . GetComponent < Animator > ( ) . Play ( "translator_idle" , 0 , 0 ) ; } )
} ) ;
isSpeaking = true ;
}
public void alienSuccess ( float beat )
{
//Make this codeblock smaller
if ( alienSpeakCount = = translatorSpeakCount )
{
string [ ] sounds = new string [ ] { "firstContact/success_1" , "firstContact/success_2" } ;
var sound = new MultiSound . Sound [ ]
{
new MultiSound . Sound ( sounds [ 0 ] , beat ) ,
new MultiSound . Sound ( sounds [ 1 ] , beat + . 5f , offset : . 15f )
} ;
MultiSound . Play ( sound ) ;
BeatAction . New ( alien , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( beat , delegate { alien . GetComponent < Animator > ( ) . Play ( "alien_success" , 0 , 0 ) ; } ) ,
new BeatAction . Action ( beat + . 5f , delegate { alien . GetComponent < Animator > ( ) . Play ( "alien_success" , 0 , 0 ) ; } )
} ) ;
BeatAction . New ( translator . gameObject , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( beat , delegate { translator . GetComponent < Animator > ( ) . Play ( "translator_idle" , 0 , 0 ) ; } ) ,
} ) ;
}
else if ( alienSpeakCount ! = translatorSpeakCount )
{
string [ ] sounds = new string [ ] { "firstContact/failAlien_1" , "firstContact/failAlien_2" } ;
var sound = new MultiSound . Sound [ ]
{
new MultiSound . Sound ( sounds [ 0 ] , beat ) ,
new MultiSound . Sound ( sounds [ 1 ] , beat + . 5f )
} ;
MultiSound . Play ( sound ) ;
BeatAction . New ( alien , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( beat , delegate { alien . GetComponent < Animator > ( ) . Play ( "alien_fail" , 0 , 0 ) ; } ) ,
new BeatAction . Action ( beat + . 5f , delegate { alien . GetComponent < Animator > ( ) . Play ( "alien_fail" , 0 , 0 ) ; } )
} ) ;
BeatAction . New ( translator . gameObject , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( beat , delegate { translator . GetComponent < Animator > ( ) . Play ( "translator_idle" , 0 , 0 ) ; } ) ,
} ) ;
}
alienSpeakCount = 0 ;
translatorSpeakCount = 0 ;
isSpeaking = false ;
hasMissed = false ;
noHitOnce = false ;
}
public void missionControlDisplay ( float beat , bool stay )
{
missionControl . SetActive ( true ) ;
string textToPut = "" ;
if ( alienSpeakCount = = translatorSpeakCount )
{
textToPut = "missionControl_success" ;
}
else
{
textToPut = "missionControl_fail" ;
}
BeatAction . New ( missionControl , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( beat , delegate { missionControl . GetComponentInParent < Animator > ( ) . Play ( textToPut , 0 , 0 ) ; } ) ,
new BeatAction . Action ( beat , delegate { alien . GetComponentInParent < Animator > ( ) . Play ( "alien_idle" , 0 , 0 ) ; } ) ,
new BeatAction . Action ( beat , delegate { translator . GetComponent < Animator > ( ) . Play ( "translator_idle" , 0 , 0 ) ; } ) ,
} ) ;
if ( ! stay )
{
BeatAction . New ( missionControl , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( beat + 1f , delegate { missionControl . SetActive ( false ) ; } ) ,
} ) ;
}
else
{
missionControl . SetActive ( true ) ;
}
alienSpeakCount = 0 ;
translatorSpeakCount = 0 ;
isSpeaking = false ;
}
2022-07-03 08:42:18 +00:00
public void alienTapping ( PlayerActionEvent caller , float beat ) //OnHit
{
if ( ! noHitOnce )
{
+ + translatorSpeakCount ;
Jukebox . PlayOneShotGame ( "firstContact/" + randomizerLines ( ) ) ;
isCorrect = true ;
BeatAction . New ( this . gameObject , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( . 5f , delegate { translator . GetComponent < Animator > ( ) . Play ( "translator_speak" , 0 , 0 ) ; } ) ,
} ) ;
}
else if ( noHitOnce )
{
Jukebox . PlayOneShotGame ( "firstContact/slightlyFail" ) ;
BeatAction . New ( this . gameObject , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( . 5f , delegate { translator . GetComponent < Animator > ( ) . Play ( "translator_eh" , 0 , 0 ) ; } ) ,
} ) ;
}
}
public void alienOnMiss ( PlayerActionEvent caller ) //OnMiss
{
if ( ! noHitOnce )
{
Jukebox . PlayOneShotGame ( "firstContact/alienNoHit" ) ;
noHitOnce = true ;
}
BeatAction . New ( alien , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( . 5f , delegate { alien . GetComponent < Animator > ( ) . Play ( "alien_noHit" , 0 , 0 ) ; } ) ,
} ) ;
}
public void AlienEmpty ( PlayerActionEvent caller ) //OnEmpty
{
//empty
}
public int randomizerLines ( )
{
return Random . Range ( 1 , 11 ) ;
}
//public void alienSuccessTest(PlayerActionEvent caller, float beat)
//{
// string[] sfxStrings = { "", "" };
// string animString = "";
// float off = 0f;
// if (alienSpeakCount == translatorSpeakCount)
// {
// sfxStrings[0] = "firstContact/success_1";
// sfxStrings[1] = "firstContact/success_2";
// animString = "alien_success";
// off = .15f;
// }
// else if(alienSpeakCount != translatorSpeakCount)
// {
// sfxStrings[0] = "firstContact/failAlien_1";
// sfxStrings[1] = "firstContact/failAlien_2";
// animString = "alien_fail";
// off = .5f;
// }
// string[] sounds = new string[] { sfxStrings[0], sfxStrings[0] };
// var sound = new MultiSound.Sound[]
// {
// new MultiSound.Sound(sounds[0], beat),
// new MultiSound.Sound(sounds[1], beat + .5f, offset: off)
// };
// MultiSound.Play(sound);
// BeatAction.New(alien, new List<BeatAction.Action>()
// {
// new BeatAction.Action(beat, delegate { alien.GetComponent<Animator>().Play(animString, 0, 0); }),
// new BeatAction.Action(beat + .5f, delegate { alien.GetComponent<Animator>().Play(animString, 0, 0); })
// });
// BeatAction.New(translator.gameObject, new List<BeatAction.Action>()
// {
// new BeatAction.Action(beat, delegate { translator.GetComponent<Animator>().Play("translator_idle", 0, 0); }),
// });
// alienSpeakCount = 0;
// translatorSpeakCount = 0;
// isSpeaking = false;
// hasMissed = false;
// noHitOnce = false;
//}
2022-06-29 05:37:14 +00:00
}
}