const NxExpand = require("nx.fx.sv.expand"); const BridgeWindow = require( "bridge.window" ); const AdventureEVT = require("adventure_event"); const ADVCT = require("adventure_controller"); const PlaneRole = require("cmp.adventure.role"); cc.Class({ extends: BridgeWindow, properties: { mapNd:{//主地图根节点 default:null, type:cc.Node }, list:{ default:null, type:cc.Node }, dirTag:{ default:null, type:cc.Node }, dirRole:{ default:null, type:PlaneRole }, mapScroll:{ default:null, type:cc.ScrollView }, mapItem:{ default:null, type:cc.Prefab }, touchLayer:{ default:null, type:cc.Node }, moveLayer:{//角色移动层 default:null, type:cc.Node }, foots:{ default:null, type:cc.Node }, explores:{//探索度 default:null, type:cc.Node }, powers:{//體力值 default:null, type:cc.Node }, floors:{ default:null, type:cc.Node }, infoNd:{ default:null, type:cc.Node }, }, // LIFE-CYCLE CALLBACKS: onLoad () { this.ctrl = ADVCT.getInstance(); this.mapPool = new cc.NodePool(); this.paths = [];//实际路径 this.nightPaths = [];//迷雾路径,只保留序号 this.curMovePaths = []; this.maps = {}; this.is_trap = 0;//立即触发陷阱,0 没有 1 触发 this.is_moving = false;//移動時不能觸發任務 this.is_use_inMove = false;//是否在行動中使用了道具 this.need_refresh_all = true;//是否需要重建所有room //处理预设路径 this.touchLayer.on(cc.Node.EventType.TOUCH_MOVE,this.orderPath.bind(this)); //单点地图块 this.touchLayer.on(cc.Node.EventType.TOUCH_START,this.pointMap.bind(this)); // this.touchLayer.on(cc.Node.EventType.TOUCH_END,this.pointMap.bind(this)); this.mapScroll.node.on("scrolling",this.synchLayerPos.bind(this)); this.bindGEvent( AdventureEVT.Update_Player_Info, this.updatePlayerInfo.bind(this)) //消息绑定 this.bindGEvent( AdventureEVT.Update_Role_Info, this.InitRoleInfo.bind( this ) ); //初始化 this.bindGEvent( AdventureEVT.Update_Room_Base_Info, this.InitBase.bind( this ) ); //正确路径 this.bindGEvent( AdventureEVT.Update_Room_Path, this.resultPath.bind( this ) ); //重置路径 this.bindGEvent( AdventureEVT.Reset_Room_Path, this.ClickPathCancel.bind( this ) ); //更新指定房间 this.bindGEvent( AdventureEVT.Update_Room_Info, this.updateRoomInfo.bind( this ) ); //更新模型 this.bindGEvent( AdventureEVT.Update_Role_Model, this.updateRoleModel.bind( this )) //更新人物状态 this.bindGEvent( AdventureEVT.Update_Role_Good_Status, this.updateRoleStatus.bind( this )) this.bindGEvent(AdventureEVT.Buy_Energy,this.updateBuyEnergy.bind(this)); }, synchLayerPos(){ this.touchLayer.position = this.list.position; this.moveLayer.position = this.list.position; }, InitRoleInfo(){ //设置起始位置 this.setInitPos(); }, updateRoomInfo(index){ if(index == null)return; let cmp = this.maps[index]; if(cmp){ //刷新房间信息 cmp.updateInfo(); } }, updateBuyEnergy(energy){ nx.gui.setString(this.powers,"num",energy); }, //設置和更新探索度,體力等玩家消耗的信息 updatePlayerInfo(base_data){ //無盡模式不需要探索度 if(this.type == 1){ this.explores.active = false; this.powers.active = false; this.floors.active = true; nx.gui.setString(this.floors,"num",base_data.id); }else{ this.explores.active = true; this.floors.active = false; this.powers.active = true; nx.gui.setString(this.explores,"bg/num",base_data.explore); //體力值 nx.gui.setString(this.powers,"num",base_data.energy); } }, InitBase(){ this.base_data = this.ctrl.getBaseData(); //地图初始化 let mapdata = this.ctrl.getMapsInfo(); let total = 96; total = mapdata.x * mapdata.y; this.list.setContentSize(mapdata.x*90+300,mapdata.y*90+300); for(let i=0;i= 10)return;//需要包含起始位置且可行进为10 for(let i in this.paths){ if(this.paths[i].x == tx && this.paths[i].y == ty){ return; } } let index = this.reverseIndex(tx,ty); if(index != null){ let cmp = this.maps[index]; if(cmp){ cmp.lightMap(); } } this.paths.push({x:tx,y:ty}); nx.gui.setString(this.foots,"",cc.js.formatStr(nx.text.getKey("AdvenFoots"),this.paths.length)); }, //服务端返回的结果处理路径 resultPath(data){ this.is_trap = data.is_trap; //去点无用路径 let points = data.footpoint; for(let p = 0;p < this.paths.length;p++){ let path = this.paths[p]; let index = this.reverseIndex(path.x,path.y); let cmp = this.maps[index]; if(cmp){ cmp.nightMap(); } } //人物按照路径行动 this.startMove(points); nx.gui.setString(this.foots,"",cc.js.formatStr(nx.text.getKey("AdvenFoots"),points.length)); this.paths = []; this.nightPaths = []; }, //角色移动 startMove(points){ let pts = [];//路径位置 for(let i = 0;i < points.length;i++){ let xy = points[i]; let real_x = xy.x*90 - 45; let real_y = xy.y*90 - 45; let real_pos = new cc.Vec2(real_x,real_y); pts.push(real_pos); } this.curMovePaths = points; this.dirRole.pushPaths( pts ); }, //检测解锁迷雾路径 checkFogPath(path){ if(!path)return; let x = path.x; let y = path.y; let up = [x,y + 1]; let uindex = this.reverseIndex(up[0],up[1]); let cmp = this.maps[uindex]; if(cmp){ cmp.delCloud();//解锁迷雾 this.nightPaths.push(uindex); } let down = [x,y - 1]; let dindex = this.reverseIndex(down[0],down[1]); let cmp2 = this.maps[dindex]; if(cmp2){ cmp2.delCloud();//解锁迷雾 this.nightPaths.push(dindex); } let left = [x - 1,y]; let lindex = this.reverseIndex(left[0],left[1]); let cmp3 = this.maps[lindex]; if(cmp3){ cmp3.delCloud();//解锁迷雾 this.nightPaths.push(lindex); } let right = [x + 1,y]; let rindex = this.reverseIndex(right[0],right[1]); let cmp4 = this.maps[rindex]; if(cmp4){ cmp4.delCloud();//解锁迷雾 this.nightPaths.push(rindex); } }, reverseIndex(x,y){ let index = null; if((x>0) && (x<=this.ctrl.getMapsInfo().x) &&( y>0) && (y<=this.ctrl.getMapsInfo().y)){ index = ((y-1)*this.ctrl.getMapsInfo().x + x) -1; } return index; }, //基于已解锁的格子主动触发的事件 pointMap(t){ if(this.paths.length > 0)return; if(this.is_moving)return; let t_pos = t.getLocation(); let pos = this.list.convertToNodeSpaceAR(t_pos); //需要計算偏移,不然會錯位 let tx = Math.ceil((pos.x)/90);// - this.touchLayer.x let ty = Math.ceil((pos.y)/90);// - this.touchLayer.y let index = this.reverseIndex(tx,ty); //要判斷是否跟角色節點相鄰 let start_pos = this.ctrl.getCurStartPos(); let start_index = this.reverseIndex(start_pos.x,start_pos.y); let is_neib = this.checkNeighber(index,start_index);//檢查臨近 if(!is_neib)return;//不臨近 if(index!=null){ let cmp = this.maps[index]; //处理事件 if(cmp){ cmp.checkEvtInPath(); } } }, checkNeighber(target_index,start_index){ let is_neib = false; let target_cmp = this.maps[target_index]; let s_cmp = this.maps[start_index]; //去絕對距離 if(!target_cmp || !s_cmp ||!target_cmp.node || !s_cmp.node)return; let x = Math.abs(target_cmp.node.x - s_cmp.node.x); let y = Math.abs(target_cmp.node.y - s_cmp.node.y); if(x <= 110 && y <= 110){ is_neib = true; }else{ is_neib = false; } return is_neib; }, ClickPathCancel(){ if(this.paths.length == 0){ return nx.tbox("AdvenPathTip"); } for(let a in this.maps){ let pos = this.maps[a].getPoses(); if(pos){ for(let b in this.paths){ if(this.paths[b].x == pos.x && this.paths[b].y == pos.y){ this.maps[a].nightMap(); break; } } } } this.paths = []; this.nightPaths = []; }, ClickPathSend(){ //检测是否是从出发点开始的合法路径 let start_pos = this.ctrl.getCurStartPos(); let is_real = false; if(this.paths.length > 0){ let up = [start_pos.x,start_pos.y+1]; if(this.paths[0].x == up[0] && this.paths[0].y == up[1]){ is_real = true; } let down = [start_pos.x,start_pos.y-1]; if(this.paths[0].x == down[0] && this.paths[0].y == down[1]){ is_real = true; } let left = [start_pos.x-1,start_pos.y]; if(this.paths[0].x == left[0] && this.paths[0].y == left[1]){ is_real = true; } let right = [start_pos.x+1,start_pos.y]; if(this.paths[0].x == right[0] && this.paths[0].y == right[1]){ is_real = true; } } if(!is_real){ this.ClickPathCancel(); return nx.tbox("AdvenRightPath"); } //发消息通知服务端 this.ctrl.send29508(this.paths,this.ctrl.getPlayModel()); }, //切换可视化模式还是编辑模式 ClickChangeModel(){ this.touchLayer.active = !this.touchLayer.active; }, clickShowInfos(){ if(this.infoNd.scale == 1){ this.infoNd.scale = 0; }else{ this.infoNd.scale = 1; } }, // update (dt) {}, });