2023-06-10 19:13:29 +00:00
using System ;
2023-03-27 03:09:55 +00:00
using System.Text ;
2022-06-29 05:37:14 +00:00
using System.Collections.Generic ;
using UnityEngine ;
using HeavenStudio.Util ;
2023-10-29 19:44:47 +00:00
using HeavenStudio.InputSystem ;
2023-03-27 03:09:55 +00:00
using TMPro ;
2023-07-12 16:49:32 +00:00
using Jukebox ;
using UnityEngine.Assertions.Must ;
using UnityEngine.UIElements ;
2022-06-29 05:37:14 +00:00
namespace HeavenStudio.Games.Loaders
{
using static Minigames ;
public static class CtrFirstContact
{
public static Minigame AddGame ( EventCaller eventCaller )
{
2023-04-02 02:28:23 +00:00
return new Minigame ( "firstContact" , "Second Contact" , "1f3833" , false , false , new List < GameAction > ( )
2022-06-29 05:37:14 +00:00
{
2022-08-21 03:13:52 +00:00
new GameAction ( "beat intervals" , "Start Interval" )
2022-07-08 05:27:10 +00:00
{
2023-07-12 16:49:32 +00:00
preFunction = delegate { var e = eventCaller . currentEntity ; FirstContact . PreInterval ( e . beat , e . length , e [ "dialogue" ] , e [ "auto" ] ) ; } ,
2023-03-27 03:09:55 +00:00
parameters = new List < Param > ( )
{
2024-01-15 02:04:10 +00:00
new Param ( "dialogue" , "REPLACE THIS" , "Mistranslation Dialogue" , "Set the line to use when messing up the translation." ) ,
new Param ( "auto" , true , "Auto Pass Turn" , "Toggle if the turn should be passed automatically at the end of the start interval." )
2023-03-27 03:09:55 +00:00
} ,
2023-09-08 14:27:07 +00:00
defaultLength = 3f ,
2023-01-19 02:31:08 +00:00
resizable = true ,
2023-03-27 03:09:55 +00:00
priority = 2 ,
2022-08-21 03:13:52 +00:00
} ,
2023-03-27 03:09:55 +00:00
new GameAction ( "alien speak" , "Bob Speak" )
2022-06-29 05:37:14 +00:00
{
2022-08-21 03:13:52 +00:00
defaultLength = 0.5f ,
parameters = new List < Param > ( )
{
2024-01-15 02:04:10 +00:00
new Param ( "spaceNum" , new EntityTypes . Integer ( 0 , 12 , 0 ) , "Amount Of Spaces" , "Choose the amount of spaces to add before the icon." ) ,
new Param ( "dotdotdot" , false , "Ellipses" , "Toggle if the symbol should have \"...\" before it." ) ,
new Param ( "newline" , false , "New line" , "Toggle if this text starts a new line." ) ,
new Param ( "dialogue" , "" , "Translation" , "Set the text that this syllable will translate to. Spaces will not be automatically added." )
2023-03-27 03:09:55 +00:00
} ,
priority = 1
2022-08-21 03:13:52 +00:00
} ,
2023-03-27 03:09:55 +00:00
new GameAction ( "alien turnover" , "Pass Turn" )
2022-06-29 05:37:14 +00:00
{
2023-07-12 16:49:32 +00:00
function = delegate { FirstContact . instance . PassTurnStandalone ( eventCaller . currentEntity . beat ) ; } ,
2023-09-08 14:27:07 +00:00
resizable = true ,
2022-08-21 03:13:52 +00:00
} ,
2023-03-27 03:09:55 +00:00
new GameAction ( "alien success" , "Success" )
2022-07-25 02:04:55 +00:00
{
2023-03-27 03:09:55 +00:00
function = delegate { FirstContact . instance . AlienSuccess ( eventCaller . currentEntity . beat ) ; } ,
2022-08-21 03:13:52 +00:00
} ,
new GameAction ( "mission control" , "Show Mission Control" )
{
2023-03-27 03:09:55 +00:00
function = delegate { var e = eventCaller . currentEntity ; FirstContact . instance . MissionControlDisplay ( e . beat , e [ "toggle" ] , e . length ) ; } ,
resizable = true ,
2022-08-21 03:13:52 +00:00
parameters = new List < Param >
{
2024-01-15 02:04:10 +00:00
new Param ( "toggle" , false , "Stay" , "Toggle if the camera should stay on mission control even after the event has ended. This is usually used for the end of a level." )
2022-08-21 03:13:52 +00:00
}
} ,
2024-01-15 02:04:10 +00:00
new GameAction ( "look at" , "Look" )
2022-08-21 03:13:52 +00:00
{
2023-03-27 03:09:55 +00:00
function = delegate { FirstContact . instance . LookAtDirection ( eventCaller . currentEntity [ "type" ] , eventCaller . currentEntity [ "type2" ] ) ; } ,
2022-08-21 03:13:52 +00:00
defaultLength = . 5f ,
parameters = new List < Param > ( )
{
2024-01-15 02:04:10 +00:00
new Param ( "type" , FirstContact . alienLookAt . lookAtAlien , "Farmer Bob" , "Set where Farmer Bob will look." ) ,
new Param ( "type2" , FirstContact . translatorLookAt . lookAtBob , "Alien" , "Set where the alien will look." ) ,
2022-08-21 03:13:52 +00:00
}
} ,
2024-01-15 02:04:10 +00:00
new GameAction ( "live bar beat" , "\"Live\" Bar" )
2022-08-21 03:13:52 +00:00
{
2023-03-27 03:09:55 +00:00
function = delegate { FirstContact . instance . LiveBarBeat ( eventCaller . currentEntity [ "toggle" ] ) ; } ,
2022-08-21 03:13:52 +00:00
defaultLength = . 5f ,
parameters = new List < Param > ( )
{
2024-01-15 02:04:10 +00:00
new Param ( "toggle" , true , "On Beat" , "Toggle if the \"Live\" bar in the top-left will animate on onbeats or offbeats." )
2022-08-21 03:13:52 +00:00
}
2023-03-27 03:09:55 +00:00
}
2023-05-28 17:34:44 +00:00
} ,
2024-01-14 14:24:32 +00:00
new List < string > ( ) { "ctr" , "repeat" } ,
2023-05-28 17:34:44 +00:00
"ctrinterpreter" , "en" ,
2024-03-29 02:35:07 +00:00
new List < string > ( ) { } ,
chronologicalSortKey : 13
2023-05-28 17:34:44 +00:00
) ;
2022-07-25 02:04:55 +00:00
}
}
}
namespace HeavenStudio.Games
{
//using Scripts_FirstContact;
public class FirstContact : Minigame
{
2023-03-27 03:09:55 +00:00
const string MID_MSG_MISS = "<color=\"red\"> ..? </color>" ;
const string MSG_ALIEN = "<sprite name=\"AlienIcn\">" ;
const string MSG_MAN = "<sprite name=\"ManIcn\">" ;
2023-07-12 16:49:32 +00:00
const string MSG_MAN_DDD = "...<sprite name=\"ManIcn\">" ;
2023-03-27 03:09:55 +00:00
// I should add a DonkTroll sprite 🫰🫰🫰🫰🫰
2022-07-25 02:04:55 +00:00
public static FirstContact instance { get ; private set ; }
2023-07-12 16:49:32 +00:00
//[Header("Properties")]
private bool hasMissed ;
2023-06-10 19:13:29 +00:00
private double lastReportedBeat = 0 ;
2022-07-25 02:04:55 +00:00
[Header("Components")]
2023-07-12 16:49:32 +00:00
[SerializeField] Animator alien ;
[SerializeField] Animator translator ;
2022-07-25 02:04:55 +00:00
//[SerializeField] GameObject alienSpeech;
[SerializeField] GameObject missionControl ;
2023-07-12 16:49:32 +00:00
[SerializeField] Animator liveBar ;
2022-07-25 02:04:55 +00:00
2023-03-27 03:09:55 +00:00
[SerializeField] GameObject alienTextbox ;
[SerializeField] TMP_Text alienText ;
[SerializeField] GameObject translateTextbox ;
[SerializeField] TMP_Text translateText ;
[SerializeField] GameObject translateFailTextbox ;
[SerializeField] TMP_Text translateFailText ;
2022-07-25 02:04:55 +00:00
[Header("Variables")]
2023-03-27 03:09:55 +00:00
int currentVoicelineIndex = - 1 ;
public bool noHitOnce , isSpeaking ;
2022-07-25 02:04:55 +00:00
//public int version;
public float lookAtLength = 1f ;
bool onBeat ;
float liveBarBeatOffset ;
2023-03-27 03:09:55 +00:00
string onOutDialogue = "YOU SUCK AT CHARTING" ;
string callDiagBuffer = "" ;
string respDiagBuffer = "" ;
2024-01-14 14:24:32 +00:00
List < ( string , bool ) > callDiagList = new ( ) ;
2023-03-27 03:09:55 +00:00
int callDiagIndex = 0 ;
2023-07-12 16:49:32 +00:00
private struct QueuedInterval
2023-03-27 03:09:55 +00:00
{
2023-07-12 16:49:32 +00:00
public double beat ;
public float interval ;
public bool autoPassTurn ;
public string outDialogue ;
2023-03-27 03:09:55 +00:00
}
2023-07-12 16:49:32 +00:00
private static List < QueuedInterval > queuedIntervals = new List < QueuedInterval > ( ) ;
2022-07-25 02:04:55 +00:00
//public enum VersionOfContact
//{
// FirstContact,
// CitrusRemix,
// SecondContact
//}
public enum alienLookAt
{
2023-03-27 03:09:55 +00:00
lookAtAlien ,
2022-07-25 02:04:55 +00:00
idle
}
public enum translatorLookAt
{
2023-03-27 03:09:55 +00:00
lookAtBob ,
2022-07-25 02:04:55 +00:00
idle
}
2023-10-29 19:44:47 +00:00
protected static bool IA_PadAny ( out double dt )
{
return PlayerInput . GetPadDown ( InputController . ActionsPad . East , out dt )
| | 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 ) ;
}
public static PlayerInput . InputAction InputAction_Press =
new ( "CtrInterpreterPress" , new int [ ] { IAPressCat , IAFlickCat , IAPressCat } ,
IA_PadAny , IA_TouchBasicPress , IA_BatonBasicPress ) ;
2023-03-27 03:09:55 +00:00
void OnDestroy ( )
{
2023-06-03 23:30:17 +00:00
foreach ( var evt in scheduledInputs )
{
evt . Disable ( ) ;
}
2023-03-27 03:09:55 +00:00
}
2022-07-25 02:04:55 +00:00
private void Awake ( )
{
instance = this ;
}
2023-03-27 03:09:55 +00:00
private void Start ( )
{
callDiagBuffer = "" ;
respDiagBuffer = "" ;
callDiagList . Clear ( ) ;
callDiagIndex = 0 ;
alienTextbox . SetActive ( false ) ;
translateTextbox . SetActive ( false ) ;
translateFailTextbox . SetActive ( false ) ;
}
2023-07-12 16:49:32 +00:00
private List < RiqEntity > GetAllSpeaksInBetweenBeat ( double beat , double endBeat )
2022-07-25 02:04:55 +00:00
{
2023-07-12 16:49:32 +00:00
List < RiqEntity > speakEvents = EventCaller . GetAllInGameManagerList ( "firstContact" , new string [ ] { "alien speak" } ) ;
List < RiqEntity > tempEvents = new ( ) ;
foreach ( var entity in speakEvents )
2022-07-25 02:04:55 +00:00
{
2023-07-12 16:49:32 +00:00
if ( entity . beat > = beat & & entity . beat < endBeat )
{
tempEvents . Add ( entity ) ;
}
2022-07-25 02:04:55 +00:00
}
2023-07-12 16:49:32 +00:00
return tempEvents ;
}
2022-07-25 02:04:55 +00:00
2023-07-12 16:49:32 +00:00
private RiqEntity GetLastIntervalBeforeBeat ( double beat )
{
List < RiqEntity > intervalEvents = EventCaller . GetAllInGameManagerList ( "firstContact" , new string [ ] { "beat intervals" } ) ;
if ( intervalEvents . Count = = 0 ) return null ;
var tempEvents = intervalEvents . FindAll ( x = > x . beat < = beat ) ;
tempEvents . Sort ( ( x , y ) = > x . beat . CompareTo ( y . beat ) ) ;
return tempEvents [ ^ 1 ] ;
}
2023-03-27 03:09:55 +00:00
2023-07-12 16:49:32 +00:00
public static void PreInterval ( double beat , float interval , string outDialogue , bool autoPassTurn )
{
if ( GameManager . instance . currentGame = = "firstContact" )
{
instance . SetIntervalStart ( beat , interval , outDialogue , beat , autoPassTurn ) ;
}
else
{
queuedIntervals . Add ( new QueuedInterval
{
beat = beat ,
interval = interval ,
outDialogue = outDialogue ,
autoPassTurn = autoPassTurn
} ) ;
}
2022-07-25 02:04:55 +00:00
}
2023-07-12 16:49:32 +00:00
private void SetIntervalStart ( double beat , float interval , string outDialogue , double gameSwitchBeat , bool autoPassTurn )
2022-07-25 02:04:55 +00:00
{
2023-07-12 16:49:32 +00:00
List < RiqEntity > relevantSpeakEvents = GetAllSpeaksInBetweenBeat ( beat , beat + interval ) ;
relevantSpeakEvents . Sort ( ( x , y ) = > x . beat . CompareTo ( y . beat ) ) ;
List < BeatAction . Action > queuedSpeaks = new ( )
2023-03-27 03:09:55 +00:00
{
2023-07-12 16:49:32 +00:00
new BeatAction . Action ( beat , delegate
{
translator . Play ( "translator_lookAtAlien" , 0 , 0 ) ;
onOutDialogue = outDialogue ;
callDiagBuffer = "" ;
respDiagBuffer = "" ;
callDiagList . Clear ( ) ;
callDiagIndex = 0 ;
alienText . text = "" ;
translateText . text = "" ;
translateFailText . text = "" ;
alienTextbox . SetActive ( false ) ;
translateTextbox . SetActive ( false ) ;
translateFailTextbox . SetActive ( false ) ;
if ( autoPassTurn )
{
2023-09-08 14:27:07 +00:00
AlienTurnOver ( beat + interval , beat , beat + interval , 1 ) ;
2023-07-12 16:49:32 +00:00
}
} )
} ;
for ( int i = 0 ; i < relevantSpeakEvents . Count ; i + + )
{
RiqEntity speakEventToCheck = relevantSpeakEvents [ i ] ;
if ( speakEventToCheck . beat > = gameSwitchBeat )
{
queuedSpeaks . Add ( new BeatAction . Action ( speakEventToCheck . beat , delegate
{
AlienSpeak ( speakEventToCheck . beat , speakEventToCheck [ "spaceNum" ] , speakEventToCheck [ "dotdotdot" ] ) ;
} ) ) ;
}
else
{
AlienSpeakInactive ( speakEventToCheck [ "spaceNum" ] ) ;
}
2023-03-27 03:09:55 +00:00
}
2023-09-11 22:28:04 +00:00
BeatAction . New ( this , queuedSpeaks ) ;
2023-07-12 16:49:32 +00:00
}
public override void OnGameSwitch ( double beat )
{
if ( Conductor . instance . isPlaying & & ! Conductor . instance . isPaused )
2023-03-27 03:09:55 +00:00
{
2023-07-12 16:49:32 +00:00
if ( queuedIntervals . Count > 0 )
{
foreach ( var interval in queuedIntervals )
{
SetIntervalStart ( interval . beat , interval . interval , interval . outDialogue , beat , interval . autoPassTurn ) ;
}
queuedIntervals . Clear ( ) ;
}
2023-03-27 03:09:55 +00:00
}
2023-07-12 16:49:32 +00:00
}
private void Update ( )
{
2022-07-25 02:04:55 +00:00
if ( Conductor . instance . ReportBeat ( ref lastReportedBeat , offset : liveBarBeatOffset ) )
{
2023-07-12 16:49:32 +00:00
liveBar . Play ( "liveBar" , 0 , 0 ) ;
2022-07-25 02:04:55 +00:00
}
2023-06-10 19:13:29 +00:00
else if ( Conductor . instance . songPositionInBeatsAsDouble < lastReportedBeat )
2022-07-25 02:04:55 +00:00
{
2023-06-10 19:13:29 +00:00
lastReportedBeat = Math . Round ( Conductor . instance . songPositionInBeatsAsDouble ) ;
2022-07-25 02:04:55 +00:00
}
2023-10-29 19:44:47 +00:00
if ( PlayerInput . GetIsAction ( InputAction_Press ) & & ! IsExpectingInputNow ( InputAction_Press ) )
2022-07-25 02:04:55 +00:00
{
2023-03-27 03:09:55 +00:00
if ( isSpeaking )
2022-07-25 02:04:55 +00:00
{
2024-01-20 04:05:26 +00:00
if ( noHitOnce | | callDiagIndex = = 0 )
{
2023-03-27 03:09:55 +00:00
FailContact ( ) ;
2024-01-20 04:05:26 +00:00
}
2023-03-27 03:09:55 +00:00
else
2024-01-20 04:05:26 +00:00
{
SoundByte . PlayOneShotGame ( "firstContact/ALIEN_PLAYER_A" , - 1 , SoundByte . GetPitchFromSemiTones ( UnityEngine . Random . Range ( - 3 , 3 ) , false ) ) ;
2023-03-27 03:09:55 +00:00
TrailingContact ( ) ;
2024-01-20 04:05:26 +00:00
ScoreMiss ( ) ;
}
2023-03-27 03:09:55 +00:00
}
else if ( ! noHitOnce & & ! missionControl . activeInHierarchy )
{
2024-01-20 04:05:26 +00:00
translator . DoScaledAnimationAsync ( "translator_eh" , 0.5f ) ;
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "firstContact/ALIEN_PLAYER_MISS2_A" , - 1 , SoundByte . GetPitchFromSemiTones ( UnityEngine . Random . Range ( - 2 , 1 ) , false ) ) ;
2024-01-20 04:05:26 +00:00
ScoreMiss ( ) ;
2023-03-27 03:09:55 +00:00
}
2022-07-25 02:04:55 +00:00
}
}
2023-03-27 03:09:55 +00:00
public void LiveBarBeat ( bool onBeat )
2022-07-25 02:04:55 +00:00
{
if ( onBeat )
{
liveBarBeatOffset = 0 ;
}
else
{
liveBarBeatOffset = . 5f ;
}
}
2023-03-27 03:09:55 +00:00
public void LookAtDirection ( int alienLookAt , int translatorLookAt )
2022-07-25 02:04:55 +00:00
{
switch ( alienLookAt )
{
case 0 :
2023-07-12 16:49:32 +00:00
alien . Play ( "alien_lookAt" , 0 , 0 ) ;
2022-07-25 02:04:55 +00:00
break ;
case 1 :
2023-07-12 16:49:32 +00:00
alien . Play ( "alien_idle" , 0 , 0 ) ;
2022-07-25 02:04:55 +00:00
break ;
}
switch ( translatorLookAt )
{
case 0 :
2023-07-12 16:49:32 +00:00
translator . Play ( "translator_lookAtAlien" , 0 , 0 ) ;
2022-07-25 02:04:55 +00:00
break ;
case 1 :
2023-07-12 16:49:32 +00:00
translator . Play ( "translator_idle" , 0 , 0 ) ;
2022-07-25 02:04:55 +00:00
break ;
}
2023-03-27 03:09:55 +00:00
2022-07-25 02:04:55 +00:00
}
2023-07-12 16:49:32 +00:00
private void AlienSpeak ( double beat , int spaceNum , bool hasDDD )
2022-07-25 02:04:55 +00:00
{
2023-03-27 03:09:55 +00:00
int voiceline = UnityEngine . Random . Range ( 1 , 11 ) ;
if ( voiceline = = currentVoicelineIndex ) voiceline + + ;
if ( voiceline > 10 ) voiceline = 1 ;
currentVoicelineIndex = voiceline ;
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "firstContact/Bob" + voiceline , beat , SoundByte . GetPitchFromCents ( UnityEngine . Random . Range ( - 100 , 0 ) , false ) ) ;
SoundByte . PlayOneShotGame ( "firstContact/BobB" ) ;
2023-07-12 16:49:32 +00:00
alien . DoScaledAnimationAsync ( "alien_talk" , 0.5f ) ;
if ( UnityEngine . Random . Range ( 0 , 5 ) = = 0 ) translator . DoScaledAnimationAsync ( "translator_lookAtAlien_nod" , 0.5f ) ;
alienTextbox . SetActive ( true ) ;
for ( int i = 0 ; i < spaceNum * 2 ; i + + )
{
callDiagBuffer + = " " ;
}
callDiagBuffer + = hasDDD ? MSG_MAN_DDD : MSG_MAN ;
UpdateAlienTextbox ( ) ;
}
2023-03-27 03:09:55 +00:00
2023-07-12 16:49:32 +00:00
private void AlienSpeakInactive ( int spaceNum )
{
2023-03-27 03:09:55 +00:00
alienTextbox . SetActive ( true ) ;
for ( int i = 0 ; i < spaceNum * 2 ; i + + )
2022-07-25 02:04:55 +00:00
{
2023-03-27 03:09:55 +00:00
callDiagBuffer + = " " ;
2022-07-25 02:04:55 +00:00
}
2023-03-27 03:09:55 +00:00
callDiagBuffer + = MSG_MAN ;
UpdateAlienTextbox ( ) ;
2022-07-25 02:04:55 +00:00
}
2023-07-12 16:49:32 +00:00
public void PassTurnStandalone ( double beat )
2022-07-25 02:04:55 +00:00
{
2023-07-12 16:49:32 +00:00
RiqEntity lastInterval = GetLastIntervalBeforeBeat ( beat ) ;
2023-09-08 14:27:07 +00:00
float length = EventCaller . GetAllInGameManagerList ( "firstContact" , new string [ ] { "alien turnover" } ) . Find ( x = > x . beat = = beat ) . length ;
2023-07-12 16:49:32 +00:00
if ( lastInterval = = null ) return ;
2023-09-08 14:27:07 +00:00
AlienTurnOver ( beat , lastInterval . beat , lastInterval . beat + lastInterval . length , length ) ;
2023-07-12 16:49:32 +00:00
}
2022-07-25 02:04:55 +00:00
2023-09-08 14:27:07 +00:00
private void AlienTurnOver ( double beat , double intervalBeat , double endBeat , float length )
2023-07-12 16:49:32 +00:00
{
var inputs = GetAllSpeaksInBetweenBeat ( intervalBeat , endBeat ) ;
inputs . Sort ( ( x , y ) = > x . beat . CompareTo ( y . beat ) ) ;
for ( int i = 0 ; i < inputs . Count ; i + + )
{
var input = inputs [ i ] ;
double relativeBeat = input . beat - intervalBeat ;
2024-01-20 04:05:26 +00:00
ScheduleInput ( beat , length + relativeBeat , InputAction_Press , AlienTapping , AlienOnMiss , AlienEmpty , CanAlienTapping ) ;
2024-01-14 14:24:32 +00:00
callDiagList . Add ( ( input [ "dialogue" ] , input [ "newline" ] ) ) ;
2023-03-27 03:09:55 +00:00
}
2023-09-11 22:28:04 +00:00
BeatAction . New ( this , new List < BeatAction . Action > ( )
2023-03-27 03:09:55 +00:00
{
2023-07-12 16:49:32 +00:00
new BeatAction . Action ( beat , delegate
{
isSpeaking = true ;
2024-01-20 04:05:26 +00:00
hasMissed = false ;
2023-07-12 16:49:32 +00:00
SoundByte . PlayOneShotGame ( "firstContact/turnover" ) ;
alienTextbox . SetActive ( false ) ;
alien . Play ( "alien_point" , 0 , 0 ) ;
} ) ,
2024-01-14 14:24:32 +00:00
new BeatAction . Action ( beat + ( length / 2 ) , delegate
{
alien . Play ( "alien_idle" , 0 , 0 ) ;
2023-07-12 16:49:32 +00:00
} )
} ) ;
2022-07-25 02:04:55 +00:00
}
2023-06-10 19:13:29 +00:00
public void AlienSuccess ( double beat )
2022-07-25 02:04:55 +00:00
{
string animString = "" ;
2023-03-27 03:09:55 +00:00
List < MultiSound . Sound > sound = new List < MultiSound . Sound > ( ) ;
if ( ! ( hasMissed | | noHitOnce ) )
2022-07-25 02:04:55 +00:00
{
2023-03-27 03:09:55 +00:00
sound = new List < MultiSound . Sound > ( )
{
new MultiSound . Sound ( "firstContact/successCrowd" , beat ) ,
new MultiSound . Sound ( "firstContact/nod" , beat ) ,
new MultiSound . Sound ( "firstContact/nod" , beat + 0.5f ) ,
2023-06-10 19:13:29 +00:00
new MultiSound . Sound ( "firstContact/successExtra" + UnityEngine . Random . Range ( 1 , 3 ) , beat + 0.5f , SoundByte . GetPitchFromCents ( UnityEngine . Random . Range ( - 50 , 50 ) , false ) ) ,
new MultiSound . Sound ( "firstContact/whistle" , beat + UnityEngine . Random . Range ( 0.5f , 1.5f ) , SoundByte . GetPitchFromCents ( UnityEngine . Random . Range ( - 50 , 100 ) , false ) , UnityEngine . Random . Range ( 0.4f , 1f ) ) ,
2023-03-27 03:09:55 +00:00
} ;
2022-07-25 02:04:55 +00:00
animString = "alien_success" ;
}
2023-03-27 03:09:55 +00:00
else
2022-07-25 02:04:55 +00:00
{
2023-03-27 03:09:55 +00:00
sound = new List < MultiSound . Sound > ( )
{
new MultiSound . Sound ( "firstContact/fail" , beat ) ,
new MultiSound . Sound ( "firstContact/shakeHead" , beat ) ,
new MultiSound . Sound ( "firstContact/shakeHead" , beat + 0.5f ) ,
} ;
2022-07-25 02:04:55 +00:00
animString = "alien_fail" ;
}
2023-03-27 03:09:55 +00:00
MultiSound . Play ( sound . ToArray ( ) ) ;
2022-07-25 02:04:55 +00:00
2023-09-11 22:28:04 +00:00
BeatAction . New ( this , new List < BeatAction . Action > ( )
2022-07-25 02:04:55 +00:00
{
2023-07-12 16:49:32 +00:00
new BeatAction . Action ( beat , delegate { alien . Play ( animString , 0 , 0 ) ; } ) ,
new BeatAction . Action ( beat + . 5f , delegate { alien . Play ( animString , 0 , 0 ) ; } ) ,
2023-03-27 03:09:55 +00:00
new BeatAction . Action ( beat + 1 , delegate { alienTextbox . SetActive ( false ) ; translateTextbox . SetActive ( false ) ; translateFailTextbox . SetActive ( false ) ; } )
2022-07-25 02:04:55 +00:00
} ) ;
isSpeaking = false ;
hasMissed = false ;
noHitOnce = false ;
}
2023-03-27 03:09:55 +00:00
void UpdateAlienTextbox ( )
{
alienText . text = callDiagBuffer ;
}
2024-01-14 14:24:32 +00:00
string GetMessageFromCallDialogue ( int callDiagIndex = 0 )
2023-03-27 03:09:55 +00:00
{
2024-01-14 14:24:32 +00:00
StringBuilder sb = new StringBuilder ( ) ;
for ( int i = callDiagIndex ; i < callDiagList . Count ; i + + )
2023-03-27 03:09:55 +00:00
{
2024-01-14 14:24:32 +00:00
( string s , bool showNewline ) = callDiagList [ i ] ;
if ( showNewline & & callDiagIndex ! = i )
2023-03-27 03:09:55 +00:00
{
2024-01-14 14:24:32 +00:00
break ;
2023-03-27 03:09:55 +00:00
}
2024-01-14 14:24:32 +00:00
sb . Append ( s ) ;
}
return sb . ToString ( ) ;
}
2023-03-27 03:09:55 +00:00
2024-01-14 14:24:32 +00:00
void UpdateTranslateTextbox ( )
{
if ( callDiagIndex = = 0 & & ! hasMissed & & ! noHitOnce )
{
ResetTranslateTextbox ( ) ;
2023-03-27 03:09:55 +00:00
}
translateText . text = respDiagBuffer ;
translateFailText . text = respDiagBuffer ;
}
2024-01-14 14:24:32 +00:00
void ResetTranslateTextbox ( bool destroyText = false )
{
// shift the textbox to centre the message
string message = GetMessageFromCallDialogue ( callDiagIndex ) ;
// many hardcoded values there'll be a better way to do this
Vector2 size = translateText . GetPreferredValues ( message , 10.95f , 2 ) ;
translateText . rectTransform . anchoredPosition = new Vector2 ( Mathf . Max ( ( 10.95f / 2f ) + ( - size . x / 2 - 0.25f ) , - 0.25f ) , Mathf . Max ( ( 2.11f / 2f ) + ( - size . y / 2 ) + 0.2f , 0.2f ) ) ;
if ( destroyText )
{
respDiagBuffer = "" ;
translateText . text = "" ;
}
}
2023-06-10 19:13:29 +00:00
public void MissionControlDisplay ( double beat , bool stay , float length )
2022-07-25 02:04:55 +00:00
{
missionControl . SetActive ( true ) ;
2023-03-27 03:09:55 +00:00
alienTextbox . SetActive ( false ) ;
translateTextbox . SetActive ( false ) ;
translateFailTextbox . SetActive ( false ) ;
2022-07-25 02:04:55 +00:00
string textToPut = "" ;
2023-03-27 03:09:55 +00:00
if ( ! ( hasMissed | | noHitOnce ) )
2022-07-25 02:04:55 +00:00
{
textToPut = "missionControl_success" ;
}
else
{
textToPut = "missionControl_fail" ;
}
2023-03-27 03:09:55 +00:00
missionControl . GetComponentInParent < Animator > ( ) . Play ( textToPut , 0 , 0 ) ;
2023-07-12 16:49:32 +00:00
alien . Play ( "alien_idle" , 0 , 0 ) ;
translator . Play ( "translator_idle" , 0 , 0 ) ;
2022-07-25 02:04:55 +00:00
if ( ! stay )
{
2023-09-11 22:28:04 +00:00
BeatAction . New ( instance , new List < BeatAction . Action > ( )
2022-07-25 02:04:55 +00:00
{
new BeatAction . Action ( beat + length , delegate { missionControl . SetActive ( false ) ; } ) ,
} ) ;
}
else
{
missionControl . SetActive ( true ) ;
}
isSpeaking = false ;
}
2023-03-27 03:09:55 +00:00
void FailContact ( )
2022-07-25 02:04:55 +00:00
{
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "firstContact/failContact" ) ;
2023-07-12 16:49:32 +00:00
translator . DoScaledAnimationAsync ( "translator_speak" , 0.5f ) ;
2023-03-27 03:09:55 +00:00
if ( ! hasMissed & & callDiagIndex = = 0 )
2022-07-25 02:04:55 +00:00
{
2023-03-27 03:09:55 +00:00
translateFailTextbox . SetActive ( true ) ;
respDiagBuffer = onOutDialogue ;
UpdateTranslateTextbox ( ) ;
ScoreMiss ( ) ;
}
hasMissed = true ;
}
2022-07-25 02:04:55 +00:00
2023-03-27 03:09:55 +00:00
void TrailingContact ( )
{
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "firstContact/slightlyFail" ) ;
2023-07-12 16:49:32 +00:00
translator . Play ( "translator_eh" , 0 , 0 ) ;
2023-03-27 03:09:55 +00:00
if ( ! hasMissed )
{
respDiagBuffer + = MID_MSG_MISS ;
UpdateTranslateTextbox ( ) ;
2022-07-25 02:04:55 +00:00
}
2023-03-27 03:09:55 +00:00
hasMissed = true ;
}
2024-01-20 04:05:26 +00:00
public bool CanAlienTapping ( )
2023-03-27 03:09:55 +00:00
{
2024-01-20 04:05:26 +00:00
return ! ( hasMissed | | noHitOnce ) ;
}
2023-03-27 03:09:55 +00:00
2024-01-20 04:05:26 +00:00
public void AlienTapping ( PlayerActionEvent caller , float state ) //OnHit
{
( string dialogue , bool showNewline ) = callDiagList [ callDiagIndex ] ;
translateTextbox . SetActive ( true ) ;
if ( showNewline )
2023-03-27 03:09:55 +00:00
{
2024-01-20 04:05:26 +00:00
ResetTranslateTextbox ( true ) ;
2023-03-27 03:09:55 +00:00
}
if ( state > = 1f | | state < = - 1f )
{
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "firstContact/ALIEN_PLAYER_A" , - 1 , SoundByte . GetPitchFromSemiTones ( UnityEngine . Random . Range ( - 3 , 3 ) , false ) ) ;
2023-03-27 03:09:55 +00:00
TrailingContact ( ) ;
2024-01-20 04:05:26 +00:00
callDiagIndex + + ;
2023-03-27 03:09:55 +00:00
return ;
}
2023-07-12 16:49:32 +00:00
translator . DoScaledAnimationAsync ( "translator_speak" , 0.5f ) ;
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "firstContact/ALIEN_PLAYER_A" , - 1 , SoundByte . GetPitchFromSemiTones ( UnityEngine . Random . Range ( - 3 , 3 ) , false ) ) ;
SoundByte . PlayOneShotGame ( "firstContact/ALIEN_PLAYER_B" ) ;
2024-01-20 04:05:26 +00:00
respDiagBuffer + = dialogue ;
UpdateTranslateTextbox ( ) ;
callDiagIndex + + ;
2022-07-25 02:04:55 +00:00
}
2023-03-27 03:09:55 +00:00
public void AlienOnMiss ( PlayerActionEvent caller ) //OnMiss
2022-07-25 02:04:55 +00:00
{
2024-01-20 04:05:26 +00:00
if ( ! noHitOnce & & ! hasMissed )
2022-07-25 02:04:55 +00:00
{
2023-06-10 19:13:29 +00:00
SoundByte . PlayOneShotGame ( "firstContact/alienNoHit" ) ;
2022-07-25 02:04:55 +00:00
noHitOnce = true ;
}
2023-03-27 03:09:55 +00:00
if ( callDiagIndex > 0 & & ! hasMissed )
2022-07-25 02:04:55 +00:00
{
2023-03-27 03:09:55 +00:00
respDiagBuffer + = MID_MSG_MISS ;
UpdateTranslateTextbox ( ) ;
hasMissed = true ;
}
2022-07-25 02:04:55 +00:00
2023-07-12 16:49:32 +00:00
alien . Play ( "alien_noHit" , 0 , 0 ) ;
2022-07-25 02:04:55 +00:00
}
2023-03-27 03:09:55 +00:00
public void AlienEmpty ( PlayerActionEvent caller ) { } //OnEmpty
2022-07-25 02:04:55 +00:00
}
2022-07-25 02:09:25 +00:00
}