From b9dc593bd1230e73e91c4d4d825ca74e0deafcba Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Mon, 29 Oct 2018 12:59:24 +0800 Subject: [PATCH] F4 debug & cannotIn/Out --- _server/comment.js | 15 +++++++- libs/actions.js | 4 +++ libs/control.js | 1 + libs/core.js | 2 ++ libs/events.js | 9 ++--- libs/maps.js | 83 +++++++++++++++++++++++++------------------- project/functions.js | 13 ++++--- project/maps.js | 8 ++--- 8 files changed, 80 insertions(+), 55 deletions(-) diff --git a/_server/comment.js b/_server/comment.js index 6421f29e..0cfcfce0 100644 --- a/_server/comment.js +++ b/_server/comment.js @@ -231,6 +231,18 @@ comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_type": "checkbox", "_bool": "bool", "_data": "该图块是否可被破墙或地震" + }, + "cannotOut": { + "_leaf": true, + "_type": "textarea", + "_range": "thiseval==null||(thiseval instanceof Array)", + "_data": "该图块的不可出方向\n可以在这里定义在该图块时不能前往哪个方向,可以达到悬崖之类的效果\n例如 [\"up\", \"left\"] 代表在该图块时不能往上和左走\n此值对背景层、事件层、前景层上的图块均有效" + }, + "cannotIn": { + "_leaf": true, + "_type": "textarea", + "_range": "thiseval==null||(thiseval instanceof Array)", + "_data": "该图块的不可入方向\n可以在这里定义不能从哪个方向访问该图块,可以达到悬崖之类的效果\n例如 [\"down\", \"right\"] 代表不能从下或右访问此图块\n此值对背景层、事件层、前景层上的图块均有效" } } }, @@ -385,7 +397,8 @@ comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "cannotMove": { "_leaf": true, "_type": "textarea", - "_data": "该点不可通行的方向 \n 可以在这里定义该点不能前往哪个方向,可以达到悬崖之类的效果\n例如 [\"up\", \"left\"], // 代表该点不能往上和左走" + "_range": "thiseval==null||(thiseval instanceof Array)", + "_data": "该点不可通行的方向 \n 可以在这里定义该点不能前往哪个方向,可以达到悬崖之类的效果\n例如 [\"up\", \"left\"] 代表该点不能往上和左走" } } } diff --git a/libs/actions.js b/libs/actions.js index e0803368..5b6c1ee5 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -422,6 +422,10 @@ actions.prototype.keyUp = function(keyCode, altKey) { } } break; + case 118: // F7开启debug模式 + if (core.status.heroStop) + core.debug(); + break; } diff --git a/libs/control.js b/libs/control.js index dacb11d5..0a6ce796 100644 --- a/libs/control.js +++ b/libs/control.js @@ -422,6 +422,7 @@ control.prototype.tryMoveDirectly = function (destX, destY) { return false; var testMove = function (dx, dy, dir) { if (dx<0 || dx>=core.bigmap.width|| dy<0 || dy>=core.bigmap.height) return false; + if (core.isset(dir) && !core.canMoveHero(dx,dy,dir)) return false; if (core.control.moveDirectly(dx, dy)) { if (core.isset(dir)) core.moveHero(dir, function() {}); return true; diff --git a/libs/core.js b/libs/core.js index deea76b5..d15765ae 100644 --- a/libs/core.js +++ b/libs/core.js @@ -92,6 +92,8 @@ function core() { 'floorId': null, 'thisMap': null, 'maps': null, + 'bgmaps': {}, + 'fgmaps': {}, 'checkBlock': {}, // 显伤伤害 'lockControl': false, diff --git a/libs/events.js b/libs/events.js index e81337b6..56907f27 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1020,13 +1020,8 @@ events.prototype.insertAction = function (action, x, y, callback) { ////// 获得面前的物品(轻按) ////// events.prototype.getNextItem = function() { if (!core.status.heroStop || !core.flags.enableGentleClick) return false; - // 检查cannotMove - var x = core.getHeroLoc('x'), y=core.getHeroLoc('y'), direction=core.getHeroLoc('direction'); - if (core.isset(core.floors[core.status.floorId].cannotMove)) { - var cannotMove = core.floors[core.status.floorId].cannotMove[x+","+y]; - if (core.isset(cannotMove) && cannotMove instanceof Array && cannotMove.indexOf(direction)>=0) - return false; - } + + if (!core.canMoveHero()) return false; var nextX = core.nextX(), nextY = core.nextY(); var block = core.getBlock(nextX, nextY); diff --git a/libs/maps.js b/libs/maps.js index fe7bd20f..9a319ca6 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -264,17 +264,21 @@ maps.prototype.canMoveHero = function(x,y,direction,floorId) { return false; } - var nowBlock = core.getBlock(x,y,floorId); - if (nowBlock!=null){ - var nowId = nowBlock.block.event.id; - var nowIsArrow = nowId.slice(0, 5).toLowerCase() == 'arrow'; - if(nowIsArrow){ - var nowArrow = nowId.slice(5).toLowerCase(); - if (direction != nowArrow) { - return false; - } - } + var check = function (block, name) { + if (!core.isset(block)) return true; + if (block instanceof Array) return check((block[y]||[])[x], name); + if (typeof block == 'number') return check(core.maps.initBlock(0,0,block), name); + if (core.isset(block.block)) return check(block.block, name); + return ((block.event||{})[name]||[]).indexOf(direction)<0; } + var getNumber = function (floorId, name, x, y) { + return (core.maps.getBgFgMapArray(floorId, name)[y]||[])[x]; + } + + // 检查该点的cannotOut + if (!check(core.getBlock(x,y,floorId),"cannotOut") || !check(getNumber(floorId,"bg",x,y),"cannotOut") || !check(getNumber(floorId,"fg",x,y),"cannotOut")) + return false; + var scan = { 'up': {'x': 0, 'y': -1}, 'left': {'x': -1, 'y': 0}, @@ -282,18 +286,9 @@ maps.prototype.canMoveHero = function(x,y,direction,floorId) { 'right': {'x': 1, 'y': 0} }; var nx = x+scan[direction].x, ny = y+scan[direction].y; - var nextBlock = core.getBlock(nx,ny); - if (nextBlock!=null){ - var nextId = nextBlock.block.event.id; - // 遇到单向箭头处理 - var isArrow = nextId.slice(0, 5).toLowerCase() == 'arrow'; - if(isArrow){ - var nextArrow = nextId.slice(5).toLowerCase(); - if ( (scan[direction].x + scan[nextArrow].x) == 0 && (scan[direction].y + scan[nextArrow].y) == 0 ) { - return false; - } - } - } + // 检查目标点的cannotIn + if (!check(core.getBlock(nx,ny,floorId),"cannotIn") || !check(getNumber(floorId,"bg",nx,ny),"cannotIn") || !check(getNumber(floorId,"fg",nx,ny),"cannotIn")) + return false; // 检查将死的领域 if (floorId==core.status.floorId && core.status.hero.hp <= core.status.checkBlock.damage[nx+core.bigmap.width*ny] @@ -392,8 +387,31 @@ maps.prototype.drawBlock = function (block, animate, dx, dy) { } } +maps.prototype.getBgFgMapArray = function (floorId, name) { + floorId = floorId||core.status.floorId; + var width = core.floors[floorId].width || 13; + var height = core.floors[floorId].height || 13; + + if (core.isset(core.status[name+"maps"][floorId])) + return core.status[name+"maps"][floorId]; + + var arr = core.clone(core.floors[floorId][name+"map"] || []); + if(main.mode=='editor')arr = core.clone(editor[name+"map"])||arr; + for (var x = 0; x < width; x++) { + for (var y = 0; y < height; y++) { + arr[y] = arr[y] || []; + if (core.hasFlag(name + "_" + floorId + "_" + x + "_" + y)) arr[y][x] = 0; + else arr[y][x] = core.getFlag(name + "v_" + floorId + "_" + x + "_" + y, arr[y][x] || 0); + if(main.mode=='editor')arr[y][x]= arr[y][x].idnum || arr[y][x] || 0; + } + } + core.status[name+"maps"][floorId] = core.clone(arr); + return arr; +} + ////// 背景/前景图块的绘制 ////// maps.prototype.drawBgFgMap = function (floorId, canvas, name) { + floorId = floorId || core.status.floorId; var width = core.floors[floorId].width || 13; var height = core.floors[floorId].height || 13; @@ -401,20 +419,10 @@ maps.prototype.drawBgFgMap = function (floorId, canvas, name) { var blockIcon = core.material.icons.terrains[groundId]; var blockImage = core.material.images.terrains; - var getMapArray = function (name) { - var arr = core.clone(core.floors[floorId][name+"map"] || []); - if(main.mode=='editor')arr = core.clone(editor[name+"map"])||arr; - for (var x = 0; x < width; x++) { - for (var y = 0; y < height; y++) { - arr[y] = arr[y] || []; - if (core.hasFlag(name + "_" + floorId + "_" + x + "_" + y)) arr[y][x] = 0; - else arr[y][x] = core.getFlag(name + "v_" + floorId + "_" + x + "_" + y, arr[y][x] || 0); - if(main.mode=='editor')arr[y][x]= arr[y][x].idnum || arr[y][x] || 0; - } - } - return arr; - } - var arr = getMapArray(name); + if (!core.isset(core.status[name+"maps"])) + core.status[name+"maps"] = {}; + + var arr = this.getBgFgMapArray(floorId, name); for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { if (name=='bg') @@ -1163,6 +1171,8 @@ maps.prototype.setBgFgBlock = function (name, number, x, y, floorId) { if (name!='bg' && name!='fg') return; core.setFlag(name+"v_"+floorId+"_"+x+"_"+y, number); + core.status[name+"maps"][floorId] = null; + if (floorId == core.status.floorId) core.drawMap(floorId); } @@ -1331,6 +1341,7 @@ maps.prototype.setBgFgMap = function (type, name, loc, floorId, callback) { var flag = name+"_"+floorId+"_"+x+"_"+y; core.setFlag(flag, type=='show'?false:true); }) + core.status[name+"maps"][floorId]=null; if (floorId==core.status.floorId) { core.drawMap(floorId, callback); diff --git a/project/functions.js b/project/functions.js index 827b5ed5..fff7e6bb 100644 --- a/project/functions.js +++ b/project/functions.js @@ -120,13 +120,12 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = var enemy = core.material.enemys[enemyId]; // 播放战斗音效和动画 - var equipAnimate = 'hand'; - if (core.flags.equipment) { - var equipId = (core.status.hero.equipment||[])[0]; - if (core.isset(core.material.items[equipId]) && core.isset(core.material.items[equipId].equip.animate)) - equipAnimate = core.material.items[equipId].equip.animate; - } - core.playSound('attack.mp3'); + var equipAnimate = 'hand', equipId = (core.status.hero.equipment||[])[0]; + if (core.isset(equipId) && core.isset((core.material.items[equipId].equip||{}).animate)) + equipAnimate = core.material.items[equipId].equip.animate; + // 检查equipAnimate是否存在SE,如果不存在则使用默认音效 + if (!core.isset((core.material.animates[equipAnimate]||{}).se)) + core.playSound('attack.mp3'); core.drawAnimate(equipAnimate, x, y); var damage = core.enemys.getDamage(enemyId, x, y); diff --git a/project/maps.js b/project/maps.js index e015b2f5..6fee9b19 100644 --- a/project/maps.js +++ b/project/maps.js @@ -146,10 +146,10 @@ maps_90f36752_8815_4be8_b32b_d7fad1d0542e = ////////////////////////// 其他部分 ////////////////////////// // 171-200 其他(单向箭头、灯、箱子等等) - '161':{'cls': 'terrains', 'id': 'arrowUp', 'noPass': false}, // 单向上箭头 - '162':{'cls': 'terrains', 'id': 'arrowDown', 'noPass': false}, // 单向下箭头 - '163':{'cls': 'terrains', 'id': 'arrowLeft', 'noPass': false}, // 单向左箭头 - '164':{'cls': 'terrains', 'id': 'arrowRight', 'noPass': false}, // 单向右箭头 + '161':{'cls': 'terrains', 'id': 'arrowUp', 'noPass': false, "cannotOut": ["left","right","down"], "cannotIn": ["down"]}, // 单向上箭头 + '162':{'cls': 'terrains', 'id': 'arrowDown', 'noPass': false, "cannotOut": ["left","right","up"], "cannotIn": ["up"]}, // 单向下箭头 + '163':{'cls': 'terrains', 'id': 'arrowLeft', 'noPass': false, "cannotOut": ["up","down","right"], "cannotIn": ["right"]}, // 单向左箭头 + '164':{'cls': 'terrains', 'id': 'arrowRight', 'noPass': false, "cannotOut": ["up","down","left"], "cannotIn": ["left"]}, // 单向右箭头 '165':{'cls': 'terrains', 'id': 'light', 'trigger': 'changeLight', 'noPass': false}, // 灯 '166':{'cls': 'terrains', 'id': 'darkLight', 'noPass': true}, // 暗灯 '167':{'cls': 'terrains', 'id': 'ski', 'trigger': 'ski', 'noPass': false}, // 滑冰