GameController.cs 9.2 KB

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