From 7ce6acb664a59690302f5d7376dfaff0e8991a96 Mon Sep 17 00:00:00 2001
From: unanmed <1319491857@qq.com>
Date: Wed, 2 Aug 2023 15:20:39 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=96=E6=B6=88=E6=96=B9?=
 =?UTF-8?q?=E5=90=91=E4=BC=A4=E5=AE=B3=E9=80=A0=E6=88=90=E7=9A=84=E9=94=99?=
 =?UTF-8?q?=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/panel/enemyCritical.vue     | 14 +++----
 src/panel/enemySpecial.vue      |  4 +-
 src/plugin/game/enemy/damage.ts |  2 +-
 src/plugin/ui/book.tsx          | 42 +++++++++----------
 src/plugin/ui/fixed.ts          |  7 ++--
 src/ui/book.vue                 | 16 +++-----
 src/ui/fixed.vue                | 71 ++++++++++++---------------------
 src/ui/fixedDetail.vue          | 20 +++++-----
 8 files changed, 72 insertions(+), 104 deletions(-)

diff --git a/src/panel/enemyCritical.vue b/src/panel/enemyCritical.vue
index b9f378f..963775d 100644
--- a/src/panel/enemyCritical.vue
+++ b/src/panel/enemyCritical.vue
@@ -124,21 +124,17 @@ const allDef = ref(originDef);
 const addAtk = ref(0);
 const addDef = ref(0);
 
