wip(event): scaffold EventSetBlock class, utils helpers, anon-tokyo workspace dep

- data-state: add @motajs/anon-tokyo workspace dependency
- map.ts: new EventSetBlock BuiltInFunction class (reference style)
- utils.ts: getPossibleMap/getPossibleLayer helpers (not yet wired)

Checkpoint of user-authored in-progress event refactor.
This commit is contained in:
unanmed 2026-09-13 19:04:25 +08:00
parent b86a060759
commit 5a05eecad1
3 changed files with 51 additions and 1 deletions

View File

@ -3,6 +3,7 @@
"dependencies": {
"@motajs/types": "workspace:*",
"@motajs/common": "workspace:*",
"@motajs/anon-tokyo": "workspace:*",
"@user/data-common": "workspace:*",
"@user/data-base": "workspace:*",
"@user/data-system": "workspace:*"

View File

@ -1,4 +1,4 @@
import { BuiltInFunction } from 'anon-tokyo';
import { BuiltInFunction } from '@motajs/anon-tokyo';
import { IBlockEventEnv } from '@user/data-system';
import {
EventBuiltinName,
@ -10,6 +10,28 @@ import { isNil } from 'lodash-es';
import { logger } from '@motajs/common';
import { appendMoveSteps, getPossibleLayer } from './hero';
export class EventSetBlock implements BuiltInFunction<
ISetBlockEventParam,
IBlockEventEnv
> {
name: string = 'setBlock';
func(param: ISetBlockEventParam, env: IBlockEventEnv) {
const layer = getPossibleLayer(env);
if (!layer) return;
if (!layer.inMap(param.x, param.y)) return;
const num = env.state.tileStore.num(param.tile);
if (isNil(num)) {
logger.warn(1001);
return;
}
layer.setBlock(num, param.x, param.y);
}
}
/**
* 在解析出的目标图层设置静态图块,目标或图块缺失时安全返回
*/

View File

@ -0,0 +1,27 @@
import { IGameMap, IMapLayer } from '@user/data-base';
import { IBlockEventEnv } from '@user/data-system';
/**
* 通过环境参量获取可能的地图对象
*/
export function getPossibleMap(env: IBlockEventEnv): IGameMap | null {
if (env.map) return env.map;
if (env.layer) return env.layer.map;
const map = env.state.maps.getMap(env.heroFloor);
if (map) return map;
return null;
}
/**
* 通过环境参量获取可能的事件图层
*/
export function getPossibleLayer(env: IBlockEventEnv): IMapLayer | null {
if (env.layer) return env.layer;
const map = getPossibleMap(env);
if (map?.eventLayer) return map.eventLayer;
return null;
}