commonEventShop
This commit is contained in:
parent
31facb29e4
commit
8aca0760c0
@ -85,13 +85,25 @@ shopcommonevent
|
|||||||
tooltip : 全局商店, 执行一个公共事件
|
tooltip : 全局商店, 执行一个公共事件
|
||||||
helpUrl : https://h5mota.com/games/template/docs/#/
|
helpUrl : https://h5mota.com/games/template/docs/#/
|
||||||
default : ["shop1","回收钥匙商店",false,"回收钥匙商店",""]
|
default : ["shop1","回收钥匙商店",false,"回收钥匙商店",""]
|
||||||
|
if (EvalString_2) {
|
||||||
|
if (EvalString_2.indexOf('"')>=0)
|
||||||
|
throw new Error('请勿在此处使用双引号!尝试使用单引号吧~');
|
||||||
|
// 检查是不是数组
|
||||||
|
try {
|
||||||
|
EvalString_2 = JSON.parse(EvalString_2.replace(/'/g, '"'));
|
||||||
|
if (!(EvalString_2 instanceof Array)) throw new Error();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
throw new Error('参数列表必须是个有效的数组!');
|
||||||
|
}
|
||||||
|
}
|
||||||
var code = {
|
var code = {
|
||||||
'id': IdString_0,
|
'id': IdString_0,
|
||||||
'textInList': EvalString_0,
|
'textInList': EvalString_0,
|
||||||
'mustEnable': Bool_0,
|
'mustEnable': Bool_0,
|
||||||
'commonEvent': EvalString_1,
|
'commonEvent': EvalString_1
|
||||||
'args': EvalString_2
|
|
||||||
}
|
}
|
||||||
|
if (EvalString_2) code.args = EvalString_2;
|
||||||
code=JSON.stringify(code,null,2)+',\n';
|
code=JSON.stringify(code,null,2)+',\n';
|
||||||
return code;
|
return code;
|
||||||
*/;
|
*/;
|
||||||
@ -322,7 +334,7 @@ action
|
|||||||
| callBook_s
|
| callBook_s
|
||||||
| callSave_s
|
| callSave_s
|
||||||
| callLoad_s
|
| callLoad_s
|
||||||
| unknow_s
|
| unknown_s
|
||||||
| function_s
|
| function_s
|
||||||
| pass_s
|
| pass_s
|
||||||
;
|
;
|
||||||
@ -1746,17 +1758,19 @@ var code = '{"type": "callLoad"},\n';
|
|||||||
return code;
|
return code;
|
||||||
*/;
|
*/;
|
||||||
|
|
||||||
unknow_s
|
unknown_s
|
||||||
: '自定义事件' BGNL? RawEvalString
|
: '自定义事件' BGNL? RawEvalString
|
||||||
|
|
||||||
/* unknow_s
|
/* unknown_s
|
||||||
tooltip : 通过脚本自定义的事件类型, 以及编辑器不识别的事件类型
|
tooltip : 通过脚本自定义的事件类型, 以及编辑器不识别的事件类型
|
||||||
helpUrl : https://h5mota.com/games/template/docs/#/
|
helpUrl : https://h5mota.com/games/template/docs/#/
|
||||||
default : ['{"type":"eventType1"}']
|
default : ['{"type":"test", "data": "这是自定义的参数"}']
|
||||||
colour : this.dataColor
|
colour : this.dataColor
|
||||||
var tempobj={};
|
try {
|
||||||
eval("tempobj='"+RawEvalString_0+"'");
|
var tempobj = JSON.parse(RawEvalString_0);
|
||||||
var code = tempobj +',\n';
|
} catch (e) {throw new Error("不合法的JSON格式!");}
|
||||||
|
if (!tempobj.type) throw new Error("自定义事件需要一个type:xxx");
|
||||||
|
var code = JSON.stringify(tempobj) +',\n';
|
||||||
return code;
|
return code;
|
||||||
*/;
|
*/;
|
||||||
|
|
||||||
@ -2148,8 +2162,13 @@ ActionParser.prototype.parse = function (obj,type) {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
var buildcommentevent = function(obj,parser,next){
|
var buildcommentevent = function(obj,parser,next){
|
||||||
|
if (obj.args instanceof Array) {
|
||||||
|
try { obj.args = JSON.stringify(obj.args).replace(/"/g, "'"); }
|
||||||
|
catch (e) {obj.args = '';}
|
||||||
|
}
|
||||||
|
else obj.args = null;
|
||||||
return MotaActionBlocks['shopcommonevent'].xmlText([
|
return MotaActionBlocks['shopcommonevent'].xmlText([
|
||||||
obj.id,parser.EvalString(obj.textInList),obj.mustEnable,parser.EvalString(obj.commonEvent),parser.EvalString(obj.args),next
|
obj.id,parser.EvalString(obj.textInList),obj.mustEnable,parser.EvalString(obj.commonEvent),obj.args,next
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
var next=null;
|
var next=null;
|
||||||
@ -2651,13 +2670,8 @@ ActionParser.prototype.parseAction = function() {
|
|||||||
case "animateImage": // 兼容 animateImage
|
case "animateImage": // 兼容 animateImage
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
var rawdata = JSON.stringify(data,function(k,v){
|
this.next = MotaActionBlocks['unknown_s'].xmlText([
|
||||||
if(typeof(v)=='string')return v.split('\n').join('\\n');
|
JSON.stringify(data),this.next]);
|
||||||
else return v;
|
|
||||||
},2);
|
|
||||||
rawdata=rawdata.split('\n').join('\\n');
|
|
||||||
this.next = MotaActionBlocks['unknow_s'].xmlText([
|
|
||||||
rawdata,this.next]);
|
|
||||||
}
|
}
|
||||||
this.parseAction();
|
this.parseAction();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -159,6 +159,7 @@ editor_blockly = function () {
|
|||||||
],
|
],
|
||||||
'原生脚本':[
|
'原生脚本':[
|
||||||
MotaActionBlocks['function_s'].xmlText(),
|
MotaActionBlocks['function_s'].xmlText(),
|
||||||
|
MotaActionBlocks['unknown_s'].xmlText(),
|
||||||
],
|
],
|
||||||
'值块':[
|
'值块':[
|
||||||
MotaActionBlocks['setValue_s'].xmlText([
|
MotaActionBlocks['setValue_s'].xmlText([
|
||||||
|
|||||||
@ -1198,26 +1198,13 @@ actions.prototype._keyUpShop = function (keycode) {
|
|||||||
|
|
||||||
////// 快捷商店界面时的点击操作 //////
|
////// 快捷商店界面时的点击操作 //////
|
||||||
actions.prototype._clickQuickShop = function (x, y) {
|
actions.prototype._clickQuickShop = function (x, y) {
|
||||||
var keys = [];
|
var keys = Object.keys(core.status.shops).filter(function (shopId) {
|
||||||
if (core.flags.quickCommonEvents) {
|
|
||||||
keys = core.getFlag("__commonEventList__", []);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
keys = Object.keys(core.status.shops).filter(function (shopId) {
|
|
||||||
return core.status.shops[shopId].visited || !core.status.shops[shopId].mustEnable
|
return core.status.shops[shopId].visited || !core.status.shops[shopId].mustEnable
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (x >= this.CHOICES_LEFT && x <= this.CHOICES_RIGHT) {
|
if (x >= this.CHOICES_LEFT && x <= this.CHOICES_RIGHT) {
|
||||||
var topIndex = this.HSIZE - parseInt(keys.length / 2);
|
var topIndex = this.HSIZE - parseInt(keys.length / 2);
|
||||||
if (y >= topIndex && y < topIndex + keys.length) {
|
if (y >= topIndex && y < topIndex + keys.length) {
|
||||||
if (core.flags.quickCommonEvents) {
|
|
||||||
var name = keys[y - topIndex];
|
|
||||||
core.ui.closePanel();
|
|
||||||
core.status.route.push("common:" + core.encodeBase64(name));
|
|
||||||
core.insertAction(name);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var reason = core.events.canUseQuickShop(keys[y - topIndex]);
|
var reason = core.events.canUseQuickShop(keys[y - topIndex]);
|
||||||
if (!core.flags.enableDisabledShop && reason) {
|
if (!core.flags.enableDisabledShop && reason) {
|
||||||
core.drawText(reason);
|
core.drawText(reason);
|
||||||
@ -1227,7 +1214,6 @@ actions.prototype._clickQuickShop = function (x, y) {
|
|||||||
if (core.status.event.id == 'shop')
|
if (core.status.event.id == 'shop')
|
||||||
core.status.event.data.fromList = true;
|
core.status.event.data.fromList = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// 离开
|
// 离开
|
||||||
else if (y == topIndex + keys.length)
|
else if (y == topIndex + keys.length)
|
||||||
core.ui.closePanel();
|
core.ui.closePanel();
|
||||||
@ -1240,17 +1226,10 @@ actions.prototype._keyUpQuickShop = function (keycode) {
|
|||||||
core.ui.closePanel();
|
core.ui.closePanel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var length = 0;
|
var keys = Object.keys(core.status.shops).filter(function (shopId) {
|
||||||
if (core.flags.quickCommonEvents) {
|
return core.status.shops[shopId].visited || !core.status.shops[shopId].mustEnable
|
||||||
length = core.getFlag("__commonEventList__", []).length;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var shopList = core.status.shops, keys = Object.keys(shopList).filter(function (shopId) {
|
|
||||||
return shopList[shopId].visited || !shopList[shopId].mustEnable
|
|
||||||
});
|
});
|
||||||
length = keys.length;
|
this._selectChoices(keys.length + 1, keycode, this._clickQuickShop);
|
||||||
}
|
|
||||||
this._selectChoices(length + 1, keycode, this._clickQuickShop);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,6 @@ control.prototype._init = function () {
|
|||||||
this.registerReplayAction("fly", this._replayAction_fly);
|
this.registerReplayAction("fly", this._replayAction_fly);
|
||||||
this.registerReplayAction("shop", this._replayAction_shop);
|
this.registerReplayAction("shop", this._replayAction_shop);
|
||||||
this.registerReplayAction("turn", this._replayAction_turn);
|
this.registerReplayAction("turn", this._replayAction_turn);
|
||||||
this.registerReplayAction("common", this._replayAction_common);
|
|
||||||
this.registerReplayAction("getNext", this._replayAction_getNext);
|
this.registerReplayAction("getNext", this._replayAction_getNext);
|
||||||
this.registerReplayAction("moveDirectly", this._replayAction_moveDirectly);
|
this.registerReplayAction("moveDirectly", this._replayAction_moveDirectly);
|
||||||
this.registerReplayAction("key", this._replayAction_key);
|
this.registerReplayAction("key", this._replayAction_key);
|
||||||
@ -1412,6 +1411,12 @@ control.prototype._replayAction_shop = function (action) {
|
|||||||
if (selections.length == 0) return false;
|
if (selections.length == 0) return false;
|
||||||
var shop=core.status.shops[shopId];
|
var shop=core.status.shops[shopId];
|
||||||
if (!shop || !shop.visited) return false;
|
if (!shop || !shop.visited) return false;
|
||||||
|
// --- 判定commonEvent
|
||||||
|
if (shop.commonEvent) {
|
||||||
|
core.openShop(shopId, false);
|
||||||
|
setTimeout(core.replay);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
var choices = shop.choices;
|
var choices = shop.choices;
|
||||||
var topIndex = core.__HALF_SIZE__ - parseInt(choices.length / 2);
|
var topIndex = core.__HALF_SIZE__ - parseInt(choices.length / 2);
|
||||||
core.status.event.selection = parseInt(selections.shift());
|
core.status.event.selection = parseInt(selections.shift());
|
||||||
@ -1443,16 +1448,6 @@ control.prototype._replayAction_turn = function (action) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
control.prototype._replayAction_common = function (action) {
|
|
||||||
if (action.indexOf("common:") != 0) return false;
|
|
||||||
var name = core.decodeBase64(action.substring(7));
|
|
||||||
if (core.getFlag("__commonEventList__").indexOf(name) == -1) return false;
|
|
||||||
core.status.route.push(action);
|
|
||||||
core.insertAction(name);
|
|
||||||
setTimeout(core.replay);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
control.prototype._replayAction_getNext = function (action) {
|
control.prototype._replayAction_getNext = function (action) {
|
||||||
if (action != "getNext") return false;
|
if (action != "getNext") return false;
|
||||||
if (!core.getNextItem()) return false;
|
if (!core.getNextItem()) return false;
|
||||||
|
|||||||
@ -806,10 +806,7 @@ events.prototype.insertAction = function (action, x, y, callback, addToLast) {
|
|||||||
|
|
||||||
// ------ 判定commonEvent
|
// ------ 判定commonEvent
|
||||||
var commonEvent = this.getCommonEvent(action);
|
var commonEvent = this.getCommonEvent(action);
|
||||||
if (commonEvent instanceof Array) {
|
if (commonEvent instanceof Array) action = commonEvent;
|
||||||
this._addCommentEventToList(action, commonEvent);
|
|
||||||
action = commonEvent;
|
|
||||||
}
|
|
||||||
if (!action) return;
|
if (!action) return;
|
||||||
|
|
||||||
if (core.status.event.id != 'action') {
|
if (core.status.event.id != 'action') {
|
||||||
@ -830,22 +827,6 @@ events.prototype.getCommonEvent = function (name) {
|
|||||||
return this.commonEvent[name] || null;
|
return this.commonEvent[name] || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
events.prototype._addCommentEventToList = function (name, list) {
|
|
||||||
if (list == null) list = this.getCommonEvent(name);
|
|
||||||
if (!list || !core.flags.quickCommonEvents) return;
|
|
||||||
var addToList = false;
|
|
||||||
for (var x in list) {
|
|
||||||
if (list[x].type == 'addToList') {
|
|
||||||
addToList = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!addToList) return;
|
|
||||||
var obj = core.getFlag("__commonEventList__", []);
|
|
||||||
if (obj.indexOf(name) == -1) obj.push(name);
|
|
||||||
core.setFlag("__commonEventList__", obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
////// 恢复一个事件 //////
|
////// 恢复一个事件 //////
|
||||||
events.prototype.recoverEvents = function (data) {
|
events.prototype.recoverEvents = function (data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
@ -1144,13 +1125,12 @@ events.prototype._action_useItem = function (data, x, y, prefix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
events.prototype._action_openShop = function (data, x, y, prefix) {
|
events.prototype._action_openShop = function (data, x, y, prefix) {
|
||||||
if (core.isReplaying()) { // 正在播放录像,简单将visited置为true
|
|
||||||
core.status.shops[data.id].visited = true;
|
core.status.shops[data.id].visited = true;
|
||||||
this.setEvents([]);
|
this.setEvents([]);
|
||||||
core.doAction();
|
if (!core.isReplaying())
|
||||||
}
|
|
||||||
else
|
|
||||||
this.openShop(data.id);
|
this.openShop(data.id);
|
||||||
|
if (core.status.event.id == 'action')
|
||||||
|
core.doAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
events.prototype._action_disableShop = function (data, x, y, prefix) {
|
events.prototype._action_disableShop = function (data, x, y, prefix) {
|
||||||
@ -1207,10 +1187,6 @@ events.prototype._action_insert = function (data, x, y, prefix) {
|
|||||||
core.doAction();
|
core.doAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
events.prototype._action_addToList = function (data, x, y, prefix) {
|
|
||||||
core.doAction();
|
|
||||||
}
|
|
||||||
|
|
||||||
events.prototype._action_playBgm = function (data, x, y, prefix) {
|
events.prototype._action_playBgm = function (data, x, y, prefix) {
|
||||||
core.playBgm(data.name);
|
core.playBgm(data.name);
|
||||||
core.doAction();
|
core.doAction();
|
||||||
@ -2109,9 +2085,9 @@ events.prototype.openShop = function (shopId, needVisited) {
|
|||||||
shop.times = shop.times || 0;
|
shop.times = shop.times || 0;
|
||||||
if (shop.commonTimes) shop.times = core.getFlag('commonTimes', 0);
|
if (shop.commonTimes) shop.times = core.getFlag('commonTimes', 0);
|
||||||
if (needVisited && !shop.visited) {
|
if (needVisited && !shop.visited) {
|
||||||
if (!core.flags.enableDisabledShop) {
|
if (!core.flags.enableDisabledShop || shop.commonEvent) {
|
||||||
if (shop.times == 0) core.drawTip("该商店尚未开启");
|
if (shop.times == 0) core.drawTip("该项尚未开启");
|
||||||
else core.drawTip("该商店已失效");
|
else core.drawTip("该项已失效");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -2119,6 +2095,13 @@ events.prototype.openShop = function (shopId, needVisited) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else shop.visited = true;
|
else shop.visited = true;
|
||||||
|
|
||||||
|
// --- 商店
|
||||||
|
if (shop.commonEvent) {
|
||||||
|
core.status.route.push("shop:"+shopId+":0");
|
||||||
|
core.insertAction({"type": "insert", "name": shop.commonEvent, "args": shop.args});
|
||||||
|
return;
|
||||||
|
}
|
||||||
core.ui.drawShop(shopId);
|
core.ui.drawShop(shopId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1118,18 +1118,12 @@ ui.prototype.drawSettings = function () {
|
|||||||
////// 绘制快捷商店选择栏 //////
|
////// 绘制快捷商店选择栏 //////
|
||||||
ui.prototype.drawQuickShop = function () {
|
ui.prototype.drawQuickShop = function () {
|
||||||
core.status.event.id = 'selectShop';
|
core.status.event.id = 'selectShop';
|
||||||
var choices;
|
|
||||||
if (core.flags.quickCommonEvents) {
|
|
||||||
choices = core.clone(core.getFlag("__commonEventList__", []));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var shopList = core.status.shops, keys = Object.keys(shopList).filter(function (shopId) {
|
var shopList = core.status.shops, keys = Object.keys(shopList).filter(function (shopId) {
|
||||||
return shopList[shopId].visited || !shopList[shopId].mustEnable
|
return shopList[shopId].visited || !shopList[shopId].mustEnable
|
||||||
});
|
});
|
||||||
choices = keys.map(function (shopId) {
|
var choices = keys.map(function (shopId) {
|
||||||
return {"text": shopList[shopId].textInList, "color": shopList[shopId].visited?null:"#999999"};
|
return {"text": shopList[shopId].textInList, "color": shopList[shopId].visited?null:"#999999"};
|
||||||
});
|
});
|
||||||
}
|
|
||||||
choices.push("返回游戏");
|
choices.push("返回游戏");
|
||||||
this.drawChoices(null, choices);
|
this.drawChoices(null, choices);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -467,8 +467,6 @@ utils.prototype._encodeRoute_encodeOne = function (t) {
|
|||||||
return "P" + t.substring(6);
|
return "P" + t.substring(6);
|
||||||
else if (t.indexOf('input2:') == 0)
|
else if (t.indexOf('input2:') == 0)
|
||||||
return "Q" + t.substring(7) + ":";
|
return "Q" + t.substring(7) + ":";
|
||||||
else if (t.indexOf('common:') == 0)
|
|
||||||
return "c" + t.substring(7) + ":";
|
|
||||||
else if (t == 'no')
|
else if (t == 'no')
|
||||||
return 'N';
|
return 'N';
|
||||||
else if (t.indexOf('move:') == 0)
|
else if (t.indexOf('move:') == 0)
|
||||||
@ -527,7 +525,7 @@ utils.prototype._decodeRoute_number2id = function (number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) {
|
utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) {
|
||||||
var nxt = (c == 'I' || c == 'e' || c == 'F' || c == 'S' || c == 'Q' || c == 't' || c == 'c') ?
|
var nxt = (c == 'I' || c == 'e' || c == 'F' || c == 'S' || c == 'Q' || c == 't') ?
|
||||||
this._decodeRoute_getString(decodeObj) : this._decodeRoute_getNumber(decodeObj);
|
this._decodeRoute_getString(decodeObj) : this._decodeRoute_getNumber(decodeObj);
|
||||||
|
|
||||||
var mp = {"U": "up", "D": "down", "L": "left", "R": "right"};
|
var mp = {"U": "up", "D": "down", "L": "left", "R": "right"};
|
||||||
@ -572,9 +570,6 @@ utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) {
|
|||||||
case "Q":
|
case "Q":
|
||||||
decodeObj.ans.push("input2:" + nxt);
|
decodeObj.ans.push("input2:" + nxt);
|
||||||
break;
|
break;
|
||||||
case "c":
|
|
||||||
decodeObj.ans.push("common:" + nxt);
|
|
||||||
break;
|
|
||||||
case "N":
|
case "N":
|
||||||
decodeObj.ans.push("no");
|
decodeObj.ans.push("no");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -303,10 +303,9 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "keyShop1",
|
"id": "keyShop1",
|
||||||
"textInList": "1F回收钥匙商店",
|
"textInList": "回收钥匙商店",
|
||||||
"mustEnable": false,
|
"mustEnable": false,
|
||||||
"commonEvent": "回收钥匙商店",
|
"commonEvent": "回收钥匙商店"
|
||||||
"args": ""
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"levelUp": [
|
"levelUp": [
|
||||||
@ -408,7 +407,6 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
|
|||||||
"enableMoveDirectly": true,
|
"enableMoveDirectly": true,
|
||||||
"enableDisabledShop": true,
|
"enableDisabledShop": true,
|
||||||
"disableShopOnDamage": false,
|
"disableShopOnDamage": false,
|
||||||
"quickCommonEvents": false,
|
|
||||||
"checkConsole": false
|
"checkConsole": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user