SceneCloudSheepCrossing.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. //================================================================================
  2. //
  3. //================================================================================
  4. using UnityEngine;
  5. using System.Collections;
  6. //================================================================================
  7. //
  8. //================================================================================
  9. namespace ReaderRabbit
  10. {
  11. //================================================================================
  12. //
  13. //================================================================================
  14. public class SceneCloudSheepCrossing : SceneCommon
  15. {
  16. //================================================================================
  17. //
  18. //================================================================================
  19. private enum Characters
  20. {
  21. Reader = CharactersCommon.Reader,
  22. Sam = CharactersCommon.Sam,
  23. Paige = CharactersCommon.Paige,
  24. Chester = CharactersCommon.Chester,
  25. }
  26. //================================================================================
  27. //
  28. //================================================================================
  29. private const int SAM_WHISTLE = (int)SamAnimation.AnimationCycles.Misc1 + 1;
  30. private const int SHEEP_MAX_RATIO_100 = 8;
  31. private const int SHEEP_MAX_RATIO_125 = 10;
  32. [SerializeField] private CSC_SheepAnimation[] m_Sheeps;
  33. private bool m_IsReaderFirstClick;
  34. private bool m_IsSheepFirstClick;
  35. private const int PAIGE_MAX_CLICK_COUNT = 1;
  36. private int m_PaigeClickCount;
  37. private bool m_IsIdleRandomSpeech;
  38. private bool m_IsFirstIdle;
  39. //================================================================================
  40. //
  41. //================================================================================
  42. protected override void Start()
  43. {
  44. base.Start();
  45. //============================================================================
  46. //
  47. //============================================================================
  48. int lang = PlayerPrefs.GetInt("language");
  49. if (lang == 0)
  50. m_SpeechFolder = "Resources_DA/Audio/CloudSheepCrossing_Speech";
  51. else if (lang == 1)
  52. m_SpeechFolder = "Resources_EN/Audio/CloudSheepCrossing_Speech";
  53. else if (lang == 2)
  54. m_SpeechFolder = "Resources_NO/Audio/CloudSheepCrossing_Speech";
  55. else if (lang == 3)
  56. m_SpeechFolder = "Resources_SP/Audio/CloudSheepCrossing_Speech";
  57. else if (lang == 4)
  58. m_SpeechFolder = "Resources_SW/Audio/CloudSheepCrossing_Speech";
  59. //============================================================================
  60. //
  61. //============================================================================
  62. PlayerData.Instance().SetVisitedCloudSheepCrossing(true);
  63. PlayerData.Instance().SetCurrentLocation(Location.CloudSheepCrossing);
  64. AudioManager.Instance().PlayBGM("BGM_CloudSheepCrossing");
  65. // Always block this location.
  66. PlayerData.Instance().BlockLocation(Location.CloudSheepCrossing);
  67. UpdateOnce();
  68. if (KishiTechUnity.ScreenResolution.ScreenResolutionManager.Instance().ConversionRatio <= 1.0f)
  69. {
  70. for (int i = SHEEP_MAX_RATIO_100; i < m_Sheeps.Length; ++i)
  71. m_Sheeps[i].gameObject.SetActive(false);
  72. }
  73. else if (KishiTechUnity.ScreenResolution.ScreenResolutionManager.Instance().ConversionRatio <= 1.25f)
  74. {
  75. for (int i = SHEEP_MAX_RATIO_125; i < m_Sheeps.Length; ++i)
  76. m_Sheeps[i].gameObject.SetActive(false);
  77. }
  78. m_IsReaderFirstClick = true;
  79. m_IsSheepFirstClick = true;
  80. m_PaigeClickCount = 0;
  81. m_IsFirstIdle = true;
  82. // ******************** TODO: REMOVE ME, I'M DEBUG CODE ********************
  83. //PlayerData.Instance().SetWhistle(ItemState.Inventory);
  84. // ******************** TODO: REMOVE ME, I'M DEBUG CODE ********************
  85. }
  86. //================================================================================
  87. //
  88. //================================================================================
  89. public override void UpdateOnce()
  90. {
  91. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCloudSheepCrossing.UpdateOnce()...");
  92. // This location will always be blocked (player always need to blow the whistle).
  93. //if (PlayerData.Instance().IsLocationBlocked(Location.CloudSheepCrossing))
  94. {
  95. DisableNavigationAll();
  96. EnableNavigation("DowntownCloudNine");
  97. }
  98. }
  99. //================================================================================
  100. //
  101. //================================================================================
  102. protected override void PlayFirstEvent()
  103. {
  104. if (m_IsFirstTime)
  105. {
  106. PlayFirstDialogueFlow();
  107. }
  108. else
  109. {
  110. PlayReturnDialogueFlow();
  111. }
  112. }
  113. //================================================================================
  114. //
  115. //================================================================================
  116. void PlayFirstDialogueFlow()
  117. {
  118. NewSequence();
  119. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13150");
  120. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13151");
  121. SetSequence(2, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13152");
  122. SetSequence(3, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13153");
  123. SetSequence(4, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13154");
  124. SetSequence(5, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13201");
  125. SetSequence(6, EventSequenceItem.EventSequenceType.Callback, DoneFirstTime);
  126. StartSequence(7);
  127. }
  128. //================================================================================
  129. //
  130. //================================================================================
  131. void PlayReturnDialogueFlow()
  132. {
  133. NewSequence();
  134. if (PlayerData.Instance().GetItemState(ItemEnum.Whistle) == ItemState.Inventory)
  135. {
  136. // TODO: Original code is different.
  137. int randomValue = Random.Range(0, 100);
  138. if (randomValue < 50)
  139. {
  140. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13205");
  141. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13206");
  142. SetSequence(2, EventSequenceItem.EventSequenceType.Callback, DoneFirstTime);
  143. StartSequence(3);
  144. }
  145. else
  146. {
  147. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13207");
  148. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13168");
  149. SetSequence(2, EventSequenceItem.EventSequenceType.Callback, DoneFirstTime);
  150. StartSequence(3);
  151. }
  152. }
  153. else
  154. {
  155. int randomValue = Random.Range(0, 100);
  156. if (randomValue < 50)
  157. {
  158. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13200");
  159. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13201");
  160. SetSequence(2, EventSequenceItem.EventSequenceType.Callback, DoneFirstTime);
  161. StartSequence(3);
  162. }
  163. else
  164. {
  165. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13202");
  166. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13204");
  167. SetSequence(2, EventSequenceItem.EventSequenceType.Callback, DoneFirstTime);
  168. StartSequence(3);
  169. }
  170. }
  171. }
  172. //================================================================================
  173. //
  174. //================================================================================
  175. protected override void EnableCharacterAnimatorFirstTime()
  176. {
  177. base.EnableCharacterAnimatorFirstTime();
  178. foreach (CSC_SheepAnimation sheep in m_Sheeps)
  179. {
  180. sheep.ChangeToIdle();
  181. }
  182. }
  183. //================================================================================
  184. //
  185. //================================================================================
  186. protected override void OnRightItemUsedInScene(ItemEnum item)
  187. {
  188. // Whistle is never discarded.
  189. Chester.Instance().PutItem(ItemEnum.Whistle, null, 0.0f, 0.0f, true);
  190. if (PlayerData.Instance().IsLocationBlocked(Location.CloudSheepCrossing))
  191. {
  192. base.OnRightItemUsedInScene(item);
  193. PlayWhistle();
  194. }
  195. else
  196. {
  197. NewSequence();
  198. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "7012");
  199. StartSequence(1);
  200. }
  201. }
  202. //================================================================================
  203. //
  204. //================================================================================
  205. protected override void OnWrongItemUsedInScene(ItemEnum item)
  206. {
  207. if (PlayerData.Instance().IsLocationBlocked(Location.CloudSheepCrossing))
  208. {
  209. NewSequence();
  210. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13415");
  211. StartSequence(1);
  212. }
  213. else
  214. {
  215. base.OnWrongItemUsedInScene(item);
  216. }
  217. }
  218. //================================================================================
  219. //
  220. //================================================================================
  221. protected override void OnIdle()
  222. {
  223. if (m_IsFirstIdle && !PlayerData.Instance().DidVisitNewspaperCarrierScene())
  224. {
  225. NewSequence();
  226. if (PlayerData.Instance().GetItemState(ItemEnum.Whistle) == ItemState.Inventory)
  227. {
  228. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13251");
  229. SetSequence(1, EventSequenceItem.EventSequenceType.Callback, UpdateIdleDelay);
  230. StartSequence(2);
  231. }
  232. else
  233. {
  234. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13204");
  235. SetSequence(1, EventSequenceItem.EventSequenceType.Callback, UpdateIdleDelay);
  236. StartSequence(2);
  237. }
  238. }
  239. else
  240. {
  241. m_IsIdleRandomSpeech = true;
  242. ReaderRandomSpeech(false);
  243. }
  244. }
  245. //================================================================================
  246. //
  247. //================================================================================
  248. void PlayWhistle()
  249. {
  250. m_IsSheepFirstClick = false;
  251. PlayerData.Instance().CSC_IsFirstSheepClick = false;
  252. NewSequence();
  253. SetSequence(0, EventSequenceItem.EventSequenceType.Animation,
  254. Characters.Sam,
  255. SAM_WHISTLE,
  256. m_CharacterAnimations[(int)Characters.Sam].AnimationCyclesString[SAM_WHISTLE]);
  257. SetSequence(1, EventSequenceItem.EventSequenceType.Callback, SheepAnimation);
  258. SetSequence(2, EventSequenceItem.EventSequenceType.Callback, CheckFirstPlayWhistle);
  259. StartSequence(3);
  260. }
  261. //================================================================================
  262. //
  263. //================================================================================
  264. void SheepAnimation()
  265. {
  266. // Unblock location after player uses whistle. Unblock flag is used here only for salute animation,
  267. // since location always starts blocked.
  268. PlayerData.Instance().UnblockLocation(Location.CloudSheepCrossing);
  269. foreach (CSC_SheepAnimation sheep in m_Sheeps)
  270. {
  271. if (sheep.gameObject.activeInHierarchy)
  272. sheep.Salute();
  273. }
  274. AudioManager.Instance().PlaySFX("13080");
  275. }
  276. //================================================================================
  277. //
  278. //================================================================================
  279. void CheckFirstPlayWhistle()
  280. {
  281. Invoke("CheckFirstPlayWhistleDelayed", 1.0f);
  282. }
  283. //================================================================================
  284. //
  285. //================================================================================
  286. void CheckFirstPlayWhistleDelayed()
  287. {
  288. if (PlayerData.Instance().CSC_IsFirstWhistle)
  289. {
  290. PlayerData.Instance().CSC_IsFirstWhistle = false;
  291. NewSequence();
  292. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13410");
  293. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13411");
  294. SetSequence(2, EventSequenceItem.EventSequenceType.Callback, EnableNavigationAll);
  295. StartSequence(3);
  296. }
  297. else
  298. {
  299. EnableNavigationAll();
  300. }
  301. }
  302. //================================================================================
  303. //
  304. //================================================================================
  305. protected override void OnBlockedNavigation()
  306. {
  307. PlaySheepSpeech();
  308. }
  309. //================================================================================
  310. //
  311. //================================================================================
  312. protected override void OnOtherCharacterInteraction()
  313. {
  314. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCloudNineGateway.OnOtherCharacterInteraction()...");
  315. if (m_CurrentInteractiveRectangle.GetActionParameter(0) == "BlowSign")
  316. {
  317. // Play SoftClick SFX.
  318. AudioManager.Instance().PlaySFX("1805");
  319. NewSequence();
  320. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13154");
  321. StartSequence(1);
  322. }
  323. else if (m_CurrentInteractiveRectangle.GetActionParameter(0) == "Sheep")
  324. {
  325. if (PlayerData.Instance().IsLocationBlocked(Location.CloudSheepCrossing))
  326. PlaySheepSpeech();
  327. }
  328. }
  329. //================================================================================
  330. //
  331. //================================================================================
  332. public override void SpeechReader()
  333. {
  334. if (PlayerData.Instance().GetItemState(ItemEnum.Whistle) == ItemState.Inventory && PlayerData.Instance().CSC_IsFirstWhistle)
  335. {
  336. NewSequence();
  337. int randomValue = Random.Range(0, 100);
  338. if (randomValue < 50)
  339. {
  340. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13350");
  341. StartSequence(1);
  342. }
  343. else
  344. {
  345. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13168");
  346. StartSequence(1);
  347. }
  348. }
  349. else
  350. {
  351. if (m_IsReaderFirstClick && PlayerData.Instance().GetItemState(ItemEnum.Whistle) != ItemState.Inventory)
  352. {
  353. NewSequence();
  354. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13204");
  355. StartSequence(1);
  356. m_IsReaderFirstClick = false;
  357. }
  358. else
  359. {
  360. m_IsIdleRandomSpeech = false;
  361. ReaderRandomSpeech(true);
  362. }
  363. }
  364. }
  365. //================================================================================
  366. //
  367. //================================================================================
  368. public override void ReaderRandomSpeech(bool ignoreSomebodySpeaking)
  369. {
  370. if (ignoreSomebodySpeaking || !IsSomebodySpeaking())
  371. {
  372. int sequence = 0;
  373. NewSequence();
  374. int randomValue = Random.Range(0, 200);
  375. if (randomValue < 50)
  376. {
  377. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13267");
  378. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13268");
  379. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13269");
  380. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13270");
  381. }
  382. else if (randomValue < 100)
  383. {
  384. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13260");
  385. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13261");
  386. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13262");
  387. }
  388. else if (randomValue < 150)
  389. {
  390. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13255");
  391. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13256");
  392. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13257");
  393. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13258");
  394. }
  395. else
  396. {
  397. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13265");
  398. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13266");
  399. }
  400. if (m_IsIdleRandomSpeech)
  401. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, UpdateIdleDelay);
  402. StartSequence(sequence);
  403. }
  404. }
  405. //================================================================================
  406. //
  407. //================================================================================
  408. public override void SpeechPaige()
  409. {
  410. NewSequence();
  411. if (PlayerData.Instance().GetItemState(ItemEnum.Whistle) != ItemState.Inventory)
  412. {
  413. if (m_IsFirstTime)
  414. {
  415. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "1330" + m_PaigeClickCount.ToString());
  416. StartSequence(1);
  417. ++m_PaigeClickCount;
  418. if (m_PaigeClickCount > PAIGE_MAX_CLICK_COUNT)
  419. m_PaigeClickCount = 0;
  420. }
  421. else
  422. {
  423. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "13301");
  424. StartSequence(1);
  425. }
  426. }
  427. else
  428. {
  429. if (PlayerData.Instance().CSC_IsFirstWhistle)
  430. {
  431. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "13302");
  432. StartSequence(1);
  433. }
  434. else
  435. {
  436. string[] possibleNumbers = { "13303", "13304", "13305", "13306" };
  437. string randomPhraseNumber = possibleNumbers[Random.Range(0, possibleNumbers.Length)];
  438. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, randomPhraseNumber);
  439. StartSequence(1);
  440. }
  441. }
  442. }
  443. //================================================================================
  444. //
  445. //================================================================================
  446. void PlaySheepSpeech()
  447. {
  448. if (PlayerData.Instance().CSC_IsFirstSheepClick)
  449. {
  450. NewSequence();
  451. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13400");
  452. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13401");
  453. StartSequence(2);
  454. PlayerData.Instance().CSC_IsFirstSheepClick = false;
  455. }
  456. else
  457. {
  458. if (m_IsSheepFirstClick)
  459. {
  460. NewSequence();
  461. if (PlayerData.Instance().CSC_IsFirstWhistle)
  462. {
  463. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "13403");
  464. StartSequence(1);
  465. }
  466. else
  467. {
  468. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "13405");
  469. StartSequence(1);
  470. }
  471. m_IsSheepFirstClick = false;
  472. }
  473. else
  474. {
  475. SpeechReader();
  476. }
  477. }
  478. }
  479. } // public class SceneCloudSheepCrossing : SceneCommon
  480. } // namespace ReaderRabbit