From 15f6ed2a838e7391c36287dc729fe934ef3fd401 Mon Sep 17 00:00:00 2001 From: lizhuoyuan <2820814112@qq.com> Date: Sat, 8 Feb 2025 14:10:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E5=8D=B3=E6=8D=A1?= =?UTF-8?q?=E5=8D=B3=E7=94=A8=E9=81=93=E5=85=B7=E6=95=88=E6=9E=9C=E7=9A=84?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/MotaAction.g4 | 57 +++++++++++++++++++++++++++++++++ _server/MotaActionParser.js | 18 +++++++++++ _server/editor_blocklyconfig.js | 3 ++ _server/table/comment.js | 11 +++++-- libs/items.js | 31 ++++++++++++++++-- project/items.js | 7 +++- project/plugins.js | 7 ++-- 7 files changed, 124 insertions(+), 10 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 217ea594..4f2b72bd 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -616,6 +616,59 @@ var code = ' \n'; return code; */; +// itemEffect 事件编辑器入口之一 +itemEffect_m + : '拾取即捡即用物品的效果' BGNL? '数值提升项' itemEffectList+ '此道具cls须为items' BEND + + +/* itemEffect_m +tooltip : 道具效果 +default : [] +helpUrl : /_docs/#/instruction +var code = '{"value": {\n'+itemEffectList_0+'\n}}'; +return code; +*/; + +itemEffectList + : itemEffectKnown + | itemEffectUnknown + | itemEffectEmpty; + + +itemEffectKnown + : ItemEffect_List ':' EvalString '增加值乘以地图倍率' Bool BEND + + +/* itemEffectKnown +tooltip : 数值增加项 +default : ['atk', 10] +helpUrl : /_docs/#/instruction +if (Bool_0) ItemEffect_List_0 += ':o'; +if (!/^[+-]?\d+(\.\d+)?$/.test(EvalString_0)) EvalString_0 = '"' + EvalString_0 + '"'; +return '"'+ItemEffect_List_0+'": '+EvalString_0+', '; +*/; + +itemEffectUnknown + : EvalString ':' EvalString '需要但不消耗' Bool BEND + + +/* itemEffectUnknown +tooltip : 数值增加项 +default : ['speed', 10] +helpUrl : /_docs/#/instruction +if (Bool_0) EvalString_0 += ':o'; +if (!/^[+-]?\d+(\.\d+)?$/.test(EvalString_1)) EvalString_1 = '"' + EvalString_1 + '"'; +return '"'+EvalString_0+'": '+EvalString_1+', '; +*/; + + +itemEffectEmpty + : Newline + +/* itemEffectEmpty +var code = ' \n'; +return code; +*/; faceIds_m : '行走图朝向:' BGNL? Newline '向下ID' IdString? '向左ID' IdString? '向右ID' IdString? '向上ID' IdString? BEND @@ -4150,6 +4203,10 @@ Equip_List : '生命'|'生命上限'|'攻击'|'防御'|'护盾'|'魔力'|'魔力上限' /*Equip_List ['hp','hpmax','atk','def','mdef','mana','manamax']*/; +ItemEffect_List + : '生命'|'生命上限'|'攻击'|'防御'|'护盾'|'魔力'|'魔力上限'|'金币'|'经验' + /*ItemEffect_List ['hp','hpmax','atk','def','mdef','mana','manamax','money','exp']*/; + Key_List : '黄钥匙'|'蓝钥匙'|'红钥匙'|'绿钥匙'|'铁门钥匙' /*Key_List ['yellowKey','blueKey','redKey','greenKey','steelKey']*/; diff --git a/_server/MotaActionParser.js b/_server/MotaActionParser.js index 9d7b6774..d053a443 100644 --- a/_server/MotaActionParser.js +++ b/_server/MotaActionParser.js @@ -85,6 +85,24 @@ ActionParser.prototype.parse = function (obj,type) { return MotaActionBlocks['equip_m'].xmlText([obj.type, obj.animate, buildEquip(obj.value), buildEquip(obj.percentage), this.parseList(obj.equipEvent), this.parseList(obj.unequipEvent)]); + case 'itemEffect': + if (!obj) obj = {}; + var buildItemEffect = function (obj) { + obj = obj || {}; + var text_choices = null; + var knownItemListKeys = MotaActionBlocks['ItemEffect_List'].options.map(function (one) { return one[1]; }) + Object.keys(obj).sort().forEach(function (key) { + var noNeed = key.endsWith(':o'); + if (noNeed) key = key.substring(0, key.length - 2); + var one = knownItemListKeys.indexOf(key) >= 0 ? 'itemEffectKnown' : 'itemEffectUnknown'; + text_choices = MotaActionBlocks[one].xmlText([ + key, obj[key], noNeed, text_choices + ]); + }) + return text_choices; + } + return MotaActionBlocks['itemEffect_m'].xmlText([buildItemEffect(obj.value)]); + case 'doorInfo': if(!obj) obj={}; var buildKeys = function (obj) { diff --git a/_server/editor_blocklyconfig.js b/_server/editor_blocklyconfig.js index 5d95776b..20c8ecd1 100644 --- a/_server/editor_blocklyconfig.js +++ b/_server/editor_blocklyconfig.js @@ -80,6 +80,9 @@ editor_blocklyconfig=(function(){ MotaActionFunctions.actionParser.parse({ "type": 0, "value": {"atk": 10}, "percentage": {"speed": 10}, }, 'equip'), + MotaActionFunctions.actionParser.parse({ + "value": {"atk": 10}, + }, 'itemEffect'), MotaActionFunctions.actionParser.parse([{ "name": "bg.jpg", "x": 0, "y": 0, "canvas": "bg" }], 'floorImage'), diff --git a/_server/table/comment.js b/_server/table/comment.js index ad8ba96d..15d2b679 100644 --- a/_server/table/comment.js +++ b/_server/table/comment.js @@ -62,13 +62,20 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_docs": "回放不绘制道具栏", "_data": "此项建议在会频繁连续多次使用的道具开启(如开启技能,或者《镜子》那样的镜像切换等等)" }, + "itemEffectEvent": { + "_leaf": true, + "_type": "event", + "_event": "itemEffect", + "_docs": "即捡即用效果", + "_data": "即捡即用类物品的效果,仅对cls为items有效。" + }, "itemEffect": { "_leaf": true, "_type": "textarea", "_string": true, "_lint": true, - "_docs": "即捡即用效果", - "_data": "即捡即用类物品的效果,仅对cls为items有效。" + "_docs": "即捡即用脚本", + "_data": "即捡即用类物品在获得时执行的脚本,仅对cls为items有效。" }, "itemEffectTip": { "_leaf": true, diff --git a/libs/items.js b/libs/items.js index a74f74b9..07f23b92 100644 --- a/libs/items.js +++ b/libs/items.js @@ -28,11 +28,36 @@ items.prototype.getItems = function () { ////// “即捡即用类”道具的使用效果 ////// items.prototype.getItemEffect = function (itemId, itemNum) { - var itemCls = core.material.items[itemId].cls; + const itemCls = core.material.items[itemId].cls; // 消耗品 if (itemCls === 'items') { - var curr_hp = core.status.hero.hp; - var itemEffect = core.material.items[itemId].itemEffect; + const curr_hp = core.status.hero.hp; + const itemEffectEvent = core.material.items[itemId].itemEffectEvent; + if (itemEffectEvent) { + const { value } = itemEffectEvent; + for (var i = 0; i < itemNum; ++i) { + for (let statusName in value) { + let statusValue, ratio, needRatio; + const effect = value[statusName]; + if (statusName.endsWith(':o')) { + needRatio = true; + statusName = statusName.slice(0, -2); + } + if (core.status.hero.hasOwnProperty(statusName)) { + try { + ratio = core.status.thisMap.ratio || 1; + statusValue = eval(effect); + } + catch (e) { + console.error(e); + } + if (needRatio) statusValue *= ratio; + core.addStatus(statusName, statusValue); + } + } + } + } + const itemEffect = core.material.items[itemId].itemEffect; if (itemEffect) { try { for (var i = 0; i < itemNum; ++i) diff --git a/project/items.js b/project/items.js index cfeb840a..299e9a98 100644 --- a/project/items.js +++ b/project/items.js @@ -25,7 +25,12 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "itemEffect": "core.status.hero.atk += core.values.redGem * core.status.thisMap.ratio", "itemEffectTip": ",攻击+${core.values.redGem * core.status.thisMap.ratio}", "useItemEffect": "core.status.hero.atk += core.values.redGem", - "canUseItemEffect": "true" + "canUseItemEffect": "true", + "itemEffectEvent": { + "value": { + "atk:o": "core.values.redGem" + } + } }, "blueGem": { "cls": "items", diff --git a/project/plugins.js b/project/plugins.js index 65377fda..5c6a4641 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -3475,13 +3475,12 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = }, "setting": function () { // 自绘设置界面 - // 抽象的不好,很后悔,还是功底太差 const { ButtonBase, MenuBase, MenuPage } = this.MenuBase; class Setting { /** - * @param {(ctx:string, x:number, y:number, w:number, h:number)=>void} draw + * @param {(ctx:string)=>void} draw */ constructor(name, effect, text, replay, draw) { /** 获取选项界面显示的名称 */ @@ -3495,7 +3494,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = */ this.replay = replay; /** 除名称外的绘制内容 - * @type {(ctx:string, x:number, y:number, w:number, h:number)=>void} + * @type {(ctx:string)=>void} */ this.draw = draw; } @@ -4284,7 +4283,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = settingMenu.init(); } - // todolist 自定义设置界面添加键盘支持 + // todolist 自定义设置界面添加键盘支持 √ // todolist 剧情全skip功能 文字-文字+演出(跳跃) // todolist 批量使用:您当前选定了:xxx。请勿选定不适合批量使用的道具,请勿输入过大的数字。 // todolist 道具栏分页,可设定隐藏的道具,及自动查看显隐藏