// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html import CashOutData from "../datas/CashOutData"; import { HTTP_TYPE } from "../datas/CommonData"; import { FightData, FightRole } from "../datas/FightData"; import { GameController } from "../manager/GameController"; import GameM, { AUDIO_TYPE } from "../manager/GameM"; import HttpM from "../manager/HttpM"; import BasePanel from "../uiFrames/BasePanel"; import UIMng, { PanelType } from "../uiFrames/UIMng"; import Random from "../utils/Random"; import { Utils } from "../utils/Utils"; import RewardNode from "./RewardNode"; const { ccclass, property } = cc._decorator; @ccclass export default class FightRolePanel extends BasePanel { //武将选择界面 @property(cc.Node) panelNode: cc.Node = null; @property(cc.Label) txtName: cc.Label = null; @property(cc.Label) txtLv: cc.Label = null; @property(cc.Node) stars: cc.Node[] = []; @property(cc.Sprite) roleImg: cc.Sprite = null; @property(cc.Label) txtRedbag: cc.Label = null; @property(cc.Node) rewardBoxs: cc.Node[] = []; @property(cc.Sprite) rewardBoxImgs: cc.Sprite[] = []; @property(cc.Node) //rewardRedbag: cc.Node = null; @property(cc.Label) //txtRewardRedbag: cc.Label = null; //@property(cc.Node) //rewardTianfu: cc.Node = null; @property(cc.Node) btnLeft: cc.Node = null; @property(cc.Node) btnRight: cc.Node = null; @property(cc.Widget) widget: cc.Widget = null; private roleNum = 0; private curRoleIndex = 0; private curRole: any = null; private curRoleSer: any = null; private curRoleLv: number = 1; //private curRoleStar: number = 1; private curRoleBlood: number = 10; private curRoleTime: number = 10; private curRoleBuffId: number = 1; private isInit: boolean = false; OnEnter() { this.Init(); this.panelNode.scale = 0; this.node.active = true; cc.tween(this.panelNode).to(0.2, { scale: 1 }, { easing: "backOut" }) .call(() => { this.widget.updateAlignment(); }) .start(); //this.node.setSiblingIndex(this.node.parent.childrenCount - 1); } OnExit() { this.node.active = false; } Init() { if (!this.isInit) { this.isInit = true; this.roleImg.node.scale = 1.3; //获取武将星级配置信息 //FightData.Ins.GetFightRoleStars(() => { this.roleNum = FightData.Ins.composeFightRoles.length; this.curRoleIndex = this.roleNum - 1; this.UpdateRoleInfo(); //}); } else { //获取武将星级配置信息 //FightData.Ins.GetFightRoleStars(() => { this.roleNum = FightData.Ins.composeFightRoles.length; this.curRoleIndex = this.roleNum - 1; this.UpdateRoleInfo(); //}); } } UpdateRoleInfo() { //console.log("FightRoleCount: " + FightData.Ins.composeFightRoles.length); this.curRoleLv = FightData.Ins.composeFightRoles[this.curRoleIndex].code; this.curRole = GameM.commonData.fightRoleCfg[this.curRoleLv.toString()]; //使用服务端角色配置基础属性 this.curRoleSer = GameM.commonData.fightRoleServerCfg[this.curRoleLv.toString()]; cc.loader.loadRes('carPic/side/side_' + this.curRoleLv, cc.SpriteFrame, (err, asset) => { this.roleImg.spriteFrame = asset; }); let cfg = CashOutData.Instance.cashCft; let len = cfg.length; for (var i = 0; i < len; i++) { if (cfg[i].type_value == this.curRoleLv) { this.txtRedbag.string = cfg[i].moneyshow.split('~')[1]; break; } } this.txtName.string = this.curRole.name; this.txtLv.string = "Lv" + this.curRoleLv; this.DiaplayLevelInfo(); //this.btnLeft.active = this.curRoleIndex > 0; //this.btnRight.active = this.curRoleIndex < (this.roleNum - 1); } /**显示武将星级相关信息*/ DiaplayLevelInfo() { let rewardnames = this.curRole.reward_show; //星级 for (let i = 0; i < this.stars.length; i++) { this.stars[i].active = false; //不显示星级 //if (i + 1 <= this.curRoleStar) { // this.stars[i].active = true; //} } for (let i = 0; i < this.rewardBoxs.length; i++) { this.rewardBoxs[i].active = false; if (i < rewardnames.length) { this.rewardBoxs[i].active = true; cc.loader.loadRes('xiyou/icon/' + rewardnames[i], cc.SpriteFrame, (err, asset) => { this.rewardBoxImgs[i].spriteFrame = asset; }); } } } Click_LeftBtn() { this.curRoleIndex--; if (this.curRoleIndex < 0) this.curRoleIndex = this.roleNum - 1; this.UpdateRoleInfo(); GameM.audioM.playEffect(AUDIO_TYPE.button); } Click_RightBtn() { this.curRoleIndex++; if (this.curRoleIndex >= this.roleNum) this.curRoleIndex = 0; this.UpdateRoleInfo(); GameM.audioM.playEffect(AUDIO_TYPE.button); } async Click_ChallengeBtn() { //使用服务端角色基础属性 this.curRoleBlood = this.curRoleSer.bloods; this.curRoleTime = this.curRoleSer.times; //let buffrandom = Random.Range(0, this.curRole.buffbag_rate, false); //弃用 战斗时获取 //let buffrandom = Random.Range(0, 100, false); //let buffbag = GameM.commonData.buffbagCfg[this.curRole.buffbag_id.toString()]; //let temprate = 0; //for (let i = 0; i < buffbag.buff_rate.length; i++) { // temprate += buffbag.buff_rate[i]; // if (buffrandom <= temprate) { // this.curRoleBuffId = buffbag.id[i]; // break; // } //} //console.log("buff bag id:" + this.curRole.buffbag_id + " buff id:" + this.curRoleBuffId); let cfg = GameM.commonData.fightRoleCfg[this.curRoleLv.toString()]; FightData.Ins.flawTimes = cfg.flawclicktimes; FightData.Ins.flawDuration = cfg.flawduration; FightData.Ins.flawRate = cfg.flawrate; FightData.Ins.flawNum=cfg.flawnum; let fightrole = new FightRole(); fightrole.arrayIndex = this.curRoleIndex; fightrole.blood = this.curRoleBlood; fightrole.buffId = 1; //无效 战斗时生效 fightrole.fightTime = this.curRoleTime; fightrole.fightType = 1; fightrole.lv = this.curRoleLv; fightrole.name = this.curRoleSer.name; //弃用 使用接口回调获取结算奖励 fightrole.star = 1; //无效 //弃用 使用接口回调获取结算奖励 fightrole.rewardId = 1; GameM.audioM.playEffect(AUDIO_TYPE.button); await Utils.loadResPromise('prefabs/TransitNode') GameController.Ins.PlayTransitAniForHttp(); HttpM.Instance.SendData(HTTP_TYPE.beginBattle, { battleType: 1, bossCode: this.curRoleLv.toString(), version: GameM.commonData.version }, (res) => { console.log("-->BeginBattle:", res) if (res.data != null) { GameController.Ins.PlayCloseTransitAniForHttp(() => { fightrole.fightId = res.data; this.OnExit(); UIMng.Ins.AsyncGetPanel(PanelType.FightPanel, (panel) => { panel.OnEnter(fightrole); }); //UIMng.Ins.GetPanel(PanelType.FightPanel).OnEnter(fightrole); }); } }); } Click_CloseBtn() { this.OnExit(); GameM.audioM.playEffect(AUDIO_TYPE.button); } }