拆分core.removeBlock隐藏和删除问题

This commit is contained in:
ckcz123 2020-05-14 21:11:20 +08:00
parent a749cb302f
commit b4c6e2e90a
6 changed files with 71 additions and 52 deletions

View File

@ -698,13 +698,13 @@ return code;
*/;
hide_s
: '隐藏事件' 'x' EvalString? ',' 'y' EvalString? '楼层' IdString? '动画时间' IntString? '不等待执行完毕' Bool? Newline
: '隐藏事件' 'x' EvalString? ',' 'y' EvalString? '楼层' IdString? '同时删除' Bool '动画时间' IntString? '不等待执行完毕' Bool? Newline
/* hide_s
tooltip : hide: 将一个启用事件禁用,所有参数均可不填,代表禁用事件自身,xy可用逗号分隔表示多个点
tooltip : hide: 隐藏事件,同时可删除
helpUrl : https://h5mota.com/games/template/_docs/#/event?id=hide%EF%BC%9A%E5%B0%86%E4%B8%80%E4%B8%AA%E5%90%AF%E7%94%A8%E4%BA%8B%E4%BB%B6%E7%A6%81%E7%94%A8
default : ["","","","",false]
default : ["","","",true,"",false]
colour : this.mapColor
var floorstr = '';
if (EvalString_0 && EvalString_1) {
@ -725,8 +725,9 @@ if (EvalString_0 && EvalString_1) {
}
IdString_0 = IdString_0 && (', "floorId": "'+IdString_0+'"');
IntString_0 = IntString_0 ?(', "time": '+IntString_0):'';
Bool_0 = Bool_0 ?', "async": true':'';
var code = '{"type": "hide"'+floorstr+IdString_0+''+IntString_0+Bool_0+'},\n';
Bool_0 = Bool_0 ?', "remove": true':'';
Bool_1 = Bool_1 ?', "async": true':'';
var code = '{"type": "hide"'+floorstr+IdString_0+Bool_0+IntString_0+Bool_1+'},\n';
return code;
*/;
@ -3091,7 +3092,7 @@ ActionParser.prototype.parseAction = function() {
y_str.push(t[1]);
})
this.next = MotaActionBlocks['hide_s'].xmlText([
x_str.join(','),y_str.join(','),data.floorId||'',data.time,data.async||false,this.next]);
x_str.join(','),y_str.join(','),data.floorId||'',data.remove||false,data.time,data.async||false,this.next]);
break;
case "setBlock": // 设置图块
data.loc=data.loc||[];

View File

