404 lines
11 KiB
JavaScript
404 lines
11 KiB
JavaScript
/*******************************************************************************
|
|
*
|
|
* 活动: 七日特训
|
|
*
|
|
*
|
|
******************************************************************************/
|
|
|
|
const ActBase = require( "act.base" );
|
|
const ActDefine = require( "acts.define" );
|
|
const ActEvt = require("action_event");
|
|
|
|
const ActDay7 = cc.Class( {
|
|
|
|
extends: ActBase,
|
|
|
|
// 初始化配置数据
|
|
initConfig: function() {
|
|
|
|
// 视图附着
|
|
// this.vattach( ActDefine.ViewActs );
|
|
|
|
},
|
|
|
|
// 注册协议接受事件
|
|
registerProtocals: function() {
|
|
// 前端准备完毕
|
|
// 七天目标
|
|
this.RegisterProtocal(13601, this.handle13601.bind(this)); //數據初始化
|
|
this.RegisterProtocal(13602, this.handle13602.bind(this)); //領獎
|
|
},
|
|
|
|
// 从服务器初始化数据
|
|
reqBaseFromServer: function( _cb ) {
|
|
// 配置加载
|
|
let cfgs = [
|
|
"day_goals_data"
|
|
];
|
|
this.loadConfigs( cfgs, ( _ret, _data ) => {
|
|
this.reqBaseData( _cb );
|
|
} );
|
|
},
|
|
|
|
// 请求剧情信息
|
|
reqBaseData: function( _cb ) {
|
|
|
|
this.SendProtocal(13601, {}, _cb );
|
|
},
|
|
|
|
sender13601: function () {
|
|
this.SendProtocal(13601, {});
|
|
},
|
|
|
|
handle13601: function (data) {
|
|
if (data.period == 0) return;
|
|
this.setCurDay(data.cur_day);
|
|
this.setSevenGoldPeriod(data.period || 1);
|
|
this.initSevenWalfare(data.period || 1);
|
|
|
|
this.setSevenGoalWelfareList(data.welfare_list);
|
|
this.setSevenGoalGrowList(data.grow_list);
|
|
this.setHalfGiftList(data.price_list);
|
|
|
|
this.setSevenGoalBoxList(data.finish_list, data.num);
|
|
this.setLastScore(data.num);
|
|
|
|
gcore.GlobalEvent.fire(ActEvt.UPDATE_SEVENT_GOAL, data);
|
|
},
|
|
|
|
// 请求七日活动领取
|
|
sender13602: function (type, day, id, item) {
|
|
let protocal = {};
|
|
protocal.type = type;
|
|
protocal.day_type = day;
|
|
protocal.id = id;
|
|
protocal.item = item;
|
|
this.SendProtocal(13602, protocal);
|
|
},
|
|
|
|
handle13602: function (data) {
|
|
if (data.flag == 1) {
|
|
if(data.type == 5){
|
|
this.updataBoxListData(data.id - 1,data.status);
|
|
}
|
|
gcore.GlobalEvent.fire(ActEvt.UPDATE_SEVENT_GET, data);
|
|
}else{
|
|
nx.tbox(data.msg);
|
|
}
|
|
},
|
|
|
|
// ============================================================
|
|
// 數據處理
|
|
// ============================================================
|
|
setCurDay:function(day){
|
|
this.cur_day = day || 1;
|
|
},
|
|
|
|
getCurDay(){
|
|
return this.cur_day;
|
|
},
|
|
|
|
// 获取七日目标的周期数
|
|
setSevenGoldPeriod:function(period){
|
|
nx.bridge.acts.vset("sevenPeriod",period);
|
|
},
|
|
|
|
getSevenGoldPeriod:function(){
|
|
return nx.bridge.acts.vget("sevenPeriod");
|
|
},
|
|
|
|
initSevenWalfare:function(index){
|
|
this.setWalfareData(index);
|
|
this.setWalfareGrowUpData(index);
|
|
this.setHalfGiftData(index);
|
|
this.setBoxRewardData(index);
|
|
},
|
|
|
|
// 宝箱
|
|
setBoxRewardData:function(index){
|
|
var data = game.configs.day_goals_data.data_all_target[index]
|
|
let list = [];
|
|
for(var i in data){
|
|
list.push(data[i][0]);
|
|
}
|
|
list.sort(function(a,b){
|
|
return a.id - b.id;
|
|
})
|
|
nx.bridge.acts.vset("boxRewards",list);
|
|
},
|
|
|
|
getBoxRewardData:function(){
|
|
return nx.bridge.acts.vget("boxRewards") || [];
|
|
},
|
|
|
|
// 福利
|
|
setWalfareData:function(index){
|
|
var data = game.configs.day_goals_data.data_welfarecollection[index];
|
|
this.welfareData = data;
|
|
},
|
|
|
|
// 成长目标
|
|
setWalfareGrowUpData:function(index){
|
|
var data = game.configs.day_goals_data.data_growthtarget[index];
|
|
this.welfareGrowData = [];
|
|
// this.welfareGiftData = [];
|
|
for(var i in data){
|
|
var tab = [];
|
|
// var tab1 = [];
|
|
for(var k in data[i]){
|
|
tab.push(data[i][k]);
|
|
// if(data[i][k].target_type == 1){
|
|
// tab.push(data[i][k]);
|
|
// }else if(data[i][k].target_type == 2){
|
|
// tab1.push(data[i][k]);
|
|
// }
|
|
}
|
|
this.welfareGrowData.push(tab);
|
|
// this.welfareGiftData.push(tab1);
|
|
}
|
|
},
|
|
|
|
// 福利礼包
|
|
setHalfGiftData:function(index){
|
|
var data = game.configs.day_goals_data.data_halfdiscount[index];
|
|
this.walfareHalfData = [];
|
|
for(var i=1;i<=7;i++){
|
|
this.walfareHalfData[i] = [];
|
|
}
|
|
|
|
for(var i in data){
|
|
this.walfareHalfData[data[i][0].day].push(data[i][0]);
|
|
}
|
|
|
|
for(var i=1;i<=7;i++){
|
|
this.walfareHalfData[i].sort(function(a,b){
|
|
return a.id - b.id;
|
|
});
|
|
}
|
|
},
|
|
|
|
getWalfareData:function(day){
|
|
if(!this.welfareData)return;
|
|
return this.welfareData[day] || [];
|
|
},
|
|
|
|
getWalfareGrowUpData:function(day){
|
|
if(!this.welfareGrowData)return;
|
|
return this.welfareGrowData[day] || [];
|
|
},
|
|
|
|
getWelfareGiftData:function(day){
|
|
if(!this.welfareGiftData)return;
|
|
return this.welfareGiftData[day] || [];
|
|
},
|
|
|
|
getWelfareHalfData:function(day){
|
|
if(this.walfareHalfData && this.walfareHalfData[day]){
|
|
return this.walfareHalfData[day] || [];
|
|
}
|
|
},
|
|
|
|
setLastScore(num){
|
|
this.last_score = num;
|
|
},
|
|
|
|
getLastScore(){
|
|
return this.last_score || 0;
|
|
},
|
|
|
|
// 七天目标的福利领取
|
|
setSevenGoalWelfareList:function(data){
|
|
this.welfareList = [];
|
|
for(var i=1;i<=7;i++){
|
|
this.welfareList[i] = [];
|
|
}
|
|
for(var i in data){
|
|
this.welfareList[data[i].day].push(data[i]);
|
|
}
|
|
|
|
this.freshTips();
|
|
},
|
|
|
|
getSevenGoalWelfareList:function(day){
|
|
if(!this.welfareList)return;
|
|
return this.welfareList[day] || [];
|
|
},
|
|
|
|
// 更新数据
|
|
updataGoalWelfareList:function(day, index, status){
|
|
this.welfareList[day][index].status = status;
|
|
this.freshTips();
|
|
},
|
|
|
|
// 七天目标的成长目标
|
|
setSevenGoalGrowList:function(data){
|
|
var grow_list = [];
|
|
for(var i=1;i<=7;i++){
|
|
grow_list[i] = [];
|
|
}
|
|
for(var i in data){
|
|
grow_list[data[i].day].push(data[i]);
|
|
}
|
|
|
|
this.serverGrowListData = [];
|
|
// this.serverGiftListData = [];
|
|
for(var i in grow_list){
|
|
var tab = [];
|
|
// var tab1 = [];
|
|
for(var k in grow_list[i]){
|
|
tab.push(grow_list[i][k]);
|
|
// if(grow_list[i][k].target_type == 1){
|
|
// tab.push(grow_list[i][k]);
|
|
// }else if(grow_list[i][k].target_type == 2){
|
|
// tab1.push(grow_list[i][k]);
|
|
// }
|
|
}
|
|
this.serverGrowListData.push(tab);
|
|
// this.serverGiftListData.push(tab1);
|
|
}
|
|
|
|
this.freshTips();
|
|
},
|
|
|
|
getServerGrowListData:function(day){
|
|
if(this.serverGrowListData && this.serverGrowListData[day]){
|
|
return this.serverGrowListData[day] || [];
|
|
}
|
|
return [];
|
|
},
|
|
|
|
// 更新数据
|
|
updataGrowListData:function(day, index, status){
|
|
this.serverGrowListData[day][index].status = status;
|
|
this.freshTips();
|
|
},
|
|
|
|
// getServerGiftListData:function(day){
|
|
// if(!this.serverGiftListData)return;
|
|
// return this.serverGiftListData[day] || [];
|
|
// },
|
|
|
|
// // 更新数据
|
|
// updataGiftListData:function(day, index, status){
|
|
// this.serverGiftListData[day][index].status = status;
|
|
// },
|
|
|
|
// 福利礼包礼包购买
|
|
setHalfGiftList:function(data){
|
|
this.halfGiftList = [];
|
|
for(var i=1;i<=7;i++){
|
|
this.halfGiftList[i] = [];
|
|
}
|
|
for(var i=1;i<=7;i++){
|
|
var half_list = this.getWelfareHalfData(i);
|
|
for(var k in half_list){
|
|
for(var b in data){
|
|
if(half_list[k].id == data[b].day){
|
|
this.halfGiftList[i].push(data[b]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
getHalfGiftList:function(day){
|
|
if(this.halfGiftList && this.halfGiftList[day]){
|
|
return this.halfGiftList[day] || [];
|
|
}
|
|
},
|
|
|
|
// 更新数据
|
|
updataHalfListData:function(day, index, status){
|
|
this.halfGiftList[day][index].status = status;
|
|
},
|
|
|
|
// 活跃宝箱
|
|
setSevenGoalBoxList:function(data){
|
|
this.boxList = data;
|
|
},
|
|
|
|
getSevenGoalBoxList:function(){
|
|
if(!this.boxList)return;
|
|
this.boxList.sort(Utils.tableLowerSorter(["goal_id"]));
|
|
return this.boxList || [];
|
|
},
|
|
|
|
// 更新数据
|
|
updataBoxListData:function(index, status){
|
|
this.boxList[index].status = status;
|
|
},
|
|
|
|
sortItemList(list){
|
|
let tempsort = {
|
|
[0] : 2, //-- 0 未领取放中间
|
|
[1] : 1, //-- 1 可领取放前面
|
|
[2] : 3, //-- 2 已领取放最后
|
|
}
|
|
let sortFunc = function (objA,objB){
|
|
if (objA.status != objB.status){
|
|
if (tempsort[objA.status] && tempsort[objB.status]){
|
|
return tempsort[objA.status] - tempsort[objB.status]
|
|
}else{
|
|
return -1
|
|
}
|
|
}else{
|
|
return objA.aim - objB.aim
|
|
}
|
|
}
|
|
list.sort(sortFunc)
|
|
},
|
|
// ============================================================
|
|
// 活动红点提示
|
|
// ============================================================
|
|
|
|
// 活动用到的提示KEY
|
|
tipKeys: function() {
|
|
return ["day1","day2","day3","day4","day5","day6","day7"];
|
|
},
|
|
|
|
freshTips(){
|
|
let list1 = this.serverGrowListData;
|
|
for(let day in list1){
|
|
if(Number(day) < this.getCurDay()){
|
|
let arr = list1[day];
|
|
let is_open = false;
|
|
for(let i = 0;i < arr.length;i++){
|
|
let data = arr[i];
|
|
if(data.status == 1){
|
|
is_open = true;
|
|
}
|
|
}
|
|
if(!is_open){
|
|
this.openTip( this.tipKeys()[day], false );
|
|
}else{
|
|
this.openTip( this.tipKeys()[day], true );
|
|
}
|
|
}else{
|
|
this.openTip( this.tipKeys()[day], false );
|
|
}
|
|
}
|
|
|
|
|
|
// let list2 = this.welfareList;
|
|
// for(let day in list2){
|
|
// let arr = list2[day];
|
|
// if(arr.length > 0){
|
|
// let is_reward = false;
|
|
// for(let i = 0;i < arr.length;i++){
|
|
// let data = arr[i];
|
|
// if(data.status == 1){
|
|
// is_reward = true;
|
|
// }
|
|
// }
|
|
// if(!is_reward){
|
|
// this.openTip( this.tipKeys()[day], false );
|
|
// }else{
|
|
// this.openTip( this.tipKeys()[day], true );
|
|
// }
|
|
// }
|
|
// }
|
|
},
|
|
} );
|
|
|
|
// 模块导出
|
|
module.exports = ActDay7; |