import { _decorator, Animation, Button, Color, Component, director, instantiate, Label, Node, Prefab, ProgressBar, RichText, sp, Sprite, SpriteFrame, Toggle, tween, Vec2, Vec3 } from "cc"; import { AreanEvent, AreanNetMgr } from "../AreanNetMgr"; import { iAttribute, MsgAreanBattleReportPush, skillStatus } from "../../../module_basic/shared/protocols/public/arean/MsgAreanBattleReportPush"; import { areanMgr } from "../AreanManager"; import { RoleController } from "./GameItem/RoleController"; import { CardItem } from "./GameItem/CardItem"; import { MsgAreanGameStatusPush } from "../../../module_basic/shared/protocols/public/arean/MsgAreanGameStatusPush"; import { heroAttributeType, IAreanPlayer, IAreanUserTreasure, stage } from "../../../module_basic/shared/protocols/public/arean/AreanTypeDef"; import { ModuleDef } from "../../../scripts/ModuleDef"; import { resLoader } from "../../../core_tgx/base/utils/ResLoader"; import TouchListener from "./GameItem/TouchListener"; import { EquipmentItem } from "./GameItem/EquipmentItem"; import { TreasureItem } from "./GameItem/TreasureItem"; import { tgxAudioMgr, tgxUIAlert } from "../../../core_tgx/tgx"; import { DetailView } from "db://assets/module_arean/scripts/GameScene/GameItem/DetailView"; import { MsgAreanStageReadyPush } from "db://assets/module_basic/shared/protocols/public/arean/MsgAreanStageReadyPush"; import { IAreanUserCard } from "db://assets/module_basic/shared/protocols/public/arean/AreanTypeDef"; import { CommonFun } from "db://assets/module_arean/scripts/CommonFun"; import { settlementView } from "./GameItem/settlementView"; import { EMusicDefine } from "db://assets/module_basic/Define/MusicDefine"; import { MsgAreanDanUpdatePush } from "db://assets/module_basic/shared/protocols/public/arean/MsgAreanDanUpdatePush"; import { MsgAreanGetBattleRewards } from "../../../module_basic/shared/protocols/public/arean/MsgAreanGetBattleRewards"; import { UserMgr } from "db://assets/module_basic/scripts/UserMgr"; import { MsgAreanBattleRewardsPush } from "../../../../../tgx-games-server/src/shared/protocols/public/arean/MsgAreanBattleRewardsPush"; const { ccclass, property } = _decorator; @ccclass('BattleView') export class BattleView extends Component { @property({ type: Prefab }) roleItem: Prefab = null; @property({ type: Prefab }) cardPrefab: Prefab = null; @property({ type: Node }) bgWinNode: Node = null; @property({ type: Node }) detailView: Node = null; @property({ type: Node }) deadGroup: Node = null; @property({ type: Node }) kongGroup: Node = null; @property({ type: Node }) expNode: Node = null; timerNode: Node = null; @property({ type: Node }) equipmentNode: Node = null; @property({ type: Node }) treasureNode: Node = null; @property({ type: Node }) headIconNode: Node = null; @property({ type: Node }) topUI: Node = null; @property({ type: Node }) bottomUI: Node = null; @property({ type: Label }) timerLabel: Label; @property({ type: Label }) stageLabel: Label; @property({ type: Label }) expValue: Label; @property({ type: Label }) expLvl: Label; @property({ type: Label }) curTurnLable: Label; @property({ type: Node }) heroSkillNode: Node; @property({ type: RichText }) heroSkillName: RichText; @property({ type: RichText }) heroSkillDesc: RichText; @property({ type: Sprite }) heroJobIcon: Sprite; @property({ type: Sprite }) heroSkillIcon: Sprite; @property({ type: Button }) btnRefresh: Button; @property({ type: Label }) refreshCost: Label; @property({ type: Button }) btnLock: Button; @property({ type: Button }) btnLvlup: Button; @property({ type: Label }) lvlupCost: Label; @property({ type: Toggle }) btnPrepare: Toggle; @property({ type: Toggle }) btnSolo: Toggle; @property({ type: Node }) chooseCardView: Node = null; @property({ type: Node }) chooseEquipmentView: Node = null; @property({ type: Node }) chooseTreasureView: Node = null; @property({ type: Node }) chooseJobView: Node = null; @property({ type: Node }) jobList: Node = null; @property({ type: Node }) cardList: Node = null; @property({ type: Node }) equipmentList: Node = null; @property({ type: Node }) treasureList: Node = null; @property({ type: Node }) playerListNode: Node = null; @property({ type: Node }) equipmentTip: Node = null; @property({ type: Node }) skillPoolList: Node = null; @property({ type: Node }) equipPoolList: Node = null; @property({ type: Node }) lockNode: Node = null; @property({ type: Node }) playerGold: Node; @property({ type: Label }) playerName: Label; @property({ type: Button }) btnHeadIcon: Button; @property({ type: Node }) headIcon: Node = null; @property({ type: Node }) roleLayer: Node = null; @property({ type: Node }) effectLayer: Node = null; @property({ type: Label }) rare0Probability: Label; @property({ type: Label }) rare1Probability: Label; @property({ type: Label }) rare2Probability: Label; @property({ type: Button }) btnRefreshEquip: Button; @property({ type: Button }) btnRefreshTreasure: Button; @property({ type: Button }) btnExit: Button; @property({ type: Button }) btnSurrender: Button; @property({ type: Node }) stageTimer: Node = null; @property({ type: Node }) attackPlayerNode: Node = null; @property({ type: Node }) chooseCombo: Node = null; @property({ type: Node }) btnCardList: Node = null; @property({ type: Node }) btnETList: Node = null; @property({ type: Node }) weatherNode: Node = null; @property({ type: Node }) weatherEffectNode: Node = null; chooseJobBool: boolean = false; curTurn: number = 1; //当前回合数 curSeat: number = 0; //当前玩家座位号 battleIndex: number = 1; //当前战斗序号 battleReportNum: number = 0; seatRole: { [key: string]: RoleController } = {}; roundTime: number = 0; //当前回合时间点 remainingTime: number = 0; lockBool: boolean = false; curStage: stage = stage.await; dan: MsgAreanDanUpdatePush = null; isPlayingReport: boolean = false; speedUpStage: boolean = false; timeScale: number = 1; localPlayerId: number = null; monsterTurn: number[] = [4, 8, 12, 16, 20]; groupsPos: Vec3[] = [new Vec3(-75, -25, 0), new Vec3(75, 5, 0), new Vec3(75, -65, 0), new Vec3(-75, 25, 0)]; isInit: boolean = false; curExpLvl: number = 1; // 当前播放的背景音乐 _curPlayBgm: string = "bgm_battle"; curChoosePlayer: number; soloMode: boolean = false; hasSettlement: boolean = false; rankNum: number = 8; curGroup: number = 0; timeAdd: boolean; warningNum: number = 0; rewards: MsgAreanBattleRewardsPush = null; start() { areanMgr.BattleView = this; console.log("储存的玩家数据", AreanNetMgr.inst.playerMap); tgxAudioMgr.inst.play(EMusicDefine.MUSIC_BGM_BATTLE, 1, ModuleDef.BASIC); // AreanNetMgr.inst.sendMsg_ChooseHero(Math.floor(Math.random() * (1003 - 1001 + 1)) + 1001); // let random = Math.floor(Math.random() * (1003 - 1001 + 1)) + 1001; director.on(AreanEvent.BattleReportPush, this.initBattleGround, this); director.on(AreanEvent.PlayerStatus, this.initPlayerStatus, this); director.on(AreanEvent.BattleStagePush, this.refreshBattleStage, this); director.on(AreanEvent.SelectCardList, this.SelectCardList, this); director.on(AreanEvent.SelectCardBack, this.refreshCardBack, this); director.on(AreanEvent.SelectEquipList, this.refreshEquipList, this); director.on(AreanEvent.SelectTreasureList, this.refreshTreasureList, this); director.on(AreanEvent.PlayerReady, this._updatePlayerReadyState, this); director.on(AreanEvent.UpdateDan, this._updatePlayerDan, this); director.on(AreanEvent.GetBattleRewards, this.getBattleRewards, this); director.on(AreanEvent.UpdateBattleResult, this._updateRewards, this); this._registerToggleClick(); } protected onDestroy() { tgxAudioMgr.inst.play(EMusicDefine.MUSIC_BGM_HALL, 1, ModuleDef.BASIC); } // 刷新顶部玩家信息 private _updatePlayerInfo(index: number): void { console.log("玩家信息 === ", AreanNetMgr.inst.playerMap, index) if (AreanNetMgr.inst.playerMap) { let curData = AreanNetMgr.inst.playerMap[index]; if (curData) { // 新版本 let heroData = areanMgr.cfgMgr.HeroDatas.getData(curData.heroId); let node = this.topUI.getChildByName("players").getChildByName("playerListBg"); // 金币数 let goldValue = node.getChildByPath("playerGold/value"); goldValue.getComponent(Label).string = `${curData.money}`; // 血量 let hpValue = node.getChildByPath("hpValue"); hpValue.getComponent(Label).string = curData.bloodVolume + "/ 20"; // 玩家昵称 let nickName = node.getChildByName("nickName"); nickName.getComponent(Label).string = `${curData.nickname}`; // 英雄等级 let heroLevel = node.getChildByName("levelBg").getChildByName("level"); heroLevel.getComponent(Label).string = `${curData.lv}`; let skin = heroData.skinRes[0]; let skinId = areanMgr.cfgMgr.SkinData.getData(skin).icon let spineNode = node.getChildByName("heroSpine"); resLoader.load(ModuleDef.Arean, `res/Prefebs/heroSpine/${skinId}`, (err: Error, prefab: Prefab) => { if (err) { console.error(err); return; } else { let _spineNode = instantiate(prefab); spineNode.destroyAllChildren(); spineNode.addChild(_spineNode); } }) // 英雄大招 let bigSKillNode = node.getChildByName("bigSkillBg"); let bigSkill = bigSKillNode.getChildByName("skillIcon"); let skillData = areanMgr.cfgMgr.SkillPerformanceDatas.getData(heroData.mainSkill[0]); let sp: SpriteFrame = resLoader.getSpriteFrame(`res/Image/skill/${skillData.icon}`, ModuleDef.Arean); if (sp) bigSkill.getComponent(Sprite).spriteFrame = sp; let bigSkillName = bigSKillNode.getChildByName("skillName"); let str = skillData ? skillData.skillname : ""; bigSkillName.getComponent(Label).string = str; let bigSkillDes = node.getChildByPath("bigSkillBg/skillDesc"); bigSkillDes.getComponent(Label).string = skillData.effectDescribe; // 职业 let jobIcon = node.getChildByName("jobBg").getChildByName("jobIcon"); let jobData = areanMgr.cfgMgr.JobDatas.getData(curData.careerId); console.log("jobData ==== ", jobData) if (jobData) { let jobIconSp: SpriteFrame = resLoader.getSpriteFrame(`res/Image/skill/${jobData.occupationIcon}`, ModuleDef.Arean); if (jobIconSp) jobIcon.getComponent(Sprite).spriteFrame = jobIconSp; let jobName = node.getChildByName("jobName"); jobName.getComponent(Label).string = jobData.occupationName; let jobDes = node.getChildByName("jobDes"); jobDes.getComponent(Label).string = jobData.occupationDescribe; } // 卡牌情况 let len = curData.cardList; for (let i = 0; i < 3; i++) { let cardData: IAreanUserCard = curData.cardList[i]; let cardNode = node.getChildByName(`cardNode_${i + 1}`); cardNode.active = cardData !== null; if (cardData) { let sp: SpriteFrame = resLoader.getSpriteFrame(`res/heroImg/${666}`, ModuleDef.Arean); if (sp) cardNode.getComponent(Sprite).spriteFrame = sp; let count = cardNode.getChildByName("count"); count.getComponent(Label).string = `${CommonFun.getInstance().CalCardCount(i + 1, curData.cardList)}`; } } // 羁绊 let jiBanNode_1 = node.getChildByName("jiBan_1"); let jiBan = curData.sect; for (const jiBanKey in jiBan) { let jiBanData = jiBan[jiBanKey]; } for (let i = 1; i < 13; i++) { let node = jiBanNode_1.getChildByName(`item_${i}`); let jiBanData = jiBan[i.toString()]; // let sp: SpriteFrame = resLoader.getSpriteFrame(`res/heroImg/${666}`, SpriteFrame, ModuleDef.Arean); // if (sp) node.getComponent(Sprite).spriteFrame = sp; let count = node.getChildByName("count"); count.getComponent(Label).string = `${jiBanData}`; } // 装备 let equipNode = node.getChildByName("equipNode"); let equipData = curData.equipList; for (let i = 0; i < 4; i++) { let node = equipNode.getChildByName(`item_${i + 1}`); let equipId = equipData[i]; if (equipId) { let equipLocalData = areanMgr.cfgMgr.EquipmentData.getData(equipId); let sp: SpriteFrame = resLoader.getSpriteFrame(`res/Image/Equip/${equipLocalData.icon}`, ModuleDef.Arean); if (sp) node.getComponent(Sprite).spriteFrame = sp; let count = node.getChildByName("count"); count.getComponent(Label).string = ""; } } // 圣物 let relicNode = node.getChildByName("relicNode"); let relicData = curData.treasureList; for (let i = 0; i < 2; i++) { let node = relicNode.getChildByName(`item_${i + 1}`); let data = relicData[i]; if (data) { let localData = areanMgr.cfgMgr.TreasureDatas.getData(data.id); let sp: SpriteFrame = resLoader.getSpriteFrame(`res/Image/Treasure/${localData.icon}`, ModuleDef.Arean); if (sp) node.getComponent(Sprite).spriteFrame = sp; let count = node.getChildByName("count"); count.getComponent(Label).string = ""; } } // 老版本 // let node = this.topUI.getChildByName("players"); // // // 玩家昵称 // let playerName = node.getChildByName("name"); // playerName.getComponent(Label).string = curData.nickname; // let heroData = areanMgr.cfgMgr.HeroDatas.getData(curData.heroId); // // 英雄名字 // let heroName = node.getChildByName("name-001"); // heroName.getComponent(Label).string = heroData.name; // // // spine // let spineNode = node.getChildByName("skin"); // let skin = heroData.skinRes[0]; // let skinId = areanMgr.cfgMgr.SkinData.getData(skin).icon // resLoader.load(ModuleDef.Arean,`res/Prefebs/heroSpine/${skinId}`,(err: Error, prefab: Prefab) => { // if(err){ // console.error(err); // return; // }else { // let _spineNode = instantiate(prefab); // spineNode.destroyAllChildren(); // spineNode.addChild(_spineNode); // } // }) // let playerDetail = node.getChildByName("playerDetail"); // let attr = curData.attr; // // 生命 // let hp = playerDetail.getChildByName("Label"); // hp.getComponent(Label).string = `玩家生命:${attr.hp}/${attr.hp}`; // // // 胜利次数 // let victory = playerDetail.getChildByName("Label-001"); // victory.getComponent(Label).string = `胜利次数:${attr.hp}`; // // // 连续胜利次数 // let victory2 = playerDetail.getChildByName("Label-005"); // victory2.getComponent(Label).string = `连续胜利次数:${attr.hp}`; // // // 失败次数 // let fail = playerDetail.getChildByName("Label-002"); // fail.getComponent(Label).string = `失败次数:${attr.hp}`; // // // 连续胜利次数 // let fail2 = playerDetail.getChildByName("Label-006"); // fail2.getComponent(Label).string = `连续失败次数:${attr.hp}`; // // // 当前英雄 // let curHero = playerDetail.getChildByName("Label-003"); // curHero.getComponent(Label).string = `当前英雄:${heroData.name}`; // // // 当前职业 // let job = playerDetail.getChildByName("Label-004"); // job.getComponent(Label).string = `当前职业:???`; // // let content = node.getChildByName("ScrollView").getChildByName("view").getChildByName("content"); } else { console.log("玩家信息为空", index); } } } // 重置准备状态 private _resetPlayerReadyState(): void { for (let i = 0; i < 8; i++) { let node = this.playerListNode.getChildByName(`player${i}`); if (node) { node.getChildByName("ready").active = false; } } } // 刷新顶部玩家准备信息 private _updatePlayerReadyState(data: MsgAreanStageReadyPush): void { // let node = this.playerListNode.getChildByName("player" + index); // console.log("玩家准备信息 === ",data) if (data) { this._resetPlayerReadyState(); let arr = data.readyStatus; if (arr) { let len = arr.length; for (let i = 0; i < len; i++) { let index = arr[i]; let node = this.playerListNode.getChildByName(`player${index}`); if (node && AreanNetMgr.inst.playerMap[index].bloodVolume > 0) { node.getChildByName("ready").active = true; } } } } } // 顶部8个玩家位置点击事件 private _registerToggleClick(): void { for (let i = 0; i < 8; i++) { let node = this.playerListNode.getChildByName("player" + i); node.on("click", () => { this.onClickShowPlayersDetail(i) }) } } getBattleGroupPos() { if (this.monsterTurn.indexOf(this.curTurn) != -1) { this.groupsPos = [new Vec3(-0, -75, 0), new Vec3(0, 5, 0), new Vec3(0, -115, 0), new Vec3(0, 25, 0)]; } else { this.groupsPos = [new Vec3(-75, -75, 0), new Vec3(75, 5, 0), new Vec3(75, -115, 0), new Vec3(-75, 25, 0)]; } return this.groupsPos; } getPrepareGroupPos() { if (this.monsterTurn.indexOf(this.curTurn) != -1) { this.groupsPos = [new Vec3(0, -75, 0), new Vec3(0, 5, 0), new Vec3(0, -115, 0), new Vec3(0, 25, 0)]; } else { this.groupsPos = [new Vec3(-175, -50, 0), new Vec3(175, 30, 0), new Vec3(175, -90, 0), new Vec3(-175, 50, 0)]; } return this.groupsPos; } createRole(seatId: number, id: number) { // console.log("seatId === ", seatId, id) let role = instantiate(this.roleItem); role.name = "player" + seatId; this.kongGroup.addChild(role); this.seatRole[seatId] = role.getComponent(RoleController); this.seatRole[seatId].init(id); let name = "无名氏"; if (this.seatRole[seatId].isMonster) { name = areanMgr.cfgMgr.MonsterDatas.getData(id).name; this.seatRole[seatId].hpManaNode1.setPosition(0, 300); this.seatRole[seatId].bigName.node.setPosition(0, 360); } else { name = AreanNetMgr.inst.playerMap[seatId].nickname; } this.seatRole[seatId].roleName.string = name; this.seatRole[seatId].bigName.string = name; if (seatId == this.getLocalPlayerId()) { this.seatRole[seatId].roleName.color = new Color(0, 255, 0); this.seatRole[seatId].bigName.color = new Color(0, 255, 0); } } update(dt: number): void { if (!this.isInit && Object.keys(AreanNetMgr.inst.playerMap).length > 7) { this.isInit = true; this.initPlayerStatus(); } if (this.curStage == stage.battle) { if (AreanNetMgr.inst.gameData.curBattleReport.battleGround.round == this.curTurn) { this.roundTime += dt; this.playBattleReport(); } if (parseInt(this.timerLabel.string) > 25 && this.speedUpStage) { this.speedUpStage = false; this.timeScale = 1; director.getScheduler().setTimeScale(this.timeScale); } else if (parseInt(this.timerLabel.string) <= 25 && !this.speedUpStage) { this.speedUpStage = true; this.timeScale = 2; director.getScheduler().setTimeScale(this.timeScale); } } else if (this.speedUpStage) { this.speedUpStage = false; this.timeScale = 1; director.getScheduler().setTimeScale(this.timeScale); } } showHeroSkillDetail() { if (this.heroSkillNode.position.y == -70) { tween(this.heroSkillNode) .to(0.2, { position: new Vec3(this.heroSkillNode.position.x, 240, 0) }) .start(); } else if (this.heroSkillNode.position.y == 240) { tween(this.heroSkillNode) .to(0.2, { position: new Vec3(this.heroSkillNode.position.x, -70, 0) }) .start(); } } showWeatherDetail() { if (this.weatherNode.position.x == 440) { tween(this.weatherNode) .to(0.2, { position: new Vec3(100, this.weatherNode.position.y, 0) }) .start(); } else if (this.weatherNode.position.x == 100) { tween(this.weatherNode) .to(0.2, { position: new Vec3(440, this.weatherNode.position.y, 0) }) .start(); } } initBattleGround() { let data = AreanNetMgr.inst.gameData.curBattleReport.battleGround; this.battleReportNum = data.group.length; this.weatherEffectNode.removeAllChildren(); if (data.weather > 0 && data.weather <= 4) { this.weatherNode.active = true; let sp: SpriteFrame = resLoader.getSpriteFrame("res/Image/weather/weather" + data.weather, ModuleDef.Arean); this.weatherNode.getChildByName("icon").getComponent(Sprite).spriteFrame = sp; const path = 'res/Prefebs/weather/weather' + data.weather; let effect: Prefab = resLoader.get(path, Prefab, ModuleDef.Arean); let skillEffect = instantiate(effect); this.weatherEffectNode.addChild(skillEffect); let txt = ""; switch (data.weather) { case 1: txt = "烈日 能量回复提升,法强翻倍"; break; case 2: txt = "暴雨 攻击速度提升,攻击减半"; break; case 3: txt = "沙暴 每秒扣除一定生命值"; break; case 4: txt = "雪天 暴击与闪避的概率减半"; } this.weatherNode.getChildByName("txt").getComponent(Label).string = txt; } else { this.weatherNode.active = false; } for (let i = 0; i < data.group.length; i++) { let group = data.group[i]; let role1 = this.seatRole[group.seat1]; if (!role1 || !role1.node) { let heroId = AreanNetMgr.inst.playerMap[group.seat1].heroId this.createRole(group.seat1, heroId); role1 = this.seatRole[group.seat1]; } role1.node.setParent(this.roleLayer.getChildByName("group" + i)); role1.refreshSkin(0); role1.curGroup = i; let role2 = this.seatRole[group.seat2]; if ((!role2 || !role2.node) && group.seat2 <= 7) { let heroId = AreanNetMgr.inst.playerMap[group.seat2].heroId this.createRole(group.seat2, heroId); } else if (group.seat2 > 7) { let monsterId = areanMgr.cfgMgr.MonsterDatas.findMonsterIdsByWaveNumber(this.curTurn); this.createRole(group.seat2, monsterId); let skinID = areanMgr.cfgMgr.MonsterDatas.getData(monsterId).skinRes; let imagePath = 'res/Spine/' + areanMgr.cfgMgr.SkinData.getData(skinID[0]).icon; let spAsset: sp.SkeletonData = resLoader.get(imagePath, sp.SkeletonData, ModuleDef.Arean); this.seatRole[group.seat2].skin.getComponent(sp.Skeleton).skeletonData = spAsset; let name = areanMgr.cfgMgr.MonsterDatas.getData(monsterId).name; this.seatRole[group.seat2].bigName.string = name; this.seatRole[group.seat2].roleName.node.active = false; this.checkSoloMode(); } role2 = this.seatRole[group.seat2]; role2.node.setParent(this.roleLayer.getChildByName("group" + i)); role2.refreshSkin(1); role2.curGroup = i; if (group.seat1 == this.getLocalPlayerId() || group.seat2 == this.getLocalPlayerId()) this.curGroup = i; } if (data.emptyID != -1) { if (!this.seatRole[data.emptyID] || !this.seatRole[data.emptyID].node) { let heroId = AreanNetMgr.inst.playerMap[data.emptyID].heroId this.createRole(data.emptyID, heroId); } this.seatRole[data.emptyID].node.setParent(this.kongGroup); this.seatRole[data.emptyID].refreshSkin(1); this.seatRole[data.emptyID].curGroup = -1; this.battleIndex = 1; } this.checkSoloMode(); } refreshRolesData() { for (const seatId in this.seatRole) { //this.seatRole[seatId].node.active = false; if (this.seatRole[seatId].isMonster) { this.seatRole[seatId].node.setParent(this.deadGroup); continue; } if (AreanNetMgr.inst.playerMap[seatId].bloodVolume > 0) { //this.seatRole[seatId].node.active = false; this.seatRole[seatId].changeHp(10, 10, 0); this.seatRole[seatId].changeMp(0, 1); //this.seatRole[seatId].playAnimation("sp_idle", "sp_idle"); this.seatRole[seatId].node.setParent(this.kongGroup); this.seatRole[seatId].node.setPosition(0, 0); } else { this.seatRole[seatId].node.setParent(this.deadGroup); let posY = this.seatRole[seatId].node.position.y + (Math.random() * 50 - 25); this.seatRole[seatId].node.setPosition(this.seatRole[seatId].node.position.x, posY); } this.seatRole[seatId].curGroup = -1; this.seatRole[seatId].changeHpBarType(); this.seatRole[seatId].effectsNode.removeAllChildren(); this.seatRole[seatId].textNode.removeAllChildren(); } } refreshBattleStage(data: MsgAreanGameStatusPush) { //console.log("刷新阶段", data); this.remainingTime = data.remainingTime; this.timerLabel.string = data.remainingTime + ""; this.curTurn = data.battleRounds; //this.stageTimer.active = data.remainingTime >=0; //阶段开始 let stageLabel = this.stageLabel.string; // data.stageId === stage.card ? tgxAudioMgr.inst.play(EMusicDefine.SMUSIC_BGM_SELECT_CARD,1,ModuleDef.BASIC) : switch (data.stageId) { case stage.career: if (this.stageLabel.string != "选择职业") { stageLabel = "选择职业"; if (this.getLocalPlayerData().bloodVolume > 0) { this.refreshJobList(this.getLocalPlayerData().heroId); } } break; case stage.card: if (this.stageLabel.string != "选择卡牌") { stageLabel = "选择卡牌"; // if (this.node.getComponent(TouchListener).uiStage != 0) { // if (this.node.getComponent(TouchListener).uiStage == 2) areanMgr.BattleView.onClickClosePlayersDetail(); // areanMgr.BattleView.onClickCloseDetail(); // } if (this.getLocalPlayerData().bloodVolume > 0) { this.refreshCardList(); this.moneyChange(); this.refreshSectList() if (this._curPlayBgm !== 'bgm_select_card') { this._curPlayBgm = 'bgm_select_card'; tgxAudioMgr.inst.play(EMusicDefine.MUSIC_BGM_SELECT_CARD, 1, ModuleDef.BASIC); } } this.btnSolo.isChecked = false; this.btnSolo.node.active = false; this.checkSoloMode(); this.chooseEquipmentView.active = false; this.chooseTreasureView.active = false; this.battleIndex = 1; this.battleReportNum = 0; this.node.getChildByName("bg").setPosition(0, 0, 0); this.roleLayer.setPosition(0, 0, 0); this.node.getChildByName("bg").getComponent(Animation).play("reBg"); this.kongGroup.active = false; this.roleLayer.getChildByName("group0").setPosition(this.getPrepareGroupPos()[0]); this.roleLayer.getChildByName("group1").setPosition(this.getPrepareGroupPos()[1]); this.roleLayer.getChildByName("group2").setPosition(this.getPrepareGroupPos()[2]); this.roleLayer.getChildByName("group3").setPosition(this.getPrepareGroupPos()[3]); } break; case stage.battle: if (this.stageLabel.string != "战斗阶段") { stageLabel = "战斗阶段"; this.initBattleGround(); if (this._curPlayBgm !== 'bgm_battle') { this._curPlayBgm = 'bgm_battle'; tgxAudioMgr.inst.play(EMusicDefine.MUSIC_BGM_BATTLE, 1, ModuleDef.BASIC); } if (this.monsterTurn.indexOf(this.curTurn) != -1) { this.btnSolo.isChecked = true; this.btnSolo.node.active = false; this.kongGroup.active = false; } else { this.btnSolo.node.active = true; this.btnSolo.isChecked = true; if (this.kongGroup.children.length > 1) { this.kongGroup.active = true; this.kongGroup.children[1].active = true; } else { this.kongGroup.active = false; } } this.checkSoloMode(); // if (this.node.getComponent(TouchListener).uiStage != 1) { // if (this.node.getComponent(TouchListener).uiStage == 2) areanMgr.BattleView.onClickClosePlayersDetail(); // areanMgr.BattleView.onClickShowDetail(); // } this._resetPlayerReadyState(); this.roundTime = 0; this.chooseCardView.active = false; this.node.getChildByName("bg").getComponent(Animation).play("changeBg"); } break; case stage.equip: if (this.stageLabel.string != "选择装备") { stageLabel = "选择装备"; if (this.getLocalPlayerData().bloodVolume > 0) { this.refreshEquipList(this.getLocalPlayerData().selectEquipList); } } break; case stage.treasure: if (this.stageLabel.string != "选择圣物") { stageLabel = "选择圣物"; this.btnETList.active = true; if (this.getLocalPlayerData().bloodVolume > 0) { this.refreshTreasureList(this.getLocalPlayerData().selectTreasureList); } } break; case stage.await: break; case stage.afterCard: if (this.stageLabel.string != "即将开战") { stageLabel = "即将开战"; this.btnPrepare.node.active = false; this.btnRefresh.node.active = false; this.btnLock.node.active = false; this.btnLvlup.node.active = false; if (this.getLocalPlayerData().bloodVolume > 0) { if (parseInt(this.playerGold.getChildByName("value").getComponent(Label).string) > 0) { this.chooseCardView.getComponent(Animation).play("moneyToExp"); setTimeout(() => { this.moneyChange(); this.refreshExpLevel(); }, 500); } else { this.chooseCardView.getComponent(Animation).play("hideChooseCard"); } } } break; default: break; } //战斗结束 if (this.curStage == stage.battle && data.stageId != stage.battle) { for (let i = 0; i < 8; i++) { this.refreshPlayerRank(i); } if (!this.hasSettlement && (this.deadCount() >= 7 || this.getLocalPlayerData().bloodVolume <= 0)) { this.showSettlementView(this.getLocalPlayerData().rank); } this.btnSolo.node.active = false; this.kongGroup.active = false; this.weatherNode.active = false; this.refreshRolesData(); //this._updateAttr(); } //选择职业结束 if (this.curStage == stage.career && data.stageId != stage.career && !this.chooseJobBool) { let heroData = areanMgr.cfgMgr.HeroDatas.getData(this.getLocalPlayerData().heroId); let jobPool = heroData.jobPool; this.onClickChooseJob(0, jobPool[0], true); } this.curStage = data.stageId; this.stageLabel.string = stageLabel; this.curTurnLable.string = this.curTurn + ""; } playBattleReport() { let data = AreanNetMgr.inst.gameData.curBattleReport; let index = 0; let hpValue: number[] = []; let lastKey: number | undefined; const keys = Object.keys(data["log"]); if (keys.length > 0) { lastKey = Number(keys[keys.length - 1]); } for (const timePoint in data["log"]) { index += 1; //console.log(this.roundTime[i], lastKey + 3000, this.remainingTime * 1000); if (this.roundTime <= ((lastKey + 3000) / 1000 - this.remainingTime - 1)) { this.roundTime = ((lastKey + 3000) / 1000 - this.remainingTime); } if (this.roundTime * 1000 > parseInt(timePoint) && this.battleIndex == index) { this.battleIndex++; } else { continue; } if (data["log"].hasOwnProperty(timePoint)) { const herosReport = data["log"][timePoint]; for (const heroID in herosReport) { if (herosReport.hasOwnProperty(heroID)) { let hero = this.seatRole[heroID]; if (timePoint == "0") { tween(hero.node.getParent()) .to(0.1, { position: new Vec3(this.getBattleGroupPos()[hero.curGroup].x, this.getBattleGroupPos()[hero.curGroup].y, 0) }) .start(); hero.playAnimation("appear", "sp_idle"); hero.node.active = true; } const event = herosReport[heroID]; const { attribute, skill, buff } = event; if (skill && !this.timeAdd) { for (const sk of skill) { let skillTarget = this.seatRole[sk.target]; if (sk.value.type == 0) { hero.useSkill(sk.id, sk.status == 3, skillTarget); } if (sk.value.type == 3) { switch (sk.status) { case skillStatus.hit: //console.log("玩家" + heroID + "使用普通攻击对玩家" + heroTarget.id + "造成" + sk.value.x + "点伤害"); skillTarget.takeDamage(sk.value.y, false) if (sk.value.y == 0) skillTarget.showBattleText("抵挡"); break; case skillStatus.dodge: //console.log("玩家" + heroTarget.id + "闪避了来自" + "玩家" + heroID + "的攻击"); skillTarget.showBattleText("闪避"); break; case skillStatus.crit: //console.log("玩家" + heroID + "使用普通攻击对玩家" + heroTarget.id + "造成" + sk.value.x + "点暴击伤害"); skillTarget.takeDamage(sk.value.y, true); break; case skillStatus.dodge: //console.log("玩家" + heroTarget.id + "闪避了来自" + "玩家" + heroID + "的攻击"); hero.showBattleText("反伤"); break; } skillTarget.skillTakesEffect(sk.id); } if (sk.value.type == 5) { skillTarget.takeHeal(sk.value.y); } if (sk.suck > 0) { hero.takeHeal(sk.suck); } } } //buff效果 if (buff) { for (const bf of buff) { hero.buffList.push(bf.id); } } // 属性效果 if (attribute) { for (const attr of attribute) { if (parseInt(heroID) == this.getLocalPlayerId()) this.updateAttrForReport(attr); switch (attr.type) { case heroAttributeType.hp: hero.hp = attr.value; hero.changeHp(hero.hp, hero.maxHp, null); break; case heroAttributeType.mp: hero.mp = attr.value; hero.changeMp(hero.mp, hero.maxMp); break; case heroAttributeType.maxHp: hero.maxHp = attr.value; if (timePoint == "0") hero.hp = hero.maxHp; hero.changeHp(hero.hp, hero.maxHp, null); break; case heroAttributeType.maxMp: hero.maxMp = attr.value; if (timePoint == "0") hero.mp = hero.maxMp; hero.changeMp(hero.mp, hero.maxMp); break; case heroAttributeType.shields: hero.shields = attr.value; hero.changeHp(hero.hp, hero.maxHp, hero.shields); break; case heroAttributeType.attack: hero.attack = attr.value; hero.changeAttack(hero.attack); break; } } if (hero.hp <= 0) { hero.death(); if (!hero.isMonster) { this.playerListNode.getChildByName("player" + heroID).getComponent(Animation).play("death"); hero.playAnimation("sp_death", "sp_idle"); this.refreshPlayerRank(parseInt(heroID)); //刷新排名 } } } hpValue.push(hero.hp / hero.maxHp); } } } // let offset = (hpValue[0] - hpValue[1]) * 50 // if (offset) { // tween(this.roleLayer.getChildByName("group" + i)) // .to(0.1, { position: new Vec3(this.getBattleGroupPos()[i].x + offset, this.getBattleGroupPos()[i].y, 0) }) // .start(); // } let curGroupNode = this.roleLayer.getChildByName("group" + this.curGroup); if (this.soloMode) { let pos = new Vec3(curGroupNode.position.x * -4, curGroupNode.position.y * -4) tween(this.node.getChildByName("bg")) .to(0.2, { position: pos }) .start(); } else { tween(this.node.getChildByName("bg")) .to(0.2, { position: new Vec3(0, 0) }) .start(); } break; } for (const seatId in this.seatRole) { if (this.seatRole[seatId].buffList.length > 0) { this.seatRole[seatId].AddBuff(); this.seatRole[seatId].AddDeBuff(); this.seatRole[seatId].buffList = []; this.seatRole[seatId].debuffList = []; } } } updataRefreshButton() { if (this.getLocalPlayerData().freeRefreshTime == 0) { this.btnRefresh.node.getChildByName("CostCoin").active = true; this.btnRefresh.node.getChildByName("Free").active = false; } else { this.btnRefresh.node.getChildByName("CostCoin").active = false; this.btnRefresh.node.getChildByName("Free").active = true; } } refreshCardBack() { let data = this.getLocalPlayerData().selectCardList; for (let i = 0; i < 3; i++) { let cardData = data[i]; let cardItem = this.cardList.children[i]; cardItem.getComponent(CardItem).mask.active = cardData.purchase; } this.moneyChange(); this.refreshSectList(); // setTimeout(() => { // this.moneyChange(); // this.refreshSectList(); // }, 1000); } moneyChange(cost?: number) { let targetMoney = this.getLocalPlayerData().money; let oldValue = parseInt(this.playerGold.getChildByName("value").getComponent(Label).string); if (cost) targetMoney = oldValue - cost; if (oldValue == targetMoney) return; this.playerGold.getChildByName("value").getComponent(Label).string = targetMoney + ""; for (let coinNum = 1; coinNum <= 10; coinNum++) { this.playerGold.getChildByPath("costBg/coin" + coinNum).active = coinNum <= this.getLocalPlayerData().moneyMax; } for (let coinNum = 1; coinNum <= 10; coinNum++) { setTimeout(() => { let node = this.playerGold.getChildByPath("costBg/coin" + coinNum + "/coin"); if (coinNum <= targetMoney && coinNum > oldValue) { node.getComponent(Animation).play("getCoin"); } else if (coinNum > targetMoney && coinNum <= oldValue) { node.getComponent(Animation).play("costCoin"); } }, (coinNum - 1) * 150); } this.playerGold.getChildByName("kong").active = targetMoney == 0; } getBattleRewards(data: MsgAreanGetBattleRewards) { for (let i = 0; i < data.cardList.length; i++) { let id = data.cardList[i].id; let cardData = areanMgr.cfgMgr.CardDatas.getData(id); let color = cardData.cardRare == 1 ? "" : cardData.cardRare == 2 ? "" : "" this.playwarning("角斗士得到了训练——" + color + cardData.mainName + ""); } if (data.exp > 0) { this.playwarning("角斗士经验" + "+" + data.exp + ""); } if (data.freeRefreshTime > 0) { this.playwarning("免费刷新次数" + "+" + data.freeRefreshTime + ""); } if (data.money > 0) { this.playwarning("金币" + "+" + data.money + ""); } if (data.maxMoney > 0) { this.playwarning(",每回合金币上限" + "+" + data.maxMoney + ""); } } SelectCardList() { this.refreshCardList(); } refreshCardList() { this.chooseCardView.getComponent(Animation).play("newCard"); let data = AreanNetMgr.inst.playerMap[this.getLocalPlayerId()].selectCardList; this.refreshExpLevel(); this.chooseCardView.active = true; this.moneyChange(); this.btnLvlup.node.active = true; this.btnRefresh.node.active = true; this.btnLock.node.active = true; this.btnPrepare.node.active = true; this.btnPrepare.isChecked = false; this.updataRefreshButton(); for (let i = 0; i < data.length; i++) { let card = data[i]; let cardItem = this.cardList.children[i]; cardItem.active = true; cardItem.getComponent(CardItem).setData(card); let index = i; cardItem.off("click"); cardItem.on("click", () => { if (this.getLocalPlayerData().money < card.cost) { this.playwarning("金币不足"); } else { AreanNetMgr.inst.sendMsg_SelectCard(index); // let cardData = areanMgr.cfgMgr.CardDatas.getData(data[index].id); // for (let j = 0; j < cardData.Sect.length; j++) { // if (cardData.Sect[j] == 0) break; // this.getLocalPlayerData().sect[cardData.Sect[j]] += cardData.cardRare; // this.getLocalPlayerData().money -= card.cost; // } // this.moneyChange(); // this.refreshSectList(); // this._updateEquipOrTreasureList(); } }) } } private _refreshEquipList(data: number[], isCustom: boolean = false): void { this.btnRefreshEquip.interactable = false; this.btnRefreshEquip.node.getChildByName("zhunbei").getComponent(Label).string = "已刷新"; this.btnRefreshTreasure.node.getChildByName("Sprite").getComponent(Sprite).color = new Color(150, 150, 150, 255); this.refreshEquipList(data, isCustom); } refreshEquipList(data: number[], isCustom: boolean = false) { if (!isCustom) { this.btnRefreshEquip.interactable = true; this.btnRefreshEquip.node.getChildByName("zhunbei").getComponent(Label).string = "刷新"; this.btnRefreshEquip.node.getChildByName("Sprite").getComponent(Sprite).color = new Color(255, 255, 255, 255); } this.stageLabel.string = "选择装备"; this.chooseEquipmentView.active = true; if (this._curPlayBgm !== 'bgm_select_card') { this._curPlayBgm = 'bgm_select_card'; tgxAudioMgr.inst.play(EMusicDefine.MUSIC_BGM_SELECT_CARD, 1, ModuleDef.BASIC); } this.chooseEquipmentView.getComponent(Animation).play("newEquipment"); for (let i = 0; i < this.equipmentList.children.length; i++) { this.equipmentList.children[i].getComponent(Button).interactable = true; this.equipmentList.children[i].getComponent(Sprite).color = new Color(255, 255, 255, 255); } for (let i = 0; i < data.length; i++) { let id = data[i]; let cardItem = this.equipmentList.children[i]; cardItem.active = true; cardItem.getComponent(EquipmentItem).setData(id); let index = i; cardItem.off("click"); cardItem.on("click", () => { AreanNetMgr.inst.sendMsg_SelectEquip(index); for (let i = 0; i < this.equipmentList.children.length; i++) { this.equipmentList.children[i].getComponent(Button).interactable = false; this.equipmentList.children[i].getComponent(Sprite).color = new Color(150, 150, 150, 255); } cardItem.getComponent(Sprite).color = new Color(255, 255, 255, 255); }) } } private _refreshTreasureList(data: IAreanUserTreasure[], isCustom: boolean = false): void { this.btnRefreshTreasure.interactable = false; this.btnRefreshTreasure.node.getChildByName("zhunbei").getComponent(Label).string = "已刷新"; this.btnRefreshTreasure.node.getChildByName("Sprite").getComponent(Sprite).color = new Color(150, 150, 150, 255); this.refreshTreasureList(data, isCustom) } refreshTreasureList(data: IAreanUserTreasure[], isCustom: boolean = false) { if (!isCustom) { this.btnRefreshTreasure.interactable = true; this.btnRefreshTreasure.node.getChildByName("zhunbei").getComponent(Label).string = "刷新"; this.btnRefreshTreasure.node.getChildByName("Sprite").getComponent(Sprite).color = new Color(255, 255, 255, 255); } this.stageLabel.string = "选择圣物"; this.chooseTreasureView.active = true; if (this._curPlayBgm !== 'bgm_select_card') { this._curPlayBgm = 'bgm_select_card'; tgxAudioMgr.inst.play(EMusicDefine.MUSIC_BGM_SELECT_CARD, 1, ModuleDef.BASIC); } this.chooseTreasureView.getComponent(Animation).play("newTreasure"); for (let i = 0; i < this.treasureList.children.length; i++) { this.treasureList.children[i].getComponent(Button).interactable = true; this.treasureList.children[i].getComponent(Sprite).color = new Color(255, 255, 255, 255); } for (let i = 0; i < data.length; i++) { let d = data[i]; let cardItem = this.treasureList.children[i]; cardItem.active = true; cardItem.getComponent(TreasureItem).setData(d.id); let index = i; cardItem.off("click"); cardItem.on("click", () => { AreanNetMgr.inst.sendMsg_SelectTreasure(index); for (let i = 0; i < this.treasureList.children.length; i++) { this.treasureList.children[i].getComponent(Button).interactable = false; this.treasureList.children[i].getComponent(Sprite).color = new Color(150, 150, 150, 255); } cardItem.getComponent(Sprite).color = new Color(255, 255, 255, 255); }) } } refreshJobList(heroId: number) { this.node.getComponent(Animation).play("showJobView"); this.chooseJobView.active = true; let heroData = areanMgr.cfgMgr.HeroDatas.getData(heroId); let jobPool = heroData.jobPool; for (let i = 0; i < 3; i++) { let jobData = areanMgr.cfgMgr.JobDatas.getData(jobPool[i]); let jobItem = this.jobList.children[i]; jobItem.active = true; jobItem.getChildByName("name").getComponent(Label).string = jobData.occupationName; jobItem.getChildByName("cardDesc").getComponent(RichText).string = CommonFun.getInstance().HighlightNumbers(jobData.occupationDescribe); let sp: SpriteFrame = resLoader.getSpriteFrame("res/Image/skill/" + jobData.occupationIcon, ModuleDef.Arean); if (sp) jobItem.getChildByPath("cardBg/mask/cardIcon").getComponent(Sprite).spriteFrame = sp; let index = i; jobItem.on("click", () => { this.onClickChooseJob(index, jobPool[index], true); this.playwarning("你成为了" + jobData.occupationName); }) } } onClickChooseJob(index: number, jobId: number, send: boolean = false) { { for (let i = 0; i < 3; i++) { if (i != index) { this.jobList.children[i].active = false; } } let sp: SpriteFrame = resLoader.getSpriteFrame("res/Image/icon/" + areanMgr.cfgMgr.JobDatas.getData(jobId).occupationIcon, ModuleDef.Arean); if (sp) this.heroJobIcon.spriteFrame = sp; this.node.getComponent(Animation).play("chooseJob"); if (send) { setTimeout(() => { AreanNetMgr.inst.sendMsg_SelectCareer(jobId); //console.log("当前玩家的信息 === ", AreanNetMgr.inst._playerMap) this.getLocalPlayerData().careerId = jobId; this.chooseJobBool = true; this.detailView.getComponent(DetailView).updateJobDetail(jobId); }, 1000); } } } // 获取玩家座位号 getLocalPlayerData(): IAreanPlayer { let data = AreanNetMgr.inst.selfPlayer; //console.log("当前玩家的信息 === ", data) return data; // for (const index of Object.keys(data)) { // let element = data[index]; // if (element.uid === UserMgr.inst.uid) { // this.curChoosePlayer = parseInt(index); // return element; // } // } } getLocalPlayerId() { // let data = AreanNetMgr.inst.playerMap; // for (const index of Object.keys(data)) { // let element = data[index]; // if (element.uid === UserMgr.inst.uid) { // return parseInt(index); // } // } return AreanNetMgr.inst.selfPlayer.playerId; } async initPlayerStatus() { //首次获得玩家数据 let data = AreanNetMgr.inst.playerMap; this.node.getComponent(Animation).play("beginGame"); this.detailView.getComponent(DetailView).init(this.getLocalPlayerData().heroId); for (const seatId of Object.keys(data)) { if (parseInt(seatId) > 7) continue; this.playerListNode.getChildByName("player" + seatId).getComponent(Animation).play("roleIn"); let skin = areanMgr.cfgMgr.SkinData.getData(areanMgr.cfgMgr.HeroDatas.getData(data[seatId].heroId).skinRes[0]).icon; let imagePath = 'res/Spine/' + skin; let spAsset: sp.SkeletonData = resLoader.get(imagePath, sp.SkeletonData, ModuleDef.Arean); let spineAnimation = this.playerListNode.getChildByPath("player" + seatId + "/Node/monsterHeadIcon/skin").getComponent(sp.Skeleton); spineAnimation.skeletonData = spAsset; if (parseInt(seatId) == this.getLocalPlayerId()) { this.playerListNode.getChildByPath("player" + seatId + "/Node/monsterHeadIcon/localBg").active = true; } await new Promise(resolve => setTimeout(resolve, 100)); } setTimeout(() => { for (const key of Object.keys(data)) { if (parseInt(key) > 7) continue; let spineAnimation = this.playerListNode.getChildByPath("player" + key + "/Node/monsterHeadIcon/skin").getComponent(sp.Skeleton); spineAnimation.setAnimation(0, "idle", true); this.refreshPlayerRank(parseInt(key)); } }, 1000); let heroData = areanMgr.cfgMgr.HeroDatas.getData(data[this.getLocalPlayerId()].heroId); let SkillPerformanceData = areanMgr.cfgMgr.SkillPerformanceDatas.getData(heroData.mainSkill[0]); let sf: SpriteFrame = resLoader.getSpriteFrame("res/Image/skill/" + SkillPerformanceData.icon, ModuleDef.Arean); if (sf) this.heroSkillIcon.spriteFrame = sf; this.heroSkillName.string = SkillPerformanceData.skillname; this.heroSkillDesc.string = CommonFun.getInstance().HighlightNumbers(SkillPerformanceData.effectDescribe); let skin = areanMgr.cfgMgr.SkinData.getData(heroData.skinRes[0]).icon; let imagePath = 'res/Spine/' + skin; let spAsset: sp.SkeletonData = resLoader.get(imagePath, sp.SkeletonData, ModuleDef.Arean); this.headIconNode.getChildByName("spine").getComponent(sp.Skeleton).skeletonData = spAsset; this.playerName.string = this.getLocalPlayerData().nickname; this.btnETList.active = this.getLocalPlayerData().treasureList.length > 0; this.lockBool = this.getLocalPlayerData().listLock; this._updateSectAttr(); this.detailView.getComponent(DetailView).updateEquipAndTreasure(this.getLocalPlayerData()); } // 刷新羁绊 public _updateSectAttr(): void { this.detailView.getComponent(DetailView).updateSect(); } // 根据战报刷新属性 private updateAttrForReport(data: iAttribute): void { this.detailView.getComponent(DetailView).updateAttrForReport(data); } refreshExpLevel() { let level = this.getLocalPlayerData().lv; let expValue = this.getLocalPlayerData().exp; let data = areanMgr.cfgMgr.LevelDatas.getData(level); let nextLvData = null; if (level < 5) { nextLvData = areanMgr.cfgMgr.LevelDatas.getData(level + 1); this.expValue.string = expValue + "/" + nextLvData.experience; tween(this.expNode.getComponent(ProgressBar)) .to(0.3, { progress: expValue / nextLvData.experience }) .start(); } this.expLvl.string = level + ""; if (level != this.curExpLvl) { this.curExpLvl = level; this.rare0Probability.string = data.corProbability[0] + "%"; this.rare1Probability.string = data.corProbability[1] + "%"; this.rare2Probability.string = data.corProbability[2] + "%"; this.expNode.getComponent(Animation).play("showLvlup"); //满级特殊处理 if (level == 5) { this.expValue.string = "MAX"; this.btnLvlup.node.active = false; this.expNode.getComponent(ProgressBar).progress = 1; } } } refreshSectList() { let sect = this.getLocalPlayerData().sect; for (const index of Object.keys(sect)) { let label = this.skillPoolList.getChildByPath("sect" + index + "/value").getComponent(Label); let value = sect[index]; // let max = 5; // if (value >= 5) max = 10; // if (value >= 10) max = 20; // label.string = value + "/" + max; let max: number = (value >= 10) ? 20 : (value >= 5) ? 10 : 5; label.string = `${value}/${max}`; } // for (const index of Object.keys(this.getLocalPlayerData().sect)) { // let node = this.skillPoolList.getChildByPath("sect" + index); // let value = this.getLocalPlayerData().sect[index]; // for (let i = 1; i <= 5; i++) { // if (i <= value) { // node.getChildByName("item" + i).getComponent(Sprite).color = new Color(255, 255, 255, 255); // } // else { // node.getChildByName("item" + i).getComponent(Sprite).color = new Color(255, 255, 255, 128); // } // } // } // let value = 0; // let allTypeValue = 0; // let sect = this.getLocalPlayerData().sect; // let node = this.chooseCombo.getChildByPath("choosetypeLIst"); // for (let i = value; i < node.children.length; i++) { // node.children[i].active = false; // } // this.chooseCombo.getChildByPath("attrList/attr0").active = false; // for (const index of Object.keys(sect)) { // this.chooseCombo.getChildByPath("attrList/attr" + index).active = false; // if (sect[index] == 0) continue; // allTypeValue++; // let len = value + sect[index]; // for (let i = value; i < len; i++) { // if (!node.children[i].active) { // node.children[i].getComponent(Animation).play("sectJump"); // node.children[i].active = true; // } // let sp: SpriteFrame = resLoader.getSpriteFrame("res/Image/type/type" + index, ModuleDef.Arean); // node.children[i].getChildByName("icon").getComponent(Sprite).spriteFrame = sp; // } // value = len; // if (sect[index] > 1) { // let data = areanMgr.cfgMgr.SectData.getData(parseInt(index) * 10 + sect[index]); // this.chooseCombo.getChildByPath("attrList/attr" + index + "/desc").getComponent(RichText).string = CommonFun.getInstance().HighlightNumbers(data.desc); // this.chooseCombo.getChildByPath("attrList/attr" + index).active = true; // } // } // if (allTypeValue == 4) { // this.chooseCombo.getChildByPath("attrList/attr0").active = true; // let data = areanMgr.cfgMgr.SectData.getData(1); // this.chooseCombo.getChildByPath("attrList/attr0/desc").getComponent(RichText).string = CommonFun.getInstance().HighlightNumbers(data.desc); // } } onClickShowDetail() { let test = this.getComponent(TouchListener) if (test.uiStage == 1) return; if (this.getComponent(TouchListener).uiStage == 2) this.topUI.getChildByName("players").getComponent(Animation).play("closePlayersDetail"); this.getComponent(TouchListener).uiStage = 1; this.detailView.getChildByPath("ToggleGroup/Toggle1").getComponent(Toggle).isChecked = true; this.bottomUI.getComponent(Animation).play("showDetail"); } onClickSectDetail() { if (this.getComponent(TouchListener).uiStage == 1) return; if (this.getComponent(TouchListener).uiStage == 2) this.topUI.getChildByName("players").getComponent(Animation).play("closePlayersDetail"); this.getComponent(TouchListener).uiStage = 1; this.detailView.getChildByPath("ToggleGroup/Toggle3").getComponent(Toggle).isChecked = true; this.bottomUI.getComponent(Animation).play("showDetail"); } onClickCloseDetail() { if (this.getComponent(TouchListener).uiStage == 0) return; this.getComponent(TouchListener).uiStage = 0; this.bottomUI.getComponent(Animation).play("closeDetail"); } onClickRefreshCardList() { if (this.getLocalPlayerData().freeRefreshTime < 1 && this.getLocalPlayerData().money < 1) { this.playwarning("金币不足"); } else { AreanNetMgr.inst.sendMsg_BuySelectCardListRefresh(); } } onClickLockCardList() { AreanNetMgr.inst.sendMsg_SelectCardListLock(!this.lockBool); } onClickBuyExp() { console.log("onClickBuyExp", this.getLocalPlayerData().money); if (this.getLocalPlayerData().money < 1) { this.playwarning("金币不足"); } else { AreanNetMgr.inst.sendMsg_BuyExp(); } } onClickReady() { if (this.btnPrepare.isChecked) AreanNetMgr.inst.sendMsg_Ready(); // AreanNetMgr.inst.sendMsg_Ready(); } // 点击刷新装备 onClickRefreshEquip(): void { AreanNetMgr.inst.sendMsg_refresh_equip().then((data) => { console.log("刷新装备返回 == ", data); if (data.isSucc) { if (data.res.status) { this._refreshEquipList(data.res.selectEquipList, true); } } }) } // 点击刷新圣物 onClickRefreshTreasure(): void { AreanNetMgr.inst.sendMsg_refresh_treasure().then((data) => { console.log("刷新圣物返回 == ", data); if (data.isSucc) { if (data.res.status) { this._refreshTreasureList(data.res.selectTreasureList, true); } } }) } onClickShowPlayersDetail(index: number = this.curChoosePlayer) { this._updatePlayerInfo(index); this.curChoosePlayer = index; let stage = this.getComponent(TouchListener).uiStage; if (stage == 2) return; if (stage == 1) this.bottomUI.getComponent(Animation).play("closeDetail"); this.getComponent(TouchListener).uiStage = 2; this.topUI.getChildByPath("players").getComponent(Animation).play("showPlayersDetail"); } onClickClosePlayersDetail() { if (this.getComponent(TouchListener).uiStage == 0) return; this.getComponent(TouchListener).uiStage = 0; this.topUI.getChildByPath("players").getComponent(Animation).play("closePlayersDetail"); } refreshPlayerRank(seatID: number) { if (AreanNetMgr.inst.playerMap[seatID].bloodVolume <= 0) { this.playerListNode.getChildByPath("player" + seatID + "/Node/monsterHeadIcon/deathMask").active = true; let spineAnimation = this.playerListNode.getChildByPath("player" + seatID + "/Node/monsterHeadIcon/skin").getComponent(sp.Skeleton); spineAnimation.timeScale == 0; } else { this.playerListNode.getChildByPath("player" + seatID + "/Node/monsterHeadIcon/deathMask").active = false; } let bar = this.playerListNode.getChildByPath("player" + seatID + "/hp").getComponent(ProgressBar); bar.progress = AreanNetMgr.inst.playerMap[seatID].bloodVolume / 20; if (seatID == this.getLocalPlayerId()) { this.btnHeadIcon.node.getChildByName("hpValue").getComponent(Label).string = this.getLocalPlayerData().bloodVolume + "/ 20"; } // 获取所有玩家的血量 let playersBloodVolume = []; for (let playerId in AreanNetMgr.inst.playerMap) { let player = AreanNetMgr.inst.playerMap[playerId]; if (player.bloodVolume > 0) { playersBloodVolume.push({ playerId: Number(playerId), bloodVolume: player.bloodVolume }); } } // 按血量从大到小排序 playersBloodVolume.sort((a, b) => b.bloodVolume - a.bloodVolume); // 重新排列节点层级 for (let i = 0; i < playersBloodVolume.length; i++) { let playerId = playersBloodVolume[i].playerId; this.playerListNode.getChildByPath("player" + playerId).setSiblingIndex(i); } // 检查位置是否发生变化 for (let i = 0; i < playersBloodVolume.length; i++) { let playerId = playersBloodVolume[i].playerId; if (i != playerId) { this.playerListNode.getChildByName("player" + playerId).getComponent(Animation).play("roleIn"); } } } onClickBtnQuit() { tgxUIAlert.show(`是否确认退出 ? `, true).onClick(async b => { if (b) { AreanNetMgr.inst.sendMsg_exit(); } }); } onClickBtnSurrender() { tgxUIAlert.show(`这就投了 ? `, true).onClick(async b => { if (b) { AreanNetMgr.inst.sendMsg_surrender(); } }); } showSettlementView(rank: number) { this.hasSettlement = true; this.btnSurrender.node.active = false; this.btnExit.node.active = true; const path = 'res/Prefebs/settlementView'; let sp: Prefab = resLoader.get(path, Prefab, ModuleDef.Arean); let node = instantiate(sp); this.node.addChild(node); node.getComponent(settlementView).setData(rank); } switchSoloRole(isAdd: boolean) { if (this.monsterTurn.indexOf(this.curTurn) != -1) return; let nextGroup = this.curGroup; for (let i = 0; i < this.battleReportNum; i++) { if (isAdd) { nextGroup = nextGroup == this.battleReportNum - 1 ? 0 : nextGroup + 1; } else { nextGroup = nextGroup == 0 ? this.battleReportNum - 1 : nextGroup - 1; } let group = this.roleLayer.getChildByName("group" + nextGroup); if (group) { if (group.children.length > 0) { this.curGroup = nextGroup; break; }; } } this.checkSoloMode(); } checkSoloMode() { this.soloMode = this.btnSolo.isChecked; this.btnSolo.node.getChildByName("zoomin").active = !this.btnSolo.isChecked; this.btnSolo.node.getChildByName("zoomout").active = this.btnSolo.isChecked; // for (const seat of Object.keys(this.seatRole)) { // const role = this.seatRole[seat]; // if (role.curGroup == this.seatRole[this.soloSeat].curGroup) role.changeHpBarType(); // } if (this.soloMode) { tween(this.node.getChildByName("bg")) .to(0.2, { scale: new Vec3(1.5, 1.5) }) .start(); let curGroupNode = this.roleLayer.getChildByName("group" + this.curGroup); let pos = new Vec3(curGroupNode.position.x * - 4, curGroupNode.position.y * -4) tween(this.node.getChildByName("bg")) .to(0.2, { position: pos }) .start(); } else { tween(this.node.getChildByName("bg")) .to(0.2, { scale: new Vec3(1, 1) }) .start(); tween(this.node.getChildByName("bg")) .to(0.2, { position: new Vec3(0, 0) }) .start(); } for (const seat of Object.keys(this.seatRole)) { const role = this.seatRole[seat]; role.changeHpBarType(); } } playwarning(text: string) { this.warningNum++; setTimeout(() => { const path = 'res/Prefebs/warningTips'; let sp: Prefab = resLoader.get(path, Prefab, ModuleDef.Arean); let node = instantiate(sp); this.node.addChild(node); node.getChildByPath("node/text").getComponent(RichText).string = text; setTimeout(() => { node.removeFromParent(); this.warningNum--; }, 2000); }, this.warningNum * 200); } deadCount() { let dieNum = 0; for (const key in AreanNetMgr.inst.playerMap) { let data = AreanNetMgr.inst.playerMap[key]; if (data.bloodVolume <= 0) dieNum++; } return dieNum; } _updatePlayerDan(data: MsgAreanDanUpdatePush) { this.dan = data; // console.log("收到的段位信息 === ",this.dan); let node = this.node.getChildByName("settlementView"); if (node && this.dan.danInfo.uid == UserMgr.inst.uid) { node.getComponent(settlementView).updateDan(this.dan.danInfo); } } _updateRewards(data: MsgAreanBattleRewardsPush) { this.rewards = data; let node = this.node.getChildByName("settlementView"); if (node && this.rewards.uid == UserMgr.inst.uid) { node.getComponent(settlementView).updateRewards(this.rewards.items); } } }