import EventMgr from "../Event/EventMgr"; import { ryw_Event } from "../Event/EventEnum"; import PhysicalPowerManger from "../../ttFrame/manager/PhysicalPowerManger"; import GameMgr from "../Mgr/GameMgr"; import { DateUtils } from "../Util/DateUtils"; import Common5 from "../../Platform/th/Common5"; import AppSwitchConfig from "../Config/AppSwitchConfig"; import DayUnlock from "../../ttFrame/manager/DayUnlock"; import CommonDefine from "../../Platform/th/CommonDefine"; import AppPlatform from "../Util/AppPlatform"; import TTAPI from "../../Platform/tt/TTAPI"; export class LevelFlag{ public level:number = 0; public flag:number[] = []; } export class LevelFlag_fkwz{ public level:number = 0; public flag:number = 0; } //游戏数据,为保持版本兼容,建议不要删除和修改字段名 export class UserGameData { public physicalData: any = {}; public dayUnlock: any = {}; public levelNum: number = 0;//当前关卡 public moneyNum: number = 0;//金币数量 public unlockedItem: Array = [];//道具当前解锁的索引 public lastOnlineTime: number = 0; public otherPlatformUserID = ""; public collectLevels =[]; public successLevels=[]; public daojuArr=[0,0,0]; public userId = ''; public uuid:string = ''; public wordGameAnswerUnlock: Array = [];//侦探笔记游戏当前是否看答案,0没看,1看了提示,2看了答案 public wordGameAnswerUnlock_fkwz: Array = [];//疯狂文字游戏当前是否看答案,0没看,1看了提示,2看了答案 public levelNum_duck: number = 0;//当前鸭子关卡 /**当前道士下山关卡 */ public levelNum_dsxs_Array: Array = []; /**存储当前关卡 */ public levelNum_Array: Array = []; /**当前文字游戏关卡 */ public levelNum_Word_Array: Array = []; /**当前收纳关卡 */ public levelNum_SN_Array: Array = []; public firstIn:boolean = true; public dadianListGame = {} public isFinishCeBianLanAward:boolean = false//是否领取过侧边栏奖励 } export default class User { public static code_custom: string = ""; public static openId_custom: string = ""; public static token_custom: string = null; public static nickName_custom: string = ""; public static gender_custom: number = 0; public static get isLogin_custom() { return (User.code_custom != "") || (User.token_custom != ""); } private static readonly _gameData_custom: UserGameData = new UserGameData(); public static getSaveData_custom(): string { //体力数据 User._gameData_custom.physicalData = PhysicalPowerManger.getData(); User._gameData_custom.dayUnlock = DayUnlock.getData(); return JSON.stringify(User._gameData_custom); } public static TT() { User._gameData_custom.levelNum_Array = []; User._gameData_custom.collectLevels = []; User._gameData_custom.successLevels = []; User._gameData_custom.daojuArr = [0,0,0]; User._gameData_custom.levelNum = 0; GameMgr.getInstance_custom().saveGameData_custom(); } /** * 测试用途 */ public static testInitUser_custom() { User._gameData_custom.levelNum = 0; User._gameData_custom.moneyNum = 1000; } public static initLevel() { let levela = User.getLevelAryy_custom(); if (!levela || levela.length == 0) { if (User.getLeveNum_custom() >= 1) { console.log("恢复关卡数据", User.getLeveNum_custom(), User.getLevelAryy_custom()) for (let index = 0; index <= User.getLeveNum_custom(); index++) { User.setLevelAryy_custom(index, true); } } else { console.log("没有!!!!") } } } public static initiUser_custom(data) { console.log("***************************** User initUser ************************************** "); console.log(data); // console.log((new Date()).getTime()); if (data && 0 != data) { User._gameData_custom.levelNum = User.verify(data.levelNum, 0); User._gameData_custom.levelNum_duck = User.verify(data.levelNum_duck, 0); // User._gameData_custom.levelNum_dsxs_Array = User.verify(data.levelNum_dsxs_Array, 0); User._gameData_custom.moneyNum = User.verify(data.moneyNum, 0); User._gameData_custom.lastOnlineTime = User.verify(data.lastOnlineTime, -1) User._gameData_custom.otherPlatformUserID = User.verify(data.otherPlatformUserID, ""); PhysicalPowerManger.initData(User.verify(data.physicalData, {})); DayUnlock.initData(User.verify(data.dayUnlock, {})) //增加自己的数据 if (null != data.unlockedItem) { let unlockedItem: Array = data.unlockedItem; for (let i = 0; i < unlockedItem.length; ++i) { User._gameData_custom.unlockedItem.push(unlockedItem[i]); } } if (null != data.wordGameAnswerUnlock) { let wordGameAnswerUnlock: Array = data.wordGameAnswerUnlock; for (let i = 0; i < wordGameAnswerUnlock.length; ++i) { let find = false; for (let j = 0; j < User._gameData_custom.wordGameAnswerUnlock.length; j++){ if (User._gameData_custom.wordGameAnswerUnlock[j].level == wordGameAnswerUnlock[i].level){ find = true; break; } } if (!find){ User._gameData_custom.wordGameAnswerUnlock.push(wordGameAnswerUnlock[i]); } } } if (null != data.wordGameAnswerUnlock_fkwz) { let wordGameAnswerUnlock_fkwz: Array = data.wordGameAnswerUnlock_fkwz; for (let i = 0; i < wordGameAnswerUnlock_fkwz.length; ++i) { let find = false; for (let j = 0; j < User._gameData_custom.wordGameAnswerUnlock_fkwz.length; j++){ if (User._gameData_custom.wordGameAnswerUnlock_fkwz[j].level == wordGameAnswerUnlock_fkwz[i].level){ find = true; break; } } if (!find){ User._gameData_custom.wordGameAnswerUnlock_fkwz.push(wordGameAnswerUnlock_fkwz[i]); } } } /**增加道士下山模式 */ if (null != data.levelNum_dsxs_Array) { let levelNum_dsxs_Array: Array = data.levelNum_dsxs_Array; for (let i = 0; i < levelNum_dsxs_Array.length; ++i) { User._gameData_custom.levelNum_dsxs_Array.push(levelNum_dsxs_Array[i]); } } /**增加文字游戏模式 */ if (null != data.levelNum_Word_Array) { let levelNum_Word_Array: Array = data.levelNum_Word_Array; for (let i = 0; i < levelNum_Word_Array.length; ++i) { User._gameData_custom.levelNum_Word_Array.push(levelNum_Word_Array[i]); } } /**增加收纳模式 */ if (null != data.levelNum_SN_Array) { let levelNum_SN_Array: Array = data.levelNum_SN_Array; for (let i = 0; i < levelNum_SN_Array.length; ++i) { User._gameData_custom.levelNum_SN_Array.push(levelNum_SN_Array[i]); } } if (null != data.userId) { User._gameData_custom.userId = data.userId; } if (null != data.uuid){ User._gameData_custom.uuid = data.uuid; } if (null != data.firstIn){ User._gameData_custom.firstIn = data.firstIn; } if (null != data.levelNum_Array) { let levelNum_Array: Array = data.levelNum_Array; for (let i = 0; i < Common5.addGameArr.length; ++i) { let sum = levelNum_Array[i]; if (sum == 0 || sum == 1) { User._gameData_custom.levelNum_Array[i] = sum; // if (User.getLeveNum_custom() >= i) { // User.setLevelAryy_custom(i, true); // // User._gameData_custom.levelNum_Array[i] = 1; // } } else { User._gameData_custom.levelNum_Array[i] = 0; } } // User._gameData_custom.levelNum_Array[0] = 1; } else { for (let index = 0; index < Common5.addGameArr.length; index++) { User._gameData_custom.levelNum_Array[index] = User.getLeveNum_custom() <= index ? 1 : 0; } // User._gameData_custom.levelNum_Array[0] = 1; } if (null != data.collectLevels){ User._gameData_custom.collectLevels = data.collectLevels; } if (null != data.successLevels){ User._gameData_custom.successLevels = data.successLevels; } if (null != data.daojuArr){ User._gameData_custom.daojuArr = data.daojuArr; } if (null != data.dadianListGame){ User._gameData_custom.dadianListGame = data.dadianListGame; } if (null != data.isFinishCeBianLanAward){ User._gameData_custom.isFinishCeBianLanAward = data.isFinishCeBianLanAward; } if (User.getLastOnlineTime() != (new Date()).getDay()) { console.log("ly+++++++++++++ 第二天了", User.getLastOnlineTime(), (new Date()).getDay()); PhysicalPowerManger.initData({}) //DayUnlock.initData({}); User._gameData_custom.dadianListGame = {} User._gameData_custom.isFinishCeBianLanAward = false } User.setLastOnlineTime((new Date()).getDay()); } else { PhysicalPowerManger.initData({}); DayUnlock.initData({}); //todo:处理没有获取到玩家数据的情况 User.setLastOnlineTime((new Date()).getDay()); // for (let index = 0; index < Common5.addGameArr.length; index++) { // User._gameData_custom.levelNum_Array.push(0); // } // User._gameData_custom.levelNum_Array[0] = 1; // console.log("重置了!!!!!!!!!!!!") } // if (PhysicalPowerManger.getPhyVideoAllNum() >= AppSwitchConfig.getInstance_custom().getAppSwitchData_custom().ttcfg_custom.videoWxtlPowerNum) { // PhysicalPowerManger.addNewPhysicalAll(); // PhysicalPowerManger.setPhyVideoAllNum(0); // EventMgr.emitEvent_custom(ryw_Event.start_hideWxtlBtn); // } // if (DayUnlock.getDayUnlockVideoAllNum() >= AppSwitchConfig.getInstance_custom().getAppSwitchData_custom().ttcfg_custom.videoUnlockDayNum) { // DayUnlock.addNewDayUnlocksicalAll(); // DayUnlock.setDayUnlocVideoAllNum(0); // EventMgr.emitEvent_custom(ryw_Event.unLockAllLevelTmp); // console.log("unLockAllLevelTmp_ztbj"); // } } public static setLastOnlineTime(dayNum: number) { User._gameData_custom.lastOnlineTime = dayNum; GameMgr.getInstance_custom().saveGameData_custom(); } public static getLastOnlineTime(): number { return User._gameData_custom.lastOnlineTime; } public static setOtherplatformUserid(otn) { User._gameData_custom.otherPlatformUserID = otn; GameMgr.getInstance_custom().saveGameData_custom(); } public static getOtherplatformUserid() { return User._gameData_custom.otherPlatformUserID; } public static setLeveNum_custom(levelNum: number) { User._gameData_custom.levelNum = levelNum; GameMgr.getInstance_custom().saveGameData_custom(); } public static getLeveNum_custom(): number { return User._gameData_custom.levelNum; } public static setLevelNum_duck_custom(levelNum_duck: number) { User._gameData_custom.levelNum_duck = levelNum_duck; GameMgr.getInstance_custom().saveGameData_custom(); } public static getLevelNum_duck_custom(): number { return User._gameData_custom.levelNum_duck; } public static addMoney_custom(add: number) { add = Math.ceil(add) var last = User._gameData_custom.moneyNum User._gameData_custom.moneyNum += add; EventMgr.emitEvent_custom(ryw_Event.ryw_Game_OnUserMoneyChange_custom, { curr: User._gameData_custom.moneyNum, last: last }) GameMgr.getInstance_custom().saveGameData_custom(); } public static subMoney_custom(sub: number) { sub = Math.ceil(sub) var last = User._gameData_custom.moneyNum User._gameData_custom.moneyNum -= sub; if (User._gameData_custom.moneyNum < 0) { User._gameData_custom.moneyNum = 0; } EventMgr.emitEvent_custom(ryw_Event.ryw_Game_OnUserMoneyChange_custom, { curr: User._gameData_custom.moneyNum, last: last }) GameMgr.getInstance_custom().saveGameData_custom(); } public static getMoney_custom() { return User._gameData_custom.moneyNum; } //获取当前商店解锁的道具 public static getItemUnlocked_custom(): Array { let unlocked = new Array(); for (let i = 0; i < User._gameData_custom.unlockedItem.length; ++i) { unlocked.push(User._gameData_custom.unlockedItem[i]); } return unlocked; } //商店道具是否解锁 public static itemIsUnlocked_custom(id: number): boolean { console.log("ly++++++++++++++++++ id", id, User._gameData_custom.unlockedItem); for (let i = 0; i < User._gameData_custom.unlockedItem.length; ++i) { if (User._gameData_custom.unlockedItem[i] == id) { return true; } } return false; } /**获取当前关卡 */ public static getLevelAryy_custom(): Array { let unlocked = new Array(); for (let i = 0; i < Common5.addGameArr.length; ++i) { if (!User._gameData_custom.levelNum_Array[i]) { unlocked.push(0) } else { unlocked.push(User._gameData_custom.levelNum_Array[i]); } } // unlocked[0] = 1; return unlocked; } /**关卡解锁 */ public static setLevelAryy_custom(id, isUseInit=false) { //console.error(id, '关卡解锁') User._gameData_custom.levelNum_Array[id] = 1; GameMgr.getInstance_custom().saveGameData_custom(); } //关卡覆盖 public static setLevelAryy_Cover(data) { User._gameData_custom.levelNum_Array = data; GameMgr.getInstance_custom().saveGameData_custom(); } public static getCollectLevels(){ return User._gameData_custom.collectLevels; } public static setCollectLevels(level){ for (let i = 0; i < User._gameData_custom.collectLevels.length; i++){ if (level == User._gameData_custom.collectLevels[i]){ return; } } User._gameData_custom.collectLevels.push(level); User.saveDataToServer() GameMgr.getInstance_custom().saveGameData_custom(); } public static setCollectLevelsCover(data){ User._gameData_custom.collectLevels = data GameMgr.getInstance_custom().saveGameData_custom(); } public static removeColeectLevels(level){ for (let i = 0; i < User._gameData_custom.collectLevels.length; i++){ if (level == User._gameData_custom.collectLevels[i]){ User._gameData_custom.collectLevels.splice(i,1); break; } } User.saveDataToServer() GameMgr.getInstance_custom().saveGameData_custom(); } public static getDaojuArr(){ return User._gameData_custom.daojuArr; } public static setDaojuArr(data){ User._gameData_custom.daojuArr = data; GameMgr.getInstance_custom().saveGameData_custom(); } public static getSuccessLevels(){ return User._gameData_custom.successLevels; } public static setSuccessLevelsCover(data){ User._gameData_custom.successLevels = data; GameMgr.getInstance_custom().saveGameData_custom(); } public static setSuccessLevels(level){ for (let i = 0; i < User._gameData_custom.successLevels.length; i++){ if (level == User._gameData_custom.successLevels[i]){ return; } } if(window['tt']){ TTAPI.setImRankData(User._gameData_custom.successLevels.length) } User._gameData_custom.successLevels.push(level); TTAPI.setImRankData(User._gameData_custom.successLevels.length) GameMgr.getInstance_custom().saveGameData_custom(); } public static setlevelNum_dsxs_Array_custom(level: number) { User._gameData_custom.levelNum_dsxs_Array[level] = 1; GameMgr.getInstance_custom().saveGameData_custom(); } public static getlevelNum_dsxs_Array_custom(): Array { let dsxs = new Array(); for (let i = 0; i < Common5.swimmGameArr.length; ++i) { if (!User._gameData_custom.levelNum_dsxs_Array[i]) { dsxs.push(0) } else { dsxs.push(User._gameData_custom.levelNum_dsxs_Array[i]); } } dsxs[0] = 1; return dsxs; } public static getUnlockLevel() { let levelArray = User._gameData_custom.levelNum_Array; let _unlock = 0 for(let i = 0; i { let word = new Array(); for (let i = 0; i < Common5.RollGameArr.length; ++i) { if (!User._gameData_custom.levelNum_Word_Array[i]) { word.push(0) } else { word.push(User._gameData_custom.levelNum_Word_Array[i]); } } //word[0] = 1; return word; } public static setlevelNum_SN_Array_custom(level: number) { User._gameData_custom.levelNum_SN_Array[level] = 1; GameMgr.getInstance_custom().saveGameData_custom(); } public static getlevelNum_SN_Array_custom(): Array { let sn = new Array(); for (let i = 0; i < Common5.SaveGameArr.length; ++i) { if (!User._gameData_custom.levelNum_SN_Array[i]) { sn.push(0) } else { sn.push(User._gameData_custom.levelNum_SN_Array[i]); } } sn[0] = 1; return sn; } //获取侦探笔记解锁标志,1提示解锁,2答案解锁 public static getUnlockWordgameAnswer(level){ for (let i = 0; i < User._gameData_custom.wordGameAnswerUnlock.length; i++){ if (User._gameData_custom.wordGameAnswerUnlock[i].level == level){ return User._gameData_custom.wordGameAnswerUnlock[i].flag; } } return 0; } //侦探笔记解锁标志,1提示解锁,2答案解锁 public static unlockWordgameAnswer(level,subLevel,unlockFlag){ let find = false for (let i = 0; i < User._gameData_custom.wordGameAnswerUnlock.length; i++){ if (User._gameData_custom.wordGameAnswerUnlock[i].level == level){ find = true; User._gameData_custom.wordGameAnswerUnlock[i].flag[subLevel] = unlockFlag; GameMgr.getInstance_custom().saveGameData_custom(); return; } } let lf = new LevelFlag(); lf.flag[subLevel] = unlockFlag; lf.level = level; User._gameData_custom.wordGameAnswerUnlock.push(lf); GameMgr.getInstance_custom().saveGameData_custom(); } //获取疯狂文字解锁标志,1提示解锁,2答案解锁 public static getUnlockWordgameAnswer_fkwz(level){ for (let i = 0; i < User._gameData_custom.wordGameAnswerUnlock_fkwz.length; i++){ if (User._gameData_custom.wordGameAnswerUnlock_fkwz[i].level == level){ return User._gameData_custom.wordGameAnswerUnlock_fkwz[i].flag; } } return 0; } //疯狂文字解锁标志,1提示解锁,2答案解锁 public static unlockWordgameAnswer_fkwz(level,unlockFlag){ let find = false for (let i = 0; i < User._gameData_custom.wordGameAnswerUnlock_fkwz.length; i++){ if (User._gameData_custom.wordGameAnswerUnlock_fkwz[i].level == level){ find = true; User._gameData_custom.wordGameAnswerUnlock_fkwz[i].flag = unlockFlag; GameMgr.getInstance_custom().saveGameData_custom(); return; } } let lf = new LevelFlag_fkwz(); lf.flag = unlockFlag; lf.level = level; User._gameData_custom.wordGameAnswerUnlock_fkwz.push(lf); GameMgr.getInstance_custom().saveGameData_custom(); } //解锁商店道具 public static unlockItem_custom(id: number) { if (User.itemIsUnlocked_custom(id)) { console.log("商店重复解锁 id : ", id); return; } console.log("商店解锁 id : ", id); User._gameData_custom.unlockedItem.push(id); GameMgr.getInstance_custom().saveGameData_custom(); EventMgr.emitEvent_custom(ryw_Event.ryw_Game_OnUserUnlockedStore_custom, { unlocked: id }) } /** * 数据校验 * @param data 校验的数据 * @param defaultValue 默认值 */ public static verify(data: any, defaultValue: any) { if (data !== undefined) { return data; } return defaultValue; } public static setDadianListGame(key, value) { User._gameData_custom.dadianListGame[key] = value; GameMgr.getInstance_custom().saveGameData_custom(); } public static getDadianListGame() { return User._gameData_custom.dadianListGame; } public static setFinishCeBianLanAward(bFinish) { User._gameData_custom.isFinishCeBianLanAward = bFinish GameMgr.getInstance_custom().saveGameData_custom(); } public static getFinishCeBianLanAward() { return User._gameData_custom.isFinishCeBianLanAward; } public static setUserId(userId) { console.log("setUserId",userId) User._gameData_custom.userId = userId; GameMgr.getInstance_custom().saveGameData_custom(); } public static getUserId() { console.log("getUserId",User._gameData_custom.userId) return User._gameData_custom.userId } public static setFirstIn(first:boolean) { if(User._gameData_custom.firstIn){ User._gameData_custom.firstIn = first; GameMgr.getInstance_custom().saveGameData_custom(); } } public static getFirstIn() { return User._gameData_custom.firstIn; } public static setUUID(num: string) { User._gameData_custom.uuid = num; GameMgr.getInstance_custom().saveGameData_custom(); } public static getUUID(): string { return User._gameData_custom.uuid; } public static saveDataToServer(){ if(!AppPlatform.is_TT_GAME_custom()){ //let sendData = User.sendDataToUrl() // CommonDefine.setServerData(sendData, ()=>{ // console.log('保存数据成功') // }, ()=>{ // console.log('保存数据失败') // }) }else{ let sendData = User.sendDataToUrl() CommonDefine.setServerData(sendData, ()=>{ console.log('保存数据成功') }, ()=>{ console.log('保存数据失败') }) } } public static sendDataToUrl() { let CollectLevels = User.getCollectLevels() let SuccessLevels = User.getSuccessLevels() let levelNum_Array = User.getLevelAryy_custom() let CollectLevelsStr = '' for(let i = 0;i