GameController.cs 11 KB

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