198 lines
4.5 KiB
JavaScript
198 lines
4.5 KiB
JavaScript
const { dropConfig, all_ItemConfig } = require('../../game/gameConfig');
|
|
const NetManage = require('../../manages/NetManage');
|
|
var Utils = require('Utils');
|
|
const { uimanger } = require('../UIManger');
|
|
const { CancelBoost } = require('../../tips/CancelBoost');
|
|
const { BoostTips } = require('../../tips/BoostTips');
|
|
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
title: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
allRewardNode: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
missionPrefab: {
|
|
default: null,
|
|
type: cc.Prefab,
|
|
},
|
|
lb_time: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
|
|
getNode: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
receiveNode: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
boostNode: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
stars: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
fullStarSpriteframe: {
|
|
default: null,
|
|
type: cc.SpriteFrame,
|
|
},
|
|
|
|
ceg_num: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
},
|
|
|
|
onLoad() {
|
|
cc.Notifier.on('boostcancel', this, this.hasCancelBoost.bind(this));
|
|
cc.Notifier.on('boostsuccess', this, this.boostsuccess.bind(this));
|
|
},
|
|
|
|
onDestroy() {
|
|
cc.Notifier.off('boostcancel', this, this.hasCancelBoost.bind(this));
|
|
cc.Notifier.off('boostsuccess', this, this.boostsuccess.bind(this));
|
|
},
|
|
|
|
onClickBtn() {
|
|
if (this.missionState == 0) {
|
|
NetManage.commitMission(this.missionId, () => {
|
|
cc.uiHelper.showTips('Get Reward Success!');
|
|
});
|
|
this.node.destroy();
|
|
}
|
|
if (this.missionState == 1) {
|
|
const node = cc.instantiate(this.missionPrefab);
|
|
node.getComponent('mission_choose').initData(
|
|
this.wantedData,
|
|
this.ceg
|
|
);
|
|
cc.find('Canvas').addChild(node);
|
|
}
|
|
if (this.missionState == 2) {
|
|
var data = {
|
|
cegNum: 10,
|
|
missionId: this.missionId,
|
|
};
|
|
uimanger.showUI(BoostTips.prefabPath, data);
|
|
}
|
|
},
|
|
|
|
onCancelBtn() {
|
|
uimanger.showUI(CancelBoost.prefabPath);
|
|
},
|
|
|
|
hasCancelBoost() {
|
|
NetManage.cancelOfferRewardMission(this.missionId, () => {
|
|
this.boostNode.active = false;
|
|
this.receiveNode.active = false;
|
|
this.getNode.active = true;
|
|
this.lb_time.node.parent.active = false;
|
|
cc.uiHelper.showTips('Boost cancel!');
|
|
});
|
|
},
|
|
|
|
boostsuccess() {
|
|
NetManage.boostOfferRewardMission(this.missionId, () => {
|
|
// this.node.destroy();
|
|
cc.uiHelper.showTips('Boost Success!');
|
|
});
|
|
},
|
|
|
|
formatSeconds(value) {
|
|
let result = parseInt(value);
|
|
let h =
|
|
Math.floor(result / 3600) < 10
|
|
? '0' + Math.floor(result / 3600)
|
|
: Math.floor(result / 3600);
|
|
let m =
|
|
Math.floor((result / 60) % 60) < 10
|
|
? '0' + Math.floor((result / 60) % 60)
|
|
: Math.floor((result / 60) % 60);
|
|
let s =
|
|
Math.floor(result % 60) < 10
|
|
? '0' + Math.floor(result % 60)
|
|
: Math.floor(result % 60);
|
|
|
|
let res = '';
|
|
res += `${h}:`;
|
|
res += `${m}:`;
|
|
res += `${s}`;
|
|
return res;
|
|
},
|
|
|
|
init(data, originData) {
|
|
if (data.param2) {
|
|
for (let i = 0; i < data.param2; i += 1) {
|
|
this.stars.children[i].getComponent(cc.Sprite).spriteFrame =
|
|
this.fullStarSpriteframe;
|
|
}
|
|
}
|
|
|
|
this.wantedData = data;
|
|
this.missionId = originData.mission_id;
|
|
if (originData.state == 0) {
|
|
// this.btn_label.string = 'GET';
|
|
this.receiveNode.active = true;
|
|
this.missionState = 0;
|
|
}
|
|
if (originData.state == 2) {
|
|
if (originData.objects.length == 0) {
|
|
// this.btn_label.string = 'RECEIVE';
|
|
this.getNode.active = true;
|
|
this.missionState = 1;
|
|
} else {
|
|
var leftTime = originData.lefttime;
|
|
this.lb_time.node.parent.active = true;
|
|
// this.btn_label.string = 'BOOST';
|
|
this.boostNode.active = true;
|
|
this.missionState = 2;
|
|
this.lb_time.string = this.formatSeconds(leftTime);
|
|
this.schedule(function () {
|
|
this.lb_time.string = this.formatSeconds((leftTime -= 1));
|
|
if (leftTime <= 0) {
|
|
cc.Notifier.emit('FinishOne');
|
|
}
|
|
}, 1);
|
|
}
|
|
}
|
|
if (originData.state == 1) {
|
|
this.node.destroy();
|
|
}
|
|
|
|
this.ceg = originData.ceg_num;
|
|
this.ceg_num.string = `x${originData.ceg_num}`;
|
|
},
|
|
|
|
start() {
|
|
this.setRewards(this.wantedData.reward);
|
|
},
|
|
|
|
setRewards(string) {
|
|
var config = dropConfig[string];
|
|
var rewards = config.itemdata;
|
|
|
|
for (let i = 0; i < rewards.length; i += 1) {
|
|
let id = rewards[i].id;
|
|
let num = rewards[i].num;
|
|
var tmp = this.allRewardNode.children[i];
|
|
tmp.active = true;
|
|
tmp.children[0].getComponent(cc.Label).string = `x${num}`;
|
|
// Utils.setitem(this, id, tmp.children[1]);
|
|
}
|
|
},
|
|
});
|