290 lines
6.8 KiB
JavaScript
290 lines
6.8 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,
|
|
},
|
|
|
|
stars: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
fullStarSpriteframe: {
|
|
default: null,
|
|
type: cc.SpriteFrame,
|
|
},
|
|
ceg_num: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
// needNode: {
|
|
// default: null,
|
|
// type: cc.Node,
|
|
// },
|
|
},
|
|
|
|
initData(data, ceg_num) {
|
|
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);
|
|
|
|
console.log(data.param2);
|
|
|
|
if (data.param2) {
|
|
for (let i = 0; i < data.param2; i += 1) {
|
|
console.log('set onmr ');
|
|
this.stars.children[i].getComponent(cc.Sprite).spriteFrame =
|
|
this.fullStarSpriteframe;
|
|
}
|
|
}
|
|
|
|
if (data.param3) {
|
|
for (let i = 0; i < this.herolistNode.children.length; i += 1) {
|
|
this.herolistNode.children[i].active = false;
|
|
}
|
|
for (let i = 0; i < data.param3; i += 1) {
|
|
this.herolistNode.children[i].active = true;
|
|
}
|
|
}
|
|
if (data.param4) {
|
|
for (let i = 0; i < this.gunlistNode.children.length; i += 1) {
|
|
this.gunlistNode.children[i].active = false;
|
|
}
|
|
for (let i = 0; i < data.param4; i += 1) {
|
|
this.gunlistNode.children[i].active = true;
|
|
}
|
|
}
|
|
|
|
this.ceg_num.string = `x${ceg_num}`;
|
|
},
|
|
|
|
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()) {
|
|
var heroNum = 0;
|
|
this.sendData = '';
|
|
this.allChooseHero.forEach((element) => {
|
|
if (element) {
|
|
if (element.hero_uniid) {
|
|
heroNum += 1;
|
|
this.sendData += `${1}:${element.hero_uniid}|`;
|
|
}
|
|
}
|
|
});
|
|
|
|
this.allChooseGun.forEach((element) => {
|
|
if (element) {
|
|
if (element.gun_uniid) {
|
|
this.sendData += `${0}:${element.gun_uniid}|`;
|
|
}
|
|
}
|
|
});
|
|
|
|
if (heroNum == 0) {
|
|
cc.uiHelper.showTips('Must choose a hero');
|
|
return;
|
|
}
|
|
|
|
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');
|
|
}
|
|
},
|
|
});
|