HumanBreak/src/panel/enemyCritical.vue

267 lines
7.0 KiB
Vue
Raw Normal View History

2022-11-19 11:30:14 +08:00
<template>
<div id="critical-main">
<div id="critical">
<div class="des">加攻伤害</div>
<canvas ref="critical" class="chart"></canvas>
<div class="slider-div">
2022-12-30 11:06:46 +08:00
<span>加攻次数&nbsp;&nbsp;&nbsp;&nbsp;{{ addAtk }}</span>
2022-11-19 11:30:14 +08:00
<a-slider
class="slider"
v-model:value="addAtk"
:max="(originCri.at(-1)?.[0] ?? 2) - 1"
></a-slider>
<span
>最大值&nbsp;&nbsp;&nbsp;&nbsp;{{
(originCri.at(-1)?.[0] ?? 2) - 1
}}</span
>
</div>
</div>
<a-divider
dashed
style="width: 100%; border-color: #ddd4; margin: 1vh 0 1vh 0"
></a-divider>
<div id="def">
<div class="des">加防伤害</div>
<canvas ref="def" class="chart"></canvas>
<div class="slider-div">
2022-12-30 11:06:46 +08:00
<span>加防次数&nbsp;&nbsp;&nbsp;&nbsp;{{ addDef }}</span>
2022-11-19 11:30:14 +08:00
<a-slider
class="slider"
v-model:value="addDef"
:max="(originDef.at(-1)?.[0] ?? 2) - 1"
></a-slider>
<span
>最大值&nbsp;&nbsp;&nbsp;&nbsp;{{
(originDef.at(-1)?.[0] ?? 2) - 1
}}</span
>
</div>
</div>
<div id="now-damage">
2022-11-19 18:15:42 +08:00
<div>
<span
>当前加攻{{
isMobile ? '' : '&nbsp;&nbsp;&nbsp;&nbsp;'
}}</span
>
<span>{{ format(addAtk * ratio) }}</span>
</div>
<div>
<span
>当前加防{{
isMobile ? '' : '&nbsp;&nbsp;&nbsp;&nbsp;'
}}</span
>
<span>{{ format(addDef * ratio) }}</span>
</div>
<div>
<span
>当前减伤{{
isMobile ? '' : '&nbsp;&nbsp;&nbsp;&nbsp;'
}}</span
>
2022-12-28 12:13:52 +08:00
<span
><span style="font-family: 'Fira Code'">{{
nowDamage[0] < 0 ? '=>' : ''
}}</span
>{{
nowDamage[0] < 0
? format(-nowDamage[0])
: format(nowDamage[0])
}}</span
>
2022-11-19 18:15:42 +08:00
</div>
<div>
<span
>当前伤害{{
isMobile ? '' : '&nbsp;&nbsp;&nbsp;&nbsp;'
}}</span
>
<span>{{ format(nowDamage[1]) }}</span>
</div>
2022-11-19 11:30:14 +08:00
</div>
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref, watch } from 'vue';
2022-11-21 20:00:34 +08:00
import { getCriticalDamage, getDefDamage } from '../plugin/ui/book';
2022-11-19 11:30:14 +08:00
import Chart, { ChartConfiguration } from 'chart.js/auto';
import { has, setCanvasSize } from '../plugin/utils';
2022-11-19 13:07:42 +08:00
import { debounce } from 'lodash';
2022-11-19 18:15:42 +08:00
import { isMobile } from '../plugin/use';
2022-11-19 11:30:14 +08:00
const critical = ref<HTMLCanvasElement>();
const def = ref<HTMLCanvasElement>();
const enemy = core.plugin.bookDetailEnemy;
2022-11-19 13:07:42 +08:00
let originCri = getCriticalDamage(enemy);
let originDef = getDefDamage(enemy);
2022-11-19 11:30:14 +08:00
// 当前数据
const allCri = ref(originCri);
const allDef = ref(originDef);
// 加攻加防数量
const addAtk = ref(0);
const addDef = ref(0);
const originDamage = core.getDamageInfo(enemy);
// 转发core上的内容至当前作用域
const format = core.formatBigNumber;
const ratio = core.status.thisMap.ratio;
const nowDamage = computed(() => {
const dam = core.getDamageInfo(enemy, {
2022-11-19 13:07:42 +08:00
atk: core.status.hero.atk + addAtk.value * ratio,
def: core.status.hero.def + addDef.value * ratio
2022-11-19 11:30:14 +08:00
});
if (!has(dam)) return ['???', '???'];
if (!has(originDamage)) return [-dam.damage, dam.damage];
return [originDamage.damage - dam.damage, dam.damage];
});
function generateChart(ele: HTMLCanvasElement, data: [number, number][]) {
const config: ChartConfiguration = {
type: 'line',
2022-11-19 13:07:42 +08:00
data: generateData(data),
options: {
elements: {
point: {
radius: 5,
hoverRadius: 7
}
},
scales: {
y: {
grid: {
color: '#ddd3'
}
}
2022-11-19 18:15:42 +08:00
},
plugins: {
legend: {
display: false
}
2022-11-19 13:07:42 +08:00
}
}
2022-11-19 11:30:14 +08:00
};
return new Chart(ele, config);
}
2022-11-19 13:07:42 +08:00
/**
* 生成图表数据
* @param data 数据
*/
2022-11-21 20:00:34 +08:00
function generateData(data: [number, number][]): ChartConfiguration['data'] {
2022-11-19 11:30:14 +08:00
return {
datasets: [
{
2022-11-21 20:00:34 +08:00
data: data.map(v => v[1]),
label: '怪物伤害'
2022-11-19 11:30:14 +08:00
}
],
2022-11-19 13:07:42 +08:00
labels: data.map(v => Math.round(v[0] / ratio))
2022-11-19 11:30:14 +08:00
};
}
2022-11-19 13:07:42 +08:00
const update = debounce((atk: Chart, def: Chart) => {
allCri.value = getCriticalDamage(
enemy,
addAtk.value * ratio,
addDef.value * ratio
);
allDef.value = getDefDamage(
enemy,
addDef.value * ratio,
addAtk.value * ratio
);
if (allCri.value.length > originCri.length) originCri = allCri.value;
if (allDef.value.length > originDef.length) originDef = allDef.value;
2022-11-19 11:30:14 +08:00
atk.data = generateData(allCri.value);
def.data = generateData(allDef.value);
atk.update('resize');
def.update('resize');
2022-11-19 13:07:42 +08:00
}, 200);
2022-11-19 11:30:14 +08:00
onMounted(() => {
const div = document.getElementById('critical-main') as HTMLDivElement;
const style = getComputedStyle(div);
const width = parseFloat(style.width);
const height = window.innerHeight / 5;
const c = critical.value!;
const d = def.value!;
setCanvasSize(c, width, height);
setCanvasSize(d, width, height);
const criChart = generateChart(c, allCri.value);
const defChart = generateChart(d, allDef.value);
watch(addAtk, n => {
update(criChart, defChart);
});
watch(addDef, n => {
update(criChart, defChart);
});
});
</script>
<style lang="less" scoped>
#critical-main {
width: 100%;
height: 50vh;
user-select: none;
}
.des {
width: 100%;
text-align: center;
font-size: 2.5vh;
}
.slider-div {
display: flex;
justify-content: space-between;
align-items: center;
span {
font-size: 1.1vw;
line-height: 1;
}
}
.slider {
width: 80%;
}
#now-damage {
display: flex;
flex-direction: row;
justify-content: space-around;
font-size: 3vh;
}
2022-11-19 18:15:42 +08:00
@media screen and (max-width: 600px) {
#now-damage {
font-size: 3vw;
div {
display: flex;
flex-direction: column;
align-items: center;
}
}
.slider {
width: 60%;
}
}
2022-11-19 11:30:14 +08:00
</style>