From d440987345f4f56b7a7c80fdf8e96097b2dd3c7c Mon Sep 17 00:00:00 2001 From: oc Date: Thu, 14 Mar 2019 22:05:14 +0800 Subject: [PATCH] drawThumbnail & updateCheckBlock(floorId) --- libs/control.js | 33 +++++++------------- libs/events.js | 3 +- libs/items.js | 10 ++++-- libs/maps.js | 22 +++++++------ libs/ui.js | 23 ++++++++------ project/functions.js | 73 +++++++++++++++++++++++--------------------- 6 files changed, 84 insertions(+), 80 deletions(-) diff --git a/libs/control.js b/libs/control.js index 4996210b..f006e9ef 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1220,8 +1220,8 @@ control.prototype.updateFollowers = function () { } ////// 更新领域、夹击、阻击的伤害地图 ////// -control.prototype.updateCheckBlock = function() { - return this.controldata.updateCheckBlock(); +control.prototype.updateCheckBlock = function(floorId) { + return this.controldata.updateCheckBlock(floorId); } ////// 检查并执行领域、夹击、阻击事件 ////// @@ -1455,9 +1455,11 @@ control.prototype.updateDamage = function (floorId, canvas) { floorId = floorId || core.status.floorId; if (!core.isset(floorId)) return; if (core.status.gameOver) return; + var refreshCheckBlock = true; if (!core.isset(canvas)) { canvas = core.canvas.damage; core.clearMap('damage'); + refreshCheckBlock = false; } // 更新显伤 @@ -1502,37 +1504,24 @@ control.prototype.updateDamage = function (floorId, canvas) { if (core.flags.displayExtraDamage && core.isset((core.status.checkBlock||{}).damage)) { canvas.textAlign = 'center'; - // 临时改变 - var tempCheckBlock = null; - if (floorId != core.status.floorId) { - tempCheckBlock = core.clone(core.status.checkBlock); - core.status.thisMap = core.status.maps[floorId]; - core.bigmap.width = core.floors[floorId].width; - core.bigmap.height = core.floors[floorId].height; - core.updateCheckBlock(); - } + if (refreshCheckBlock) + this.updateCheckBlock(floorId); - for (var x=0;x0) { // 该点伤害 damage = core.formatBigNumber(damage, true); core.fillBoldText(canvas, damage, 32*x+16, 32*(y+1)-14, '#FF7F00'); } else { // 检查捕捉 - if ((core.status.checkBlock.ambush||[])[x+core.bigmap.width*y]) { + if ((core.status.checkBlock.ambush||[])[x+width*y]) { core.fillBoldText(canvas, '!', 32*x+16, 32*(y+1)-14, '#FF7F00'); } } } } - - if (floorId!=core.status.floorId) { - core.status.thisMap = core.status.maps[core.status.floorId]; - core.status.checkBlock = tempCheckBlock; - core.bigmap.width = core.floors[core.status.floorId].width; - core.bigmap.height = core.floors[core.status.floorId].height; - } } } diff --git a/libs/events.js b/libs/events.js index 8ddde54e..d4e549e9 100644 --- a/libs/events.js +++ b/libs/events.js @@ -2104,7 +2104,8 @@ events.prototype.tryUseItem = function(itemId) { var fillstyle = 'rgba(255,0,0,0.5)'; if (core.canUseItem('centerFly')) fillstyle = 'rgba(0,255,0,0.5)'; var toX = core.bigmap.width-1 - core.getHeroLoc('x'), toY = core.bigmap.height-1-core.getHeroLoc('y'); - core.ui.drawThumbnail(core.status.floorId, 'ui', core.status.thisMap.blocks, 0, 0, 416, toX, toY, core.status.hero.loc, core.getFlag('heroIcon', "hero.png")); + core.drawThumbnail(null, null, {heroLoc: core.status.hero.loc, heroIcon: core.getFlag('heroIcon', "hero.png")}, + {ctx: 'ui', centerX: toX, centerY: toY}); var offsetX = core.clamp(toX-6, 0, core.bigmap.width-13), offsetY = core.clamp(toY-6, 0, core.bigmap.height-13); core.fillRect('ui',(toX-offsetX)*32,(toY-offsetY)*32,32,32,fillstyle); core.status.event.data = {"x": toX, "y": toY, "posX": toX-offsetX, "posY": toY-offsetY}; diff --git a/libs/items.js b/libs/items.js index f38f8cb3..ec445a3c 100644 --- a/libs/items.js +++ b/libs/items.js @@ -81,7 +81,10 @@ items.prototype._afterUseItem = function (itemId) { if (core.status.hero.items[itemCls][itemId]<=0) delete core.status.hero.items[itemCls][itemId]; - core.status.event.ui = null; + if (!core.status.event.id) { + core.status.event.data = null; + core.status.event.ui = null; + } core.updateStatusBar(); } @@ -114,7 +117,10 @@ items.prototype.canUseItem = function (itemId) { main.log(e); } } - if (!able) core.status.event.ui = null; + if (!able) { + core.status.event.data = null; + core.status.event.ui = null; + } return able; } diff --git a/libs/maps.js b/libs/maps.js index 85dfa778..82a40107 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -339,13 +339,13 @@ maps.prototype.getMapBlocksObj = function (floorId, showDisable) { } ////// 将背景前景层变成二维数组的形式 ////// -maps.prototype.getBgFgMapArray = function (name, floorId) { +maps.prototype.getBgFgMapArray = function (name, floorId, useCache) { floorId = floorId||core.status.floorId; if (!core.isset(floorId)) return []; var width = core.floors[floorId].width; var height = core.floors[floorId].height; - if (main.mode!='editor' && core.isset(core.status[name+"maps"][floorId])) + if (useCache && core.isset(core.status[name+"maps"][floorId])) return core.status[name+"maps"][floorId]; var arr = core.clone(core.floors[floorId][name+"map"] || []); @@ -360,7 +360,8 @@ maps.prototype.getBgFgMapArray = function (name, floorId) { if(main.mode=='editor')arr[y][x]= arr[y][x].idnum || arr[y][x] || 0; } } - core.status[name+"maps"][floorId] = core.clone(arr); + if (useCache) + core.status[name+"maps"][floorId] = core.clone(arr); return arr; } @@ -371,8 +372,8 @@ maps.prototype.generateMovableArray = function (floorId, x, y) { floorId = floorId || core.status.floorId; if (!core.isset(floorId)) return null; var width = core.floors[floorId].width, height = core.floors[floorId].height; - var bgArray = this.getBgFgMapArray('bg', floorId), - fgArray = this.getBgFgMapArray('fg', floorId), + var bgArray = this.getBgFgMapArray('bg', floorId, true), + fgArray = this.getBgFgMapArray('fg', floorId, true), eventArray = this.getMapArray(floorId); var generate = function (x, y) { @@ -723,8 +724,8 @@ maps.prototype._drawFloorImages = function (floorId, ctx, name, images, currStat maps.prototype._getFloorImages = function (floorId) { floorId = floorId || core.status.floorId; var images = []; - if (core.isset(core.status.maps[floorId].images)) { - images = core.status.maps[floorId].images; + if (core.isset((core.status.maps||core.floors)[floorId].images)) { + images = (core.status.maps||core.floors)[floorId].images; if (typeof images == 'string') { images = [[0, 0, images]]; } @@ -898,9 +899,10 @@ maps.prototype._makeAutotileEdges = function () { ////// 绘制缩略图 ////// // 此函数将绘制一个缩略图,floorId为目标floorId,blocks为地图的图块(可为null使用floorId对应默认的) // options为绘制选项(可为null),包括: -// heroLoc: 勇士位置;heroIcon:勇士图标;damage:是否绘制显伤;flags:当前的flags(存读档时使用) +// heroLoc: 勇士位置;heroIcon:勇士图标(默认当前勇士);damage:是否绘制显伤;flags:当前的flags(存读档时使用) // toDraw为要绘制到的信息(可为null,或为一个画布名),包括: -// ctx:要绘制到的画布(名);x,y:起点横纵坐标;size:大小;all:是否绘制全图;centerX,centerY:截取中心 +// ctx:要绘制到的画布(名);x,y:起点横纵坐标(默认0);size:大小(默认416/480); +// all:是否绘制全图(默认false);centerX,centerY:截取中心(默认为地图正中心) maps.prototype.drawThumbnail = function (floorId, blocks, options, toDraw) { floorId = floorId || core.status.floorId; if (!core.isset(floorId)) return; @@ -945,7 +947,7 @@ maps.prototype._drawThumbnail_realDrawTempCanvas = function (floorId, blocks, op this.drawEvents(floorId, blocks, tempCanvas); // 缩略图:勇士 if (options.heroLoc) { - options.heroIcon = options.heroIcon || "hero.png"; + options.heroIcon = options.heroIcon || core.getFlag("heroIcon", "hero.png"); var icon = core.material.icons.hero[options.heroLoc.direction]; var height = core.material.images.images[options.heroIcon].height/4; tempCanvas.drawImage(core.material.images.images[options.heroIcon], icon.stop * 32, icon.loc * height, 32, height, diff --git a/libs/ui.js b/libs/ui.js index 0ea67f59..d7a6f361 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -1602,7 +1602,8 @@ ui.prototype.drawFly = function(page) { core.fillText('ui', '▼', 356, 247 + 96 + 7, '#FFFFFF', "17px "+globalFont); } core.strokeRect('ui', 20, 100, 273, 273, '#FFFFFF', 2); - this.drawThumbnail(floorId, 'ui', core.status.maps[floorId].blocks, 20, 100, 273); + + core.drawThumbnail(floorId, null, null, {ctx: 'ui', x: 20, y: 100, size: 273}); } ////// 绘制浏览地图界面 ////// @@ -1681,7 +1682,7 @@ ui.prototype.drawMaps = function (index, x, y) { clearTimeout(core.interval.tipAnimate); core.clearLastEvent(); core.status.checkBlock.cache = {}; - this.drawThumbnail(floorId, 'ui', core.status.maps[floorId].blocks, 0, 0, 416, x, y); + core.drawThumbnail(floorId, null, {damage: damage}, {ctx: 'ui', centerX: x, centerY: y, all: all}); // 绘图 if (core.status.event.data.paint) { @@ -2088,7 +2089,11 @@ ui.prototype.drawSLPanel = function(index, refresh) { core.fillText('ui', i==0?"自动存档":name+id, (2*i+1)*u, 30, '#FFFFFF', "bold 17px "+globalFont); core.strokeRect('ui', (2*i+1)*u-size/2, 45, size, size, i==offset?strokeColor:'#FFFFFF', i==offset?6:2); if (core.isset(data) && core.isset(data.floorId)) { - core.ui.drawThumbnail(data.floorId, 'ui', core.maps.loadMap(data.maps, data.floorId).blocks, (2*i+1)*u-size/2, 45, size, data.hero.loc.x, data.hero.loc.y, data.hero.loc, data.hero.flags.heroIcon||"hero.png"); + core.drawThumbnail(data.floorId, core.maps.loadMap(data.maps, data.floorId).blocks, { + heroLoc: data.hero.loc, heroIcon: data.hero.flags.heroIcon, flags: data.hero.flags + }, { + ctx: 'ui', x: (2*i+1)*u-size/2, y: 45, size: size, centerX: data.hero.loc.x, centerY: data.hero.loc.y + }); var v = core.formatBigNumber(data.hero.hp,true)+"/"+core.formatBigNumber(data.hero.atk,true)+"/"+core.formatBigNumber(data.hero.def,true); var v2 = "/"+core.formatBigNumber(data.hero.mdef,true); if (v.length+v2.length<=21) v+=v2; @@ -2104,7 +2109,11 @@ ui.prototype.drawSLPanel = function(index, refresh) { core.fillText('ui', name+id, (2*i-5)*u, 218, '#FFFFFF', "bold 17px "+globalFont); core.strokeRect('ui', (2*i-5)*u-size/2, 233, size, size, i==offset?strokeColor:'#FFFFFF', i==offset?6:2); if (core.isset(data) && core.isset(data.floorId)) { - core.ui.drawThumbnail(data.floorId, 'ui', core.maps.loadMap(data.maps, data.floorId).blocks, (2*i-5)*u-size/2, 233, size, data.hero.loc.x, data.hero.loc.y, data.hero.loc, data.hero.flags.heroIcon||"hero.png"); + core.drawThumbnail(data.floorId, core.maps.loadMap(data.maps, data.floorId).blocks, { + heroLoc: data.hero.loc, heroIcon: data.hero.flags.heroIcon, flags: data.hero.flags + }, { + ctx: 'ui', x: (2*i-5)*u-size/2, y: 233, size: size, centerX: data.hero.loc.x, centerY: data.hero.loc.y + }); var v = core.formatBigNumber(data.hero.hp,true)+"/"+core.formatBigNumber(data.hero.atk,true)+"/"+core.formatBigNumber(data.hero.def,true); var v2 = "/"+core.formatBigNumber(data.hero.mdef,true); if (v.length+v2.length<=21) v+=v2; @@ -2157,12 +2166,6 @@ ui.prototype.drawSLPanel = function(index, refresh) { else drawAll(); } -////// 绘制一个缩略图 ////// -ui.prototype.drawThumbnail = function(floorId, canvas, blocks, x, y, size, centerX, centerY, heroLoc, heroIcon) { - core.drawThumbnail(floorId, blocks, {heroLoc: heroLoc, heroIcon: heroIcon}, - {ctx: canvas, x: x, y: y, size: size, centerX: centerX, centerY: centerY}); -} - ui.prototype.drawKeyBoard = function () { core.lockControl(); core.status.event.id = 'keyBoard'; diff --git a/project/functions.js b/project/functions.js index 63fd72ee..0b5234c1 100644 --- a/project/functions.js +++ b/project/functions.js @@ -191,7 +191,8 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 检查equipAnimate是否存在SE,如果不存在则使用默认音效 if (!core.isset((core.material.animates[equipAnimate] || {}).se)) core.playSound('attack.mp3'); - core.drawAnimate(equipAnimate, x, y); + // 强制战斗的战斗动画 + core.drawAnimate(equipAnimate, core.isset(x)?x:core.getHeroLoc('x'), core.isset(y)?y:core.getHeroLoc('y')); var damage = core.enemys.getDamage(enemyId, x, y); if (damage == null) damage = core.status.hero.hp + 1; @@ -1017,12 +1018,14 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 更新全地图显伤 core.updateDamage(); }, - "updateCheckBlock": function () { + "updateCheckBlock": function (floorId) { // 领域、夹击、阻击等的伤害值计算 + floorId = floorId || core.status.floorId; + if (!core.isset(floorId) || !core.isset(core.status.maps)) return; + var blocks = core.status.maps[floorId].blocks; + var width = core.floors[floorId].width, height = core.floors[floorId].height; core.status.checkBlock = {}; - if (!core.isset(core.status.thisMap)) return; - var blocks = core.status.thisMap.blocks; // Step1: 更新怪物地图 core.status.checkBlock.map = []; // 记录怪物地图 @@ -1032,29 +1035,29 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = var id = block.event.id, enemy = core.material.enemys[id]; if (core.isset(enemy)) { - core.status.checkBlock.map[block.x + core.bigmap.width * block.y] = id; + core.status.checkBlock.map[block.x + width * block.y] = id; } } // 血网 if (core.isset(block.event) && !block.disable && block.event.id == 'lavaNet' && block.event.trigger == 'passNet' && !core.hasItem("shoes")) { - core.status.checkBlock.map[block.x + core.bigmap.width * block.y] = "lavaNet"; + core.status.checkBlock.map[block.x + width * block.y] = "lavaNet"; } } // Step2: 更新领域、阻击伤害 - core.status.checkBlock.damage = []; // 记录(x,y)点的伤害;(x,y)对应的值是 x+core.bigmap.width*y - for (var x = 0; x < core.bigmap.width * core.bigmap.height; x++) core.status.checkBlock.damage[x] = 0; + core.status.checkBlock.damage = []; // 记录(x,y)点的伤害;(x,y)对应的值是 x+width*y + for (var x = 0; x < width * height; x++) core.status.checkBlock.damage[x] = 0; core.status.checkBlock.ambush = []; - for (var x = 0; x < core.bigmap.width; x++) { - for (var y = 0; y < core.bigmap.height; y++) { - var id = core.status.checkBlock.map[x + core.bigmap.width * y]; + for (var x = 0; x < width; x++) { + for (var y = 0; y < height; y++) { + var id = core.status.checkBlock.map[x + width * y]; if (core.isset(id)) { // 如果是血网,直接加上伤害值 if (id == "lavaNet") { - core.status.checkBlock.damage[x + core.bigmap.width * y] += core.values.lavaDamage || 0; + core.status.checkBlock.damage[x + width * y] += core.values.lavaDamage || 0; continue; } @@ -1073,10 +1076,10 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = if (dx == 0 && dy == 0) continue; var nx = x + dx, ny = y + dy; - if (nx < 0 || nx >= core.bigmap.width || ny < 0 || ny >= core.bigmap.height) continue; + if (nx < 0 || nx >= width || ny < 0 || ny >= height) continue; // 如果是十字领域,则还需要满足 |dx|+|dy|<=range if (!zoneSquare && Math.abs(dx) + Math.abs(dy) > range) continue; - core.status.checkBlock.damage[nx + ny * core.bigmap.width] += enemy.value || 0; + core.status.checkBlock.damage[nx + ny * width] += enemy.value || 0; } } } @@ -1084,11 +1087,11 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 如果要防止激光伤害,可以直接简单的将 flag:no_laser 设为true if (core.enemys.hasSpecial(enemy.special, 24) && !core.hasFlag("no_laser")) { // 检查同行和同列,增加激光伤害值 - for (var nx = 0; nx < core.bigmap.width; nx++) { - if (nx != x) core.status.checkBlock.damage[nx + y * core.bigmap.width] += enemy.value || 0; + for (var nx = 0; nx < width; nx++) { + if (nx != x) core.status.checkBlock.damage[nx + y * width] += enemy.value || 0; } - for (var ny = 0; ny < core.bigmap.height; ny++) { - if (ny != y) core.status.checkBlock.damage[x + ny * core.bigmap.width] += enemy.value || 0; + for (var ny = 0; ny < height; ny++) { + if (ny != y) core.status.checkBlock.damage[x + ny * width] += enemy.value || 0; } } // 存在阻击 @@ -1099,8 +1102,8 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = if (dx == 0 && dy == 0) continue; var nx = x + dx, ny = y + dy; - if (nx < 0 || nx >= core.bigmap.width || ny < 0 || ny >= core.bigmap.height || Math.abs(dx) + Math.abs(dy) > 1) continue; - core.status.checkBlock.damage[nx + ny * core.bigmap.width] += enemy.value || 0; + if (nx < 0 || nx >= width || ny < 0 || ny >= height || Math.abs(dx) + Math.abs(dy) > 1) continue; + core.status.checkBlock.damage[nx + ny * width] += enemy.value || 0; } } } @@ -1110,10 +1113,10 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = for (var dir in core.utils.scan) { var nx = x + core.utils.scan[dir].x, ny = y + core.utils.scan[dir].y; - if (nx < 0 || nx >= core.bigmap.width || ny < 0 || ny >= core.bigmap.height) continue; - if (!core.isset(core.status.checkBlock.ambush[nx + ny * core.bigmap.width])) - core.status.checkBlock.ambush[nx + ny * core.bigmap.width] = []; - core.status.checkBlock.ambush[nx + ny * core.bigmap.width].push([x, y, id, dir]); + if (nx < 0 || nx >= width || ny < 0 || ny >= height) continue; + if (!core.isset(core.status.checkBlock.ambush[nx + ny * width])) + core.status.checkBlock.ambush[nx + ny * width] = []; + core.status.checkBlock.ambush[nx + ny * width].push([x, y, id, dir]); } } } @@ -1124,14 +1127,14 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = core.status.checkBlock.betweenAttack = []; // 记录(x,y)点是否有夹击 // 如果要防止夹击伤害,可以简单的将 flag:no_betweenAttack 设为true if (!core.hasFlag('no_betweenAttack')) { - for (var x = 0; x < core.bigmap.width; x++) { - for (var y = 0; y < core.bigmap.height; y++) { + for (var x = 0; x < width; x++) { + for (var y = 0; y < height; y++) { // 该点是否存在夹击 var has = false; // 检测左右是否存在相同的怪物,且拥有夹击属性 - if (x > 0 && x < core.bigmap.width - 1) { - var id1 = core.status.checkBlock.map[x - 1 + core.bigmap.width * y], - id2 = core.status.checkBlock.map[x + 1 + core.bigmap.width * y]; + if (x > 0 && x < width - 1) { + var id1 = core.status.checkBlock.map[x - 1 +width * y], + id2 = core.status.checkBlock.map[x + 1 + width * y]; if (core.isset(id1) && core.isset(id2) && id1 == id2) { var enemy = core.material.enemys[id1]; if (core.isset(enemy) && core.enemys.hasSpecial(enemy.special, 16)) { @@ -1140,9 +1143,9 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = } } // 检测上下是否存在相同的怪物,且拥有夹击属性 - if (y > 0 && y < core.bigmap.height - 1) { - var id1 = core.status.checkBlock.map[x + core.bigmap.width * (y - 1)], - id2 = core.status.checkBlock.map[x + core.bigmap.width * (y + 1)]; + if (y > 0 && y < height - 1) { + var id1 = core.status.checkBlock.map[x + width * (y - 1)], + id2 = core.status.checkBlock.map[x + width * (y + 1)]; if (core.isset(id1) && core.isset(id2) && id1 == id2) { var enemy = core.material.enemys[id1]; if (core.isset(enemy) && core.enemys.hasSpecial(enemy.special, 16)) { @@ -1152,12 +1155,12 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = } // 计算夹击伤害 if (has) { - core.status.checkBlock.betweenAttack[x + core.bigmap.width * y] = true; + core.status.checkBlock.betweenAttack[x + width * y] = true; // 先扣除该点领域/阻击/激光造成的伤害,再算夹击 - var leftHp = core.status.hero.hp - core.status.checkBlock.damage[x + core.bigmap.width * y]; + var leftHp = core.status.hero.hp - core.status.checkBlock.damage[x + width * y]; // 1血不夹;core.flags.betweenAttackCeil控制向上还是向下 if (leftHp > 1) - core.status.checkBlock.damage[x + core.bigmap.width * y] += Math.floor((leftHp + (core.flags.betweenAttackCeil ? 0 : 1)) / 2); + core.status.checkBlock.damage[x + width * y] += Math.floor((leftHp + (core.flags.betweenAttackCeil ? 0 : 1)) / 2); } } }