From 7b54f0d3d35373c74124e65cb61218987260cc43 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Wed, 20 May 2020 13:58:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=85=E5=A4=87=E5=90=8C=E6=97=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=95=B0=E5=80=BC=E5=92=8C=E7=99=BE=E5=88=86=E6=AF=94?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/MotaAction.g4 | 62 ++++++++++++++++++++++++++++++++++++-- _server/MotaActionParse.js | 16 ++++++++++ _server/editor_blockly.js | 5 ++- _server/table/comment.js | 6 ++-- editor-mobile.html | 1 + editor.html | 1 + libs/items.js | 44 ++++++++++----------------- libs/ui.js | 40 +++++++++++------------- project/items.js | 62 ++++++++++++++++++++++++++------------ 9 files changed, 161 insertions(+), 76 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 725b71f4..023bd8fa 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -358,6 +358,60 @@ var code = '{"title": "'+EvalString_0+'", "name": "'+EvalString_1+'", "hard": '+ return code; */; +// equip 事件编辑器入口之一 +equip_m + : '装备' '类型' EvalString '装备动画(第一个装备格有效)' IdString? BGNL? '数值提升项' equipList+ '百分比提升项' equipList+ BEND + + +/* equip_m +tooltip : 装备 +default : ['0', ''] +helpUrl : https://h5mota.com/games/template/_docs/#/event +if (!/^\d+$/.test(EvalString_0)) { + EvalString_0 = '"' + EvalString_0 + '"'; +} +IdString_0 = IdString_0 && (', "animate": "'+IdString_0+'"'); +var code = '{"type": '+EvalString_0+IdString_0+', "value": {\n'+equipList_0+'\n}, "percentage": {\n'+equipList_1+'\n}}'; +return code; +*/; + +equipList + : equipKnown + | equipUnknown + | equipEmpty; + + +equipKnown + : Equip_List ':' Number BEND + + +/* equipKnown +tooltip : 装备项 +default : ['atk', 10] +helpUrl : https://h5mota.com/games/template/_docs/#/event +return '"'+Equip_List_0+'": '+Number_0+', '; +*/; + +equipUnknown + : EvalString ':' Number BEND + + +/* equipUnknown +tooltip : 装备项 +default : ['speed', 10] +helpUrl : https://h5mota.com/games/template/_docs/#/event +return '"'+EvalString_0+'": '+Number_0+', '; +*/; + + +equipEmpty + : Newline + +/* equipEmpty +var code = ' \n'; +return code; +*/; + //为了避免关键字冲突,全部加了_s //动作 @@ -2908,8 +2962,8 @@ IdString ; FixedId_List - : '生命'|'攻击'|'防御'|'护盾'|'黄钥匙'|'蓝钥匙'|'红钥匙'|'金币'|'经验' - /*FixedId_List ['status:hp','status:atk','status:def','status:mdef','item:yellowKey','item:blueKey','item:redKey','status:money','status:exp']*/; + : '生命'|'生命上限'|'攻击'|'防御'|'护盾'|'黄钥匙'|'蓝钥匙'|'红钥匙'|'金币'|'经验'|'魔力'|'魔力上限' + /*FixedId_List ['status:hp','status:hpmax','status:atk','status:def','status:mdef','item:yellowKey','item:blueKey','item:redKey','status:money','status:exp','status:mana','status:manamax']*/; Id_List : '变量' | '状态' | '物品' | '独立开关' | '临时变量' |'全局存储' @@ -2919,6 +2973,10 @@ EnemyId_List : '生命'|'攻击'|'防御'|'金币'|'经验'|'加点'|'属性'|'名称'|'映射名'|'value'|'atkValue'|'defValue'|'notBomb'|'zoneSquare'|'range'|'n'|'add'|'damage' /*EnemyId_List ['hp','atk','def','money','exp','point','special','name','displayInBook','value','atkValue','defValue','notBomb','zoneSquare','range','n','add','damage']*/; +Equip_List + : '生命'|'生命上限'|'攻击'|'防御'|'护盾'|'魔力'|'魔力上限' + /*Equip_List ['hp','hpmax','atk','def','mdef','mana','manamax']*/; + //转blockly后不保留需要加" EvalString : Equote_double (ESC_double | ~["\\])* Equote_double diff --git a/_server/MotaActionParse.js b/_server/MotaActionParse.js index 5c9ab9c1..b67de2ab 100644 --- a/_server/MotaActionParse.js +++ b/_server/MotaActionParse.js @@ -58,6 +58,22 @@ ActionParser.prototype.parse = function (obj,type) { } return MotaActionBlocks['levelChoose_m'].xmlText([text_choices]); + case 'equip': + if(!obj) obj={}; + var buildEquip = function (obj) { + obj = obj || {}; + var text_choices = null; + var knownKeys = MotaActionBlocks.equipKnown.json.args0[0].options.map(function (one) {return one[1];}) + Object.keys(obj).sort().forEach(function (key) { + var one = knownKeys.indexOf(key) >= 0 ? 'equipKnown' : 'equipUnknown'; + text_choices = MotaActionBlocks[one].xmlText([ + key, obj.key, text_choices + ]); + }) + return text_choices; + } + return MotaActionBlocks['equip_m'].xmlText([obj.type, obj.animate, buildEquip(obj.value), buildEquip(obj.percentage)]); + case 'shop': var buildsub = function(obj,parser,next){ var text_choices = null; diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 4a7cfd49..74325011 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -75,6 +75,9 @@ editor_blockly = function () { {"type": "comment", "text": "在这里写该难度需执行的事件"} ]} ], 'levelChoose'), + MotaActionFunctions.actionParser.parse({ + "type": 0, "value": {"atk": 10}, "percentage": {"speed": 10}, + }, 'equip'), ], '显示文字':[ MotaActionBlocks['text_0_s'].xmlText(), @@ -1067,7 +1070,7 @@ function omitedcheckUpdateFunction(event) { } // 对动画进行补全 - if (type == 'animate_s' && name == 'IdString_0') { + if ((type == 'animate_s' && name == 'IdString_0') || (type == 'equip_m' && name == 'IdString_0')) { return filter(allAnimates, content); } diff --git a/_server/table/comment.js b/_server/table/comment.js index 702e54a8..5b92b2f1 100644 --- a/_server/table/comment.js +++ b/_server/table/comment.js @@ -49,9 +49,9 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { }, "equip": { "_leaf": true, - "_type": "textarea", - "_docs": "道具的装备属性", - "_data": "装备属性设置,仅对cls为equips有效。\n如果此项不为null,需要是一个对象,里面可含\"type\",\"atk\",\"def\",\"mdef\",\"animate\"五项,分别对应装备部位、攻防护盾和动画。\n具体详见文档(元件说明-装备)和已有的几个装备的写法。" + "_type": "event", + "_event": "equip", + "_docs": "道具的装备属性" }, "hideInReplay": { "_leaf": true, diff --git a/editor-mobile.html b/editor-mobile.html index 8bc87798..b82d63df 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -218,6 +218,7 @@ + diff --git a/editor.html b/editor.html index 5e0f8560..5c00ccf8 100644 --- a/editor.html +++ b/editor.html @@ -214,6 +214,7 @@ + diff --git a/libs/items.js b/libs/items.js index 41c9d61c..f332c4dd 100644 --- a/libs/items.js +++ b/libs/items.js @@ -292,53 +292,41 @@ items.prototype.unloadEquip = function (equipType, callback) { } items.prototype.compareEquipment = function (compareEquipId, beComparedEquipId) { - var result = {}; + var result = {"value": {}, "percentage": {}}; var first = core.material.items[compareEquipId], second = core.material.items[beComparedEquipId]; - for (var name in core.status.hero) { - if (typeof core.status.hero[name] == 'number') { - var ans = 0; - if (first) ans += (first.equip || {})[name] || 0; - if (second) ans -= (second.equip || {})[name] || 0; - if (ans != 0) result[name] = ans; + for (var one in result) { + for (var name in core.status.hero) { + if (typeof core.status.hero[name] == 'number') { + var ans = 0; + if (first) ans += ((first.equip || {})[one] || {})[name] || 0; + if (second) ans -= ((second.equip || {})[one] || {})[name] || 0; + if (ans != 0) result[one][name] = ans; + } } } return result; } ////// 实际换装的效果 ////// -items.prototype._loadEquipEffect = function (equipId, unloadEquipId, isPercentage) { +items.prototype._loadEquipEffect = function (equipId, unloadEquipId) { // 比较能力值 var result = core.compareEquipment(equipId, unloadEquipId); - if (isPercentage) { - for (var name in result) - core.addBuff(name, result[name] / 100); - } - else { - for (var name in result) - core.status.hero[name] += result[name]; - } + for (var name in result.percentage) + core.addBuff(name, result.percentage[name] / 100); + + for (var name in result.value) + core.status.hero[name] += result.value[name]; } items.prototype._realLoadEquip = function (type, loadId, unloadId, callback) { var loadEquip = core.material.items[loadId] || {}, unloadEquip = core.material.items[unloadId] || {}; - loadEquip.equip = loadEquip.equip || {}; - unloadEquip.equip = unloadEquip.equip || {} - - var loadPercentage = loadEquip.equip.percentage, unloadPercentage = unloadEquip.equip.percentage; - - if (loadId && unloadId && (loadPercentage || false) != (unloadPercentage || false)) { - this.unloadEquip(type); - this.loadEquip(loadId); - if (callback) callback(); - return; - } // --- 音效 this._realLoadEquip_playSound(); // --- 实际换装 - this._loadEquipEffect(loadId, unloadId, loadPercentage == null ? unloadPercentage : loadPercentage); + this._loadEquipEffect(loadId, unloadId); // --- 加减 if (loadId) core.removeItem(loadId); diff --git a/libs/ui.js b/libs/ui.js index 79836eee..7a8aee74 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -2459,23 +2459,17 @@ ui.prototype._drawEquipbox_description = function (info, max_height) { } ui.prototype._drawEquipbox_getStatusChanged = function (info, equip, equipType, y) { - var compare, differentMode = null; - if (info.index < this.LAST) compare = core.compareEquipment(null, info.selectId); - else { - if (equipType<0) differentMode = '<当前没有该装备的空位,请先卸下装备>'; - else { - var last = core.material.items[info.equipEquipment[equipType]]||{}; - if (last.equip && (last.equip.percentage || false) != (equip.equip.percentage || false)) - differentMode = '<数值和比例模式之间的切换不显示属性变化>'; - else - compare = core.compareEquipment(info.selectId, info.equipEquipment[equipType]); - } + if (info.index < this.LAST) { + // 光标在装备栏上:查询卸下装备属性 + return core.compareEquipment(null, info.selectId); } - if (differentMode != null) { - core.fillText('ui', differentMode, 10, y, '#CCCCCC', this._buildFont(14, false)); - return; + if (equipType < 0) { + // 没有空位 + core.fillText('ui', '<当前没有该装备的空位,请先卸下装备>', 10, y, '#CCCCCC', this._buildFont(14, false)); + return null; } - return compare; + // 光标在装备上:查询装上后的属性变化 + return core.compareEquipment(info.selectId, info.equipEquipment[equipType]); } ui.prototype._drawEquipbox_drawStatusChanged = function (info, y, equip, equipType) { @@ -2485,19 +2479,19 @@ ui.prototype._drawEquipbox_drawStatusChanged = function (info, y, equip, equipTy // --- 变化值... core.setFont('ui', this._buildFont(14, true)); - for (var name in compare) { + for (var name in core.status.hero) { + if (typeof core.status.hero[name] != 'number') continue; + var nowValue = core.getRealStatus(name); + // 查询新值 + var newValue = (core.getStatus(name) + (compare.value[name] || 0)) + * (core.getBuff(name) + (compare.percentage[name] || 0) / 100); + if (nowValue == newValue) continue; var text = this._drawEquipbox_getStatusName(name); this._drawEquipbox_drawStatusChanged_draw(text + " ", '#CCCCCC', obj); - var nowValue = core.getStatus(name) * core.getBuff(name), newValue = (core.getStatus(name) + compare[name]) * core.getBuff(name); - if (equip.equip.percentage) { - var nowBuff = core.getBuff(name), newBuff = nowBuff + compare[name] / 100; - nowValue = Math.floor(nowBuff * core.getStatus(name)); - newValue = Math.floor(newBuff * core.getStatus(name)); - } nowValue = core.formatBigNumber(nowValue); newValue = core.formatBigNumber(newValue); this._drawEquipbox_drawStatusChanged_draw(nowValue+"->", '#CCCCCC', obj); - this._drawEquipbox_drawStatusChanged_draw(newValue, compare[name]>0?'#00FF00':'#FF0000', obj); + this._drawEquipbox_drawStatusChanged_draw(newValue, newValue>nowValue?'#00FF00':'#FF0000', obj); obj.drawOffset += 8; } } diff --git a/project/items.js b/project/items.js index 86c61b84..68c39d06 100644 --- a/project/items.js +++ b/project/items.js @@ -65,8 +65,10 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "text": "一把已经生锈的剑", "equip": { "type": 0, - "atk": 0, - "animate": "sword" + "animate": "sword", + "value": { + "atk": 0 + } } }, "sword1": { @@ -75,8 +77,10 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "text": "一把很普通的铁剑", "equip": { "type": 0, - "atk": 10, - "animate": "sword" + "animate": "sword", + "value": { + "atk": 10 + } } }, "sword2": { @@ -85,8 +89,10 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "text": "一把很普通的银剑", "equip": { "type": 0, - "atk": 20, - "animate": "sword" + "animate": "sword", + "value": { + "atk": 20 + } } }, "sword3": { @@ -95,8 +101,10 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "text": "一把很普通的骑士剑", "equip": { "type": 0, - "atk": 40, - "animate": "sword" + "animate": "sword", + "value": { + "atk": 40 + } } }, "sword4": { @@ -105,8 +113,10 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "text": "一把很普通的圣剑", "equip": { "type": 0, - "atk": 80, - "animate": "sword" + "animate": "sword", + "value": { + "atk": 80 + } } }, "sword5": { @@ -115,8 +125,10 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "text": "一把很普通的神圣剑", "equip": { "type": 0, - "atk": 100, - "animate": "sword" + "animate": "sword", + "value": { + "atk": 160 + } } }, "shield0": { @@ -125,7 +137,9 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "text": "一个很破旧的铁盾", "equip": { "type": 1, - "def": 0 + "value": { + "def": 0 + } } }, "shield1": { @@ -134,7 +148,9 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "text": "一个很普通的铁盾", "equip": { "type": 1, - "def": 10 + "value": { + "def": 10 + } } }, "shield2": { @@ -143,7 +159,9 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "text": "一个很普通的银盾", "equip": { "type": 1, - "def": 20 + "value": { + "def": 20 + } } }, "shield3": { @@ -152,7 +170,9 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "text": "一个很普通的骑士盾", "equip": { "type": 1, - "def": 40 + "value": { + "def": 40 + } } }, "shield4": { @@ -161,7 +181,9 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "text": "一个很普通的圣盾", "equip": { "type": 1, - "def": 80 + "value": { + "def": 80 + } } }, "shield5": { @@ -170,8 +192,10 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "text": "一个很普通的神圣盾", "equip": { "type": 1, - "def": 100, - "mdef": 100 + "value": { + "def": 100, + "mdef": 100 + } } }, "superPotion": {