diff --git a/public/libs/control.js b/public/libs/control.js index a3cd94a..7fbd0c2 100644 --- a/public/libs/control.js +++ b/public/libs/control.js @@ -1492,65 +1492,7 @@ control.prototype.updateDamage = function (floorId, ctx) { }; control.prototype._updateDamage_damage = function (floorId, onMap) { - core.status.damage.data = []; - if (!core.flags.displayEnemyDamage && !core.flags.displayExtraDamage) - return; - - core.extractBlocks(floorId); - core.status.maps[floorId].blocks.forEach(function (block) { - var x = block.x, - y = block.y; - - // v2优化,只绘制范围内的部分 - if (onMap && core.bigmap.v2) { - if ( - x < core.bigmap.posX - core.bigmap.extend || - x > core.bigmap.posX + core._WIDTH_ + core.bigmap.extend || - y < core.bigmap.posY - core.bigmap.extend || - y > core.bigmap.posY + core._HEIGHT_ + core.bigmap.extend - ) { - return; - } - } - - if ( - !block.disable && - block.event.cls.indexOf('enemy') == 0 && - block.event.displayDamage !== false - ) { - if (core.flags.displayEnemyDamage) { - var damageString = core.enemys.getDamageString( - block.event.id, - x, - y, - floorId - ); - core.status.damage.data.push({ - text: damageString.damage, - px: 32 * x + 1, - py: 32 * (y + 1) - 1, - color: damageString.color - }); - } - if (core.flags.displayCritical) { - var critical = core.enemys.nextCriticals( - block.event.id, - 1, - x, - y, - floorId - ); - critical = core.formatBigNumber((critical[0] || [])[0], true); - if (critical == '???') critical = '?'; - core.status.damage.data.push({ - text: critical, - px: 32 * x + 1, - py: 32 * (y + 1) - 11, - color: '#FFFFFF' - }); - } - } - }); + // Deprecated. See src/plugin/game/damage.ts EnemyCollection.render. }; control.prototype._updateDamage_extraDamage = function (floorId, onMap) { @@ -1558,7 +1500,7 @@ control.prototype._updateDamage_extraDamage = function (floorId, onMap) { }; ////// 重绘地图显伤 ////// -control.prototype.drawDamage = function (ctx) { +control.prototype.drawDamage = function (ctx, floorId = core.status.floorId) { if (core.status.gameOver || !core.status.damage || main.mode != 'play') return; var onMap = false; @@ -1579,53 +1521,11 @@ control.prototype.drawDamage = function (ctx) { return this.updateDamage(); } } - return this._drawDamage_draw(ctx, onMap); + return this._drawDamage_draw(ctx, onMap, floorId); }; control.prototype._drawDamage_draw = function (ctx, onMap) { - if (!core.hasItem('book')) return; - core.plugin.halo.drawHalo(ctx, onMap); - - core.setFont(ctx, "14px 'normal'"); - core.setTextAlign(ctx, 'center'); - core.setTextBaseline(ctx, 'middle'); - core.status.damage.extraData.forEach(function (one) { - var px = one.px, - py = one.py; - if (onMap && core.bigmap.v2) { - px -= core.bigmap.posX * 32; - py -= core.bigmap.posY * 32; - if ( - px < -32 || - px > core._PX_ + 32 || - py < -32 || - py > core._PY_ + 32 - ) - return; - } - var alpha = core.setAlpha(ctx, one.alpha); - core.fillBoldText(ctx, one.text, px, py, one.color); - core.setAlpha(ctx, alpha); - }); - - core.setTextAlign(ctx, 'left'); - core.setTextBaseline(ctx, 'alphabetic'); - core.status.damage.data.forEach(function (one) { - var px = one.px, - py = one.py; - if (onMap && core.bigmap.v2) { - px -= core.bigmap.posX * 32; - py -= core.bigmap.posY * 32; - if ( - px < -32 * 2 || - px > core._PX_ + 32 || - py < -32 || - py > core._PY_ + 32 - ) - return; - } - core.fillBoldText(ctx, one.text, px, py, one.color); - }); + // Deprecated. See src/plugin/game/popup.js }; // ------ 录像相关 ------ // diff --git a/public/libs/enemys.js b/public/libs/enemys.js index e0450a1..ccabad3 100644 --- a/public/libs/enemys.js +++ b/public/libs/enemys.js @@ -448,7 +448,7 @@ enemys.prototype._getDamage = function (enemy, hero, x, y, floorId) { ////// 获得当前楼层的怪物列表 ////// enemys.prototype.getCurrentEnemys = function (floorId) { - // todo: 删除getEnemyInfo - _getCurrentEnemys_addEnemy + // todo: 删除 getEnemyInfo - _getCurrentEnemys_addEnemy floorId = floorId || core.status.floorId; var enemys = [], used = {}; diff --git a/public/libs/maps.js b/public/libs/maps.js index 2e0033d..79ad849 100644 --- a/public/libs/maps.js +++ b/public/libs/maps.js @@ -939,8 +939,7 @@ maps.prototype._canMoveDirectly_checkGlobal = function () { }; maps.prototype._canMoveDirectly_checkStartPoint = function (sx, sy) { - // todo: 不使用 core.status.checkBlock - if (core.status.checkBlock.damage[sx + ',' + sy]) return false; + if (core.status.thisMap.enemy.mapDamage[`${sx},${sy}`]) return false; var block = core.getBlock(sx, sy); if (block != null) { // 只有起点是传送点才是能无视 @@ -2589,8 +2588,6 @@ maps.prototype._drawThumbnail_realDrawTempCanvas = function ( options.ctx.imageSmoothingEnabled = true; // 缩略图:显伤 if (options.damage && core.hasItem('book')) { - // todo: 删除 updateCheckBlock - core.updateCheckBlock(floorId); core.control.updateDamage(floorId, options.ctx); } }; diff --git a/public/libs/ui.js b/public/libs/ui.js index 7f25a47..ff6838f 100644 --- a/public/libs/ui.js +++ b/public/libs/ui.js @@ -3302,7 +3302,6 @@ ui.prototype._drawViewMaps = function (index, x, y) { if (index == null) return this._drawViewMaps_drawHint(); core.animateFrame.tip = null; // todo: 不使用 core.status.checkBlock - core.status.checkBlock.cache = {}; var data = this._drawViewMaps_buildData(index, x, y); core.fillRect('ui', 0, 0, core._PX_, core._PY_, '#000000'); core.drawThumbnail(data.floorId, null, { diff --git a/src/plugin/game/damage.ts b/src/plugin/game/damage.ts index 3a04311..86fd0ce 100644 --- a/src/plugin/game/damage.ts +++ b/src/plugin/game/damage.ts @@ -54,6 +54,7 @@ interface HaloData { type: T; data: HaloType[T]; from: DamageEnemy; + special: number; } interface DamageDelta { @@ -107,8 +108,8 @@ export class EnemyCollection implements RangeCollection { * 计算怪物真实属性 * @param noCache 是否不使用缓存 */ - calRealAttribute(noCache: boolean = false) { - if (!noCache) return; + calRealAttribute() { + this.haloList = []; this.list.forEach(v => { v.reset(); v.preProvideHalo(); @@ -127,7 +128,7 @@ export class EnemyCollection implements RangeCollection { * @param noCache 是否不使用缓存 */ calDamage(noCache: boolean = false, onMap: boolean = false) { - if (noCache) this.calRealAttribute(noCache); + if (noCache) this.calRealAttribute(); this.list.forEach(v => { v.calDamage(void 0, onMap); }); @@ -137,9 +138,8 @@ export class EnemyCollection implements RangeCollection { * 计算地图伤害 * @param noCache 是否不使用缓存 */ - calMapDamage(noCache: boolean = false) { - if (!noCache) return; - if (noCache) this.mapDamage = {}; + calMapDamage() { + this.mapDamage = {}; const hero = getHeroStatusOn( realStatus, core.status.hero.loc.x, @@ -200,7 +200,7 @@ export class EnemyCollection implements RangeCollection { ) { if (cal) { this.calDamage(noCache, true); - this.calMapDamage(noCache); + this.calMapDamage(); } core.status.damage.data = []; core.status.damage.extraData = []; @@ -527,6 +527,12 @@ export class DamageEnemy { e.damageDecline += this.enemy.iceHalo ?? 0; }); this.providedHalo.push(21); + col.haloList.push({ + type: 'square', + data: { x: this.x, y: this.y, d: 7 }, + special: 21, + from: this + }); } // 冰封之核 @@ -535,6 +541,12 @@ export class DamageEnemy { e.defBuff += this.enemy.iceCore ?? 0; }); this.providedHalo.push(26); + col.haloList.push({ + type: 'square', + data: { x: this.x, y: this.y, d: 5 }, + special: 26, + from: this + }); } // 火焰之核 @@ -543,6 +555,12 @@ export class DamageEnemy { e.atkBuff += this.enemy.fireCore ?? 0; }); this.providedHalo.push(27); + col.haloList.push({ + type: 'square', + data: { x: this.x, y: this.y, d: 5 }, + special: 27, + from: this + }); } col.applyHalo('square', { x: this.x, y: this.y, d: 7 }, square7); diff --git a/src/plugin/game/halo.js b/src/plugin/game/halo.js deleted file mode 100644 index 118aa9f..0000000 --- a/src/plugin/game/halo.js +++ /dev/null @@ -1,55 +0,0 @@ -/// - -/** - * 绘制光环范围 - * @param {CanvasRenderingContext2D} ctx - * @param {boolean} onMap - */ -export function drawHalo(ctx, onMap) { - if (main.replayChecking) return; - if (!core.getLocalStorage('showHalo', true)) return; - // todo: 不使用 core.status.checkBlock - const halo = core.status.checkBlock.halo; - ctx.save(); - for (const [loc, range] of Object.entries(halo)) { - const [x, y] = loc.split(',').map(v => parseInt(v)); - for (const r of range) { - const [type, value, color, border] = r.split(':'); - if (type === 'square') { - // 正方形光环 - const n = parseInt(value); - const r = Math.floor(n / 2); - let left = x - r, - right = x + r, - top = y - r, - bottom = y + r; - if (onMap && core.bigmap.v2) { - left -= core.bigmap.posX; - top -= core.bigmap.posY; - right -= core.bigmap.posX; - bottom -= core.bigmap.posY; - if ( - right < -1 || - left > core._PX_ / 32 + 1 || - top < -1 || - bottom > core._PY_ / 32 + 1 - ) { - continue; - } - } - ctx.fillStyle = color; - ctx.strokeStyle = border ?? color; - ctx.lineWidth = 1; - ctx.globalAlpha = 0.1; - ctx.fillRect(left * 32, top * 32, n * 32, n * 32); - ctx.globalAlpha = 0.6; - ctx.strokeRect(left * 32, top * 32, n * 32, n * 32); - } - } - } - ctx.restore(); -} - -core.plugin.halo = { - drawHalo -}; diff --git a/src/plugin/game/halo.ts b/src/plugin/game/halo.ts new file mode 100644 index 0000000..ce6b1da --- /dev/null +++ b/src/plugin/game/halo.ts @@ -0,0 +1,50 @@ +const haloColor: Record = { + 21: ['cyan'], + 26: ['blue'], + 27: ['red'] +}; + +export function drawHalo( + ctx: CanvasRenderingContext2D, + onMap: boolean, + floorId: FloorIds +) { + if (main.replayChecking) return; + if (!core.getLocalStorage('showHalo', true)) return; + const list = core.status.maps[floorId].enemy.haloList; + ctx.save(); + for (const halo of list) { + if (halo.type === 'square') { + const { x, y, d } = halo.data; + const [color, border] = haloColor[halo.special]; + const r = Math.floor(d / 2); + let left = x - r, + right = x + r, + top = y - r, + bottom = y + r; + if (onMap && core.bigmap.v2) { + left -= core.bigmap.posX; + top -= core.bigmap.posY; + right -= core.bigmap.posX; + bottom -= core.bigmap.posY; + if ( + right < -1 || + left > core._PX_ / 32 + 1 || + top < -1 || + bottom > core._PY_ / 32 + 1 + ) { + continue; + } + } + ctx.fillStyle = color; + ctx.strokeStyle = border ?? color; + ctx.lineWidth = 1; + ctx.globalAlpha = 0.1; + ctx.fillRect(left * 32, top * 32, d * 32, d * 32); + ctx.globalAlpha = 0.6; + ctx.strokeRect(left * 32, top * 32, d * 32, d * 32); + } + } + + ctx.restore(); +} diff --git a/src/plugin/game/itemDetail.ts b/src/plugin/game/itemDetail.ts index 6797c11..25f0d63 100644 --- a/src/plugin/game/itemDetail.ts +++ b/src/plugin/game/itemDetail.ts @@ -19,15 +19,13 @@ core.control.updateDamage = function (floorId = core.status.floorId, ctx) { core.plugin.damage.ensureFloorDamage(floorId); floor.enemy.calDamage(true, onMap); - floor.enemy.calMapDamage(true); + floor.enemy.calMapDamage(); core.status.damage.data = []; floor.enemy.render(); - // this._updateDamage_damage(floorId, onMap); - // this._updateDamage_extraDamage(floorId, onMap); getItemDetail(floorId, onMap); // 宝石血瓶详细信息 - this.drawDamage(ctx); + this.drawDamage(ctx, floorId); }; // 获取宝石信息 并绘制 diff --git a/src/plugin/game/popup.js b/src/plugin/game/popup.js index 7a69ea7..ade3598 100644 --- a/src/plugin/game/popup.js +++ b/src/plugin/game/popup.js @@ -1,5 +1,5 @@ /// -export {}; +import { drawHalo } from './halo'; // 伤害弹出 // 复写阻激夹域检测 @@ -40,9 +40,9 @@ control.prototype.checkBlock = function (forceMockery) { /** * @param {CanvasRenderingContext2D} ctx */ -control.prototype._drawDamage_draw = function (ctx, onMap) { +control.prototype._drawDamage_draw = function (ctx, onMap, floorId) { if (!core.hasItem('book')) return; - core.plugin.halo.drawHalo(ctx, onMap); + drawHalo(ctx, onMap, floorId); core.setFont(ctx, "14px 'normal'"); core.setTextAlign(ctx, 'center'); diff --git a/src/types/control.d.ts b/src/types/control.d.ts index a97dcae..c6a7fc7 100644 --- a/src/types/control.d.ts +++ b/src/types/control.d.ts @@ -490,7 +490,7 @@ interface Control { * 重绘地图显伤 * @param ctx 绘制到的画布 */ - drawDamage(ctx?: CtxRefer): void; + drawDamage(ctx?: CtxRefer, floorId: FloorIds): void; /** * 选择录像文件