GameController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. using FairyGUI;
  2. using UnityEngine;
  3. using ET;
  4. using static GFGGame.LauncherConfig;
  5. using TapTap.Bootstrap;
  6. namespace GFGGame
  7. {
  8. public class GameController
  9. {
  10. public static void Start()
  11. {
  12. //界面
  13. ViewManager.Init();
  14. //日志
  15. LogController.Instance.Init();
  16. //全局
  17. GameGlobal.Init();
  18. //缓存
  19. LocalCache.InitLocalData();
  20. //sqlite
  21. SqliteController.Instance.Init(false, ResPathUtil.SQLITE_FILE_PATH);
  22. //全局点击效果
  23. ViewGlobal.CreatClickEffect();
  24. ViewGlobal.AddShowGMViewEventListener();
  25. //获取游戏配置
  26. GetGameCfg();
  27. }
  28. /// <summary>
  29. /// 获取游戏配置
  30. /// </summary>
  31. public static void GetGameCfg()
  32. {
  33. var url = LauncherConfig.cfgUrl.Replace("{cfgName}", GameGlobal.cfgName);
  34. url = url + "?t=" + TimeHelper.ClientNow();
  35. HttpTool.Instance.Get(url, (string data) =>
  36. {
  37. //初始化游戏配置
  38. GameConfig.InitData(data);
  39. //显示登录
  40. LoginController.ShowLogin();
  41. });
  42. }
  43. public static bool CheckLoginCache(bool doLogin)
  44. {
  45. string account = PlayerPrefs.GetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, null);
  46. string password = PlayerPrefs.GetString(GameConst.PASSWORD_LAST_LOGIN_KEY, null);
  47. bool lastLoginIsVisitor = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, false);
  48. if (lastLoginIsVisitor)
  49. {
  50. long id = (long)PlayerPrefs.GetFloat(GameConst.VISITOR_ID_KEY, -1);
  51. if (id >= 0)
  52. {
  53. if (doLogin)
  54. {
  55. //LoginProxy.LoginAsVisitor();
  56. }
  57. return true;
  58. }
  59. }
  60. else if (!string.IsNullOrEmpty(account))
  61. {
  62. if (!string.IsNullOrEmpty(password))
  63. {
  64. if (doLogin)
  65. {
  66. LoginController.Login(account, password, true).Coroutine();
  67. }
  68. return true;
  69. }
  70. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL && PlayerPrefs.HasKey(GameConst.PASSWORD_LAST_LOGIN_KEY))
  71. {
  72. if (doLogin)
  73. {
  74. LoginController.LoginTest(account).Coroutine();
  75. }
  76. return true;
  77. }
  78. }
  79. return false;
  80. }
  81. public static void CheckSpecialAccount(string account)
  82. {
  83. GameGlobal.antiAddiction = !(account.IndexOf("sygfg") == 0);
  84. }
  85. public static void ShowCreateRole()
  86. {
  87. ViewManager.Show(ViewName.CREATE_ROLE_VIEW);
  88. }
  89. public static async ETTask PreEnterGameAsync()
  90. {
  91. QDTapTapManager.Instance.OnEnterGame();
  92. RoleDataHandler.StartUpdate();
  93. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("CommonGame"));
  94. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Main"));
  95. LeagueSproxy.ReqGetLeagueInfo().Coroutine();
  96. await ItemProxy.GetItemInfos();
  97. await RoleLimitSProxy.ReqUnitLimitInfos();
  98. await InstanceZonesSProxy.GetInstanceZonesInfos();
  99. await StorageSProxy.ReqGetClientValues();
  100. await SuitFosterProxy.SendGetSuitInfos();
  101. await ActivitySProxy.ReqSevenDayLoginInfos();
  102. // await RechargeSProxy.ReqRequestGiftBagInfo();
  103. await ShopSProxy.ReqShopInfo();
  104. await StudioSProxy.ReqStudioInfos();
  105. await RoleInfoSProxy.ReqPersonalInfo();
  106. GameGlobal.lastLoginTime = StorageDataManager.Instance.GetStorageValue(ConstStorageId.LAST_LOGIN_TIME);
  107. long lastTime = GameGlobal.myNumericComponent.GetAsInt(NumericType.OnlineTimeSecs);
  108. StorageSProxy.ReqSetClientValue(ConstStorageId.LAST_LOGIN_TIME, (int)lastTime).Coroutine();
  109. int skipGuide = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_SKIP_GUIDE);
  110. if (skipGuide <= 0 && LauncherConfig.netType == EnumNetType.LOCAL)
  111. {
  112. AlertUI.Show("是否跳过引导?如果您是第一次体验,建议不要跳过引导!")
  113. .SetLeftButton(true, "不用", (obj) =>
  114. {
  115. EnterGame();
  116. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 1).Coroutine();
  117. })
  118. .SetRightButton(true, "跳过", (obj) =>
  119. {
  120. GameGlobal.skipGuide = true;
  121. EnterGame();
  122. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 2).Coroutine();
  123. });
  124. }
  125. else
  126. {
  127. if (skipGuide == 2) GameGlobal.skipGuide = true;
  128. EnterGame();
  129. }
  130. }
  131. public static void QuitToLoginView(bool logout)
  132. {
  133. GameGlobal.DataInited = false;
  134. QDManager.OnQuitToLoginView();
  135. GameGlobal.isVisitor = false;
  136. GameGlobal.antiAddiction = true;
  137. GameGlobal.userId = 0;
  138. GameGlobal.userAge = 0;
  139. GameGlobal.skipGuide = false;
  140. GuideDataManager.currentGuideId = 0;
  141. MainDataManager.Instance.ViewType = 0;
  142. RoleDataHandler.StopUpdate();
  143. CardDataManager.Clear();
  144. ItemDataManager.Clear();
  145. DecomposeDataManager.Instance.Clear();
  146. PhotographDataManager.Instance.Clear();
  147. SkillDataManager.Instance.Clear();
  148. SuitFosterDataManager.Instance.Clear();
  149. StudioDataManager.Instance.Clear();
  150. StorageDataManager.Instance.Clear();
  151. ShopDataManager.Instance.Clear();
  152. DressUpMenuItemDataManager.Clear();
  153. GuideDataManager.Clear();
  154. GetSuitItemController.Clear();
  155. FriendDataManager.Instance.Clear();
  156. RedDotController.Instance.Clear();
  157. BagDataManager.Instance.Clear();
  158. PoemPhotoDataManager.Instance.Clear();
  159. PoemGalleryDataManager.Instance.Clear();
  160. RoleInfoManager.Instance.Clear();
  161. DailyTaskDataManager.Instance.Clear();
  162. TravelDataManager.Instance.Clear();
  163. ArenaDataManager.Instance.Clear();
  164. ChatDataManager.Instance.Clear();
  165. GameGlobal.zoneScene.GetComponent<SessionComponent>()?.Disconnect();
  166. GameGlobal.zoneScene.GetComponent<ServerInfosComponent>()?.ServerInfoList?.Clear();
  167. GameGlobal.zoneScene.GetComponent<AccountInfoComponent>()?.Clear();
  168. if (logout)
  169. {
  170. Logout();
  171. }
  172. LoginController.OnLogout();
  173. ViewManager.Hide<GuideView>();
  174. ViewManager.Show<LoginView>(null, null, true);
  175. }
  176. //注销
  177. public static void Logout()
  178. {
  179. QDManager.Logout();
  180. PlayerPrefs.DeleteKey(GameConst.PASSWORD_LAST_LOGIN_KEY);
  181. }
  182. public static void GoBackToMainView()
  183. {
  184. ViewManager.Show(ViewName.MAINUI_VIEW, null, null, true);
  185. }
  186. private static void EnterGame()
  187. {
  188. LoadingView.Instance.GetUI();
  189. LoadingView.Instance.SetProgress(100, () =>
  190. {
  191. ViewManager.Hide<LoadingView>();
  192. // LoadingView.Instance.Close();
  193. GameGlobal.isEnterGame = true;
  194. if (MainStoryDataManager.CheckOpenMainUI() || GameGlobal.skipGuide)
  195. {
  196. ViewManager.Show(ViewName.MAINUI_VIEW);
  197. }
  198. else
  199. {
  200. MainStoryDataManager.currentChapterCfgId = 10001;
  201. if (GameGlobal.isFirstEntry == true)
  202. {
  203. GameGlobal.isFirstEntry = false;
  204. // StoryController.ShowPriorStoryDialog();
  205. StoryController.ShowLevelView(100001001);
  206. }
  207. else
  208. {
  209. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, MainStoryDataManager.currentChapterCfgId, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW });
  210. }
  211. }
  212. Timers.inst.Add(1f, 1, AfterEnterGame);
  213. });
  214. }
  215. private static async void AfterEnterGame(object param)
  216. {
  217. ItemHelper.GetItemAttributeInfos().Coroutine();
  218. MainStorySProxy.GetStoryInfos().Coroutine();
  219. CardSProxy.GetCardInfos().Coroutine();
  220. TaskSProxy.GetTaskInfos();
  221. // RechargeSProxy.ReqRechargeInfo().Coroutine();
  222. // RechargeSProxy.ReqExchangeInfo().Coroutine();
  223. DailyTaskSProxy.ReqDailyTaskInfos().Coroutine();
  224. NoticeSProxy.ReqSystemNoticeList().Coroutine();
  225. MailSProxy.ReqMailCount().Coroutine();
  226. FriendSProxy.ReqAllFriendInfos().Coroutine();
  227. PoemPhotoSProxy.ReqAllPhotoInfos().Coroutine();
  228. TravelSProxy.ReqTravelInfo().Coroutine();
  229. TravelSProxy.ReqTravelGuideInfo().Coroutine();
  230. PoemGallerySProxy.ReqGalleryTheme().Coroutine();
  231. ArenaDataManager.Instance.ReqArenaInfo();
  232. SkillSProxy.ReqGetSkillList(SkillType.LeagueSkill).Coroutine();
  233. EnduringGiftBoxSProxy.ReqGetAllGiftBagRebateStatus().Coroutine();
  234. int storageAutoPlay = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY);
  235. FightDataManager.Instance.autoPlay = storageAutoPlay <= 0 ? false : true;
  236. int fightSpeed = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_FIGHT_AUTO_PLAY_SPEED);
  237. FightDataManager.Instance.fightSpeed = fightSpeed <= 0 ? 1 : fightSpeed;
  238. int dialogSpeed = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_DIALOG_AUTO_PLAY_SPEED);
  239. FightDataManager.Instance.dialogSpeed = dialogSpeed <= 0 ? 1 : dialogSpeed;
  240. int filingChapterId = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STUDIO_FILING_CHAPTERID);
  241. StudioDataManager.Instance.filingChapterId = filingChapterId <= 0 ? StudioDataManager.Instance.FilingDatas[0].id : filingChapterId;
  242. GameGlobal.skipCheckOpen = StorageDataManager.Instance.GetStorageValue(ConstStorageId.SKIP_CHECK_OPEN) <= 0 ? false : true;
  243. bool result = await FieldSProxy.ReqFieldInstanceInfos();
  244. if (result && FieldDataManager.Instance.fieldInfos.hasBonus)
  245. {
  246. bool result1 = await FieldSProxy.ReqFieldInstanceResult();
  247. if (result1)
  248. {
  249. ViewManager.Show<FieldFightEndView>();
  250. }
  251. }
  252. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  253. }
  254. }
  255. }