413 lines
9.8 KiB
JavaScript
413 lines
9.8 KiB
JavaScript
var battlenet = require('battlenetmanage');
|
|
var SDKManage = require('SDKManage');
|
|
var gameConfig = require('gameConfig');
|
|
var Utils = require('Utils');
|
|
const NetManage = require('../../manages/NetManage');
|
|
const { showLoading } = require('../../gif/Loading');
|
|
const { OperationType } = require('../../Operation/Operation');
|
|
const jcgamelog = require('../../jcfw/service/jcgamelog');
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
nd_chat: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
nd_back: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
lb_time: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
nd_time5: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
nd_btns: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
btn_ready: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
btn_noready: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
btn_go: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
pb_herolihui: {
|
|
default: null,
|
|
type: cc.Prefab,
|
|
},
|
|
nd_teamlihui: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
nd_onehui: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
tableView_chose: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
pb_chooseWeapon: {
|
|
default: null,
|
|
type: cc.Prefab,
|
|
},
|
|
|
|
nd_weaponNode1: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
nd_weaponNode2: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
onLoad() {
|
|
this.weaponStr = '[]';
|
|
this.weapon_uniid = new Array();
|
|
|
|
cc.Notifier.on(
|
|
'battleclickchose',
|
|
this,
|
|
this.battleclickchose.bind(this)
|
|
);
|
|
cc.Notifier.on(
|
|
'SMUpdateMatchInfo',
|
|
this,
|
|
this.SMUpdateMatchInfo.bind(this)
|
|
);
|
|
cc.Notifier.on('infochangeskin', this, this.infochangeskin.bind(this));
|
|
// choose weapon
|
|
cc.Notifier.on('haschooseWeapon', this, (index, name) => {
|
|
if (index) {
|
|
console.log(`index-------${window.currentWeaponName}`);
|
|
if (index == 0) {
|
|
cc.loader.loadRes(
|
|
`icons/${window.currentWeaponName}`,
|
|
cc.SpriteFrame,
|
|
(err, res) => {
|
|
if (this.nd_weaponNode1)
|
|
this.nd_weaponNode1.getComponent(
|
|
cc.Sprite
|
|
).spriteFrame = res;
|
|
}
|
|
);
|
|
} else if (index == 1) {
|
|
cc.loader.loadRes(
|
|
`icons/${window.currentWeaponName}`,
|
|
cc.SpriteFrame,
|
|
(err, res) => {
|
|
if (this.nd_weaponNode2)
|
|
this.nd_weaponNode2.getComponent(
|
|
cc.Sprite
|
|
).spriteFrame = res;
|
|
}
|
|
);
|
|
}
|
|
//
|
|
|
|
if (window.firstgun && this.weapon_uniid) {
|
|
this.weapon_uniid[0] = window.firstgun;
|
|
}
|
|
if (window.secondgun && this.weapon_uniid) {
|
|
this.weapon_uniid[1] = window.secondgun;
|
|
}
|
|
|
|
this.weaponStr = JSON.stringify(this.weapon_uniid);
|
|
|
|
console.log(this.weaponStr);
|
|
}
|
|
});
|
|
},
|
|
onDestroy() {
|
|
cc.Notifier.off('battleclickchose', this);
|
|
cc.Notifier.off('SMUpdateMatchInfo', this);
|
|
cc.Notifier.off('infochangeskin', this);
|
|
},
|
|
SMUpdateMatchInfo(_data) {
|
|
var data = _data.info;
|
|
this.herodatalist = data.members;
|
|
for (var i = 0; i < data.members.length; i++) {
|
|
var onedata = data.members[i];
|
|
if (onedata.hero_skin > 0) {
|
|
onedata.hero_id =
|
|
gameConfig.all_ItemConfig[onedata.hero_skin].playerid;
|
|
onedata.hero_skin = onedata.hero_skin;
|
|
}
|
|
}
|
|
if (data.countdown <= 5) {
|
|
this.lb_time.node.active = false;
|
|
this.nd_btns.active = false;
|
|
this.nd_time5.active = true;
|
|
} else {
|
|
this.lb_time.node.active = true;
|
|
this.lb_time.string = Utils.second3Time(data.countdown);
|
|
}
|
|
this.refresh();
|
|
},
|
|
|
|
battleclickchose(v) {
|
|
this.tmpv = v;
|
|
if (this.mystate != 0) {
|
|
return;
|
|
}
|
|
|
|
var heroDetail = this.getHeroDetailByID(v.hero_id);
|
|
var process =
|
|
(heroDetail.ceg_uplimit - heroDetail.today_get_gold) /
|
|
heroDetail.ceg_uplimit;
|
|
|
|
this.node.getComponentInChildren('pbbattleui').nd_processbar.progress =
|
|
process;
|
|
this.node.getComponentInChildren('pbbattleui').nd_remainceg.string =
|
|
heroDetail.ceg_uplimit - heroDetail.today_get_gold;
|
|
|
|
for (var i = 0; i < this.herodatalist.length; i++) {
|
|
if (this.herodatalist[i].account_id == v.account_id) {
|
|
this.herodatalist[i].hero_id = v.hero_id;
|
|
this.herodatalist[i].hero_skin = v.hero_skin;
|
|
this.herodatalist[i].hero_uuid = this.getHeroUUidByid(
|
|
v.hero_id
|
|
);
|
|
if (SDKManage.account_id == v.account_id) {
|
|
cc.playerData.changeHero(v.hero_id);
|
|
this.hero_id = v.hero_id;
|
|
this.hero_uuid = this.getHeroUUidByid(v.hero_id);
|
|
this.canzb = true;
|
|
if (this.team_mode) {
|
|
let data = {
|
|
hero_id: v.hero_id,
|
|
weapons: JSON.parse(this.weaponStr),
|
|
skins: [],
|
|
baseskin:
|
|
gameConfig.all_ItemConfig[v.hero_skin].skinid,
|
|
hero_skin: v.hero_skin,
|
|
skill_list: cc.playerData.getbattleskilllist(),
|
|
hero_uniid: this.herodatalist[i].hero_uuid,
|
|
};
|
|
|
|
this.matchdata = data;
|
|
|
|
cc.battleIns.sendbattlemsg('CMMatchChoose', data);
|
|
}
|
|
}
|
|
|
|
this.refresh();
|
|
break;
|
|
}
|
|
}
|
|
},
|
|
initdata(opt) {
|
|
this.lb_time.node.active = false;
|
|
this.mystate = 0;
|
|
this.nd_time5.active = false;
|
|
this.btn_ready.active = false;
|
|
this.btn_noready.active = false;
|
|
this.btn_go.active = false;
|
|
this.nd_back.active = false;
|
|
this.herodatalist = [];
|
|
this.herolist = [];
|
|
|
|
cc.playerData.changeHero(30100);
|
|
var addnode = this.nd_teamlihui;
|
|
var pcount = 1;
|
|
|
|
if (opt.teamuuid) {
|
|
this.team_mode = true;
|
|
pcount = 4;
|
|
} else {
|
|
this.btn_go.active = true;
|
|
this.nd_back.active = true;
|
|
addnode = this.nd_onehui;
|
|
this.herodatalist.push({
|
|
state: 0,
|
|
name: cc.playerData.name,
|
|
hero_id: 0,
|
|
hero_skin: 0,
|
|
account_id: SDKManage.account_id,
|
|
hero_uuid: 0,
|
|
});
|
|
}
|
|
for (var i = 0; i < pcount; i++) {
|
|
var nd = cc.instantiate(this.pb_herolihui);
|
|
addnode.addChild(nd);
|
|
var scp = nd.getComponent('pbbattleui');
|
|
scp.target = this;
|
|
this.herolist.push(scp);
|
|
}
|
|
|
|
this.refresh();
|
|
this.changelist(0);
|
|
},
|
|
|
|
changetype(data1, data2) {
|
|
this.changelist(Number(data2));
|
|
cc.Notifier.emit('btnchose', { k: data2 });
|
|
},
|
|
|
|
changelist(type) {
|
|
var cherolist = [];
|
|
var openherolist = cc.playerData.getopenhero();
|
|
|
|
var herolist = [];
|
|
this.allHeroUUID = [];
|
|
this.allHeroID = [];
|
|
this.heroDetails = [];
|
|
|
|
NetManage.getHeroList((data) => {
|
|
herolist = data.hero_list;
|
|
for (var i = 0; i < herolist.length; i++) {
|
|
var element = herolist[i];
|
|
if (element.lock_type != 3) {
|
|
this.allHeroUUID.push(element.hero_uniid);
|
|
this.allHeroID.push(parseInt(element.hero_id));
|
|
this.heroDetails.push(herolist[i]);
|
|
}
|
|
}
|
|
|
|
for (var i = 0; i < this.allHeroID.length; i++) {
|
|
var hid = this.allHeroID[i];
|
|
var heroType = gameConfig.playerConfig[hid].herotype;
|
|
if (type == 0 || type == heroType) {
|
|
if (cc.playerData.checkhasgethero(hid)) {
|
|
cherolist.push(hid);
|
|
}
|
|
}
|
|
}
|
|
|
|
var newlist = Utils.arrtoarr(cherolist, 2);
|
|
// this.allHeroID = cherolist;
|
|
this.tableView_chose
|
|
.getComponent('tableView')
|
|
.initTableView(newlist.length, {
|
|
array: newlist,
|
|
target: this,
|
|
});
|
|
});
|
|
|
|
// for (var i = 0; i < openherolist.length; i++) {
|
|
// var hid = openherolist[i];
|
|
// var heroType = gameConfig.playerConfig[hid].herotype;
|
|
// if (type == 0 || type == heroType) {
|
|
// if (cc.playerData.checkhasgethero(hid)) {
|
|
// cherolist.push(hid);
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// var newlist = Utils.arrtoarr(cherolist, 2);
|
|
// this.allHeroID = cherolist;
|
|
// this.tableView_chose
|
|
// .getComponent("tableView")
|
|
// .initTableView(newlist.length, {
|
|
// array: newlist,
|
|
// target: this,
|
|
// });
|
|
},
|
|
|
|
getHeroUUidByid(id) {
|
|
var index = this.allHeroID.indexOf(id);
|
|
return this.allHeroUUID[index];
|
|
},
|
|
|
|
getHeroDetailByID(id) {
|
|
var index = this.allHeroID.indexOf(id);
|
|
return this.heroDetails[index];
|
|
},
|
|
|
|
onclickclose() {
|
|
window.firstgun = null;
|
|
window.secondgun = null;
|
|
this.node.destroy();
|
|
},
|
|
onclickgo() {
|
|
//single
|
|
jcgamelog.addOperation(OperationType.BUTTON, 'startgame');
|
|
if (!this.canzb) {
|
|
cc.uiHelper.showTips('Please choose a hero first');
|
|
return;
|
|
}
|
|
// showLoading();
|
|
// setTimeout(() => {
|
|
// this.btn_noready.parent.parent.zindex = 99;
|
|
// }, 1500);
|
|
var opt = cc.playerData.getbattleopt();
|
|
opt.team_mode = 0;
|
|
opt.player_count = 1;
|
|
opt.hero_uniid = this.hero_uuid;
|
|
|
|
if (window.firstgun) {
|
|
opt.weapon_uniid = new Array();
|
|
opt.weapon_uniid.push(window.firstgun);
|
|
if (window.secondgun) {
|
|
opt.weapon_uniid.push(window.secondgun);
|
|
}
|
|
}
|
|
|
|
battlenet.initengine(opt);
|
|
},
|
|
refresh() {
|
|
for (var i = 0; i < this.herodatalist.length; i++) {
|
|
this.herolist[i].initdata(this.herodatalist[i]);
|
|
}
|
|
},
|
|
onclicktype() {},
|
|
onclickcancelready() {
|
|
cc.battleIns.sendbattlemsg('CMMatchCancelStartGame');
|
|
},
|
|
onclickready() {
|
|
jcgamelog.addOperation(OperationType.BUTTON, 'startgame');
|
|
// team
|
|
if (!this.canzb) {
|
|
cc.uiHelper.showTips('Please choose a hero first');
|
|
return;
|
|
}
|
|
//
|
|
if (this.matchdata) {
|
|
this.matchdata.weapons = JSON.parse(this.weaponStr);
|
|
cc.battleIns.sendbattlemsg('CMMatchChoose', this.matchdata);
|
|
}
|
|
//
|
|
cc.battleIns.sendbattlemsg('CMMatchStartGame');
|
|
},
|
|
doready(state) {
|
|
if (this.team_mode) {
|
|
this.mystate = state;
|
|
this.btn_ready.active = state == 0;
|
|
this.btn_noready.active = !this.btn_ready.active;
|
|
}
|
|
},
|
|
infochangeskin(v) {
|
|
cc.Notifier.emit('battleclickchose', {
|
|
account_id: SDKManage.account_id,
|
|
hero_id: this.hero_id,
|
|
hero_skin: v,
|
|
});
|
|
cc.playerData.changeSkin(v);
|
|
},
|
|
|
|
// update (dt) {},
|
|
|
|
onClickChooseWeapon(event, data) {
|
|
var node = cc.instantiate(this.pb_chooseWeapon);
|
|
node.scale = 0.8;
|
|
this.node.addChild(node);
|
|
node.getComponent('chooseGun').startFrom(data);
|
|
},
|
|
});
|