diff --git a/_server/data.comment.js b/_server/data.comment.js index bc4b3876..99f824e1 100644 --- a/_server/data.comment.js +++ b/_server/data.comment.js @@ -233,7 +233,7 @@ data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "weakValue": { "_leaf": true, "_type": "textarea", - "_data": "衰弱状态下攻防减少的数值" + "_data": "衰弱状态下攻防减少的数值\n如果此项不小于1,则作为实际下降的数值(比如10就是攻防各下降10)\n如果在0到1之间则为下降的比例(比如0.3就是下降30%的攻防)" }, "redJewel": { "_leaf": true, diff --git a/docs/event.md b/docs/event.md index a7f7e333..8b63ae48 100644 --- a/docs/event.md +++ b/docs/event.md @@ -1051,6 +1051,91 @@ choices为一个数组,其中每一项都是一个选项列表。 ], ``` +### while:循环处理 + +从2.2.1样板开始,我们提供了循环处理(while事件)。 + +其大致写法如下: + +``` js +"x,y": [ // 实际执行的事件列表 + {"type": "while", "condition": "...", // 循环测试某个条件 + "data": [ // 条件成立则执行data里面的事件 + + ] + }, +] +``` + +我们可以在condition中给出一个表达式(能将`status:xxx, item:xxx, flag:xxx`来作为参数),并进行判断是否成立。 + +如果条件成立,则将执行`"data"`中的列表事件内容。 + +该事件列表执行完毕后,将继续测试`"condition"`,如果还为true则重新进行执行data内容。 + +下面是一个输出1到10之间的数字,每隔1秒显示一个的例子。 + +``` js +"x,y": [ // 实际执行的事件列表 + {"type":"while", "condition": "flag:i<=10", // 循环处理;注意flag未设置则默认为0 + "data":[ + {"type": "setValue", "name": "flag:i", "value": "flag:i+1"}, // 递增i + "${flag:i}", // 输出i + {"type": "sleep","time":1000}, // 等待1秒 + ] + }, +] +``` + +### break:跳出循环 + +使用 `{"type": "break"}` 可以跳出当前循环。 + +上面的输出例子也可以这么写: + +``` js +"x,y": [ // 实际执行的事件列表 + {"type":"while", "condition": "true", // 循环处理;永远为真 + "data":[ + {"type": "setValue", "name": "flag:i", "value": "flag:i+1"}, // 递增i + {"type": "if", "condition": "flag:i>10", // 测试i是否超过了10 + "true": [{"type": "break"}], // 是的,则直接break调出循环 + "false": [] + }, + "${flag:i}", // 输出i + {"type": "sleep","time":1000}, // 等待1秒 + ] + }, +] +``` + +!> 如果break事件不在任何循环中被执行,则和exit等价,即会立刻结束当前事件! + +### continue:继续执行当前循环 + +使用 `{"type": "continue"}` 可以继续执行当前循环。 + +上面的输出例子也可以这么写: + +``` js +"x,y": [ // 实际执行的事件列表 + {"type":"while", "condition": "true", // 循环处理;永远为真 + "data":[ + {"type": "setValue", "name": "flag:i", "value": "flag:i+1"}, // 递增i + "${flag:i}", // 输出i + {"type": "sleep","time":1000}, // 等待1秒 + {"type": "if", "condition": "flag:i<10", // 测试i是否小于10 + "true": [{"type": "continue"}], // 是的,则继续循环 + "false": [] + }, + {"type": "break"}, // 跳出循环 + ] + }, +] +``` + +!> 如果continue事件不在任何循环中被执行,则和exit等价,即会立刻结束当前事件! + ### function: 自定义JS脚本 上述给出了这么多事件,但有时候往往不能满足需求,这时候就需要执行自定义脚本了。 diff --git a/libs/actions.js b/libs/actions.js index 085318d5..0bf91aa6 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -1658,7 +1658,7 @@ actions.prototype.clickSyncSave = function (x,y) { if (data instanceof Array) { core.ui.drawConfirmBox("所有本地存档都将被覆盖,确认?", function () { - for (var i=1;i<=150;i++) { + for (var i=1;i<=5*(main.savePages||30);i++) { if (i<=data.length) { core.setLocalStorage("save"+i, data[i-1]); } @@ -1673,8 +1673,8 @@ actions.prototype.clickSyncSave = function (x,y) { }) } else { - var index=150; - for (var i=150;i>=1;i--) { + var index=5*(main.savePages||30); + for (var i=5*(main.savePages||30);i>=1;i--) { if (core.getLocalStorage("save"+i, null)==null) index=i; else break; @@ -1797,7 +1797,7 @@ actions.prototype.clickLocalSaveSelect = function (x,y) { switch (selection) { case 0: saves=[]; - for (var i=1;i<=150;i++) { + for (var i=1;i<=5*(main.savePages||30);i++) { var data = core.getLocalStorage("save"+i, null); if (core.isset(data)) { saves.push(data); @@ -1805,7 +1805,7 @@ actions.prototype.clickLocalSaveSelect = function (x,y) { } break; case 1: - for (var i=150;i>=1;i--) { + for (var i=5*(main.savePages||30);i>=1;i--) { saves=core.getLocalStorage("save"+i, null); if (core.isset(saves)) { break; @@ -1869,7 +1869,7 @@ actions.prototype.clickStorageRemove = function (x, y) { core.drawText("\t[操作成功]你的所有存档已被清空。"); break; case 1: - for (var i=1;i<=150;i++) { + for (var i=1;i<=5*(main.savePages||30);i++) { core.removeLocalStorage("save"+i); } core.drawText("\t[操作成功]当前塔的存档已被清空。"); diff --git a/libs/control.js b/libs/control.js index 9d91b972..a7047e7a 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1550,9 +1550,9 @@ control.prototype.replay = function () { } core.status.replay.steps++; - if (core.status.replay.steps%20==0) { - if (core.status.replay.save.length == 30) - core.status.replay.save.shift(); + if (core.status.replay.steps%50==0) { + //if (core.status.replay.save.length == 30) + // core.status.replay.save.shift(); core.status.replay.save.push({"data": core.saveData(), "replay": { "totalList": core.clone(core.status.replay.totalList), "toReplay": core.clone(core.status.replay.toReplay), @@ -1584,7 +1584,7 @@ control.prototype.replay = function () { core.useItem(itemId, function () { core.replay(); }); - }, 750 / Math.sqrt(core.status.replay.speed)); + }, 750 / core.status.replay.speed); } return; } @@ -1602,7 +1602,7 @@ control.prototype.replay = function () { core.changeFloor(floorId, stair, null, null, function () { core.replay(); }); - }, 750 / Math.sqrt(core.status.replay.speed)); + }, 750 / core.status.replay.speed); return; } } @@ -1635,7 +1635,7 @@ control.prototype.replay = function () { core.status.event.selection = parseInt(selections.shift()); core.events.openShop(shopId, false); - }, 750 / Math.sqrt(core.status.replay.speed)); + }, 750 / core.status.replay.speed); return; } } @@ -1898,7 +1898,7 @@ control.prototype.syncSave = function (type) { // data if (type=='all') { saves=[]; - for (var i=1;i<=150;i++) { + for (var i=1;i<=5*(main.savePages||30);i++) { var data = core.getLocalStorage("save"+i, null); if (core.isset(data)) { saves.push(data); @@ -1906,7 +1906,7 @@ control.prototype.syncSave = function (type) { } } else { - for (var i=150;i>=1;i--) { + for (var i=5*(main.savePages||30);i>=1;i--) { saves=core.getLocalStorage("save"+i, null); if (core.isset(saves)) { break; @@ -1967,7 +1967,7 @@ control.prototype.syncLoad = function () { if (data instanceof Array) { core.status.event.selection=1; core.ui.drawConfirmBox("所有本地存档都将被覆盖,确认?", function () { - for (var i=1;i<=150;i++) { + for (var i=1;i<=5*(main.savePages||30);i++) { if (i<=data.length) { core.setLocalStorage("save"+i, data[i-1]); } @@ -1983,8 +1983,8 @@ control.prototype.syncLoad = function () { } else { // 只覆盖单存档 - var index=150; - for (var i=150;i>=1;i--) { + var index=5*(main.savePages||30); + for (var i=5*(main.savePages||30);i>=1;i--) { if (core.getLocalStorage("save"+i, null)==null) index=i; else break; diff --git a/libs/core.js b/libs/core.js index 79aef3b0..525d3685 100644 --- a/libs/core.js +++ b/libs/core.js @@ -265,7 +265,8 @@ core.prototype.init = function (coreData, callback) { core.setRequestAnimationFrame(); core.showStartAnimate(); - core.events.initGame(); + if (main.mode=='play') + core.events.initGame(); if (core.isset(functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.plugins)) core.plugin = new functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.plugins.plugin(); diff --git a/libs/events.js b/libs/events.js index cae460c5..bf0866fe 100644 --- a/libs/events.js +++ b/libs/events.js @@ -253,7 +253,9 @@ events.prototype.doEvents = function (list, x, y, callback) { core.waitHeroToStop(function() { core.lockControl(); core.status.event = {'id': 'action', 'data': { - 'list': core.clone(list), 'x': x, 'y': y, 'callback': callback + 'list': [ + {"todo": core.clone(list), "total": core.clone(list), "condition": "false"} + ], 'x': x, 'y': y, 'callback': callback }} core.events.doAction(); }); @@ -278,7 +280,18 @@ events.prototype.doAction = function() { return; } - var data = core.status.event.data.list.shift(); + var current = core.status.event.data.list[0]; + if (current.todo.length == 0) { // current list is empty + if (core.calValue(current.condition)) { // check condition + current.todo = core.clone(current.total); + } + else { + core.status.event.data.list.shift(); // remove stackc + } + this.doAction(); + return; + } + var data = current.todo.shift(); core.status.event.data.current = data; var x=core.status.event.data.x, y=core.status.event.data.y; @@ -553,7 +566,9 @@ events.prototype.doAction = function() { block = block.block; if (core.isset(block.event) && block.event.trigger=='action') { // 触发 - core.status.event.data.list = core.clone(block.event.data); + core.status.event.data.list = [ + {"todo": core.clone(block.event.data), "total": core.clone(block.event.data), "condition": "false"} + ]; core.status.event.data.x=block.x; core.status.event.data.y=block.y; } @@ -678,7 +693,7 @@ events.prototype.doAction = function() { core.status.route.push("choices:"+index); core.events.insertAction(data.choices[index].action); core.events.doAction(); - }, 750 / Math.sqrt(core.status.replay.speed)) + }, 750 / core.status.replay.speed) } else { core.stopReplay(); @@ -688,6 +703,27 @@ events.prototype.doAction = function() { } core.ui.drawChoices(data.text, data.choices); break; + case "while": + if (core.calValue(data.condition)) { + core.unshift(core.status.event.data.list, + {"todo": core.clone(data.data), "total": core.clone(data.data), "condition": data.condition} + ); + } + this.doAction(); + break; + case "break": + core.status.event.data.list.shift(); + this.doAction(); + break; + case "continue": + if (core.calValue(core.status.event.data.list[0].condition)) { + core.status.event.data.list[0].todo = core.clone(core.status.event.data.list[0].total); + } + else { + core.status.event.data.list.shift(); + } + this.doAction(); + break; case "win": core.events.win(data.reason, function () { core.events.doAction(); @@ -734,7 +770,9 @@ events.prototype.doAction = function() { if (block!=null) { block = block.block; if (core.isset(block.event) && block.event.trigger=='action') { - core.status.event.data.list = core.clone(block.event.data); + core.status.event.data.list = [ + {"todo": core.clone(block.event.data), "total": core.clone(block.event.data), "condition": "false"} + ]; } } this.doAction(); @@ -757,7 +795,7 @@ events.prototype.insertAction = function (action, x, y, callback) { this.doEvents(action, x, y, callback); } else { - core.unshift(core.status.event.data.list, action) + core.unshift(core.status.event.data.list[0].todo, action) if (core.isset(x)) core.status.event.data.x=x; if (core.isset(y)) core.status.event.data.y=y; if (core.isset(callback)) core.status.event.data.callback=callback; @@ -1286,8 +1324,13 @@ events.prototype.passNet = function (data) { if (data.event.id=='weakNet') { // 衰网 if (core.hasFlag('weak')) return; core.setFlag('weak', true); - core.status.hero.atk-=core.values.weakValue; - core.status.hero.def-=core.values.weakValue; + var weakValue = core.status.weakValue; + var weakAtk = weakValue>=1?weakValue:Math.floor(weakValue*core.status.hero.atk); + var weakDef = weakValue>=1?weakValue:Math.floor(weakValue*core.status.hero.def); + core.setFlag('weakAtk', weakAtk); + core.setFlag('weakDef', weakDef); + core.status.hero.atk-=weakAtk; + core.status.hero.def-=weakDef; } if (data.event.id=='curseNet') { // 咒网 if (core.hasFlag('curse')) return; diff --git a/libs/ui.js b/libs/ui.js index f875e18b..b539d278 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -1571,7 +1571,8 @@ ui.prototype.drawSLPanel = function(index) { if (index<0) index=0; var page = parseInt(index/10), offset=index%10; - if (page>=30) page=29; + var max_page = main.savePages || 30; + if (page>=max_page) page=max_page - 1; if (offset>5) offset=5; index=10*page+offset; @@ -1617,7 +1618,7 @@ ui.prototype.drawSLPanel = function(index) { } } } - this.drawPagination(page+1, 30); + this.drawPagination(page+1, max_page); if (core.status.event.selection) core.setFillStyle('ui', '#FF6A6A'); diff --git a/libs/utils.js b/libs/utils.js index ddcdf0e4..8ad8e03b 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -170,10 +170,13 @@ utils.prototype.setTwoDigits = function (x) { } utils.prototype.formatBigNumber = function (x) { - x = parseFloat(x); + x = Math.floor(parseFloat(x)); if (!core.isset(x)) return '???'; - if (x<=999999) return x; + var c = x<0?"-":""; + x = Math.abs(x); + + if (x<=999999) return c + x; var all = [ {"val": 1e20, "c": "g"}, @@ -187,11 +190,11 @@ utils.prototype.formatBigNumber = function (x) { var one = all[i]; if (x>=10*one.val) { var v = x/one.val; - return v.toFixed(Math.max(0, Math.floor(4-Math.log10(v+1)))) + one.c; + return c + v.toFixed(Math.max(0, Math.floor(4-Math.log10(v+1)))) + one.c; } } - return x; + return c+x; } ////// 数组转RGB ////// diff --git a/main.js b/main.js index c4327eaf..3dddfd0d 100644 --- a/main.js +++ b/main.js @@ -14,6 +14,8 @@ function main() { this.isCompetition = false; // 是否是比赛模式 + this.savePages = 30; // 存档页数,每页可存5个;默认为30页150个存档 + //------------------------ 用户修改内容 END ------------------------// this.dom = { diff --git a/project/functions.js b/project/functions.js index ce14382f..975d9aab 100644 --- a/project/functions.js +++ b/project/functions.js @@ -155,8 +155,13 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 衰弱 if (core.enemys.hasSpecial(special, 13) && !core.hasFlag('weak')) { core.setFlag('weak', true); - core.status.hero.atk-=core.values.weakValue; - core.status.hero.def-=core.values.weakValue; + var weakValue = core.status.weakValue; + var weakAtk = weakValue>=1?weakValue:Math.floor(weakValue*core.status.hero.atk); + var weakDef = weakValue>=1?weakValue:Math.floor(weakValue*core.status.hero.def); + core.setFlag('weakAtk', weakAtk); + core.setFlag('weakDef', weakDef); + core.status.hero.atk-=weakAtk; + core.status.hero.def-=weakDef; } // 诅咒 if (core.enemys.hasSpecial(special, 14) && !core.hasFlag('curse')) { diff --git a/project/icons.js b/project/icons.js index cfc26a35..1d36e5e0 100644 --- a/project/icons.js +++ b/project/icons.js @@ -207,6 +207,7 @@ icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1 = 'bluePotion': 21, 'greenPotion': 22, 'yellowPotion': 23, + 'lifeWand': 33, 'sword0': 60, 'sword1': 50, 'sword2': 51, diff --git a/project/items.js b/project/items.js index 3c529527..5a2788fe 100644 --- a/project/items.js +++ b/project/items.js @@ -222,7 +222,12 @@ items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "cls": "tools", "name": "圣锤", "text": "可以炸掉勇士面前的怪物" - } + }, + "lifeWand": { + "cls": "tools", + "name": "生命魔杖", + "text": "可以恢复100点生命值" + } }, "itemEffect": { "redJewel": "core.status.hero.atk += core.values.redJewel * ratio", @@ -284,9 +289,9 @@ items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "upFly": "var loc = {'direction': core.status.hero.loc.direction, 'x': core.status.event.data.x, 'y': core.status.event.data.y};\ncore.changeFloor(core.status.event.data.id, null, loc, null, function (){\n core.drawTip(core.material.items[itemId].name + '使用成功');\n core.replay();\n});", "downFly": "var loc = {'direction': core.status.hero.loc.direction, 'x': core.status.event.data.x, 'y': core.status.event.data.y};\ncore.changeFloor(core.status.event.data.id, null, loc, null, function (){\n core.drawTip(core.material.items[itemId].name + '使用成功');\n core.replay();\n});", "poisonWine": "core.setFlag('poison', false);", - "weakWine": "core.setFlag('weak', false);\ncore.status.hero.atk += core.values.weakValue;\ncore.status.hero.def += core.values.weakValue;", + "weakWine": "core.setFlag('weak', false);\ncore.status.hero.atk += core.getFlag('weakAtk', core.values.weakValue);\ncore.status.hero.def += core.getFlag('weakDef', core.values.weakValue);", "curseWine": "core.setFlag('curse', false);", - "superWine": "core.setFlag('poison', false);\nif (core.hasFlag('weak')) {\n core.setFlag('weak', false);\n core.status.hero.atk += core.values.weakValue;\n core.status.hero.def += core.values.weakValue;\n}\ncore.setFlag('curse', false);", + "superWine": "core.setFlag('poison', false);\nif (core.hasFlag('weak')) {\n core.setFlag('weak', false);\n core.status.hero.atk += core.getFlag('weakAtk', core.values.weakValue);\n core.status.hero.def += core.getFlag('weakDef', core.values.weakValue);\n}\ncore.setFlag('curse', false);", "sword0": "core.plugin.useEquipment(itemId)", "sword1": "core.plugin.useEquipment(itemId)", "sword2": "core.plugin.useEquipment(itemId)", @@ -298,7 +303,8 @@ items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "shield2": "core.plugin.useEquipment(itemId)", "shield3": "core.plugin.useEquipment(itemId)", "shield4": "core.plugin.useEquipment(itemId)", - "shield5": "core.plugin.useEquipment(itemId)" + "shield5": "core.plugin.useEquipment(itemId)", + "lifeWand": "core.insertAction([\n\t{\"type\": \"input\", \"text\": \"请输入生命魔杖使用次数:(0-${item:lifeWand})\"},\n\t{\"type\": \"if\", \"condition\": \"flag:input<=item:lifeWand\",\n\t\t\"true\": [\n\t\t\t{\"type\": \"setValue\", \"name\": \"item:lifeWand\", \"value\": \"item:lifeWand-flag:input\"},\n\t\t\t{\"type\": \"setValue\", \"name\": \"status:hp\", \"value\": \"status:hp+flag:input*100\"},\n\t\t\t\"成功使用${flag:input}次生命魔杖,恢复${flag:input*100}点生命。\"\n\t\t],\n\t\t\"false\": [\"输入不合法!\"]\n\t},\n]);\ncore.setItem('lifeWand', core.itemCount('lifeWand')+1);" }, "canUseItemEffect": { "book": "true", @@ -329,6 +335,7 @@ items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "shield3": "true", "shield4": "true", "shiled5": "true", - "shield5": "true" + "shield5": "true", + "lifeWand": "true" } } \ No newline at end of file diff --git a/project/maps.js b/project/maps.js index 07484df7..815c0ca9 100644 --- a/project/maps.js +++ b/project/maps.js @@ -76,6 +76,7 @@ maps_90f36752_8815_4be8_b32b_d7fad1d0542e = '63':{'cls': 'items', 'id': 'moneyPocket'}, // 金钱袋 '64':{'cls': 'items', 'id': 'shoes'}, // 绿鞋 '65':{'cls': 'items', 'id': 'hammer'}, // 圣锤 + '66':{'cls': 'items', 'id': 'lifeWand'}, // 生命魔杖 ////////////////////////// 门、楼梯、传送点部分 //////////////////////////