From 2c4887899cb84c845c933b62bc51a24609d75b6b Mon Sep 17 00:00:00 2001 From: strawberry42271 <2806566736@qq.com> Date: Sat, 8 Mar 2025 12:58:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E9=81=93=E5=85=B7=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/table/comment.js | 8 + project/items.js | 6 +- project/plugins.js | 894 ++++++++++++++++++--------------------- 3 files changed, 427 insertions(+), 481 deletions(-) diff --git a/_server/table/comment.js b/_server/table/comment.js index 8c592ce..b8ae4ff 100644 --- a/_server/table/comment.js +++ b/_server/table/comment.js @@ -116,6 +116,14 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_lint": true, "_docs": "能否使用或装备", "_data": "当前能否使用或装备该道具,仅对cls不为items有效。null表示始终不可使用但可装备" + }, + "canBatchUse": { + "_leaf": true, + "_type": "textarea", + "_string": true, + "_lint": true, + "_docs": "能否批量使用", + "_data": "该道具是否允许批量使用,仅对cls为tools或constants有效,true表示可批量使用。建议同时勾选【回放不绘制道具栏】" } } }, diff --git a/project/items.js b/project/items.js index 52cff8d..53d1d78 100644 --- a/project/items.js +++ b/project/items.js @@ -310,13 +310,15 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "itemEffectTip": ",防御+100,护盾+100" }, "superPotion": { - "cls": "items", + "cls": "tools", "name": "圣水", "itemEffect": "core.status.hero.hp *= 2", "itemEffectTip": ",生命值翻倍", "useItemEffect": "core.status.hero.hp *= 2;core.playSound('回血');", "canUseItemEffect": "true", - "text": "生命值翻倍" + "text": "生命值翻倍", + "canBatchUse": "true", + "hideInReplay": true }, "book": { "cls": "constants", diff --git a/project/plugins.js b/project/plugins.js index 287dff0..823da2a 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -5489,22 +5489,23 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = }; }, "新道具栏/装备栏": function () { - // 在此增加新插件 + // 这个插件有点离谱 个人觉得参数过多只会降低可读性,还不如硬编码 + // 注:///// *** 裹起来的区域: 该区域内参数可以随意更改调整ui绘制 不会影响总体布局 // 请尽量修改该区域而不是其他区域 修改的时候最好可以对照现有ui修改 ///// *** 道具类型 // cls对应name var itemClsName = { - constants: "永久道具", - tools: "消耗道具", - }; + "constants": "永久道具", + "tools": "消耗道具", + } // 一页最大放的道具数量 将把整个道具左栏分成num份 每份是一个道具项 var itemNum = 12; ///// *** // 背景设置 - this.drawBoxBackground = function (ctx) { + function drawBoxBackground(ctx) { core.setTextAlign(ctx, "left"); core.clearMap(ctx); core.deleteCanvas("_selector"); @@ -5544,25 +5545,8 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.strokeRect(ctx, x, y, w, h, borderStyle, borderWidth); */ core.setAlpha(ctx, backgroundAlpha); - core.strokeRoundRect( - ctx, - x, - y, - w, - h, - borderRadius, - borderStyle, - borderWidth - ); - core.fillRoundRect( - ctx, - start_x, - start_y, - width, - height, - borderRadius, - backgroundColor - ); + core.strokeRoundRect(ctx, x, y, w, h, borderRadius, borderStyle, borderWidth); + core.fillRoundRect(ctx, start_x, start_y, width, height, borderRadius, backgroundColor); core.setAlpha(ctx, 1); ///// *** 左栏配置 @@ -5586,7 +5570,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var arrow_width = 20; var arrow_style = "white"; // 暂时只能是1 否则不太行 等待新样板(2.7.3)之后对drawArrow做优化 - var arrow_lineWidth = 1; + var arrow_lineWidth = 2; // 右箭头 var rightArrow_right = leftbar_right - 10; // 道具内栏顶部坐标 本质是通过该项 控制(道具栏顶部文字和箭头)与道具内栏顶部的间隔 @@ -5594,28 +5578,9 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = ///// *** var itembar_right = rightArrow_right; - var boxName = - core.status.event.id == "toolbox" ? - "\r[yellow]道具栏\r | 装备栏" : - "道具栏 | \r[yellow]装备栏\r"; - core.drawArrow( - ctx, - arrow_x + arrow_width, - arrow_y, - arrow_x, - arrow_y, - arrow_style, - arrow_lineWidth - ); - core.drawArrow( - ctx, - rightArrow_right - arrow_width, - arrow_y, - rightArrow_right, - arrow_y, - arrow_style, - arrow_lineWidth - ); + var boxName = core.status.event.id == "toolbox" ? "\r[yellow]道具栏\r | 装备栏" : "道具栏 | \r[yellow]装备栏\r"; + core.drawArrow(ctx, arrow_x + arrow_width, arrow_y, arrow_x, arrow_y, arrow_style, arrow_lineWidth); + core.drawArrow(ctx, rightArrow_right - arrow_width, arrow_y, rightArrow_right, arrow_y, arrow_style, arrow_lineWidth); core.setTextAlign(ctx, "center"); core.setTextBaseline(ctx, "middle"); var changeBox = function () { @@ -5623,15 +5588,8 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.closePanel(); if (id == "toolbox") core.openEquipbox(); else core.openToolbox(); - }; - core.fillText( - ctx, - boxName, - (leftbar_right + leftbar_x) / 2, - arrow_y + 2, - boxName_color, - boxName_font - ); + } + core.fillText(ctx, boxName, (leftbar_right + leftbar_x) / 2, arrow_y + 2, boxName_color, boxName_font); ///// *** 底栏按钮 var pageBtn_radius = 8; @@ -5647,47 +5605,20 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var bottomSpace = 8; ///// *** - core.drawItemListbox_setPageBtn( - ctx, - pageBtn_left, - pageBtn_right, - pageBtn_bottom, - pageBtn_radius, - pageBtn_borderStyle, - pageBtn_borderWidth - ); + drawItemListbox_setPageBtn(ctx, pageBtn_left, pageBtn_right, pageBtn_bottom, pageBtn_radius, pageBtn_borderStyle, pageBtn_borderWidth); var page = info.page || 1; var pageFontSize = pageBtn_radius * 2 - 4; var pageFont = core.ui._buildFont(pageFontSize); - core.setPageItems(page); + setPageItems(page); var num = itemNum; if (core.status.event.id == "equipbox") num -= 5; var maxPage = info.maxPage; var pageText = page + " / " + maxPage; core.setTextAlign(ctx, "center"); core.setTextBaseline(ctx, "bottom"); - core.fillText( - ctx, - pageText, - (leftbar_x + leftbar_right) / 2, - pageBtn_bottom, - pageText_color, - pageFont - ); - core.addUIEventListener( - start_x, - start_y, - leftbar_right - start_x, - arrow_y - start_y + 13, - changeBox - ); - var itembar_height = Math.ceil( - pageBtn_bottom - - pageBtn_radius * 2 - - pageBtn_borderWidth / 2 - - bottomSpace - - itembar_top - ); + core.fillText(ctx, pageText, (leftbar_x + leftbar_right) / 2, pageBtn_bottom, pageText_color, pageFont); + addUIEventListener(start_x, start_y, leftbar_right - start_x, arrow_y - start_y + 13, changeBox); + var itembar_height = Math.ceil(pageBtn_bottom - pageBtn_radius * 2 - pageBtn_borderWidth / 2 - bottomSpace - itembar_top); var oneItemHeight = (itembar_height - 4) / itemNum; return { x: start_x, @@ -5700,12 +5631,12 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = y: itembar_top, width: itembar_right - arrow_x, height: itembar_height, - oneItemHeight: oneItemHeight, - }, - }; - }; + oneItemHeight: oneItemHeight + } + } + } - this.drawItemListbox = function (ctx, obj) { + function drawItemListbox(ctx, obj) { ctx = ctx || core.canvas.ui; var itembar_x = obj.x, itembar_y = obj.y, @@ -5738,16 +5669,9 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = ///// *** core.setAlpha(ctx, itembar_alpha); - core.fillRect( - ctx, - itembar_x, - itembar_y, - itembar_width, - itembar_height, - itembar_style - ); + core.fillRect(ctx, itembar_x, itembar_y, itembar_width, itembar_height, itembar_style); core.setAlpha(ctx, 1); - var pageItems = core.setPageItems(page); + var pageItems = setPageItems(page); var marginHeight = itembar_marginHeightRatio * oneItemHeight; core.setTextBaseline(ctx, "middle"); var originColor = itemName_color; @@ -5756,30 +5680,13 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var item = pageItems[i]; // 设置某个的字体颜色的一个例子 // if (item.id == "xxx") itemName_color = "green"; - core.drawItemListbox_drawItem( - ctx, - item_x, - item_right, - item_y, - oneItemHeight, - item_marginLeft, - marginHeight, - itemName_color, - pageItems[i] - ); - if (index == i + 1) - core.ui._drawWindowSelector( - item_selector, - item_x + 1, - item_y - 1, - item_right - item_x - 2, - oneItemHeight - 2 - ); + drawItemListbox_drawItem(ctx, item_x, item_right, item_y, oneItemHeight, item_marginLeft, marginHeight, itemName_color, pageItems[i]); + if (index == i + 1) core.ui._drawWindowSelector(item_selector, item_x + 1, item_y - 1, item_right - item_x - 2, oneItemHeight - 2); item_y += oneItemHeight; } - }; + } - this.drawToolboxRightbar = function (ctx, obj) { + function drawToolboxRightbar(ctx, obj) { ctx = ctx || core.canvas.ui; var info = core.status.thisUIEventInfo || {}; var page = info.page || 1, @@ -5792,6 +5699,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var toolboxRight = start_x + width, toolboxBottom = start_y + height; + ///// *** 侧边栏(rightbar)背景设置(物品介绍) var rightbar_width = width * 0.4; var rightbar_height = height; @@ -5801,15 +5709,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var rightbar_x = toolboxRight - rightbar_width - rightbar_lineWidth / 2; var rightbar_y = start_y; - core.drawLine( - ctx, - rightbar_x, - rightbar_y, - rightbar_x, - rightbar_y + rightbar_height, - rightbar_lineStyle, - rightbar_lineWidth - ); + core.drawLine(ctx, rightbar_x, rightbar_y, rightbar_x, rightbar_y + rightbar_height, rightbar_lineStyle, rightbar_lineWidth); // 获取道具id(有可能为null) var itemId = select.id; @@ -5844,23 +5744,21 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = itemNameColor = "#fff", itemNameFont = core.ui._buildFont(itemNameFontSize, true); var itemName_x = iconRect_right + space; - var itemName_middle = - iconRect_y + iconRect_height / 2 + iconRect_lineWidth; + var itemName_middle = iconRect_y + iconRect_height / 2 + iconRect_lineWidth; // 修改这里可以编辑未选中道具时的默认值 var defaultItem = { cls: "constants", name: "未知道具", - text: "没有道具最永久", - }; + text: "没有道具最永久" + } var defaultEquip = { cls: "equips", name: "未知装备", text: "一无所有,又何尝不是一种装备", - equipCls: "无", equip: { - type: "装备", - }, - }; + type: "装备" + } + } ///// *** var originItem = item; @@ -5870,9 +5768,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = itemName = item.name, itemText = item.text; itemText = core.replaceText(itemText); - if (itemText[0] == "," || itemText[0] == ",") - itemText = itemText.substring(1); - + if (!itemText) itemText = '该道具无描述。' /* 一个根据道具id修改道具名字(右栏)的例子 * if (item.id == "xxx") itemNameColor = "red"; */ @@ -5959,12 +5855,12 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = ((compare2?.percentage[name] || 1))) ); - } if (nowValue == newValue) continue; var color = newValue > nowValue ? "#00FF00" : "#FF0000"; nowValue = core.formatBigNumber(nowValue); newValue = core.formatBigNumber(newValue); + if (name === "mdef") { nowValue += '%'; newValue += '%' @@ -6016,39 +5912,31 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = ///// *** // 获取圆心位置 - var btn_x = btnRight - btnRadius - btnBorderWidth / 2, - btn_y = btnBottom - btnRadius - btnBorderWidth / 2; - core.drawToolbox_setExitBtn( - ctx, - btn_x, - btn_y, - btnRadius, - btnBorderStyle, - btnBorderWidth - ); + var btn_x = btnRight - btnRadius - btnBorderWidth / 2; + btn_y = btnBottom - btnRadius - btnBorderWidth / 2; + drawToolbox_setExitBtn(ctx, btn_x, btn_y, btnRadius, btnBorderStyle, btnBorderWidth); ///// *** 使用按钮设置 var useBtnHeight = btnRadius * 2; // 这里不设置useBtnWidth而是根据各项数据自动得出width - var useBtnRadius = useBtnHeight / 2; + var useBtnRadius = useBtnHeight / 4; var useBtn_x = rightbar_x + 4, useBtn_y = btnBottom - useBtnHeight; var useBtnBorderStyle = "#fff"; var useBtnBorderWidth = btnBorderWidth; + const batchUseBtn_x = useBtn_x + 50; // 个人觉得,搞这么多参数还不如硬编码 + const hideBtn_y = useBtn_y - useBtnHeight - 8; ///// *** - core.drawToolbox_setUseBtn( - ctx, - useBtn_x, - useBtn_y, - useBtnRadius, - useBtnHeight, - useBtnBorderStyle, - useBtnBorderWidth - ); - }; + drawToolbox_setUseBtn(ctx, useBtn_x, useBtn_y, useBtnRadius, useBtnHeight, useBtnBorderStyle, useBtnBorderWidth); + if (core.status.event.id === 'toolbox') { + drawToolbox_setBatchUseBtn(ctx, batchUseBtn_x, useBtn_y, useBtnRadius, useBtnHeight, useBtnBorderStyle, useBtnBorderWidth); + } + drawToolbox_setHideBtn(ctx, useBtn_x, hideBtn_y, useBtnRadius, useBtnHeight, useBtnBorderStyle, useBtnBorderWidth); + drawToolbox_setShowHideBtn(ctx, rightbar_x, useBtn_y, useBtnHeight, useBtnBorderStyle); + } - this.drawEquipbox_drawOthers = function (ctx, obj) { + function drawEquipbox_drawOthers(ctx, obj) { var info = core.status.thisUIEventInfo; ///// *** 装备格设置 @@ -6115,7 +6003,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var borderStyle = selectBorder ? box_selectBorderStyle : box_borderStyle; - core.drawEquipbox_drawOne( + drawEquipbox_drawOne( ctx, name, id, @@ -6132,7 +6020,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var todo = new Function( "core.clickOneEquipbox('" + id + "'," + i + ")" ); - core.addUIEventListener( + addUIEventListener( box_x - box_borderWidth / 2, box_y - box_borderWidth / 2, oneBoxWidth, @@ -6207,7 +6095,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var borderStyle = selectBorder ? box_selectBorderStyle : box_borderStyle; - core.drawEquipbox_drawOne( + drawEquipbox_drawOne( ctx, name, id, @@ -6224,7 +6112,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var todo = new Function( "core.clickOneEquipbox('" + id + "'," + i + ")" ); - core.addUIEventListener( + addUIEventListener( box_x - box_borderWidth / 2, box_y - box_borderWidth / 2, oneBoxWidth, @@ -6233,87 +6121,53 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = ); box_x += space_x + oneBoxWidth; } - }; + + } this.drawToolbox = function (ctx) { ctx = ctx || core.canvas.ui; core.status.thisEventClickArea = []; - var info = core.drawBoxBackground(ctx); + var info = drawBoxBackground(ctx); info.itemNum = itemNum; - core.drawItemListbox(ctx, info.obj); - core.drawToolboxRightbar(ctx, info); + drawItemListbox(ctx, info.obj); + drawToolboxRightbar(ctx, info); core.setTextBaseline(ctx, "alphabetic"); core.setTextAlign("left"); - }; + } var reduceItem = 4; this.drawEquipbox = function (ctx) { ctx = ctx || core.canvas.ui; core.status.thisEventClickArea = []; - var info = core.drawBoxBackground(ctx); + var info = drawBoxBackground(ctx); info.itemNum = itemNum - reduceItem; info.obj.y += info.obj.oneItemHeight * reduceItem; info.obj.height -= info.obj.oneItemHeight * reduceItem; - core.drawItemListbox(ctx, info.obj); - core.drawEquipbox_drawOthers(ctx, info); - core.drawToolboxRightbar(ctx, info); + drawItemListbox(ctx, info.obj); + drawEquipbox_drawOthers(ctx, info); + drawToolboxRightbar(ctx, info); core.setTextBaseline(ctx, "alphabetic"); core.setTextAlign("left"); - }; + } - this.drawEquipbox_drawOne = function ( - ctx, - name, - id, - x, - y, - width, - height, - space, - font, - color, - style, - lineWidth - ) { - if (id) - core.drawIcon( - ctx, - id, - x + lineWidth / 2, - y + lineWidth / 2, - width, - height - ); - core.strokeRect( - ctx, - x, - y, - width + lineWidth, - height + lineWidth, - style, - lineWidth - ); + + function drawEquipbox_drawOne(ctx, name, id, x, y, width, height, space, font, color, style, lineWidth) { + if (id) core.drawIcon(ctx, id, x + lineWidth / 2, y + lineWidth / 2, width, height); + core.strokeRect(ctx, x, y, width + lineWidth, height + lineWidth, style, lineWidth); core.setTextAlign(ctx, "center"); core.setTextBaseline(ctx, "top"); var tx = (x + x + lineWidth / 2 + width) / 2, - ty = y + height + (lineWidth / 2) * 3 + space; + ty = y + height + lineWidth / 2 * 3 + space; core.fillText(ctx, name, tx, ty, color, font); + + core.setAlpha(ctx, 1); + core.setTextBaseline(ctx, "alphabetic"); core.setTextAlign("left"); - }; + } - this.drawItemListbox_drawItem = function ( - ctx, - left, - right, - top, - height, - marginLeft, - marginHeight, - style, - id - ) { + function drawItemListbox_drawItem(ctx, left, right, top, height, marginLeft, marginHeight, style, id) { var info = core.status.thisUIEventInfo; var nowClick = info.index; var item = core.material.items[id] || {}; @@ -6322,48 +6176,29 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var fontSize = Math.floor(height - marginHeight * 2); core.setTextAlign(ctx, "right"); var numText = "x" + num; - core.fillText( - ctx, - numText, - right - marginLeft, - top + height / 2, - style, - core.ui._buildFont(fontSize) - ); - if (name != "???") - core.drawIcon( - ctx, - id, - left + marginLeft, - top + marginHeight, - fontSize, - fontSize - ); + core.fillText(ctx, numText, right - marginLeft, top + height / 2, style, core.ui._buildFont(fontSize)); + + const hideInfo = core.getFlag('hideInfo', {}); + if (item && (hideInfo.hasOwnProperty(id) ? hideInfo[id] : item.hideInToolbox)) core.setAlpha(ctx, 0.5); + + if (name != "???") core.drawIcon(ctx, id, left + marginLeft, top + marginHeight, fontSize, fontSize); var text_x = left + marginLeft + fontSize + 2; var maxWidth = right - core.calWidth(ctx, numText) - text_x; core.setTextAlign(ctx, "left"); - core.fillText( - ctx, - name, - text_x, - top + height / 2, - style, - core.ui._buildFont(fontSize), - maxWidth - ); - var todo = new Function("core.clickItemFunc('" + id + "');"); - core.addUIEventListener(left, top, right - left, height, todo); - }; + core.fillText(ctx, name, text_x, top + height / 2, style, core.ui._buildFont(fontSize), maxWidth); + core.setAlpha(ctx, 1); - this.setPageItems = function (page) { + var todo = new Function("core.clickItemFunc('" + id + "');"); + addUIEventListener(left, top, right - left, height, todo); + } + + function setPageItems(page) { var num = itemNum; if (core.status.event.id == "equipbox") num -= reduceItem; var info = core.status.thisUIEventInfo; if (!info) return; page = page || info.page; - var items = core.getToolboxItems( - core.status.event.id == "toolbox" ? "all" : "equips" - ); + var items = core.getToolboxItems(core.status.event.id == "toolbox" ? "all" : "equips", core.getFlag('showHideItem', false)); info.allItems = items; var maxPage = Math.ceil(items.length / num); info.maxPage = maxPage; @@ -6373,35 +6208,27 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = if (items.length == 0 && pageItems.length == 0) info.index = null; if (pageItems.length == 0 && info.page > 1) { info.page = Math.max(1, info.page - 1); - return core.setPageItems(info.page); + return setPageItems(info.page); } return pageItems; - }; + } - this.drawToolbox_setExitBtn = function (ctx, x, y, r, style, lineWidth) { + function drawToolbox_setExitBtn(ctx, x, y, r, style, lineWidth) { core.strokeCircle(ctx, x, y, r, style, lineWidth); ctx.textAlign = "center"; ctx.textBaseline = "middle"; var textSize = Math.sqrt(2) * r; - core.fillText( - ctx, - "x", - x, - y, - style, - core.ui._buildFont(textSize), - textSize - ); + core.fillText(ctx, "x", x, y, style, core.ui._buildFont(textSize), textSize); core.setTextAlign(ctx, "start"); core.setTextBaseline(ctx, "top"); var todo = function () { core.closePanel(); - }; - core.addUIEventListener(x - r, y - r, r * 2, r * 2, todo); - }; + } + addUIEventListener(x - r, y - r, r * 2, r * 2, todo); + } - this.drawToolbox_setUseBtn = function (ctx, x, y, r, h, style, lineWidth) { + function drawToolbox_setUseBtn(ctx, x, y, r, h, style, lineWidth) { core.setTextAlign(ctx, "left"); core.setTextBaseline(ctx, "top"); var fontSize = h - 4; @@ -6415,55 +6242,194 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var todo = function () { core.useSelectItemInBox(); - }; - core.addUIEventListener(x, y, w, h, todo); + } + addUIEventListener(x, y, w, h, todo); + } + + function getSelectedItem() { + var info = core.status.thisUIEventInfo; + if (!(info && info.select.id && ["toolbox", "equipbox"].includes(core.status.event.id))) { + core.drawFailTip('发生了未知错误!'); + return; + } + return info.select.id; + } + + function batchUse(item, count) { + try { + const itemCount = core.itemCount(item); + if (count > itemCount) count = itemCount; + core.closePanel(); + for (let i = 0; i < count; i++) { + if (core.canUseItem(item)) core.useItem(item); + else return; + } + } catch (e) { + console.error(e); + core.drawFailTip('批量使用时出现未知错误!'); + } + } + + function drawToolbox_setBatchUseBtn(ctx, x, y, r, h, style, lineWidth) { + try { + const selectedItem = getSelectedItem(); + let canBatchUse = eval(core.material.items[selectedItem]?.canBatchUse); + if (!canBatchUse) return; + } catch (error) { + console.error(error); + return; + } + core.setTextAlign(ctx, "left"); + core.setTextBaseline(ctx, "top"); + var fontSize = h - 4; + var font = core.ui._buildFont(fontSize); + var text = "批量使用"; + var w = core.calWidth(ctx, text, font) + 2 * r + lineWidth / 2; + + core.strokeRoundRect(ctx, x, y, w, h, r, style, lineWidth); + core.fillText(ctx, text, x + r, y + lineWidth / 2 + 2, style, font); + + var todo = function () { + core.utils.myprompt('输入要使用该物品的次数(0~99)。', null, (value) => { + + value = parseInt(value); + const id = getSelectedItem(); + + if (Number.isNaN(value) || value < 0 || value > 99) { + core.drawFailTip('输入不合法!'); + return; + } + if (!core.canUseItem(id)) { + core.drawFailTip('当前无法使用该道具!'); + return; + } + core.closePanel(); + batchUse(id, value); + }); + } + addUIEventListener(x, y, w, h, todo); + } + + function drawToolbox_setHideBtn(ctx, x, y, r, h, style, lineWidth) { + core.setTextAlign(ctx, "left"); + core.setTextBaseline(ctx, "top"); + var fontSize = h - 4; + var font = core.ui._buildFont(fontSize); + var text = "显示/隐藏"; + var w = core.calWidth(ctx, text, font) + 2 * r + lineWidth / 2; + + core.strokeRoundRect(ctx, x, y, w, h, r, style, lineWidth); + core.fillText(ctx, text, x + r, y + lineWidth / 2 + 2, style, font); + + var todo = function () { + //debugger; + var id = getSelectedItem(); + let hideInfo = core.getFlag('hideInfo', {}); + console.log(id); + if (hideInfo.hasOwnProperty(id)) { + hideInfo[id] = !hideInfo[id]; + core.setFlag('hideInfo', hideInfo); + } else { + hideInfo[id] = !core.material.items[id].hideInToolbox; + core.setFlag('hideInfo', hideInfo); + } + if (core.status.event.id === 'toolbox') core.plugin.drawToolbox(); + else if (core.status.event.id === 'equipbox') core.plugin.drawEquipbox(); + } + addUIEventListener(x, y, w, h, todo); + } + + ui.prototype.getToolboxItems = function (cls, showHide) { + let list = Object.keys(core.status.hero.items[cls] || {});; + if (cls === "all") { + for (let name in core.status.hero.items) { + if (name == "equips") continue; + list = list.concat(Object.keys(core.status.hero.items[name])); + } + if (!showHide) list = list.filter(function (id2) { + const hideInfo = core.getFlag("hideInfo", {}); + if (hideInfo.hasOwnProperty(id2)) return !hideInfo[id2]; + else return !core.material.items[id2].hideInToolbox; + }); + list = list.sort(); + return list; + } + if (cls === "equips") { + if (!showHide) list = list.filter(function (id2) { + const hideInfo = core.getFlag("hideInfo", {}); + if (hideInfo.hasOwnProperty(id2)) return !hideInfo[id2]; + else return !core.material.items[id2].hideInToolbox; + }); + + list = list.sort(); + return list; + } + if (this.uidata.getToolboxItems) { + return this.uidata.getToolboxItems(cls, showHide); + } + if (!showHide) list = list.filter(function (id2) { + return !core.material.items[id2].hideInToolbox; + }); + list = list.sort(); + return list; }; - this.drawItemListbox_setPageBtn = function ( - ctx, - left, - right, - bottom, - r, - style, - lineWidth - ) { + function drawToolbox_setShowHideBtn(ctx, x, y, h, style) { + core.setTextAlign(ctx, "left"); + core.setTextBaseline(ctx, "top"); + var fontSize = h - 6; + var font = core.ui._buildFont(fontSize); + var text = "显示隐藏"; + var w = core.calWidth(ctx, text, font) + h += 4; + const squareSize = h - 6; + + x -= w + squareSize + 26; + + const border = 2; + core.fillRect(ctx, x, y, squareSize, squareSize, ' #F5F5F5'); + if (core.hasFlag('showHideItem')) { + core.fillRect(ctx, x + border, y + border, squareSize - 2 * border, squareSize - 2 * border, 'lime'); + } + core.fillText(ctx, text, x + squareSize + 2, y + 4, style, font); + + var todo = function () { + core.setFlag('showHideItem', !core.getFlag('showHideItem', false)); + if (core.status.event.id === 'toolbox') core.plugin.drawToolbox(); + else if (core.status.event.id === 'equipbox') core.plugin.drawEquipbox(); + } + addUIEventListener(x, y, w, h, todo); + } + + function drawItemListbox_setPageBtn(ctx, left, right, bottom, r, style, lineWidth) { var offset = lineWidth / 2 + r; var x = left + offset; var y = bottom - offset; - var pos = (Math.sqrt(2) / 2) * (r - lineWidth / 2); - core.fillPolygon( - ctx, - [ - [x - pos, y], - [x + pos - 2, y - pos], - [x + pos - 2, y + pos], - ], - style - ); + var pos = Math.sqrt(2) / 2 * (r - lineWidth / 2); + core.fillPolygon(ctx, [ + [x - pos, y], + [x + pos - 2, y - pos], + [x + pos - 2, y + pos] + ], style); core.strokeCircle(ctx, x, y, r, style, lineWidth); var todo = function () { core.addItemListboxPage(-1); - }; - core.addUIEventListener(x - r - 2, y - r - 2, r * 2 + 4, r * 2 + 4, todo); + } + addUIEventListener(x - r - 2, y - r - 2, r * 2 + 4, r * 2 + 4, todo); x = right - offset; - core.fillPolygon( - ctx, - [ - [x + pos, y], - [x - pos + 2, y - pos], - [x - pos + 2, y + pos], - ], - style - ); + core.fillPolygon(ctx, [ + [x + pos, y], + [x - pos + 2, y - pos], + [x - pos + 2, y + pos] + ], style); core.strokeCircle(ctx, x, y, r, style, lineWidth); var todo = function () { core.addItemListboxPage(1); - }; - core.addUIEventListener(x - r - 2, y - r - 2, r * 2 + 4, r * 2 + 4, todo); - }; + } + addUIEventListener(x - r - 2, y - r - 2, r * 2 + 4, r * 2 + 4, todo); + } this.clickItemFunc = function (id) { var info = core.status.thisUIEventInfo; @@ -6471,47 +6437,21 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = if (info.select.id == id) return core.useSelectItemInBox(); info.select = {}; info.select.id = id; - core.setIndexAndSelect("index"); - core.refreshBox(); - }; + core.setIndexAndSelect('index'); + refreshBox(); + } this.clickOneEquipbox = function (id, type) { var info = core.status.thisUIEventInfo; if (!info) return; - if (info.select.id == id && info.select.type == type) - core.useSelectItemInBox(); - else - core.status.thisUIEventInfo.select = { - id: id, - type: type, - action: "unload", - }; - return core.refreshBox(); - }; - - core.ui.getToolboxItems = function (cls) { - var list = Object.keys(core.status.hero.items[cls] || {}); - if (cls == "all") { - for (var name in core.status.hero.items) { - if (name == "equips") continue; - list = list.concat(Object.keys(core.status.hero.items[name])); - } - return list - .filter(function (id) { - return !core.material.items[id].hideInToolbox; - }) - .sort(); + if (info.select.id == id && info.select.type == type) core.useSelectItemInBox(); + else core.status.thisUIEventInfo.select = { + id: id, + type: type, + action: "unload" } - - if (this.uidata.getToolboxItems) { - return this.uidata.getToolboxItems(cls); - } - return list - .filter(function (id) { - return !core.material.items[id].hideInToolbox; - }) - .sort(); - }; + return refreshBox(); + } this.useSelectItemInBox = function () { var info = core.status.thisUIEventInfo; @@ -6560,30 +6500,22 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = } } core.updateStatusBar(); - }; + } + this.setIndexAndSelect = function (toChange) { var info = core.status.thisUIEventInfo; if (!info) return; - core.setPageItems(info.page); + setPageItems(info.page); var index = info.index || 1; var items = info.pageItems; - /*if (info.select.type != null) { - var type = info.select.type; - id = core.getEquip(type); - info.index = null; - info.select = { - id: id, - action: "unload", - type: type, - }; - return; - } else {*/ + info.select.action = null; info.select.type = null; if (toChange == "index") info.index = items.indexOf(info.select.id) + 1; info.select.id = items[info.index - 1]; - //} - }; + + + } this.addItemListboxPage = function (num) { var info = core.status.thisUIEventInfo; @@ -6594,10 +6526,10 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = if (info.page <= 0) info.page = maxPage; if (info.page > maxPage) info.page = 1; info.index = 1; - core.setPageItems(info.page); + setPageItems(info.page); core.setIndexAndSelect("select"); - core.refreshBox(); - }; + refreshBox(); + } this.addItemListboxIndex = function (num) { var info = core.status.thisUIEventInfo; @@ -6608,8 +6540,8 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = if (info.index <= 0) info.index = 1; if (info.index > maxItem) info.index = maxItem; core.setIndexAndSelect("select"); - core.refreshBox(); - }; + refreshBox(); + } this.addEquipboxType = function (num) { var info = core.status.thisUIEventInfo; @@ -6619,47 +6551,45 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var max = core.status.globalAttribute.equipName.length; if (info.select.type >= max) { info.select = {}; - core.setIndexAndSelect("select"); + core.setIndexAndSelect("select") return core.addItemListboxPage(0); } else { var m = Math.abs(info.select.type); if (info.select.type < 0) info.select.type = max - m; - core.setIndexAndSelect("select"); - core.refreshBox(); + core.setIndexAndSelect("select") + refreshBox(); return; } - }; + } core.actions._keyDownToolbox = function (keycode) { if (!core.status.thisEventClickArea) return; - if (keycode == 37) { - // left + if (keycode == 37) { // left core.addItemListboxPage(-1); return; } - if (keycode == 38) { - // up + if (keycode == 38) { // up core.addItemListboxIndex(-1); return; } - if (keycode == 39) { - // right + if (keycode == 39) { // right core.addItemListboxPage(1); return; } - if (keycode == 40) { - // down + if (keycode == 40) { // down core.addItemListboxIndex(1); return; } - }; + } ////// 工具栏界面时,放开某个键的操作 ////// core.actions._keyUpToolbox = function (keycode) { if (keycode == 81) { core.ui.closePanel(); - if (core.isReplaying()) core.control._replay_equipbox(); - else core.openEquipbox(); + if (core.isReplaying()) + core.control._replay_equipbox(); + else + core.openEquipbox(); return; } if (keycode == 84 || keycode == 27 || keycode == 88) { @@ -6673,40 +6603,36 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = } return; } - }; + } core.actions._keyDownEquipbox = function (keycode) { if (!core.status.thisEventClickArea) return; - if (keycode == 37) { - // left + if (keycode == 37) { // left var info = core.status.thisUIEventInfo; if (info.index != null) return core.addItemListboxPage(-1); return core.addEquipboxType(-1); } - if (keycode == 38) { - // up + if (keycode == 38) { // up var info = core.status.thisUIEventInfo; if (info.index == 1) { info.select.type = core.status.globalAttribute.equipName.length - 1; core.setIndexAndSelect(); - return core.refreshBox(); + return refreshBox(); } if (info.index) return core.addItemListboxIndex(-1); return core.addEquipboxType(-1 * info.equips); } - if (keycode == 39) { - // right + if (keycode == 39) { // right var info = core.status.thisUIEventInfo; if (info.index != null) return core.addItemListboxPage(1); return core.addEquipboxType(1); } - if (keycode == 40) { - // down + if (keycode == 40) { // down var info = core.status.thisUIEventInfo; if (info.index) return core.addItemListboxIndex(1); return core.addEquipboxType(info.equips); } - }; + } core.actions._keyUpEquipbox = function (keycode, altKey) { if (altKey && keycode >= 48 && keycode <= 57) { @@ -6715,8 +6641,10 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = } if (keycode == 84) { core.ui.closePanel(); - if (core.isReplaying()) core.control._replay_toolbox(); - else core.openToolbox(); + if (core.isReplaying()) + core.control._replay_toolbox(); + else + core.openToolbox(); return; } if (keycode == 81 || keycode == 27 || keycode == 88) { @@ -6728,65 +6656,49 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = if (info.select) core.useSelectItemInBox(); return; } - }; + } - core.registerAction( - "ondown", - "inEventClickAction", - function (x, y, px, py) { - if (!core.status.thisEventClickArea) return false; - // console.log(px + "," + py); - var info = core.status.thisEventClickArea; - for (var i = 0; i < info.length; i++) { - var obj = info[i]; - if ( - px >= obj.x && - px <= obj.x + obj.width && - py > obj.y && - py < obj.y + obj.height - ) { - if (obj.todo) obj.todo(); - break; - } + core.registerAction("ondown", "inEventClickAction", function (x, y, px, py) { + if (!core.status.thisEventClickArea) return false; + var info = core.status.thisEventClickArea; + for (var i = 0; i < info.length; i++) { + var obj = info[i]; + if (px >= obj.x && px <= obj.x + obj.width && py > obj.y && py < obj.y + obj.height) { + if (obj.todo) obj.todo(); + break; } - return true; - }, - 51 - ); - core.registerAction( - "onclick", - "stopClick", - function () { - if (core.status.thisEventClickArea) return true; - }, - 51 - ); + } + return true; + }, 51); + core.registerAction("onclick", "stopClick", function () { + if (core.status.thisEventClickArea) return true; + }, 51); - this.addUIEventListener = function (x, y, width, height, todo) { + function addUIEventListener(x, y, width, height, todo) { if (!core.status.thisEventClickArea) return; var obj = { x: x, y: y, width: width, height: height, - todo: todo, - }; + todo: todo + } core.status.thisEventClickArea.push(obj); - }; + } this.initThisEventInfo = function () { core.status.thisUIEventInfo = { page: 1, - select: {}, + select: {} }; core.status.thisEventClickArea = []; - }; + } - this.refreshBox = function () { + function refreshBox() { if (!core.status.event.id) return; if (core.status.event.id == "toolbox") core.drawToolbox(); else core.drawEquipbox(); - }; + } core.ui.closePanel = function () { if (core.status.hero && core.status.hero.flags) { @@ -6807,8 +6719,8 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.status.event.ui = null; core.status.event.interval = null; core.status.thisUIEventInfo = null; - core.status.thisEventClickArea = null; - }; + core.status.thisEventClickArea = null + } this.getItemClsName = function (item) { if (item == null) return itemClsName; @@ -6817,27 +6729,27 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var type = core.getEquipTypeById(item.id); return core.status.globalAttribute.equipName[type]; } else return itemClsName[item.cls] || item.cls; - }; + } core.events.openToolbox = function (fromUserAction) { if (core.isReplaying()) return; - if (!this._checkStatus("toolbox", fromUserAction)) return; + if (!this._checkStatus('toolbox', fromUserAction)) return; core.initThisEventInfo(); - let info = core.status.thisUIEventInfo; - info.index = 1; - core.setIndexAndSelect("select"); + let info = core.status.thisUIEventInfo + info.index = 1 + core.setIndexAndSelect('select') core.drawToolbox(); - }; + } core.events.openEquipbox = function (fromUserAction) { if (core.isReplaying()) return; - if (!this._checkStatus("equipbox", fromUserAction)) return; + if (!this._checkStatus('equipbox', fromUserAction)) return; core.initThisEventInfo(); - let info = core.status.thisUIEventInfo; - info.select.type = 0; - core.setIndexAndSelect("select"); + let info = core.status.thisUIEventInfo + info.select.type = 0 + core.setIndexAndSelect('select') core.drawEquipbox(); - }; + } core.control._replay_toolbox = function () { if (!core.isPlaying() || !core.isReplaying()) return; @@ -6846,9 +6758,9 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = return core.drawTip("请等待当前事件的处理结束"); core.lockControl(); - core.status.event.id = "toolbox"; + core.status.event.id = 'toolbox'; core.drawToolbox(); - }; + } core.control._replay_equipbox = function () { if (!core.isPlaying() || !core.isReplaying()) return; @@ -6857,92 +6769,113 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = return core.drawTip("请等待当前事件的处理结束"); core.lockControl(); - core.status.event.id = "equipbox"; + core.status.event.id = 'equipbox'; core.drawEquipbox(); - }; + } core.control._replayAction_item = function (action) { if (action.indexOf("item:") != 0) return false; var itemId = action.substring(5); if (!core.canUseItem(itemId)) return false; - if ( - core.material.items[itemId].hideInReplay || - core.status.replay.speed == 24 - ) { + if (core.material.items[itemId].hideInReplay || core.status.replay.speed == 24) { core.useItem(itemId, false, core.replay); return true; } core.status.event.id = "toolbox"; core.initThisEventInfo(); var info = core.status.thisUIEventInfo; - var items = core.getToolboxItems("all"); - core.setPageItems(1); + var items = core.getToolboxItems("all", core.getFlag('showHideItem', false)); + setPageItems(1); var index = items.indexOf(itemId) + 1; info.page = Math.ceil(index / info.maxItem); info.index = index % info.maxItem || info.maxItem; core.setIndexAndSelect("select"); - core.setPageItems(info.page); + setPageItems(info.page); core.drawToolbox(); setTimeout(function () { core.ui.closePanel(); core.useItem(itemId, false, core.replay); }, core.control.__replay_getTimeout()); return true; - }; + } core.control._replayAction_equip = function (action) { if (action.indexOf("equip:") != 0) return false; var itemId = action.substring(6); - var items = core.getToolboxItems("equips"); + var items = core.getToolboxItems('equips', core.getFlag('showHideItem', false)); var index = items.indexOf(itemId) + 1; - if (index < 1) return false; + if (index < 1) { + core.removeFlag('__doNotCheckAutoEvents__'); + return false; + } + + var cb = function () { + var next = core.status.replay.toReplay[0] || ""; + if (!next.startsWith('equip:') && !next.startsWith('unEquip:')) { + core.removeFlag('__doNotCheckAutoEvents__'); + core.checkAutoEvents(); + } + core.replay(); + } + core.setFlag('__doNotCheckAutoEvents__', true); + core.status.route.push(action); - if ( - core.material.items[itemId].hideInReplay || - core.status.replay.speed == 24 - ) { - core.loadEquip(itemId, core.replay); + if (core.material.items[itemId].hideInReplay || core.status.replay.speed == 24) { + core.loadEquip(itemId, cb); return true; } core.status.event.id = "equipbox"; core.initThisEventInfo(); var info = core.status.thisUIEventInfo; - core.setPageItems(1); + setPageItems(1); info.page = Math.ceil(index / info.maxItem); info.index = index % info.maxItem || info.maxItem; core.setIndexAndSelect("select"); - core.setPageItems(info.page); + setPageItems(info.page); core.drawEquipbox(); setTimeout(function () { core.ui.closePanel(); - core.loadEquip(itemId, core.replay); + core.loadEquip(itemId, cb); }, core.control.__replay_getTimeout()); return true; - }; + } core.control._replayAction_unEquip = function (action) { if (action.indexOf("unEquip:") != 0) return false; var equipType = parseInt(action.substring(8)); - if (!core.isset(equipType)) return false; + if (!core.isset(equipType)) { + core.removeFlag('__doNotCheckAutoEvents__'); + return false; + } + + var cb = function () { + var next = core.status.replay.toReplay[0] || ""; + if (!next.startsWith('equip:') && !next.startsWith('unEquip:')) { + core.removeFlag('__doNotCheckAutoEvents__'); + core.checkAutoEvents(); + } + core.replay(); + } + core.setFlag('__doNotCheckAutoEvents__', true); + core.status.route.push(action); if (core.status.replay.speed == 24) { - core.unloadEquip(equipType, core.replay); + core.unloadEquip(equipType, cb); return true; } core.status.event.id = "equipbox"; core.initThisEventInfo(); var info = core.status.thisUIEventInfo; - core.setPageItems(1); + setPageItems(1); info.select.type = equipType; core.setIndexAndSelect(); core.drawEquipbox(); setTimeout(function () { core.ui.closePanel(); - core.unloadEquip(equipType, core.replay); + core.unloadEquip(equipType, cb); }, core.control.__replay_getTimeout()); return true; - }; - + } core.registerReplayAction("item", core.control._replayAction_item); core.registerReplayAction("equip", core.control._replayAction_equip); core.registerReplayAction("unEquip", core.control._replayAction_unEquip); @@ -21496,7 +21429,9 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = if (!attack && nowattacking) { let herodamage = enemyDiffList[turn].hp + if (herodamage > 0) herodamage = '+' + herodamage let text = herodamage === 0 ? "抵抗" : herodamage + Dove.MorePerform.ShowDamagePop.PopDamage( ctx, // 默认画布名称 270, // 英雄位置 x @@ -21504,8 +21439,8 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = text, // 伤害值 18, // 默认字体大小 "Arial", //默认字体 - null, // 默认颜色 - null, // 默认描边颜色 + typeof text === 'string' && text.startsWith('+') ? '#22FF44' : typeof text === 'string' ? "#FFFFFF" : null, // 默认颜色 + text === '抵抗' ? "#000000" : null, // 默认描边颜色 0, // 默认水平速度 -1, // 默认垂直速度 0, // 默认重力 @@ -21515,7 +21450,8 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = enemyInfo[v] += enemyDiffList[turn][v] } enemyanimateList[turn].forEach(v => animateOnAttack(v, true)) - const enemydamage = heroDiffList[turn].hp + let enemydamage = heroDiffList[turn].hp + if (enemydamage > 0) enemydamage = '+' + enemydamage text = enemydamage === 0 ? "抵抗" : enemydamage Dove.MorePerform.ShowDamagePop.PopDamage( ctx, // 默认画布名称 @@ -21524,8 +21460,8 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = text, // 伤害值 18, // 默认字体大小 "Arial", //默认字体 - null, // 默认颜色 - null, // 默认描边颜色 + typeof text === 'string' && text.startsWith('+') ? '#22FF44' : typeof text === 'string' ? "#FFFFFF" : null, // 默认颜色 + text === '抵抗' ? "#000000" : null, // 默认描边颜色 0, // 默认水平速度 -1, // 默认垂直速度 0, // 默认重力