mirror of
https://github.com/motajs/template.git
synced 2026-11-12 14:04:31 +08:00
feat: 特殊光环描述
This commit is contained in:
1 parent
a2dd4ace72
commit
77a8adc05d
11 files changed
+110
-53
No files matched your search
@@ -13,10 +13,8 @@ import { isNil } from 'lodash-es';
|
||||
|
||||
export class EnemyManager<TEnemy> implements IEnemyManager<TEnemy> {
|
||||
/** 特殊属性注册表,code -> 创建函数 */
|
||||
private readonly specialRegistry: Map<
|
||||
number,
|
||||
SpecialCreation<any, TEnemy>
|
||||
> = new Map();
|
||||
private readonly specialRegistry: Map<number, SpecialCreation<any>> =
|
||||
new Map();
|
||||
/** 怪物模板表,code -> IEnemy */
|
||||
private readonly prefabByCode: Map<number, IEnemy<TEnemy>> = new Map();
|
||||
/** 复用映射,reusedCode -> sourceCode */
|
||||
@@ -32,10 +30,14 @@ export class EnemyManager<TEnemy> implements IEnemyManager<TEnemy> {
|
||||
|
||||
constructor(private readonly tileStore: ITileStore) {}
|
||||
|
||||
registerSpecial(code: number, cons: SpecialCreation<any, TEnemy>): void {
|
||||
registerSpecial(code: number, cons: SpecialCreation<any>): void {
|
||||
this.specialRegistry.set(code, cons);
|
||||
}
|
||||
|
||||
getSpecial(code: number): SpecialCreation<any> | null {
|
||||
return this.specialRegistry.get(code) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据怪物的图块数字或 id 获取其模板
|
||||
* @param token 怪物的图块数字或 id
|
||||
|
||||
@@ -133,18 +133,18 @@ export class NonePropertySpecial implements ISpecial<void> {
|
||||
}
|
||||
}
|
||||
|
||||
export function defineCommonSerializableSpecial<T, TAttr = any>(
|
||||
export function defineCommonSerializableSpecial<T>(
|
||||
code: number,
|
||||
value: T,
|
||||
config: ICommonSpecialConfig<T>
|
||||
): SpecialCreation<T, TAttr> {
|
||||
): SpecialCreation<T> {
|
||||
return () =>
|
||||
new CommonSerializableSpecial(code, structuredClone(value), config);
|
||||
}
|
||||
|
||||
export function defineNonePropertySpecial<TAttr = any>(
|
||||
export function defineNonePropertySpecial(
|
||||
code: number,
|
||||
config: ICommonSpecialConfig<void>
|
||||
): SpecialCreation<void, TAttr> {
|
||||
): SpecialCreation<void> {
|
||||
return () => new NonePropertySpecial(code, config);
|
||||
}
|
||||
@@ -161,7 +161,7 @@ export interface IEnemy<TAttr>
|
||||
|
||||
//#region 怪物管理器
|
||||
|
||||
export type SpecialCreation<T, TAttr> = (enemy: IEnemy<TAttr>) => ISpecial<T>;
|
||||
export type SpecialCreation<T> = () => ISpecial<T>;
|
||||
|
||||
export interface IEnemyManager<TAttr> extends ISaveableContent<
|
||||
IEnemyManagerSaveState<TAttr>
|
||||
@@ -171,7 +171,13 @@ export interface IEnemyManager<TAttr> extends ISaveableContent<
|
||||
* @param code 特殊属性代码
|
||||
* @param cons 特殊属性创建函数
|
||||
*/
|
||||
registerSpecial(code: number, cons: SpecialCreation<any, TAttr>): void;
|
||||
registerSpecial(code: number, cons: SpecialCreation<any>): void;
|
||||
|
||||
/**
|
||||
* 获取一个特殊属性的注册函数
|
||||
* @param code 特殊属性代码
|
||||
*/
|
||||
getSpecial(code: number): SpecialCreation<any> | null;
|
||||
|
||||
/**
|
||||
* 创建怪物对象,如果对应数字的怪物不存在则会返回 `null`
|
||||
|
||||
Reference in new issue
Block a user