feat:使用物品前自动保存

This commit is contained in:
ShakeFlower 2026-02-22 18:47:31 +08:00
parent 0e1b1ac8b2
commit 2294d5042d
5 changed files with 40 additions and 15 deletions

View File

@ -110,6 +110,12 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = {
"_lint": true,
"_docs": "能否使用或装备",
"_data": "当前能否使用或装备该道具仅对cls不为items有效。null表示始终不可使用但可装备"
},
"noAutoSaveBeforeUse": {
"_leaf": true,
"_type": "checkbox",
"_docs": "使用前不自动存档",
"_data": "勾选时,即使设置中开启了使用(tools)类道具前自动存档,对此道具也无效",
}
}
},

View File

@ -659,7 +659,7 @@ control.prototype.moveAction = function (callback) {
var noPass = core.noPass(core.nextX(), core.nextY()), canMove = core.canMoveHero();
// 下一个点如果不能走
if (noPass || !canMove) return this._moveAction_noPass(canMove, callback);
if (core.getLocalStorage("autoSaveAfterItem")) { // 即将进入滑冰前触发自动存档
if (core.getLocalStorage("autoSaveBeforeUseItem")) { // 即将进入滑冰前触发自动存档
const nextbgNumber = core.maps.getBgNumber(core.nextX(), core.nextY(), core.status.floorId);
if (core.onSki(nextbgNumber)) {
core.control.autosave();
@ -1186,7 +1186,7 @@ control.prototype.checkBlock = function () {
if (currChase && currChase.length > 0) {
core.push(actions, { "type": "function", "async": true, "function": "function(){core.checkBlock_adjacentChase(true);}" });
}
if (ambushAction.length > 0 && core.getLocalStorage("autoSaveAfterItem")) {
if (ambushAction.length > 0 && core.getLocalStorage("autoSaveBeforeUseItem")) {
core.push(actions, { "type": "autoSave" }); // 捕捉触发后自动存档
}

View File

@ -128,6 +128,14 @@ items.prototype.useItem = function (itemId, noRoute, callback) {
if (callback) callback();
return;
}
const itemData = core.material.items[itemId];
// 使用道具前自动存档
if (core.getLocalStorage("autoSaveBeforeUseItem") &&
itemData.cls === 'tools' && !itemData.noAutoSaveBeforeUse) {
if (noRoute) core.autosave(true);
else core.autosave(false);
}
// 执行道具效果
this._useItemEffect(itemId);
// 执行完毕

View File

@ -418,8 +418,9 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a =
"cls": "tools",
"name": "破墙镐",
"text": "可以破坏勇士面前的墙",
"useItemEffect": "(function () {\n\tvar canBreak = function (x, y) {\n\t\tvar block = core.getBlock(x, y);\n\t\tif (block == null || block.disable) return false;\n\t\treturn block.event.canBreak;\n\t};\n\n\tvar success = false;\n\tvar pickaxeFourDirections = false; // 是否多方向破如果是将其改成true\n\tif (pickaxeFourDirections) {\n\t\tlet hasAutoSaved = false;\n\t\t// 多方向破\n\t\tfor (var direction in core.utils.scan) { // 多方向破默认四方向如需改成八方向请将这两个scan改为scan2\n\t\t\tvar delta = core.utils.scan[direction];\n\t\t\tvar nx = core.getHeroLoc('x') + delta.x,\n\t\t\t\tny = core.getHeroLoc('y') + delta.y;\n\t\t\tif (canBreak(nx, ny)) {\n\t\t\t\tif (core.getLocalStorage(\"autoSaveAfterItem\")) {\n\t\t\t\t\tif (!hasAutoSaved) core.control.autosave();\n\t\t\t\t\thasAutoSaved = true;\n\t\t\t\t}\n\t\t\t\tcore.removeBlock(nx, ny);\n\t\t\t\tsuccess = true;\n\t\t\t}\n\t\t}\n\t} else {\n\t\t// 仅破当前\n\t\tif (canBreak(core.nextX(), core.nextY())) {\n\t\t\tif (core.getLocalStorage(\"autoSaveAfterItem\")) {\n\t\t\t\tcore.control.autosave();\n\t\t\t}\n\t\t\tcore.removeBlock(core.nextX(), core.nextY());\n\t\t\tsuccess = true;\n\t\t}\n\t}\n\n\tif (success) {\n\t\tcore.playSound('破墙镐');\n\t\tcore.drawTip(core.material.items[itemId].name + '使用成功', itemId);\n\t} else {\n\t\t// 无法使用\n\t\tcore.playSound('操作失败');\n\t\tcore.drawTip(\"当前无法使用\" + core.material.items[itemId].name, itemId);\n\t\tcore.addItem(itemId, 1);\n\t\treturn;\n\t}\n})();",
"canUseItemEffect": "true"
"useItemEffect": "(function () {\n\tvar canBreak = function (x, y) {\n\t\tvar block = core.getBlock(x, y);\n\t\tif (block == null || block.disable) return false;\n\t\treturn block.event.canBreak;\n\t};\n\n\tvar success = false;\n\tvar pickaxeFourDirections = false; // 是否多方向破如果是将其改成true\n\tif (pickaxeFourDirections) {\n\t\tlet hasAutoSaved = false;\n\t\t// 多方向破\n\t\tfor (var direction in core.utils.scan) { // 多方向破默认四方向如需改成八方向请将这两个scan改为scan2\n\t\t\tvar delta = core.utils.scan[direction];\n\t\t\tvar nx = core.getHeroLoc('x') + delta.x,\n\t\t\t\tny = core.getHeroLoc('y') + delta.y;\n\t\t\tif (canBreak(nx, ny)) {\n\t\t\t\tif (core.getLocalStorage(\"autoSaveBeforeUseItem\")) {\n\t\t\t\t\tif (!hasAutoSaved) core.control.autosave();\n\t\t\t\t\thasAutoSaved = true;\n\t\t\t\t}\n\t\t\t\tcore.removeBlock(nx, ny);\n\t\t\t\tsuccess = true;\n\t\t\t}\n\t\t}\n\t} else {\n\t\t// 仅破当前\n\t\tif (canBreak(core.nextX(), core.nextY())) {\n\t\t\tif (core.getLocalStorage(\"autoSaveBeforeUseItem\")) {\n\t\t\t\tcore.control.autosave();\n\t\t\t}\n\t\t\tcore.removeBlock(core.nextX(), core.nextY());\n\t\t\tsuccess = true;\n\t\t}\n\t}\n\n\tif (success) {\n\t\tcore.playSound('破墙镐');\n\t\tcore.drawTip(core.material.items[itemId].name + '使用成功', itemId);\n\t} else {\n\t\t// 无法使用\n\t\tcore.playSound('操作失败');\n\t\tcore.drawTip(\"当前无法使用\" + core.material.items[itemId].name, itemId);\n\t\tcore.addItem(itemId, 1);\n\t\treturn;\n\t}\n})();",
"canUseItemEffect": "true",
"noAutoSaveBeforeUse": true
},
"icePickaxe": {
"cls": "tools",
@ -432,14 +433,15 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a =
"cls": "tools",
"name": "炸弹",
"text": "可以炸掉勇士面前的怪物",
"useItemEffect": "(function () {\n\tconst bombList = []; // 炸掉的怪物坐标列表\n\tconst todo = []; // 炸弹后事件\n\tlet money = 0,\n\t\texp = 0; // 炸弹获得的金币和经验\n\n\tconst canBomb = function (x, y) {\n\t\tvar block = core.getBlock(x, y);\n\t\tif (block == null || block.disable || block.event.cls.indexOf('enemy') != 0) return false;\n\t\tvar enemy = core.getEnemyValue(block.event.id, null, x, y);\n\t\treturn { enemy, notBomb: enemy.notBomb };\n\t};\n\n\tlet hasAutoSaved = false;\n\n\tconst bomb = function (x, y) {\n\t\tconst { enemy, notBomb } = canBomb(x, y);\n\t\tif (!enemy) {\n\t\t\tcore.drawFailTip('该点不是敌人!');\n\t\t\treturn;\n\t\t}\n\t\tif (notBomb) {\n\t\t\tcore.drawFailTip('该点敌人不可炸!');\n\t\t\treturn;\n\t\t}\n\t\tif (core.getLocalStorage(\"autoSaveAfterItem\")) {\n\t\t\tif (!hasAutoSaved) core.control.autosave();\n\t\t\thasAutoSaved = true;\n\t\t}\n\t\tbombList.push([x, y]);\n\t\tmoney += enemy.money || 0;\n\t\texp += enemy.exp || 0;\n\t\tcore.push(todo, core.floors[core.status.floorId].afterBattle[x + \",\" + y]);\n\t\tcore.push(todo, enemy.afterBattle);\n\t\tcore.removeBlock(x, y);\n\t}\n\n\t// 如果要多方向可炸把这里的false改成true\n\tif (false) {\n\t\tvar scan = core.utils.scan; // 多方向炸时默认四方向,如果要改成八方向炸可以改成 core.utils.scan2\n\t\tfor (var direction in scan) {\n\t\t\tvar delta = scan[direction];\n\t\t\tbomb(core.getHeroLoc('x') + delta.x, core.getHeroLoc('y') + delta.y);\n\t\t}\n\t} else {\n\t\t// 仅炸当前\n\t\tbomb(core.nextX(), core.nextY());\n\t}\n\n\tif (bombList.length == 0) {\n\t\tcore.playSound('操作失败');\n\t\tcore.drawTip('当前无法使用' + core.material.items[itemId].name, itemId);\n\t\tcore.addItem(itemId, 1);\n\t\treturn;\n\t}\n\n\tcore.playSound('炸弹');\n\tcore.drawTip(core.material.items[itemId].name + '使用成功', itemId);\n\n\t// 取消这里的注释可以炸弹后获得金币和经验\n\t// core.status.hero.money += money;\n\t// core.status.hero.exp += exp;\n\n\t// 取消这里的注释可以炸弹引发战后事件\n\t// if (todo.length > 0) core.insertAction(todo);\n\n})();",
"canUseItemEffect": "true"
"useItemEffect": "(function () {\n\tconst bombList = []; // 炸掉的怪物坐标列表\n\tconst todo = []; // 炸弹后事件\n\tlet money = 0,\n\t\texp = 0; // 炸弹获得的金币和经验\n\n\tconst canBomb = function (x, y) {\n\t\tvar block = core.getBlock(x, y);\n\t\tif (block == null || block.disable || block.event.cls.indexOf('enemy') != 0) return false;\n\t\tvar enemy = core.getEnemyValue(block.event.id, null, x, y);\n\t\treturn { enemy, notBomb: enemy.notBomb };\n\t};\n\n\tlet hasAutoSaved = false;\n\n\tconst bomb = function (x, y) {\n\t\tconst { enemy, notBomb } = canBomb(x, y);\n\t\tif (!enemy) {\n\t\t\tcore.drawFailTip('该点不是敌人!');\n\t\t\treturn;\n\t\t}\n\t\tif (notBomb) {\n\t\t\tcore.drawFailTip('该点敌人不可炸!');\n\t\t\treturn;\n\t\t}\n\t\tif (core.getLocalStorage(\"autoSaveBeforeUseItem\")) {\n\t\t\tif (!hasAutoSaved) core.control.autosave();\n\t\t\thasAutoSaved = true;\n\t\t}\n\t\tbombList.push([x, y]);\n\t\tmoney += enemy.money || 0;\n\t\texp += enemy.exp || 0;\n\t\tcore.push(todo, core.floors[core.status.floorId].afterBattle[x + \",\" + y]);\n\t\tcore.push(todo, enemy.afterBattle);\n\t\tcore.removeBlock(x, y);\n\t}\n\n\t// 如果要多方向可炸把这里的false改成true\n\tif (false) {\n\t\tvar scan = core.utils.scan; // 多方向炸时默认四方向,如果要改成八方向炸可以改成 core.utils.scan2\n\t\tfor (var direction in scan) {\n\t\t\tvar delta = scan[direction];\n\t\t\tbomb(core.getHeroLoc('x') + delta.x, core.getHeroLoc('y') + delta.y);\n\t\t}\n\t} else {\n\t\t// 仅炸当前\n\t\tbomb(core.nextX(), core.nextY());\n\t}\n\n\tif (bombList.length == 0) {\n\t\tcore.playSound('操作失败');\n\t\tcore.drawTip('当前无法使用' + core.material.items[itemId].name, itemId);\n\t\tcore.addItem(itemId, 1);\n\t\treturn;\n\t}\n\n\tcore.playSound('炸弹');\n\tcore.drawTip(core.material.items[itemId].name + '使用成功', itemId);\n\n\t// 取消这里的注释可以炸弹后获得金币和经验\n\t// core.status.hero.money += money;\n\t// core.status.hero.exp += exp;\n\n\t// 取消这里的注释可以炸弹引发战后事件\n\t// if (todo.length > 0) core.insertAction(todo);\n\n})();",
"canUseItemEffect": "true",
"noAutoSaveBeforeUse": true
},
"centerFly": {
"cls": "tools",
"name": "中心对称飞行器",
"text": "可以飞向当前楼层中心对称的位置",
"useItemEffect": "if (core.getLocalStorage(\"autoSaveAfterItem\")) {\n\tcore.control.autosave();\n}\ncore.playSound('centerFly.mp3');\ncore.clearMap('hero');\ncore.setHeroLoc('x', core.bigmap.width - 1 - core.getHeroLoc('x'));\ncore.setHeroLoc('y', core.bigmap.height - 1 - core.getHeroLoc('y'));\ncore.drawHero();\ncore.drawTip(core.material.items[itemId].name + '使用成功');",
"useItemEffect": "core.playSound('centerFly.mp3');\ncore.clearMap('hero');\ncore.setHeroLoc('x', core.bigmap.width - 1 - core.getHeroLoc('x'));\ncore.setHeroLoc('y', core.bigmap.height - 1 - core.getHeroLoc('y'));\ncore.drawHero();\ncore.drawTip(core.material.items[itemId].name + '使用成功');",
"canUseItemEffect": "(function () {\n\tvar toX = core.bigmap.width - 1 - core.getHeroLoc('x'),\n\t\ttoY = core.bigmap.height - 1 - core.getHeroLoc('y');\n\tvar id = core.getBlockId(toX, toY);\n\treturn id == null;\n})();"
},
"upFly": {
@ -500,7 +502,7 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a =
"cls": "tools",
"name": "跳跃靴",
"text": "能跳跃到前方两格处",
"useItemEffect": "if (core.getLocalStorage(\"autoSaveAfterItem\")) {\n\tcore.control.autosave();\n}\ncore.playSound(\"跳跃\");\ncore.insertAction({ \"type\": \"jumpHero\", \"loc\": [core.nextX(2), core.nextY(2)] });",
"useItemEffect": "core.playSound(\"跳跃\");\ncore.insertAction({ \"type\": \"jumpHero\", \"loc\": [core.nextX(2), core.nextY(2)] });",
"canUseItemEffect": "(function () {\n\tvar nx = core.nextX(2),\n\t\tny = core.nextY(2);\n\treturn nx >= 0 && nx < core.bigmap.width && ny >= 0 && ny < core.bigmap.height && core.getBlockId(nx, ny) == null;\n})();"
},
"wand": {
@ -566,7 +568,8 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a =
"operator": "+=",
"value": "100*flag:input"
}
]
],
"noAutoSaveBeforeUse": true
},
"pack": {
"cls": "items",

View File

@ -4869,14 +4869,22 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
text: '一个楼层已无物品、敌人、NPC(不含已忽略图块),且无未到达楼层传送口时可被自动隐藏,仅在首次进入此状态时在楼传界面触发。',
replay: true,
},
autoSaveAfterItem: {
getName: () => '破炸飞跳自动保存:' + (core.getLocalStorage('autoSaveAfterItem') ? '开' : '关'),
autoSaveBeforeUseItem: {
getName: () => '使用物品自动保存:' + (core.getLocalStorage('autoSaveBeforeUseItem') ? '开' : '关'),
effect: () => {
invertLocalStorage('autoSaveAfterItem');
invertLocalStorage('autoSaveBeforeUseItem');
},
text: '使用破、炸、飞、跳等特定道具前,以及即将走入滑冰、触发捕捉时自动存档。',
text: '使用消耗类物品(含破炸飞跳)前,以及即将走入滑冰、触发捕捉时自动存档。',
replay: false,
}
},
autoSaveBeforePickItem: {
getName: () => '拾取物品自动保存:' + (core.getLocalStorage('autoSaveBeforePickItem') ? '开' : '关'),
effect: () => {
invertLocalStorage('autoSaveBeforePickItem');
},
text: '拾取地上物品前自动存档。',
replay: false,
},
}
class GamePlay extends SettingOnePage {
@ -4912,7 +4920,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
['2,4', 'skipPeform', new SettingButton(220, 305, 150, 25)],
['1,5', 'comment', new SettingButton(40, 330, 150, 25)],
['2,5', 'autoHideFloor', new SettingButton(220, 330, 150, 25)],
['1,6', 'autoSaveAfterItem', new SettingButton(40, 355, 150, 25)],
['1,6', 'autoSaveBeforeUseItem', new SettingButton(40, 355, 150, 25)],
]);
return gamePlayMenu;
}