"use strict"; cc._RF.push(module, '804f72ONDhHFqTAWhUMTBeA', 'cmp.adventure.main'); // Scripts/mod/pve/adventure/cmp/cmp.adventure.main.js "use strict"; var NxExpand = require("nx.fx.sv.expand"); var BridgeWindow = require("bridge.window"); var AdventureEVT = require("adventure_event"); var ADVCT = require("adventure_controller"); var 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: function 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: function synchLayerPos() { this.touchLayer.position = this.list.position; this.moveLayer.position = this.list.position; }, InitRoleInfo: function InitRoleInfo() { //设置起始位置 this.setInitPos(); }, updateRoomInfo: function updateRoomInfo(index) { if (index == null) return; var cmp = this.maps[index]; if (cmp) { //刷新房间信息 cmp.updateInfo(); } }, updateBuyEnergy: function updateBuyEnergy(energy) { nx.gui.setString(this.powers, "num", energy); }, //設置和更新探索度,體力等玩家消耗的信息 updatePlayerInfo: function 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: function InitBase() { this.base_data = this.ctrl.getBaseData(); //地图初始化 var mapdata = this.ctrl.getMapsInfo(); var total = 96; total = mapdata.x * mapdata.y; this.list.setContentSize(mapdata.x * 90 + 300, mapdata.y * 90 + 300); for (var i = 0; i < total; i++) { var item = this.maps[i]; if (!item) { item = cc.instantiate(this.mapItem); item.parent = this.list; var cmp = item.getComponent("cmp.adventure.map"); cmp.setPos(i); this.maps[i] = cmp; } else { if (this.need_refresh_all) { //需要重建 item.setPos(i); } else { item.updateInfo(i); } } } this.touchLayer.setContentSize(mapdata.x * 90 + 300, mapdata.y * 90 + 300); //设置起始位置 if (this.need_refresh_all) { this.setInitPos(); this.need_refresh_all = false; } }, setInitPos: function setInitPos() { if (nx.dt.objEmpty(this.maps)) return; var start_pos = this.ctrl.getCurStartPos(); var index = this.reverseIndex(start_pos.x, start_pos.y); var cmp = this.maps[index]; if (cmp) { this.dirTag.x = start_pos.x * 90 - 90 / 2; this.dirTag.y = start_pos.y * 90 - 90 / 2; } this.setRightAngle(); //设置模型 // this.updateRoleModel(); }, updateRoleModel: function updateRoleModel() { if (this.is_moving) { this.is_use_inMove = true; return; } var leader = this.ctrl.getCurLeader(); var leader_res = game.configs.partner_data.data_partner_base[leader].bustid; this.dirRole.setModel(leader_res, this.roleMovePath.bind(this)); }, updateRoleStatus: function updateRoleStatus(effect) { // if(!effect)return; //如果不是中毒,就播一次,播完再播中毒 if (effect == "E66002") { this.dirRole.setMethyStatus(1); } else { this.dirRole.setBuffEft(effect); } }, setRightAngle: function setRightAngle() { var start_pos = this.ctrl.getCurStartPos(); var map_info = this.ctrl.getMapsInfo(); this.mapScroll.scrollTo(cc.v2((start_pos.x - 1) / map_info.x, (start_pos.y - 1) / map_info.y), 1); this.synchLayerPos(); }, roleMovePath: function roleMovePath(_key) { if (_key == "end") { //检测是否要触发事件 nx.gui.setString(this.foots, "", ""); this.is_moving = false; this.setRightAngle(); if (this.is_use_inMove) { this.is_use_inMove = false; this.updateRoleModel(); } } else if (_key == "start") { //有可能要重置状态 this.is_moving = true; } else if (_key == "move") { //移动中的事件 var move_path = this.curMovePaths.shift(); //点亮路径周围迷雾 this.checkFogPath(move_path); var index = this.reverseIndex(move_path.x, move_path.y); var cmp = this.maps[index]; if (cmp) { cmp.delCloud(); if (this.is_trap == 1) { cmp.checkEvtInPath(); } } if (this.curMovePaths.length <= 0) { this.ctrl.setCurStartPos(move_path); } } }, start: function start() {}, onOpenConfigs: function onOpenConfigs(params) { this.type = params.type || 1; //1 无尽模式 2 周回模式 if (this.type == 1) { this.ctrl.send29509(this.type); //请求英雄列表 } else { this.ctrl.send29500(this.type); this.ctrl.send29502(this.type); } this.ctrl.send29501(this.type); this.ctrl.send29506(this.type); // this.updateRoleStatus("E66002"); }, onPreClosed: function onPreClosed() { this.maps = null; this.mapPool.clear(); nx.bridge.NodeChidrenDestroy(this.list); }, //基于未解锁的格子 orderPath: function orderPath(t) { if (this.is_moving) return; if (this.ctrl.getDeadStatus()) { return; //已死亡 } var t_pos = t.getLocation(); var pos = this.list.convertToNodeSpaceAR(t_pos); var tx = Math.ceil(pos.x / 90); var ty = Math.ceil(pos.y / 90); var start_pos = this.ctrl.getCurStartPos(); if (tx == start_pos.x && ty == start_pos.y) return; if (this.paths.length >= 10) return; //需要包含起始位置且可行进为10 for (var i in this.paths) { if (this.paths[i].x == tx && this.paths[i].y == ty) { return; } } var index = this.reverseIndex(tx, ty); if (index != null) { var 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: function resultPath(data) { this.is_trap = data.is_trap; //去点无用路径 var points = data.footpoint; for (var p = 0; p < this.paths.length; p++) { var path = this.paths[p]; var index = this.reverseIndex(path.x, path.y); var 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: function startMove(points) { var pts = []; //路径位置 for (var i = 0; i < points.length; i++) { var xy = points[i]; var real_x = xy.x * 90 - 45; var real_y = xy.y * 90 - 45; var real_pos = new cc.Vec2(real_x, real_y); pts.push(real_pos); } this.curMovePaths = points; this.dirRole.pushPaths(pts); }, //检测解锁迷雾路径 checkFogPath: function checkFogPath(path) { if (!path) return; var x = path.x; var y = path.y; var up = [x, y + 1]; var uindex = this.reverseIndex(up[0], up[1]); var cmp = this.maps[uindex]; if (cmp) { cmp.delCloud(); //解锁迷雾 this.nightPaths.push(uindex); } var down = [x, y - 1]; var dindex = this.reverseIndex(down[0], down[1]); var cmp2 = this.maps[dindex]; if (cmp2) { cmp2.delCloud(); //解锁迷雾 this.nightPaths.push(dindex); } var left = [x - 1, y]; var lindex = this.reverseIndex(left[0], left[1]); var cmp3 = this.maps[lindex]; if (cmp3) { cmp3.delCloud(); //解锁迷雾 this.nightPaths.push(lindex); } var right = [x + 1, y]; var rindex = this.reverseIndex(right[0], right[1]); var cmp4 = this.maps[rindex]; if (cmp4) { cmp4.delCloud(); //解锁迷雾 this.nightPaths.push(rindex); } }, reverseIndex: function reverseIndex(x, y) { var 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: function pointMap(t) { if (this.paths.length > 0) return; if (this.is_moving) return; var t_pos = t.getLocation(); var pos = this.list.convertToNodeSpaceAR(t_pos); //需要計算偏移,不然會錯位 var tx = Math.ceil(pos.x / 90); // - this.touchLayer.x var ty = Math.ceil(pos.y / 90); // - this.touchLayer.y var index = this.reverseIndex(tx, ty); //要判斷是否跟角色節點相鄰 var start_pos = this.ctrl.getCurStartPos(); var start_index = this.reverseIndex(start_pos.x, start_pos.y); var is_neib = this.checkNeighber(index, start_index); //檢查臨近 if (!is_neib) return; //不臨近 if (index != null) { var cmp = this.maps[index]; //处理事件 if (cmp) { cmp.checkEvtInPath(); } } }, checkNeighber: function checkNeighber(target_index, start_index) { var is_neib = false; var target_cmp = this.maps[target_index]; var s_cmp = this.maps[start_index]; //去絕對距離 if (!target_cmp || !s_cmp || !target_cmp.node || !s_cmp.node) return; var x = Math.abs(target_cmp.node.x - s_cmp.node.x); var 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: function ClickPathCancel() { if (this.paths.length == 0) { return nx.tbox("AdvenPathTip"); } for (var a in this.maps) { var pos = this.maps[a].getPoses(); if (pos) { for (var 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: function ClickPathSend() { //检测是否是从出发点开始的合法路径 var start_pos = this.ctrl.getCurStartPos(); var is_real = false; if (this.paths.length > 0) { var up = [start_pos.x, start_pos.y + 1]; if (this.paths[0].x == up[0] && this.paths[0].y == up[1]) { is_real = true; } var down = [start_pos.x, start_pos.y - 1]; if (this.paths[0].x == down[0] && this.paths[0].y == down[1]) { is_real = true; } var left = [start_pos.x - 1, start_pos.y]; if (this.paths[0].x == left[0] && this.paths[0].y == left[1]) { is_real = true; } var 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: function ClickChangeModel() { this.touchLayer.active = !this.touchLayer.active; }, clickShowInfos: function clickShowInfos() { if (this.infoNd.scale == 1) { this.infoNd.scale = 0; } else { this.infoNd.scale = 1; } } // update (dt) {}, }); cc._RF.pop();