左右转,楼层切换,事件转向

This commit is contained in:
ckcz123 2020-05-14 19:13:52 +08:00
parent 2a15b29f36
commit a749cb302f
8 changed files with 129 additions and 28 deletions

View File

@ -283,6 +283,7 @@ if (Floor_List_0!='floorId') toFloorId = Floor_List_0;
var loc = ', "loc": ['+Number_0+', '+Number_1+']';
if (Stair_List_0===':now') loc = '';
else if (Stair_List_0!=='loc')loc = ', "stair": "'+Stair_List_0+'"';
if (DirectionEx_List_0 == 'null') DirectionEx_List_0 = '';
DirectionEx_List_0 = DirectionEx_List_0 && (', "direction": "'+DirectionEx_List_0+'"');
IntString_0 = IntString_0 ?(', "time": '+IntString_0):'';
if (IgnoreChangeFloor_List_0!='null') {
@ -341,6 +342,7 @@ action
| insert_2_s
| exit_s
| setBlock_s
| turnBlock_s
| showFloorImg_s
| hideFloorImg_s
| showBgFgMap_s
@ -825,6 +827,39 @@ var code = '{"type": "setBlock", "number": "'+EvalString_0+'"'+floorstr+IdString
return code;
*/;
turnBlock_s
: '事件转向' DirectionEx_List 'x' EvalString? ',' 'y' EvalString? '楼层' IdString? Newline
/* turnBlock_s
tooltip : turnBlock事件转向自动检索faceIds
helpUrl : https://h5mota.com/games/template/_docs/#/event?id=setblock%EF%BC%9A%E8%AE%BE%E7%BD%AE%E6%9F%90%E4%B8%AA%E5%9B%BE%E5%9D%97
colour : this.mapColor
default : [null,"","",""]
var floorstr = '';
if (EvalString_0 && EvalString_1) {
var pattern1 = MotaActionFunctions.pattern.id;
if(pattern1.test(EvalString_0) || pattern1.test(EvalString_1)){
EvalString_0=MotaActionFunctions.PosString_pre(EvalString_0);
EvalString_1=MotaActionFunctions.PosString_pre(EvalString_1);
EvalString_0=[EvalString_0,EvalString_1]
} else {
var pattern2 = /^([+-]?\d+)(,[+-]?\d+)*$/;
if(!pattern2.test(EvalString_0) || !pattern2.test(EvalString_1))throw new Error('坐标格式错误,请右键点击帮助查看格式');
EvalString_0=EvalString_0.split(',');
EvalString_1=EvalString_1.split(',');
if(EvalString_0.length!==EvalString_1.length)throw new Error('坐标格式错误,请右键点击帮助查看格式');
for(var ii=0;ii<EvalString_0.length;ii++)EvalString_0[ii]='['+EvalString_0[ii]+','+EvalString_1[ii]+']';
}
floorstr = ', "loc": ['+EvalString_0.join(',')+']';
}
if (DirectionEx_List_0 == 'null') DirectionEx_List_0 = '';
DirectionEx_List_0 = DirectionEx_List_0 && (', "direction": "'+DirectionEx_List_0+'"');
IdString_0 = IdString_0 && (', "floorId": "'+IdString_0+'"');
var code = '{"type": "turnBlock"'+DirectionEx_List_0+floorstr+IdString_0+'},\n';
return code;
*/;
showFloorImg_s
: '显示贴图' 'x' EvalString? ',' 'y' EvalString? '楼层' IdString? Newline
@ -1143,21 +1178,24 @@ return code;
*/;
changeFloor_s
: '楼层切换' IdString? 'x' PosString? ',' 'y' PosString? '朝向' DirectionEx_List '动画时间' IntString? Newline
: '楼层切换' Floor_List IdString? Stair_List 'x' Number ',' 'y' Number '朝向' DirectionEx_List '动画时间' IntString? Newline
/* changeFloor_s
tooltip : changeFloor: 楼层切换,动画时间可不填
helpUrl : https://h5mota.com/games/template/_docs/#/event?id=changefloor%EF%BC%9A%E6%A5%BC%E5%B1%82%E5%88%87%E6%8D%A2
default : ["MTx","0","0",null,""]
default : [null,"",null,"","",null,"",null]
colour : this.dataColor
var toFloorId = IdString_0;
if (Floor_List_0!='floorId') toFloorId = Floor_List_0;
toFloorId = toFloorId ? (', "floorId": ' + toFloorId) : '';
var loc = ', "loc": ['+Number_0+', '+Number_1+']';
if (Stair_List_0===':now') loc = '';
else if (Stair_List_0!=='loc')loc = ', "stair": "'+Stair_List_0+'"';
if (DirectionEx_List_0 == 'null') DirectionEx_List_0 = '';
DirectionEx_List_0 = DirectionEx_List_0 && (', "direction": "'+DirectionEx_List_0+'"');
IntString_0 = IntString_0 ?(', "time": '+IntString_0):'';
var floorstr = '';
if (PosString_0 && PosString_1) {
floorstr = ', "loc": ['+PosString_0+','+PosString_1+']';
}
var code = '{"type": "changeFloor", "floorId": "'+IdString_0+'"'+floorstr+DirectionEx_List_0+IntString_0+' },\n';
IntString_0 = IntString_0 ?(', "time": '+IntString_0):'';
var code = '{"type": "changeFloor"'+toFloorId+loc+DirectionEx_List_0+IntString_0+' }\n';
return code;
*/;
@ -1171,6 +1209,7 @@ helpUrl : https://h5mota.com/games/template/_docs/#/event?id=changepos%EF%BC%9A%
default : ["","",null]
colour : this.dataColor
var loc = (PosString_0 && PosString_1) ? (', "loc": ['+PosString_0+','+PosString_1+']') : '';
if (DirectionEx_List_0 == 'null') DirectionEx_List_0 = '';
DirectionEx_List_0 = DirectionEx_List_0 && (', "direction": "'+DirectionEx_List_0+'"');
var code = '{"type": "changePos"'+loc+DirectionEx_List_0+'},\n';
return code;
@ -2654,8 +2693,8 @@ FontString
;
Floor_List
: '楼层ID'|'前一楼'|'后一楼'
/*Floor_List ['floorId',':before',':next']*/;
: '楼层ID'|'前一楼'|'后一楼'|'当前楼'
/*Floor_List ['floorId',':before',':next',':now']*/;
Stair_List
: '坐标'|'上楼梯'|'下楼梯'|'保持不变'|'中心对称点'|'x对称点'|'y对称点'
@ -2757,8 +2796,8 @@ Direction_List
/*Direction_List ['up','down','left','right']*/;
DirectionEx_List
: '不变'|'上'|'下'|'左'|'右'
/*DirectionEx_List ['','up','down','left','right']*/;
: '不变'|'上'|'下'|'左'|'右'|'左转'|'右转'|'背对'
/*DirectionEx_List ['null','up','down','left','right',':left',':right',':back']*/;
StepString
: (Direction_List Int?)+
@ -2875,7 +2914,7 @@ ActionParser.prototype.parse = function (obj,type) {
obj.loc=[0,0];
if (!this.isset(obj.stair)) obj.stair=':now';
}
if (obj.floorId==':before'||obj.floorId==':next') {
if (obj.floorId==':before'||obj.floorId==':next'||obj.floorId==':now') {
obj.floorType=obj.floorId;
delete obj.floorId;
}
@ -3066,6 +3105,18 @@ ActionParser.prototype.parseAction = function() {
this.next = MotaActionBlocks['setBlock_s'].xmlText([
data.number||0,x_str.join(','),y_str.join(','),data.floorId||'',this.next]);
break;
case "turnBlock": // 事件转向
data.loc=data.loc||[];
if (!(data.loc[0] instanceof Array))
data.loc = [data.loc];
var x_str=[],y_str=[];
data.loc.forEach(function (t) {
x_str.push(t[0]);
y_str.push(t[1]);
})
this.next = MotaActionBlocks['turnBlock_s'].xmlText([
data.direction,x_str.join(','),y_str.join(','),data.floorId||'',this.next]);
break;
case "showFloorImg": // 显示贴图
data.loc=data.loc||[];
if (!(data.loc[0] instanceof Array))
@ -3151,9 +3202,17 @@ ActionParser.prototype.parseAction = function() {
data.loc[0],data.loc[1],data.time,data.async||false,this.next]);
break;
case "changeFloor": // 楼层转换
data.loc=data.loc||['','']
this.next = MotaActionBlocks['changeFloor_s'].xmlText([
data.floorId,data.loc[0],data.loc[1],data.direction,data.time,this.next]);
if (!data.loc) {
data.loc = data.loc || ['',''];
data.stair = data.stair || ':now';
}
if (data.floorId==':before'||data.floorId==':next'||data.floorId==':now') {
data.floorType=data.floorId;
delete data.floorId;
}
return MotaActionBlocks['changeFloor_s'].xmlText([
data.floorType||'floorId',data.floorId,data.stair||'loc',data.loc[0],data.loc[1],obj.direction,
data.time, this.next]);
break;
case "changePos": // 直接更换勇士位置, 不切换楼层
data.loc=data.loc||['','']

View File

@ -128,6 +128,7 @@ editor_blockly = function () {
MotaActionBlocks['show_s'].xmlText(),
MotaActionBlocks['hide_s'].xmlText(),
MotaActionBlocks['setBlock_s'].xmlText(),
MotaActionBlocks['turnBlock_s'].xmlText(),
MotaActionBlocks['move_s'].xmlText(),
MotaActionBlocks['jump_s'].xmlText(),
MotaActionBlocks['showBgFgMap_s'].xmlText(),
@ -826,7 +827,7 @@ function omitedcheckUpdateFunction(event) {
var selectPointBlocks = {
"changeFloor_m": ["Number_0", "Number_1", "IdString_0", true],
"jumpHero_s": ["PosString_0", "PosString_1"],
"changeFloor_s": ["PosString_0", "PosString_1", "IdString_0", true],
"changeFloor_s": ["Number_0", "Number_1", "IdString_0", true],
"changePos_s": ["PosString_0", "PosString_1"],
"battle_1_s": ["PosString_0", "PosString_1"],
"openDoor_s": ["PosString_0", "PosString_1", "IdString_0"],
@ -874,7 +875,7 @@ function omitedcheckUpdateFunction(event) {
block.setFieldValue(xv+"", arr[0]);
block.setFieldValue(yv+"", arr[1]);
}
if (block.type == 'changeFloor_m') {
if (block.type == 'changeFloor_m' || block.type == 'changeFloor_s') {
block.setFieldValue("floorId", "Floor_List_0");
block.setFieldValue("loc", "Stair_List_0");
}
@ -988,6 +989,7 @@ function omitedcheckUpdateFunction(event) {
var allBgms = Object.keys(core.material.bgms);
var allSounds = Object.keys(core.material.sounds);
var allShops = Object.keys(core.status.shops);
var allFloorIds = core.floorIds;
var allColors = ["aqua青色", "black黑色", "blue蓝色", "fuchsia品红色", "gray灰色", "green深绿色", "lime绿色",
"maroon深红色", "navy深蓝色", "gold金色", "olive黄褐色", "orange橙色", "purple品红色",
"red红色", "silver淡灰色", "teal深青色", "white白色", "yellow黄色"];
@ -1042,6 +1044,14 @@ function omitedcheckUpdateFunction(event) {
return filter(allShops, content);
}
// 对楼层名进行补全
if ((type == 'setFloor_s' || type == 'show_s' || type == 'hide_s' || type == 'insert_2_s'
|| type == 'setBlock_s' || type == 'turnBlock_s' || type == 'showFloorImg_s' || type == 'hideFloorImg_s'
|| type == 'showBgFgMap_s' || type == 'hideBgFgMap_s' || type == 'setBgFgBlock_s'
|| type == 'openDoor_s' || type == 'changeFloor_m') && name == "IdString_0") {
return filter(allFloorIds, content);
}
// 对\f进行自动补全
index = Math.max(content.lastIndexOf("\f["), content.lastIndexOf("\\f["));
if (index >= 0) {

View File

@ -756,8 +756,7 @@ control.prototype.turnHero = function(direction) {
core.status.route.push("turn:"+direction);
return;
}
var dirs = {'up':'right','right':'down','down':'left','left':'up'};
core.setHeroLoc('direction', dirs[core.getHeroLoc('direction')]);
core.setHeroLoc('direction', core.turnDirection(':right'));
core.drawHero();
core.status.route.push("turn");
}

View File

@ -599,6 +599,8 @@ events.prototype._changeFloor_getInfo = function (floorId, stair, heroLoc, time)
var index = core.floorIds.indexOf(core.status.floorId);
if (index < core.floorIds.length - 1) floorId = core.floorIds[index + 1];
else floorId = core.status.floorId;
} else if (floorId == ':now') {
floorId = core.status.floorId;
}
if (!core.status.maps[floorId]) {
main.log("不存在的楼层:" + floorId);
@ -780,7 +782,7 @@ events.prototype._sys_action = function (data, callback) {
var ev = core.clone(data.event.data), ex = data.x, ey = data.y;
// 检查是否需要改变朝向
if (ex == core.nextX() && ey == core.nextY()) {
var dir = core.reverseDirection();
var dir = core.turnDirection(":back");
var id = data.event.id, toId = (data.event.faceIds || {})[dir];
if (toId && id != toId) {
var number = core.getNumberById(toId);
@ -1363,7 +1365,7 @@ events.prototype._action_changeFloor = function (data, x, y, prefix) {
events.prototype._action_changePos = function (data, x, y, prefix) {
core.clearMap('hero');
if (data.x == null && data.y == null && data.direction) {
core.setHeroLoc('direction', data.direction, true);
core.setHeroLoc('direction', core.turnDirection(data.direction), true);
core.drawHero();
return core.doAction();
}
@ -1371,7 +1373,7 @@ events.prototype._action_changePos = function (data, x, y, prefix) {
var loc = this.__action_getHeroLoc(data.loc, prefix);
core.setHeroLoc('x', loc[0]);
core.setHeroLoc('y', loc[1]);
if (data.direction) core.setHeroLoc('direction', data.direction);
if (data.direction) core.setHeroLoc('direction', core.turnDirection(data.direction));
core.drawHero();
core.doAction();
}

View File

@ -516,7 +516,7 @@ maps.prototype._canMoveHero_checkCannotInOut = function (number, name, direction
}
return false;
}
if (name == 'cannotIn') direction = core.reverseDirection(direction);
if (name == 'cannotIn') direction = core.turnDirection(":back", direction);
return core.inArray((this.getBlockByNumber(number).event || {})[name], direction);
}
@ -1642,6 +1642,26 @@ maps.prototype.setBlock = function (number, x, y, floorId) {
}
}
////// 事件转向 //////
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 currDirection = null;
for (var dir in core.utils.scan) {
if (faceIds[dir] == id) {
currDirection = dir;
}
}
if (currDirection == null) return;
var nextDirection = core.turnDirection(direction, currDirection);
var nextId = faceIds[nextDirection];
if (nextId != null && nextId != id) {
this.setBlock(nextId, x, y, floorId);
}
}
////// 将地图中所有某个图块替换成另一个图块 //////
maps.prototype.replaceBlock = function (fromNumber, toNumber, floorId) {
floorId = floorId || core.status.floorId;

View File

@ -691,9 +691,19 @@ utils.prototype.strlen = function (str) {
return count;
};
utils.prototype.reverseDirection = function (direction) {
utils.prototype.turnDirection = function (turn, direction) {
direction = direction || core.getHeroLoc('direction');
return {"left":"right","right":"left","down":"up","up":"down"}[direction] || direction;
var directionList = ["left", "up", "right", "down"];
if (directionList.indexOf(turn) >= 0) return turn;
switch (turn) {
case ':left': turn = 3; break; // turn left
case ':right': turn = 1; break; // turn right
case ':back': turn = 2; break; // turn back
default: turn = 0; break;
}
var index = directionList.indexOf(direction);
if (index < 0) return direction;
return directionList[(index + (turn || 0)) % 4];
}
utils.prototype.matchWildcard = function (pattern, string) {

View File

@ -111,6 +111,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
// 重置画布尺寸
core.maps.resizeMap(floorId);
// 设置勇士的位置
heroLoc.direction = core.turnDirection(heroLoc.direction);
core.status.hero.loc = heroLoc;
// 检查重生怪并重置
if (!fromLoad) {
@ -1107,7 +1108,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
type[currloc] = type[currloc] || {};
type[currloc]["阻击伤害"] = true;
var rdir = core.reverseDirection(dir);
var rdir = core.turnDirection(":back", dir);
// 检查下一个点是否存在事件(从而判定是否移动)
var rnx = x + core.utils.scan[rdir].x,
rny = y + core.utils.scan[rdir].y;

View File

@ -33,7 +33,7 @@
(已完成!) 图块ID不可全数字
怪物详细信息富文本化
(已完成!) for和forEach事件
转向:顺时针/逆时针/反向
(已完成!) 转向:顺时针/逆时针/反向
事件转向
(已完成!) 合并数值操作事件
(已完成!) fromLoad聚集问题