Skip to main content

changeActorState 改变角色状态

changeActorState

类型: MethodDeclaration

所属类: CommandFunctionList

定义位置: command.ts

描述

改变角色状态

参数

参数名类型描述默认值
\{ actor, operation, stateId, state, \}{
	actor: [`ActorGetter`](https://github.com/Open-Yami-Community/open-yami-doc/blob/main/i18n/zh/docusaurus-plugin-content-docs/current/script/yami/yami.command.d.ts#L152);
operation: "add" \| "remove" \| "remove-instance";
stateId?: string;
state?: [`StateGetter`](https://github.com/Open-Yami-Community/open-yami-doc/blob/main/i18n/zh/docusaurus-plugin-content-docs/current/script/yami/yami.command.d.ts#L211);
} | - | - |

返回值

类型: CommandFunction | null

源代码

位置: 第 6933 行

protected changeActorState({
actor,
operation,
stateId,
state,
}: {
actor: ActorGetter;
operation: "add" | "remove" | "remove-instance";
stateId?: string;
state?: StateGetter;
}): CommandFunction | null {
const getActor = Command.compileActor(actor);
switch (operation) {
case "add": {
const data = Data.states[stateId!];
return !data
? null
: () => {
const actor = getActor();
if (actor) {
const state = new State(data);
if (CurrentEvent.casterActor) {
state.caster = CurrentEvent.casterActor;
}
state.currentTime = 60000;
state.duration = 60000;
actor.state.add(state);
}
return true;
};
}
case "remove":
return () => {
getActor()?.state.delete(stateId!);
return true;
};
case "remove-instance": {
const getState = Command.compileState(state!);
return () => {
const state = getState();
if (state) {
getActor()?.state.remove(state);
}
return true;
};
}
}
}

文档生成时间:2026/2/1 16:51:39