mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-26 11:34:30 +08:00
fix: 战斗报错
This commit is contained in:
1 parent
1b18ce4268
commit
b93e286c52
10 files changed
+143
-49
No files matched your search
@@ -1,12 +1,11 @@
|
||||
import {
|
||||
DamageEnemy,
|
||||
ensureFloorDamage,
|
||||
getSingleEnemy,
|
||||
getEnemy,
|
||||
HeroSkill,
|
||||
NightSpecial
|
||||
} from '@user/data-state';
|
||||
import { hook, loading } from '@user/data-base';
|
||||
import { hook } from '@user/data-base';
|
||||
import { Patch, PatchClass } from '@motajs/legacy-common';
|
||||
import { isNil } from 'lodash-es';
|
||||
|
||||
@@ -47,7 +46,7 @@ export function patchBattle() {
|
||||
);
|
||||
}
|
||||
// 非强制战斗
|
||||
// @ts-ignore
|
||||
// @ts-expect-error 2.c 重构
|
||||
if (!core.canBattle(x, y) && !force && !core.status.event.id) {
|
||||
core.stopSound();
|
||||
core.playSound('操作失败');
|
||||
@@ -116,7 +115,7 @@ export function patchBattle() {
|
||||
core.clearContinueAutomaticRoute();
|
||||
|
||||
// 自动存档
|
||||
var inAction = core.status.event.id == 'action';
|
||||
const inAction = core.status.event.id === 'action';
|
||||
if (inAction) {
|
||||
core.insertAction(beforeBattle, data.x, data.y);
|
||||
core.doAction();
|
||||
@@ -131,7 +130,7 @@ export function patchBattle() {
|
||||
|
||||
patch2.add('_action_battle', function (data, x, y, prefix) {
|
||||
if (data.id) {
|
||||
const enemy = getSingleEnemy(data.id as EnemyIds);
|
||||
// const enemy = getSingleEnemy(data.id as EnemyIds);
|
||||
// todo: 与不在地图上的怪物战斗
|
||||
} else {
|
||||
if (data.floorId != core.status.floorId) {
|
||||
@@ -256,7 +255,6 @@ export function patchBattle() {
|
||||
}
|
||||
);
|
||||
}
|
||||
loading.once('coreInit', patchBattle);
|
||||
|
||||
declare global {
|
||||
interface Enemys {
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
import { Patch, PatchClass } from '@motajs/legacy-common';
|
||||
import { EnemyCollection, ensureFloorDamage } from '@user/data-state';
|
||||
import { formatDamage } from '@user/data-utils';
|
||||
|
||||
export function patchDamage() {
|
||||
const patch = new Patch(PatchClass.Control);
|
||||
patch.add(
|
||||
'updateDamage',
|
||||
function (
|
||||
floorId = core.status.floorId,
|
||||
ctx,
|
||||
thumbnail: boolean = false
|
||||
) {
|
||||
if (!floorId || core.status.gameOver || main.mode !== 'play')
|
||||
return;
|
||||
const onMap = ctx == null;
|
||||
const floor = core.status.maps[floorId];
|
||||
|
||||
// 没有怪物手册
|
||||
// if (!core.hasItem('book')) return;
|
||||
core.status.damage.posX = core.bigmap.posX;
|
||||
core.status.damage.posY = core.bigmap.posY;
|
||||
if (!onMap) {
|
||||
const width = core.floors[floorId].width,
|
||||
height = core.floors[floorId].height;
|
||||
// 地图过大的缩略图不绘制显伤
|
||||
if (width * height > core.bigmap.threshold) return;
|
||||
}
|
||||
// 计算伤害
|
||||
ensureFloorDamage(floorId);
|
||||
|
||||
floor.enemy.extract();
|
||||
floor.enemy.calRealAttribute();
|
||||
floor.enemy.calMapDamage();
|
||||
floor.enemy.emit('calculated');
|
||||
core.status.damage.data = [];
|
||||
|
||||
// floor.enemy.render(true);
|
||||
|
||||
// getItemDetail(floorId, onMap); // 宝石血瓶详细信息
|
||||
if (thumbnail) {
|
||||
renderThumbnailDamage(floor.enemy);
|
||||
core.control.drawDamage(ctx, floorId);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function renderThumbnailDamage(col: EnemyCollection) {
|
||||
core.status.damage.data = [];
|
||||
core.status.damage.extraData = [];
|
||||
core.status.damage.dir = [];
|
||||
|
||||
// 怪物伤害
|
||||
col.list.forEach(v => {
|
||||
const { damage } = v.calDamage();
|
||||
|
||||
// 伤害全部相等,绘制在怪物本身所在位置
|
||||
const { damage: dam, color } = formatDamage(damage);
|
||||
const critical = v.calCritical(1)[0];
|
||||
core.status.damage.data.push({
|
||||
text: dam,
|
||||
px: 32 * v.x! + 1,
|
||||
py: 32 * (v.y! + 1) - 1,
|
||||
color: color
|
||||
});
|
||||
const setting = Mota.require('@motajs/legacy-ui').mainSetting;
|
||||
const criGem = setting.getValue('screen.criticalGem', false);
|
||||
const n = critical?.atkDelta ?? Infinity;
|
||||
const ratio = core.status.maps[col.floorId].ratio;
|
||||
const cri = criGem ? Math.ceil(n / ratio) : n;
|
||||
|
||||
core.status.damage.data.push({
|
||||
text: isFinite(cri) ? cri.toString() : '?',
|
||||
px: 32 * v.x! + 1,
|
||||
py: 32 * (v.y! + 1) - 11,
|
||||
color: '#fff'
|
||||
});
|
||||
});
|
||||
|
||||
// 地图伤害
|
||||
const floor = core.status.maps[col.floorId];
|
||||
const width = floor.width;
|
||||
const height = floor.height;
|
||||
const objs = core.getMapBlocksObj(col.floorId);
|
||||
|
||||
const startX = 0;
|
||||
const endX = width;
|
||||
const startY = 0;
|
||||
const endY = height;
|
||||
|
||||
for (let x = startX; x < endX; x++) {
|
||||
for (let y = startY; y < endY; y++) {
|
||||
const id = `${x},${y}` as LocString;
|
||||
const dam = col.mapDamage[id];
|
||||
if (!dam || objs[id]?.event.noPass) continue;
|
||||
|
||||
// 地图伤害
|
||||
if (dam.damage !== 0) {
|
||||
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 + 16,
|
||||
color,
|
||||
alpha: 1
|
||||
});
|
||||
}
|
||||
|
||||
// 电摇嘲讽
|
||||
if (dam.mockery) {
|
||||
dam.mockery.sort((a, b) =>
|
||||
a[0] === b[0] ? a[1] - b[1] : a[0] - b[0]
|
||||
);
|
||||
const [tx, ty] = dam.mockery[0];
|
||||
const dir = x > tx ? '←' : x < tx ? '→' : y > ty ? '↑' : '↓';
|
||||
core.status.damage.extraData.push({
|
||||
text: '嘲' + dir,
|
||||
px: 32 * x + 16,
|
||||
py: 32 * (y + 1) - 14,
|
||||
color: '#fd4',
|
||||
alpha: 1
|
||||
});
|
||||
}
|
||||
|
||||
// 追猎
|
||||
if (dam.hunt) {
|
||||
core.status.damage.extraData.push({
|
||||
text: '猎',
|
||||
px: 32 * x + 16,
|
||||
py: 32 * (y + 1) - 14,
|
||||
color: '#fd4',
|
||||
alpha: 1
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { patchBattle } from './battle';
|
||||
import { patchDamage } from './damage';
|
||||
|
||||
export function patchAll() {
|
||||
patchBattle();
|
||||
patchDamage();
|
||||
}
|
||||
Reference in new issue
Block a user