fix: 战斗报错

This commit is contained in:
unanmed 2025-06-17 18:20:21 +08:00
parent 1b18ce4268
commit b93e286c52
10 changed files with 143 additions and 49 deletions

View File

@ -3,6 +3,7 @@
"dependencies": {
"@motajs/legacy-common": "workspace:*",
"@user/data-state": "workspace:*",
"@user/data-base": "workspace:*"
"@user/data-base": "workspace:*",
"@user/data-utils": "workspace:*"
}
}
}

View File

@ -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 {

View File

@ -1,43 +1,49 @@
import { Patch, PatchClass } from '@motajs/legacy-common';
import { EnemyCollection, ensureFloorDamage } from '@user/data-state';
import { formatDamage } from '@user/data-utils';
export function init() {
core.control.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];
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;
// 没有怪物手册
// 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);
}
}
// 计算伤害
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);
this.drawDamage(ctx, floorId);
}
};
);
}
function renderThumbnailDamage(col: EnemyCollection) {

View File

@ -1,5 +1,7 @@
import { patchBattle } from './battle';
import { patchDamage } from './damage';
export function patchAll() {
patchBattle();
patchDamage();
}

View File

@ -1,5 +0,0 @@
import { init as initItemDetail } from './itemDetail';
initItemDetail();
export * from './itemDetail';

View File

@ -0,0 +1,3 @@
{
"name": "@user/types"
}

View File

@ -0,0 +1,85 @@
export interface IEnemyInfo {}
export interface IDamageInfo {}
export interface IDamageEnemy {
/** 原始怪物信息 */
readonly enemy: Enemy;
/** 该怪物所属的怪物列表 */
readonly collection: IEnemyCollection | null;
/** 怪物横坐标 */
readonly x: number | undefined;
/**
*
*/
getEnemyInfo(): IEnemyInfo;
/**
*
*/
getDamageInfo(): IDamageInfo;
}
export interface IMapDamage {
/** 伤害类型 */
readonly type: string;
/** 伤害值 */
readonly damage: number;
/** 伤害优先级 */
readonly priority: number;
}
export interface IMapDamageSummary {
/** 该点的总伤害 */
readonly totalDamage: number;
/** 该点的伤害信息 */
readonly damages: IMapDamage[];
}
export interface IEnemyCollection {
/** 怪物列表,索引为 x + width * y值表示该点对应的怪物 */
readonly list: Map<number, IDamageEnemy>;
/** 楼层 id */
readonly floorId: FloorIds;
/** 楼层宽度 */
readonly width: number;
/** 楼层高度 */
readonly height: number;
/** 地图伤害 */
readonly mapDamage: Map<number, IMapDamageSummary>;
/** 用于计算本怪物列表中怪物信息的勇士属性 */
readonly hero: HeroStatus;
/**
* null
* @param x
* @param y
*/
getEnemy(x: number, y: number): IDamageEnemy | null;
/**
* null
* @param x
* @param y
*/
getMapDamage(x: number, y: number): IMapDamageSummary | null;
/**
*
*/
refresh(): void;
/**
*
* @param status
*/
with(status: HeroStatus): IEnemyCollection;
}
export interface IDamageSystem {
readonly collections: Map<FloorIds, IEnemyCollection>;
}

View File

@ -0,0 +1 @@
export * from './enemy';

View File

@ -161,7 +161,7 @@ export class Logger {
const n = Math.floor(code / 50) + 1;
const n2 = code % 50;
const url = `${location.origin}/_docs/logger/warn/warn${n}.html#warn-code-${n2}`;
console.warn(`[WARNING Code ${code}] ${text}. See ${url}`);
console.warn(`[WARNING Code ${code}] ${text} See ${url}`);
}
}

View File

@ -118,9 +118,12 @@ export class Patch<T extends PatchClass> {
const set = this.patched[patchClass];
const obj = this.getPatchClass(patchClass);
for (const [key, func] of patch.patches) {
// console.log(key);
if (set.has(key)) {
logger.warn(49, patchName[patchClass], key);
}
set.add(key);
obj[key] = func;
}
this.patchList.delete(patch);