496 lines
15 KiB
JavaScript
496 lines
15 KiB
JavaScript
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<total;i++){
|
|
let item = this.maps[i];
|
|
if(!item){
|
|
item = cc.instantiate(this.mapItem);
|
|
item.parent = this.list;
|
|
let 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(){
|
|
if(nx.dt.objEmpty(this.maps))return;
|
|
let start_pos = this.ctrl.getCurStartPos();
|
|
let index = this.reverseIndex(start_pos.x,start_pos.y);
|
|
let 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(){
|
|
if(this.is_moving){
|
|
this.is_use_inMove = true;
|
|
return;
|
|
}
|
|
let leader = this.ctrl.getCurLeader();
|
|
let leader_res = game.configs.partner_data.data_partner_base[leader].bustid;
|
|
this.dirRole.setModel(leader_res,this.roleMovePath.bind(this));
|
|
},
|
|
|
|
updateRoleStatus(effect){
|
|
// if(!effect)return;
|
|
//如果不是中毒,就播一次,播完再播中毒
|
|
if(effect == "E66002"){
|
|
this.dirRole.setMethyStatus(1);
|
|
}else{
|
|
this.dirRole.setBuffEft(effect);
|
|
}
|
|
},
|
|
|
|
setRightAngle(){
|
|
let start_pos = this.ctrl.getCurStartPos();
|
|
let 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(_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"){//移动中的事件
|
|
let move_path = this.curMovePaths.shift();
|
|
//点亮路径周围迷雾
|
|
this.checkFogPath(move_path);
|
|
let index = this.reverseIndex(move_path.x,move_path.y);
|
|
let 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 () {
|
|
|
|
},
|
|
|
|
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() {
|
|
this.maps = null;
|
|
this.mapPool.clear();
|
|
nx.bridge.NodeChidrenDestroy(this.list);
|
|
},
|
|
|
|
//基于未解锁的格子
|
|
orderPath(t){
|
|
if(this.is_moving)return;
|
|
if(this.ctrl.getDeadStatus()){
|
|
return;//已死亡
|
|
}
|
|
|
|
let t_pos = t.getLocation();
|
|
let pos = this.list.convertToNodeSpaceAR(t_pos);
|
|
let tx = Math.ceil(pos.x/90);
|
|
let ty = Math.ceil(pos.y/90);
|
|
|
|
let start_pos = this.ctrl.getCurStartPos();
|
|
if(tx == start_pos.x && ty == start_pos.y)return;
|
|
if(this.paths.length >= 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) {},
|
|
});
|