From 2b92921e43f41e0dccc6f2e0af9e4e8152421295 Mon Sep 17 00:00:00 2001 From: oc Date: Wed, 20 Feb 2019 23:36:26 +0800 Subject: [PATCH] color in choices --- _server/blockly/MotaAction.g4 | 23 +- _server/editor_blockly.js | 8 +- libs/ui.js | 158 ++-- project/floors/sample1.js | 1501 +++++++++++++++++---------------- 4 files changed, 853 insertions(+), 837 deletions(-) diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4 index d81a1128..d87bd35e 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/blockly/MotaAction.g4 @@ -1528,15 +1528,22 @@ return code; */; choicesContext - : '子选项' EvalString BGNL? Newline action+ + : '子选项' EvalString '颜色' EvalString? Colour BGNL? Newline action+ /* choicesContext tooltip : 选项的选择 helpUrl : https://h5mota.com/games/template/docs/#/event?id=choices%EF%BC%9A%E7%BB%99%E7%94%A8%E6%88%B7%E6%8F%90%E4%BE%9B%E9%80%89%E9%A1%B9 -default : ["提示文字:红钥匙"] +default : ["提示文字:红钥匙",""] colour : this.subColor -var code = '{"text": "'+EvalString_0+'", "action": [\n'+action_0+']},\n'; +if (EvalString_1) { + var colorRe = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d),(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d),(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(,0(\.\d+)?|,1)?$/; + if (colorRe.test(EvalString_1)) + EvalString_1 = ', "color": ['+EvalString_1+']'; + else + EvalString_1 = ', "color": "'+EvalString_1+'"'; +} +var code = '{"text": "'+EvalString_0+'"'+EvalString_1+', "action": [\n'+action_0+']},\n'; return code; */; @@ -2095,7 +2102,9 @@ ActionParser.prototype.parseAction = function() { if (!/^\w+\.png$/.test(data.background)) data.background=setTextfunc(data.background); this.next = MotaActionBlocks['setText_s'].xmlText([ - data.position,data.offset,data.title,`rgba(${data.title})`,data.text,`rgba(${data.text})`,data.background,`rgba(${data.background})`,data.bold,data.titlefont,data.textfont,data.time,this.next]); + data.position,data.offset,data.title,'rgba('+data.title+')', + data.text,'rgba('+data.text+')',data.background,'rgba('+data.background+')', + data.bold,data.titlefont,data.textfont,data.time,this.next]); break; case "tip": this.next = MotaActionBlocks['tip_s'].xmlText([ @@ -2267,7 +2276,7 @@ ActionParser.prototype.parseAction = function() { case "setFg": // 颜色渐变 if(this.isset(data.color)){ this.next = MotaActionBlocks['setFg_0_s'].xmlText([ - data.color,`rgba(${data.color})`,data.time||0,data.async||false,this.next]); + data.color,'rgba('+data.color+')',data.time||0,data.async||false,this.next]); } else { this.next = MotaActionBlocks['setFg_1_s'].xmlText([ data.time||0,data.async||false,this.next]); @@ -2275,7 +2284,7 @@ ActionParser.prototype.parseAction = function() { break; case "screenFlash": // 画面闪烁 this.next = MotaActionBlocks['screenFlash_s'].xmlText([ - data.color,`rgba(${data.color})`,data.time||500,data.times||1,data.async||false,this.next]); + data.color,'rgba('+data.color+')',data.time||500,data.times||1,data.async||false,this.next]); break; case "setWeather": // 更改天气 this.next = MotaActionBlocks['setWeather_s'].xmlText([ @@ -2402,7 +2411,7 @@ ActionParser.prototype.parseAction = function() { var text_choices = null; for(var ii=data.choices.length-1,choice;choice=data.choices[ii];ii--) { text_choices=MotaActionBlocks['choicesContext'].xmlText([ - choice.text,this.insertActionList(choice.action),text_choices]); + choice.text,choice.color,'rgba('+choice.color+')',this.insertActionList(choice.action),text_choices]); } this.next = MotaActionBlocks['choices_s'].xmlText([ this.isset(data.text)?this.EvalString(data.text):null,'','',text_choices,this.next]); diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 020fab43..f9c6723c 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -64,9 +64,9 @@ editor_blockly = function () { MotaActionBlocks['lose_s'].xmlText(), MotaActionBlocks['choices_s'].xmlText([ '选择剑或者盾','流浪者','man',MotaActionBlocks['choicesContext'].xmlText([ - '剑',MotaActionFunctions.actionParser.parseList([{"type": "openDoor", "loc": [3,3]}]), + '剑','',null,MotaActionFunctions.actionParser.parseList([{"type": "openDoor", "loc": [3,3]}]), MotaActionBlocks['choicesContext'].xmlText([ - '盾',MotaActionFunctions.actionParser.parseList([{"type": "openDoor", "loc": [9,3]}]), + '盾','',null,MotaActionFunctions.actionParser.parseList([{"type": "openDoor", "loc": [9,3]}]), ]) ]) ]), @@ -175,7 +175,7 @@ editor_blockly = function () { MotaActionFunctions.actionParser.parse([ {"type": "choices", "text": "\t[老人,man]少年,你需要钥匙吗?\n我这里有大把的!", "choices": [ - {"text": "黄钥匙(\${9+flag:shop_times}金币)", "action": [ + {"text": "黄钥匙(\${9+flag:shop_times}金币)", "color": [255,255,0,1], "action": [ {"type": "if", "condition": "status:money>=9+flag:shop_times", "true": [ {"type": "setValue", "name": "status:money", "value": "status:money-(9+flag:shop_times)"}, @@ -187,7 +187,7 @@ editor_blockly = function () { ] } ]}, - {"text": "蓝钥匙(\${18+2*flag:shop_times}金币)", "action": [ + {"text": "蓝钥匙(\${18+2*flag:shop_times}金币)", "color": [0,0,255,1], "action": [ ]}, {"text": "离开", "action": [ {"type": "exit"} diff --git a/libs/ui.js b/libs/ui.js index 04209587..26f86589 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -503,6 +503,73 @@ ui.prototype.calTextBoxWidth = function (canvas, content, min_width, max_width) } } +ui.prototype.__drawText = function (canvas, content, content_left, content_top, valid_width, + color, per_height, time) { + + var offsetx = content_left, offsety = content_top; + core.setFillStyle(canvas, color); + var index = 0, currcolor = color, changed = false; + + var drawNext = function () { + if (index >= content.length) return false; + if (changed) { + core.setFillStyle(canvas, currcolor); + changed = false; + } + + // get next character + var ch = content.charAt(index++); + // \n, \\n + if (ch == '\n' || (ch=='\\' && content.charAt(index)=='n')) { + offsetx = content_left; + offsety += per_height; + if (ch=='\\') index++; + return drawNext(); + } + // \r, \\r + if (ch == '\r' || (ch=='\\' && content.charAt(index)=='r')) { + if (ch == '\\') index++; + changed = true; + // 检查是不是 [] + var index2; + if (content.charAt(index) == '[' && ((index2=content.indexOf(']', index))>=0)) { + // 变色 + var str = content.substring(index+1, index2); + if (str=="") currcolor = color; + else currcolor = str; + index = index2+1; + } + else currcolor = color; + return drawNext(); + } + // 检查是不是自动换行 + if (core.isset(valid_width)) { + var charwidth = core.calWidth(canvas, ch); + if (offsetx + charwidth > content_left + valid_width) { + index--; + offsetx = content_left; + offsety += per_height; + return drawNext(); + } + } + // 输出 + core.fillText(canvas, ch, offsetx, offsety); + offsetx += charwidth; + return true; + }; + + if (!core.isset(time) || time<=0) while (drawNext()); + else { + core.status.event.interval = setInterval(function () { + changed = true; + if (!drawNext()) { + clearInterval(core.status.event.interval); + core.status.event.interval = null; + } + }, time); + } +} + ////// 绘制一个对话框 ////// ui.prototype.drawTextBox = function(content, showAll) { @@ -729,69 +796,10 @@ ui.prototype.drawTextBox = function(content, showAll) { core.drawImage('ui', image, 0, 0, image.width, image.height, left+10, top+10, 70, 70); } - var offsetx = content_left, offsety = content_top; core.setFont('ui', font); - core.setFillStyle('ui', textColor); - var index = 0, currcolor = textColor, changed = false; - var drawNext = function () { - if (index >= content.length) return false; - if (changed) { - core.setFillStyle('ui', currcolor); - changed = false; - } - - // get next character - var ch = content.charAt(index++); - // \n, \\n - if (ch == '\n' || (ch=='\\' && content.charAt(index)=='n')) { - offsetx = content_left; - offsety += textfont+5; - if (ch=='\\') index++; - return drawNext(); - } - // \r, \\r - if (ch == '\r' || (ch=='\\' && content.charAt(index)=='r')) { - if (ch == '\\') index++; - changed = true; - // 检查是不是 [] - var index2; - if (content.charAt(index) == '[' && ((index2=content.indexOf(']', index))>=0)) { - // 变色 - var str = content.substring(index+1, index2); - if (str=="") currcolor = textColor; - else currcolor = str; - index = index2+1; - } - else currcolor = textColor; - return drawNext(); - } - // 检查是不是自动换行 - var charwidth = core.calWidth('ui', ch); - if (offsetx + charwidth > content_left + validWidth) { - index--; - offsetx = content_left; - offsety += textfont+5; - return drawNext(); - } - // 输出 - core.fillText('ui', ch, offsetx, offsety); - offsetx += charwidth; - return true; - }; - - if (showAll || textAttribute.time<=0 || core.status.event.id!='action') { - while (drawNext()); - } - else { - core.status.event.interval = setInterval(function () { - changed = true; - if (!drawNext()) { - clearInterval(core.status.event.interval); - core.status.event.interval = null; - } - }, textAttribute.time); - } + this.__drawText('ui', content, content_left, content_top, validWidth, textColor, textfont + 5, + (showAll || textAttribute.time<=0 || core.status.event.id!='action')?0:textAttribute.time); } @@ -812,7 +820,8 @@ ui.prototype.drawScrollText = function (content, time, callback) { var font = textfont+"px "+core.status.globalAttribute.font; if (textAttribute.bold) font = "bold "+font; - var contents = core.splitLines('ui', content), lines = contents.length; + var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, ""); + var contents = core.splitLines('ui', realContent), lines = contents.length; // 计算总高度,按1.4倍行距计算 var width = 416, height = textfont * 1.4 * lines; @@ -821,15 +830,8 @@ ui.prototype.drawScrollText = function (content, time, callback) { tempCanvas.canvas.height = height; tempCanvas.clearRect(0, 0, width, height); tempCanvas.font = font; - tempCanvas.fillStyle = textColor; - // 全部绘制 - var currH = textfont; - for (var i = 0; i < lines; ++i) { - var text = contents[i]; - tempCanvas.fillText(text, offset, currH); - currH += 1.4 * textfont; - } + this.__drawText(tempCanvas, content, 0, textfont, null, textColor, 1.4*textfont, 0); // 开始绘制到UI上 core.clearMap('ui'); @@ -891,17 +893,19 @@ ui.prototype.drawChoices = function(content, choices) { var contents = null; var content_left = left + 15; + var validWidth = width-(content_left-left)-10; if (core.isset(content)) { - // 获得name, image, icon // 获得name, image, icon var info = this.getTitleAndIcon(content); content = core.replaceText(info.content); + var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, ""); id=info.id; name=info.name; image=info.image; icon=info.icon; iconHeight=info.iconHeight; animate=info.animate; if (id=='hero' || core.isset(icon)) content_left = left+60; - contents = core.splitLines('ui', content, width-(content_left-left)-10, 'bold 15px '+globalFont); + validWidth = width-(content_left-left)-10 + contents = core.splitLines('ui', realContent, validWidth, 'bold 15px '+globalFont); // content部分高度 var cheight=0; @@ -964,16 +968,16 @@ ui.prototype.drawChoices = function(content, choices) { } core.setTextAlign('ui', 'left'); - for (var i=0;i=9+flag:woman_times", - "true": [ - { - "type": "setValue", - "name": "status:money", - "value": "status:money-(9+flag:woman_times)" - }, - { - "type": "setValue", - "name": "item:yellowKey", - "value": "item:yellowKey+1" - } - ], - "false": [ - "\t[老人,woman]你的金钱不足!", - { - "type": "revisit" - } - ] - } - ] - }, - { - "text": "蓝钥匙(${18+2*flag:woman_times}金币)", - "action": [ - { - "type": "if", - "condition": "status:money>=18+2*flag:woman_times", - "true": [ - { - "type": "setValue", - "name": "status:money", - "value": "status:money-(18+2*flag:woman_times)" - }, - { - "type": "setValue", - "name": "item:blueKey", - "value": "item:blueKey+1" - } - ], - "false": [ - "\t[老人,woman]你的金钱不足!", - { - "type": "revisit" - } - ] - } - ] - }, - { - "text": "红钥匙(${36+4*flag:woman_times}金币)", - "action": [ - { - "type": "if", - "condition": "status:money>=36+4*flag:woman_times", - "true": [ - { - "type": "setValue", - "name": "status:money", - "value": "status:money-(36+4*flag:woman_times)" - }, - { - "type": "setValue", - "name": "item:redKey", - "value": "item:redKey+1" - } - ], - "false": [ - "\t[老人,woman]你的金钱不足!", - { - "type": "revisit" - } - ] - } - ] - }, - { - "text": "离开", - "action": [ - { - "type": "exit" - } - ] - } - ] - } + [ + 0, + 7 + ], + [ + 1, + 8 + ], + [ + 2, + 7 ] - } - ] - }, - { - "type": "setValue", - "name": "flag:woman_times", - "value": "flag:woman_times+1" - }, - { - "type": "revisit" - } - ], - "12,11": [ - "\t[老人,womanMagician]使用 {\"type\":\"function\"} 可以写自定义的JS脚本。\n本塔支持的所有主要API会在doc文档内给出。", - "\t[老人,womanMagician]例如这个例子:即将弹出一个输入窗口,然后会将你的输入结果直接加到你的攻击力上。", - { - "type": "input", - "text": "请输入你要加攻击力的数值:" - }, - { - "type": "if", - "condition": "flag:input>0", - "true": [ - { - "type": "setValue", - "name": "status:atk", - "value": "status:atk+flag:input" - }, - { - "type": "tip", - "text": "操作成功,攻击+${flag:input}" - }, - "操作成功,攻击+${flag:input}" - ], - "false": [] - }, - "\t[老人,womanMagician]具体可参见样板中本事件的写法。" - ], - "10,12": null, - "12,12": [ - { - "type": "switch", - "condition": "flag:woman_times", - "caseList": [ - { - "case": "0", - "action": [ - "\t[老人,woman]现在使用switch改写这个例子" + ], + "time": 500 + }, + "\t[hero]什么?", + { + "type": "playSound", + "name": "attack.mp3" + }, + { + "type": "setValue", + "name": "status:atk", + "value": "status:atk/10" + }, + { + "type": "setValue", + "name": "status:def", + "value": "status:def/10" + }, + { + "type": "hide", + "loc": [ + [ + 1, + 6 + ], + [ + 0, + 7 + ], + [ + 2, + 7 + ], + [ + 1, + 8 ] - }, - { - "case": "8", - "action": [ - "\t[老人,woman]你购买的钥匙已经够多了,再继续卖给你的话我会有危险的。", - "\t[老人,woman]看在你贡献给我这么多钱的份上,送你一把大黄门钥匙吧,希望你能好好用它。", - { - "type": "setValue", - "name": "item:bigKey", - "value": "item:bigKey+1" - }, - "\t[老人,woman]我先走了,拜拜~", - { - "type": "hide", - "time": 500 - }, - { - "type": "exit" - } - ] - }, - { - "case": "default", - "action": [ - { - "type": "comment", - "text": "当没有符合的值的场合执行此事件" - }, - { - "type": "choices", - "text": "\t[老人,woman]少年,你需要钥匙吗?\n我这里有大把的!", - "choices": [ - { - "text": "黄钥匙(${9+flag:woman_times}金币)", - "action": [ - { - "type": "if", - "condition": "status:money>=9+flag:woman_times", - "true": [ - { - "type": "setValue", - "name": "status:money", - "value": "status:money-(9+flag:woman_times)" - }, - { - "type": "setValue", - "name": "item:yellowKey", - "value": "item:yellowKey+1" - } - ], - "false": [ - "\t[老人,woman]你的金钱不足!", - { - "type": "revisit" - } - ] - } - ] - }, - { - "text": "蓝钥匙(${18+2*flag:woman_times}金币)", - "action": [ - { - "type": "if", - "condition": "status:money>=18+2*flag:woman_times", - "true": [ - { - "type": "setValue", - "name": "status:money", - "value": "status:money-(18+2*flag:woman_times)" - }, - { - "type": "setValue", - "name": "item:blueKey", - "value": "item:blueKey+1" - } - ], - "false": [ - "\t[老人,woman]你的金钱不足!", - { - "type": "revisit" - } - ] - } - ] - }, - { - "text": "红钥匙(${36+4*flag:woman_times}金币)", - "action": [ - { - "type": "if", - "condition": "status:money>=36+4*flag:woman_times", - "true": [ - { - "type": "setValue", - "name": "status:money", - "value": "status:money-(36+4*flag:woman_times)" - }, - { - "type": "setValue", - "name": "item:redKey", - "value": "item:redKey+1" - } - ], - "false": [ - "\t[老人,woman]你的金钱不足!", - { - "type": "revisit" - } - ] - } - ] - }, - { - "text": "离开", - "action": [ - { - "type": "exit" - } - ] - } - ] - } - ] - } - ] + ] + }, + { + "type": "hide", + "loc": [ + 1, + 5 + ], + "time": 500 + }, + { + "type": "hide" + }, + { + "type": "setFg", + "color": [ + 0, + 0, + 0 + ], + "time": 1250 + }, + { + "type": "sleep", + "time": 700 + }, + { + "type": "changeFloor", + "floorId": "sample1", + "loc": [ + 1, + 11 + ], + "direction": "right", + "time": 1000 + }, + { + "type": "trigger", + "loc": [ + 2, + 11 + ] + } + ], + "2,11": [ + "\t[杰克,thief]喂!醒醒!快醒醒!", + { + "type": "setFg", + "time": 1500 + }, + "\t[hero]额,我这是在什么地方?", + "\t[杰克,thief]你被魔王抓了起来扔进了监狱,和我关在了一起,但是幸运的是我在昨天刚刚挖好一条越狱的暗道!", + { + "type": "openDoor", + "loc": [ + 3, + 11 + ] + }, + { + "type": "sleep", + "time": 300 + }, + "\t[杰克,thief]我先走了,祝你好运!", + { + "type": "move", + "time": 750, + "steps": [ + { + "direction": "right", + "value": 2 + }, + "down" + ] + }, + "上面是个move事件,可以对NPC等进行移动。\n详见样板中小偷事件的写法。", + "\t[hero]怎么跑的这么快..." + ], + "4,2": [ + "\t[老人,man]本塔的商店有两类,全局商店和非全局商店。\n\n所谓非全局商店,就类似于右下角那个卖钥匙的老人一样,一定要碰到才能触发事件。\n\n而全局商店,则能在快捷商店中直接使用。", + "\t[老人,man]要注册一个全局商店,你需要在 data.js 中,找到 shops,并在内添加你的商店信息。", + "\t[老人,man]商店信息添加后,可以在需要的事件处调用{\"type\": \"openShop\"}来打开你添加的全局商店。", + "\t[老人,man]在上面的例子里,左边是一个仿50层的金币商店,右边是一个仿24层的经验商店。\n\n商店被访问后即可在快捷商店中进行使用。", + "\t[老人,man]如果你需要在某层暂时禁用快捷商店,可以在data.js中设置cannotUseQuickShop。\n如果需要永久禁用商店,请使用{\"type\":\"disableShop\"}", + { + "type": "hide", + "time": 500 + } + ], + "1,0": [ + { + "type": "openShop", + "id": "moneyShop1" + } + ], + "5,0": [ + { + "type": "openShop", + "id": "expShop1" + } + ], + "7,7": [ + "\t[老人,man]这是一个典型的杀怪开门、强制战斗事件。", + { + "type": "hide" + } + ], + "8,7": { + "enable": false, + "data": [] }, - { - "type": "setValue", - "name": "flag:woman_times", - "value": "flag:woman_times+1" + "9,7": [ + { + "type": "show", + "loc": [ + 8, + 7 + ] + }, + { + "type": "hide" + } + ], + "10,4": [ + "\t[blackKing]你终于还是来了。", + "\t[hero]放开我们的公主!", + "\t[blackKing]如果我不愿意呢?", + "\t[hero]无需多说,拔剑吧!", + { + "type": "battle", + "id": "blackKing" + }, + { + "type": "hide", + "loc": [ + 10, + 2 + ] + }, + { + "type": "openDoor", + "loc": [ + 8, + 7 + ] + }, + "\t[blackKing]没想到你已经变得这么强大了... 算你厉害。\n公主就交给你了,请好好对她。", + { + "type": "hide" + } + ], + "10,0": [ + "\t[hero]公主,我来救你了~", + "\t[公主,princess]快救我出去!我受够这里了!", + "\t[hero]公主别怕,我们走吧~", + { + "type": "win", + "reason": "救出公主" + } + ], + "6,12": { + "enable": false, + "data": [] }, - { - "type": "revisit" - } - ] -}, -"changeFloor": { - "4,12": { - "floorId": "sample0", - "loc": [ - 6, - 0 + "6,11": [ + "\t[仙子,fairy]通过调用 {\"type\": \"show\"} 可以使隐藏的事件显示出来。\n比如我下面这个机关门。", + { + "type": "show", + "loc": [ + 6, + 12 + ] + }, + "\t[仙子,fairy]通过调用 {\"type\": \"openDoor\"} 可以无需钥匙打开一扇门或暗墙。", + { + "type": "openDoor", + "loc": [ + 6, + 12 + ] + }, + "\t[仙子,fairy]同时,也可以对其它层进行操作,比如楼下的机关门,现在已经为你打开了。", + { + "type": "openDoor", + "loc": [ + 11, + 10 + ], + "floorId": "sample0" + }, + "\t[仙子,fairy]如果 show 或 hide 指定了 time 参数,则以动画效果显示,指定的参数作为消失时间(毫秒)来计算。", + "\t[仙子,fairy]现在到楼下来找我吧~", + { + "type": "show", + "loc": [ + 12, + 10 + ], + "floorId": "sample0" + }, + { + "type": "hide", + "time": 500 + } + ], + "8,11": [ + { + "type": "setValue", + "name": "flag:man_times", + "value": "flag:man_times+1" + }, + "\t[老人,man]在文字中使用${' ${ '}和 } 可以计算并显示一个表达式的结果。\n", + "\t[老人,man]例如:\n你的当前攻击力是${status:atk},防御力是${status:def}。\n攻防和的十倍是${10*(status:atk+status:def)},攻防之积是${status:atk*status:def}。\n你有${item:yellowKey}把黄钥匙,${item:blueKey}把蓝钥匙,${item:redKey}把红钥匙。\n你有${item:pickaxe}个破,${item:bomb}个炸,${item:centerFly}个飞。\n这是你第${flag:man_times}次和我对话。", + "\t[老人,man]同时,你也可以通过{\"type\": \"setValue\"}来设置一个勇士的属性、道具,或某个Flag。", + "\t[老人,man]例如:\n现在我将让你的攻防提升50%,再将攻防和的十倍加到生命值上。", + { + "type": "setValue", + "name": "status:atk", + "value": "status:atk*1.5" + }, + { + "type": "setValue", + "name": "status:def", + "value": "status:def*1.5" + }, + { + "type": "setValue", + "name": "status:hp", + "value": "status:hp+10*(status:atk+status:def)" + }, + "\t[老人,man]再送你500金币,1000经验,1破2炸3飞!", + { + "type": "setValue", + "name": "status:money", + "value": "status:money+500" + }, + { + "type": "setValue", + "name": "status:experience", + "value": "status:experience+1000" + }, + { + "type": "setValue", + "name": "item:pickaxe", + "value": "item:pickaxe+1" + }, + { + "type": "setValue", + "name": "item:bomb", + "value": "item:bomb+2" + }, + { + "type": "setValue", + "name": "item:centerFly", + "value": "item:centerFly+3" + }, + "\t[老人,man]status:xxx 代表勇士的某个属性。\n其中xxx可取hp, atk, def, mdef, money,experience这几项。\n\nitem:xxx 代表勇士的某个道具的个数。\nxxx为道具ID,具体可参见items.js中的定义。\n\nflag:xxx 代表某个自定义Flag或变量。\nxxx为Flag/变量名,可以自行定义,由字母、数字和下划线组成。\n未定义过而直接取用的Flag默认值为false。", + "\t[老人,man]你现在可以重新和我进行对话,进一步看到属性值的改变。" + ], + "10,11": [ + { + "type": "if", + "condition": "flag:woman_times==0", + "true": [ + "\t[老人,woman]这是个很复杂的例子,它将教会你如何使用if 语句进行条件判断,以及 choices 提供选项来供用户进行选择。", + "\t[老人,woman]第一次访问我将显示这段文字;从第二次开始将会向你出售钥匙。\n钥匙价格将随着访问次数递增。\n当合计出售了七把钥匙后,将送你一把大黄门钥匙,并消失不再出现。", + "\t[老人,woman]这部分的逻辑比较长,请细心看样板的写法,是很容易看懂并理解的。" + ], + "false": [ + { + "type": "if", + "condition": "flag:woman_times==8", + "true": [ + "\t[老人,woman]你购买的钥匙已经够多了,再继续卖给你的话我会有危险的。", + "\t[老人,woman]看在你贡献给我这么多钱的份上,送你一把大黄门钥匙吧,希望你能好好用它。", + { + "type": "setValue", + "name": "item:bigKey", + "value": "item:bigKey+1" + }, + "\t[老人,woman]我先走了,拜拜~", + { + "type": "hide", + "time": 500 + }, + { + "type": "exit" + } + ], + "false": [ + { + "type": "choices", + "text": "\t[老人,woman]少年,你需要钥匙吗?\n我这里有大把的!", + "choices": [ + { + "text": "黄钥匙(${9+flag:woman_times}金币)", + "action": [ + { + "type": "if", + "condition": "status:money>=9+flag:woman_times", + "true": [ + { + "type": "setValue", + "name": "status:money", + "value": "status:money-(9+flag:woman_times)" + }, + { + "type": "setValue", + "name": "item:yellowKey", + "value": "item:yellowKey+1" + } + ], + "false": [ + "\t[老人,woman]你的金钱不足!", + { + "type": "revisit" + } + ] + } + ] + }, + { + "text": "蓝钥匙(${18+2*flag:woman_times}金币)", + "action": [ + { + "type": "if", + "condition": "status:money>=18+2*flag:woman_times", + "true": [ + { + "type": "setValue", + "name": "status:money", + "value": "status:money-(18+2*flag:woman_times)" + }, + { + "type": "setValue", + "name": "item:blueKey", + "value": "item:blueKey+1" + } + ], + "false": [ + "\t[老人,woman]你的金钱不足!", + { + "type": "revisit" + } + ] + } + ] + }, + { + "text": "红钥匙(${36+4*flag:woman_times}金币)", + "action": [ + { + "type": "if", + "condition": "status:money>=36+4*flag:woman_times", + "true": [ + { + "type": "setValue", + "name": "status:money", + "value": "status:money-(36+4*flag:woman_times)" + }, + { + "type": "setValue", + "name": "item:redKey", + "value": "item:redKey+1" + } + ], + "false": [ + "\t[老人,woman]你的金钱不足!", + { + "type": "revisit" + } + ] + } + ] + }, + { + "text": "离开", + "action": [ + { + "type": "exit" + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "setValue", + "name": "flag:woman_times", + "value": "flag:woman_times+1" + }, + { + "type": "revisit" + } + ], + "12,11": [ + "\t[老人,womanMagician]使用 {\"type\":\"function\"} 可以写自定义的JS脚本。\n本塔支持的所有主要API会在doc文档内给出。", + "\t[老人,womanMagician]例如这个例子:即将弹出一个输入窗口,然后会将你的输入结果直接加到你的攻击力上。", + { + "type": "input", + "text": "请输入你要加攻击力的数值:" + }, + { + "type": "if", + "condition": "flag:input>0", + "true": [ + { + "type": "setValue", + "name": "status:atk", + "value": "status:atk+flag:input" + }, + { + "type": "tip", + "text": "操作成功,攻击+${flag:input}" + }, + "操作成功,攻击+${flag:input}" + ], + "false": [] + }, + "\t[老人,womanMagician]具体可参见样板中本事件的写法。" + ], + "10,12": null, + "12,12": [ + { + "type": "switch", + "condition": "flag:woman_times", + "caseList": [ + { + "case": "0", + "action": [ + "\t[老人,woman]现在使用switch改写这个例子" + ] + }, + { + "case": "8", + "action": [ + "\t[老人,woman]你购买的钥匙已经够多了,再继续卖给你的话我会有危险的。", + "\t[老人,woman]看在你贡献给我这么多钱的份上,送你一把大黄门钥匙吧,希望你能好好用它。", + { + "type": "setValue", + "name": "item:bigKey", + "value": "item:bigKey+1" + }, + "\t[老人,woman]我先走了,拜拜~", + { + "type": "hide", + "time": 500 + }, + { + "type": "exit" + } + ] + }, + { + "case": "default", + "action": [ + { + "type": "comment", + "text": "当没有符合的值的场合执行此事件" + }, + { + "type": "choices", + "text": "\t[老人,woman]少年,你需要钥匙吗?\n我这里有大把的!", + "choices": [ + { + "text": "黄钥匙(${9+flag:woman_times}金币)", + "color": [255,255,0,1], + "action": [ + { + "type": "if", + "condition": "status:money>=9+flag:woman_times", + "true": [ + { + "type": "setValue", + "name": "status:money", + "value": "status:money-(9+flag:woman_times)" + }, + { + "type": "setValue", + "name": "item:yellowKey", + "value": "item:yellowKey+1" + } + ], + "false": [ + "\t[老人,woman]你的金钱不足!", + { + "type": "revisit" + } + ] + } + ] + }, + { + "text": "蓝钥匙(${18+2*flag:woman_times}金币)", + "color": [0,0,255,1], + "action": [ + { + "type": "if", + "condition": "status:money>=18+2*flag:woman_times", + "true": [ + { + "type": "setValue", + "name": "status:money", + "value": "status:money-(18+2*flag:woman_times)" + }, + { + "type": "setValue", + "name": "item:blueKey", + "value": "item:blueKey+1" + } + ], + "false": [ + "\t[老人,woman]你的金钱不足!", + { + "type": "revisit" + } + ] + } + ] + }, + { + "text": "红钥匙(${36+4*flag:woman_times}金币)", + "color": [255,0,0,1], + "action": [ + { + "type": "if", + "condition": "status:money>=36+4*flag:woman_times", + "true": [ + { + "type": "setValue", + "name": "status:money", + "value": "status:money-(36+4*flag:woman_times)" + }, + { + "type": "setValue", + "name": "item:redKey", + "value": "item:redKey+1" + } + ], + "false": [ + "\t[老人,woman]你的金钱不足!", + { + "type": "revisit" + } + ] + } + ] + }, + { + "text": "离开", + "action": [ + { + "type": "exit" + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "setValue", + "name": "flag:woman_times", + "value": "flag:woman_times+1" + }, + { + "type": "revisit" + } ] }, - "5,5": { - "floorId": "sample2", - "stair": "downFloor", - "direction": "up" + "changeFloor": { + "4,12": { + "floorId": "sample0", + "loc": [ + 6, + 0 + ] + }, + "5,5": { + "floorId": "sample2", + "stair": "downFloor", + "direction": "up" + }, + "10,12": null }, - "10,12": null -}, -"afterBattle": { - "9,6": [ - { - "type": "setValue", - "name": "flag:door", - "value": "flag:door+1" - }, - { - "type": "if", - "condition": "flag:door==2", - "true": [ - { - "type": "openDoor", - "loc": [ - 10, - 5 - ] - } - ], - "false": [] - } - ], - "11,6": [ - { - "type": "setValue", - "name": "flag:door", - "value": "flag:door+1" - }, - { - "type": "if", - "condition": "flag:door==2", - "true": [ - { - "type": "openDoor", - "loc": [ - 10, - 5 - ] - } - ], - "false": [] - } - ], - "10,12": null -}, -"afterGetItem": {}, -"afterOpenDoor": {}, -"cannotMove": {}, -"bgmap": [ + "afterBattle": { + "9,6": [ + { + "type": "setValue", + "name": "flag:door", + "value": "flag:door+1" + }, + { + "type": "if", + "condition": "flag:door==2", + "true": [ + { + "type": "openDoor", + "loc": [ + 10, + 5 + ] + } + ], + "false": [] + } + ], + "11,6": [ + { + "type": "setValue", + "name": "flag:door", + "value": "flag:door+1" + }, + { + "type": "if", + "condition": "flag:door==2", + "true": [ + { + "type": "openDoor", + "loc": [ + 10, + 5 + ] + } + ], + "false": [] + } + ], + "10,12": null + }, + "afterGetItem": {}, + "afterOpenDoor": {}, + "cannotMove": {}, + "bgmap": [ ], -"fgmap": [ + "fgmap": [ -], +] } \ No newline at end of file