GameController.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using FairyGUI;
  2. using UnityEngine;
  3. using ET;
  4. using System.Threading.Tasks;
  5. namespace GFGGame
  6. {
  7. public class GameController
  8. {
  9. public static async ET.ETTask Start()
  10. {
  11. await LoginController.CheckVersion();
  12. CheckShowLoginView();
  13. }
  14. private static void CheckShowLoginView()
  15. {
  16. LauncherView.Instance.Close();
  17. ViewManager.Show<LoginView>();
  18. }
  19. public static bool CheckLoginCache(bool doLogin)
  20. {
  21. string account = PlayerPrefs.GetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, null);
  22. string password = PlayerPrefs.GetString(GameConst.PASSWORD_LAST_LOGIN_KEY, null);
  23. bool lastLoginIsVisitor = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, false);
  24. if (lastLoginIsVisitor)
  25. {
  26. long id = (long)PlayerPrefs.GetFloat(GameConst.VISITOR_ID_KEY, -1);
  27. if (id >= 0)
  28. {
  29. if (doLogin)
  30. {
  31. //LoginProxy.LoginAsVisitor();
  32. }
  33. return true;
  34. }
  35. }
  36. else if (!string.IsNullOrEmpty(account))
  37. {
  38. if (!string.IsNullOrEmpty(password))
  39. {
  40. if (doLogin)
  41. {
  42. LoginController.Login(account, password, true).Coroutine();
  43. }
  44. return true;
  45. }
  46. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL && PlayerPrefs.HasKey(GameConst.PASSWORD_LAST_LOGIN_KEY))
  47. {
  48. if (doLogin)
  49. {
  50. LoginController.LoginTest(account).Coroutine();
  51. }
  52. return true;
  53. }
  54. }
  55. return false;
  56. }
  57. public static void CheckSpecialAccount(string account)
  58. {
  59. GameGlobal.antiAddiction = !(account.IndexOf("sygfg") == 0);
  60. }
  61. public static void ShowCreateRole()
  62. {
  63. ViewManager.Show(ViewName.CREATE_ROLE_VIEW);
  64. }
  65. public static async Task PreEnterGameAsync()
  66. {
  67. //RoleInfo roleInfo = null;
  68. GetSuitItemController.enable = false;
  69. //roleInfo = result.roleInfo;
  70. //bool rerult = AntiAddictionController.CheckAntiAddiction(roleInfo.onlineTimeSecs, roleInfo.onlineDurationSecs, roleInfo.onlineDurationSecsDay);
  71. //if (rerult)
  72. //{
  73. // return;
  74. //}
  75. //ServerDataManager.SetServerTime(roleInfo.serverTime);
  76. RoleDataManager.InitServerData();
  77. //ItemDataManager.InitServerData(result.roleItemList);
  78. //CustomSuitDataManager.InitServerData(roleInfo.suitIndex, result.roleSuitList);
  79. //StoryDataManager.InitServerData(roleInfo);
  80. //GuideDataManager.InitServerData(result.roleGuideList);
  81. //CardDataManager.InitServerData(result.roleCardList);
  82. //SkillDataManager.Instance.InitServerData(result.roleSkillList);
  83. //SkillDataManager.Instance.SetDicPassivitySkillCfg();
  84. GetSuitItemController.enable = true;
  85. RoleDataHandler.StartUpdate();
  86. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("CommonGame"));
  87. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Main"));
  88. InstanceZonesSProxy.GetInstanceZonesInfos().Coroutine();
  89. await StorageSProxy.ReqGetClientValues();
  90. int skipGuide = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_SKIP_GUIDE);
  91. if (skipGuide <= 0)
  92. {
  93. Alert.Show("是否跳过引导?如果您是第一次体验,建议不要跳过引导!")
  94. .SetLeftButton(true, "不用", (obj) =>
  95. {
  96. EnterGame();
  97. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 1).Coroutine();
  98. })
  99. .SetRightButton(true, "跳过", (obj) =>
  100. {
  101. GameGlobal.skipGuide = true;
  102. EnterGame();
  103. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 2).Coroutine();
  104. });
  105. }
  106. else
  107. {
  108. if (skipGuide == 2) GameGlobal.skipGuide = true;
  109. EnterGame();
  110. }
  111. }
  112. public static void QuitToLoginView(bool logout)
  113. {
  114. GetSuitItemController.enable = false;
  115. GameGlobal.isVisitor = false;
  116. GameGlobal.antiAddiction = true;
  117. GameGlobal.userId = 0;
  118. GameGlobal.userAge = 0;
  119. GameGlobal.skipGuide = false;
  120. RoleDataHandler.StopUpdate();
  121. CardDataManager.Clear();
  122. DecomposeDataManager.Instance.Clear();
  123. PhotographDataManager.Instance.Clear();
  124. SkillDataManager.Instance.Clear();
  125. SuitFosterDataManager.Instance.Clear();
  126. StudioDataManager.Instance.Clear();
  127. StorageDataManager.Instance.Clear();
  128. RechargeDataManager.Instance.Clear();
  129. GameGlobal.zoneScene.GetComponent<SessionComponent>()?.Disconnect();
  130. GameGlobal.zoneScene.GetComponent<ServerInfosComponent>()?.ServerInfoList?.Clear();
  131. if (logout)
  132. {
  133. Logout();
  134. }
  135. ViewManager.Show<LoginView>(null, null, true);
  136. if (logout)
  137. {
  138. ViewManager.Show<LoginInputView>();
  139. }
  140. LoginController.Logout();
  141. }
  142. //注销
  143. public static void Logout()
  144. {
  145. PlayerPrefs.DeleteKey(GameConst.PASSWORD_LAST_LOGIN_KEY);
  146. }
  147. public static void GoBackToMainView()
  148. {
  149. ViewManager.Show(ViewName.MAINUI_VIEW, null, null, true);
  150. }
  151. private static void EnterGame()
  152. {
  153. ViewManager.Hide<LoginView>();
  154. if (MainStoryDataManager.CheckOpenMainUI() || GameGlobal.skipGuide)
  155. {
  156. ViewManager.Show(ViewName.MAINUI_VIEW);
  157. }
  158. else
  159. {
  160. MainStoryDataManager.currentChapterCfgId = 10001;
  161. if (GameGlobal.isFirstEntry == true)
  162. {
  163. // ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW, });
  164. StoryController.ShowPriorStoryDialog();
  165. }
  166. else
  167. {
  168. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, MainStoryDataManager.currentChapterCfgId, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW });
  169. }
  170. }
  171. Timers.inst.CallLater(AfterEnterGame);
  172. }
  173. private static async void AfterEnterGame(object param)
  174. {
  175. //GameProxy.ReqGetStoryScoreList();
  176. //GameProxy.ReqGetStoryStarList();
  177. ItemHelper.GetItemAttributeInfos().Coroutine();
  178. SuitFosterProxy.SendGetSuitInfos().Coroutine();
  179. MainStorySProxy.GetStoryInfos().Coroutine();
  180. CardSProxy.GetCardInfos().Coroutine();
  181. RechargeSProxy.ReqRechargeInfo().Coroutine();
  182. RechargeSProxy.ReqRequestGiftBagInfo().Coroutine();
  183. RechargeSProxy.ReqExchangeInfo().Coroutine();
  184. EquipDataCache.cacher.autoPlay = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY) <= 0 ? false : true;
  185. EquipDataCache.cacher.fightSpeed = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED) <= 1 ? 1 : StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED);
  186. GameGlobal.skipCheckOpen = StorageDataManager.Instance.GetStorageValue(ConstStorageId.SKIP_CHECK_OPEN) <= 0 ? false : true;
  187. GameGlobal.isEnterGame = true;
  188. bool result = await FieldSProxy.ReqFieldInstanceInfos();
  189. if (result && FieldDataManager.Instance.fieldInfos.hasBonus)
  190. {
  191. bool result1 = await FieldSProxy.ReqFieldInstanceResult();
  192. if (result1)
  193. {
  194. ViewManager.Show<FieldFightEndView>();
  195. }
  196. }
  197. }
  198. }
  199. }