From 24ff4b682f0a075bd52e840c7558c63eb04644b2 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Fri, 30 Jun 2023 22:34:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E4=BC=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin/game/damage.ts | 96 ++++++++++++++++++++++++++++++++++- src/plugin/game/itemDetail.ts | 3 ++ src/plugin/game/utils.ts | 18 +++++++ 3 files changed, 115 insertions(+), 2 deletions(-) diff --git a/src/plugin/game/damage.ts b/src/plugin/game/damage.ts index b49f354..f41f68b 100644 --- a/src/plugin/game/damage.ts +++ b/src/plugin/game/damage.ts @@ -1,6 +1,14 @@ import { getHeroStatusOf, getHeroStatusOn } from './hero'; import { Range, RangeCollection } from './range'; -import { backDir, checkV2, ensureArray, has, manhattan, ofDir } from './utils'; +import { + backDir, + checkV2, + ensureArray, + formatDamage, + has, + manhattan, + ofDir +} from './utils'; interface HaloType { square: { @@ -97,7 +105,6 @@ export class EnemyCollection implements RangeCollection { v.calRealAttribute(); } v.calDamage(void 0, onMap); - console.log(v.damage); }); } @@ -116,6 +123,7 @@ export class EnemyCollection implements RangeCollection { this.list.forEach(v => { v.calMapDamage(this.mapDamage, hero); }); + console.log(this.mapDamage); } /** @@ -157,6 +165,89 @@ export class EnemyCollection implements RangeCollection { v.preProvideHalo(); }); } + + render(onMap?: boolean): void; + render(onMap: boolean, cal: boolean, noCache: boolean): void; + render( + onMap: boolean = false, + cal: boolean = false, + noCache: boolean = false + ) { + if (cal) { + this.calDamage(noCache, true); + this.calMapDamage(noCache); + } + + // 怪物伤害 + this.list.forEach(v => { + if (onMap && !checkV2(v.x, v.y)) return; + + if (!v.damage) { + throw new Error( + `Unexpected null of enemy's damage. Loc: '${v.x},${v.y}'. Floor: ${v.floorId}` + ); + } + for (const dam of v.damage) { + if (dam.dir === 'none') { + // 怪物本身所在位置 + const { damage, color } = formatDamage(dam.damage); + core.status.damage.data.push({ + text: damage, + px: 32 * v.x! + 1, + py: 32 * (v.y! + 1) - 1, + color: color + }); + } + } + }); + + // 地图伤害 + const floor = core.status.maps[this.floorId]; + const width = floor.width; + const height = floor.height; + const objs = core.getMapBlocksObj(this.floorId); + + const startX = + onMap && core.bigmap.v2 + ? Math.max(0, core.bigmap.posX - core.bigmap.extend) + : 0; + const endX = + onMap && core.bigmap.v2 + ? Math.min( + width, + core.bigmap.posX + core._WIDTH_ + core.bigmap.extend + 1 + ) + : width; + const startY = + onMap && core.bigmap.v2 + ? Math.max(0, core.bigmap.posY - core.bigmap.extend) + : 0; + const endY = + onMap && core.bigmap.v2 + ? Math.min( + height, + core.bigmap.posY + core._HEIGHT_ + core.bigmap.extend + 1 + ) + : height; + + for (let x = startX; x < endX; x++) { + for (let y = startY; y < endY; y++) { + const id = `${x},${y}` as LocString; + const dam = this.mapDamage[id]; + if (!dam || objs[id]?.event.noPass) continue; + if (dam.damage === 0) continue; + const damage = core.formatBigNumber(dam.damage, true); + const color = dam.damage < 0 ? '#6eff6a' : '#fa3'; + core.status.damage.extraData.push({ + text: damage, + px: 32 * x + 16, + py: 32 * (y + 1) - 14, + color, + alpha: 1 + }); + } + } + } } export class DamageEnemy { @@ -491,6 +582,7 @@ export class DamageEnemy { const loc = `${x},${y}` as LocString; const block = objs[loc]; if ( + block && block.event.noPass && block.event.cls !== 'enemys' && block.event.cls !== 'enemy48' && diff --git a/src/plugin/game/itemDetail.ts b/src/plugin/game/itemDetail.ts index 71f76e8..f75b272 100644 --- a/src/plugin/game/itemDetail.ts +++ b/src/plugin/game/itemDetail.ts @@ -18,8 +18,11 @@ core.control.updateDamage = function (floorId = core.status.floorId, ctx) { // 计算伤害 core.plugin.damage.ensureFloorDamage(floorId); floor.enemy.calDamage(true, onMap); + floor.enemy.calMapDamage(true); core.status.damage.data = []; + floor.enemy.render(); + // this._updateDamage_damage(floorId, onMap); // this._updateDamage_extraDamage(floorId, onMap); getItemDetail(floorId, onMap); // 宝石血瓶详细信息 diff --git a/src/plugin/game/utils.ts b/src/plugin/game/utils.ts index 53678f6..56a1dbb 100644 --- a/src/plugin/game/utils.ts +++ b/src/plugin/game/utils.ts @@ -79,6 +79,24 @@ export function checkV2(x?: number, y?: number) { ); } +export function formatDamage(damage: number): DamageString { + let dam = ''; + let color = ''; + if (!Number.isFinite(damage)) { + dam = '???'; + color = '#f22'; + } else { + dam = core.formatBigNumber(damage, true); + if (damage <= 0) color = '#1f1'; + else if (damage < core.status.hero.hp / 3) color = '#fff'; + else if (damage < (core.status.hero.hp * 2) / 3) color = '#ff0'; + else if (damage < core.status.hero.hp) color = '#f93'; + else color = '#f22'; + } + + return { damage: dam, color: color as Color }; +} + declare global { interface GamePluginUtils { ofDir: typeof ofDir;