/// <summary> /// 是主角等级上升 /// </summary> /// <param name="toLv">To lv.</param> public void HostRoleUpgrade(int toLv) { if (HostData.Lv >= toLv) { return; } RoleData role = null; db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select RoleData from RolesTable where RoleId = '" + currentRoleId + "'"); string roleDataStr; if (sqReader.Read()) { roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData")); roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr); role = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr); role.Lv = toLv > role.Lv ? toLv : role.Lv; //更新主角数据 db.ExecuteQuery("update RolesTable set RoleData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(role)) + "' where RoleId = '" + currentRoleId + "'"); } db.CloseSqlConnection(); if (role != null) { HostData.MakeJsonToModel(); role.MakeJsonToModel(); Messenger.Broadcast <RoleData, RoleData>(NotifyTypes.HostRoleUpgradeEcho, HostData, role); CallRoleInfoPanelData(false); //刷新队伍数据 MaiHandler.SetAccount(role); } }
/// <summary> /// 用户相关消息 /// </summary> public static void UserNotifyInit() { Messenger.AddListener <System.Action <UserData> >(NotifyTypes.CallUserData, (callback) => { callUserDataCallback = callback; DbManager.Instance.CallUserData(); }); Messenger.AddListener <System.Action <UserData> >(NotifyTypes.UpdateUserData, (callback) => { if (UserModel.CurrentUserData != null) { callUserDataCallback = callback; DbManager.Instance.UpdateUserData(JsonManager.GetInstance().SerializeObjectDealVector(UserModel.CurrentUserData)); } }); Messenger.AddListener <JObject>(NotifyTypes.CallUserDataEcho, (obj) => { if (callUserDataCallback != null) { JArray data = (JArray)obj["data"]; if (data.Count > 4) { UserModel.CurrentUserData = JsonManager.GetInstance().DeserializeObject <UserData>(data[1].ToString()); UserModel.CurrentUserData.Id = data[0].ToString(); UserModel.CurrentUserData.AreaFood.Num = (int)data[2]; UserModel.CurrentUserData.TimeAngle = (float)data[3]; UserModel.CurrentUserData.TimeTicks = (long)data[4]; UserModel.CurrentFoodNums = UserModel.CurrentUserData.AreaFood.MaxNum; FramePanelCtrl.TimePlay(UserModel.CurrentUserData.TimeAngle, UserModel.CurrentUserData.TimeTicks); //初始化时辰时间戳 } callUserDataCallback(UserModel.CurrentUserData); callUserDataCallback = null; } }); Messenger.AddListener <string, Vector2, System.Action <UserData> >(NotifyTypes.UpdateUserDataAreaInfo, (areaName, pos, callback) => { if (UserModel.CurrentUserData != null) { UserModel.CurrentUserData.PositionStatu = UserPositionStatusType.InArea; UserModel.CurrentUserData.CurrentAreaSceneName = areaName; UserModel.CurrentUserData.CurrentAreaX = (int)pos.x; UserModel.CurrentUserData.CurrentAreaY = (int)pos.y; Messenger.Broadcast <System.Action <UserData> >(NotifyTypes.UpdateUserData, callback); } }); Messenger.AddListener <string>(NotifyTypes.UpdateUserDataCityInfo, (cityId) => { if (UserModel.CurrentUserData != null) { SceneData scene = JsonManager.GetInstance().GetMapping <SceneData>("Scenes", cityId); //战斗据点场景不缓存 if (!scene.IsJustFightScene) { UserModel.CurrentUserData.PositionStatu = UserPositionStatusType.InCity; UserModel.CurrentUserData.CurrentCitySceneId = cityId; } } }); Messenger.AddListener <string, Vector2, System.Action <UserData> >(NotifyTypes.UpdateUserDataAreaPos, (areaName, pos, callback) => { if (UserModel.CurrentUserData != null) { UserModel.CurrentUserData.CurrentAreaSceneName = areaName; UserModel.CurrentUserData.CurrentAreaX = (int)pos.x; UserModel.CurrentUserData.CurrentAreaY = (int)pos.y; Messenger.Broadcast <System.Action <UserData> >(NotifyTypes.UpdateUserData, callback); } }); Messenger.AddListener(NotifyTypes.PlayBgm, () => { if (UserModel.CurrentUserData != null) { switch (UserModel.CurrentUserData.PositionStatu) { case UserPositionStatusType.InArea: if (AreaModel.AreaMainScript) { AreaModel.AreaMainScript.PlayBgm(); } break; case UserPositionStatusType.InCity: CityScenePanelCtrl.MakePlayBgm(); break; default: break; } } }); Messenger.AddListener(NotifyTypes.EnterGame, () => { DbManager.Instance.ResetTasks(); //初始化任务 if (DbManager.Instance.GetRecordNum() > 0) { // MainPanelCtrl.Hide(); // RecordListPanelCtrl.Hide(); // SettingPanelCtrl.Hide(); UIModel.CloseAllWindows(); Messenger.Broadcast <bool>(NotifyTypes.CallRoleInfoPanelData, false); MaiHandler.SetAccount(DbManager.Instance.HostData); Messenger.Broadcast <System.Action <UserData> >(NotifyTypes.CallUserData, (userData) => { if (userData != null) { Messenger.Broadcast <string>(NotifyTypes.GoToScene, userData.CurrentAreaSceneName); } else { //修复上一次创建新角色没创建完就退出游戏,再进后卡死的bug Messenger.Broadcast(NotifyTypes.GetRecordListData); } // //大于等于5级每次登陆游戏都弹一次插屏广告 // if (DbManager.Instance.HostData != null && // DbManager.Instance.HostData.Lv >= 5 && // DbManager.Instance.GetPlusWorkerNum() <= 0 && // PlayerPrefs.GetInt("TotalPay") <= 0) { // MaiHandler.ShowInterstitial(false); // MaiHandler.SendEvent("StartInterstitialForLogin", DbManager.Instance.HostData.Lv.ToString()); // } }); } else { Messenger.Broadcast <string>(NotifyTypes.ShowCreateHostRolePanel, "role_0"); //第一个角色创建 } }); Messenger.AddListener <string>(NotifyTypes.ShowCreateHostRolePanel, (id) => { // MainPanelCtrl.Hide(); // RecordListPanelCtrl.Hide(); // SettingPanelCtrl.Hide(); UIModel.CloseAllWindows(); CreateHostRolePanelCtrl.Show(id); }); Messenger.AddListener <RoleData>(NotifyTypes.CreateHostRole, (role) => { PlayerPrefs.SetString("CurrentRoleId", role.Id); //记录当前角色存档id DbManager.Instance.SetCurrentRoleId(role.Id); DbManager.Instance.AddNewRecord(role.Id, role.Name, "{}", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //创建用户数据 UserData userData = new UserData(); userData.AreaFood = new ItemData(); userData.AreaFood.Num = 0; userData.AreaFood.MaxNum = 30; userData.PositionStatu = UserPositionStatusType.InCity; userData.CurrentAreaSceneName = "Area00"; userData.CurrentCitySceneId = "00001"; userData.CurrentAreaX = 15; userData.CurrentAreaY = 15; userData.MaxRoleNum = 2; DbManager.Instance.AddNewUserData(JsonManager.GetInstance().SerializeObjectDealVector(userData), userData.AreaFood.Num, role.Id, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //创建角色数据 role.ResourceBookDataIds.Clear(); MaiHandler.SetAccount(role); if (DbManager.Instance.AddNewRole(role.Id, JsonManager.GetInstance().SerializeObjectDealVector(role), (int)RoleStateType.InTeam, 0, role.HometownCityId, role.Id, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))) { // DbManager.Instance.AddNewWeapon(role.ResourceWeaponDataId, role.Id); // DbManager.Instance.AddNewWeapon("1"); // DbManager.Instance.AddNewWeapon("2"); // DbManager.Instance.AddNewWeapon("3"); CreateHostRolePanelCtrl.MakeStoryContinue(role.Name); } }); Messenger.AddListener(NotifyTypes.GetRecordListData, () => { DbManager.Instance.GetRecordListData(); }); Messenger.AddListener <List <JArray> >(NotifyTypes.GetRecordListDataEcho, (data) => { RecordListPanelCtrl.Show(data); }); Messenger.AddListener(NotifyTypes.ShowMainPanel, () => { // MainPanelCtrl.Hide(); // RecordListPanelCtrl.Hide(); // SettingPanelCtrl.Hide(); UIModel.CloseAllWindows(); MainPanelCtrl.Show(); }); Messenger.AddListener <bool>(NotifyTypes.ShowSettingPanel, (flag) => { //战斗时不能打开设置界面 if (BattleMainPanelCtrl.Ctrl != null) { return; } SettingPanelCtrl.Show(flag); }); }