import { DailyShopKind, DailyShopParsed, DailyShopPassiveType, } from './DailyShopTypes'; import { BattleBuffSlotType, BattleBuffFunctionType, passiveBuffUsesBattleGameCd } from './battleBuff/BattleBuffTypes'; import { parseBattleBuffVigourDelta, parseFunctionParNums } from './battleBuff/BattleBuffParamParse'; /** * 读取配表 type;缺省或非法时按被动处理(新表已无 type 列)。 * @param row 表行 */ function readSlotType(row: ITableBattlebuff): BattleBuffSlotType { const raw = (row as ITableBattlebuff & { type?: number }).type; const slotType = Math.floor(Number(raw) || 0); if ( slotType === BattleBuffSlotType.Active || slotType === BattleBuffSlotType.Passive || slotType === BattleBuffSlotType.Auto ) { return slotType; } return BattleBuffSlotType.Passive; } /** * 解析 Battlebuff 行 → 通用视图。 * @param row 表行 */ export function parseBattleBuffRow(row: ITableBattlebuff | null | undefined): DailyShopParsed | null { if (!row) return null; const id = Number(row.id) || 0; if (id <= 0) return null; const functiontype = Number(row.functiontype) || 0; if (functiontype <= 0) { console.warn('[BattleBuff] 缺少 functiontype', id); return null; } const slotType = readSlotType(row); let kind: DailyShopKind; if (slotType === BattleBuffSlotType.Active) { kind = DailyShopKind.Active; } else { kind = DailyShopKind.Passive; } const parsed: DailyShopParsed = { id, kind, name: String(row.name ?? ''), icon: String(row.icon ?? row.name ?? ''), quality: Number(row.quality) || 0, cost: Number(row.price) || 0, weight: Number(row.weight) || 0, cd: 0, isStrategy: false, row, }; if (slotType === BattleBuffSlotType.Active) { const nums = parseFunctionParNums(row.functionpar); if (nums.length < 1) { console.warn('[BattleBuff] 主动 buff functionpar 缺少 CD', id, row.functionpar); } else { parsed.cd = Math.max(0, nums[0] | 0); } } else if (slotType === BattleBuffSlotType.Passive && passiveBuffUsesBattleGameCd(functiontype)) { const nums = parseFunctionParNums(row.functionpar); if (nums.length < 1) { console.warn('[BattleBuff] 被动 buff functionpar 缺少 CD', id, row.functionpar); } else { parsed.cd = Math.max(0, nums[0] | 0); } } else if (slotType === BattleBuffSlotType.Auto && functiontype === BattleBuffFunctionType.Vigour) { const vigour = parseBattleBuffVigourDelta(row.functionpar); parsed.passive = { type: DailyShopPassiveType.MetaVigour, vigour }; } return parsed; } /** Battlebuff 行 → 商店 kind(主动/被动);type=3 自动返回 null */ export function battleBuffRowKind(row: ITableBattlebuff | null | undefined): DailyShopKind | null { if (!row) return null; const slotType = readSlotType(row); if (slotType === BattleBuffSlotType.Active) return DailyShopKind.Active; if (slotType === BattleBuffSlotType.Passive) return DailyShopKind.Passive; return null; } /** 是否为 Battlebuff 来源的解析结果 */ export function isBattleBuffParsed(parsed: DailyShopParsed | null | undefined): boolean { if (!parsed?.row) return false; const row = parsed.row as ITableBattlebuff; return row.icon != null && row.functiontype != null; } /** Battlebuff 是否抽中即生效(type=3 自动,不入携带槽) */ export function isBattleBuffInstant(row: ITableBattlebuff | null | undefined): boolean { if (!row) return false; return readSlotType(row) === BattleBuffSlotType.Auto; } /** 配表 type → 槽位类型 */ export function battleBuffSlotType(row: ITableBattlebuff | null | undefined): BattleBuffSlotType | null { if (!row) return null; return readSlotType(row); }