SceneRaingearForestMath.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. //================================================================================
  2. //
  3. //================================================================================
  4. using UnityEngine;
  5. using System.Collections;
  6. using SimpleJSON;
  7. //================================================================================
  8. //
  9. //================================================================================
  10. namespace ReaderRabbit
  11. {
  12. //================================================================================
  13. //
  14. //================================================================================
  15. public class SceneRaingearForestMath : SceneCommon
  16. {
  17. //================================================================================
  18. //
  19. //================================================================================
  20. private enum Characters
  21. {
  22. Reader = CharactersCommon.Reader,
  23. Sam = CharactersCommon.Sam,
  24. Paige = CharactersCommon.Paige,
  25. Chester = CharactersCommon.Chester,
  26. Squirrel = CharactersCommon.StartSceneSpecific,
  27. Tree,
  28. }
  29. //================================================================================
  30. //
  31. //================================================================================
  32. private const int SAM_EAT_ANIMATION = (int)SamAnimation.AnimationCycles.Misc1 + 1;
  33. private const int WORD_LIST_1_SIZE = 11;
  34. private const int WORD_LIST_2_SIZE = 12;
  35. private const int WORD_LIST_3_SIZE = 16;
  36. private const int WORD_LIST_1_NON_PRACTICE_SIZE = 3;
  37. private const int NUMBER_OF_MINIGAME_LEVELS = 3;
  38. private const int NUMBER_OF_WINS_TO_GIVE_MARBLE = 3;
  39. public int INITIAL_NUMBER_SPEECH_ID = 0;
  40. public int NUMBER_ZERO_SPEECH_ID = 0;
  41. public int OP_PLUS_SPEECH_ID = 0;
  42. public int OP_MINUS_SPEECH_ID = 0;
  43. public int OP_EQUAL_SPEECH_ID = 0;
  44. /*private const int INITIAL_NUMBER_SPEECH_ID = 2748;
  45. private const int NUMBER_ZERO_SPEECH_ID = 2867;
  46. private const int OP_PLUS_SPEECH_ID = 18170;
  47. private const int OP_MINUS_SPEECH_ID = 18171;
  48. private const int OP_EQUAL_SPEECH_ID = 18172;*/
  49. //================================================================================
  50. //
  51. //================================================================================
  52. private enum SpeechEquationState
  53. {
  54. None = 0,
  55. MustReadRight,
  56. MustGetNextTree,
  57. }
  58. //================================================================================
  59. //
  60. //================================================================================
  61. [SerializeField] private CollectableMarble m_Marble;
  62. [SerializeField] private PrizeNut m_PrizeNut;
  63. [SerializeField] private TreeManager m_TreeManager;
  64. [SerializeField] private BoxCollider2D m_ScreenBlocker;
  65. private int m_CurrentMinigameLevel;
  66. private int m_CurrentWordList;
  67. private int m_WinsCount;
  68. private bool m_DidHearSubtractionInstructions;
  69. private bool m_NutClicked;
  70. private int m_SquirrelClickCount;
  71. private bool m_HeardCorrectLeft;
  72. private bool m_HeardCorrectRight;
  73. private bool m_IsFirstPlayAfterEntry;
  74. private SpeechEquationState m_SpeechEquationState;
  75. //================================================================================
  76. //
  77. //================================================================================
  78. protected override void Start()
  79. {
  80. base.Start();
  81. //============================================================================
  82. //
  83. //============================================================================
  84. int lang = PlayerPrefs.GetInt("language");
  85. if (lang == 0)
  86. m_SpeechFolder = "Resources_DA/Audio/RaingearForestMath_Speech";
  87. else if (lang == 1)
  88. m_SpeechFolder = "Resources_EN/Audio/RaingearForestMath_Speech";
  89. else if (lang == 2)
  90. m_SpeechFolder = "Resources_NO/Audio/RaingearForestMath_Speech";
  91. else if (lang == 3)
  92. m_SpeechFolder = "Resources_SP/Audio/RaingearForestMath_Speech";
  93. else if (lang == 4)
  94. m_SpeechFolder = "Resources_SW/Audio/RaingearForestMath_Speech";
  95. //============================================================================
  96. //
  97. //============================================================================
  98. PlayerData.Instance().SetVisitedRaingearForestMath(true);
  99. PlayerData.Instance().SetCurrentLocation(Location.RaingearForestMath);
  100. PlayerData.Instance().UnlockActivity(Activity.RaingearForestMath);
  101. AudioManager.Instance().PlayBGM("BGM_RaingearForestMath");
  102. this.m_CurrentMinigameLevel = PlayerData.Instance().GetActivityLevel(Activity.RaingearForestMath);
  103. this.m_CurrentWordList = 0;
  104. m_Marble.SetParentScene(this);
  105. KishiTechUnity.ScreenResolution.ScreenResolutionManager.Instance().ForceUpdateGameObject(m_Marble.gameObject, false);
  106. KishiTechUnity.ScreenResolution.ScreenResolutionManager.Instance().ForceUpdateGameObject(m_PrizeNut.gameObject);
  107. KishiTechUnity.ScreenResolution.ScreenResolutionManager.Instance().ForceUpdateGameObject(m_CharacterAnimations[(int)Characters.Tree].gameObject);
  108. m_IsFirstPlayAfterEntry = true;
  109. Invoke("LoadNextLevel", 0.01f);
  110. Invoke("EnableInput", 0.1f);
  111. m_WinsCount = 0;
  112. m_DidHearSubtractionInstructions = false;
  113. m_NutClicked = false;
  114. m_SquirrelClickCount = 0;
  115. m_HeardCorrectLeft = false;
  116. m_HeardCorrectRight = false;
  117. m_SpeechEquationState = SpeechEquationState.None;
  118. }
  119. //================================================================================
  120. //
  121. //================================================================================
  122. private void LoadNextLevel()
  123. {
  124. TextAsset jsonText = Resources.Load<TextAsset>("Resources_EN/RaingearForestMath/r1ia1");
  125. JSONNode json = JSONNode.Parse(jsonText.text);
  126. JSONNode currentLevelWordLists = json["DataSet"]["Level_"+m_CurrentMinigameLevel];
  127. int wordListSize = GetCurrentWordListSize();
  128. m_CurrentWordList++;
  129. if (m_CurrentWordList >= wordListSize) //if (m_CurrentWordList > wordListSize)
  130. {
  131. m_CurrentWordList = 1;
  132. //Updates mini-game's next level
  133. if (m_CurrentWordList < wordListSize && !PlayerData.Instance().IsActivityLocked(Activity.RaingearForestMath)) //if (m_CurrentWordList > wordListSize && !PlayerData.Instance().IsActivityLocked(Activity.RaingearForestMath))
  134. {
  135. m_CurrentMinigameLevel++;
  136. if (m_CurrentMinigameLevel > wordListSize)
  137. {
  138. m_CurrentMinigameLevel = NUMBER_OF_MINIGAME_LEVELS;
  139. }
  140. PlayerData.Instance().SetActivityLevel(Activity.RaingearForestMath, m_CurrentMinigameLevel);
  141. }
  142. }
  143. //Get a random word list set
  144. JSONNode selectedWordList = currentLevelWordLists["WordList_" + m_CurrentWordList];
  145. JSONNode wordListSet = selectedWordList["Set_" + Random.Range(1, 4)];
  146. this.m_TreeManager.Reset();
  147. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Set: " + wordListSet.Value);
  148. m_TreeManager.ReleaseBox(true);
  149. SetupBoxes(wordListSet);
  150. DoResetSpeech();
  151. }
  152. //================================================================================
  153. //
  154. //================================================================================
  155. private void SetupBoxes(JSONNode wordListSet)
  156. {
  157. char[] tokensSeparators = {' '};
  158. string[] tokens = wordListSet.Value.Split(tokensSeparators, System.StringSplitOptions.RemoveEmptyEntries);
  159. m_TreeManager.SetupBoxes(tokens);
  160. }
  161. //================================================================================
  162. //
  163. //================================================================================
  164. private int GetCurrentWordListSize()
  165. {
  166. int wordListSize = 0;
  167. //Check number of word lists
  168. if (m_CurrentMinigameLevel == 1)
  169. {
  170. if (!PlayerData.Instance().IsPracticeMode() && !PlayerData.Instance().IsActivityLocked(Activity.RaingearForestMath))
  171. {
  172. wordListSize = WORD_LIST_1_NON_PRACTICE_SIZE;
  173. }
  174. else
  175. {
  176. wordListSize = WORD_LIST_1_SIZE;
  177. }
  178. }
  179. else if (m_CurrentMinigameLevel == 2)
  180. {
  181. wordListSize = WORD_LIST_2_SIZE;
  182. }
  183. else
  184. {
  185. wordListSize = WORD_LIST_3_SIZE;
  186. }
  187. return wordListSize;
  188. }
  189. //================================================================================
  190. //
  191. //================================================================================
  192. public void EnableInput()
  193. {
  194. m_ScreenBlocker.enabled = false;
  195. }
  196. //================================================================================
  197. //
  198. //================================================================================
  199. public void DisableInput()
  200. {
  201. m_ScreenBlocker.enabled = true;
  202. }
  203. //================================================================================
  204. //
  205. //================================================================================
  206. public void GivePrize()
  207. {
  208. DisableInput();
  209. // Play kCorrectSFX.
  210. AudioManager.Instance().PlaySFX("18310");
  211. string[] possibleNumbers = { "18300", "18301", "18302", "18303", "18304" };
  212. int sequence = 0;
  213. NewSequence();
  214. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, possibleNumbers[Random.Range(0, possibleNumbers.Length)]);
  215. if (!PlayerData.Instance().IsPracticeMode())
  216. {
  217. ++PlayerData.Instance().RFM_RoundsCompleted;
  218. ++m_WinsCount;
  219. if (m_WinsCount == NUMBER_OF_WINS_TO_GIVE_MARBLE)
  220. {
  221. if (m_Marble.IsEnabled())
  222. {
  223. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18313");
  224. }
  225. else
  226. {
  227. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18312");
  228. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, GiveMarble);
  229. }
  230. }
  231. else
  232. {
  233. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18311");
  234. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, GiveNut);
  235. }
  236. }
  237. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, ReadBothEquations);
  238. StartSequence(sequence);
  239. }
  240. //================================================================================
  241. //
  242. //================================================================================
  243. private void ReadBothEquations()
  244. {
  245. Invoke("ReadBothEquationsDelayed", 0.1f);
  246. }
  247. //================================================================================
  248. //
  249. //================================================================================
  250. private void ReadBothEquationsDelayed()
  251. {
  252. m_SpeechEquationState = SpeechEquationState.MustReadRight;
  253. SpeechEquation(true);
  254. }
  255. //================================================================================
  256. //
  257. //================================================================================
  258. private void GetNextTree()
  259. {
  260. Invoke("GetNextTreeDelayed", 0.1f);
  261. }
  262. //================================================================================
  263. //
  264. //================================================================================
  265. private void GetNextTreeDelayed()
  266. {
  267. int sequence = 0;
  268. NewSequence();
  269. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18315");
  270. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, PrepareTreeAnimation);
  271. SetSequence(sequence++,
  272. EventSequenceItem.EventSequenceType.Animation,
  273. Characters.Tree,
  274. 1,
  275. m_CharacterAnimations[(int)Characters.Tree].AnimationCyclesString[1]);
  276. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, FinishTreeAnimation);
  277. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, LoadNextLevel);
  278. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, EnableInput);
  279. StartSequence(sequence);
  280. }
  281. //================================================================================
  282. //
  283. //================================================================================
  284. private void PrepareTreeAnimation()
  285. {
  286. m_TreeManager.gameObject.SetActive(false);
  287. m_CharacterAnimations[(int)Characters.Tree].gameObject.SetActive(true);
  288. }
  289. //================================================================================
  290. //
  291. //================================================================================
  292. private void FinishTreeAnimation()
  293. {
  294. m_TreeManager.gameObject.SetActive(true);
  295. m_CharacterAnimations[(int)Characters.Tree].gameObject.SetActive(false);
  296. }
  297. //================================================================================
  298. //
  299. //================================================================================
  300. private void GiveMarble()
  301. {
  302. // TODO: Play kMarbleSFX and marble animation.
  303. m_Marble.gameObject.SetActive(true);
  304. m_Marble.Enable();
  305. m_WinsCount = 0;
  306. }
  307. //================================================================================
  308. //
  309. //================================================================================
  310. private void GiveNut()
  311. {
  312. m_PrizeNut.gameObject.SetActive(true);
  313. m_PrizeNut.isCollected = false;
  314. m_PrizeNut.Enable();
  315. }
  316. //================================================================================
  317. //
  318. //================================================================================
  319. public void OnMouseDown()
  320. {
  321. m_TreeManager.ReturnBoxToBranch();
  322. }
  323. //================================================================================
  324. //
  325. //================================================================================
  326. protected override void PlayFirstEvent()
  327. {
  328. if (!PlayerData.Instance().IsPracticeMode())
  329. {
  330. if (m_IsFirstTime)
  331. {
  332. int sequence = 0;
  333. NewSequence();
  334. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18303");
  335. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18454");
  336. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "18455");
  337. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18456");
  338. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18457");
  339. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "18458");
  340. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18471");
  341. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18472");
  342. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, m_TreeManager.AnimateLeftBranchUp);
  343. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, m_TreeManager.AnimateRightBranchUp);
  344. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18460");
  345. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "18461");
  346. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, DoneFirstTime);
  347. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, CheckIfSubtraction);
  348. StartSequence(sequence);
  349. }
  350. else
  351. {
  352. int sequence = 0;
  353. NewSequence();
  354. string[] possibleNumbers = { "18250", "18251", "18252" };
  355. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, possibleNumbers[Random.Range(0, possibleNumbers.Length)]);
  356. // Play the following sequence 50% of the time.
  357. int randomValue = Random.Range(0, 100);
  358. if (randomValue < 50)
  359. {
  360. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "18260");
  361. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "18261");
  362. }
  363. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, DoneFirstTime);
  364. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, CheckIfSubtraction);
  365. StartSequence(sequence);
  366. }
  367. }
  368. else
  369. {
  370. SquirrelSpeech(true);
  371. }
  372. }
  373. //================================================================================
  374. //
  375. //================================================================================
  376. private void CheckIfSubtraction()
  377. {
  378. if (!m_TreeManager.CurrentOperationIsSum)
  379. {
  380. Invoke("DoSubtractionSpeech", 0.1f);
  381. }
  382. }
  383. //================================================================================
  384. //
  385. //================================================================================
  386. private void DoSubtractionSpeech()
  387. {
  388. NewSequence();
  389. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18340");
  390. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18341");
  391. // Subtraction speech is non-interruptible for the first subtraction problem per entry.
  392. StartSequence(2, m_DidHearSubtractionInstructions);
  393. m_DidHearSubtractionInstructions = true;
  394. }
  395. //================================================================================
  396. //
  397. //================================================================================
  398. protected override void OnNavigation()
  399. {
  400. string[] bye1 = { "18104", "18105" };
  401. string[] bye2 = { "18106", "18107", "18108" };
  402. NewSequence();
  403. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, bye1[Random.Range(0, bye1.Length)]);
  404. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, bye2[Random.Range(0, bye2.Length)]);
  405. SetSequence(2, EventSequenceItem.EventSequenceType.Callback, base.OnNavigation);
  406. StartSequence(3);
  407. }
  408. //================================================================================
  409. //
  410. //================================================================================
  411. protected override void OnIdle()
  412. {
  413. NewSequence();
  414. int randomValue = Random.Range(0, 150);
  415. if (randomValue < 50)
  416. {
  417. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18400");
  418. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18402");
  419. StartSequence(2);
  420. }
  421. else if (randomValue < 100)
  422. {
  423. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18403");
  424. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18404");
  425. StartSequence(2);
  426. }
  427. else
  428. {
  429. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "18405");
  430. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "18406");
  431. StartSequence(2);
  432. }
  433. }
  434. //================================================================================
  435. //
  436. //================================================================================
  437. public override void SpeechReader()
  438. {
  439. NewSequence();
  440. int randomValue = Random.Range(0, 200);
  441. if (randomValue < 50)
  442. {
  443. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "18405");
  444. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "18406");
  445. StartSequence(2);
  446. }
  447. else if (randomValue < 100)
  448. {
  449. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "18555");
  450. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18403");
  451. SetSequence(2, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18404");
  452. StartSequence(3);
  453. }
  454. else if (randomValue < 150)
  455. {
  456. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "18560");
  457. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18561");
  458. SetSequence(2, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18337");
  459. StartSequence(3);
  460. }
  461. else
  462. {
  463. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "18570");
  464. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18571");
  465. StartSequence(2);
  466. }
  467. }
  468. //================================================================================
  469. //
  470. //================================================================================
  471. public override void SpeechPaige()
  472. {
  473. string[] possibleNumbers = { "18501", "18502", "18503", "18504", "18505", "18506" };
  474. int randomValue = Random.Range(0, m_TreeManager.CurrentOperationIsSum ? possibleNumbers.Length - 1: possibleNumbers.Length);
  475. NewSequence();
  476. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, possibleNumbers[randomValue]);
  477. StartSequence(1);
  478. }
  479. //================================================================================
  480. //
  481. //================================================================================
  482. protected override void OnOtherCharacterInteraction()
  483. {
  484. if (m_CurrentInteractiveRectangle.GetActionParameter(0) == "Squirrel")
  485. SquirrelSpeech(false);
  486. else if (m_CurrentInteractiveRectangle.GetActionParameter(0) == "Target")
  487. SpeechTarget();
  488. else if (m_CurrentInteractiveRectangle.GetActionParameter(0) == "Equation1")
  489. {
  490. m_SpeechEquationState = SpeechEquationState.None;
  491. SpeechEquation(true);
  492. }
  493. else if (m_CurrentInteractiveRectangle.GetActionParameter(0) == "Equation2")
  494. {
  495. m_SpeechEquationState = SpeechEquationState.None;
  496. SpeechEquation(false);
  497. }
  498. }
  499. //================================================================================
  500. //
  501. //================================================================================
  502. private void SquirrelSpeech(bool fromPlayFirstEvent)
  503. {
  504. string[] possibleNumbers = { "18470", "18471", "18472", "18473", "18474" };
  505. int sequence = 0;
  506. NewSequence();
  507. int randomValue = Random.Range(0, 100);
  508. if (randomValue < 50)
  509. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, possibleNumbers[0]);
  510. int tempSpeechIndex = m_SquirrelClickCount + 1;
  511. if (m_CurrentMinigameLevel > 1)
  512. {
  513. if (tempSpeechIndex == 1)
  514. {
  515. ++m_SquirrelClickCount;
  516. tempSpeechIndex = m_SquirrelClickCount + 1;
  517. }
  518. }
  519. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, possibleNumbers[tempSpeechIndex]);
  520. if (fromPlayFirstEvent)
  521. {
  522. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, DoneFirstTime);
  523. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, CheckIfSubtraction);
  524. }
  525. StartSequence(sequence);
  526. ++m_SquirrelClickCount;
  527. if (PlayerData.Instance().IsPracticeMode())
  528. {
  529. if (m_SquirrelClickCount == 2)
  530. m_SquirrelClickCount = 0;
  531. }
  532. else
  533. {
  534. if (m_SquirrelClickCount == 3)
  535. m_SquirrelClickCount = 0;
  536. }
  537. }
  538. //================================================================================
  539. //
  540. //================================================================================
  541. private void SpeechTarget()
  542. {
  543. int speechId = (INITIAL_NUMBER_SPEECH_ID + m_TreeManager.ExpectedResult) - 1;
  544. NewSequence();
  545. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, speechId.ToString());
  546. StartSequence(1);
  547. }
  548. //================================================================================
  549. //
  550. //================================================================================
  551. private void SpeechEquation(bool isLeftEquation)
  552. {
  553. int sequence = 0;
  554. NewSequence();
  555. int number1 = (INITIAL_NUMBER_SPEECH_ID + m_TreeManager.GetEquationValue(isLeftEquation, 1)) - 1;
  556. int number2 = (INITIAL_NUMBER_SPEECH_ID + m_TreeManager.GetEquationValue(isLeftEquation, 2)) - 1;
  557. int number3 = (INITIAL_NUMBER_SPEECH_ID + m_TreeManager.GetEquationValue(isLeftEquation, 3)) - 1;
  558. int total = (INITIAL_NUMBER_SPEECH_ID + m_TreeManager.GetEquationValue(isLeftEquation, 4)) - 1;
  559. if (m_TreeManager.GetEquationValue(isLeftEquation, 1) == 0)
  560. number1 = NUMBER_ZERO_SPEECH_ID;
  561. if (m_TreeManager.GetEquationValue(isLeftEquation, 2) == 0)
  562. number2 = NUMBER_ZERO_SPEECH_ID;
  563. if (m_TreeManager.GetEquationValue(isLeftEquation, 3) == 0)
  564. number3 = NUMBER_ZERO_SPEECH_ID;
  565. if (m_TreeManager.GetEquationValue(isLeftEquation, 4) == 0)
  566. total = NUMBER_ZERO_SPEECH_ID;
  567. if (m_TreeManager.CurrentOperationIsSum)
  568. {
  569. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, number1.ToString());
  570. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, OP_PLUS_SPEECH_ID.ToString());
  571. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, number2.ToString());
  572. // Level 1 has hidden values (uses only two boxes, not three).
  573. if (!m_TreeManager.IsSmallOperation)
  574. {
  575. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, OP_PLUS_SPEECH_ID.ToString());
  576. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, number3.ToString());
  577. }
  578. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, OP_EQUAL_SPEECH_ID.ToString());
  579. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, total.ToString());
  580. }
  581. else
  582. {
  583. // If second slot is empty ("_") then play kBlankSFX (18173).
  584. if (m_TreeManager.GetEquationValue(isLeftEquation, 2) == -1)
  585. number2 = 18173;
  586. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, number1.ToString());
  587. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, OP_MINUS_SPEECH_ID.ToString());
  588. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, number2.ToString());
  589. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, OP_EQUAL_SPEECH_ID.ToString());
  590. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, total.ToString());
  591. }
  592. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, SpeechEquationFinished);
  593. StartSequence(sequence);
  594. }
  595. //================================================================================
  596. //
  597. //================================================================================
  598. private void SpeechEquationFinished()
  599. {
  600. Invoke("SpeechEquationFinishedDelayed", 0.1f);
  601. }
  602. //================================================================================
  603. //
  604. //================================================================================
  605. private void SpeechEquationFinishedDelayed()
  606. {
  607. switch (m_SpeechEquationState)
  608. {
  609. case SpeechEquationState.None:
  610. break;
  611. case SpeechEquationState.MustReadRight:
  612. m_SpeechEquationState = SpeechEquationState.MustGetNextTree;
  613. SpeechEquation(false);
  614. break;
  615. case SpeechEquationState.MustGetNextTree:
  616. m_SpeechEquationState = SpeechEquationState.None;
  617. GetNextTree();
  618. break;
  619. }
  620. }
  621. //================================================================================
  622. //
  623. //================================================================================
  624. public void GetMarble()
  625. {
  626. // Play kCOMPickUpSfxID.
  627. AudioManager.Instance().PlaySFX("1802");
  628. NewSequence();
  629. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "18600");
  630. SetSequence(1, EventSequenceItem.EventSequenceType.Callback, m_Marble.DoAction);
  631. if (m_Marble.IsEnabled()){
  632. m_Marble.SetEnable(false);
  633. }
  634. StartSequence(2);
  635. }
  636. //================================================================================
  637. //
  638. //================================================================================
  639. public void GetNut()
  640. {
  641. // Play kCOMPickUpSfxID.
  642. AudioManager.Instance().PlaySFX("1802");
  643. int sequence = 0;
  644. NewSequence();
  645. if (!m_NutClicked)
  646. {
  647. m_NutClicked = true;
  648. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18615");
  649. }
  650. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, m_PrizeNut.DoAction);
  651. SetSequence(sequence++,
  652. EventSequenceItem.EventSequenceType.Animation,
  653. Characters.Sam,
  654. SAM_EAT_ANIMATION,
  655. m_CharacterAnimations[(int)Characters.Sam].AnimationCyclesString[SAM_EAT_ANIMATION]);
  656. string[] possibleNumbers = { "18611", "18612", "18613", "18614" };
  657. int randomValue = Random.Range(0, possibleNumbers.Length);
  658. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, possibleNumbers[randomValue]);
  659. StartSequence(sequence);
  660. }
  661. //================================================================================
  662. //
  663. //================================================================================
  664. public void ResetCorrectFeedbackFlag(bool isLeftBranch)
  665. {
  666. if (isLeftBranch)
  667. m_HeardCorrectLeft = false;
  668. else
  669. m_HeardCorrectRight = false;
  670. }
  671. //================================================================================
  672. //
  673. //================================================================================
  674. public void FeedbackIfCorrect(bool isLeftBranch, int value)
  675. {
  676. if (value == m_TreeManager.ExpectedResult)
  677. {
  678. if (isLeftBranch && !m_HeardCorrectLeft)
  679. {
  680. m_HeardCorrectLeft = true;
  681. AudioManager.Instance().PlaySFX("18310");
  682. }
  683. else if (!isLeftBranch && !m_HeardCorrectRight)
  684. {
  685. m_HeardCorrectRight = true;
  686. AudioManager.Instance().PlaySFX("18310");
  687. }
  688. }
  689. }
  690. //================================================================================
  691. //
  692. //================================================================================
  693. public void FeedbackIfIncorrect(bool isLeftBranch, int value, int boxCount)
  694. {
  695. if (m_TreeManager.CurrentOperationIsSum)
  696. {
  697. // Only give feedback if there is enough boxes on branches (based on current level).
  698. if (boxCount >= m_CurrentMinigameLevel)
  699. {
  700. if (value > m_TreeManager.ExpectedResult)
  701. {
  702. // Play kWrongSfxID.
  703. AudioManager.Instance().PlaySFX("18374");
  704. NewSequence();
  705. // Heavy speeches 50%.
  706. int randomValue = Random.Range(0, 100);
  707. if (randomValue < 50)
  708. {
  709. randomValue = Random.Range(0, 100);
  710. if (randomValue < 50)
  711. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18350");
  712. else
  713. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18351");
  714. StartSequence(1);
  715. }
  716. }
  717. else if (value < m_TreeManager.ExpectedResult)
  718. {
  719. // Play kWrongSfxID.
  720. AudioManager.Instance().PlaySFX("18374");
  721. NewSequence();
  722. // Light speeches 50%.
  723. int randomValue = Random.Range(0, 100);
  724. if (randomValue < 50)
  725. {
  726. randomValue = Random.Range(0, 100);
  727. if (randomValue < 50)
  728. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18360");
  729. else
  730. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18361");
  731. StartSequence(1);
  732. }
  733. }
  734. }
  735. }
  736. else
  737. {
  738. if (value != m_TreeManager.ExpectedResult)
  739. {
  740. // Play kWrongSfxID.
  741. AudioManager.Instance().PlaySFX("18374");
  742. string[] possibleNumbers = { "18370", "18371", "18372", "18373" };
  743. NewSequence();
  744. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, possibleNumbers[Random.Range(0, possibleNumbers.Length)]);
  745. //SetSequence(1, EventSequenceItem.EventSequenceType.Callback, m_TreeManager.ReturnBoxToBranch);
  746. // Wait for a brief moment and then put the basket back in the tree.
  747. // This is done already!
  748. StartSequence(1);
  749. }
  750. }
  751. }
  752. //================================================================================
  753. //
  754. //================================================================================
  755. private void DoResetSpeech()
  756. {
  757. // Do not play this sfx the first time.
  758. if (!m_IsFirstPlayAfterEntry)
  759. AudioManager.Instance().PlaySFX("18345");
  760. else
  761. m_IsFirstPlayAfterEntry = false;
  762. int sequence = 0;
  763. NewSequence();
  764. if (PlayerData.Instance().RFM_RoundsCompleted < 7)
  765. {
  766. string[] possibleNumbers = { "18325", "18326", "18327", "18328" };
  767. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, possibleNumbers[Random.Range(0, possibleNumbers.Length)]);
  768. }
  769. if (PlayerData.Instance().RFM_RoundsCompleted == 1)
  770. {
  771. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "18330");
  772. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18331");
  773. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18332");
  774. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18333");
  775. }
  776. else if (PlayerData.Instance().RFM_RoundsCompleted == 2)
  777. {
  778. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "18335");
  779. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18336");
  780. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Squirrel, "18337");
  781. }
  782. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, CheckIfSubtraction);
  783. StartSequence(sequence);
  784. }
  785. } // public class SceneRaingearForestMath : SceneCommon
  786. } // namespace ReaderRabbit