refactor: 录像系统指令

This commit is contained in:
AncTe committed 2026-09-13 16:38:19 +08:00
1 parent dd4e66a335
commit 46a38fa0c6
7 files changed
+47 -57

No files matched your search

+7 -4
View File
@@ -226,6 +226,9 @@ export class CoreState implements ICoreState {
);
this.eventSystem = eventSystem;
// 录像系统
this.replaySystem = new ReplaySystem();
//#endregion
//#region L3 初始化
@@ -259,8 +262,8 @@ export class CoreState implements ICoreState {
pathfinding.useMover(this.hero.location.mover);
this.pathfinding = pathfinding;
this.replaySystem = new ReplaySystem();
this.registerReplayCommand();
// 录像系统初始化注册
this.registerReplayCommands();
//#endregion
}
@@ -270,7 +273,7 @@ export class CoreState implements ICoreState {
/**
* 注册全部录像指令
*/
private registerReplayCommand() {
private registerReplayCommands() {
this.replaySystem.registerCommand(
ReplayCommandCode.Up,
new ReplayMoveCommand(this, FaceDirection.Up)
@@ -288,7 +291,7 @@ export class CoreState implements ICoreState {
new ReplayMoveCommand(this, FaceDirection.Left)
);
this.replaySystem.registerCommand(
ReplayCommandCode.AutoPathfindToPoint,
ReplayCommandCode.Teleport,
new ReplayTeleportCommand(this)
);
this.replaySystem.registerCommand(
@@ -54,7 +54,7 @@ describe('replay commands', () => {
ReplayCommandCode.Right,
ReplayCommandCode.Down,
ReplayCommandCode.Left,
ReplayCommandCode.AutoPathfindToPoint,
ReplayCommandCode.Teleport,
ReplayCommandCode.UseItem,
ReplayCommandCode.Equip,
ReplayCommandCode.Unequip
@@ -155,7 +155,7 @@ describe('replay commands', () => {
let result: boolean | undefined;
const pending = command
.execute(step(ReplayCommandCode.AutoPathfindToPoint, [2, 3]))
.execute(step(ReplayCommandCode.Teleport, [2, 3]))
.then(value => {
result = value;
});
@@ -169,7 +169,7 @@ describe('replay commands', () => {
const error = vi.spyOn(logger, 'error');
teleport.mockReturnValueOnce(null);
await expect(
command.execute(step(ReplayCommandCode.AutoPathfindToPoint, [4, 5]))
command.execute(step(ReplayCommandCode.Teleport, [4, 5]))
).resolves.toBe(false);
expect(error).toHaveBeenCalledWith(2005, '4', '5');
error.mockRestore();
@@ -327,10 +327,8 @@ describe('replay commands', () => {
const unequip = new ReplayUnequipCommand(state);
const invalid = [
move.execute(step(ReplayCommandCode.Up, [1])),
teleport.execute(
step(ReplayCommandCode.AutoPathfindToPoint, ['x', 1])
),
teleport.execute(step(ReplayCommandCode.AutoPathfindToPoint, [1])),
teleport.execute(step(ReplayCommandCode.Teleport, ['x', 1])),
teleport.execute(step(ReplayCommandCode.Teleport, [1])),
useItem.execute(step(ReplayCommandCode.UseItem, [])),
useItem.execute(step(ReplayCommandCode.UseItem, ['id'])),
equip.execute(step(ReplayCommandCode.Equip, [1, 0])),
@@ -4,7 +4,6 @@ import {
IReplayCommand,
ReplayParamValue
} from '@user/data-common';
import { EquipStatus } from '@user/data-base';
import { IStateSystem } from '@user/data-system';
import { logger } from '@motajs/common';
@@ -178,16 +177,9 @@ export class ReplayEquipCommand
boolean
];
const equipment = this.state.hero.equip;
if (equipment.getEquipped(slot) === uid) {
return true;
}
if (equipment.canEquipTo(uid, slot) === EquipStatus.CannotEquip) {
logger.error(2007, uid.toString(), slot.toString());
return false;
}
equipment.equip(uid, slot, autoUnload);
if (equipment.getEquipped(slot) !== uid) {
logger.error(2008, uid.toString(), slot.toString());
logger.error(2007, uid.toString(), slot.toString());
return false;
}
return true;
@@ -209,13 +201,9 @@ export class ReplayUnequipCommand
// Parameter: [int8 slot]
const slot = step.params[0] as number;
const equipment = this.state.hero.equip;
if (equipment.getEquipped(slot) === undefined) {
logger.error(2009, slot.toString());
return false;
}
equipment.unequip(slot);
if (equipment.getEquipped(slot) !== undefined) {
logger.error(2010, slot.toString());
if (equipment.getEquipped(slot) !== void 0) {
logger.error(2008, slot.toString());
return false;
}
return true;
+2 -2
View File
@@ -9,7 +9,7 @@ export const enum ReplayCommandCode {
/** 向左移动一步 */
Left = 3,
/** 自动寻路至目标点 */
AutoPathfindToPoint = 4,
Teleport = 4,
/** 使用道具 */
UseItem = 5,
/** 装备物品 */
@@ -24,7 +24,7 @@ export const REPLAY_COMMAND_ORDER: readonly ReplayCommandCode[] = [
ReplayCommandCode.Right,
ReplayCommandCode.Down,
ReplayCommandCode.Left,
ReplayCommandCode.AutoPathfindToPoint,
ReplayCommandCode.Teleport,
ReplayCommandCode.UseItem,
ReplayCommandCode.Equip,
ReplayCommandCode.Unequip