修复取消方向伤害造成的错误

This commit is contained in:
unanmed 2023-08-02 15:20:39 +08:00
parent b8711e2014
commit 7ce6acb664
8 changed files with 72 additions and 104 deletions

View File

@ -124,21 +124,17 @@ const allDef = ref(originDef);
const addAtk = ref(0); const addAtk = ref(0);
const addDef = ref(0); const addDef = ref(0);
const originDamage = enemy.enemy.calEnemyDamage(core.status.hero, 'none')[0] const originDamage = enemy.enemy.calDamage(core.status.hero).damage;
.damage;
// core // core
const format = core.formatBigNumber; const format = core.formatBigNumber;
const ratio = core.status.thisMap.ratio; const ratio = core.status.thisMap.ratio;
const nowDamage = computed(() => { const nowDamage = computed(() => {
const dam = enemy.enemy.calEnemyDamage( const dam = enemy.enemy.calDamage({
{ atk: core.status.hero.atk + addAtk.value * ratio,
atk: core.status.hero.atk + addAtk.value * ratio, def: core.status.hero.def + addDef.value * ratio
def: core.status.hero.def + addDef.value * ratio }).damage;
},
'none'
)[0].damage;
if (!isFinite(dam)) return ['???', '???']; if (!isFinite(dam)) return ['???', '???'];
if (!isFinite(originDamage)) return [-dam, dam]; if (!isFinite(originDamage)) return [-dam, dam];
return [originDamage - dam, dam]; return [originDamage - dam, dam];

View File

@ -18,7 +18,7 @@
<span>加攻</span> <span>加攻</span>
<span>减伤</span> <span>减伤</span>
</div> </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 class="critical-atk">{{ format(cri.atkDelta) }}</span>
<span>{{ format(cri.delta) }}</span> <span>{{ format(cri.delta) }}</span>
</div> </div>
@ -39,7 +39,7 @@ const enemy = detailInfo.enemy!;
const info = getSpecialHint(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; const format = core.formatBigNumber;
</script> </script>

View File

@ -712,7 +712,7 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
if (i++ >= 10000) { if (i++ >= 10000) {
throw new Error( throw new Error(
`Unexpected endless loop in calculating critical.` + `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}`
); );
} }
} }

View File

@ -60,26 +60,23 @@ export function getDefDamage(
const max = 100 - Math.floor(addDef / ratio); const max = 100 - Math.floor(addDef / ratio);
for (let i = 0; i <= max; i++) { for (let i = 0; i <= max; i++) {
const dam = enemy.enemy.calEnemyDamage( const dam = enemy.enemy.calDamage({
{ atk: core.status.hero.atk + addAtk,
atk: core.status.hero.atk + addAtk, def: core.status.hero.def + addDef + i * ratio
def: core.status.hero.def + addDef + i * ratio });
},
'none'
);
if (res.length === 0) { if (res.length === 0) {
origin = dam[0].damage; origin = dam.damage;
if (has(origin)) { if (has(origin)) {
res.push([addDef + i * ratio, origin]); res.push([addDef + i * ratio, origin]);
last = origin; last = origin;
} }
continue; continue;
} }
if (!isFinite(dam[0].damage)) continue; if (!isFinite(dam.damage)) continue;
if (dam[0].damage === res.at(-1)?.[1]) continue; if (dam.damage === res.at(-1)?.[1]) continue;
last = dam[0].damage; last = dam.damage;
res.push([ratio * i + addDef, dam[0].damage]); res.push([ratio * i + addDef, dam.damage]);
} }
return res; return res;
@ -103,26 +100,23 @@ export function getCriticalDamage(
const max = 100 - Math.floor(addAtk / ratio); const max = 100 - Math.floor(addAtk / ratio);
for (let i = 0; i <= max; i++) { for (let i = 0; i <= max; i++) {
const dam = enemy.enemy.calEnemyDamage( const dam = enemy.enemy.calDamage({
{ atk: core.status.hero.atk + addAtk + i * ratio,
atk: core.status.hero.atk + addAtk + i * ratio, def: core.status.hero.def + addDef
def: core.status.hero.def + addDef });
},
'none'
);
if (res.length === 0) { if (res.length === 0) {
origin = dam[0].damage; origin = dam.damage;
if (has(origin)) { if (has(origin)) {
res.push([addAtk + i * ratio, origin]); res.push([addAtk + i * ratio, origin]);
last = origin; last = origin;
} }
continue; continue;
} }
if (!isFinite(dam[0].damage)) continue; if (!isFinite(dam.damage)) continue;
if (dam[0].damage === res.at(-1)?.[1]) continue; if (dam.damage === res.at(-1)?.[1]) continue;
last = dam[0].damage; last = dam.damage;
res.push([ratio * i + addAtk, dam[0].damage]); res.push([ratio * i + addAtk, dam.damage]);
} }
return res; return res;

View File

@ -13,8 +13,9 @@ const show = debounce((ev: MouseEvent) => {
if (!flags.mouseLoc) return; if (!flags.mouseLoc) return;
flags.clientLoc = [ev.clientX, ev.clientY]; flags.clientLoc = [ev.clientX, ev.clientY];
const [mx, my] = getLocFromMouseLoc(...flags.mouseLoc); const [mx, my] = getLocFromMouseLoc(...flags.mouseLoc);
const e = core.status.thisMap.enemy.list.find(v => { 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; if (!e) return;
@ -68,8 +69,8 @@ export function getDetailedEnemy(
const dam = enemy.calDamage().damage; const dam = enemy.calDamage().damage;
const cri = enemy.calCritical(1)[0]; const cri = enemy.calCritical(1)[0];
const critical = core.formatBigNumber(cri?.atkDelta); const critical = core.formatBigNumber(cri?.atkDelta);
const criticalDam = core.formatBigNumber(cri?.delta); const criticalDam = core.formatBigNumber(-cri?.delta);
const defDam = core.formatBigNumber(enemy.calDefDamage(ratio).damage); const defDam = core.formatBigNumber(-enemy.calDefDamage(ratio).delta);
const damage = core.formatBigNumber(dam); const damage = core.formatBigNumber(dam);
const fromFunc = ( const fromFunc = (

View File

@ -64,16 +64,14 @@ const specials = Object.fromEntries(
const enemy = core.getCurrentEnemys(floorId); const enemy = core.getCurrentEnemys(floorId);
const toShow: ToShowEnemy[] = enemy.map(v => { 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 critical = core.formatBigNumber(cri[0]?.atkDelta);
const criticalDam = core.formatBigNumber(-cri[0]?.delta); const criticalDam = core.formatBigNumber(-cri[0]?.delta);
const ratio = core.status.maps[floorId].ratio; const ratio = core.status.maps[floorId].ratio;
const defDam = core.formatBigNumber( const defDam = core.formatBigNumber(-e.calDefDamage(ratio).delta);
-v.enemy.calDefDamage(ratio, 'none')[0]?.delta const damage = core.formatBigNumber(dam);
);
const damage = core.formatBigNumber(
v.enemy.damage?.[0]?.damage ?? Infinity
);
const fromFunc = ( const fromFunc = (
func: string | ((enemy: Enemy) => string), func: string | ((enemy: Enemy) => string),
@ -96,9 +94,7 @@ const toShow: ToShowEnemy[] = enemy.map(v => {
? special.slice(0, 2).concat(['...', '', '#fff']) ? special.slice(0, 2).concat(['...', '', '#fff'])
: special.slice(); : special.slice();
const damageColor = getDamageColor( const damageColor = getDamageColor(dam) as string;
v.enemy.damage?.[0]?.damage ?? Infinity
) as string;
return { return {
critical, critical,

View File

@ -9,25 +9,21 @@
v-model:width="width" v-model:width="width"
> >
<div id="enemy-fixed"> <div id="enemy-fixed">
<span id="enemy-name">{{ enemy.name }}</span> <span id="enemy-name">{{ enemy.enemy.enemy.name }}</span>
<div id="enemy-special"> <div id="enemy-special">
<span <span
v-for="(text, i) of enemy.toShowSpecial" v-for="(text, i) of enemy.showSpecial"
:style="{color: (enemy.toShowColor[i] as string)} " :style="{ color: text[2] }"
>{{ text }}</span >{{ text[0] }}</span
> >
</div> </div>
<div class="enemy-attr" v-for="(a, i) of toShowAttrs"> <div class="enemy-attr" v-for="(a, i) of toShowAttrs">
<span <span class="attr-name" :style="{ color: a[2] }">{{
class="attr-name" a[1]
:style="{ color: attrColor[i] }" }}</span>
>{{ getLabel(a) }}</span <span class="attr-value" :style="{ color: a[2] }">{{
> format(a[0])
<span }}</span>
class="attr-value"
:style="{ color: attrColor[i] }"
>{{ format(enemy[a] as number) }}</span
>
</div> </div>
</div> </div>
</Box> </Box>
@ -36,9 +32,10 @@
</template> </template>
<script lang="ts" setup> <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 Box from '../components/box.vue';
import { showFixed } from '../plugin/ui/fixed'; import { showFixed } from '../plugin/ui/fixed';
import { ToShowEnemy, detailInfo } from '../plugin/ui/book';
watch(showFixed, n => { watch(showFixed, n => {
if (n) calHeight(); if (n) calHeight();
@ -47,29 +44,20 @@ watch(showFixed, n => {
let main: HTMLDivElement; let main: HTMLDivElement;
const format = core.formatBigNumber; const format = core.formatBigNumber;
const enemy = ref(detailInfo.enemy!);
const toShowAttrs: (keyof DetailedEnemy)[] = [ const toShowAttrs: ComputedRef<[number | string, string, string][]> = computed(
'hp', () => [
'atk', [enemy.value.enemy.info.hp, '生命', 'lightgreen'],
'def', [enemy.value.enemy.info.atk, '攻击', 'lightcoral'],
'money', [enemy.value.enemy.info.def, '防御', 'lightblue'],
'exp', [enemy.value.enemy.enemy.money, '金币', 'lightyellow'],
'critical', [enemy.value.enemy.enemy.exp, '经验', 'lawgreen'],
'criticalDamage', [enemy.value.critical, '临界', 'lightsalmon'],
'defDamage' [enemy.value.criticalDam, '减伤', 'lightpink'],
]; [enemy.value.defDam, `${core.status.thisMap?.ratio ?? 1}`, 'cyan']
const attrColor = [ ]
'lightgreen', );
'lightcoral',
'lightblue',
'lightyellow',
'lawngreen',
'lightsalmon',
'lightpink',
'cyan'
];
const enemy = ref(core.plugin.bookDetailEnemy);
const left = ref(0); const left = ref(0);
const top = ref(0); const top = ref(0);
@ -79,7 +67,7 @@ let vh = window.innerHeight;
let vw = window.innerWidth; let vw = window.innerWidth;
async function calHeight() { async function calHeight() {
enemy.value = core.plugin.bookDetailEnemy; enemy.value = detailInfo.enemy!;
vh = window.innerHeight; vh = window.innerHeight;
vw = window.innerWidth; vw = window.innerWidth;
width.value = vh * 0.28; width.value = vh * 0.28;
@ -99,13 +87,6 @@ async function calHeight() {
height.value = h; 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() { function updateMain() {
main = document.getElementById('enemy-fixed') as HTMLDivElement; main = document.getElementById('enemy-fixed') as HTMLDivElement;
if (main) { if (main) {

View File

@ -9,22 +9,22 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from 'vue'; import { getDetailedEnemy, getLocFromMouseLoc } from '../plugin/ui/fixed';
import { getDetailedEnemy } from '../plugin/ui/fixed';
import BookDetail from './bookDetail.vue'; import BookDetail from './bookDetail.vue';
import { detailInfo } from '../plugin/ui/book';
const panel = core.plugin.fixedDetailPanel ?? 'special'; const panel = core.plugin.fixedDetailPanel ?? 'special';
core.plugin.bookDetailPos = 0; detailInfo.pos = 0;
const [x, y] = flags.mouseLoc; const [x, y] = flags.mouseLoc;
const mx = Math.round(x + core.bigmap.offsetX / 32); const [mx, my] = getLocFromMouseLoc(x, y);
const my = Math.round(y + core.bigmap.offsetY / 32); const enemy = core.status.thisMap.enemy.list.find(v => {
const e = core.getBlockId(mx, my); return v.x === mx && v.y === my;
if (e && core.getClsFromId(e)?.startsWith('enemy')) { });
const enemy = core.material.enemys[e as EnemyIds]; if (enemy) {
const detail = getDetailedEnemy(enemy, mx, my); const detail = getDetailedEnemy(enemy);
core.plugin.bookDetailEnemy = detail; detailInfo.enemy = detail;
} else { } else {
close(); close();
} }