using FairyGUI; using UnityEngine; using UI.CommonGame; using UI.Main; using UI.Common; namespace GFGGame { public class GameController { public static void Start() { LoginProxy.SayHi((LoginResult result) => { CheckShowLoginView(); }); } private static void CheckShowLoginView() { LauncherView.Instance.Close(); ViewManager.Show(); } public static bool CheckLoginCache(bool doLogin) { string account = PlayerPrefs.GetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, null); string password = PlayerPrefs.GetString(GameConst.PASSWORD_LAST_LOGIN_KEY, null); bool lastLoginIsVisitor = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, false); if (lastLoginIsVisitor) { long id = (long)PlayerPrefs.GetFloat(GameConst.VISITOR_ID_KEY, -1); if (id >= 0) { if (doLogin) { LoginProxy.LoginAsVisitor(); } return true; } } else if (account != null && account.Length > 0) { if (password != null && password.Length > 0) { if (doLogin) { LoginProxy.Login(account, password); } return true; } } return false; } public static void OnLoginSuccess(LoginResult result) { ViewManager.Hide(); ViewManager.Hide(); if (GameGlobal.isOfflineVisitor) { GameProxy.ReqRoleInfo(GameGlobal.userId); } else { User user = result.user; GameGlobal.userId = user.id; GameGlobal.userAge = user.age; if (GameGlobal.isVisitor) { PlayerPrefs.SetFloat(GameConst.VISITOR_ID_KEY, GameGlobal.userId); } else { PlayerPrefs.SetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, user.account); PlayerPrefs.SetString(GameConst.PASSWORD_LAST_LOGIN_KEY, user.password); } GameController.CheckSpecialAccount(user.account); LocalCache.SetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, GameGlobal.isVisitor); PlayerPrefs.Save(); GameProxy.ReqRoleInfo(GameGlobal.userId); } } public static void OnLoginFail(LoginResult result) { if (result.code == 107) { string promptStr = "您属于未成年人,已被纳入防沉迷系统。每日22时至次日8时,本游戏将无法为未成年人用户提供游戏服务。"; Alert.Show(promptStr) .SetRightButton(true, "知道啦", (object data) => { }); } else { ViewManager.Show(); } } public static void CheckSpecialAccount(string account) { GameGlobal.antiAddiction = !(account.IndexOf("sygfg") == 0); } public static void ShowCreateRole() { ViewManager.Show(ViewName.CREATE_ROLE_VIEW); Alert.Show("是否跳过引导?如果您是第一次体验,建议不要跳过引导!") .SetLeftButton(true, "不用") .SetRightButton(true, "跳过", (obj) => { GameGlobal.skipGuide = true; }); } public static void PreEnterGame(GameResult result) { RoleInfo roleInfo = null; GetSuitItemController.enable = false; DressUpMenuSuitDataManager.InitData(); DressUpMenuItemDataManager.InitData(); if (!GameGlobal.isOfflineVisitor) { roleInfo = result.roleInfo; bool rerult = AntiAddictionController.CheckAntiAddiction(roleInfo.onlineTimeSecs, roleInfo.onlineDurationSecs, roleInfo.onlineDurationSecsDay); if (rerult) { return; } ServerDataManager.SetServerTime(roleInfo.serverTime); RoleDataManager.InitServerData(roleInfo); ItemDataManager.InitServerData(result.roleItemList); CustomSuitDataManager.InitServerData(roleInfo.suitIndex, result.roleSuitList); StoryDataManager.InitServerData(roleInfo); GuideDataManager.InitServerData(result.roleGuideList); DressUpMenuSuitDataManager.InitServerData(result.systemSuitList); CardDataManager.InitServerData(result.roleCardList); } else { RoleDataManager.InitServerData(null); ItemDataManager.InitServerData(null); CustomSuitDataManager.InitServerData(0, null); StoryDataManager.InitServerData(null); GuideDataManager.InitServerData(null); DressUpMenuSuitDataManager.InitServerData(null); CardDataManager.InitServerData(null); } GetSuitItemController.enable = true; RoleDataHandler.StartUpdate(); GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("CommonGame")); GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Main")); if (GameGlobal.isOfflineVisitor) { Alert.Show("离线体验可以选择跳过引导并获取所有衣服。") .SetLeftButton(true, "跳过引导", (object data) => { GameGlobal.skipGuide = true; GMController.GetAllDressUpItem(); EnterGame(); }) .SetRightButton(true, "体验引导", (object data) => { GameGlobal.skipGuide = false; EnterGame(); }); } else { if (RoleDataManager.lvl >= 50) { GameGlobal.skipGuide = true; } EnterGame(); } } public static void QuitToLoginView(bool logout) { GetSuitItemController.enable = false; GameGlobal.isVisitor = false; GameGlobal.antiAddiction = true; GameGlobal.userId = 0; GameGlobal.userAge = 0; GameGlobal.skipGuide = false; RoleDataHandler.StopUpdate(); CardDataManager.Clear(); PhotographDataManager.Instance.Clear(); if (logout) { Logout(); } ViewManager.Hide(ViewName.ROLE_INFO_VIEW); ViewManager.Hide(ViewName.MAINUI_VIEW); ViewManager.Show(); if (logout) { ViewManager.Show(); } } //注销 public static void Logout() { PlayerPrefs.DeleteKey(GameConst.PASSWORD_LAST_LOGIN_KEY); } public static void GoBackToMainView() { ViewManager.Show(ViewName.MAINUI_VIEW, null, null, true); } private static void EnterGame() { ViewManager.Hide(); if (StoryDataManager.CheckOpenMainUI() || GameGlobal.skipGuide) { ViewManager.Show(ViewName.MAINUI_VIEW); } else { StoryDataManager.currentChapter = 1; if (!StoryDataManager.CheckLevelPass(1, 1)) { StoryController.ShowLevelView(StoryDataManager.currentChapter, 1); } else { ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW }); } } AfterEnterGame(); } private static void AfterEnterGame() { GameProxy.ReqGetStoryScoreList(); GameProxy.ReqGetStoryStarList(); } public static void PrepareUpdateTreasure() { if (!Timers.inst.Exists(UpdateTreasure)) { Timers.inst.Add(0.1f, 1, UpdateTreasure); } } private static void UpdateTreasure(object param) { GameProxy.ReqUpdateTreasure(); } } }