autoEvent

This commit is contained in:
ckcz123 2019-10-20 19:01:17 +08:00
parent 0531487bc7
commit c0078aeb5f
16 changed files with 182 additions and 62 deletions

View File

@ -661,8 +661,9 @@ core.clearStatusBar()
清空状态栏的数据。 清空状态栏的数据。
core.updateStatusBar() core.updateStatusBar(doNotCheckAutoEvents)
更新状态栏,被转发到了脚本编辑中。此函数还会根据是否在回放来设置工具栏的图标。 更新状态栏,被转发到了脚本编辑中。此函数还会根据是否在回放来设置工具栏的图标。
如果doNotCheckAutoEvents为true则此时不检查自动事件。
core.showStatusBar() / core.hideStatusBar(showToolbox) core.showStatusBar() / core.hideStatusBar(showToolbox)

View File

@ -654,9 +654,9 @@ core.clearStatusBar()
清空状态栏的数据。 清空状态栏的数据。
core.updateStatusBar() core.updateStatusBar(doNotCheckAutoEvents)
更新状态栏,被转发到了脚本编辑中。此函数还会根据是否在回放来设置工具栏的图标。 更新状态栏,被转发到了脚本编辑中。此函数还会根据是否在回放来设置工具栏的图标。
如果doNotCheckAutoEvents为true则此时不检查自动事件。
core.showStatusBar() / core.hideStatusBar(showToolbox) core.showStatusBar() / core.hideStatusBar(showToolbox)
显示和隐藏状态栏。 显示和隐藏状态栏。

View File

