var i = require('ModuleEventEnum');
require('MathUtils');
cc.Class({
extends: cc.Component,
properties: {},
initConfig: function() {
cc.loader.loadRes("config/SignConfig", this.setConfig.bind(this)), cc.loader.loadRes("config/CharacterConfig", cc.JsonAsset, this.characterLoaded.bind(this)), cc.systemEvent.on(i.WX_SHOW, this.onWxShow.bind(this)), cc.systemEvent.on(i.WX_HIDE, this.onWxHide.bind(this))
},
dealLoadData: function(e) {
var t = JSON.parse(e);
this.gotGameRecord = !0, this.localCash = t || {}, console.log("GameModel data:", e), facade.getComponent("LevelModel").httpResDeal(this.localCash), this.formDatas()
},
httpResDeal: function(e) {},
getLocalTime: function() {
var e = new Date;
return e.getTime() - 6e4 * e.getTimezoneOffset()
},
getLocalTimeHour: function() {
return (new Date).getHours()
},
formDatas: function(e) {
this.firstLoginTime1 = this.localCash.firstLoginTime1, this.cash = Number(this.localCash.cash), this.energy = Number(this.localCash.energy), this.energyLostTime = Number(this.localCash.energyLostTime), this.characterId = Number(this.localCash.characterId), this.unlockCharacters = this.localCash.unlockCharacters, this.characterVideoCounts = this.localCash.characterVideoCounts, this.lastRewardEnergyTime = Number(this.localCash.lastRewardEnergyTime), this.rewardEnergyCount = Number(this.localCash.rewardEnergyCount), this.lastFetchColectTime = Number(this.localCash.lastFetchColectTime), this.lastFetchSignInTime = Number(this.localCash.lastFetchSignInTime), this.fetchDays = Number(this.localCash.fetchDays), this.aliveFetchList = this.localCash.aliveFetchList, this.newbieFetchList = this.localCash.newbieFetchList, this.lastFetchFloatReward = this.localCash.lastFetchFloatReward, this.lastFetchClientTime = this.localCash.lastFetchClientTime, this.gotNextReward = Number(this.localCash.gotNextReward), this.gotNewerReward = Number(this.localCash.gotNewerReward), this.gotAdvanceReward = Number(this.localCash.gotAdvanceReward), this.oneShotLevelList = this.localCash.oneShotLevelList, this.oneShotLevel = Number(this.localCash.oneShotLevel), this.oneShotLevelCupNum = Number(this.localCash.oneShotLevelCupNum), this.levelShotUpdate = Number(this.localCash.levelShotUpdate), this.chanllenTimes = Number(this.localCash.chanllenTimes), this.cupNumData = Number(this.localCash.cupNumData), this.levelFreeRetry = Number(this.localCash.levelFreeRetry), this.today = this.localCash.today, e || (this.localCash.today ? this.today != (new Date).getMonth() + "_" + (new Date).getDate() && (this.today = (new Date).getMonth() + "_" + (new Date).getDate(), this.aliveFetchList = [], this.newbieFetchList = [], this.saveData()) : (this.today = (new Date).getMonth() + "_" + (new Date).getDate(), this.saveData())), this.levelFreeRetry || (this.levelFreeRetry = 0), this.oneShotLevelCupNum || (this.oneShotLevelCupNum = 0), this.chanllenTimes || (this.chanllenTimes = 0), this.oneShotLevel || (this.oneShotLevel = 0), this.cupNumData || (this.cupNumData = 0), this.oneShotLevelList || (this.oneShotLevelList = []), this.levelShotUpdate || (this.levelShotUpdate = 0), this.cash || (this.cash = 0), this.gotNextReward || (this.gotNextReward = 0), this.gotNewerReward || (this.gotNewerReward = 0), this.gotAdvanceReward || (this.gotAdvanceReward = 0), this.characterId || (this.characterId = 1, this.unlockCharacters = [1]), this.characterVideoCounts || (this.characterVideoCounts = {}), this.energyLostTime || (this.energyLostTime = 0, (!this.energy || this.energy < 15) && (this.energy = this.maxEnergy));
var t = Math.floor(this.getLocalTime() / 86400 / 1e3);
if (this.lastRewardEnergyTime) {
var n = Math.floor(this.lastRewardEnergyTime / 86400 / 1e3),
o = new Date(86400 * n * 1e3),
a = new Date(86400 * t * 1e3);
console.log("lastRewardDate:", a.toString()), console.log("todayDate:", o.toString()), n < t && (this.rewardEnergyCount = 0, this.lastRewardEnergyTime = this.getLocalTime(), this.levelShotUpdate = 0, this.chanllenTimes = 0, this.freeLuckyVideoTimes = 0, this.cupNumData = 0, this.oneShotLevelCupNum = 0, this.oneShotLevel = 0, this.levelFreeRetry = 0)
} else this.lastRewardEnergyTime = 0;
this.getLocalTimeHour() >= 21 && 0 == this.levelShotUpdate && (this.levelShotUpdate = 1), this.levelRetryTouch = !1;
var s = new Date;
if (this.energy < this.maxEnergy && this.energyLostTime) {
var c = s.getTime() - this.energyLostTime,
r = Math.floor(c / (2 * this.energyCD));
r + this.energy > 15 && (r = 15 - this.energy), this.energy += r, this.energyLostTime += r * this.energyCD * 2, this.energy >= this.maxEnergy && (this.energyLostTime = 0), this.offlineEnergy(r)
}
this.lastFetchColectTime || (this.lastFetchColectTime = 0), this.lastFetchSignInTime || (this.lastFetchSignInTime = 0), this.fetchDays || (this.fetchDays = 0), this.aliveFetchList || (this.aliveFetchList = []), this.newbieFetchList || (this.newbieFetchList = []), this.lastFetchFloatReward || (this.lastFetchFloatReward = 0), this.lastFetchClientTime || (this.lastFetchClientTime = 0), e || ("Game" != facade.CurrentScene ? facade.needShowSign = !0 : (facade.needShowSign = !1, this.saveData(), cc.systemEvent.emit(i.INIT_ROLEINFO_COMPLETED)))
},
setShotUpdateData: function(e) {
this.levelShotUpdate = e, this.saveData()
},
setAddChanllenNum: function() {
this.chanllenTimes++, this.saveData()
},
setOneShotLeves: function() {
if (facade.getComponent("LevelModel").oneShotConfigList) {
this.oneShotLevelList = [], this.oneShotLevel = 1, this.oneShotLevelCupNum = 0;
for (var e = facade.getComponent("LevelModel").oneShotConfigList.length; this.oneShotLevelList.length < 20;) {
for (var t = Math.floor(Math.random() * e + 1), n = !1, i = 0; i < this.oneShotLevelList.length; i++)
if (this.oneShotLevelList[i] == t) {
n = !0;
break
} n || (this.oneShotLevelList.push(t), 0)
}
this.saveData()
}
},
onLevelShotPassed: function() {
this.showLevelOver = !1, this.oneShotLevel < 20 ? this.oneShotLevel++ : 20 == this.oneShotLevel && (this.showLevelOver = !0);
var e = facade.getComponent("LevelModel").nowLevelConfig.LuckyPoint;
this.cupNumData += e, this.oneShotLevelCupNum += e;
var t = {
game_id: window.facade.GameId,
token: window.facade.getComponent("PlayerModel").token,
score_type: 2,
score: this.cupNumData
};
window.net.getComponent("Net").httpRequest(window.net.SaveScore, t), this.node.runAction(cc.sequence(cc.delayTime(3), cc.callFunc(this.goToShotNextLevel, this))), this.saveData()
},
goToShotNextLevel: function() {
this.showLevelOver ? cc.systemEvent.emit(i.SHOT_NOW_OVER_SHOW) : cc.systemEvent.emit(i.GO_SHOT_NEXT)
},
onLevelShotNext: function() {
this.oneShotLevel < 20 ? this.oneShotLevel++ : 20 == this.oneShotLevel && this.setOneShotLeves(), cc.systemEvent.emit(i.GO_SHOT_NEXT), this.saveData()
},
setOpenRankfFlag: function(e) {
this.openRankFlag = e
},
getFreeRetry: function() {
var e = facade.getComponent("ShareADModel").GameConfig.Free_Rematch_Cnt.Value;
return !!e && this.levelFreeRetry <= e
},
setAddFreeRetryNum: function() {
this.levelFreeRetry++, this.saveData()
},
offlineEnergy: function(e) {
console.log("offlineEnergy:", e), this._offLineEnergy = e, this.saveData()
},
characterLoaded: function(e, t) {
console.log("asset:", t), this.charaterConfig = t.json, cc.systemEvent.emit(i.CHARACTER_INFO)
},
setConfig: function(e, t) {
if (e) console.er