From 553a58923691d96af6e330838a9627daaba07592 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Fri, 30 Jun 2023 21:56:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BC=A4=E5=AE=B3=E8=AE=A1?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin/game/damage.ts | 28 +++++++++----- .../game/{itemDetail.js => itemDetail.ts} | 37 +++++++++++-------- src/plugin/game/utils.ts | 17 +++++++++ src/types/enemy.d.ts | 3 +- src/types/map.d.ts | 2 + src/types/status.d.ts | 2 +- src/types/util.d.ts | 2 +- 7 files changed, 64 insertions(+), 27 deletions(-) rename src/plugin/game/{itemDetail.js => itemDetail.ts} (76%) diff --git a/src/plugin/game/damage.ts b/src/plugin/game/damage.ts index 25a5bb9..b49f354 100644 --- a/src/plugin/game/damage.ts +++ b/src/plugin/game/damage.ts @@ -1,6 +1,6 @@ import { getHeroStatusOf, getHeroStatusOn } from './hero'; import { Range, RangeCollection } from './range'; -import { backDir, ensureArray, has, manhattan, ofDir } from './utils'; +import { backDir, checkV2, ensureArray, has, manhattan, ofDir } from './utils'; interface HaloType { square: { @@ -90,13 +90,14 @@ export class EnemyCollection implements RangeCollection { * 计算怪物伤害 * @param noCache 是否不使用缓存 */ - calDamage(noCache: boolean = false) { + calDamage(noCache: boolean = false, onMap: boolean = false) { this.list.forEach(v => { if (noCache || v.needCalculate) { v.reset(); v.calRealAttribute(); } - v.calDamage(); + v.calDamage(void 0, onMap); + console.log(v.damage); }); } @@ -377,7 +378,11 @@ export class DamageEnemy { /** * 计算怪物伤害 */ - calDamage(hero: Partial = core.status.hero) { + calDamage( + hero: Partial = core.status.hero, + onMap: boolean = false + ) { + if (onMap && !checkV2(this.x, this.y)) return this.damage!; if (!this.needCalDamage) return this.damage!; const info = this.getRealInfo(); const dirs = getNeedCalDir(this.x, this.y, this.floorId, hero); @@ -580,7 +585,7 @@ export function getNeedCalDir( if (tx < 0 || ty < 0 || tx >= width || ty >= height) return false; const index = `${tx},${ty}` as LocString; const block = blocks[index]; - if (block.event.noPass) return false; + if (!block || block.event.noPass) return false; if (!core.canMoveHero(tx, ty, backDir(v), floorId)) return false; return true; @@ -641,6 +646,11 @@ export function calDamageWith( } heroPerDamage *= 1 - info.damageDecline; + // 苍蓝刻 + if (special.includes(28)) { + heroPerDamage *= 1 - enemy.paleShield! / 100; + } + let turn = Math.ceil(monHp / heroPerDamage); // 致命一击 @@ -672,9 +682,9 @@ export function calDamageWith( return damage; } -export function initFloorDamage(floorId: FloorIds) { +export function ensureFloorDamage(floorId: FloorIds) { const floor = core.status.maps[floorId]; - floor.enemy = new EnemyCollection(floorId); + floor.enemy ??= new EnemyCollection(floorId); } declare global { @@ -682,7 +692,7 @@ declare global { damage: { Enemy: typeof DamageEnemy; Collection: typeof EnemyCollection; - initFloorDamage: typeof initFloorDamage; + ensureFloorDamage: typeof ensureFloorDamage; }; } @@ -694,5 +704,5 @@ declare global { core.plugin.damage = { Enemy: DamageEnemy, Collection: EnemyCollection, - initFloorDamage + ensureFloorDamage }; diff --git a/src/plugin/game/itemDetail.js b/src/plugin/game/itemDetail.ts similarity index 76% rename from src/plugin/game/itemDetail.js rename to src/plugin/game/itemDetail.ts index 4f1e1b6..71f76e8 100644 --- a/src/plugin/game/itemDetail.js +++ b/src/plugin/game/itemDetail.ts @@ -1,10 +1,9 @@ -/// export {}; -core.control.updateDamage = function (floorId, ctx) { - floorId = floorId || core.status.floorId; - if (!floorId || core.status.gameOver || main.mode != 'play') return; +core.control.updateDamage = function (floorId = core.status.floorId, ctx) { + if (!floorId || core.status.gameOver || main.mode !== 'play') return; const onMap = ctx == null; + const floor = core.status.maps[floorId]; // 没有怪物手册 if (!core.hasItem('book')) return; @@ -16,20 +15,25 @@ core.control.updateDamage = function (floorId, ctx) { // 地图过大的缩略图不绘制显伤 if (width * height > core.bigmap.threshold) return; } - this._updateDamage_damage(floorId, onMap); - this._updateDamage_extraDamage(floorId, onMap); + // 计算伤害 + core.plugin.damage.ensureFloorDamage(floorId); + floor.enemy.calDamage(true, onMap); + core.status.damage.data = []; + + // this._updateDamage_damage(floorId, onMap); + // this._updateDamage_extraDamage(floorId, onMap); getItemDetail(floorId, onMap); // 宝石血瓶详细信息 this.drawDamage(ctx); }; // 获取宝石信息 并绘制 -function getItemDetail(floorId, onMap) { +function getItemDetail(floorId: FloorIds, onMap: boolean) { if (!core.getFlag('itemDetail')) return; floorId ??= core.status.thisMap.floorId; - let diff = {}; + let diff: Record = {}; const before = core.status.hero; const hero = core.clone(core.status.hero); - const handler = { + const handler: ProxyHandler = { set(target, key, v) { diff[key] = v - (target[key] || 0); if (!diff[key]) diff[key] = void 0; @@ -54,14 +58,17 @@ function getItemDetail(floorId, onMap) { } } diff = {}; - const id = block.event.id; + const id = block.event.id as AllIdsOf<'items'>; const item = core.material.items[id]; if (item.cls === 'equips') { // 装备也显示 - const diff = core.clone(item.equip.value ?? {}); + const diff: Record = core.clone( + item.equip.value ?? {} + ); const per = item.equip.percentage ?? {}; for (const name in per) { - diff[name + 'per'] = per[name].toString() + '%'; + diff[name + 'per'] = + per[name as SelectKey].toString() + '%'; } drawItemDetail(diff, x, y); return; @@ -69,7 +76,7 @@ function getItemDetail(floorId, onMap) { // 跟数据统计原理一样 执行效果 前后比较 core.setFlag('__statistics__', true); try { - eval(item.itemEffect); + eval(item.itemEffect!); } catch (error) {} drawItemDetail(diff, x, y); }); @@ -79,7 +86,7 @@ function getItemDetail(floorId, onMap) { } // 绘制 -function drawItemDetail(diff, x, y) { +function drawItemDetail(diff: any, x: number, y: number) { const px = 32 * x + 2, py = 32 * y + 31; let content = ''; @@ -121,7 +128,7 @@ function drawItemDetail(diff, x, y) { text: content, px: px, py: py - 10 * i, - color: color + color: color as Color }); i++; } diff --git a/src/plugin/game/utils.ts b/src/plugin/game/utils.ts index 817a8f1..53678f6 100644 --- a/src/plugin/game/utils.ts +++ b/src/plugin/game/utils.ts @@ -62,6 +62,23 @@ export function manhattan(x1: number, y1: number, x2: number, y2: number) { return Math.abs(x1 - x2) + Math.abs(y1 - y2); } +/** + * 检查一个点是否在当前超大地图 v2 优化范围内 + */ +export function checkV2(x?: number, y?: number) { + return ( + has(x) && + has(y) && + !( + core.bigmap.v2 && + (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) + ) + ); +} + declare global { interface GamePluginUtils { ofDir: typeof ofDir; diff --git a/src/types/enemy.d.ts b/src/types/enemy.d.ts index c917e32..ab970d0 100644 --- a/src/types/enemy.d.ts +++ b/src/types/enemy.d.ts @@ -24,7 +24,8 @@ type PartialNumbericEnemyProperty = | 'ice' | 'crit' | 'courage' - | 'charge'; + | 'charge' + | 'paleShield'; type BooleanEnemyProperty = | 'zoneSquare' diff --git a/src/types/map.d.ts b/src/types/map.d.ts index 09f1cc9..4a7357f 100644 --- a/src/types/map.d.ts +++ b/src/types/map.d.ts @@ -39,6 +39,8 @@ interface Block = Exclude> { */ id: N; + disable: boolean; + /** * 事件信息 */ diff --git a/src/types/status.d.ts b/src/types/status.d.ts index f8f1845..32a2164 100644 --- a/src/types/status.d.ts +++ b/src/types/status.d.ts @@ -608,7 +608,7 @@ interface InitGameStatus { /** * 伤害显示信息 */ - damage: DeepReadonly; + damage: DamageStatus; /** * 是否锁定了用户控制 diff --git a/src/types/util.d.ts b/src/types/util.d.ts index e22fc68..d0d6171 100644 --- a/src/types/util.d.ts +++ b/src/types/util.d.ts @@ -250,7 +250,7 @@ interface Utils { * @returns 格式化结果 */ formatBigNumber(x: T, onMap?: number): T; - formatBigNumber(x: number | string, onMap?: number): string; + formatBigNumber(x: number | string, onMap?: number | boolean): string; /** * @deprecated