GameController.cs 12 KB

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