mirror of
https://github.com/motajs/template.git
synced 2026-11-06 01:14:31 +08:00
feat: 完成数据端数据类型的构建
This commit is contained in:
1 parent
c0a58706d9
commit
d12790280a
30 files changed
+885
-52
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { isNil } from 'lodash-es';
|
||||
import { IEnemyRawData, IEnemyStore, ITileStore } from './types';
|
||||
import { logger } from '@motajs/common';
|
||||
|
||||
export class EnemyStore<THero> implements IEnemyStore<THero> {
|
||||
/** 以道具图块数字为键的原始道具定义表 */
|
||||
private readonly dataMap: Map<number, IEnemyRawData<THero>> = new Map();
|
||||
|
||||
constructor(readonly tileStore: ITileStore) {}
|
||||
|
||||
addEnemy(enemy: IEnemyRawData<THero>): void {
|
||||
if (this.dataMap.has(enemy.num)) {
|
||||
logger.warn(181, enemy.num.toString(), 'enemy');
|
||||
}
|
||||
this.dataMap.set(enemy.num, enemy);
|
||||
}
|
||||
|
||||
getEnemy(token: number | string): IEnemyRawData<THero> | null {
|
||||
const num = this.tileStore.num(token);
|
||||
if (isNil(num)) return null;
|
||||
return this.dataMap.get(num) ?? null;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,27 @@
|
||||
import { IItemRawData, IItemStore, ItemCategory } from './types';
|
||||
import { isNil } from 'lodash-es';
|
||||
import { IItemRawData, IItemStore, ItemCategory, ITileStore } from './types';
|
||||
import { logger } from '@motajs/common';
|
||||
|
||||
export class ItemStore<THero> implements IItemStore<THero> {
|
||||
/** 以道具图块数字为键的原始道具定义表 */
|
||||
private readonly dataMap: Map<number, IItemRawData<THero>> = new Map();
|
||||
|
||||
getData(num: number): IItemRawData<THero> | null {
|
||||
constructor(readonly tileStore: ITileStore) {}
|
||||
|
||||
addItem(data: IItemRawData<THero>): void {
|
||||
if (this.dataMap.has(data.num)) {
|
||||
logger.warn(181, data.num.toString(), 'item');
|
||||
}
|
||||
this.dataMap.set(data.num, data);
|
||||
}
|
||||
|
||||
getData(token: number | string): IItemRawData<THero> | null {
|
||||
const num = this.tileStore.num(token);
|
||||
if (isNil(num)) return null;
|
||||
return this.dataMap.get(num) ?? null;
|
||||
}
|
||||
|
||||
getCategory(num: number): ItemCategory {
|
||||
return this.dataMap.get(num)?.category ?? ItemCategory.Unknown;
|
||||
}
|
||||
|
||||
addItem(data: IItemRawData<THero>): void {
|
||||
this.dataMap.set(data.num, data);
|
||||
}
|
||||
}
|
||||
@@ -129,25 +129,27 @@ export const enum ItemCategory {
|
||||
Equipment
|
||||
}
|
||||
|
||||
export interface IItemEffect<THero> {
|
||||
export interface IItemEffect<THero, State = unknown> {
|
||||
/**
|
||||
* 道具使用事件内容对于 `Pick` 类型,会在拾取时触发;
|
||||
* 对于 `Constant` 和 `Consumable` 类型,会在使用时触发。
|
||||
*/
|
||||
readonly useEvent: unknown;
|
||||
readonly useEvent?: string;
|
||||
|
||||
/**
|
||||
* 道具使用效果,使用道具时调用。对于 `Pick` 类型,会在拾取时触发;
|
||||
* 对于 `Constant` 和 `Consumable` 类型,会在使用时触发。
|
||||
* @param item 当前道具数据
|
||||
* @param state 当前的数据端对象,即 `CoreState` 对象
|
||||
*/
|
||||
useEffect(item: IItemRawData<THero>): void;
|
||||
useEffect?(item: IItemRawData<THero>, state: State): void;
|
||||
|
||||
/**
|
||||
* 能否使用道具,仅对 `Constant` 和 `Consumable` 类型的道具生效
|
||||
* @param item 当前道具数据
|
||||
* @param state 当前的数据端对象,即 `CoreState` 对象
|
||||
*/
|
||||
canUse(item: IItemRawData<THero>): boolean;
|
||||
canUse?(item: IItemRawData<THero>, state: State): boolean;
|
||||
}
|
||||
|
||||
export interface IItemEquipData<THero> {
|
||||
@@ -156,9 +158,9 @@ export interface IItemEquipData<THero> {
|
||||
/** 动画 id */
|
||||
readonly animate: AnimationIds;
|
||||
/** 数值加成 */
|
||||
readonly value: Map<SelectKey<THero, number>, number>;
|
||||
readonly value: Record<SelectKey<THero, number>, number>;
|
||||
/** 百分比加成 */
|
||||
readonly percentage: Map<SelectKey<THero, number>, number>;
|
||||
readonly percentage: Record<SelectKey<THero, number>, number>;
|
||||
/** 穿上装备事件 */
|
||||
readonly loadEvent: unknown;
|
||||
/** 脱下装备事件 */
|
||||
@@ -168,8 +170,6 @@ export interface IItemEquipData<THero> {
|
||||
export interface IItemRawData<THero> {
|
||||
/** 道具在地图上的图块数字 */
|
||||
readonly num: number;
|
||||
/** 道具的字符串标识符 */
|
||||
readonly id: string;
|
||||
/** 道具分类 */
|
||||
readonly category: ItemCategory;
|
||||
/** 道具显示名称 */
|
||||
@@ -188,10 +188,10 @@ export interface IItemRawData<THero> {
|
||||
|
||||
export interface IItemStore<THero> {
|
||||
/**
|
||||
* 获取指定图块数字对应的道具原始数据
|
||||
* @param num 道具图块数字
|
||||
* 获取指定图块数字或图块 id 对应的道具原始数据
|
||||
* @param token 道具图块数字或图块 id
|
||||
*/
|
||||
getData(num: number): IItemRawData<THero> | null;
|
||||
getData(token: number | string): IItemRawData<THero> | null;
|
||||
|
||||
/**
|
||||
* 获取指定图块数字对应的道具分类
|
||||
@@ -307,3 +307,30 @@ export interface IGameEventStore {
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region enemy
|
||||
|
||||
export interface IEnemyRawData<T> {
|
||||
/** 怪物的图块数字 */
|
||||
readonly num: number;
|
||||
/** 怪物数据定义 */
|
||||
readonly attribute: Readonly<T>;
|
||||
/** 怪物拥有的特殊属性,键表示特殊属性数字,值表示特殊属性数值 */
|
||||
readonly special: Record<number, any>;
|
||||
}
|
||||
|
||||
export interface IEnemyStore<T> {
|
||||
/**
|
||||
* 添加怪物原始数据定义
|
||||
* @param enemy 怪物原始数据
|
||||
*/
|
||||
addEnemy(enemy: IEnemyRawData<T>): void;
|
||||
|
||||
/**
|
||||
* 根据图块数字或图块 id 获取怪物原始数据
|
||||
* @param token 怪物的图块数字或图块 id
|
||||
*/
|
||||
getEnemy(token: number | string): IEnemyRawData<T> | null;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
@@ -4,6 +4,8 @@ import { IGameEventStore, IItemStore, IMapStore, ITileStore } from './store';
|
||||
import { IReplaySystem } from './replay';
|
||||
|
||||
export interface IEnemyAttr {
|
||||
/** 怪物名称 */
|
||||
name: string;
|
||||
/** 怪物生命值 */
|
||||
hp: number;
|
||||
/** 怪物攻击力 */
|
||||
@@ -23,6 +25,8 @@ export interface IEnemyAttr {
|
||||
export interface IHeroAttr {
|
||||
/** 勇士名称 */
|
||||
name: string;
|
||||
/** 勇士等级 */
|
||||
level: number;
|
||||
/** 勇士生命值 */
|
||||
hp: number;
|
||||
/** 勇士生命值上限 */
|
||||
|
||||
Reference in new issue
Block a user