-const originDamage = enemy.enemy.calEnemyDamage(core.status.hero, 'none')[0]
-    .damage;
+const originDamage = enemy.enemy.calDamage(core.status.hero).damage;
 
 // 转发core上的内容至当前作用域
 const format = core.formatBigNumber;
 const ratio = core.status.thisMap.ratio;
 
 const nowDamage = computed(() => {
-    const dam = enemy.enemy.calEnemyDamage(
-        {
-            atk: core.status.hero.atk + addAtk.value * ratio,
-            def: core.status.hero.def + addDef.value * ratio
-        },
-        'none'
-    )[0].damage;
+    const dam = enemy.enemy.calDamage({
+        atk: core.status.hero.atk + addAtk.value * ratio,
+        def: core.status.hero.def + addDef.value * ratio
+    }).damage;
     if (!isFinite(dam)) return ['???', '???'];
     if (!isFinite(originDamage)) return [-dam, dam];
     return [originDamage - dam, dam];
diff --git a/src/panel/enemySpecial.vue b/src/panel/enemySpecial.vue
index 91cd824..aac5b60 100644
--- a/src/panel/enemySpecial.vue
+++ b/src/panel/enemySpecial.vue
@@ -18,7 +18,7 @@
                     <span>加攻</span>
                     <span>减伤</span>
                 </div>
-                <div v-for="cri of criticals[0]" class="critical">
+                <div v-for="cri of criticals" class="critical">
                     <span class="critical-atk">{{ format(cri.atkDelta) }}</span>
                     <span>{{ format(cri.delta) }}</span>
                 </div>
@@ -39,7 +39,7 @@ const enemy = detailInfo.enemy!;
 
 const info = getSpecialHint(enemy);
 
-const criticals = enemy.enemy.calCritical(isMobile ? 4 : 8, 'none');
+const criticals = enemy.enemy.calCritical(isMobile ? 4 : 8);
 
 const format = core.formatBigNumber;
 </script>
diff --git a/src/plugin/game/enemy/damage.ts b/src/plugin/game/enemy/damage.ts
index 15e3c4e..0553a40 100644
--- a/src/plugin/game/enemy/damage.ts
+++ b/src/plugin/game/enemy/damage.ts
@@ -712,7 +712,7 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
             if (i++ >= 10000) {
                 throw new Error(
                     `Unexpected endless loop in calculating critical.` +
-                        `Enemy loc: ${this.x},${this.y}. Floor: ${this.floorId}`
+                        `Enemy Id: ${this.id}. Loc: ${this.x},${this.y}. Floor: ${this.floorId}`
                 );
             }
         }
diff --git a/src/plugin/ui/book.tsx b/src/plugin/ui/book.tsx
index 57ee632..e8d4a18 100644
--- a/src/plugin/ui/book.tsx
+++ b/src/plugin/ui/book.tsx
@@ -60,26 +60,23 @@ export function getDefDamage(
     const max = 100 - Math.floor(addDef / ratio);
 
     for (let i = 0; i <= max; i++) {
-        const dam = enemy.enemy.calEnemyDamage(
-            {
-                atk: core.status.hero.atk + addAtk,
-                def: core.status.hero.def + addDef + i * ratio
-            },
-            'none'
-        );
+        const dam = enemy.enemy.calDamage({
+            atk: core.status.hero.atk + addAtk,
+            def: core.status.hero.def + addDef + i * ratio
+        });
 
         if (res.length === 0) {
-            origin = dam[0].damage;
+            origin = dam.damage;
             if (has(origin)) {
                 res.push([addDef + i * ratio, origin]);
                 last = origin;
             }
             continue;
         }
-        if (!isFinite(dam[0].damage)) continue;
-        if (dam[0].damage === res.at(-1)?.[1]) continue;
-        last = dam[0].damage;
-        res.push([ratio * i + addDef, dam[0].damage]);
+        if (!isFinite(dam.damage)) continue;
+        if (dam.damage === res.at(-1)?.[1]) continue;
+        last = dam.damage;
+        res.push([ratio * i + addDef, dam.damage]);
     }
 
     return res;
@@ -103,26 +100,23 @@ export function getCriticalDamage(
     const max = 100 - Math.floor(addAtk / ratio);
 
     for (let i = 0; i <= max; i++) {
-        const dam = enemy.enemy.calEnemyDamage(
-            {
-                atk: core.status.hero.atk + addAtk + i * ratio,
-                def: core.status.hero.def + addDef
-            },
-            'none'
-        );
+        const dam = enemy.enemy.calDamage({
+            atk: core.status.hero.atk + addAtk + i * ratio,
+            def: core.status.hero.def + addDef
+        });
 
         if (res.length === 0) {
-            origin = dam[0].damage;
+            origin = dam.damage;
             if (has(origin)) {
                 res.push([addAtk + i * ratio, origin]);
                 last = origin;
             }
             continue;
         }
-        if (!isFinite(dam[0].damage)) continue;
-        if (dam[0].damage === res.at(-1)?.[1]) continue;
-        last = dam[0].damage;
-        res.push([ratio * i + addAtk, dam[0].damage]);
+        if (!isFinite(dam.damage)) continue;
+        if (dam.damage === res.at(-1)?.[1]) continue;
+        last = dam.damage;
+        res.push([ratio * i + addAtk, dam.damage]);
     }
 
     return res;
diff --git a/src/plugin/ui/fixed.ts b/src/plugin/ui/fixed.ts
index 056eb6b..ac5a3d4 100644
--- a/src/plugin/ui/fixed.ts
+++ b/src/plugin/ui/fixed.ts
@@ -13,8 +13,9 @@ const show = debounce((ev: MouseEvent) => {
     if (!flags.mouseLoc) return;
     flags.clientLoc = [ev.clientX, ev.clientY];
     const [mx, my] = getLocFromMouseLoc(...flags.mouseLoc);
+
     const e = core.status.thisMap.enemy.list.find(v => {
-        v.x === mx && v.y === my;
+        return v.x === mx && v.y === my;
     });
 
     if (!e) return;
@@ -68,8 +69,8 @@ export function getDetailedEnemy(
     const dam = enemy.calDamage().damage;
     const cri = enemy.calCritical(1)[0];
     const critical = core.formatBigNumber(cri?.atkDelta);
-    const criticalDam = core.formatBigNumber(cri?.delta);
-    const defDam = core.formatBigNumber(enemy.calDefDamage(ratio).damage);
+    const criticalDam = core.formatBigNumber(-cri?.delta);
+    const defDam = core.formatBigNumber(-enemy.calDefDamage(ratio).delta);
     const damage = core.formatBigNumber(dam);
 
     const fromFunc = (
diff --git a/src/ui/book.vue b/src/ui/book.vue
index 861a261..3559358 100644
--- a/src/ui/book.vue
+++ b/src/ui/book.vue
@@ -64,16 +64,14 @@ const specials = Object.fromEntries(
 
 const enemy = core.getCurrentEnemys(floorId);
 const toShow: ToShowEnemy[] = enemy.map(v => {
-    const cri = v.enemy.calCritical(1, 'none')[0];
+    const e = v.enemy;
+    const dam = e.calDamage().damage;
+    const cri = e.calCritical(1);
     const critical = core.formatBigNumber(cri[0]?.atkDelta);
     const criticalDam = core.formatBigNumber(-cri[0]?.delta);
     const ratio = core.status.maps[floorId].ratio;
-    const defDam = core.formatBigNumber(
-        -v.enemy.calDefDamage(ratio, 'none')[0]?.delta
-    );
-    const damage = core.formatBigNumber(
-        v.enemy.damage?.[0]?.damage ?? Infinity
-    );
+    const defDam = core.formatBigNumber(-e.calDefDamage(ratio).delta);
+    const damage = core.formatBigNumber(dam);
 
     const fromFunc = (
         func: string | ((enemy: Enemy) => string),
@@ -96,9 +94,7 @@ const toShow: ToShowEnemy[] = enemy.map(v => {
             ? special.slice(0, 2).concat(['...', '', '#fff'])
             : special.slice();
 
-    const damageColor = getDamageColor(
-        v.enemy.damage?.[0]?.damage ?? Infinity
-    ) as string;
+    const damageColor = getDamageColor(dam) as string;
 
     return {
         critical,
diff --git a/src/ui/fixed.vue b/src/ui/fixed.vue
index bcba79e..399caaa 100644
--- a/src/ui/fixed.vue
+++ b/src/ui/fixed.vue
@@ -9,25 +9,21 @@
                 v-model:width="width"
             >
                 <div id="enemy-fixed">
-                    <span id="enemy-name">{{ enemy.name }}</span>
+                    <span id="enemy-name">{{ enemy.enemy.enemy.name }}</span>
                     <div id="enemy-special">
                         <span
-                            v-for="(text, i) of enemy.toShowSpecial"
-                            :style="{color: (enemy.toShowColor[i] as string)} "
-                            >{{ text }}</span
+                            v-for="(text, i) of enemy.showSpecial"
+                            :style="{ color: text[2] }"
+                            >{{ text[0] }}</span
                         >
                     </div>
                     <div class="enemy-attr" v-for="(a, i) of toShowAttrs">
-                        <span
-                            class="attr-name"
-                            :style="{ color: attrColor[i] }"
-                            >{{ getLabel(a) }}</span
-                        >
-                        <span
-                            class="attr-value"
-                            :style="{ color: attrColor[i] }"
-                            >{{ format(enemy[a] as number) }}</span
-                        >
+                        <span class="attr-name" :style="{ color: a[2] }">{{
+                            a[1]
+                        }}</span>
+                        <span class="attr-value" :style="{ color: a[2] }">{{
+                            format(a[0])
+                        }}</span>
                     </div>
                 </div>
             </Box>
@@ -36,9 +32,10 @@
 </template>
 
 <script lang="ts" setup>
-import { onMounted, onUpdated, ref, watch } from 'vue';
+import { ComputedRef, computed, onMounted, onUpdated, ref, watch } from 'vue';
 import Box from '../components/box.vue';
 import { showFixed } from '../plugin/ui/fixed';
+import { ToShowEnemy, detailInfo } from '../plugin/ui/book';
 
 watch(showFixed, n => {
     if (n) calHeight();
@@ -47,29 +44,20 @@ watch(showFixed, n => {
 let main: HTMLDivElement;
 
 const format = core.formatBigNumber;
+const enemy = ref(detailInfo.enemy!);
 
-const toShowAttrs: (keyof DetailedEnemy)[] = [
-    'hp',
-    'atk',
-    'def',
-    'money',
-    'exp',
-    'critical',
-    'criticalDamage',
-    'defDamage'
-];
-const attrColor = [
-    'lightgreen',
-    'lightcoral',
-    'lightblue',
-    'lightyellow',
-    'lawngreen',
-    'lightsalmon',
-    'lightpink',
-    'cyan'
-];
-
-const enemy = ref(core.plugin.bookDetailEnemy);
+const toShowAttrs: ComputedRef<[number | string, string, string][]> = computed(
+    () => [
+        [enemy.value.enemy.info.hp, '生命', 'lightgreen'],
+        [enemy.value.enemy.info.atk, '攻击', 'lightcoral'],
+        [enemy.value.enemy.info.def, '防御', 'lightblue'],
+        [enemy.value.enemy.enemy.money, '金币', 'lightyellow'],
+        [enemy.value.enemy.enemy.exp, '经验', 'lawgreen'],
+        [enemy.value.critical, '临界', 'lightsalmon'],
+        [enemy.value.criticalDam, '减伤', 'lightpink'],
+        [enemy.value.defDam, `${core.status.thisMap?.ratio ?? 1}防`, 'cyan']
+    ]
+);
 
 const left = ref(0);
 const top = ref(0);
@@ -79,7 +67,7 @@ let vh = window.innerHeight;
 let vw = window.innerWidth;
 
 async function calHeight() {
-    enemy.value = core.plugin.bookDetailEnemy;
+    enemy.value = detailInfo.enemy!;
     vh = window.innerHeight;
     vw = window.innerWidth;
     width.value = vh * 0.28;
@@ -99,13 +87,6 @@ async function calHeight() {
     height.value = h;
 }
 
-function getLabel(attr: keyof DetailedEnemy) {
-    if (attr === 'critical') return '临界';
-    if (attr === 'criticalDamage') return '临界减伤';
-    if (attr === 'defDamage') return `${core.status?.thisMap?.ratio ?? 1}防`;
-    return core.getStatusLabel(attr);
-}
-
 function updateMain() {
     main = document.getElementById('enemy-fixed') as HTMLDivElement;
     if (main) {
diff --git a/src/ui/fixedDetail.vue b/src/ui/fixedDetail.vue
index 91d0bb3..cf1510e 100644
--- a/src/ui/fixedDetail.vue
+++ b/src/ui/fixedDetail.vue
@@ -9,22 +9,22 @@
 </template>
 
 <script lang="ts" setup>
-import { onMounted, ref } from 'vue';
-import { getDetailedEnemy } from '../plugin/ui/fixed';
+import { getDetailedEnemy, getLocFromMouseLoc } from '../plugin/ui/fixed';
 import BookDetail from './bookDetail.vue';
+import { detailInfo } from '../plugin/ui/book';
 
 const panel = core.plugin.fixedDetailPanel ?? 'special';
 
-core.plugin.bookDetailPos = 0;
+detailInfo.pos = 0;
 
 const [x, y] = flags.mouseLoc;
-const mx = Math.round(x + core.bigmap.offsetX / 32);
-const my = Math.round(y + core.bigmap.offsetY / 32);
-const e = core.getBlockId(mx, my);
-if (e && core.getClsFromId(e)?.startsWith('enemy')) {
-    const enemy = core.material.enemys[e as EnemyIds];
-    const detail = getDetailedEnemy(enemy, mx, my);
-    core.plugin.bookDetailEnemy = detail;
+const [mx, my] = getLocFromMouseLoc(x, y);
+const enemy = core.status.thisMap.enemy.list.find(v => {
+    return v.x === mx && v.y === my;
+});
+if (enemy) {
+    const detail = getDetailedEnemy(enemy);
+    detailInfo.enemy = detail;
 } else {
     close();
 }