You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdLike2048/assets/mx/module/merge/rules/MapPlaceRules.ts

102 lines
3.3 KiB

3 weeks ago
import { MapCellKind, PlaceRejectReason, TileSource, Weapon2TileType, type MapTileRecord } from '../types/MergeTypes';
/** 根据 Weapon2.type 判断能否落到该格(type1/2 只认可放置且尚无字块) */
export function canDropWeapon2OnCell(
weapon2Type: Weapon2TileType,
cellKind: MapCellKind,
hasTile: boolean,
canPutGrid = false,
): boolean {
if (hasTile) return false;
// 配表 type 可能是字符串,统一成数字再比
switch (Number(weapon2Type)) {
case Weapon2TileType.Single:
case Weapon2TileType.Combo:
return cellKind === MapCellKind.Put;
case Weapon2TileType.Grid:
return cellKind === MapCellKind.Walkable && canPutGrid;
case Weapon2TileType.Shovel:
return cellKind === MapCellKind.Dig;
default:
return false;
}
}
/** type3 落子后:不可通行 + 可放置(由 MapGrid 自行刷新背景) */
export function cellKindAfterType3Place(): MapCellKind {
return MapCellKind.Put;
}
/** type4 落子后的格语义 */
export function cellKindAfterType4Place(): MapCellKind {
return MapCellKind.Put;
}
/** 拖回背包后 type1/2 原格恢复为空的可放置格 */
export function cellKindAfterReturnToBag(): MapCellKind {
return MapCellKind.Put;
}
/** type3 拖起/撤销后恢复可行走 */
export function cellKindAfterType3Pickup(): MapCellKind {
return MapCellKind.Walkable;
}
/** 备战阶段该字块是否可再拖 */
export function canDragMapTile(
tile: MapTileRecord,
weapon2Type: Weapon2TileType,
isBuiltinPutWithoutTile: boolean,
): boolean {
switch (Number(weapon2Type)) {
case Weapon2TileType.Single:
case Weapon2TileType.Combo:
return true;
case Weapon2TileType.Grid:
return tile.source === TileSource.PrepPlaced && !isBuiltinPutWithoutTile;
case Weapon2TileType.Shovel:
return false;
default:
return false;
}
}
/** type3 落子后可再拖动的时长(毫秒) */
export const PREP_TYPE3_MOVE_WINDOW_MS = 5000;
/** 备战 type3 扩展格(无字块节点)是否可拖起(落子后限时) */
export function canDragPrepType3Cell(
isPrepType3: boolean,
hasTile: boolean,
placedAtMs: number | null = null,
nowMs: number = Date.now(),
): boolean {
if (!isPrepType3 || hasTile || placedAtMs == null) return false;
return nowMs - placedAtMs < PREP_TYPE3_MOVE_WINDOW_MS;
}
export function rejectReasonToMessage(reason: PlaceRejectReason): string {
switch (reason) {
case PlaceRejectReason.PathBlocked:
return '不能将路径堵死';
case PlaceRejectReason.WrongCellKind:
return '不能放在这里';
case PlaceRejectReason.CellOccupied:
return '格子已被占用';
case PlaceRejectReason.NotDraggable:
return '该格子不可移动';
case PlaceRejectReason.InvalidMerge:
return '无法升级';
case PlaceRejectReason.MaxLevel:
return '已达最高等级';
case PlaceRejectReason.BagFull:
return '背包已满';
case PlaceRejectReason.SpiderWebBlocked:
return '此处不能放置!';
case PlaceRejectReason.WrongCampArea:
return '只能放在己方区域';
default:
return '';
}
}