diff --git a/public/libs/control.js b/public/libs/control.js index 67edf7b..9fded0a 100644 --- a/public/libs/control.js +++ b/public/libs/control.js @@ -1501,7 +1501,7 @@ control.prototype.drawDamage = function (ctx, floorId = core.status.floorId) { }; control.prototype._drawDamage_draw = function (ctx, onMap) { - // Deprecated. See src/plugin/game/popup.js + // Deprecated. See src/plugin/game/fx/checkblock.js }; // ------ 录像相关 ------ // diff --git a/public/libs/enemys.js b/public/libs/enemys.js index b68a2a4..54090fa 100644 --- a/public/libs/enemys.js +++ b/public/libs/enemys.js @@ -207,29 +207,7 @@ enemys.prototype.canBattle = function (enemy, x, y, floorId) { }; enemys.prototype.getDamageString = function (enemy, x, y, floorId, hero) { - // todo: 删除 - if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; - var damage = this.getDamage(enemy, x, y, floorId, hero); - - var color = '#000000'; - - if (damage == null) { - damage = '???'; - color = '#FF2222'; - } else { - if (damage <= 0) color = '#11FF11'; - else if (damage < core.status.hero.hp / 3) color = '#FFFFFF'; - else if (damage < (core.status.hero.hp * 2) / 3) color = '#FFFF00'; - else if (damage < core.status.hero.hp) color = '#FF9933'; - else color = '#FF2222'; - - damage = core.formatBigNumber(damage, true); - } - - return { - damage: damage, - color: color - }; + // Deprecated. }; ////// 接下来N个临界值和临界减伤计算 ////// diff --git a/src/plugin/game/fx/rewrite.ts b/src/plugin/game/fx/rewrite.ts new file mode 100644 index 0000000..71e333f --- /dev/null +++ b/src/plugin/game/fx/rewrite.ts @@ -0,0 +1,70 @@ +import { getEnemy } from '../enemy/battle'; +import { DamageDir, getNeedCalDir } from '../enemy/damage'; +import { formatDamage } from '../utils'; + +export {}; + +core.maps._initDetachedBlock = function ( + info: BlockInfo, + x: number, + y: number, + displayDamage: boolean = false +) { + let headCanvas = null, + bodyCanvas = '__body_' + x + '_' + y, + damageCanvas = null; + + // head + if (!info.bigImage && info.height > 32) { + headCanvas = '__head_' + x + '_' + y; + core.createCanvas(headCanvas, 0, 0, 32, info.height - 32, 55); + } + // body + if (info.bigImage) { + var bigImageInfo = this._getBigImageInfo( + info.bigImage, + info.face, + info.posX + ); + const { per_width, per_height } = bigImageInfo; + core.createCanvas(bodyCanvas, 0, 0, per_width, per_height, 35); + } else { + core.createCanvas(bodyCanvas, 0, 0, 32, 32, 35); + } + + // 伤害 + if ( + info.cls.indexOf('enemy') == 0 && + core.hasItem('book') && + displayDamage + ) { + const enemy = getEnemy(x, y); + const dam = enemy.calEnemyDamage(core.status.hero, getNeedCalDir(x, y)); + let min = Infinity; + let minDir: DamageDir = 'none'; + for (const d of dam) { + if (d.damage < min) { + min = d.damage; + minDir = d.dir; + } + } + const { damage, color } = formatDamage(min); + + damageCanvas = '__damage_' + x + '_' + y; + const ctx = core.createCanvas(damageCanvas, 0, 0, 32, 32, 65); + ctx.textAlign = 'left'; + ctx.font = '14px normal'; + core.fillBoldText(ctx, damage, 1, 31, color as string); + if (core.flags.displayCritical) { + const critical = enemy.calCritical(1, minDir)[0]; + const atk = core.formatBigNumber(critical[0].dirDelta, true); + const display = atk === '???' ? '?' : atk; + core.fillBoldText(ctx, display, 1, 21, '#FFFFFF'); + } + } + return { + headCanvas, + bodyCanvas, + damageCanvas + }; +}; diff --git a/src/plugin/game/index.js b/src/plugin/game/index.js index fb2f24c..bd9475f 100644 --- a/src/plugin/game/index.js +++ b/src/plugin/game/index.js @@ -5,6 +5,7 @@ import './fx/itemDetail'; import './enemy/checkblock'; import './replay'; import './ui'; +import './fx/rewrite'; import * as halo from './fx/halo'; import * as hero from './hero'; import * as loopMap from './loopMap'; diff --git a/src/types/map.d.ts b/src/types/map.d.ts index 4a7357f..74be353 100644 --- a/src/types/map.d.ts +++ b/src/types/map.d.ts @@ -1380,6 +1380,19 @@ interface Maps { stopAnimate(id?: number, doCallback?: boolean): void; _makeAutotileEdges(): void; + + _initDetachedBlock( + info: BlockInfo, + x: number, + y: number, + displayDamage: boolean + ): { + headCanvas: string | null; + bodyCanvas: string; + damageCanvas: string | null; + }; + + _getBigImageInfo(bigImage: HTMLImageElement, face: Dir, posX: number): any; } declare const maps: new () => Maps;