chore: 调整 AI 计划执行不按流程导致的代码问题

This commit is contained in:
unanmed 2026-10-05 17:15:35 +08:00
parent b28848e3e6
commit 59e190b468
5 changed files with 20 additions and 29 deletions

View File

@ -353,7 +353,7 @@ export class HeroEquipment<THero> implements IHeroEquipment<THero> {
});
// 由于装备修饰器不进存档,所以此时的勇士处于没有任何装备修饰器的状态,故可以安全清除
this.equips.clear();
// 读档期间的重新装备不应写入录像,故用禁用窗口包裹
const replay = this.state.replaySystem;
replay.disable();
for (const [index, uid] of state.equipped) {

View File

@ -53,7 +53,7 @@ export class HeroLocation
@shouldReplay('Setting hero floor should be replayed.')
setFloor(map: IGameMap | null): void {
this.floorId = map ? map.floorId : undefined;
this.floorId = map?.floorId ?? void 0;
this.map = map;
this.forEachHook(hook => hook.onSetFloor?.(map));
}

View File

@ -17,8 +17,9 @@ import { Hookable, HookController, ITileLocator, logger } from '@motajs/common';
import {
FaceDirection,
IDataCommon,
ILocationIndexer,
ILocationHelper,
IRoleFaceBinder,
MapLocIndexer,
SaveCompression,
shouldReplay
} from '@user/data-common';
@ -31,7 +32,7 @@ export class MapLayer
implements IResizableMapLayer
{
readonly state: IDataCommon;
readonly indexer: ILocationIndexer;
readonly indexer: ILocationHelper;
width: number;
height: number;
@ -77,7 +78,7 @@ export class MapLayer
expired: false,
array: this.mapArray
};
this.indexer = map.indexer as ILocationIndexer;
this.indexer = map.indexer;
}
protected createController(
@ -528,20 +529,16 @@ export class MapLayer
/**
* 裁剪超出新图层范围的点事件,并按新宽度重建索引
* @param oldWidth 变更前的图层宽度,用于解码旧索引
* @param width 新图层宽度
* @param height 新图层高度
*/
private cropPointEvents(
oldWidth: number,
width: number,
height: number
): void {
private cropPointEvents(oldWidth: number): void {
const oldIndex = new MapLocIndexer();
oldIndex.setWidth(oldWidth);
for (const [index, eventView] of [...this.pointEvents]) {
const x = index % oldWidth;
const y = Math.floor(index / oldWidth);
const { x, y } = oldIndex.locator(index);
this.pointEvents.delete(index);
if (x < width && y < height) {
this.pointEvents.set(y * width + x, eventView);
if (this.inMap(x, y)) {
const index = this.indexer.index(x, y);
this.pointEvents.set(index, eventView);
}
}
}
@ -561,7 +558,6 @@ export class MapLayer
const beforeArea = beforeWidth * beforeHeight;
this.width = width;
this.height = height;
this.indexer.setWidth(width);
const area = width * height;
const newArray = new Uint32Array(area);
this.mapArray = newArray;
@ -583,7 +579,7 @@ export class MapLayer
};
// 其他杂项清理
this.cropPointEvents(beforeWidth, width, height);
this.cropPointEvents(beforeWidth);
this.staticTileCache.clear();
this.forEachHook(hook => {
hook.onResize?.(width, height);
@ -605,7 +601,6 @@ export class MapLayer
this.mapData.expired = true;
this.width = width;
this.height = height;
this.indexer.setWidth(width);
this.mapArray = new Uint32Array(width * height);
this.mapData = {
expired: false,

View File

@ -40,9 +40,6 @@ export abstract class MapTileBase<TSave extends IMapBlockSaveBase>
abstract set(num: number): void;
/**
* 根据当前图块原始数据恢复默认事件并建立干净基准
*/
restoreDefaultEvents(): void {
const eventView = this.tileEvent();
eventView.clear();

View File

@ -295,13 +295,12 @@ export class ReplaySandbox
}
async step(): Promise<boolean> {
if (
this.playing &&
!this.appendingStep &&
!this.reader.expired &&
!this.ended
) {
this.appendingStep = this.reader.read();
if (!this.playing && !this.ended) {
if (!this.reader.expired && !this.appendingStep) {
this.playing = true;
this.pausing = true;
this.appendingStep = this.reader.read();
}
}
const res = await this.replayStep();
if (res.success) {