From 4079bb9710abce498b45a1a97c3e2f929b6a22e5 Mon Sep 17 00:00:00 2001 From: strawberry42271 <2806566736@qq.com> Date: Wed, 5 Feb 2025 17:24:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8D=A2=E8=A3=85bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/MotaAction.g4 | 8 +- project/floors/yiqu1.js | 4 +- project/functions.js | 61 +- project/items.js | 6 +- project/plugins.js | 5362 ++++++++++++++++++++------------------- 5 files changed, 2743 insertions(+), 2698 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index eaa641e..e02ee40 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -4624,8 +4624,8 @@ IdString ; FixedId_List - : '生命'|'生命上限'|'攻击'|'防御'|'法强'|'魔攻比例'|'护盾比例'|'黄钥匙'|'蓝钥匙'|'红钥匙'|'金币'|'经验'|'魔力'|'魔力上限'|'当前横坐标'|'当前纵坐标'|'当前朝向'|'攻击增益'|'防御增益'|'护盾增益' - /*FixedId_List ['status:hp','status:hpmax','status:atk','status:def','status:spell','status:matk','status:mdef','item:yellowKey','item:blueKey','item:redKey','status:money','status:exp','status:mana','status:manamax','status:x','status:y','status:direction','buff:atk','buff:def','buff:mdef']*/; + : '生命'|'生命上限'|'攻击'|'防御'|'法强'|'魔攻比例'|'护盾比例'|'法抗比例'|'黄钥匙'|'蓝钥匙'|'红钥匙'|'金币'|'经验'|'魔力'|'魔力上限'|'当前横坐标'|'当前纵坐标'|'当前朝向'|'攻击增益'|'防御增益'|'法强增益'|'魔攻增益'|'法抗增益'|'护盾增益' + /*FixedId_List ['status:hp','status:hpmax','status:atk','status:def','status:spell','status:matk','status:mhp','status:mdef','item:yellowKey','item:blueKey','item:redKey','status:money','status:exp','status:mana','status:manamax','status:x','status:y','status:direction','buff:atk','buff:def','buff:spell','buff:matk','buff:mdef','buff:mhp']*/; Id_List : '变量' | '状态' | '物品' | '增益' | '独立开关' | '临时变量' |'全局存储' @@ -4640,8 +4640,8 @@ EnemyPoint_List /*EnemyPoint_List ['hp','atk','def','money','exp','point','name']*/; Equip_List - : '生命'|'生命上限'|'攻击'|'防御'|'法强'|'魔攻比例'|'护盾比例'|'魔力'|'魔力上限'|'速度' - /*Equip_List ['hp','hpmax','atk','def','spell','matk','mdef','mana','manamax','speed']*/; + : '生命'|'生命上限'|'攻击'|'防御'|'法强'|'魔攻比例'|'护盾比例'|'法抗百分比'|'魔力'|'魔力上限'|'速度' + /*Equip_List ['hp','hpmax','atk','def','spell','matk','mhp','mdef','mana','manamax','speed']*/; Key_List : '黄钥匙'|'蓝钥匙'|'红钥匙'|'绿钥匙'|'铁门钥匙' diff --git a/project/floors/yiqu1.js b/project/floors/yiqu1.js index ec80832..c7c3f66 100644 --- a/project/floors/yiqu1.js +++ b/project/floors/yiqu1.js @@ -48,8 +48,8 @@ main.floors.yiqu1= [140142, 0,120015,120028,201037, 0,201029, 0, 0, 0, 0, 0,110197], [140150, 0, 0,120019, 0, 0,201029, 0,110189,140,110191, 0,110205], [ 92, 0, 0,120019,201037,201037,201037, 0,110197,140,110199, 81,110224], - [ 0, 0, 0,120027, 0, 0, 0, 0,110197,140,110199, 0,110232], - [110191, 0, 0, 0, 0, 0,110189,140,140,140,110199, 0, 94], + [ 0, 0, 0,120027, 37, 37, 0, 0,110197,140,110199, 0,110232], + [110191, 0, 0, 0, 36, 35,110189,140,140,140,110199, 0, 94], [110199,140,140,110191, 0, 0,110197,140,140,110204,110207, 0, 0], [140,140,140,110199,90684,90684,110197,140,140,110199,110234, 0, 0], [140,140,140,110199,100307,100308,110197,140,140,110199, 0, 0, 0] diff --git a/project/functions.js b/project/functions.js index a9ae699..949d962 100644 --- a/project/functions.js +++ b/project/functions.js @@ -1450,31 +1450,30 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = if (play) core.doAction(); }, "getStatusLabel": function (name) { - // 返回某个状态英文名的对应中文标签,如atk -> 攻击,def -> 防御等。 - // 请注意此项仅影响 libs/ 下的内容(如绘制怪物手册、数据统计等) - // 自行定义的(比如获得道具效果)中用到的“攻击+3”等需要自己去对应地方修改 + // 返回某个状态英文名的对应中文标签,如atk -> 攻击,def -> 防御等。 + // 请注意此项仅影响 libs/ 下的内容(如绘制怪物手册、数据统计等) + // 自行定义的(比如获得道具效果)中用到的“攻击+3”等需要自己去对应地方修改 - return ( - { - name: "名称", - lv: "等级", - hpmax: "生命上限", - hp: "生命", - manamax: "魔力上限", - mana: "魔力", - atk: "攻击", - def: "防御", - spell: "法强", - matk: "魔攻比例", - mdef: "护盾比例", - speed: "速度", - money: "金币", - exp: "经验", - point: "加点", - steps: "步数", - }[name] || name - ); - }, + return ({ + name: "名称", + lv: "等级", + hpmax: "生命上限", + hp: "生命", + manamax: "魔力上限", + mana: "魔力", + atk: "攻击", + def: "防御", + spell: "法强", + matk: "魔攻比例", + mhp: "护盾比例", + mdef: "法抗比例", + speed: "速度", + money: "金币", + exp: "经验", + point: "加点", + steps: "步数", + } [name] || name); +}, "triggerDebuff": function (action, type) { // 毒衰咒效果的获得与解除 // action:获得还是解除;'get'表示获得,'remove'表示解除 @@ -1533,13 +1532,13 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = } }, "updateStatusBar": function () { - // 更新状态栏 - core.ui.statusBar.update(); - // 更新阻激夹域的伤害值 - core.updateCheckBlock(); - // 更新全地图显伤 - core.updateDamage(); - }, + // 更新状态栏 + core.ui.statusBar.update(); + // 更新阻激夹域的伤害值 + core.updateCheckBlock(); + // 更新全地图显伤 + core.updateDamage(); +}, "updateCheckBlock": function (floorId) { // 领域、夹击、阻击等的伤害值计算 floorId = floorId || core.status.floorId; diff --git a/project/items.js b/project/items.js index 95ed773..761cb9f 100644 --- a/project/items.js +++ b/project/items.js @@ -151,7 +151,7 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "type": 0, "animate": "sword", "value": { - "atk": 10 + "mdef": 10 }, "percentage": {} }, @@ -167,7 +167,7 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "type": "武器", "animate": "sword", "value": { - "atk": 20 + "mdef": 20 }, "percentage": {} }, @@ -248,7 +248,7 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "equip": { "type": 1, "value": { - "def": 10 + "mdef": 10 }, "percentage": {} }, diff --git a/project/plugins.js b/project/plugins.js index 27fd1e2..5f9ffbe 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -3736,591 +3736,588 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = // init() called in `afterLoadResources`. }, "override": function () { - core.statusBar.icons = { - floor: 0, - name: null, - lv: 1, - hpmax: 2, - hp: 3, - atk: 4, - def: 5, - mdef: 6, - money: 7, - exp: 8, - up: 9, - book: 10, - fly: 11, - toolbox: 12, - keyboard: 13, - shop: 14, - save: 15, - load: 16, - settings: 17, - play: 18, - pause: 19, - stop: 20, - speedDown: 21, - speedUp: 22, - rewind: 23, - equipbox: 24, - mana: 25, - skill: 26, - exit: 27, - btn1: 28, - btn2: 29, - btn3: 30, - btn4: 31, - btn5: 32, - btn6: 33, - btn7: 34, - alt: 35, - keys: 36, - help: 37, - battle: 38, - }; - core.actions._getClickLoc = function (x, y) { - var size = 32 * core.domStyle.scale; - var left = main.dom.gameDraw.offsetLeft + main.dom.gameGroup.offsetLeft; - var top = main.dom.gameDraw.offsetTop + main.dom.gameGroup.offsetTop; - var loc = { - x: Math.max(x - left, 0), - y: Math.max(y - top, 0), - size: size, - }; - return loc; - }; - core.ui._drawWindowSelector = function (background, x, y, w, h) { - w = Math.round(w) + 48; - h = Math.round(h); - var ctx = core.ui.createCanvas("_selector", x - 24, y, w, h, 165); - ctx.canvas.id = ""; - this._drawSelector(ctx, background, w, h); - }; + core.statusBar.icons = { + floor: 0, + name: null, + lv: 1, + hpmax: 2, + hp: 3, + atk: 4, + def: 5, + mdef: 6, + money: 7, + exp: 8, + up: 9, + book: 10, + fly: 11, + toolbox: 12, + keyboard: 13, + shop: 14, + save: 15, + load: 16, + settings: 17, + play: 18, + pause: 19, + stop: 20, + speedDown: 21, + speedUp: 22, + rewind: 23, + equipbox: 24, + mana: 25, + skill: 26, + exit: 27, + btn1: 28, + btn2: 29, + btn3: 30, + btn4: 31, + btn5: 32, + btn6: 33, + btn7: 34, + alt: 35, + keys: 36, + help: 37, + battle: 38, + }; + core.actions._getClickLoc = function (x, y) { + var size = 32 * core.domStyle.scale; + var left = main.dom.gameDraw.offsetLeft + main.dom.gameGroup.offsetLeft; + var top = main.dom.gameDraw.offsetTop + main.dom.gameGroup.offsetTop; + var loc = { + x: Math.max(x - left, 0), + y: Math.max(y - top, 0), + size: size, + }; + return loc; + }; + /* core.ui._drawWindowSelector = function (background, x, y, w, h) { + w = Math.round(w) + 48; + h = Math.round(h); + var ctx = core.ui.createCanvas("_selector", x - 24, y, w, h, 165); + ctx.canvas.id = ""; + this._drawSelector(ctx, background, w, h); + }; - core.ui._drawSelector = function (ctx, background, w, h, left, top) { - left = left || 0; - top = top || 0; - ctx = this.getContextByName(ctx); - if (!ctx) return; - if (typeof background == "string") - background = core.material.images.images[background]; - if (!(background instanceof Image)) return; - // badge - ctx.drawImage(background, 132, 68, 24, 24, left + 4, top + 4, 24, 24); - ctx.drawImage( - background, - 132, - 68, - 24, - 24, - w - left - 28, - top + 4, - 24, - 24 - ); - }; + core.ui._drawSelector = function (ctx, background, w, h, left, top) { + left = left || 0; + top = top || 0; + ctx = this.getContextByName(ctx); + if (!ctx) return; + if (typeof background == "string") + background = core.material.images.images[background]; + if (!(background instanceof Image)) return; + // badge + ctx.drawImage(background, 132, 68, 24, 24, left + 4, top + 4, 24, 24); + ctx.drawImage( + background, + 132, + 68, + 24, + 24, + w - left - 28, + top + 4, + 24, + 24 + ); + };*/ - enemys.prototype._nextCriticals_useBinarySearch = function ( - enemy, - info, - number, - x, - y, - floorId - ) { - var mon_hp = info.mon_hp, - hero_atk = core.status.hero.atk, - mon_def = info.mon_def, - pre = info.damage; - var list = []; - var start_atk = hero_atk; - if (info.__over__) { - start_atk += info.__overAtk__; - list.push([info.__overAtk__, -info.damage]); - } - var calNext = function (currAtk, maxAtk) { - var start = Math.floor(currAtk), - end = Math.floor(maxAtk); - if (start > end) return null; + enemys.prototype._nextCriticals_useBinarySearch = function ( + enemy, + info, + number, + x, + y, + floorId + ) { + var mon_hp = info.mon_hp, + hero_atk = core.status.hero.atk, + mon_def = info.mon_def, + pre = info.damage; + var list = []; + var start_atk = hero_atk; + if (info.__over__) { + start_atk += info.__overAtk__; + list.push([info.__overAtk__, -info.damage]); + } + var calNext = function (currAtk, maxAtk) { + var start = Math.floor(currAtk), + end = Math.floor(maxAtk); + if (start > end) return null; - while (start < end) { - var mid = Math.floor((start + end) / 2); - if (mid - start > end - mid) mid--; - var nextInfo = core.enemys.getDamageInfo( - enemy, - { atk: mid }, - x, - y, - floorId - ); - if (nextInfo == null || typeof nextInfo == "number") return null; - if (pre > nextInfo.damage) end = mid; - else start = mid + 1; - } - var nextInfo = core.enemys.getDamageInfo( - enemy, - { atk: start }, - x, - y, - floorId - ); - return nextInfo == null || - typeof nextInfo == "number" || - nextInfo.damage >= pre - ? null - : [start, nextInfo.damage]; - }; - var currAtk = start_atk; - while (true) { - var next = calNext(currAtk + 1, Number.MAX_SAFE_INTEGER, pre); - if (next == null) break; - currAtk = next[0]; - pre = next[1]; - list.push([currAtk - hero_atk, info.damage - pre]); - if (pre <= 0 && !core.flags.enableNegativeDamage) break; - if (list.length >= number) break; - } - if (list.length == 0) list.push([0, 0]); - return list; - }; - core.ui.clearMap = function (name, x, y, width, height) { - if (name == "all") { - for (var m in core.canvas) { - core.canvas[m].clearRect( - -32, - -32, - core.canvas[m].canvas.width + 32, - core.canvas[m].canvas.height + 32 - ); - } - core.clearMap("outerUI"); - core.dom.gif.innerHTML = ""; - core.removeGlobalAnimate(); - core.deleteCanvas(function (one) { - return one.startsWith("_bigImage_"); - }); - core.setWeather(null); - } else { - var ctx = this.getContextByName(name); - if (ctx) - ctx.clearRect( - x || 0, - y || 0, - width || ctx.canvas.width, - height || ctx.canvas.height - ); - } - }; - events.prototype.openBook = function (fromUserAction) { - if (core.isReplaying()) return; - // 如果能恢复事件(从callBook事件触发) - if ( - core.status.event.id == "book" && - core.events.recoverEvents(core.status.event.interval) - ) - return; - // 当前是book,且从“浏览地图”打开 - if (core.status.event.id == "book" && core.status.event.ui) { - core.status.boxAnimateObjs = []; - core.ui._drawViewMaps(core.status.event.ui); - return; - } - // 从“浏览地图”页面打开 - if (core.status.event.id == "viewMaps" || core.status.event.id == "fly") { - fromUserAction = false; - core.status.event.ui = core.status.event.data; - } - if (!this._checkStatus("book", fromUserAction, true)) return; - core.playSound("打开界面"); - core.useItem("book", true); - }; - ////// 怪物手册界面时,放开某个键的操作 ////// - core.actions._keyUpBook = function (keycode) { - if (keycode == 27 || keycode == 88) { - core.playSound("取消"); - if (core.events.recoverEvents(core.status.event.interval)) { - return; - } else if (core.status.event.ui != null) { - core.status.boxAnimateObjs = []; - if (typeof core.status.event.ui === "number") { - core.status.event.id = "fly"; - core.ui.drawFly(core.status.event.ui); - } else { - core.ui._drawViewMaps(core.status.event.ui); - } - } else core.ui.closePanel(); - return; - } - if (keycode == 13 || keycode == 32 || keycode == 67) { - var data = core.status.event.data; - if (data != null) { - core.ui._drawBookDetail(data); - } - return; - } - }; - ////// 怪物手册界面的点击操作 ////// - actions.prototype._clickBook = function (x, y) { - var pageinfo = core.ui._drawBook_pageinfo(); - // 上一页 - if ( - (x == this._HX_ - 2 || x == this._HX_ - 3) && - y === core._HEIGHT_ - 1 - ) { - core.playSound("光标移动"); - core.ui.drawBook(core.status.event.data - pageinfo.per_page); - return; - } - // 下一页 - if ( - (x == this._HX_ + 2 || x == this._HX_ + 3) && - y === core._HEIGHT_ - 1 - ) { - core.playSound("光标移动"); - core.ui.drawBook(core.status.event.data + pageinfo.per_page); - return; - } - // 返回 - if (x >= this.LAST - 2 && y === core._HEIGHT_ - 1) { - core.playSound("取消"); - if (core.events.recoverEvents(core.status.event.interval)) { - return; - } else if (core.status.event.ui != null) { - core.status.boxAnimateObjs = []; - if (typeof core.status.event.ui === "number") { - core.status.event.id = "fly"; - core.ui.drawFly(core.status.event.ui); - } else { - core.ui._drawViewMaps(core.status.event.ui); - } - } else core.ui.closePanel(); - return; - } - // 怪物信息 - var data = core.status.event.data; - if (data != null && y < core._HEIGHT_ - 1) { - var per_page = pageinfo.per_page, - page = parseInt(data / per_page); - var u = (core._HEIGHT_ - 1) / per_page; - for (var i = 0; i < per_page; ++i) { - if (y >= u * i && y < u * (i + 1)) { - var index = per_page * page + i; - core.ui.drawBook(index); - core.ui._drawBookDetail(index); - break; - } - } - return; - } - return; - }; + while (start < end) { + var mid = Math.floor((start + end) / 2); + if (mid - start > end - mid) mid--; + var nextInfo = core.enemys.getDamageInfo( + enemy, { atk: mid }, + x, + y, + floorId + ); + if (nextInfo == null || typeof nextInfo == "number") return null; + if (pre > nextInfo.damage) end = mid; + else start = mid + 1; + } + var nextInfo = core.enemys.getDamageInfo( + enemy, { atk: start }, + x, + y, + floorId + ); + return nextInfo == null || + typeof nextInfo == "number" || + nextInfo.damage >= pre ? + null : [start, nextInfo.damage]; + }; + var currAtk = start_atk; + while (true) { + var next = calNext(currAtk + 1, Number.MAX_SAFE_INTEGER, pre); + if (next == null) break; + currAtk = next[0]; + pre = next[1]; + list.push([currAtk - hero_atk, info.damage - pre]); + if (pre <= 0 && !core.flags.enableNegativeDamage) break; + if (list.length >= number) break; + } + if (list.length == 0) list.push([0, 0]); + return list; + }; + core.ui.clearMap = function (name, x, y, width, height) { + if (name == "all") { + for (var m in core.canvas) { + core.canvas[m].clearRect( + -32, + -32, + core.canvas[m].canvas.width + 32, + core.canvas[m].canvas.height + 32 + ); + } + core.clearMap("outerUI"); + core.dom.gif.innerHTML = ""; + core.removeGlobalAnimate(); + core.deleteCanvas(function (one) { + return one.startsWith("_bigImage_"); + }); + core.setWeather(null); + } else { + var ctx = this.getContextByName(name); + if (ctx) + ctx.clearRect( + x || 0, + y || 0, + width || ctx.canvas.width, + height || ctx.canvas.height + ); + } + }; + events.prototype.openBook = function (fromUserAction) { + if (core.isReplaying()) return; + // 如果能恢复事件(从callBook事件触发) + if ( + core.status.event.id == "book" && + core.events.recoverEvents(core.status.event.interval) + ) + return; + // 当前是book,且从“浏览地图”打开 + if (core.status.event.id == "book" && core.status.event.ui) { + core.status.boxAnimateObjs = []; + core.ui._drawViewMaps(core.status.event.ui); + return; + } + // 从“浏览地图”页面打开 + if (core.status.event.id == "viewMaps" || core.status.event.id == "fly") { + fromUserAction = false; + core.status.event.ui = core.status.event.data; + } + if (!this._checkStatus("book", fromUserAction, true)) return; + core.playSound("打开界面"); + core.useItem("book", true); + }; + ////// 怪物手册界面时,放开某个键的操作 ////// + core.actions._keyUpBook = function (keycode) { + if (keycode == 27 || keycode == 88) { + core.playSound("取消"); + if (core.events.recoverEvents(core.status.event.interval)) { + return; + } else if (core.status.event.ui != null) { + core.status.boxAnimateObjs = []; + if (typeof core.status.event.ui === "number") { + core.status.event.id = "fly"; + core.ui.drawFly(core.status.event.ui); + } else { + core.ui._drawViewMaps(core.status.event.ui); + } + } else core.ui.closePanel(); + return; + } + if (keycode == 13 || keycode == 32 || keycode == 67) { + var data = core.status.event.data; + if (data != null) { + core.ui._drawBookDetail(data); + } + return; + } + }; + ////// 怪物手册界面的点击操作 ////// + actions.prototype._clickBook = function (x, y) { + var pageinfo = core.ui._drawBook_pageinfo(); + // 上一页 + if ( + (x == this._HX_ - 2 || x == this._HX_ - 3) && + y === core._HEIGHT_ - 1 + ) { + core.playSound("光标移动"); + core.ui.drawBook(core.status.event.data - pageinfo.per_page); + return; + } + // 下一页 + if ( + (x == this._HX_ + 2 || x == this._HX_ + 3) && + y === core._HEIGHT_ - 1 + ) { + core.playSound("光标移动"); + core.ui.drawBook(core.status.event.data + pageinfo.per_page); + return; + } + // 返回 + if (x >= this.LAST - 2 && y === core._HEIGHT_ - 1) { + core.playSound("取消"); + if (core.events.recoverEvents(core.status.event.interval)) { + return; + } else if (core.status.event.ui != null) { + core.status.boxAnimateObjs = []; + if (typeof core.status.event.ui === "number") { + core.status.event.id = "fly"; + core.ui.drawFly(core.status.event.ui); + } else { + core.ui._drawViewMaps(core.status.event.ui); + } + } else core.ui.closePanel(); + return; + } + // 怪物信息 + var data = core.status.event.data; + if (data != null && y < core._HEIGHT_ - 1) { + var per_page = pageinfo.per_page, + page = parseInt(data / per_page); + var u = (core._HEIGHT_ - 1) / per_page; + for (var i = 0; i < per_page; ++i) { + if (y >= u * i && y < u * (i + 1)) { + var index = per_page * page + i; + core.ui.drawBook(index); + core.ui._drawBookDetail(index); + break; + } + } + return; + } + return; + }; - ////// 执行当前自定义事件列表中的下一个事件 ////// - events.prototype.doAction = function () { - // 清空boxAnimate和UI层 - clearInterval(core.status.event.interval); - clearTimeout(core.status.event.interval); - clearInterval(core.status.event.animateUI); - core.status.event.interval = null; - delete core.status.event.aniamteUI; - if (core.status.gameOver || core.status.replay.failed) return; - // 判定是否执行完毕 - if (this._doAction_finishEvents()) return; - core.clearUI(); - var floorId = core.status.event.data.floorId || core.status.floorId; - // 当前点坐标和前缀 - var x = core.status.event.data.x, - y = core.status.event.data.y; - var prefix = [ - floorId || ":f", - x != null ? x : "x", - y != null ? y : "y", - ].join("@"); - var current = core.status.event.data.list[0]; - if (this._popEvents(current, prefix)) return; - // 当前要执行的事件 - var data = current.todo.shift(); - core.status.event.data.current = data; - if (typeof data == "string") data = { type: "text", text: data }; - // 该事件块已经被禁用 - if (data._disabled) return core.doAction(); - if (data.type !== "cgtext") { - core.unregisterAnimationFrame("skip"); - core.setFlag("skip", false); - } - data.floorId = data.floorId || floorId; - core.status.event.data.type = data.type; - this.doEvent(data, x, y, prefix); - return; - }; + ////// 执行当前自定义事件列表中的下一个事件 ////// + events.prototype.doAction = function () { + // 清空boxAnimate和UI层 + clearInterval(core.status.event.interval); + clearTimeout(core.status.event.interval); + clearInterval(core.status.event.animateUI); + core.status.event.interval = null; + delete core.status.event.aniamteUI; + if (core.status.gameOver || core.status.replay.failed) return; + // 判定是否执行完毕 + if (this._doAction_finishEvents()) return; + core.clearUI(); + var floorId = core.status.event.data.floorId || core.status.floorId; + // 当前点坐标和前缀 + var x = core.status.event.data.x, + y = core.status.event.data.y; + var prefix = [ + floorId || ":f", + x != null ? x : "x", + y != null ? y : "y", + ].join("@"); + var current = core.status.event.data.list[0]; + if (this._popEvents(current, prefix)) return; + // 当前要执行的事件 + var data = current.todo.shift(); + core.status.event.data.current = data; + if (typeof data == "string") data = { type: "text", text: data }; + // 该事件块已经被禁用 + if (data._disabled) return core.doAction(); + if (data.type !== "cgtext") { + core.unregisterAnimationFrame("skip"); + core.setFlag("skip", false); + } + data.floorId = data.floorId || floorId; + core.status.event.data.type = data.type; + this.doEvent(data, x, y, prefix); + return; + }; - ////// 在某个canvas上绘制粗体 ////// - core.fillBoldText1 = function ( - name, - text, - x, - y, - style, - strokeStyle, - lineWidth, - font, - maxWidth - ) { - var ctx = this.getContextByName(name); - if (!ctx) return; - if (font) ctx.font = font; - if (!style) style = ctx.fillStyle; - style = core.arrayToRGBA(style); - if (!strokeStyle) strokeStyle = "#000000"; - strokeStyle = core.arrayToRGBA(strokeStyle); - if (maxWidth != null) { - this.setFontForMaxWidth(ctx, text, maxWidth); - } - ctx.strokeStyle = strokeStyle; + ////// 在某个canvas上绘制粗体 ////// + core.fillBoldText1 = function ( + name, + text, + x, + y, + style, + strokeStyle, + lineWidth, + font, + maxWidth + ) { + var ctx = this.getContextByName(name); + if (!ctx) return; + if (font) ctx.font = font; + if (!style) style = ctx.fillStyle; + style = core.arrayToRGBA(style); + if (!strokeStyle) strokeStyle = "#000000"; + strokeStyle = core.arrayToRGBA(strokeStyle); + if (maxWidth != null) { + this.setFontForMaxWidth(ctx, text, maxWidth); + } + ctx.strokeStyle = strokeStyle; - if (!lineWidth) lineWidth = 2; - ctx.lineWidth = lineWidth; - ctx.strokeText(text, x, y); - ctx.fillStyle = style; - ctx.fillText(text, x, y); - }; - ////// 绘制 WindowSkin - ui.prototype.drawWindowSkin = function ( - background, - ctx, - x, - y, - w, - h, - direction, - px, - py, - size = 1 - ) { - background = background || core.status.textAttribute.background; + if (!lineWidth) lineWidth = 2; + ctx.lineWidth = lineWidth; + ctx.strokeText(text, x, y); + ctx.fillStyle = style; + ctx.fillText(text, x, y); + }; + ////// 绘制 WindowSkin + ui.prototype.drawWindowSkin = function ( + background, + ctx, + x, + y, + w, + h, + direction, + px, + py, + size = 1 + ) { + background = background || core.status.textAttribute.background; - // 仿RM窗口皮肤 ↓ - // 绘制背景 - core.drawImage( - ctx, - background, - 0, - 0, - 128, - 128, - x + 2 * size, - y + 2 * size, - w - 4 * size, - h - 4 * size - ); - // 绘制边框 - // 上方 - core.drawImage( - ctx, - background, - 128, - 0, - 16, - 16, - x, - y, - 16 * size, - 16 * size - ); - for (var dx = 0; dx < w - 64 * size; dx += 32 * size) { - core.drawImage( - ctx, - background, - 144, - 0, - 32, - 16, - x + dx + 16 * size, - y, - 32 * size, - 16 * size - ); - core.drawImage( - ctx, - background, - 144, - 48, - 32, - 16, - x + dx + 16 * size, - y + h - 16 * size, - 32 * size, - 16 * size - ); - } - core.drawImage( - ctx, - background, - 144, - 0, - (w - dx - 32 * size) / size, - 16, - x + dx + 16 * size, - y, - w - dx - 32 * size, - 16 * size - ); - core.drawImage( - ctx, - background, - 144, - 48, - (w - dx - 32 * size) / size, - 16, - x + dx + 16 * size, - y + h - 16 * size, - w - dx - 32 * size, - 16 * size - ); - core.drawImage( - ctx, - background, - 176, - 0, - 16, - 16, - x + w - 16 * size, - y, - 16 * size, - 16 * size - ); - // 左右 - for (var dy = 0; dy < h - 64 * size; dy += 32 * size) { - core.drawImage( - ctx, - background, - 128, - 16, - 16, - 32, - x, - y + dy + 16 * size, - 16 * size, - 32 * size - ); - core.drawImage( - ctx, - background, - 176, - 16, - 16, - 32, - x + w - 16 * size, - y + dy + 16 * size, - 16 * size, - 32 * size - ); - } - core.drawImage( - ctx, - background, - 128, - 16, - 16, - (h - dy - 32 * size) / size, - x, - y + dy + 16 * size, - 16 * size, - h - dy - 32 * size - ); - core.drawImage( - ctx, - background, - 176, - 16, - 16, - (h - dy - 32 * size) / size, - x + w - 16 * size, - y + dy + 16 * size, - 16 * size, - h - dy - 32 * size - ); - //下方 - core.drawImage( - ctx, - background, - 128, - 48, - 16, - 16, - x, - y + h - 16 * size, - 16 * size, - 16 * size - ); - core.drawImage( - ctx, - background, - 176, - 48, - 16, - 16, - x + w - 16 * size, - y + h - 16 * size, - 16 * size, - 16 * size - ); + // 仿RM窗口皮肤 ↓ + // 绘制背景 + core.drawImage( + ctx, + background, + 0, + 0, + 128, + 128, + x + 2 * size, + y + 2 * size, + w - 4 * size, + h - 4 * size + ); + // 绘制边框 + // 上方 + core.drawImage( + ctx, + background, + 128, + 0, + 16, + 16, + x, + y, + 16 * size, + 16 * size + ); + for (var dx = 0; dx < w - 64 * size; dx += 32 * size) { + core.drawImage( + ctx, + background, + 144, + 0, + 32, + 16, + x + dx + 16 * size, + y, + 32 * size, + 16 * size + ); + core.drawImage( + ctx, + background, + 144, + 48, + 32, + 16, + x + dx + 16 * size, + y + h - 16 * size, + 32 * size, + 16 * size + ); + } + core.drawImage( + ctx, + background, + 144, + 0, + (w - dx - 32 * size) / size, + 16, + x + dx + 16 * size, + y, + w - dx - 32 * size, + 16 * size + ); + core.drawImage( + ctx, + background, + 144, + 48, + (w - dx - 32 * size) / size, + 16, + x + dx + 16 * size, + y + h - 16 * size, + w - dx - 32 * size, + 16 * size + ); + core.drawImage( + ctx, + background, + 176, + 0, + 16, + 16, + x + w - 16 * size, + y, + 16 * size, + 16 * size + ); + // 左右 + for (var dy = 0; dy < h - 64 * size; dy += 32 * size) { + core.drawImage( + ctx, + background, + 128, + 16, + 16, + 32, + x, + y + dy + 16 * size, + 16 * size, + 32 * size + ); + core.drawImage( + ctx, + background, + 176, + 16, + 16, + 32, + x + w - 16 * size, + y + dy + 16 * size, + 16 * size, + 32 * size + ); + } + core.drawImage( + ctx, + background, + 128, + 16, + 16, + (h - dy - 32 * size) / size, + x, + y + dy + 16 * size, + 16 * size, + h - dy - 32 * size + ); + core.drawImage( + ctx, + background, + 176, + 16, + 16, + (h - dy - 32 * size) / size, + x + w - 16 * size, + y + dy + 16 * size, + 16 * size, + h - dy - 32 * size + ); + //下方 + core.drawImage( + ctx, + background, + 128, + 48, + 16, + 16, + x, + y + h - 16 * size, + 16 * size, + 16 * size + ); + core.drawImage( + ctx, + background, + 176, + 48, + 16, + 16, + x + w - 16 * size, + y + h - 16 * size, + 16 * size, + 16 * size + ); - // arrow - if (px != null && py != null) { - if (direction == "up") { - core.drawImage( - ctx, - background, - 128, - 96, - 32, - 32, - px, - y + h - 3 * size, - 32 * size, - 32 * size - ); - } else if (direction == "down") { - core.drawImage( - ctx, - background, - 160, - 96, - 32, - 32, - px, - y - 29 * size, - 32 * size, - 32 * size - ); - } - } - // 仿RM窗口皮肤 ↑ - }; - events.prototype.battle = function (id, x, y, force, callback) { - core.saveAndStopAutomaticRoute(); - id = id || core.getBlockId(x, y); - const cls = core.getClsFromId(id); - if (!id || !cls || !(cls === "enemys" || cls === "enemy48")) - return core.clearContinueAutomaticRoute(callback); - // 非强制战斗 - if (!core.enemys.canBattle(id, x, y) && !force && !core.status.event.id) { - core.stopSound(); - core.playSound("操作失败"); - core.drawTip("你打不过此怪物!", id); - return core.clearContinueAutomaticRoute(callback); - } - // 自动存档 - if (!core.status.event.id) core.autosave(true); - // 战前事件 - if (!this.beforeBattle(id, x, y)) - return core.clearContinueAutomaticRoute(callback); - // 战后事件 - this.afterBattle(id, x, y); - if (callback) callback(); - }; - }, + // arrow + if (px != null && py != null) { + if (direction == "up") { + core.drawImage( + ctx, + background, + 128, + 96, + 32, + 32, + px, + y + h - 3 * size, + 32 * size, + 32 * size + ); + } else if (direction == "down") { + core.drawImage( + ctx, + background, + 160, + 96, + 32, + 32, + px, + y - 29 * size, + 32 * size, + 32 * size + ); + } + } + // 仿RM窗口皮肤 ↑ + }; + events.prototype.battle = function (id, x, y, force, callback) { + core.saveAndStopAutomaticRoute(); + id = id || core.getBlockId(x, y); + const cls = core.getClsFromId(id); + if (!id || !cls || !(cls === "enemys" || cls === "enemy48")) + return core.clearContinueAutomaticRoute(callback); + // 非强制战斗 + if (!core.enemys.canBattle(id, x, y) && !force && !core.status.event.id) { + core.stopSound(); + core.playSound("操作失败"); + core.drawTip("你打不过此怪物!", id); + return core.clearContinueAutomaticRoute(callback); + } + // 自动存档 + if (!core.status.event.id) core.autosave(true); + // 战前事件 + if (!this.beforeBattle(id, x, y)) + return core.clearContinueAutomaticRoute(callback); + // 战后事件 + this.afterBattle(id, x, y); + if (callback) callback(); + }; +}, "额外信息": function () { /* 宝石血瓶左下角显示数值 * 注意!!!不要在道具属性中直接操作flags,使用core.status.hero.flags或core.setFlag系列函数代替! @@ -5179,1442 +5176,1457 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = }; }, "新道具栏/装备栏": function () { - // 在此增加新插件 - // 注:///// *** 裹起来的区域: 该区域内参数可以随意更改调整ui绘制 不会影响总体布局 - // 请尽量修改该区域而不是其他区域 修改的时候最好可以对照现有ui修改 + // 在此增加新插件 + // 注:///// *** 裹起来的区域: 该区域内参数可以随意更改调整ui绘制 不会影响总体布局 + // 请尽量修改该区域而不是其他区域 修改的时候最好可以对照现有ui修改 - ///// *** 道具类型 - // cls对应name - var itemClsName = { - constants: "永久道具", - tools: "消耗道具", - }; - // 一页最大放的道具数量 将把整个道具左栏分成num份 每份是一个道具项 - var itemNum = 12; - ///// *** + ///// *** 道具类型 + // cls对应name + var itemClsName = { + constants: "永久道具", + tools: "消耗道具", + }; + // 一页最大放的道具数量 将把整个道具左栏分成num份 每份是一个道具项 + var itemNum = 12; + ///// *** - // 背景设置 - this.drawBoxBackground = function (ctx) { - core.setTextAlign(ctx, "left"); - core.clearMap(ctx); - core.deleteCanvas("_selector"); - var info = core.status.thisUIEventInfo || {}; + // 背景设置 + this.drawBoxBackground = function (ctx) { + core.setTextAlign(ctx, "left"); + core.clearMap(ctx); + core.deleteCanvas("_selector"); + var info = core.status.thisUIEventInfo || {}; - ///// *** 背景设置 - var max = core.__PIXELS__; - var x = 2, - y = x, - w = max - x * 2, - h = w; - var borderWidth = 2, - borderRadius = 5, // radius:圆角矩形的圆角半径 - borderStyle = "#fff"; - var backgroundColor = "gray"; - // 设置背景不透明度(0.85) - var backgroundAlpha = 0.85; - ///// *** + ///// *** 背景设置 + var max = core.__PIXELS__; + var x = 2, + y = x, + w = max - x * 2, + h = w; + var borderWidth = 2, + borderRadius = 5, // radius:圆角矩形的圆角半径 + borderStyle = "#fff"; + var backgroundColor = "gray"; + // 设置背景不透明度(0.85) + var backgroundAlpha = 0.85; + ///// *** - var start_x = x + borderWidth / 2, - start_y = y + borderWidth / 2, - width = max - start_x * 2, - height = max - start_y * 2; + var start_x = x + borderWidth / 2, + start_y = y + borderWidth / 2, + width = max - start_x * 2, + height = max - start_y * 2; - // 渐变色背景的一个例子(黑色渐变白色): - // 有关渐变色的具体知识请网上搜索canvas createGradient了解 - /* + // 渐变色背景的一个例子(黑色渐变白色): + // 有关渐变色的具体知识请网上搜索canvas createGradient了解 + /* var grd = ctx.createLinearGradient(x, y, x + w, y); grd.addColorStop(0, "black"); grd.addColorStop(1, "white"); backgroundColor = grd; */ - // 使用图片背景要注释掉下面的strokeRect和fillRoundRect - // 图片背景的一个例子: - /* + // 使用图片背景要注释掉下面的strokeRect和fillRoundRect + // 图片背景的一个例子: + /* core.drawImage(ctx, "xxx.png", x, y, w, h); 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.setAlpha(ctx, 1); - - ///// *** 左栏配置 - var leftbar_height = height; - // 左边栏宽度(width*0.6) 本身仅为坐标使用 需要与底下的rightbar_width(width*0.4)同时更改 - var leftbar_width = width * 0.6; - ///// *** - - // xxx_right参数 代表最右侧坐标 - var leftbar_right = start_x + leftbar_width - borderWidth / 2; - var leftbar_bottom = start_y + leftbar_height; - var leftbar_x = start_x; - var leftbar_y = start_y; - - ///// *** 道具栏配置 - var boxName_color = "#fff"; - var boxName_fontSize = 15; - var boxName_font = core.ui._buildFont(boxName_fontSize, true); - var arrow_x = 10 + start_x; - var arrow_y = 10 + start_y; - var arrow_width = 20; - var arrow_style = "white"; - // 暂时只能是1 否则不太行 等待新样板(2.7.3)之后对drawArrow做优化 - var arrow_lineWidth = 1; - // 右箭头 - var rightArrow_right = leftbar_right - 10; - // 道具内栏顶部坐标 本质是通过该项 控制(道具栏顶部文字和箭头)与道具内栏顶部的间隔 - var itembar_top = arrow_y + 15; - ///// *** - - 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 - ); - core.setTextAlign(ctx, "center"); - core.setTextBaseline(ctx, "middle"); - var changeBox = function () { - var id = core.status.event.id; - 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 - ); - - ///// *** 底栏按钮 - var pageBtn_radius = 8; - // xxx_left 最左侧坐标 - var pageBtn_left = leftbar_x + 3; - var pageBtn_right = leftbar_right - 3; - // xxx_bottom 最底部坐标 - var pageBtn_bottom = leftbar_bottom - 2; - var pageBtn_borderStyle = "#fff"; - var pageBtn_borderWidth = 2; - var pageText_color = "#fff"; - // 底部按钮与上面的道具内栏的间隔大小 - var bottomSpace = 8; - ///// *** - - core.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); - 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 - ); - var oneItemHeight = (itembar_height - 4) / itemNum; - return { - x: start_x, - y: start_y, - width: width, - height: height, - leftbar_right: leftbar_right, - obj: { - x: arrow_x, - y: itembar_top, - width: itembar_right - arrow_x, - height: itembar_height, - oneItemHeight: oneItemHeight, - }, - }; - }; - - this.drawItemListbox = function (ctx, obj) { - ctx = ctx || core.canvas.ui; - var itembar_x = obj.x, - itembar_y = obj.y, - itembar_width = obj.width, - itembar_height = obj.height, - itemNum = obj.itemNum, - oneItemHeight = obj.oneItemHeight; - var itembar_right = itembar_x + itembar_width; - var info = core.status.thisUIEventInfo || {}; - var obj = {}; - var page = info.page || 1, - index = info.index, - select = info.select || {}; - - ///// *** 道具栏内栏配置 - var itembar_style = "black"; - var itembar_alpha = 0.7; - // 一个竖屏下减少道具显示的例子: - // if (core.domStyle.isVertical) itemNum = 10; - // 每个道具项的上下空隙占总高度的比例 - var itembar_marginHeightRatio = 0.2; - // 左右间隔空隙 - var item_marginLeft = 2; - var item_x = itembar_x + 2, - item_y = itembar_y + 2, - item_right = itembar_right - 2, - itemName_color = "#fff"; - // 修改此项以更换闪烁光标 - var item_selector = "winskin.webp"; - ///// *** - - core.setAlpha(ctx, itembar_alpha); - core.fillRect( - ctx, - itembar_x, - itembar_y, - itembar_width, - itembar_height, - itembar_style - ); - core.setAlpha(ctx, 1); - var pageItems = core.setPageItems(page); - var marginHeight = itembar_marginHeightRatio * oneItemHeight; - core.setTextBaseline(ctx, "middle"); - var originColor = itemName_color; - for (var i = 0; i < pageItems.length; i++) { - itemName_color = originColor; - 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 - ); - item_y += oneItemHeight; - } - }; - - this.drawToolboxRightbar = function (ctx, obj) { - ctx = ctx || core.canvas.ui; - var info = core.status.thisUIEventInfo || {}; - var page = info.page || 1, - index = info.index || 1, - select = info.select || {}; - var start_x = obj.x, - start_y = obj.y, - width = obj.width, - height = obj.height; - var toolboxRight = start_x + width, - toolboxBottom = start_y + height; - - ///// *** 侧边栏(rightbar)背景设置(物品介绍) - var rightbar_width = width * 0.4; - var rightbar_height = height; - var rightbar_lineWidth = 2; - var rightbar_lineStyle = "#fff"; - ///// *** - - 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 - ); - - // 获取道具id(有可能为null) - var itemId = select.id; - var item = core.material.items[itemId]; - - ///// *** 侧边栏物品Icon信息 - var iconRect_y = rightbar_y + 10; - // space:间距 - // 这里布局设定iconRect与侧边栏左边框 itemName与工具栏右边框 itemRect与itemName的间距均为space - var space = 15; - var iconRect_x = rightbar_x + space; - var iconRect_radius = 2, - iconRect_width = 32, - iconRect_height = 32, - iconRect_style = "#fff", - iconRect_lineWidth = 2; - ///// *** - - var iconRect_bottom = iconRect_y + iconRect_height, - iconRect_right = iconRect_x + iconRect_width; - - ///// *** 侧边栏各项信息 - var itemTextFontSize = 15, - itemText_x = iconRect_x - 4, - itemText_y = Math.floor(start_y + rightbar_height * 0.25), // 坐标取整防止模糊 - itemClsFontSize = 15, - itemClsFont = core.ui._buildFont(itemClsFontSize), - itemClsColor = "#fff", - itemCls_x = itemText_x - itemClsFontSize / 2, - itemCls_middle = (iconRect_bottom + itemText_y) / 2, //_middle代表文字的中心y坐标 - itemNameFontSize = 18, - 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 defaultItem = { - cls: "constants", - name: "未知道具", - text: "没有道具最永久", - }; - var defaultEquip = { - cls: "equips", - name: "未知装备", - text: "一无所有,又何尝不是一种装备", - equipCls: "无", - equip: { - type: "装备", - }, - }; - ///// *** - - var originItem = item; - if (core.status.event.id == "equipbox") item = item || defaultEquip; - item = item || defaultItem; - var itemCls = item.cls, - itemName = item.name, - itemText = item.text; - itemText = core.replaceText(itemText); - if (itemText[0] == "," || itemText[0] == ",") - itemText = itemText.substring(1); - - /* 一个根据道具id修改道具名字(右栏)的例子 - * if (item.id == "xxx") itemNameColor = "red"; - */ - var itemClsName = core.getItemClsName(item); - var itemNameMaxWidth = - rightbar_width - iconRect_width - iconRect_lineWidth * 2 - space * 2; - core.strokeRoundRect( - ctx, - iconRect_x, - iconRect_y, - iconRect_width, - iconRect_height, - iconRect_radius, - iconRect_style, - iconRect_lineWidth - ); - if (item.id) - core.drawIcon( - ctx, - item.id, - iconRect_x + iconRect_lineWidth / 2, - iconRect_y + iconRect_lineWidth / 2, - iconRect_width - iconRect_lineWidth, - iconRect_height - iconRect_lineWidth - ); - core.setTextAlign(ctx, "left"); - core.setTextBaseline(ctx, "middle"); - if (itemCls === "equips" && item.id) { - itemName = "【" + item.equipCls + "】" + itemName; - } - core.fillText( - ctx, - itemName, - itemName_x, - itemName_middle, - itemNameColor, - itemNameFont, - itemNameMaxWidth - ); - if (!item.equip) - core.fillText( - ctx, - "【" + itemClsName + "】", - itemCls_x, - itemCls_middle, - itemClsColor, - itemClsFont - ); - - var statusText = ""; - if (core.status.event.id == "equipbox") { - var type = item.equip.type; - if (typeof type == "string") type = core.getEquipTypeByName(type); - var compare = core.compareEquipment(item.id, core.getEquip(type)); - var compare2; - if (item.equipCls === "双手剑") - compare2 = core.compareEquipment(null, core.getEquip(1)); - if (info.select.action == "unload") - compare = core.compareEquipment(null, item.id); - // --- 变化值... - for (var name in core.status.hero) { - if (typeof core.status.hero[name] != "number") continue; - var nowValue = core.getRealStatus(name); - // 查询新值 - var newValue = Math.floor( - ((core.getStatus(name) + - (compare.value[name] || 0) + - (compare2?.value[name] || 0)) * - (core.getBuff(name) * 100 + - (compare.percentage[name] || 0) + - (compare2?.percentage[name] || 0))) / - 100 - ); - if (nowValue == newValue) continue; - var color = newValue > nowValue ? "#00FF00" : "#FF0000"; - nowValue = core.formatBigNumber(nowValue); - newValue = core.formatBigNumber(newValue); - statusText += - core.getStatusLabel(name) + - " " + - nowValue + - "->\r[" + - color + - "]" + - newValue + - "\r\n"; - } - } - itemText = statusText + itemText; - if (item.equip) { - core.drawTextContent(ctx, itemText, { - left: itemText_x, - top: itemCls_middle, - bold: false, - color: "white", - align: "left", - fontSize: itemTextFontSize, - maxWidth: - rightbar_width - - (itemText_x - rightbar_x) * 2 + - itemTextFontSize / 2, - }); - } else { - core.drawTextContent(ctx, itemText, { - left: itemText_x, - top: itemText_y, - bold: false, - color: "white", - align: "left", - fontSize: itemTextFontSize, - maxWidth: - rightbar_width - - (itemText_x - rightbar_x) * 2 + - itemTextFontSize / 2, - }); - } - - ///// *** 退出按钮设置 - var btnRadius = 10; - var btnBorderWidth = 2; - var btnRight = toolboxRight - 2; - var btnBottom = toolboxBottom - 2; - var btnBorderStyle = "#fff"; - ///// *** - - // 获取圆心位置 - 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 useBtnHeight = btnRadius * 2; - // 这里不设置useBtnWidth而是根据各项数据自动得出width - var useBtnRadius = useBtnHeight / 2; - var useBtn_x = rightbar_x + 4, - useBtn_y = btnBottom - useBtnHeight; - var useBtnBorderStyle = "#fff"; - var useBtnBorderWidth = btnBorderWidth; - ///// *** - - core.drawToolbox_setUseBtn( - ctx, - useBtn_x, - useBtn_y, - useBtnRadius, - useBtnHeight, - useBtnBorderStyle, - useBtnBorderWidth - ); - }; - - this.drawEquipbox_drawOthers = function (ctx, obj) { - var info = core.status.thisUIEventInfo; - - ///// *** 装备格设置 - var equipList_lineWidth = 2; - var equipList_boxSize = 32; - var equipList_borderWidth = 2; - var equipList_borderStyle = "#fff"; - var equipList_nameColor = "#fff"; - ///// *** - - var equipList_x = obj.x + 4, - equipList_bottom = obj.obj.y - equipList_lineWidth, - equipList_y = equipList_bottom - obj.obj.oneItemHeight * reduceItem - 2, - equipList_height = equipList_bottom - equipList_y; - var equipList_right = obj.leftbar_right, - equipList_width = equipList_right - equipList_x; - core.drawLine( - ctx, - obj.x, - equipList_bottom + equipList_lineWidth / 2, - equipList_right, - equipList_bottom + equipList_lineWidth / 2, - equipList_borderStyle, - equipList_lineWidth - ); - var toDrawList = core.status.globalAttribute.equipName, - len = toDrawList.length; - - ///// *** 装备格设置 - var maxItem = 2; - var box_width = 32, - box_height = 32, - box_borderStyle = "#fff", - box_selectBorderStyle = "gold", // 选中的装备格的颜色 - box_borderWidth = 2; - var boxName_fontSize = 14, - boxName_space = 2, - boxName_color = "#fff"; // 装备格名称与上面的装备格框的距离 - var maxLine = Math.ceil(len / maxItem); - ///// *** - var l = Math.sqrt(len); - if (Math.pow(l) == len && len != 4) { - if (l <= maxItem) maxItem = l; - } - maxItem = Math.min(toDrawList.length, maxItem); - info.equips = maxItem; - - var boxName_font = core.ui._buildFont(boxName_fontSize); - // 总宽高减去所有装备格宽高得到空隙大小 - var oneBoxWidth = box_width + box_borderWidth * 2; - var oneBoxHeight = - box_height + boxName_fontSize + boxName_space + 2 * box_borderWidth; - var space_y = (equipList_height - maxLine * oneBoxHeight) / (1 + maxLine), - space_x = (equipList_width - maxItem * oneBoxWidth) / (1 + maxItem); - var box_x = equipList_x + space_x, - box_y = equipList_y + space_y + 12; - for (var i = 0; i < 2; i++) { - var id = core.getEquip(i), - name = toDrawList[i]; - if (i === 0) name = "主手"; - if (i === 1) name = "副手"; - var selectBorder = false; - if (core.status.thisUIEventInfo.select.type == i) selectBorder = true; - var borderStyle = selectBorder - ? box_selectBorderStyle - : box_borderStyle; - core.drawEquipbox_drawOne( - ctx, - name, - id, - box_x, - box_y, - box_width, - box_height, - boxName_space, - boxName_font, - boxName_color, - borderStyle, - box_borderWidth - ); - var todo = new Function( - "core.clickOneEquipbox('" + id + "'," + i + ")" - ); - core.addUIEventListener( - box_x - box_borderWidth / 2, - box_y - box_borderWidth / 2, - oneBoxWidth, - oneBoxHeight, - todo - ); - box_x += space_x + oneBoxWidth; - if ((i + 1) % maxItem == 0) { - box_x = equipList_x + space_x; - box_y += space_y + oneBoxHeight; - } - } - if (core.material.items[core.getEquip(0)]?.equipCls === "双手剑") { - core.drawLine( - ctx, - equipList_x + space_x + space_x + oneBoxWidth, - equipList_y + space_y + 12, - equipList_x + - space_x + - space_x + - oneBoxWidth + - box_width + - box_borderWidth, - equipList_y + space_y + box_height + 12 - ); - core.drawLine( - ctx, - equipList_x + space_x + space_x + oneBoxWidth, - equipList_y + space_y + box_height + 12, - equipList_x + - space_x + - space_x + - oneBoxWidth + - box_width + - box_borderWidth, - equipList_y + space_y + 12 - ); - } - ///// *** 装备格设置 - var maxItem = 3; - var box_width = 32, - box_height = 32, - box_borderStyle = "#fff", - box_selectBorderStyle = "gold", // 选中的装备格的颜色 - box_borderWidth = 2; - var boxName_fontSize = 14, - boxName_space = 2, - boxName_color = "#fff"; // 装备格名称与上面的装备格框的距离 - var maxLine = Math.ceil(len / maxItem); - ///// *** - var l = Math.sqrt(len); - if (Math.pow(l) == len && len != 4) { - if (l <= maxItem) maxItem = l; - } - maxItem = Math.min(toDrawList.length, maxItem); - info.equips = maxItem; - - var boxName_font = core.ui._buildFont(boxName_fontSize); - // 总宽高减去所有装备格宽高得到空隙大小 - var oneBoxWidth = box_width + box_borderWidth * 2; - var oneBoxHeight = - box_height + boxName_fontSize + boxName_space + 2 * box_borderWidth; - var space_y = (equipList_height - maxLine * oneBoxHeight) / (1 + maxLine), - space_x = (equipList_width - maxItem * oneBoxWidth) / (1 + maxItem); - var box_x = equipList_x + space_x, - box_y = equipList_y + space_y + space_y + oneBoxHeight; - for (var i = 2; i < len; i++) { - var id = core.getEquip(i), - name = toDrawList[i]; - var selectBorder = false; - if (core.status.thisUIEventInfo.select.type == i) selectBorder = true; - var borderStyle = selectBorder - ? box_selectBorderStyle - : box_borderStyle; - core.drawEquipbox_drawOne( - ctx, - name, - id, - box_x, - box_y, - box_width, - box_height, - boxName_space, - boxName_font, - boxName_color, - borderStyle, - box_borderWidth - ); - var todo = new Function( - "core.clickOneEquipbox('" + id + "'," + i + ")" - ); - core.addUIEventListener( - box_x - box_borderWidth / 2, - box_y - box_borderWidth / 2, - oneBoxWidth, - oneBoxHeight, - todo - ); - box_x += space_x + oneBoxWidth; - } - }; - - this.drawToolbox = function (ctx) { - ctx = ctx || core.canvas.ui; - core.status.thisEventClickArea = []; - - var info = core.drawBoxBackground(ctx); - info.itemNum = itemNum; - core.drawItemListbox(ctx, info.obj); - core.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); - 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); - 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 - ); - core.setTextAlign(ctx, "center"); - core.setTextBaseline(ctx, "top"); - var tx = (x + x + lineWidth / 2 + width) / 2, - ty = y + height + (lineWidth / 2) * 3 + space; - core.fillText(ctx, name, tx, ty, color, font); - core.setTextBaseline(ctx, "alphabetic"); - core.setTextAlign("left"); - }; - - this.drawItemListbox_drawItem = function ( - ctx, - left, - right, - top, - height, - marginLeft, - marginHeight, - style, - id - ) { - var info = core.status.thisUIEventInfo; - var nowClick = info.index; - var item = core.material.items[id] || {}; - var name = item.name || "???"; - var num = core.itemCount(id) || 0; - 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 - ); - 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); - }; - - this.setPageItems = function (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" - ); - info.allItems = items; - var maxPage = Math.ceil(items.length / num); - info.maxPage = maxPage; - var pageItems = items.slice((page - 1) * num, page * num); - info.pageItems = pageItems; - info.maxItem = pageItems.length; - 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 pageItems; - }; - - this.drawToolbox_setExitBtn = function (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.setTextAlign(ctx, "start"); - core.setTextBaseline(ctx, "top"); - - var todo = function () { - core.closePanel(); - }; - core.addUIEventListener(x - r, y - r, r * 2, r * 2, todo); - }; - - this.drawToolbox_setUseBtn = function (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 = core.status.event.id == "toolbox" ? "使用" : "装备"; - if (core.status.thisUIEventInfo.select.action == "unload") 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.useSelectItemInBox(); - }; - core.addUIEventListener(x, y, w, h, todo); - }; - - this.drawItemListbox_setPageBtn = function ( - 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 - ); - 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); - - x = right - offset; - 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); - }; - - this.clickItemFunc = function (id) { - var info = core.status.thisUIEventInfo; - if (!info) return; - if (info.select.id == id) return core.useSelectItemInBox(); - info.select = {}; - info.select.id = id; - core.setIndexAndSelect("index"); - core.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 (this.uidata.getToolboxItems) { - return this.uidata.getToolboxItems(cls); - } - return list - .filter(function (id) { - return !core.material.items[id].hideInToolbox; - }) - .sort(); - }; - - this.useSelectItemInBox = function () { - var info = core.status.thisUIEventInfo; - if (!info) return; - if (!info.select.id) return; - var id = info.select.id; - if (core.status.event.id == "toolbox") { - core.events.tryUseItem(id); - // core.closePanel(); - } else if (core.status.event.id == "equipbox") { - var action = info.select.action || "load"; - info.index = 1; - if (action == "load") { - var type = core.getEquipTypeById(id); - let equipClsid = core.material.items[id]?.equipCls; - let equipCls0 = core.material.items[core.getEquip(0)]?.equipCls; - let equipCls1 = core.material.items[core.getEquip(1)]?.equipCls; - if (equipClsid === "双手剑") { - core.unloadEquip(0, function () { - core.status.route.push("unEquip:" + 0); - }); - core.unloadEquip(1, function () { - core.status.route.push("unEquip:" + 1); - }); - } - core.loadEquip(id, function () { - core.status.route.push("equip:" + id); - info.select.type = type; - core.setIndexAndSelect("select"); - core.drawEquipbox(); - }); - } else { - var type = info.select.type; - core.unloadEquip(type, function () { - core.status.route.push("unEquip:" + type); - info.select.type = type; - //info.select.action = 'load' - core.setIndexAndSelect("select"); - core.drawEquipbox(); - }); - } - } - core.updateStatusBar(); - }; - this.setIndexAndSelect = function (toChange) { - var info = core.status.thisUIEventInfo; - if (!info) return; - core.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; - if (!info) return; - var maxPage = info.maxPage || 1; - info.page = info.page || 1; - info.page += num; - if (info.page <= 0) info.page = maxPage; - if (info.page > maxPage) info.page = 1; - info.index = 1; - core.setPageItems(info.page); - core.setIndexAndSelect("select"); - core.refreshBox(); - }; - - this.addItemListboxIndex = function (num) { - var info = core.status.thisUIEventInfo; - if (!info) return; - var maxItem = info.maxItem || 0; - info.index = info.index || 0; - info.index += num; - if (info.index <= 0) info.index = 1; - if (info.index > maxItem) info.index = maxItem; - core.setIndexAndSelect("select"); - core.refreshBox(); - }; - - this.addEquipboxType = function (num) { - var info = core.status.thisUIEventInfo; - var type = info.select.type; - if (type == null && num > 0) info.select.type = 0; - else info.select.type = type + num; - var max = core.status.globalAttribute.equipName.length; - if (info.select.type >= max) { - info.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(); - return; - } - }; - - core.actions._keyDownToolbox = function (keycode) { - if (!core.status.thisEventClickArea) return; - if (keycode == 37) { - // left - core.addItemListboxPage(-1); - return; - } - if (keycode == 38) { - // up - core.addItemListboxIndex(-1); - return; - } - if (keycode == 39) { - // right - core.addItemListboxPage(1); - return; - } - 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(); - return; - } - if (keycode == 84 || keycode == 27 || keycode == 88) { - core.closePanel(); - return; - } - if (keycode == 13 || keycode == 32 || keycode == 67) { - var info = core.status.thisUIEventInfo; - if (info.select) { - core.useSelectItemInBox(); - } - return; - } - }; - - core.actions._keyDownEquipbox = function (keycode) { - if (!core.status.thisEventClickArea) return; - 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 - var info = core.status.thisUIEventInfo; - if (info.index == 1) { - info.select.type = core.status.globalAttribute.equipName.length - 1; - core.setIndexAndSelect(); - return core.refreshBox(); - } - if (info.index) return core.addItemListboxIndex(-1); - return core.addEquipboxType(-1 * info.equips); - } - 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 - 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) { - core.items.quickSaveEquip(keycode - 48); - return; - } - if (keycode == 84) { - core.ui.closePanel(); - if (core.isReplaying()) core.control._replay_toolbox(); - else core.openToolbox(); - return; - } - if (keycode == 81 || keycode == 27 || keycode == 88) { - core.closePanel(); - return; - } - if (keycode == 13 || keycode == 32 || keycode == 67) { - var info = core.status.thisUIEventInfo; - 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; - } - } - return true; - }, - 51 - ); - core.registerAction( - "onclick", - "stopClick", - function () { - if (core.status.thisEventClickArea) return true; - }, - 51 - ); - - this.addUIEventListener = function (x, y, width, height, todo) { - if (!core.status.thisEventClickArea) return; - var obj = { - x: x, - y: y, - width: width, - height: height, - todo: todo, - }; - core.status.thisEventClickArea.push(obj); - }; - - this.initThisEventInfo = function () { - core.status.thisUIEventInfo = { - page: 1, - select: {}, - }; - core.status.thisEventClickArea = []; - }; - - this.refreshBox = function () { - 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) { - // 清除全部临时变量 - Object.keys(core.status.hero.flags).forEach(function (name) { - if (name.startsWith("@temp@") || /^arg\d+$/.test(name)) { - delete core.status.hero.flags[name]; - } - }); - } - this.clearUI(); - core.maps.generateGroundPattern(); - core.updateStatusBar(true); - core.unlockControl(); - core.status.event.data = null; - core.status.event.id = null; - core.status.event.selection = null; - core.status.event.ui = null; - core.status.event.interval = null; - core.status.thisUIEventInfo = null; - core.status.thisEventClickArea = null; - }; - - this.getItemClsName = function (item) { - if (item == null) return itemClsName; - if (item.cls == "equips") { - if (typeof item.equip.type == "string") return item.equip.type; - 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; - core.initThisEventInfo(); - 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; - core.initThisEventInfo(); - 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; - if (!core.status.replay.pausing) return core.drawTip("请先暂停录像"); - if (core.isMoving() || core.status.replay.animate || core.status.event.id) - return core.drawTip("请等待当前事件的处理结束"); - - core.lockControl(); - core.status.event.id = "toolbox"; - core.drawToolbox(); - }; - - core.control._replay_equipbox = function () { - if (!core.isPlaying() || !core.isReplaying()) return; - if (!core.status.replay.pausing) return core.drawTip("请先暂停录像"); - if (core.isMoving() || core.status.replay.animate || core.status.event.id) - return core.drawTip("请等待当前事件的处理结束"); - - core.lockControl(); - 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 - ) { - 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 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); - 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 index = items.indexOf(itemId) + 1; - if (index < 1) return false; - core.status.route.push(action); - if ( - core.material.items[itemId].hideInReplay || - core.status.replay.speed == 24 - ) { - core.loadEquip(itemId, core.replay); - return true; - } - core.status.event.id = "equipbox"; - core.initThisEventInfo(); - var info = core.status.thisUIEventInfo; - core.setPageItems(1); - info.page = Math.ceil(index / info.maxItem); - info.index = index % info.maxItem || info.maxItem; - core.setIndexAndSelect("select"); - core.setPageItems(info.page); - core.drawEquipbox(); - setTimeout(function () { - core.ui.closePanel(); - core.loadEquip(itemId, core.replay); - }, 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; - core.status.route.push(action); - if (core.status.replay.speed == 24) { - core.unloadEquip(equipType, core.replay); - return true; - } - core.status.event.id = "equipbox"; - core.initThisEventInfo(); - var info = core.status.thisUIEventInfo; - core.setPageItems(1); - info.select.type = equipType; - core.setIndexAndSelect(); - core.drawEquipbox(); - setTimeout(function () { - core.ui.closePanel(); - core.unloadEquip(equipType, core.replay); - }, 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); - }, + 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.setAlpha(ctx, 1); + + ///// *** 左栏配置 + var leftbar_height = height; + // 左边栏宽度(width*0.6) 本身仅为坐标使用 需要与底下的rightbar_width(width*0.4)同时更改 + var leftbar_width = width * 0.6; + ///// *** + + // xxx_right参数 代表最右侧坐标 + var leftbar_right = start_x + leftbar_width - borderWidth / 2; + var leftbar_bottom = start_y + leftbar_height; + var leftbar_x = start_x; + var leftbar_y = start_y; + + ///// *** 道具栏配置 + var boxName_color = "#fff"; + var boxName_fontSize = 15; + var boxName_font = core.ui._buildFont(boxName_fontSize, true); + var arrow_x = 10 + start_x; + var arrow_y = 10 + start_y; + var arrow_width = 20; + var arrow_style = "white"; + // 暂时只能是1 否则不太行 等待新样板(2.7.3)之后对drawArrow做优化 + var arrow_lineWidth = 1; + // 右箭头 + var rightArrow_right = leftbar_right - 10; + // 道具内栏顶部坐标 本质是通过该项 控制(道具栏顶部文字和箭头)与道具内栏顶部的间隔 + var itembar_top = arrow_y + 15; + ///// *** + + 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 + ); + core.setTextAlign(ctx, "center"); + core.setTextBaseline(ctx, "middle"); + var changeBox = function () { + var id = core.status.event.id; + 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 + ); + + ///// *** 底栏按钮 + var pageBtn_radius = 8; + // xxx_left 最左侧坐标 + var pageBtn_left = leftbar_x + 3; + var pageBtn_right = leftbar_right - 3; + // xxx_bottom 最底部坐标 + var pageBtn_bottom = leftbar_bottom - 2; + var pageBtn_borderStyle = "#fff"; + var pageBtn_borderWidth = 2; + var pageText_color = "#fff"; + // 底部按钮与上面的道具内栏的间隔大小 + var bottomSpace = 8; + ///// *** + + core.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); + 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 + ); + var oneItemHeight = (itembar_height - 4) / itemNum; + return { + x: start_x, + y: start_y, + width: width, + height: height, + leftbar_right: leftbar_right, + obj: { + x: arrow_x, + y: itembar_top, + width: itembar_right - arrow_x, + height: itembar_height, + oneItemHeight: oneItemHeight, + }, + }; + }; + + this.drawItemListbox = function (ctx, obj) { + ctx = ctx || core.canvas.ui; + var itembar_x = obj.x, + itembar_y = obj.y, + itembar_width = obj.width, + itembar_height = obj.height, + itemNum = obj.itemNum, + oneItemHeight = obj.oneItemHeight; + var itembar_right = itembar_x + itembar_width; + var info = core.status.thisUIEventInfo || {}; + var obj = {}; + var page = info.page || 1, + index = info.index, + select = info.select || {}; + + ///// *** 道具栏内栏配置 + var itembar_style = "black"; + var itembar_alpha = 0.7; + // 一个竖屏下减少道具显示的例子: + // if (core.domStyle.isVertical) itemNum = 10; + // 每个道具项的上下空隙占总高度的比例 + var itembar_marginHeightRatio = 0.2; + // 左右间隔空隙 + var item_marginLeft = 2; + var item_x = itembar_x + 2, + item_y = itembar_y + 2, + item_right = itembar_right - 2, + itemName_color = "#fff"; + // 修改此项以更换闪烁光标 + var item_selector = "winskin.webp"; + ///// *** + + core.setAlpha(ctx, itembar_alpha); + core.fillRect( + ctx, + itembar_x, + itembar_y, + itembar_width, + itembar_height, + itembar_style + ); + core.setAlpha(ctx, 1); + var pageItems = core.setPageItems(page); + var marginHeight = itembar_marginHeightRatio * oneItemHeight; + core.setTextBaseline(ctx, "middle"); + var originColor = itemName_color; + for (var i = 0; i < pageItems.length; i++) { + itemName_color = originColor; + 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 + ); + item_y += oneItemHeight; + } + }; + + this.drawToolboxRightbar = function (ctx, obj) { + ctx = ctx || core.canvas.ui; + var info = core.status.thisUIEventInfo || {}; + var page = info.page || 1, + index = info.index || 1, + select = info.select || {}; + var start_x = obj.x, + start_y = obj.y, + width = obj.width, + height = obj.height; + var toolboxRight = start_x + width, + toolboxBottom = start_y + height; + + ///// *** 侧边栏(rightbar)背景设置(物品介绍) + var rightbar_width = width * 0.4; + var rightbar_height = height; + var rightbar_lineWidth = 2; + var rightbar_lineStyle = "#fff"; + ///// *** + + 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 + ); + + // 获取道具id(有可能为null) + var itemId = select.id; + var item = core.material.items[itemId]; + + ///// *** 侧边栏物品Icon信息 + var iconRect_y = rightbar_y + 10; + // space:间距 + // 这里布局设定iconRect与侧边栏左边框 itemName与工具栏右边框 itemRect与itemName的间距均为space + var space = 15; + var iconRect_x = rightbar_x + space; + var iconRect_radius = 2, + iconRect_width = 32, + iconRect_height = 32, + iconRect_style = "#fff", + iconRect_lineWidth = 2; + ///// *** + + var iconRect_bottom = iconRect_y + iconRect_height, + iconRect_right = iconRect_x + iconRect_width; + + ///// *** 侧边栏各项信息 + var itemTextFontSize = 15, + itemText_x = iconRect_x - 4, + itemText_y = Math.floor(start_y + rightbar_height * 0.25), // 坐标取整防止模糊 + itemClsFontSize = 15, + itemClsFont = core.ui._buildFont(itemClsFontSize), + itemClsColor = "#fff", + itemCls_x = itemText_x - itemClsFontSize / 2, + itemCls_middle = (iconRect_bottom + itemText_y) / 2, //_middle代表文字的中心y坐标 + itemNameFontSize = 18, + 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 defaultItem = { + cls: "constants", + name: "未知道具", + text: "没有道具最永久", + }; + var defaultEquip = { + cls: "equips", + name: "未知装备", + text: "一无所有,又何尝不是一种装备", + equipCls: "无", + equip: { + type: "装备", + }, + }; + ///// *** + + var originItem = item; + if (core.status.event.id == "equipbox") item = item || defaultEquip; + item = item || defaultItem; + var itemCls = item.cls, + itemName = item.name, + itemText = item.text; + itemText = core.replaceText(itemText); + if (itemText[0] == "," || itemText[0] == ",") + itemText = itemText.substring(1); + + /* 一个根据道具id修改道具名字(右栏)的例子 + * if (item.id == "xxx") itemNameColor = "red"; + */ + var itemClsName = core.getItemClsName(item); + var itemNameMaxWidth = + rightbar_width - iconRect_width - iconRect_lineWidth * 2 - space * 2; + core.strokeRoundRect( + ctx, + iconRect_x, + iconRect_y, + iconRect_width, + iconRect_height, + iconRect_radius, + iconRect_style, + iconRect_lineWidth + ); + if (item.id) + core.drawIcon( + ctx, + item.id, + iconRect_x + iconRect_lineWidth / 2, + iconRect_y + iconRect_lineWidth / 2, + iconRect_width - iconRect_lineWidth, + iconRect_height - iconRect_lineWidth + ); + core.setTextAlign(ctx, "left"); + core.setTextBaseline(ctx, "middle"); + if (itemCls === "equips" && item.id) { + itemName = "【" + item.equipCls + "】" + itemName; + } + core.fillText( + ctx, + itemName, + itemName_x, + itemName_middle, + itemNameColor, + itemNameFont, + itemNameMaxWidth + ); + if (!item.equip) + core.fillText( + ctx, + "【" + itemClsName + "】", + itemCls_x, + itemCls_middle, + itemClsColor, + itemClsFont + ); + + var statusText = ""; + if (core.status.event.id == "equipbox") { + var type = item.equip.type; + if (typeof type == "string") type = core.getEquipTypeByName(type); + var compare = core.compareEquipment(item.id, core.getEquip(type)); + var compare2; + if (item.equipCls === "双手剑") + compare2 = core.compareEquipment(null, core.getEquip(1)); + if (info.select.action == "unload") + compare = core.compareEquipment(null, item.id); + // --- 变化值... + for (var name in core.status.hero) { + if (typeof core.status.hero[name] != "number") continue; + var nowValue = core.getRealStatus(name); + // 查询新值 + var newValue = Math.floor( + ((core.getStatus(name) + + (compare.value[name] || 0) + + (compare2?.value[name] || 0)) * + (core.getBuff(name) * 100 + + (compare.percentage[name] || 0) + + (compare2?.percentage[name] || 0))) / + 100 + ); + /*if (name === 'mdef') { + nowValue = core.getRealStatus(name) + '%' + newValue = Math.floor( + ((core.getStatus(name) + + ((compare.value[name] || 0) + + (compare2?.value[name] || 0) - 2) * 100) * + (core.getBuff(name) * 100 + + (compare.percentage[name] || 0) + + (compare2?.percentage[name] || 0))) / + 100 + ) + '%'; + }*/ + if (nowValue == newValue) continue; + var color = newValue > nowValue ? "#00FF00" : "#FF0000"; + nowValue = core.formatBigNumber(nowValue); + newValue = core.formatBigNumber(newValue); + statusText += + core.getStatusLabel(name) + + " " + + nowValue + + "->\r[" + + color + + "]" + + newValue + + "\r\n"; + } + } + itemText = statusText + itemText; + if (item.equip) { + core.drawTextContent(ctx, itemText, { + left: itemText_x, + top: itemCls_middle, + bold: false, + color: "white", + align: "left", + fontSize: itemTextFontSize, + maxWidth: rightbar_width - + (itemText_x - rightbar_x) * 2 + + itemTextFontSize / 2, + }); + } else { + core.drawTextContent(ctx, itemText, { + left: itemText_x, + top: itemText_y, + bold: false, + color: "white", + align: "left", + fontSize: itemTextFontSize, + maxWidth: rightbar_width - + (itemText_x - rightbar_x) * 2 + + itemTextFontSize / 2, + }); + } + + ///// *** 退出按钮设置 + var btnRadius = 10; + var btnBorderWidth = 2; + var btnRight = toolboxRight - 2; + var btnBottom = toolboxBottom - 2; + var btnBorderStyle = "#fff"; + ///// *** + + // 获取圆心位置 + 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 useBtnHeight = btnRadius * 2; + // 这里不设置useBtnWidth而是根据各项数据自动得出width + var useBtnRadius = useBtnHeight / 2; + var useBtn_x = rightbar_x + 4, + useBtn_y = btnBottom - useBtnHeight; + var useBtnBorderStyle = "#fff"; + var useBtnBorderWidth = btnBorderWidth; + ///// *** + + core.drawToolbox_setUseBtn( + ctx, + useBtn_x, + useBtn_y, + useBtnRadius, + useBtnHeight, + useBtnBorderStyle, + useBtnBorderWidth + ); + }; + + this.drawEquipbox_drawOthers = function (ctx, obj) { + var info = core.status.thisUIEventInfo; + + ///// *** 装备格设置 + var equipList_lineWidth = 2; + var equipList_boxSize = 32; + var equipList_borderWidth = 2; + var equipList_borderStyle = "#fff"; + var equipList_nameColor = "#fff"; + ///// *** + + var equipList_x = obj.x + 4, + equipList_bottom = obj.obj.y - equipList_lineWidth, + equipList_y = equipList_bottom - obj.obj.oneItemHeight * reduceItem - 2, + equipList_height = equipList_bottom - equipList_y; + var equipList_right = obj.leftbar_right, + equipList_width = equipList_right - equipList_x; + core.drawLine( + ctx, + obj.x, + equipList_bottom + equipList_lineWidth / 2, + equipList_right, + equipList_bottom + equipList_lineWidth / 2, + equipList_borderStyle, + equipList_lineWidth + ); + var toDrawList = core.status.globalAttribute.equipName, + len = toDrawList.length; + + ///// *** 装备格设置 + var maxItem = 2; + var box_width = 32, + box_height = 32, + box_borderStyle = "#fff", + box_selectBorderStyle = "gold", // 选中的装备格的颜色 + box_borderWidth = 2; + var boxName_fontSize = 14, + boxName_space = 2, + boxName_color = "#fff"; // 装备格名称与上面的装备格框的距离 + var maxLine = Math.ceil(len / maxItem); + ///// *** + var l = Math.sqrt(len); + if (Math.pow(l) == len && len != 4) { + if (l <= maxItem) maxItem = l; + } + maxItem = Math.min(toDrawList.length, maxItem); + info.equips = maxItem; + + var boxName_font = core.ui._buildFont(boxName_fontSize); + // 总宽高减去所有装备格宽高得到空隙大小 + var oneBoxWidth = box_width + box_borderWidth * 2; + var oneBoxHeight = + box_height + boxName_fontSize + boxName_space + 2 * box_borderWidth; + var space_y = (equipList_height - maxLine * oneBoxHeight) / (1 + maxLine), + space_x = (equipList_width - maxItem * oneBoxWidth) / (1 + maxItem); + var box_x = equipList_x + space_x, + box_y = equipList_y + space_y + 12; + for (var i = 0; i < 2; i++) { + var id = core.getEquip(i), + name = toDrawList[i]; + if (i === 0) name = "主手"; + if (i === 1) name = "副手"; + var selectBorder = false; + if (core.status.thisUIEventInfo.select.type == i) selectBorder = true; + var borderStyle = selectBorder ? + box_selectBorderStyle : + box_borderStyle; + core.drawEquipbox_drawOne( + ctx, + name, + id, + box_x, + box_y, + box_width, + box_height, + boxName_space, + boxName_font, + boxName_color, + borderStyle, + box_borderWidth + ); + var todo = new Function( + "core.clickOneEquipbox('" + id + "'," + i + ")" + ); + core.addUIEventListener( + box_x - box_borderWidth / 2, + box_y - box_borderWidth / 2, + oneBoxWidth, + oneBoxHeight, + todo + ); + box_x += space_x + oneBoxWidth; + if ((i + 1) % maxItem == 0) { + box_x = equipList_x + space_x; + box_y += space_y + oneBoxHeight; + } + } + if (core.material.items[core.getEquip(0)]?.equipCls === "双手剑") { + core.drawLine( + ctx, + equipList_x + space_x + space_x + oneBoxWidth, + equipList_y + space_y + 12, + equipList_x + + space_x + + space_x + + oneBoxWidth + + box_width + + box_borderWidth, + equipList_y + space_y + box_height + 12 + ); + core.drawLine( + ctx, + equipList_x + space_x + space_x + oneBoxWidth, + equipList_y + space_y + box_height + 12, + equipList_x + + space_x + + space_x + + oneBoxWidth + + box_width + + box_borderWidth, + equipList_y + space_y + 12 + ); + } + ///// *** 装备格设置 + var maxItem = 3; + var box_width = 32, + box_height = 32, + box_borderStyle = "#fff", + box_selectBorderStyle = "gold", // 选中的装备格的颜色 + box_borderWidth = 2; + var boxName_fontSize = 14, + boxName_space = 2, + boxName_color = "#fff"; // 装备格名称与上面的装备格框的距离 + var maxLine = Math.ceil(len / maxItem); + ///// *** + var l = Math.sqrt(len); + if (Math.pow(l) == len && len != 4) { + if (l <= maxItem) maxItem = l; + } + maxItem = Math.min(toDrawList.length, maxItem); + info.equips = maxItem; + + var boxName_font = core.ui._buildFont(boxName_fontSize); + // 总宽高减去所有装备格宽高得到空隙大小 + var oneBoxWidth = box_width + box_borderWidth * 2; + var oneBoxHeight = + box_height + boxName_fontSize + boxName_space + 2 * box_borderWidth; + var space_y = (equipList_height - maxLine * oneBoxHeight) / (1 + maxLine), + space_x = (equipList_width - maxItem * oneBoxWidth) / (1 + maxItem); + var box_x = equipList_x + space_x, + box_y = equipList_y + space_y + space_y + oneBoxHeight; + for (var i = 2; i < len; i++) { + var id = core.getEquip(i), + name = toDrawList[i]; + var selectBorder = false; + if (core.status.thisUIEventInfo.select.type == i) selectBorder = true; + var borderStyle = selectBorder ? + box_selectBorderStyle : + box_borderStyle; + core.drawEquipbox_drawOne( + ctx, + name, + id, + box_x, + box_y, + box_width, + box_height, + boxName_space, + boxName_font, + boxName_color, + borderStyle, + box_borderWidth + ); + var todo = new Function( + "core.clickOneEquipbox('" + id + "'," + i + ")" + ); + core.addUIEventListener( + box_x - box_borderWidth / 2, + box_y - box_borderWidth / 2, + oneBoxWidth, + oneBoxHeight, + todo + ); + box_x += space_x + oneBoxWidth; + } + }; + + this.drawToolbox = function (ctx) { + ctx = ctx || core.canvas.ui; + core.status.thisEventClickArea = []; + + var info = core.drawBoxBackground(ctx); + info.itemNum = itemNum; + core.drawItemListbox(ctx, info.obj); + core.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); + 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); + 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 + ); + core.setTextAlign(ctx, "center"); + core.setTextBaseline(ctx, "top"); + var tx = (x + x + lineWidth / 2 + width) / 2, + ty = y + height + (lineWidth / 2) * 3 + space; + core.fillText(ctx, name, tx, ty, color, font); + core.setTextBaseline(ctx, "alphabetic"); + core.setTextAlign("left"); + }; + + this.drawItemListbox_drawItem = function ( + ctx, + left, + right, + top, + height, + marginLeft, + marginHeight, + style, + id + ) { + var info = core.status.thisUIEventInfo; + var nowClick = info.index; + var item = core.material.items[id] || {}; + var name = item.name || "???"; + var num = core.itemCount(id) || 0; + 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 + ); + 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); + }; + + this.setPageItems = function (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" + ); + info.allItems = items; + var maxPage = Math.ceil(items.length / num); + info.maxPage = maxPage; + var pageItems = items.slice((page - 1) * num, page * num); + info.pageItems = pageItems; + info.maxItem = pageItems.length; + 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 pageItems; + }; + + this.drawToolbox_setExitBtn = function (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.setTextAlign(ctx, "start"); + core.setTextBaseline(ctx, "top"); + + var todo = function () { + core.closePanel(); + }; + core.addUIEventListener(x - r, y - r, r * 2, r * 2, todo); + }; + + this.drawToolbox_setUseBtn = function (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 = core.status.event.id == "toolbox" ? "使用" : "装备"; + if (core.status.thisUIEventInfo.select.action == "unload") 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.useSelectItemInBox(); + }; + core.addUIEventListener(x, y, w, h, todo); + }; + + this.drawItemListbox_setPageBtn = function ( + 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 + ); + 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); + + x = right - offset; + 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); + }; + + this.clickItemFunc = function (id) { + var info = core.status.thisUIEventInfo; + if (!info) return; + if (info.select.id == id) return core.useSelectItemInBox(); + info.select = {}; + info.select.id = id; + core.setIndexAndSelect("index"); + core.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 (this.uidata.getToolboxItems) { + return this.uidata.getToolboxItems(cls); + } + return list + .filter(function (id) { + return !core.material.items[id].hideInToolbox; + }) + .sort(); + }; + + this.useSelectItemInBox = function () { + var info = core.status.thisUIEventInfo; + if (!info) return; + if (!info.select.id) return; + var id = info.select.id; + if (core.status.event.id == "toolbox") { + core.events.tryUseItem(id); + // core.closePanel(); + } else if (core.status.event.id == "equipbox") { + var action = info.select.action || "load"; + info.index = 1; + if (action == "load") { + var type = core.getEquipTypeById(id); + let equipClsid = core.material.items[id]?.equipCls; + let equipCls0 = core.material.items[core.getEquip(0)]?.equipCls; + let equipCls1 = core.material.items[core.getEquip(1)]?.equipCls; + if (equipClsid === "双手剑") { + core.unloadEquip(0, function () { + core.status.route.push("unEquip:" + 0); + }); + core.unloadEquip(1, function () { + core.status.route.push("unEquip:" + 1); + }); + } + if (equipCls0 === "双手剑" && !(equipClsid === "饰品" || equipClsid === "护具")) { + core.unloadEquip(0, function () { + core.status.route.push("unEquip:" + 0); + }); + } + core.loadEquip(id, function () { + core.status.route.push("equip:" + id); + info.select.type = type; + //core.setIndexAndSelect("select"); + core.drawEquipbox(); + }); + } else { + var type = info.select.type; + core.unloadEquip(type, function () { + core.status.route.push("unEquip:" + type); + info.select.type = type; + //info.select.action = 'load' + //core.setIndexAndSelect("select"); + core.drawEquipbox(); + }); + } + } + core.updateStatusBar(); + }; + this.setIndexAndSelect = function (toChange) { + var info = core.status.thisUIEventInfo; + if (!info) return; + core.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; + if (!info) return; + var maxPage = info.maxPage || 1; + info.page = info.page || 1; + info.page += num; + if (info.page <= 0) info.page = maxPage; + if (info.page > maxPage) info.page = 1; + info.index = 1; + core.setPageItems(info.page); + core.setIndexAndSelect("select"); + core.refreshBox(); + }; + + this.addItemListboxIndex = function (num) { + var info = core.status.thisUIEventInfo; + if (!info) return; + var maxItem = info.maxItem || 0; + info.index = info.index || 0; + info.index += num; + if (info.index <= 0) info.index = 1; + if (info.index > maxItem) info.index = maxItem; + core.setIndexAndSelect("select"); + core.refreshBox(); + }; + + this.addEquipboxType = function (num) { + var info = core.status.thisUIEventInfo; + var type = info.select.type; + if (type == null && num > 0) info.select.type = 0; + else info.select.type = type + num; + var max = core.status.globalAttribute.equipName.length; + if (info.select.type >= max) { + info.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(); + return; + } + }; + + core.actions._keyDownToolbox = function (keycode) { + if (!core.status.thisEventClickArea) return; + if (keycode == 37) { + // left + core.addItemListboxPage(-1); + return; + } + if (keycode == 38) { + // up + core.addItemListboxIndex(-1); + return; + } + if (keycode == 39) { + // right + core.addItemListboxPage(1); + return; + } + 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(); + return; + } + if (keycode == 84 || keycode == 27 || keycode == 88) { + core.closePanel(); + return; + } + if (keycode == 13 || keycode == 32 || keycode == 67) { + var info = core.status.thisUIEventInfo; + if (info.select) { + core.useSelectItemInBox(); + } + return; + } + }; + + core.actions._keyDownEquipbox = function (keycode) { + if (!core.status.thisEventClickArea) return; + 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 + var info = core.status.thisUIEventInfo; + if (info.index == 1) { + info.select.type = core.status.globalAttribute.equipName.length - 1; + core.setIndexAndSelect(); + return core.refreshBox(); + } + if (info.index) return core.addItemListboxIndex(-1); + return core.addEquipboxType(-1 * info.equips); + } + 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 + 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) { + core.items.quickSaveEquip(keycode - 48); + return; + } + if (keycode == 84) { + core.ui.closePanel(); + if (core.isReplaying()) core.control._replay_toolbox(); + else core.openToolbox(); + return; + } + if (keycode == 81 || keycode == 27 || keycode == 88) { + core.closePanel(); + return; + } + if (keycode == 13 || keycode == 32 || keycode == 67) { + var info = core.status.thisUIEventInfo; + 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; + } + } + return true; + }, + 51 + ); + core.registerAction( + "onclick", + "stopClick", + function () { + if (core.status.thisEventClickArea) return true; + }, + 51 + ); + + this.addUIEventListener = function (x, y, width, height, todo) { + if (!core.status.thisEventClickArea) return; + var obj = { + x: x, + y: y, + width: width, + height: height, + todo: todo, + }; + core.status.thisEventClickArea.push(obj); + }; + + this.initThisEventInfo = function () { + core.status.thisUIEventInfo = { + page: 1, + select: {}, + }; + core.status.thisEventClickArea = []; + }; + + this.refreshBox = function () { + 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) { + // 清除全部临时变量 + Object.keys(core.status.hero.flags).forEach(function (name) { + if (name.startsWith("@temp@") || /^arg\d+$/.test(name)) { + delete core.status.hero.flags[name]; + } + }); + } + this.clearUI(); + core.maps.generateGroundPattern(); + core.updateStatusBar(true); + core.unlockControl(); + core.status.event.data = null; + core.status.event.id = null; + core.status.event.selection = null; + core.status.event.ui = null; + core.status.event.interval = null; + core.status.thisUIEventInfo = null; + core.status.thisEventClickArea = null; + }; + + this.getItemClsName = function (item) { + if (item == null) return itemClsName; + if (item.cls == "equips") { + if (typeof item.equip.type == "string") return item.equip.type; + 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; + core.initThisEventInfo(); + 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; + core.initThisEventInfo(); + 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; + if (!core.status.replay.pausing) return core.drawTip("请先暂停录像"); + if (core.isMoving() || core.status.replay.animate || core.status.event.id) + return core.drawTip("请等待当前事件的处理结束"); + + core.lockControl(); + core.status.event.id = "toolbox"; + core.drawToolbox(); + }; + + core.control._replay_equipbox = function () { + if (!core.isPlaying() || !core.isReplaying()) return; + if (!core.status.replay.pausing) return core.drawTip("请先暂停录像"); + if (core.isMoving() || core.status.replay.animate || core.status.event.id) + return core.drawTip("请等待当前事件的处理结束"); + + core.lockControl(); + 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 + ) { + 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 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); + 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 index = items.indexOf(itemId) + 1; + if (index < 1) return false; + core.status.route.push(action); + if ( + core.material.items[itemId].hideInReplay || + core.status.replay.speed == 24 + ) { + core.loadEquip(itemId, core.replay); + return true; + } + core.status.event.id = "equipbox"; + core.initThisEventInfo(); + var info = core.status.thisUIEventInfo; + core.setPageItems(1); + info.page = Math.ceil(index / info.maxItem); + info.index = index % info.maxItem || info.maxItem; + core.setIndexAndSelect("select"); + core.setPageItems(info.page); + core.drawEquipbox(); + setTimeout(function () { + core.ui.closePanel(); + core.loadEquip(itemId, core.replay); + }, 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; + core.status.route.push(action); + if (core.status.replay.speed == 24) { + core.unloadEquip(equipType, core.replay); + return true; + } + core.status.event.id = "equipbox"; + core.initThisEventInfo(); + var info = core.status.thisUIEventInfo; + core.setPageItems(1); + info.select.type = equipType; + core.setIndexAndSelect(); + core.drawEquipbox(); + setTimeout(function () { + core.ui.closePanel(); + core.unloadEquip(equipType, core.replay); + }, 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); +}, "技能树": function () { // 在此增加新插件 // @@ -18273,682 +18285,676 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = }); }, "天气叠加": function () { - //使用方法:使用core.setWeather(天气,等级)来增加天气,使用core.setWeather()来清空天气 - // 天气叠加功能 - ////// 更改天气效果 ////// - control.prototype.setWeather = function (type, level) { - // 非雨雪 - if (type == null) { - Object.keys(core.control.weathers).forEach(function (one) { - core.deleteCanvas("weather" + one); - }); - core.animateFrame.weather.type = []; - core.animateFrame.weather.nodes = {}; - core.animateFrame.weather.level = {}; - core.animateFrame.weather.time = {}; - return; - } - if (!core.animateFrame.weather.level || level == null) - core.animateFrame.weather.level = {}; - if (!core.animateFrame.weather.type) core.animateFrame.weather.type = []; - level = core.clamp(parseInt(level) || 5, 1, 10); - // 当前天气:则忽略 - if ( - core.animateFrame.weather.type.includes(type) && - level == core.animateFrame.weather.level[type] - ) - return; - if (core.animateFrame.weather.nodes[type]) return; - // 计算当前的宽高 - core.createCanvas( - "weather" + type, - 0, - 0, - core.__PIXELS__, - core.__PIXELS__, - 80 - ); - core.animateFrame.weather.type.push(type); - core.animateFrame.weather.level[type] = level; - this._setWeather_createNodes(type, level); - }; - control.prototype._setWeather_createNodes = function (type, level) { - var number = - level * - parseInt( - (20 * core.bigmap.width * core.bigmap.height) / - (core.__SIZE__ * core.__SIZE__) - ); - if (!core.animateFrame.weather.nodes[type]) - core.animateFrame.weather.nodes[type] = []; - switch (type) { - case "rain": - for (var a = 0; a < number; a++) { - core.animateFrame.weather.nodes.rain.push({ - x: Math.random() * core.bigmap.width * 32, - y: Math.random() * core.bigmap.height * 32, - l: Math.random() * 2.5, - xs: -4 + Math.random() * 4 + 2, - ys: Math.random() * 10 + 10, - }); - } - break; - case "snow": - for (var a = 0; a < number; a++) { - core.animateFrame.weather.nodes.snow.push({ - x: Math.random() * core.bigmap.width * 32, - y: Math.random() * core.bigmap.height * 32, - r: Math.random() * 5 + 1, - d: Math.random() * Math.min(level, 200), - }); - } - break; - case "fog": - if (core.animateFrame.weather.fog) { - core.animateFrame.weather.nodes[type] = [ - { - level: number, - x: 0, - y: -core.__PIXELS__ / 2, - dx: -Math.random() * 1.5, - dy: Math.random(), - delta: 0.001, - }, - ]; - } - break; - case "cloud": - if (core.animateFrame.weather.cloud) { - core.animateFrame.weather.nodes[type] = [ - { - level: number, - x: 0, - y: -core.__PIXELS__ / 2, - dx: -Math.random() * 1.5, - dy: Math.random(), - delta: 0.001, - }, - ]; - } - break; - case "sun": - if (core.animateFrame.weather.sun) { - // 直接绘制 - core.clearMap("weather" + type); - core.setAlpha("weather" + type, level / 10); - core.drawImage( - "weather" + type, - core.animateFrame.weather.sun, - 0, - 0, - core.animateFrame.weather.sun.width, - core.animateFrame.weather.sun.height, - 0, - 0, - core.__PIXELS__, - core.__PIXELS__ - ); - core.setAlpha("weather" + type, 1); - } - break; - } - }; - core.registerAnimationFrame("weather", true, function (timestamp) { - var weather = core.animateFrame.weather; - if (!weather.type) return; - weather.type.forEach(function (one) { - if ( - timestamp - weather.time[one] <= 30 || - !core.dymCanvas["weather" + one] - ) - return; - core.control["_animationFrame_weather_" + one](); - weather.time[one] = timestamp; - }); - }); - // 雨 - control.prototype._animationFrame_weather_rain = function () { - var ctx = core.dymCanvas.weatherrain, - ox = core.bigmap.offsetX, - oy = core.bigmap.offsetY; - core.clearMap("weatherrain"); - ctx.strokeStyle = "rgba(174,194,224,0.8)"; - ctx.lineWidth = 1; - ctx.lineCap = "round"; - core.animateFrame.weather.nodes.rain.forEach(function (p) { - ctx.beginPath(); - ctx.moveTo(p.x - ox, p.y - oy); - ctx.lineTo(p.x + p.l * p.xs - ox, p.y + p.l * p.ys - oy); - ctx.stroke(); - p.x += p.xs; - p.y += p.ys; - if (p.x > core.bigmap.width * 32 || p.y > core.bigmap.height * 32) { - p.x = Math.random() * core.bigmap.width * 32; - p.y = -10; - } - }); - ctx.fill(); - }; - // 雪 - control.prototype._animationFrame_weather_snow = function () { - var ctx = core.dymCanvas.weathersnow, - ox = core.bigmap.offsetX, - oy = core.bigmap.offsetY; - core.clearMap("weathersnow"); - ctx.fillStyle = "rgba(255, 255, 255, 0.8)"; - ctx.beginPath(); - if (!core.animateFrame.weather.data) core.animateFrame.weather.data = {}; - core.animateFrame.weather.data.snow = - core.animateFrame.weather.data.snow || 0; - core.animateFrame.weather.data.snow += 0.01; - var angle = core.animateFrame.weather.data.snow; - core.animateFrame.weather.nodes.snow.forEach(function (p) { - ctx.moveTo(p.x - ox, p.y - oy); - ctx.arc(p.x - ox, p.y - oy, p.r, 0, Math.PI * 2, true); - // update - p.x += Math.sin(angle) * core.animateFrame.weather.level.snow; - p.y += Math.cos(angle + p.d) + 1 + p.r / 2; - if ( - p.x > core.bigmap.width * 32 + 5 || - p.x < -5 || - p.y > core.bigmap.height * 32 - ) { - if (Math.random() > 1 / 3) { - p.x = Math.random() * core.bigmap.width * 32; - p.y = -10; - } else { - if (Math.sin(angle) > 0) p.x = -5; - else p.x = core.bigmap.width * 32 + 5; - p.y = Math.random() * core.bigmap.height * 32; - } - } - }); - ctx.fill(); - }; - // 图片天气 - control.prototype.__animateFrame_weather_image = function (image, type) { - if (!image) return; - var node = core.animateFrame.weather.nodes[type][0]; - core.setAlpha("weather" + type, node.level / 500); - var wind = 1.5; - var width = image.width, - height = image.height; - node.x += node.dx * wind; - node.y += (2 * node.dy - 1) * wind; - if (node.x + 3 * width <= core.__PIXELS__) { - node.x += 4 * width; - while (node.x > 0) node.x -= width; - } - node.dy += node.delta; - if (node.dy >= 1) { - node.delta = -0.001; - } else if (node.dy <= 0) { - node.delta = 0.001; - } - if (node.y + 3 * height <= core.__PIXELS__) { - node.y += 4 * height; - while (node.y > 0) node.y -= height; - } else if (node.y >= 0) { - node.y -= height; - } - for (var i = 0; i < 3; ++i) { - for (var j = 0; j < 3; ++j) { - if ( - node.x + (i + 1) * width <= 0 || - node.x + i * width >= core.__PIXELS__ || - node.y + (j + 1) * height <= 0 || - node.y + j * height >= core.__PIXELS__ - ) - continue; - core.drawImage( - "weather" + type, - image, - node.x + i * width, - node.y + j * height - ); - } - } - core.setAlpha("weather" + type, 1); - }; - // 雾 - control.prototype._animationFrame_weather_fog = function () { - core.clearMap("weatherfog"); - this.__animateFrame_weather_image(core.animateFrame.weather.fog, "fog"); - }; - // 云 - control.prototype._animationFrame_weather_cloud = function () { - core.clearMap("weathercloud"); - this.__animateFrame_weather_image( - core.animateFrame.weather.cloud, - "cloud" - ); - }; - }, + //使用方法:使用core.setWeather(天气,等级)来增加天气,使用core.setWeather()来清空天气 + // 天气叠加功能 + ////// 更改天气效果 ////// + control.prototype.setWeather = function (type, level) { + // 非雨雪 + if (type == null) { + Object.keys(core.control.weathers).forEach(function (one) { + core.deleteCanvas("weather" + one); + }); + core.animateFrame.weather.type = []; + core.animateFrame.weather.nodes = {}; + core.animateFrame.weather.level = {}; + core.animateFrame.weather.time = {}; + return; + } + if (!core.animateFrame.weather.level || level == null) + core.animateFrame.weather.level = {}; + if (!core.animateFrame.weather.type) core.animateFrame.weather.type = []; + level = core.clamp(parseInt(level) || 5, 1, 10); + // 当前天气:则忽略 + if ( + core.animateFrame.weather.type.includes(type) && + level == core.animateFrame.weather.level[type] + ) + return; + if (core.animateFrame.weather.nodes[type]) return; + // 计算当前的宽高 + core.createCanvas( + "weather" + type, + 0, + 0, + core.__PIXELS__, + core.__PIXELS__, + 80 + ); + core.animateFrame.weather.type.push(type); + core.animateFrame.weather.level[type] = level; + this._setWeather_createNodes(type, level); + }; + control.prototype._setWeather_createNodes = function (type, level) { + var number = + level * + parseInt( + (20 * core.bigmap.width * core.bigmap.height) / + (core.__SIZE__ * core.__SIZE__) + ); + if (!core.animateFrame.weather.nodes[type]) + core.animateFrame.weather.nodes[type] = []; + switch (type) { + case "rain": + for (var a = 0; a < number; a++) { + core.animateFrame.weather.nodes.rain.push({ + x: Math.random() * core.bigmap.width * 32, + y: Math.random() * core.bigmap.height * 32, + l: Math.random() * 2.5, + xs: -4 + Math.random() * 4 + 2, + ys: Math.random() * 10 + 10, + }); + } + break; + case "snow": + for (var a = 0; a < number; a++) { + core.animateFrame.weather.nodes.snow.push({ + x: Math.random() * core.bigmap.width * 32, + y: Math.random() * core.bigmap.height * 32, + r: Math.random() * 5 + 1, + d: Math.random() * Math.min(level, 200), + }); + } + break; + case "fog": + if (core.animateFrame.weather.fog) { + core.animateFrame.weather.nodes[type] = [{ + level: number, + x: 0, + y: -core.__PIXELS__ / 2, + dx: -Math.random() * 1.5, + dy: Math.random(), + delta: 0.001, + }, ]; + } + break; + case "cloud": + if (core.animateFrame.weather.cloud) { + core.animateFrame.weather.nodes[type] = [{ + level: number, + x: 0, + y: -core.__PIXELS__ / 2, + dx: -Math.random() * 1.5, + dy: Math.random(), + delta: 0.001, + }, ]; + } + break; + case "sun": + if (core.animateFrame.weather.sun) { + // 直接绘制 + core.clearMap("weather" + type); + core.setAlpha("weather" + type, level / 10); + core.drawImage( + "weather" + type, + core.animateFrame.weather.sun, + 0, + 0, + core.animateFrame.weather.sun.width, + core.animateFrame.weather.sun.height, + 0, + 0, + core.__PIXELS__, + core.__PIXELS__ + ); + core.setAlpha("weather" + type, 1); + } + break; + } + }; + core.registerAnimationFrame("weather", true, function (timestamp) { + var weather = core.animateFrame.weather; + if (!weather.type) return; + weather.type.forEach(function (one) { + if ( + timestamp - weather.time[one] <= 30 || + !core.dymCanvas["weather" + one] + ) + return; + core.control["_animationFrame_weather_" + one](); + weather.time[one] = timestamp; + }); + }); + // 雨 + control.prototype._animationFrame_weather_rain = function () { + var ctx = core.dymCanvas.weatherrain, + ox = core.bigmap.offsetX, + oy = core.bigmap.offsetY; + core.clearMap("weatherrain"); + ctx.strokeStyle = "rgba(174,194,224,0.8)"; + ctx.lineWidth = 1; + ctx.lineCap = "round"; + core.animateFrame.weather.nodes.rain.forEach(function (p) { + ctx.beginPath(); + ctx.moveTo(p.x - ox, p.y - oy); + ctx.lineTo(p.x + p.l * p.xs - ox, p.y + p.l * p.ys - oy); + ctx.stroke(); + p.x += p.xs; + p.y += p.ys; + if (p.x > core.bigmap.width * 32 || p.y > core.bigmap.height * 32) { + p.x = Math.random() * core.bigmap.width * 32; + p.y = -10; + } + }); + ctx.fill(); + }; + // 雪 + control.prototype._animationFrame_weather_snow = function () { + var ctx = core.dymCanvas.weathersnow, + ox = core.bigmap.offsetX, + oy = core.bigmap.offsetY; + core.clearMap("weathersnow"); + ctx.fillStyle = "rgba(255, 255, 255, 0.8)"; + ctx.beginPath(); + if (!core.animateFrame.weather.data) core.animateFrame.weather.data = {}; + core.animateFrame.weather.data.snow = + core.animateFrame.weather.data.snow || 0; + core.animateFrame.weather.data.snow += 0.01; + var angle = core.animateFrame.weather.data.snow; + core.animateFrame.weather.nodes.snow.forEach(function (p) { + ctx.moveTo(p.x - ox, p.y - oy); + ctx.arc(p.x - ox, p.y - oy, p.r, 0, Math.PI * 2, true); + // update + p.x += Math.sin(angle) * core.animateFrame.weather.level.snow; + p.y += Math.cos(angle + p.d) + 1 + p.r / 2; + if ( + p.x > core.bigmap.width * 32 + 5 || + p.x < -5 || + p.y > core.bigmap.height * 32 + ) { + if (Math.random() > 1 / 3) { + p.x = Math.random() * core.bigmap.width * 32; + p.y = -10; + } else { + if (Math.sin(angle) > 0) p.x = -5; + else p.x = core.bigmap.width * 32 + 5; + p.y = Math.random() * core.bigmap.height * 32; + } + } + }); + ctx.fill(); + }; + // 图片天气 + control.prototype.__animateFrame_weather_image = function (image, type) { + if (!image) return; + var node = core.animateFrame.weather.nodes[type][0]; + core.setAlpha("weather" + type, node.level / 500); + var wind = 1.5; + var width = image.width, + height = image.height; + node.x += node.dx * wind; + node.y += (2 * node.dy - 1) * wind; + if (node.x + 3 * width <= core.__PIXELS__) { + node.x += 4 * width; + while (node.x > 0) node.x -= width; + } + node.dy += node.delta; + if (node.dy >= 1) { + node.delta = -0.001; + } else if (node.dy <= 0) { + node.delta = 0.001; + } + if (node.y + 3 * height <= core.__PIXELS__) { + node.y += 4 * height; + while (node.y > 0) node.y -= height; + } else if (node.y >= 0) { + node.y -= height; + } + for (var i = 0; i < 3; ++i) { + for (var j = 0; j < 3; ++j) { + if ( + node.x + (i + 1) * width <= 0 || + node.x + i * width >= core.__PIXELS__ || + node.y + (j + 1) * height <= 0 || + node.y + j * height >= core.__PIXELS__ + ) + continue; + core.drawImage( + "weather" + type, + image, + node.x + i * width, + node.y + j * height + ); + } + } + core.setAlpha("weather" + type, 1); + }; + // 雾 + control.prototype._animationFrame_weather_fog = function () { + core.clearMap("weatherfog"); + this.__animateFrame_weather_image(core.animateFrame.weather.fog, "fog"); + }; + // 云 + control.prototype._animationFrame_weather_cloud = function () { + core.clearMap("weathercloud"); + this.__animateFrame_weather_image( + core.animateFrame.weather.cloud, + "cloud" + ); + }; +}, "回合战斗动画": function () { - // 在此增加新插件 - const animateAttack = document.createElement("canvas"); //画布设置 - animateAttack.style.zIndex = 80; - animateAttack.id = "animateAttack"; - animateAttack.classList.add("gameCanvas", "anti-aliasing"); - animateAttack.style.display = "block"; - animateAttack.width = 416; - animateAttack.height = 416; - animateAttack.style.width = core.__PIXELS__ * core.domStyle.scale + "px"; - animateAttack.style.height = core.__PIXELS__ * core.domStyle.scale + "px"; - main.dom.animateAttack = animateAttack; - const ctx = animateAttack.getContext("2d"); + // 在此增加新插件 + const animateAttack = document.createElement("canvas"); //画布设置 + animateAttack.style.zIndex = 80; + animateAttack.id = "animateAttack"; + animateAttack.classList.add("gameCanvas", "anti-aliasing"); + animateAttack.style.display = "block"; + animateAttack.width = 416; + animateAttack.height = 416; + animateAttack.style.width = core.__PIXELS__ * core.domStyle.scale + "px"; + animateAttack.style.height = core.__PIXELS__ * core.domStyle.scale + "px"; + main.dom.animateAttack = animateAttack; + const ctx = animateAttack.getContext("2d"); - main.dom.gameDraw.appendChild(animateAttack); + main.dom.gameDraw.appendChild(animateAttack); - this.drawAttackAnimate = function ( - heroInfo, - oneTurn, - enemyInfo, - equipInfo, - farme, - damageInfo - ) { - let attack = false; - if (heroInfo.isAttack) attack = true; - if (enemyInfo.isAttack) attack = true; - equipInfo.forEach(function (v) { - if (v.isAttack) attack = true; - }); - core.clearMap(ctx); - let animate = Math.floor(farme / 30); - core.fillRect(ctx, 64, 64, 288, 288, "rgba(0,0,0,0.5)"); - core.strokeRect(ctx, 64, 64, 288, 288, "rgba(255,255,255,0.5)", 4); - core.setTextAlign(ctx, "center"); - core.fillBoldText( - ctx, - hero.name, - 127, - 128, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); - core.setTextAlign(ctx, "left"); - core.drawIcon(ctx, "hp", 70, 190, 16, 16); - core.drawIcon(ctx, "atk", 70, 210, 16, 16); - core.drawIcon(ctx, "def", 70, 230, 16, 16); - core.drawIcon(ctx, "I374", 70, 250, 16, 16); - core.drawIcon(ctx, "I375", 70, 270, 16, 16); - core.drawIcon(ctx, "mdef", 70, 290, 16, 16); - core.drawIcon(ctx, "amulet", 70, 310, 16, 16); - core.drawIcon(ctx, "jumpShoes", 70, 330, 16, 16); - core.fillBoldText( - ctx, - "生命 " + - core.formatBigNumber(heroInfo.hp, true) + - " / " + - core.formatBigNumber(heroInfo.hpmax, true), - 90, - 205, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); - core.fillBoldText( - ctx, - "攻击 " + core.formatBigNumber(heroInfo.atk), - 90, - 225, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); - core.fillBoldText( - ctx, - "防御 " + core.formatBigNumber(heroInfo.def), - 90, - 245, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); - core.fillBoldText( - ctx, - "法强 " + core.formatBigNumber(heroInfo.spell), - 90, - 265, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); - core.fillBoldText( - ctx, - "法攻 " + - core.formatBigNumber((heroInfo.matk / 100) * heroInfo.spell) + - "(" + - heroInfo.matk + - "%)", - 90, - 285, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); - core.fillBoldText( - ctx, - "护盾 " + - core.formatBigNumber((heroInfo.mhp / 100) * heroInfo.spell) + - "(" + - heroInfo.mhp + - "%)", - 90, - 305, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); - core.fillBoldText( - ctx, - "法抗 " + heroInfo.mdef + "%", - 90, - 325, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); - core.fillBoldText( - ctx, - "速度 " + core.formatBigNumber(heroInfo.speed), - 90, - 345, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); + this.drawAttackAnimate = function ( + heroInfo, + oneTurn, + enemyInfo, + equipInfo, + farme, + damageInfo + ) { + let attack = false; + if (heroInfo.isAttack) attack = true; + if (enemyInfo.isAttack) attack = true; + equipInfo.forEach(function (v) { + if (v.isAttack) attack = true; + }); + core.clearMap(ctx); + let animate = Math.floor(farme / 30); + core.fillRect(ctx, 64, 64, 288, 288, "rgba(0,0,0,0.5)"); + core.strokeRect(ctx, 64, 64, 288, 288, "rgba(255,255,255,0.5)", 4); + core.setTextAlign(ctx, "center"); + core.fillBoldText( + ctx, + hero.name, + 127, + 128, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); + core.setTextAlign(ctx, "left"); + core.drawIcon(ctx, "hp", 70, 190, 16, 16); + core.drawIcon(ctx, "atk", 70, 210, 16, 16); + core.drawIcon(ctx, "def", 70, 230, 16, 16); + core.drawIcon(ctx, "I374", 70, 250, 16, 16); + core.drawIcon(ctx, "I375", 70, 270, 16, 16); + core.drawIcon(ctx, "mdef", 70, 290, 16, 16); + core.drawIcon(ctx, "amulet", 70, 310, 16, 16); + core.drawIcon(ctx, "jumpShoes", 70, 330, 16, 16); + core.fillBoldText( + ctx, + "生命 " + + core.formatBigNumber(heroInfo.hp, true) + + 90, + 205, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); + core.fillBoldText( + ctx, + "攻击 " + core.formatBigNumber(heroInfo.atk), + 90, + 225, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); + core.fillBoldText( + ctx, + "防御 " + core.formatBigNumber(heroInfo.def), + 90, + 245, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); + core.fillBoldText( + ctx, + "法强 " + core.formatBigNumber(heroInfo.spell), + 90, + 265, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); + core.fillBoldText( + ctx, + "法攻 " + + core.formatBigNumber((heroInfo.matk / 100) * heroInfo.spell) + + "(" + + heroInfo.matk + + "%)", + 90, + 285, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); + core.fillBoldText( + ctx, + "护盾 " + + core.formatBigNumber((heroInfo.mhp / 100) * heroInfo.spell) + + "(" + + heroInfo.mhp + + "%)", + 90, + 305, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); + core.fillBoldText( + ctx, + "法抗 " + heroInfo.mdef + "%", + 90, + 325, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); + core.fillBoldText( + ctx, + "速度 " + core.formatBigNumber(heroInfo.speed), + 90, + 345, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); - core.strokeRect(ctx, 112, 139, 32, 48, "rgba(255,255,255,1)", 1); - core.drawImage( - ctx, - "hero.webp", - 32 * (animate % 4), - 0, - 32, - 48, - 112, - 139, - 32, - 48 - ); + core.strokeRect(ctx, 112, 139, 32, 48, "rgba(255,255,255,1)", 1); + core.drawImage( + ctx, + "hero.webp", + 32 * (animate % 4), + 0, + 32, + 48, + 112, + 139, + 32, + 48 + ); - core.setTextAlign(ctx, "center"); - core.fillBoldText( - ctx, - enemyInfo.name, - 289, - 128, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); + core.setTextAlign(ctx, "center"); + core.fillBoldText( + ctx, + enemyInfo.name, + 289, + 128, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); - core.setTextAlign(ctx, "right"); - if (enemyInfo.cls === "enemys") { - core.strokeRect(ctx, 272, 155, 32, 32, "rgba(255,255,255,1)", 1); + core.setTextAlign(ctx, "right"); + if (enemyInfo.cls === "enemys") { + core.strokeRect(ctx, 272, 155, 32, 32, "rgba(255,255,255,1)", 1); - core.drawImage( - ctx, - core.getBlockInfo(enemyInfo.id).image, - 32 * (animate % 2), - core.getBlockInfo(enemyInfo.id).posY * 32, - 32, - 32, - 272, - 155, - 32, - 32 - ); - } else { - core.strokeRect(ctx, 272, 139, 32, 48, "rgba(255,255,255,1)", 1); + core.drawImage( + ctx, + core.getBlockInfo(enemyInfo.id).image, + 32 * (animate % 2), + core.getBlockInfo(enemyInfo.id).posY * 32, + 32, + 32, + 272, + 155, + 32, + 32 + ); + } else { + core.strokeRect(ctx, 272, 139, 32, 48, "rgba(255,255,255,1)", 1); - core.drawImage( - ctx, - core.getBlockInfo(enemyInfo.id).image, - 32 * (animate % 4), - core.getBlockInfo(enemyInfo.id).posY * 48, - 32, - 48, - 272, - 139, - 32, - 48 - ); - } - core.drawIcon(ctx, "hp", 330, 190, 16, 16); - core.drawIcon(ctx, "atk", 330, 210, 16, 16); - core.drawIcon(ctx, "def", 330, 230, 16, 16); - core.drawIcon(ctx, "amulet", 330, 250, 16, 16); - core.drawIcon(ctx, "jumpShoes", 330, 270, 16, 16); - core.fillBoldText( - ctx, - core.formatBigNumber(enemyInfo.hp, true) + " 生命", - 330, - 205, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); - core.fillBoldText( - ctx, - core.formatBigNumber(enemyInfo.atk) + " 攻击", - 330, - 225, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); - core.fillBoldText( - ctx, - core.formatBigNumber(enemyInfo.def) + " 防御", - 330, - 245, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); + core.drawImage( + ctx, + core.getBlockInfo(enemyInfo.id).image, + 32 * (animate % 4), + core.getBlockInfo(enemyInfo.id).posY * 48, + 32, + 48, + 272, + 139, + 32, + 48 + ); + } + core.drawIcon(ctx, "hp", 330, 190, 16, 16); + core.drawIcon(ctx, "atk", 330, 210, 16, 16); + core.drawIcon(ctx, "def", 330, 230, 16, 16); + core.drawIcon(ctx, "amulet", 330, 250, 16, 16); + core.drawIcon(ctx, "jumpShoes", 330, 270, 16, 16); + core.fillBoldText( + ctx, + core.formatBigNumber(enemyInfo.hp, true) + " 生命", + 330, + 205, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); + core.fillBoldText( + ctx, + core.formatBigNumber(enemyInfo.atk) + " 攻击", + 330, + 225, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); + core.fillBoldText( + ctx, + core.formatBigNumber(enemyInfo.def) + " 防御", + 330, + 245, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); - core.fillBoldText( - ctx, - (enemyInfo.mdef ?? 0) * 100 + "% 法抗", - 330, - 265, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); - core.fillBoldText( - ctx, - core.formatBigNumber(enemyInfo.speed) + " 速度", - 330, - 285, - "#FFFFFF", - "#000000", - "bold 14px pala" - ); - core.fillBoldText( - ctx, - "V", - 219, - 163, - "#FFFFFF", - "#000000", - "bold 48px pala" - ); - core.fillBoldText( - ctx, - "s", - 231, - 163, - "#FFFFFF", - "#000000", - "bold 36px pala" - ); + core.fillBoldText( + ctx, + (enemyInfo.mdef ?? 0) * 100 + "% 法抗", + 330, + 265, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); + core.fillBoldText( + ctx, + core.formatBigNumber(enemyInfo.speed) + " 速度", + 330, + 285, + "#FFFFFF", + "#000000", + "bold 14px pala" + ); + core.fillBoldText( + ctx, + "V", + 219, + 163, + "#FFFFFF", + "#000000", + "bold 48px pala" + ); + core.fillBoldText( + ctx, + "s", + 231, + 163, + "#FFFFFF", + "#000000", + "bold 36px pala" + ); - if (!attack) enemyInfo.now += (enemyInfo.speed / oneTurn) * 215; - let enemynow = Math.min(100 + enemyInfo.now, 315); - ctx.fillStyle = "#FFFFFF"; - ctx.beginPath(); - ctx.moveTo(enemynow, 100); - ctx.lineTo(enemynow + 3, 90); - ctx.lineTo(enemynow - 3, 90); - ctx.closePath(); - ctx.fill(); + if (!attack) enemyInfo.now += (enemyInfo.speed / oneTurn) * 215; + let enemynow = Math.min(100 + enemyInfo.now, 315); + ctx.fillStyle = "#FFFFFF"; + ctx.beginPath(); + ctx.moveTo(enemynow, 100); + ctx.lineTo(enemynow + 3, 90); + ctx.lineTo(enemynow - 3, 90); + ctx.closePath(); + ctx.fill(); - if (enemyInfo.cls === "enemys") { - core.drawImage( - ctx, - core.getBlockInfo(enemyInfo.id).image, - 32, - core.getBlockInfo(enemyInfo.id).posY * 32, - 32, - 32, - enemynow - 16, - 64, - 32, - 32 - ); - } else { - core.drawImage( - ctx, - core.getBlockInfo(enemyInfo.id).image, - 32, - core.getBlockInfo(enemyInfo.id).posY * 48, - 32, - 19, - enemynow - 16, - 70, - 32, - 19 - ); - } - core.drawLine(ctx, 100, 105, 315, 105, "#FFFFFF", 5); - equipInfo.forEach(function (v) { - if (!attack) v.now += (v.speed / oneTurn) * 215; - let vnow = Math.min(100 + v.now, 315); - ctx.beginPath(); - ctx.moveTo(vnow, 100); - ctx.lineTo(vnow + 3, 90); - ctx.lineTo(vnow - 3, 90); - ctx.closePath(); + if (enemyInfo.cls === "enemys") { + core.drawImage( + ctx, + core.getBlockInfo(enemyInfo.id).image, + 32, + core.getBlockInfo(enemyInfo.id).posY * 32, + 32, + 32, + enemynow - 16, + 64, + 32, + 32 + ); + } else { + core.drawImage( + ctx, + core.getBlockInfo(enemyInfo.id).image, + 32, + core.getBlockInfo(enemyInfo.id).posY * 48, + 32, + 19, + enemynow - 16, + 70, + 32, + 19 + ); + } + core.drawLine(ctx, 100, 105, 315, 105, "#FFFFFF", 5); + equipInfo.forEach(function (v) { + if (!attack) v.now += (v.speed / oneTurn) * 215; + let vnow = Math.min(100 + v.now, 315); + ctx.beginPath(); + ctx.moveTo(vnow, 100); + ctx.lineTo(vnow + 3, 90); + ctx.lineTo(vnow - 3, 90); + ctx.closePath(); - ctx.fill(); + ctx.fill(); - core.drawIcon(ctx, v.id, vnow - 16, 64, 32, 32); - }); - if (!attack) heroInfo.now += (heroInfo.speed / oneTurn) * 215; - let heronow = Math.min(100 + heroInfo.now, 315); - ctx.beginPath(); - ctx.moveTo(heronow, 100); - ctx.lineTo(heronow + 3, 90); - ctx.lineTo(heronow - 3, 90); - ctx.closePath(); + core.drawIcon(ctx, v.id, vnow - 16, 64, 32, 32); + }); + if (!attack) heroInfo.now += (heroInfo.speed / oneTurn) * 215; + let heronow = Math.min(100 + heroInfo.now, 315); + ctx.beginPath(); + ctx.moveTo(heronow, 100); + ctx.lineTo(heronow + 3, 90); + ctx.lineTo(heronow - 3, 90); + ctx.closePath(); - ctx.fill(); - core.drawImage(ctx, "hero.webp", 0, 0, 32, 19, heronow - 16, 70, 32, 19); + ctx.fill(); + core.drawImage(ctx, "hero.webp", 0, 0, 32, 19, heronow - 16, 70, 32, 19); - if (heroInfo.now >= 215 && !heroInfo.isAttack) { - heroInfo.isAttack = true; - animateOnAttack("sword", true, () => { - heroInfo.now -= 215; - heroInfo.isAttack = false; - }); - } - if (enemyInfo.now >= 215 && !enemyInfo.isAttack) { - enemyInfo.isAttack = true; - animateOnAttack("sword", false, () => { - enemyInfo.now -= 215; - enemyInfo.isAttack = false; - }); - } - equipInfo.forEach((v) => { - if (v.now >= 215 && !v.isAttack) { - v.isAttack = true; + if (heroInfo.now >= 215 && !heroInfo.isAttack) { + heroInfo.isAttack = true; + animateOnAttack("sword", true, () => { + heroInfo.now -= 215; + heroInfo.isAttack = false; + }); + } + if (enemyInfo.now >= 215 && !enemyInfo.isAttack) { + enemyInfo.isAttack = true; + animateOnAttack("sword", false, () => { + enemyInfo.now -= 215; + enemyInfo.isAttack = false; + }); + } + equipInfo.forEach((v) => { + if (v.now >= 215 && !v.isAttack) { + v.isAttack = true; - animateOnAttack("sword", true, () => { - v.now -= 215; - v.isAttack = false; - }); - } - }); - }; + animateOnAttack("sword", true, () => { + v.now -= 215; + v.isAttack = false; + }); + } + }); + }; - function animateOnAttack(name, onenemy, callback) { - if (onenemy) { - core.playanimate(name, 290, 160, null, 1, 1, callback); - } else { - core.playanimate(name, 130, 160, null, 1, 1, callback); - } - } + function animateOnAttack(name, onenemy, callback) { + if (onenemy) { + core.playanimate(name, 290, 160, null, 1, 1, callback); + } else { + core.playanimate(name, 130, 160, null, 1, 1, callback); + } + } - this.attackAnimate = function ( - enemyId, - enemyInfo, - damageInfo, - equipInfo = [] - ) { - //参数分别为怪物真实属性,战斗信息,特殊装备(如火焰风衣)属性特殊装备属性为以元组{equipId,oneDamage,speed,now:0}构成的数组(列出每个需要计算的特殊装备,没有则为空数组或不填) - core.lockControl(); - core.clearMap(ctx); - core.status.event.id = "attackAnimate"; - let hero_hp = core.getRealStatusOrDefault(hero, "hp"), - hero_atk = core.getRealStatusOrDefault(hero, "atk"), - hero_def = core.getRealStatusOrDefault(hero, "def"), - hero_spell = core.getRealStatusOrDefault(hero, "spell"), - hero_matk = core.getRealStatusOrDefault(hero, "matk"), - hero_mdef = core.getRealStatusOrDefault(hero, "mdef"), - hero_speed = core.getRealStatusOrDefault(hero, "speed"), - hero_hpmax = core.getRealStatusOrDefault(hero, "hpmax"), - hero_mhp = core.getRealStatusOrDefault(hero, "mhp"); - const heroInfo = { - hp: hero_hp, - hpmax: hero_hpmax, - atk: hero_atk, - def: hero_def, - spell: hero_spell, - mhp: hero_mhp, - matk: hero_matk, - mdef: hero_mdef, - speed: hero_speed, - now: 0, - isAttack: false, - }; - enemyInfo.id = enemyId; - enemyInfo.cls = core.getClsFromId(enemyId); - enemyInfo.name = core.material.enemys[enemyId].name; - enemyInfo.now = 0; - enemyInfo.isAttack = false; - let oneTurn = heroInfo.speed + enemyInfo.speed; - if (equipInfo.length > 0) { - for (let i; i < equipInfo.length - 1; i++) { - equipInfo[i].now = 0; - equipInfo[i].isAttack = false; - oneTurn += equipInfo[i].speed; - } - } - oneTurn *= 25; - let time = 0, - farme = 0; + this.attackAnimate = function ( + enemyId, + enemyInfo, + damageInfo, + equipInfo = [] + ) { + //参数分别为怪物真实属性,战斗信息,特殊装备(如火焰风衣)属性特殊装备属性为以元组{equipId,oneDamage,speed,now:0}构成的数组(列出每个需要计算的特殊装备,没有则为空数组或不填) + core.lockControl(); + core.clearMap(ctx); + core.status.event.id = "attackAnimate"; + let hero_hp = core.getRealStatusOrDefault(hero, "hp"), + hero_atk = core.getRealStatusOrDefault(hero, "atk"), + hero_def = core.getRealStatusOrDefault(hero, "def"), + hero_spell = core.getRealStatusOrDefault(hero, "spell"), + hero_matk = core.getRealStatusOrDefault(hero, "matk"), + hero_mdef = core.getRealStatusOrDefault(hero, "mdef"), + hero_speed = core.getRealStatusOrDefault(hero, "speed"), + hero_hpmax = core.getRealStatusOrDefault(hero, "hpmax"), + hero_mhp = core.getRealStatusOrDefault(hero, "mhp"); + const heroInfo = { + hp: hero_hp, + hpmax: hero_hpmax, + atk: hero_atk, + def: hero_def, + spell: hero_spell, + mhp: hero_mhp, + matk: hero_matk, + mdef: hero_mdef, + speed: hero_speed, + now: 0, + isAttack: false, + }; + enemyInfo.id = enemyId; + enemyInfo.cls = core.getClsFromId(enemyId); + enemyInfo.name = core.material.enemys[enemyId].name; + enemyInfo.now = 0; + enemyInfo.isAttack = false; + let oneTurn = heroInfo.speed + enemyInfo.speed; + if (equipInfo.length > 0) { + for (let i; i < equipInfo.length - 1; i++) { + equipInfo[i].now = 0; + equipInfo[i].isAttack = false; + oneTurn += equipInfo[i].speed; + } + } + oneTurn *= 25; + let time = 0, + farme = 0; - core.registerAnimationFrame("attackAnimate", true, (temptime) => { - if (temptime - time > 1000 / 60) { - time = temptime; - this.drawAttackAnimate( - heroInfo, - oneTurn, - enemyInfo, - equipInfo, - farme, - damageInfo - ); - farme++; - } - }); - }; - }, + core.registerAnimationFrame("attackAnimate", true, (temptime) => { + if (temptime - time > 1000 / 60) { + time = temptime; + this.drawAttackAnimate( + heroInfo, + oneTurn, + enemyInfo, + equipInfo, + farme, + damageInfo + ); + farme++; + } + }); + }; +}, "剧情内容": function () { // 在此增加新插件 // 每项为一个数组,第一项是名字,第二项是对话内容 @@ -19564,5 +19570,45 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = ["梅尔特", "「我忘记了」"], ["吉克", "「骗人」"], ]; - } + }, + "勇士法抗乘算叠加": function () { + // 在此增加新插件 + items.prototype.compareEquipment = function (compareEquipId, beComparedEquipId) { + var result = { "value": {}, "percentage": {} }; + var first = core.material.items[compareEquipId], + second = core.material.items[beComparedEquipId]; + for (var one in result) { + for (var name in core.status.hero) { + if (name === "mdef" && one === 'value') { + var ans = 1; + if (first) ans *= (((first.equip || {})[one] || {})[name] || 0) / 100 + 1; + if (second) ans /= (((second.equip || {})[one] || {})[name] || 0) / 100 + 1; + if (ans != 1) result[one][name] = ans; + } else { + if (typeof core.status.hero[name] == 'number') { + var ans = 0; + if (first) ans += ((first.equip || {})[one] || {})[name] || 0; + if (second) ans -= ((second.equip || {})[one] || {})[name] || 0; + if (ans != 0) result[one][name] = ans; + } + } + } + } + return result; + } + items.prototype._loadEquipEffect = function (equipId, unloadEquipId) { + // 比较能力值 + var result = core.compareEquipment(equipId, unloadEquipId); + + for (var name in result.percentage) + core.addBuff(name, result.percentage[name] / 100); + + for (var name in result.value) + if (name === 'mdef') { + core.status.hero[name] += (result.value[name] - 1) * 100 + } else { + core.status.hero[name] += result.value[name]; + } + } +} } \ No newline at end of file