@ -835,6 +835,7 @@ function omitedcheckUpdateFunction(event) {
"show_s": ["EvalString_0", "EvalString_1", "IdString_0"],
"hide_s": ["EvalString_0", "EvalString_1", "IdString_0"],
"setBlock_s": ["EvalString_1", "EvalString_2", "IdString_0"],
"turnBlock_s": ["EvalString_1", "EvalString_2", "IdString_0"],
"move_s": ["PosString_0", "PosString_1"],
"jump_s": ["PosString_2", "PosString_3"], // 跳跃暂时只考虑终点
"showBgFgMap_s": ["EvalString_0", "EvalString_1", "IdString_0"],

View File

@ -1251,14 +1251,12 @@ events.prototype._action_show = function (data, x, y, prefix) {
events.prototype._action_hide = function (data, x, y, prefix) {
data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
if (data.time > 0 && data.floorId == core.status.floorId) {
data.loc.forEach(function (t) {
core.hideBlock(t[0], t[1], data.floorId);
});
this.__action_doAsyncFunc(data.async, core.animateBlock, data.loc, 'hide', data.time);
this.__action_doAsyncFunc(data.async, core.animateBlock, data.loc, data.remove ? 'remove' : 'hide', data.time);
}
else {
data.loc.forEach(function (t) {
core.removeBlock(t[0], t[1], data.floorId)
if (data.remove) core.removeBlock(t[0], t[1], data.floorId);
else core.hideBlock(t[0], t[1], data.floorId);
});
core.doAction();
}
@ -1272,6 +1270,14 @@ events.prototype._action_setBlock = function (data, x, y, prefix) {
core.doAction();
}
events.prototype._action_turnBlock = function (data, x, y, prefix) {
data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
data.loc.forEach(function (t) {
core.turnBlock(data.number, t[0], t[1], data.floorId);
});
core.doAction();
}
events.prototype._action_showFloorImg = function (data, x, y, prefix) {
core.maps.showFloorImage(this.__action_getLoc2D(data.loc, x, y, prefix), data.floorId, core.doAction);
}

View File

@ -1464,11 +1464,29 @@ maps.prototype.hideBlock = function (x, y, floorId) {
core.clearMap('event2', x * 32, y * 32 + 32 - height, 32, height - 32);
}
block.block.disable = true;
core.hideBlockByIndex(block.index, floorId);
core.updateStatusBar();
}
////// 将某个块从启用变成禁用状态 //////
////// 根据图块的索引来隐藏图块 //////
maps.prototype.hideBlockByIndex = function (index, floorId) {
floorId = floorId || core.status.floorId;
if (!floorId) return;
var blocks = core.status.maps[floorId].blocks, block = blocks[index];
block.disable = true;
}
////// 一次性隐藏多个block //////
maps.prototype.hideBlockByIndexes = function (indexes, floorId) {
indexes.sort(function (a, b) {
return b - a;
}).forEach(function (index) {
core.hideBlockByIndex(index, floorId);
});
}
////// 删除某个图块 //////
maps.prototype.removeBlock = function (x, y, floorId) {
floorId = floorId || core.status.floorId;
if (!floorId) return false;
@ -1476,8 +1494,6 @@ maps.prototype.removeBlock = function (x, y, floorId) {
var block = core.getBlock(x, y, floorId, true);
if (block == null) return false; // 不存在
var index = block.index;
// 删除动画,清除地图
if (floorId == core.status.floorId) {
core.removeGlobalAnimate(x, y);
@ -1487,8 +1503,7 @@ maps.prototype.removeBlock = function (x, y, floorId) {
core.clearMap('event2', x * 32, y * 32 + 32 - height, 32, height - 32);
}
// 删除Index
core.removeBlockByIndex(index, floorId);
core.removeBlockByIndex(block.index, floorId);
core.updateStatusBar();
return true;
}
@ -1499,13 +1514,7 @@ maps.prototype.removeBlockByIndex = function (index, floorId) {
if (!floorId) return;
var blocks = core.status.maps[floorId].blocks, block = blocks[index];
if (this.canRemoveBlock(block, floorId)) { // 能否彻底删除该图块
blocks.splice(index, 1);
}
else {
block.disable = true;
}
blocks.splice(index, 1);
}
////// 一次性删除多个block //////
@ -1517,19 +1526,6 @@ maps.prototype.removeBlockByIndexes = function (indexes, floorId) {
});
}
////// 能否彻底从地图中删除一个图块 //////
maps.prototype.canRemoveBlock = function (block, floorId) {
var x = block.x, y = block.y;
// 检查该点是否存在事件
if (core.floors[floorId].events[x + "," + y] || core.floors[floorId].changeFloor[x + "," + y])
return false;
// 检查是否存在重生
if (block.event && block.event.cls.indexOf('enemy') == 0 && core.hasSpecial(block.event.id, 23))
return false;
return true;
}
////// 显示前景/背景地图 //////
maps.prototype.showBgFgMap = function (name, loc, floorId, callback) {
this._triggerBgFgMap('show', name, loc, floorId, callback);
@ -1612,7 +1608,7 @@ maps.prototype.setBlock = function (number, x, y, floorId) {
var block = this.initBlock(x, y, number, true, core.floors[floorId]);
if (block.id == 0 && !block.event.trigger) {
// 转变图块为0且该点无事件视为隐藏
// 转变图块为0且该点无事件视为删除
core.removeBlock(x, y, floorId);
return;
}
@ -1647,7 +1643,7 @@ maps.prototype.turnBlock = function (direction, x, y, floorId) {
var id = core.getBlockId(x, y, floorId, true);
var blockInfo = core.getBlockInfo(id);
if (blockInfo == null) return;
var faceIds = blockInfo.faceIds;
var faceIds = blockInfo.faceIds || {};
var currDirection = null;
for (var dir in core.utils.scan) {
if (faceIds[dir] == id) {
@ -1962,24 +1958,23 @@ maps.prototype._moveJumpBlock_finished = function (blockInfo, canvases, info, an
////// 显示/隐藏某个块时的动画效果 //////
maps.prototype.animateBlock = function (loc, type, time, callback) {
if (core.status.replay.speed == 24) time = 1;
var isHide = type == 'hide';
if (typeof loc[0] == 'number' && typeof loc[1] == 'number')
loc = [loc];
// --- 检测所有是0的点
var list = this._animateBlock_getList(loc);
var list = this._animateBlock_getList(loc, type);
if (list.length == 0) {
if (callback) callback();
return;
}
this._animateBlock_drawList(list, isHide ? 1 : 0);
this._animateBlock_drawList(list, type != 'show' ? 1 : 0);
time /= Math.max(core.status.replay.speed, 1)
this._animateBlock_doAnimate(loc, list, isHide, 10 / time, callback);
this._animateBlock_doAnimate(loc, list, type, 10 / time, callback);
}
maps.prototype._animateBlock_doAnimate = function (loc, list, isHide, delta, callback) {
var opacity = isHide ? 1 : 0;
maps.prototype._animateBlock_doAnimate = function (loc, list, type, delta, callback) {
var opacity = type != 'show' ? 1 : 0;
var animate = setInterval(function () {
opacity += isHide ? -delta : delta;
opacity += type != 'show' ? -delta : delta;
core.maps._animateBlock_drawList(list, opacity);
if (opacity >= 1 || opacity <= 0) {
delete core.animateFrame.asyncId[animate];
@ -1989,8 +1984,9 @@ maps.prototype._animateBlock_doAnimate = function (loc, list, isHide, delta, cal
core.maps._deleteDetachedBlock(t.canvases);
});
loc.forEach(function (t) {
if (isHide) core.removeBlock(t[0], t[1]);
else core.showBlock(t[0], t[1]);
if (type == 'show') core.showBlock(t[0], t[1]);
else if (type == 'hide') core.hideBlock(t[0], t[1]);
else if (type == 'remove') core.removeBlock(t[0], t[1]);
});
if (callback) callback();
}
@ -1999,7 +1995,7 @@ maps.prototype._animateBlock_doAnimate = function (loc, list, isHide, delta, cal
core.animateFrame.asyncId[animate] = true;
}
maps.prototype._animateBlock_getList = function (loc) {
maps.prototype._animateBlock_getList = function (loc, type) {
var list = [];
loc.forEach(function (t) {
var block = core.getBlock(t[0], t[1], null, true);
@ -2011,6 +2007,16 @@ maps.prototype._animateBlock_getList = function (loc) {
list.push({ 'x': t[0], 'y': t[1] });
return;
}
// 该点是否已经被启用/删除
if ((type == 'show' && !block.disable) || ((type == 'hide' || type == 'remove') && block.disable)) {
list.push({ 'x': t[0], 'y': t[1] });
return;
}
if (type == 'hide' || type == 'remove') {
core.hideBlock(t[0], t[1]); // 暂时先隐藏
}
var canvases = core.maps._initDetachedBlock(blockInfo, t[0], t[1], block.event.displayDamage !== false);
list.push({

View File

@ -1,4 +1,4 @@
var enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80 =
var enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80 =
{
"greenSlime": {"name":"绿头怪","hp":100,"atk":120,"def":0,"money":1,"exp":1,"point":0,"special":[1,5,7,8]},
"redSlime": {"name":"红头怪","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[16,18],"value":10},
@ -36,7 +36,7 @@ var enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80 =
"poisonSkeleton": {"name":"紫骷髅","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[]},
"poisonBat": {"name":"紫蝙蝠","hp":100,"atk":120,"def":0,"money":14,"exp":0,"point":0,"special":[13]},
"steelRock": {"name":"铁面人","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[]},
"skeletonPriest": {"name":"骷髅法师","hp":100,"atk":100,"def":0,"money":0,"exp":0,"point":0,"special":[18],"value":20},
"skeletonPriest": {"name":"骷髅法师","hp":100,"atk":100,"def":0,"money":0,"exp":0,"point":0,"special":[18,23],"value":20},
"skeletonKing": {"name":"骷髅王","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[]},
"skeletonWizard": {"name":"骷髅巫师","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[]},
"redSkeletonCaption": {"name":"骷髅武士","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[]},

View File

@ -273,7 +273,12 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
// 删除该块
var guards = []; // 支援
if (x != null && y != null) {
core.removeBlock(x, y);
// 检查是否是重生怪物;如果是则仅隐藏不删除
if (core.hasSpecial(enemy.special, 23)) {
core.hideBlock(x, y);
} else {
core.removeBlock(x, y);
}
guards = core.getFlag("__guards__" + x + "_" + y, []);
core.removeFlag("__guards__" + x + "_" + y);
}