@ -28,13 +28,13 @@ return code;
//自动事件 事件编辑器入口之一 //自动事件 事件编辑器入口之一
autoEvent_m autoEvent_m
: '自动事件' BGNL? Newline '触发条件' EvalString '优先级' Int BGNL? Newline '仅在本层检测' Bool '延迟执行' Bool '多次执行' Bool BGNL? Newline action+ BEND : '自动事件' '触发条件' EvalString '优先级' Int BGNL? Newline '仅在本层检测' Bool '事件流中延迟执行' Bool '允许多次执行' Bool BGNL? Newline action+ BEND
/* autoEvent_m /* autoEvent_m
tooltip : ????? tooltip : ?????
helpUrl : https://h5mota.com/games/template/_docs/#/event helpUrl : https://h5mota.com/games/template/_docs/#/event
default : ["flag:__door__==2",0,null,null,null,null] default : ["flag:__door__==2",0,true,false,false,null]
var code = { var code = {
"condition": EvalString_0, // 条件不可为null "condition": EvalString_0, // 条件不可为null
"currentFloor": Bool_0, // 是否仅在本层检测 "currentFloor": Bool_0, // 是否仅在本层检测

View File

@ -253,8 +253,15 @@ editor.prototype.drawEventBlock = function () {
var loc=(i+core.bigmap.offsetX/32)+","+(j+core.bigmap.offsetY/32); var loc=(i+core.bigmap.offsetX/32)+","+(j+core.bigmap.offsetY/32);
if (editor.currentFloorData.events[loc]) if (editor.currentFloorData.events[loc])
color.push('#FF0000'); color.push('#FF0000');
if (editor.currentFloorData.autoEvent[loc]) if (editor.currentFloorData.autoEvent[loc]) {
var x = editor.currentFloorData.autoEvent[loc];
for (var index in x) {
if (x[index] && x[index].data) {
color.push('#FFA500'); color.push('#FFA500');
break;
}
}
}
if (editor.currentFloorData.afterBattle[loc]) if (editor.currentFloorData.afterBattle[loc])
color.push('#FFFF00'); color.push('#FFFF00');
if (editor.currentFloorData.changeFloor[loc]) if (editor.currentFloorData.changeFloor[loc])

View File

@ -123,6 +123,20 @@ editor_datapanel_wrapper = function (editor) {
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// 添加自动事件页,无需双击
editor.uifunctions.addAutoEvent = function () {
if (editor_mode.mode != 'loc') return false;
var newid = '2';
var ae = editor.currentFloorData.autoEvent[editor_mode.pos.x + ',' + editor_mode.pos.y];
if (ae != null) {
var testid;
for (testid = 2; Object.hasOwnProperty.call(ae, testid); testid++);
newid = testid + '';
}
editor_mode.addAction(['add', "['autoEvent']['" + newid + "']", null]);
editor_mode.onmode('save');
}

View File

@ -341,12 +341,12 @@ editor_table_wrapper = function (editor) {
var mode = editor.dom.editModeSelect.value; var mode = editor.dom.editModeSelect.value;
// 1.输入id // 1.输入id
var newid = '3'; var newid = '2';
if (mode == 'loc') { if (mode == 'loc') {
var ae = editor.currentFloorData.autoEvent[editor_mode.pos.x + ',' + editor_mode.pos.y]; var ae = editor.currentFloorData.autoEvent[editor_mode.pos.x + ',' + editor_mode.pos.y];
if (ae != null) { if (ae != null) {
var testid; var testid;
for (testid = 3; Object.hasOwnProperty.call(ae, testid); testid++); // 从3开始是因为comment中设置了始终显示012 for (testid = 2; Object.hasOwnProperty.call(ae, testid); testid++); // 从3开始是因为comment中设置了始终显示012
newid = testid + ''; newid = testid + '';
} }
} else { } else {

View File

@ -435,6 +435,24 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = {
"_event": "event", "_event": "event",
"_data": "该点的可能事件列表,可以双击进入事件编辑器。" "_data": "该点的可能事件列表,可以双击进入事件编辑器。"
}, },
"autoEvent": {
"_type": "object",
"_leaf": false,
"_action": function (args) {
args.vobj=args.vobj||{};
for(var ii=0;ii<2;ii++){
args.vobj[ii]=args.vobj[ii]||null;
}
},
"_data": function (key) {
return {
"_leaf": true,
"_type": "event",
"_event": "autoEvent",
"_data": "自动事件页"
}
}
},
"changeFloor": { "changeFloor": {
"_leaf": true, "_leaf": true,
"_type": "event", "_type": "event",
@ -465,24 +483,6 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = {
"_range": "thiseval==null||(thiseval instanceof Array)", "_range": "thiseval==null||(thiseval instanceof Array)",
"_data": "该点不可通行的方向 \n 可以在这里定义该点不能前往哪个方向,可以达到悬崖之类的效果\n例如 [\"up\", \"left\"] 代表该点不能往上和左走" "_data": "该点不可通行的方向 \n 可以在这里定义该点不能前往哪个方向,可以达到悬崖之类的效果\n例如 [\"up\", \"left\"] 代表该点不能往上和左走"
}, },
"autoEvent": {
"_type": "object",
"_leaf": false,
"_action": function (args) {
args.vobj=args.vobj||{};
for(var ii=0;ii<3;ii++){
args.vobj[ii]=args.vobj[ii]||null;
}
},
"_data": function (key) {
return {
"_leaf": true,
"_type": "event",
"_event": "autoEvent",
"_data": "自动事件"
}
}
}
} }
} }
} }

View File

@ -101,7 +101,7 @@
</div> </div>
</div> </div>
<div id="left2" class='leftTab' style="z-index:-1;opacity: 0;"><!-- loc --> <div id="left2" class='leftTab' style="z-index:-1;opacity: 0;"><!-- loc -->
<h3 class="leftTabHeader">地图选点&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">保存</button>&nbsp;&nbsp;<button onclick="editor.mode.changeDoubleClickModeByButton('add')">添加</button>&nbsp;&nbsp;<button onclick="editor.mode.changeDoubleClickModeByButton('delete')">删除</button>&nbsp;&nbsp;<button onclick="editor_multi.editCommentJs('loc')">配置表格</button> <h3 class="leftTabHeader">地图选点&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">保存</button>&nbsp;&nbsp;<button onclick="editor.uifunctions.addAutoEvent()">添加自动事件页</button>&nbsp;&nbsp;<button onclick="editor_multi.editCommentJs('loc')">配置表格</button>
</h3> </h3>
<div class="leftTabContent"> <div class="leftTabContent">
<p id='pos_a6771a78_a099_417c_828f_0a24851ebfce' style="margin-left: 15px">0,0</p> <p id='pos_a6771a78_a099_417c_828f_0a24851ebfce' style="margin-left: 15px">0,0</p>

View File

@ -97,7 +97,7 @@
</div> </div>
</div> </div>
<div id="left2" class='leftTab' style="z-index:-1;opacity: 0;"><!-- loc --> <div id="left2" class='leftTab' style="z-index:-1;opacity: 0;"><!-- loc -->
<h3 class="leftTabHeader">地图选点&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">保存</button>&nbsp;&nbsp;<button onclick="editor.mode.changeDoubleClickModeByButton('add')">添加</button>&nbsp;&nbsp;<button onclick="editor.mode.changeDoubleClickModeByButton('delete')">删除</button>&nbsp;&nbsp;<button onclick="editor_multi.editCommentJs('loc')">配置表格</button> <h3 class="leftTabHeader">地图选点&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">保存</button>&nbsp;&nbsp;<button onclick="editor.uifunctions.addAutoEvent()">添加自动事件页</button>&nbsp;&nbsp;<button onclick="editor_multi.editCommentJs('loc')">配置表格</button>
</h3> </h3>
<div class="leftTabContent"> <div class="leftTabContent">
<p id='pos_a6771a78_a099_417c_828f_0a24851ebfce' style="margin-left: 15px">0,0</p> <p id='pos_a6771a78_a099_417c_828f_0a24851ebfce' style="margin-left: 15px">0,0</p>

View File

@ -2626,7 +2626,6 @@ actions.prototype.exitPaint = function () {
core.ui.closePanel(); core.ui.closePanel();
core.statusBar.image.keyboard.style.opacity = 1; core.statusBar.image.keyboard.style.opacity = 1;
core.statusBar.image.shop.style.opacity = 1; core.statusBar.image.shop.style.opacity = 1;
core.updateStatusBar();
core.drawTip("退出绘图模式"); core.drawTip("退出绘图模式");
} }

View File

@ -2329,9 +2329,10 @@ control.prototype.clearStatusBar = function() {
} }
////// 更新状态栏 ////// ////// 更新状态栏 //////
control.prototype.updateStatusBar = function () { control.prototype.updateStatusBar = function (doNotCheckAutoEvents) {
if (!core.isPlaying()) return; if (!core.isPlaying()) return;
this.controldata.updateStatusBar(); this.controldata.updateStatusBar();
if (!doNotCheckAutoEvents) core.checkAutoEvents();
this._updateStatusBar_setToolboxIcon(); this._updateStatusBar_setToolboxIcon();
} }

View File

@ -16,7 +16,7 @@ function core() {
'ground': null, 'ground': null,
'items': {}, 'items': {},
'enemys': {}, 'enemys': {},
'icons': {} 'icons': {},
} }
this.timeout = { this.timeout = {
'tipTimeout': null, 'tipTimeout': null,
@ -170,6 +170,7 @@ function core() {
'ui': null, 'ui': null,
'interval': null, 'interval': null,
}, },
'autoEvents': [],
'textAttribute': { 'textAttribute': {
'position': "center", 'position': "center",
"offset": 0, "offset": 0,
@ -236,6 +237,32 @@ core.prototype._init_flags = function () {
document.title = core.firstData.title + " - HTML5魔塔"; document.title = core.firstData.title + " - HTML5魔塔";
document.getElementById("startLogo").innerHTML = core.firstData.title; document.getElementById("startLogo").innerHTML = core.firstData.title;
(core.firstData.shops||[]).forEach(function (t) { core.initStatus.shops[t.id] = t; }); (core.firstData.shops||[]).forEach(function (t) { core.initStatus.shops[t.id] = t; });
// 初始化自动事件
for (var floorId in core.floors) {
var autoEvents = core.floors[floorId].autoEvent || {};
for (var loc in autoEvents) {
var locs = loc.split(","), x = parseInt(locs[0]), y = parseInt(locs[1]);
for (var index in autoEvents[loc]) {
var autoEvent = core.clone(autoEvents[loc][index]);
if (autoEvent && autoEvent.data) {
autoEvent.floorId = floorId;
autoEvent.x = x;
autoEvent.y = y;
autoEvent.index = index;
autoEvent.symbol = floorId + "@" + x + "@" + y + "@" + index;
core.initStatus.autoEvents.push(autoEvent);
}
}
}
}
core.initStatus.autoEvents.sort(function (e1, e2) {
if (e1.priority != e2.priority) return e2.priority - e1.priority;
if (e1.floorId != e2.floorId) return core.floorIds.indexOf(e1.floorId) - core.floorIds.indexOf(e2.floorId);
if (e1.x != e2.x) return e1.x - e2.x;
if (e1.y != e2.y) return e1.y - e2.y;
return e1.index - e2.index;
})
core.maps._setFloorSize(); core.maps._setFloorSize();
// 初始化怪物、道具等 // 初始化怪物、道具等
core.material.enemys = core.enemys.getEnemys(); core.material.enemys = core.enemys.getEnemys();

View File

@ -802,6 +802,8 @@ events.prototype.setEvents = function (list, x, y, callback) {
if (x != null) data.x = x; if (x != null) data.x = x;
if (y != null) data.y = y; if (y != null) data.y = y;
if (callback) data.callback = callback; if (callback) data.callback = callback;
if (!data.appendingEvents) data.appendingEvents = [];
if (!data.locStack) data.locStack = [];
core.status.event.id = 'action'; core.status.event.id = 'action';
core.status.event.data = data; core.status.event.data = data;
} }
@ -848,6 +850,11 @@ events.prototype.doAction = function (keepUI) {
events.prototype._doAction_finishEvents = function () { events.prototype._doAction_finishEvents = function () {
// 事件处理完毕 // 事件处理完毕
if (core.status.event.data.list.length == 0) { if (core.status.event.data.list.length == 0) {
// 检测并执行延迟自动事件
if (core.status.event.data.appendingEvents.length > 0) {
this.setEvents(core.status.event.data.appendingEvents.shift());
return false;
}
var callback = core.status.event.data.callback; var callback = core.status.event.data.callback;
core.ui.closePanel(); core.ui.closePanel();
if (callback) callback(); if (callback) callback();
@ -917,6 +924,81 @@ events.prototype.recoverEvents = function (data) {
return false; return false;
} }
////// 检测自动事件 //////
events.prototype.checkAutoEvents = function () {
// 只有在无操作或事件流中才能执行自动事件!
if (!core.isPlaying() || core.status.lockControl && core.status.event.id != 'action') return;
var todo = [], delay = [];
core.status.autoEvents.forEach(function (autoEvent) {
var symbol = autoEvent.symbol, x = autoEvent.x, y = autoEvent.y, floorId = autoEvent.floorId;
// 不在当前楼层 or 已经执行过 or 正在执行中
if (autoEvent.currentFloor && floorId != core.status.floorId) return;
if (!autoEvent.multiExecute && autoEvent.executed) return;
if (core.autoEventExecuting(symbol)) return;
var prefix = floorId + "@" + x + "@" + y;
try {
if (!core.calValue(autoEvent.condition, prefix)) return;
} catch (e) {
return;
}
core.autoEventExecuting(symbol, true);
autoEvent.executed = true;
var event = [
{"type": "function", "function":
"function() { core.pushEventLoc(" + x + ", " + y + ", '" + floorId + "' ); }"},
// 用do-while(0)包一层防止break影响事件流
{"type": "dowhile", "condition": "false", "data": autoEvent.data},
{"type": "function", "function":
"function() { core.popEventLoc(); core.autoEventExecuting('" + symbol + "', false); }"}
];
if (autoEvent.delayExecute)
delay.push(event);
else
core.push(todo, event);
});
if (todo.length == 0 && delay.length == 0) return;
if (core.status.event.id == 'action' || todo.length > 0) {
core.insertAction(todo);
core.push(core.status.event.data.appendingEvents, delay);
} else {
core.insertAction(delay);
}
}
events.prototype.autoEventExecuting = function (symbol, value) {
var name = '_executing_autoEvent_' + symbol;
if (value == null) return core.getFlag(name, false);
else core.setFlag(name, value || null);
}
events.prototype.pushEventLoc = function (x, y, floorId) {
if (core.status.event.id != 'action') return;
core.status.event.data.locStack.push({
x: core.status.event.data.x,
y: core.status.event.data.y,
floorId: core.status.event.data.floorId
});
core.status.event.data.x = x;
core.status.event.data.y = y;
core.status.event.data.floorId = floorId;
}
events.prototype.popEventLoc = function () {
if (core.status.event.id != 'action') return;
var loc = core.status.event.data.locStack.shift();
if (loc) {
core.status.event.data.x = loc.x;
core.status.event.data.y = loc.y;
core.status.event.data.floorId = loc.floorId;
}
}
// ------ 样板提供的的自定义事件 ------ // // ------ 样板提供的的自定义事件 ------ //
events.prototype.__action_checkReplaying = function () { events.prototype.__action_checkReplaying = function () {

View File

@ -440,7 +440,7 @@ ui.prototype._uievent_drawIcon = function (data) {
ui.prototype.closePanel = function () { ui.prototype.closePanel = function () {
this.clearUI(); this.clearUI();
core.maps.generateGroundPattern(); core.maps.generateGroundPattern();
core.updateStatusBar(); core.updateStatusBar(true);
core.unLockControl(); core.unLockControl();
core.status.event.data = null; core.status.event.data = null;
core.status.event.id = null; core.status.event.id = null;

View File

@ -728,20 +728,6 @@ main.floors.sample1=
"type": "setValue", "type": "setValue",
"name": "flag:door", "name": "flag:door",
"value": "flag:door+1" "value": "flag:door+1"
},
{
"type": "if",
"condition": "flag:door==2",
"true": [
{
"type": "openDoor",
"loc": [
10,
5
]
}
],
"false": []
} }
], ],
"11,6": [ "11,6": [
@ -749,20 +735,6 @@ main.floors.sample1=
"type": "setValue", "type": "setValue",
"name": "flag:door", "name": "flag:door",
"value": "flag:door+1" "value": "flag:door+1"
},
{
"type": "if",
"condition": "flag:door==2",
"true": [
{
"type": "openDoor",
"loc": [
10,
5
]
}
],
"false": []
} }
] ]
}, },
@ -775,4 +747,21 @@ main.floors.sample1=
"fgmap": [ "fgmap": [
], ],
"autoEvent": {
"10,5": {
"0": {
"condition": "flag:door==2",
"currentFloor": true,
"priority": 0,
"delayExecute": false,
"multiExecute": false,
"data": [
{
"type": "openDoor"
}
]
}
}
}
} }

View File

@ -353,7 +353,6 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
core.setFlag('skill', 0); core.setFlag('skill', 0);
core.setFlag('skillName', '无'); core.setFlag('skillName', '无');
} }
core.updateStatusBar();
// 如果有加点 // 如果有加点
var point = core.material.enemys[enemyId].point; var point = core.material.enemys[enemyId].point;
@ -375,6 +374,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
// 如果事件不为空,将其插入 // 如果事件不为空,将其插入
if (todo.length > 0) core.insertAction(todo, x, y); if (todo.length > 0) core.insertAction(todo, x, y);
core.updateStatusBar();
// 如果已有事件正在处理中 // 如果已有事件正在处理中
if (core.status.event.id == null) if (core.status.event.id == null)