//================================================================================ // //================================================================================ using UnityEngine; using System.Collections; using SimpleJSON; using System.Collections.Generic; using System; //================================================================================ // //================================================================================ namespace ReaderRabbit { //================================================================================ // //================================================================================ public class RaingearDescription { //================================================================================ // //================================================================================ public RaingearDescription() { GearColor = GearColor.R_COLOR; GearShape = GearShape.R_SHAPE; GearType = GearType.R_OBJECT_GEAR; } //================================================================================ // //================================================================================ public GearColor GearColor { get; set; } //================================================================================ // //================================================================================ public GearShape GearShape { get; set; } //================================================================================ // //================================================================================ public GearType GearType { get; set; } } // public class RaingearDescription //================================================================================ // //================================================================================ public class SceneRaingearRescue : SceneCommon { //================================================================================ // //================================================================================ private enum Characters { Reader = CharactersCommon.Reader, Sam = CharactersCommon.Sam, Paige = CharactersCommon.Paige, } //================================================================================ // //================================================================================ private const int WORD_LISTS_SIZE = 15; private const int NUMBER_OF_MINIGAME_LEVELS = 3; private const int NUMBER_OF_WINS_TO_END_GAME = 6; private const int SETS_PER_LEVEL_NORMAL_MODE = 2; private const int MINIMUM_TO_WIN = 10; private const int WIN_EXCELLENT = 16; private const int WIN_GOOD = 14; private const int WIN_OK = 12; //================================================================================ // //================================================================================ [SerializeField] private RaingearRescueBarrelsManager m_BarrelsManager; [SerializeField] private RaingearRescueFlagsManager m_FlagsManager; [SerializeField] private RaingearRescueObjectsSpawner m_ObjectsSpawner; [SerializeField] private RaingearRescueObjectsCounter m_ObjectsCounter; private int m_CurrentWordList; private int m_CurrentMinigameLevel; private int m_NumberOfWins; private List m_CurrentDescription; private bool m_SpeechPaigeHighlightBarrels; private bool m_HasSpeechAfterPaigeSetupLines; private int m_SpeechPaigeCurrentWordList; int lang; //================================================================================ // //================================================================================ protected override void Start() { base.Start(); //============================================================================ // //============================================================================ lang = PlayerPrefs.GetInt("language"); if (lang == 0) m_SpeechFolder = "Resources_DA/Audio/RaingearRescue_Speech"; else if (lang == 1) m_SpeechFolder = "Resources_EN/Audio/RaingearRescue_Speech"; else if (lang == 2) m_SpeechFolder = "Resources_NO/Audio/RaingearRescue_Speech"; else if (lang == 3) m_SpeechFolder = "Resources_SP/Audio/RaingearRescue_Speech"; else if (lang == 4) m_SpeechFolder = "Resources_SW/Audio/RaingearRescue_Speech"; //============================================================================ // //============================================================================ PlayerData.Instance().SetVisitedRaingearRescue(true); PlayerData.Instance().SetCurrentLocation(Location.RaingearRescue); PlayerData.Instance().UnlockActivity(Activity.RaingearRescue); AudioManager.Instance().PlayBGM("BGM_RaingearRescue"); m_CurrentWordList = 1; m_CurrentMinigameLevel = PlayerData.Instance().GetActivityLevel(Activity.RaingearRescue); m_NumberOfWins = -1; if (PlayerData.Instance().IsPracticeMode()) { m_FlagsManager.gameObject.SetActive(false); } else { m_FlagsManager.gameObject.SetActive(true); } } //================================================================================ // //================================================================================ public void LoadNextWordSet() { TextAsset jsonText = null; if (lang == 0) jsonText = Resources.Load("Resources_DA/RaingearRescue/r1la3"); else if (lang == 1) jsonText = Resources.Load("Resources_EN/RaingearRescue/r1la3"); else if (lang == 2) jsonText = Resources.Load("Resources_NO/RaingearRescue/r1la3"); else if (lang == 3) jsonText = Resources.Load("Resources_SP/RaingearRescue/r1la3"); else if (lang == 4) jsonText = Resources.Load("Resources_SW/RaingearRescue/r1la3"); JSONNode json = JSONNode.Parse(jsonText.text); int wordListSize = WORD_LISTS_SIZE; if (PlayerData.Instance().IsPracticeMode()) { if (m_CurrentWordList > wordListSize && !PlayerData.Instance().IsActivityLocked(Activity.RaingearRescue)) { m_CurrentMinigameLevel++; if (m_CurrentMinigameLevel > NUMBER_OF_MINIGAME_LEVELS) { m_CurrentMinigameLevel = NUMBER_OF_MINIGAME_LEVELS; } PlayerData.Instance().SetActivityLevel(Activity.RaingearRescue, m_CurrentMinigameLevel); m_CurrentWordList = 1; wordListSize = WORD_LISTS_SIZE; } else if (m_CurrentWordList > wordListSize && PlayerData.Instance().IsActivityLocked(Activity.RaingearRescue)) { m_CurrentWordList = 1; } } else if (m_CurrentWordList > SETS_PER_LEVEL_NORMAL_MODE && !PlayerData.Instance().IsActivityLocked(Activity.RaingearRescue)) { m_CurrentWordList = 1; m_CurrentMinigameLevel++; if (m_CurrentMinigameLevel > NUMBER_OF_MINIGAME_LEVELS) { m_CurrentMinigameLevel = NUMBER_OF_MINIGAME_LEVELS; } PlayerData.Instance().SetActivityLevel(Activity.RaingearRescue, m_CurrentMinigameLevel); } JSONNode currentLevelWordLists = json["DataSet"]["Level_" + m_CurrentMinigameLevel]; m_SpeechPaigeCurrentWordList = m_CurrentWordList - 1; m_CurrentDescription = ParseProblemDescription(currentLevelWordLists["WordList_" + m_CurrentWordList++]); m_ObjectsCounter.Reset(); m_ObjectsSpawner.Reset(); m_ObjectsSpawner.Setup(m_CurrentDescription); ShowPartialBarrelsManager(); } //================================================================================ // //================================================================================ protected override void PlayFirstEvent() { ShowCharacters(); m_SpeechPaigeHighlightBarrels = true; m_HasSpeechAfterPaigeSetupLines = true; if (m_IsFirstTime) { NewSequence(); SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27200"); SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27201"); SetSequence(2, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "27202"); SetSequence(3, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27203"); SetSequence(4, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27300"); SetSequence(5, EventSequenceItem.EventSequenceType.Callback, LoadNextWordSet); SetSequence(6, EventSequenceItem.EventSequenceType.Callback, PaigeSpeechSetupLines); StartSequence(7); } else { NewSequence(); SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27301"); SetSequence(1, EventSequenceItem.EventSequenceType.Callback, LoadNextWordSet); SetSequence(2, EventSequenceItem.EventSequenceType.Callback, PaigeSpeechSetupLines); StartSequence(3); } } //================================================================================ // //================================================================================ private void PaigeSpeechSetupLines() { Invoke("PaigeSpeechSetupLinesDelayed", 0.1f); } //================================================================================ // //================================================================================ private void PaigeSpeechSetupLinesDelayed() { int sequence = 0; NewSequence(); if (m_SpeechPaigeHighlightBarrels) SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, HighlightBarrelLeft); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "27305"); // pSayContainerAttributes. string primaryWord = RaingearRescueWords.GetPrimaryWord(m_CurrentMinigameLevel, m_SpeechPaigeCurrentWordList, BarrelPosition.LEFT_BARREL); string secondaryWord = RaingearRescueWords.GetSecondaryWord(m_CurrentMinigameLevel, m_SpeechPaigeCurrentWordList, BarrelPosition.LEFT_BARREL); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, primaryWord); if (!secondaryWord.Equals("0")) SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, secondaryWord); if (m_SpeechPaigeHighlightBarrels) SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, HighlightBarrelCenter); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "27306"); // pSayContainerAttributes. primaryWord = RaingearRescueWords.GetPrimaryWord(m_CurrentMinigameLevel, m_SpeechPaigeCurrentWordList, BarrelPosition.CENTER_BARREL); secondaryWord = RaingearRescueWords.GetSecondaryWord(m_CurrentMinigameLevel, m_SpeechPaigeCurrentWordList, BarrelPosition.CENTER_BARREL); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, primaryWord); if (!secondaryWord.Equals("0")) SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, secondaryWord); if (m_SpeechPaigeHighlightBarrels) SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, HighlightBarrelRight); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "27307"); // pSayContainerAttributes. primaryWord = RaingearRescueWords.GetPrimaryWord(m_CurrentMinigameLevel, m_SpeechPaigeCurrentWordList, BarrelPosition.RIGHT_BARREL); secondaryWord = RaingearRescueWords.GetSecondaryWord(m_CurrentMinigameLevel, m_SpeechPaigeCurrentWordList, BarrelPosition.RIGHT_BARREL); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, primaryWord); if (!secondaryWord.Equals("0")) SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, secondaryWord); if (m_HasSpeechAfterPaigeSetupLines) SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, SpeechAfterPaigeSetupLines); StartSequence(sequence); } //================================================================================ // //================================================================================ private void SpeechAfterPaigeSetupLines() { Invoke("SpeechAfterPaigeSetupLinesDelayed", 0.1f); } //================================================================================ // //================================================================================ private void SpeechAfterPaigeSetupLinesDelayed() { NewSequence(); if (m_IsFirstTime) SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27350"); else SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27351"); SetSequence(1, EventSequenceItem.EventSequenceType.Callback, DoneFirstTime); SetSequence(2, EventSequenceItem.EventSequenceType.Callback, StartSpawning); StartSequence(3); } //================================================================================ // //================================================================================ private void StartSpawning() { ShowBarrelsManager(); m_ObjectsSpawner.StartSpawning(); AudioManager.Instance().PlayBGM("BGM_RaingearRescue2"); } //================================================================================ // //================================================================================ private void HighlightBarrelLeft() { m_BarrelsManager.SetActiveBarrel(BarrelPosition.LEFT_BARREL); } //================================================================================ // //================================================================================ private void HighlightBarrelCenter() { m_BarrelsManager.SetActiveBarrel(BarrelPosition.CENTER_BARREL); } //================================================================================ // //================================================================================ private void HighlightBarrelRight() { m_BarrelsManager.SetActiveBarrel(BarrelPosition.RIGHT_BARREL); } //================================================================================ // //================================================================================ private void ShowCharacters() { m_CharacterAnimations[(int)Characters.Reader].gameObject.SetActive(true); m_CharacterAnimations[(int)Characters.Sam].gameObject.SetActive(true); m_BarrelsManager.gameObject.SetActive(false); } //================================================================================ // //================================================================================ private void ShowPartialBarrelsManager() { m_BarrelsManager.gameObject.SetActive(true); m_BarrelsManager.ShowLabels(); } //================================================================================ // //================================================================================ private void ShowBarrelsManager() { m_CharacterAnimations[(int)Characters.Reader].gameObject.SetActive(false); m_CharacterAnimations[(int)Characters.Sam].gameObject.SetActive(false); m_BarrelsManager.Center(); m_BarrelsManager.gameObject.SetActive(true); m_BarrelsManager.ShowAll(); } //================================================================================ // //================================================================================ public void RoundFinished() { ShowCharacters(); AudioManager.Instance().PlayBGM("BGM_RaingearRescue"); int sequence = 0; NewSequence(); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "27400"); if (m_ObjectsCounter.GetCurrentValue() < MINIMUM_TO_WIN) { SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27410"); int randomValue = UnityEngine.Random.Range(0, 200); if (randomValue < 50) { SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "27415"); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "27416"); } else if (randomValue < 100) { SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "27417"); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "27418"); } else if (randomValue < 150) { SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "27419"); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "27420"); } else { SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "27421"); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "27422"); } } else { ++m_NumberOfWins; m_FlagsManager.ActivateFlags(m_NumberOfWins); if (m_NumberOfWins < NUMBER_OF_WINS_TO_END_GAME) { if (m_ObjectsCounter.GetCurrentValue() < WIN_OK) SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27432"); else if (m_ObjectsCounter.GetCurrentValue() < WIN_GOOD) SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27431"); else if (m_ObjectsCounter.GetCurrentValue() < WIN_EXCELLENT) SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27430"); int randomValue = UnityEngine.Random.Range(0, 150); if (randomValue < 50) SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27450"); else if (randomValue < 100) SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "27451"); else SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27452"); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "27470"); } else { SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27480"); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "27481"); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "27482"); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Video, VideoType.EndGame); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, EndGame); } } if (m_NumberOfWins < NUMBER_OF_WINS_TO_END_GAME) { // Similar to PlayFirstEvent. m_SpeechPaigeHighlightBarrels = true; m_HasSpeechAfterPaigeSetupLines = true; SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "27301"); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, LoadNextWordSet); SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, PaigeSpeechSetupLines); } StartSequence(sequence); } //================================================================================ // //================================================================================ private void EndGame() { // TODO: Goto Credits screen with "Play again" button enabled. Also play "Congratulations" Reader speech. this.gameObject.SetActive(false); // HACK: Clear previous BGM (call twice). AudioManager.Instance().RestorePreviousBGM(); AudioManager.Instance().RestorePreviousBGM(); Options.Instance().Open(this); Options.Instance().ShowCredits(false); } //================================================================================ // //================================================================================ private List ParseProblemDescription(JSONNode description) { List result = new List(); string[] separators = { " " }; string[] tokens = description.Value.Split(separators, StringSplitOptions.RemoveEmptyEntries); List tokensList = new List(tokens); List barrelsSetupAuxList = new List(); while (tokensList.Count > 0) { RaingearDescription gearDescription = new RaingearDescription(); int numberOfElements = int.Parse(tokensList[0]); tokensList.RemoveAt(0); while (tokensList.Count > 0 && !IsNumber(tokensList[0])) { if (IsGearColor(tokensList[0])) { gearDescription.GearColor = GetGearColorPerColorName(tokensList[0]); } else if (IsGearShape(tokensList[0])) { gearDescription.GearShape = GetGearShapePerShapeName(tokensList[0]); } else if (IsGearType(tokensList[0])) { gearDescription.GearType = GetGearTypePerTypeName(tokensList[0]); } tokensList.RemoveAt(0); } for (int i = 0; i < numberOfElements; ++i) { result.Add(gearDescription); } if (barrelsSetupAuxList.Count < 3) { barrelsSetupAuxList.Add(gearDescription); } } m_BarrelsManager.Setup(barrelsSetupAuxList); return result; } //================================================================================ // //================================================================================ private GearColor GetGearColorPerColorName(string color) { if (color == "red") { return GearColor.RED_GEAR; } else if (color == "yellow") { return GearColor.YELLOW_GEAR; } else if (color == "blue") { return GearColor.BLUE_GEAR; } else if (color == "green") { return GearColor.GREEN_GEAR; } else if (color == "rcolor") { return GearColor.R_COLOR; } else { return GearColor.INVALID_GEAR_COLOR; } } //================================================================================ // //================================================================================ private GearShape GetGearShapePerShapeName(string shape) { if (shape == "trapezoid") { return GearShape.TRAPEZOID_SHAPE; } else if (shape == "triangle") { return GearShape.TRIANGLE_SHAPE; } else if (shape == "square") { return GearShape.SQUARE_SHAPE; } else if (shape == "circle") { return GearShape.CIRCLE_SHAPE; } else if (shape == "rshape") { return GearShape.R_SHAPE; } else { return GearShape.INVALID_GEAR_SHAPE; } } //================================================================================ // //================================================================================ private GearType GetGearTypePerTypeName(string type) { if (type == "coat") { return GearType.COAT_GEAR; } else if (type == "boot") { return GearType.BOOT_GEAR; } else if (type == "umbrella") { return GearType.UMBRELLA_GEAR; } else if (type == "hat") { return GearType.HAT_GEAR; } else if (type == "robject") { return GearType.R_OBJECT_GEAR; } else { return GearType.INVALID_GEAR_TYPE; } } //================================================================================ // //================================================================================ private bool IsNumber(string s) { bool result = false; for (int i = 0; i < 10; ++i) { result |= (s == i.ToString()); } return result; } //================================================================================ // //================================================================================ private bool IsGearColor(string color) { return (color == "red" || color == "yellow" || color == "blue" || color == "green" || color == "rcolor"); } //================================================================================ // //================================================================================ private bool IsGearShape(string shape) { return (shape == "trapezoid" || shape == "triangle" || shape == "square" || shape == "circle" || shape == "rshape"); } //================================================================================ // //================================================================================ private bool IsGearType(string shape) { return (shape == "coat" || shape == "boot" || shape == "hat" || shape == "umbrella" || shape == "robject"); } //================================================================================ // //================================================================================ public RaingearRescueObjectsCounter ObjectsCounter { get { return m_ObjectsCounter; } } //================================================================================ // //================================================================================ public RaingearRescueBarrelsManager BarrelsManager { get { return m_BarrelsManager; } } } // public class SceneRaingearRescue : SceneCommon } // namespace ReaderRabbit