MC_survival/map.d.ts

1403 lines
35 KiB
TypeScript
Raw Normal View History

2025-01-14 12:27:52 +08:00
type NotCopyPropertyInCompressedMap =
| 'firstArrive'
| 'eachArrive'
| 'blocks'
| 'parallelDo'
| 'map'
| 'bgmap'
| 'fgmap'
| 'events'
| 'changeFloor'
| 'beforeBattle'
| 'afterBattle'
| 'afterGetItem'
| 'afterOpenDoor'
| 'cannotMove'
| 'cannotMoveIn';
/**
*
*/
type CompressedMap<T extends FloorIds = FloorIds> = Omit<
Floor<T>,
NotCopyPropertyInCompressedMap
>;
interface Block<N extends Exclude<AllNumbers, 0> = Exclude<AllNumbers, 0>> {
/**
*
*/
x: number;
/**
*
*/
y: number;
/**
*
*/
id: N;
disable: boolean;
/**
*
*/
event: {
/**
*
*/
cls: ClsOf<NumberToId[N]>;
/**
* id
*/
id: NumberToId[N];
/**
*
*/
animate: FrameOf<ClsOf<NumberToId[N]>>;
/**
*
*/
noPass: boolean;
/**
*
*/
height: 32 | 48;
/**
*
*/
trigger?: MotaTrigger;
/**
*
*/
canBreak?: boolean;
/**
*
*/
doorInfo?: DoorInfo;
data?: any;
script?: string;
event?: MotaEvent;
};
}
interface FloorBase<T extends FloorIds = FloorIds> {
/**
* id
*/
floorId: T;
/**
*
*/
name: string;
/**
*
*/
ratio: number;
/**
*
*/
width: number;
/**
*
*/
height: number;
/**
*
*/
defaultGround: AllIds;
/**
*
*/
image: FloorAnimate[];
/**
*
*/
title: string;
/**
*
*/
canFlyFrom: boolean;
/**
*
*/
canFlyTo: boolean;
/**
* 使
*/
canUseQuickShop: boolean;
/**
*
*/
cannotViewMap?: boolean;
/**
*
*/
cannotMoveDirectly?: boolean;
/**
*
*/
underGround?: boolean;
/**
*
*/
autoEvent: Record<LocString, AutoEvent>;
/**
*
*/
weather?: [type: string, level: WeatherLevel];
/**
*
*/
map: number[][];
/**
*
*/
parallelDo?: string;
/**
*
*/
color?: Color;
/**
*
*/
bgm?: BgmIds | BgmIds[];
}
interface Floor<T extends FloorIds = FloorIds> extends FloorBase<T> {
/**
*
*/
blocks: Block[];
/**
*
*/
deleted?: boolean;
/**
*
*/
forceDelete?: boolean;
}
interface ResolvedFloor<T extends FloorIds = FloorIds> extends FloorBase<T> {
/**
*
*/
afterBattle: Record<LocString, MotaEvent>;
/**
*
*/
afterGetItem: Record<LocString, MotaAction>;
/**
*
*/
afterOpenDoor: Record<LocString, MotaEvent>;
/**
*
*/
beforeBattle: Record<LocString, MotaEvent>;
/**
*
*/
cannotMove: Record<LocString, Dir[]>;
/**
*
*/
cannotMoveIn: Record<LocString, Dir[]>;
/**
*
*/
events: Record<LocString, MotaEvent>;
/**
*
*/
bgmap: number[][];
/**
*
*/
fgmap: number[][];
/**
*
*/
changeFloor: Record<LocString, ChangeFloorEvent>;
/**
*
*/
firstArrive?: MotaEvent;
/**
*
*/
eachArrive?: MotaEvent;
}
interface BlockInfo<T extends keyof NumberToId = keyof NumberToId> {
/**
*
*/
number: T;
/**
* id
*/
id: NumberToId[T];
/**
*
*/
cls: ClsOf<NumberToId[T]>;
/**
*
*/
name: string;
/**
*
*/
image: HTMLImageElement;
/**
*
*/
posX: number;
/**
*
*/
posY: number;
/**
*
*/
doorInfo: DoorInfo;
/**
*
*/
height: 32 | 48;
/**
* faceId信息
*/
faceIds: Record<Dir, AllIds>;
/**
*
*/
animate: FrameOf<ClsOf<NumberToId[T]>>;
/**
*
*/
face: Dir;
/**
*
*/
bigImage: HTMLImageElement;
}
interface DrawMapConfig {
/**
*
*/
redraw: boolean;
/**
*
*/
ctx: CtxRefer;
/**
*
*/
onMap: boolean;
}
interface DrawThumbnailConfig {
/**
*
*/
heroLoc: LocArr;
/**
*
*/
heroIcon: ImageIds;
/**
*
*/
damage: boolean;
/**
* 使
*/
flags: Flags;
/**
*
*/
ctx: CtxRefer;
/**
*
*/
x: number;
/**
*
*/
y: number;
/**
* 1
*/
size: number;
/**
*
*/
all: boolean;
/**
*
*/
centerX: number;
/**
*
*/
centerY: number;
/**
* 使
*/
noHD: boolean;
/**
* 使v2优化
*/
v2: boolean;
/**
*
*/
inFlyMap: boolean;
/**
*
*/
w: number;
/**
*
*/
h: number;
}
interface BlockFilter {
/**
*
*/
blur: number;
/**
*
*/
hue: number;
/**
*
*/
grayscale: number;
/**
*
*/
invert: boolean;
/**
*
*/
shadow: boolean;
}
interface SearchedBlock {
/**
*
*/
x: number;
/**
*
*/
y: number;
/**
* id
*/
floorId: FloorIds;
/**
*
*/
block: Block;
}
/**
*
*/
interface Maps {
/**
*
*/
blocksInfo: {
[P in keyof NumberToId]: MapDataOf<P>;
};
/**
*
* @param floorId id
* @param map
*/
loadFloor<T extends FloorIds>(
floorId: T,
map?: number[][] | { map: number[][] }
): ResolvedFloor<T>;
/**
*
* @param map id或地图对象
*/
extractBlocks(map?: FloorIds | ResolvedFloor): void;
/**
* UI解析出blocks
* @param map
* @param flags
*/
extractBlocksForUI(map?: ResolvedFloor, flags?: Record<string, any>): void;
/**
* id得到数字
* @example core.getNumberById('yellowWall'); // 1
* @param id id
* @returns
*/
getNumberById<T extends AllIds>(id: T): IdToNumber[T];
/**
*
* @param number
*/
getBlockByNumber<T extends keyof NumberToId>(number: T): Block<T>;
/**
* ID获得图块
* @param id id
*/
getBlockById<T extends AllIds>(id: T): Block<IdToNumber[T]>;
/**
* ID
*/
getIdOfThis(id?: 'this' | AllIds): string;
/**
*
* @param x
* @param y
* @param id id
* @param addInfo
* @param eventFloor
*/
initBlock(
x: number,
y: number,
id: AllIds | AllNumbers,
addInfo?: boolean,
eventFloor?: ResolvedFloor
): Block;
/**
*
* @param mapArr
* @param floorId id
*/
compressMap(mapArr?: number[][], floorId?: FloorIds): number[][];
/**
*
* @param opacity
* @param x
* @param y
* @param floorId id
*/
setBlockOpacity(
opacity: number,
x: number,
y: number,
floorId?: FloorIds
): void;
/**
*
* @param filter
* @param x
* @param y
* @param floorId id
*/
setBlockFilter(
filter: string,
x: number,
y: number,
floorId?: FloorIds
): void;
/**
*
* @param floorId id
* @param x
* @param y
* @param flags
*/
isMapBlockDisabled(
floorId: FloorIds,
x: number,
y: number,
flags?: Record<string, any>
);
/**
* /
* @param floorId id
* @param x
* @param y
* @param disable
*/
setMapBlockDisabled(
floorId: FloorIds,
x: number,
y: number,
disable: boolean
);
/**
*
* @param mapArr
* @param floorId id
*/
decompressMap(mapArr?: number[][], floorId?: FloorIds): number[][];
/**
* 便
*/
saveMap(): { [P in FloorIds]?: Partial<CompressedMap<P>> };
/**
* 便
*/
saveMap(floorId: FloorIds): Partial<CompressedMap>;
/**
*
* @param data
* @param floorId
* @param flags
*/
loadMap<T extends FloorIds>(
data: { [P in T]: Partial<CompressedMap<P>> },
floorId?: undefined,
flags?: Record<string, any>
): { [P in T]: ResolvedFloor<T> };
/**
*
* @param data
* @param floorId
*/
loadMap<T extends FloorIds>(
data: { [P in T]?: Partial<CompressedMap<P>> },
floorId: T
): ResolvedFloor<T>;
/**
*
* @param floorId id
*/
resizeMap(floorId?: FloorIds): void;
/**
*
* @example core.getMapArray('MT0'); // 生成主塔0层的事件层矩阵隐藏的图块视为0
* @param floorId id
* @param noCache
* @returns 访[y][x]
*/
getMapArray(floorId?: FloorIds, noCache?: boolean): AllNumbers[][];
/**
*
* @param x
* @param y
* @param floorId id
* @param noCache
*/
getMapNumber(
x: number,
y: number,
floorId?: FloorIds,
noCache?: boolean
): AllNumbers;
/**
* x,y的形式返回每个点的事件
* @param floorId id
* @param noCache 使
*/
getMapBlocksObj(
floorId?: FloorIds,
noCache?: boolean
): Record<LocString, Block>;
/**
*
* @param floorId id
*/
getBgMapArray(floorId: FloorIds): AllNumbers[][];
/**
*
* @param floorId id
*/
getFgMapArray(floorId: FloorIds): AllNumbers[][];
/**
*
* @example core.getBgNumber(); // 判断主角脚下的背景层图块的数字
* @param x
* @param y
* @param floorId id
* @param noCache 使
*/
getBgNumber(
x?: number,
y?: number,
floorId?: FloorIds,
noCache?: boolean
): AllNumbers;
/**
*
* @example core.getFgNumber(); // 判断主角脚下的前景层图块的数字
* @param x
* @param y
* @param floorId id
* @param noCache 使
*/
getFgNumber(
x?: number,
y?: number,
floorId?: FloorIds,
noCache?: boolean
): AllNumbers;
/**
*
* @example core.generateMovableArray(); // 判断当前地图主角从各点能向何方向移动
* @param floorId id
* @returns
*/
generateMovableArray(floorId?: FloorIds): Dir[][][];
/**
* nopass
* @exmaple core.canMoveHero(); // 判断主角是否可以前进一步
* @param x
* @param y
* @param direction
* @param floorId id
* @returns true表示可移动false表示不可移动
*/
canMoveHero(
x?: number,
y?: number,
direction?: Dir,
floorId?: FloorIds
): boolean;
/**
*
* @example core.canMoveDirectly(0, 0); // 能否瞬移到地图左上角
* @param destX
* @param destY
* @returns -1
*/
canMoveDirectly(destX: number, destY: number): number;
/**
*
* @param locs
* @param canMoveArray
*/
canMoveDirectlyArray(locs: LocArr[], canMoveArray?: Dir[][][]): number[];
/**
*
* @example core.automaticRoute(0, 0); // 自动寻路到地图左上角
* @param destX
* @param destY
* @returns loc属性组成的一维数组
*/
automaticRoute(destX: number, destY: number): DiredLoc[];
/**
*
* @param block
* @param animate
* @param ctx
*/
drawBlock(block?: Block, animate?: number, ctx?: CtxRefer): void;
/**
* groundPattern
* @param floorId id
*/
generateGroundPattern(floorId?: FloorIds): void;
/**
*
* @example core.drawMap(); // 绘制当前地图
* @param floorId id
*/
drawMap(floorId?: FloorIds): void;
/**
*
*/
redrawMap(): void;
/**
*
* @example core.drawBg(); // 绘制当前地图的背景层
* @param floorId id
* @param config
*/
drawBg(floorId?: FloorIds, config?: Partial<DrawMapConfig>): void;
/**
*
* @example core.drawEvents(); // 绘制当前地图的事件层
* @param floorId id
* @param blocks
* @param config
*/
drawEvents(
floorId?: FloorIds,
blocks?: Block[],
config?: Partial<DrawMapConfig>
): void;
/**
*
* @example core.drawFg(); // 绘制当前地图的前景层
* @param floorId id
* @param config
*/
drawFg(floorId?: FloorIds, config?: Partial<DrawMapConfig>): void;
/**
*
* @example core.drawThumbnail(); // 绘制当前地图的缩略图
* @param floorId id
* @param blocks
* @param options flags用于存读档
*/
drawThumbnail(
floorId?: FloorIds,
blocks?: Block[],
options?: Partial<DrawThumbnailConfig>
): void;
/**
* cannotIn属性
* @example core.noPass(0, 0); // 判断地图左上角能否被踏入
* @param x
* @param y
* @param floorId id
*/
noPass(x: number, y: number, floorId?: FloorIds): boolean;
/**
* NPC
* @param x
* @param y
* @param floorId id
*/
npcExists(x: number, y: number, floorId?: FloorIds): boolean;
/**
*
* @param x
* @param y
* @param id id
* @param floorId id
*/
terrainExists(
x: number,
y: number,
id?: AllIdsOf<'terrains'>,
floorId?: FloorIds
): boolean;
/**
*
* @param x
* @param y
* @param floorId id
*/
stairExists(x: number, y: number, floorId?: FloorIds): boolean;
/**
*
*/
nearStair(): boolean;
/**
*
* @param x
* @param y
* @param id id
* @param floorId id
*/
enemyExists(
x: number,
y: number,
id?: AllIdsOf<'enemys' | 'enemy48'>,
floorId?: FloorIds
): boolean;
/**
* block
* @param x
* @param y
* @param floorId id
* @param showDisable
*/
getBlock(
x: number,
y: number,
floorId?: FloorIds,
showDisable?: boolean
): Block;
/**
* id
* @example
* // 一个简单的机关门事件,打败或炸掉这一对绿头怪和红头怪就开门
* if (
* core.getBlockId(x1, y1) !== 'greenSlime' &&
* core.getBlockId(x2, y2) !== 'redSlime'
* )
* core.openDoor(x3, y3);
* @param x
* @param y
* @param floorId id
* @param showDisable
* @returns idnull
*/
getBlockId(
x: number,
y: number,
floorId?: FloorIds,
showDisable?: boolean
): AllIds | null;
/**
*
* @param x
* @param y
* @param floorId id
* @param showDisable
*/
getBlockNumber(
x: number,
y: number,
floorId?: FloorIds,
showDisable?: boolean
): AllNumbers;
/**
*
* @example
* // 另一个简单的机关门事件,打败或炸掉这一对不同身高的敌人就开门
* if (core.getBlockCls(x1, y1) !== 'enemys' && core.getBlockCls(x2, y2) !== 'enemy48') core.openDoor(x3, y3);
* @param x
* @param y
* @param floorId id
* @param showDisable
*/
getBlockCls(
x: number,
y: number,
floorId?: FloorIds,
showDisable?: boolean
): Cls | null;
/**
*
* @param x
* @param y
* @param floorId id
* @param showDisable
*/
getBlockOpacity(
x: number,
y: number,
floorId?: FloorIds,
showDisable?: boolean
): number | null;
/**
*
* @param x
* @param y
* @param floorId id
* @param showDisable
*/
getBlockFilter(
x: number,
y: number,
floorId?: FloorIds,
showDisable?: boolean
): BlockFilter | null;
/**
*
* @param block id
*/
getBlockInfo<T extends keyof NumberToId>(
block?: Block<T> | NumberToId[T] | T
): BlockInfo<T>;
/**
* ,
* @example core.searchBlock('*Door'); // 搜索当前地图的所有门
* @param id id0
* @param floorId id
* @param showDisable true表示计入
*/
searchBlock(
id: string,
floorId?: FloorIds | FloorIds[],
showDisable?: boolean
): SearchedBlock[];
/**
*
* @example
* // 搜索当前地图的所有门
* core.searchBlockWithFilter(function (block) { return block.event.id.endsWith('Door'); });
* @param blockFilter block输入boolean值
* @param floorId id
* @param showDisable true表示计入
* @returns
*/
searchBlockWithFilter(
blockFilter: (block: Block) => boolean,
floorId?: FloorIds | FloorIds[],
showDisable?: boolean
): SearchedBlock[];
/**
* idid
* @param block
*/
getFaceDownId(block: Block | AllIds | AllNumbers): AllIds;
/**
* /
* @example core.showBlock(0, 0); // 显示地图左上角的图块
* @param x
* @param y
* @param floorId id
*/
showBlock(x: number, y: number, floorId?: FloorIds): void;
/**
*
* @example core.hideBlock(0, 0); // 隐藏地图左上角的图块
* @param x
* @param y
* @param floorId id
*/
hideBlock(x: number, y: number, floorId?: FloorIds): void;
/**
*
* @param index
* @param floorId id
*/
hideBlockByIndex(index: number, floorId?: FloorIds): void;
/**
* block
* @param indexes
* @param floorId id
*/
hideBlockByIndexes(indexes: number[], floorId?: FloorIds): void;
/**
*
* @example core.removeBlock(0, 0); // 尝试删除地图左上角的图块
* @param x
* @param y
* @param floorId id
* @returns
*/
removeBlock(x: number, y: number, floorId?: FloorIds): boolean;
/**
* block的索引
* @param index
* @param floorId id
*/
removeBlockByIndex(index: number, floorId?: FloorIds): void;
/**
* block
* @param indexes
* @param floorId id
*/
removeBlockByIndexes(indexes: number[], floorId?: FloorIds): void;
/**
* /
* @param name
* @param loc
* @param floorId id
* @param callback
*/
showBgFgMap(
name: 'bg' | 'bg2' | 'fg' | 'fg2',
loc: LocArr | LocArr[],
floorId?: FloorIds,
callback?: () => void
): void;
/**
* /
* @param name
* @param loc
* @param floorId id
* @param callback
*/
hideBgFgMap(
name: 'bg' | 'bg2' | 'fg' | 'fg2',
loc: LocArr | LocArr[],
floorId?: FloorIds,
callback?: () => void
): void;
/**
*
* @param loc
* @param floorId id
* @param callback
*/
showFloorImage(
loc?: LocArr | LocArr[],
floorId?: FloorIds,
callback?: () => void
): void;
/**
*
* @param loc
* @param floorId id
* @param callback
*/
hideFloorImage(
loc?: LocArr | LocArr[],
floorId?: FloorIds,
callback?: () => void
): void;
/**
*
* @example core.setBlock(1, 0, 0); // 把地图左上角变成黄墙
* @param number id
* @param x
* @param y
* @param floorId id
* @param noredraw
*/
setBlock(
number: AllIds | AllNumbers | `${AllNumbers}`,
x: number,
y: number,
floorId?: FloorIds,
noredraw?: boolean
): void;
/**
*
* @param number id
* @param x
* @param y
* @param floorId id
* @param time
* @param callback
*/
animateSetBlock(
number: AllIds | AllNumbers | `${AllNumbers}`,
x: number,
y: number,
floorId?: FloorIds,
time?: number,
callback?: () => void
): void;
/**
*
* @param number id
* @param locs
* @param floorId id
* @param time
* @param callback
*/
animateSetBlocks(
number: AllIds | AllNumbers | `${AllNumbers}`,
locs: LocArr | LocArr[],
floorId?: FloorIds,
time?: number,
callback?: () => void
): void;
/**
*
* @param direction
* @param x
* @param y
* @param floorId id
*/
turnBlock(
direction: HeroTurnDir,
x: number,
y: number,
floorId?: FloorIds
): void;
/**
*
* @example core.replaceBlock(21, 22, core.floorIds); // 把游戏中地上当前所有的黄钥匙都变成蓝钥匙
* @param fromNumber
* @param toNumber
* @param floorId id或其数组
*/
replaceBlock(
fromNumber: AllNumbers,
toNumber: AllNumbers,
floorId?: FloorIds | FloorIds[]
): void;
/**
*
* @example core.setBgFgBlock('bg', 167, 6, 6); // 把当前地图背景层的中心块改为滑冰
* @param name
* @param number id
* @param x
* @param y
* @param floorId id
*/
setBgFgBlock(
name: 'bg' | 'fg' | 'bg2' | 'fg2',
number: AllIds | AllNumbers | `${AllNumbers}`,
x: number,
y: number,
floorId?: FloorIds
): void;
/**
*
* @param floorId id或数组
*/
resetMap(floorId?: FloorIds | FloorIds[]): void;
/**
*
* @example core.moveBlock(0, 0, ['down']); // 令地图左上角的图块下移一格,用时半秒,再花半秒淡出
* @param x
* @param y
* @param steps
* @param time
* @param keep true表示不淡出
* @param callback
*/
moveBlock(
x: number,
y: number,
steps: Step[],
time?: number,
keep?: boolean,
callback?: () => void
): void;
/**
* V2.7
* @example core.jumpBlock(0, 0, 0, 0); // 令地图左上角的图块原地跳跃半秒,再花半秒淡出
* @param sx
* @param sy
* @param ex
* @param ey
* @param time
* @param keep true表示不淡出
* @param callback
*/
jumpBlock(
sx: number,
sy: number,
ex: number,
ey: number,
time?: number,
keep?: boolean,
callback?: () => void
): void;
/**
* /
* @param loc
* @param type
* @param time
* @param callback
*/
animateBlock(
loc: LocArr | LocArr[],
type: 'show' | 'hide' | 'remove' | number,
time: number,
callback?: () => void
): void;
/**
*
* @param block
*/
addGlobalAnimate(block?: Block): void;
/**
*
*/
removeGlobalAnimate(): void;
/**
*
* @param x
* @param y
*/
removeGlobalAnimate(x?: number, y?: number): void;
/**
* UI层的box动画
*/
drawBoxAnimate(): void;
/**
* 使使core.drawHeroAnimate(name, callback)
* @example core.drawAnimate('attack', core.nextX(), core.nextY(), false, core.vibrate); // 在主角面前一格播放普攻动画动画停止后视野左右抖动1秒
* @param name
* @param x
* @param y
* @param alignWindow
* @param callback
* @returns core.stopAnimate()
*/
drawAnimate(
name: AnimationIds | NameMapIn<AnimationIds>,
x: number,
y: number,
alignWindow?: boolean,
callback?: () => void
): number;
/**
*
* @param name
* @param callback
* @returns core.stopAnimate()
*/
drawHeroAnimate(
name: AnimationIds | NameMapIn<AnimationIds>,
callback?: () => void
): number;
/**
* id列表
* @param name
*/
getPlayingAnimates(name?: AnimationIds): number[];
/**
*
* @param id drawAnimate或drawHeroAnimate返回值
* @param doCallback
*/
stopAnimate(id?: number, doCallback?: boolean): void;
_makeAutotileEdges(): void;
_initDetachedBlock(
info: BlockInfo,
x: number,
y: number,
displayDamage: boolean
): {
headCanvas: string | null;
bodyCanvas: string;
damageCanvas: string | null;
};
_getBigImageInfo(bigImage: HTMLImageElement, face: Dir, posX: number): any;
}
declare const maps: new () => Maps;