GameController.cs 12 KB

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