278 lines
6.4 KiB
JavaScript
278 lines
6.4 KiB
JavaScript
const {
|
|
dropConfig,
|
|
all_ItemConfig,
|
|
} = require('../../game/gameConfig');
|
|
const NetManage = require('../../manages/NetManage');
|
|
const { type } = require('../../netBattle/net/proto/bytebuffer');
|
|
var Utils = require("Utils")
|
|
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
mission_detail: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
// allAddNode: {
|
|
// default: null,
|
|
// type: cc.Node,
|
|
// },
|
|
|
|
missionTitle:{
|
|
default:null,
|
|
type:cc.Label
|
|
},
|
|
|
|
missionDesc:{
|
|
default:null,
|
|
type:cc.Label
|
|
},
|
|
|
|
herolistNode:{
|
|
default:null,
|
|
type:cc.Node
|
|
},
|
|
|
|
gunlistNode:{
|
|
default:null,
|
|
type:cc.Node
|
|
},
|
|
|
|
rewardIcons:{
|
|
default:null,
|
|
type:cc.Node
|
|
}
|
|
|
|
// needNode: {
|
|
// default: null,
|
|
// type: cc.Node,
|
|
// },
|
|
},
|
|
|
|
initData(data) {
|
|
|
|
console.log("mission detail:"+JSON.stringify(data))
|
|
this.allChooseHero = new Array();
|
|
this.allChooseHero.length = 5;
|
|
this.allChooseGun = new Array();
|
|
this.allChooseHero.length = 10;
|
|
|
|
this.missionData = data;
|
|
|
|
this.setRewards(data.reward)
|
|
|
|
// this.currentBtn = 0;
|
|
// this.allChoose.length = 5;
|
|
|
|
// this.allShowNode = new Array();
|
|
|
|
// this.allNeed = new Array();
|
|
// if (data.param1) {
|
|
// this.initNeedIcon(data.param1, 0);
|
|
// this.allNeed.push(data.param1.toString());
|
|
// }
|
|
// if (data.param2) {
|
|
// this.initNeedIcon(data.param2, 1);
|
|
// this.allNeed.push(data.param2.toString());
|
|
// }
|
|
// if (data.param3) {
|
|
// this.initNeedIcon(data.param3, 2);
|
|
// this.allNeed.push(data.param3.toString());
|
|
// }
|
|
// if (data.param4) {
|
|
// this.initNeedIcon(data.param4, 3);
|
|
// this.allNeed.push(data.param4.toString());
|
|
// }
|
|
// if (data.param5) {
|
|
// this.initNeedIcon(data.param5, 4);
|
|
// this.allNeed.push(data.param5.toString());
|
|
// }
|
|
},
|
|
|
|
setRewards(string){
|
|
var config = dropConfig[string]
|
|
var rewards = config.itemdata
|
|
// console.log(`reward---${JSON.stringify(rewards)}`)
|
|
|
|
for(let i=0;i<rewards.length;i+=1){
|
|
let id = rewards[i].id
|
|
let num = rewards[i].num
|
|
var tmp = this.rewardIcons.children[i]
|
|
tmp.active = true
|
|
tmp.children[0].getComponent(cc.Label).string = `x${num}`
|
|
|
|
// console.log(JSON.stringify(all_ItemConfig[id]))
|
|
|
|
// Utils.setitem(this, id, tmp.children[1]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// initNeedIcon(param, index) {
|
|
// var count = param.toString().length;
|
|
// var url = '';
|
|
// if (count == 1) {
|
|
// url = `textures/wanted/ocupation_${param}`;
|
|
// } else {
|
|
// if (param.toString()[0] == '3') {
|
|
// url = `textures/wanted/role_${param}`;
|
|
// } else if (param.toString()[0] == '7') {
|
|
// url = `textures/wanted/weapon_${param}`;
|
|
// } else if (param.toString()[0] == '2') {
|
|
// var pp = dropItemConfig[param.toString()].link_sort;
|
|
// url = `textures/wanted/weapon_${pp}`;
|
|
// this.allNeed.push(pp.toString());
|
|
// }
|
|
// }
|
|
// if (url != '') {
|
|
// cc.loader.loadRes(url, cc.SpriteFrame, (err, res) => {
|
|
// if (err) {
|
|
// return false;
|
|
// }
|
|
|
|
// var paramp = param;
|
|
// if (param.toString()[0] == '2') {
|
|
// paramp =
|
|
// dropItemConfig[param.toString()].link_sort.toString();
|
|
// }
|
|
|
|
// // this.needNode.children[index].name = `${paramp}`;
|
|
// // this.needNode.children[index].getComponent(
|
|
// // cc.Sprite
|
|
// // ).spriteFrame = res;
|
|
// // this.needNode.children[index].active = true;
|
|
// // this.allShowNode.push(this.needNode.children[index]);
|
|
// });
|
|
// }
|
|
// },
|
|
|
|
onLoad() {
|
|
cc.Notifier.on('hasChooseHero', this, (data) => {
|
|
if(this.herolistNode){
|
|
this.herolistNode.children[this.currentBtn]
|
|
.getComponent('mission_oneBox')
|
|
.init(data);
|
|
this.allChooseHero[this.currentBtn] = data;
|
|
}
|
|
|
|
});
|
|
|
|
cc.Notifier.on('hasChooseGun', this, (data) => {
|
|
if(this.gunlistNode){
|
|
this.gunlistNode.children[this.currentBtn]
|
|
.getComponent('mission_oneBox')
|
|
.init(data);
|
|
this.allChooseGun[this.currentBtn] = data;
|
|
}
|
|
|
|
});
|
|
|
|
// cc.Notifier.on('ClearOneBox', this, (data) => {
|
|
// this.allChoose[data] = null;
|
|
// this.setIcon();
|
|
// });
|
|
},
|
|
|
|
|
|
close() {
|
|
this.node.destroy();
|
|
cc.Notifier.off('hasChooseHero', this);
|
|
cc.Notifier.off('hasChooseGun', this);
|
|
|
|
},
|
|
|
|
onClickAdd(event, param) {
|
|
this.currentBtn = param;
|
|
console.log(this.currentBtn)
|
|
this.mission_detail.active = true;
|
|
// set currentdata
|
|
|
|
console.log()
|
|
|
|
var type = 0;
|
|
if(event.currentTarget.parent.name=="Hero"){
|
|
type = 0
|
|
}else{
|
|
type = 1
|
|
}
|
|
|
|
this.mission_detail
|
|
.getComponent('mission_chooseDetail')
|
|
.init(this.allChooseHero,this.allChooseGun,type);
|
|
},
|
|
|
|
check() {
|
|
return true
|
|
// let toReturn = true;
|
|
// this.allShowNode.forEach((element) => {
|
|
// if (element.children[0].active == false) {
|
|
// toReturn = false;
|
|
// }
|
|
// });
|
|
// return toReturn;
|
|
// this.hasChooseParam = new Array();
|
|
// this.allChoose.forEach((element) => {
|
|
// if (element) {
|
|
// if (element.gun_id) {
|
|
// this.hasChooseParam.push(element.gun_id);
|
|
// }
|
|
// if (element.hero_id) {
|
|
// var type = playerConfig[element.hero_id].herotype;
|
|
// this.hasChooseParam.push(element.hero_id);
|
|
// this.hasChooseParam.push(type.toString());
|
|
// }
|
|
// }
|
|
// });
|
|
// function includes(arr1, arr2) {
|
|
// console.log(arr1);
|
|
// console.log(arr2);
|
|
// return arr2.every((val) => arr1.includes(val));
|
|
// }
|
|
// return includes(this.hasChooseParam, this.allNeed);
|
|
},
|
|
|
|
// 0:1234|1:1234
|
|
onClickSend() {
|
|
if (this.check()) {
|
|
this.sendData = '';
|
|
this.allChooseHero.forEach((element) => {
|
|
if (element) {
|
|
if (element.hero_uniid) {
|
|
this.sendData += `${1}:${element.hero_uniid}|`;
|
|
}
|
|
}
|
|
});
|
|
|
|
this.allChooseGun.forEach((element) => {
|
|
if (element) {
|
|
if (element.gun_uniid) {
|
|
this.sendData += `${0}:${element.gun_uniid}|`;
|
|
}
|
|
}
|
|
});
|
|
|
|
if(this.sendData!=""){
|
|
NetManage.sendWantedMission(
|
|
this.missionData.id,
|
|
this.sendData,
|
|
(res) => {
|
|
if (res.errcode == 0) {
|
|
this.node.destroy();
|
|
cc.Notifier.emit('ReFreshMission');
|
|
} else {
|
|
cc.uiHelper.showTips('Failed');
|
|
}
|
|
}
|
|
);
|
|
}else{
|
|
cc.uiHelper.showTips('Not meeting the requirements');
|
|
}
|
|
} else {
|
|
cc.uiHelper.showTips('Not meeting the requirements');
|
|
}
|
|
},
|
|
});
|