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/script/manager/BattleBuffParse.ts

111 lines
4.2 KiB

3 weeks ago
import {
DailyShopKind,
DailyShopParsed,
DailyShopPassiveType,
} from './DailyShopTypes';
import { BattleBuffSlotType, BattleBuffFunctionType, passiveBuffUsesBattleGameCd } from './battleBuff/BattleBuffTypes';
import { parseBattleBuffVigourDelta, parseFunctionParNums } from './battleBuff/BattleBuffParamParse';
/**
* 解析 Battlebuff 行 → 每日商店通用视图(抽奖 / 携带槽)
* 入槽分类依据配表 type:1 主动 / 2 被动 / 3 自动(不入槽,抽中即生效)。
* @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.log('[BattleBuff] 缺少 functiontype', id);
return null;
}
const slotType = Math.floor(Number(row.type) || 0);
if (
slotType !== BattleBuffSlotType.Active
&& slotType !== BattleBuffSlotType.Passive
&& slotType !== BattleBuffSlotType.Auto
) {
console.log('[BattleBuff] 无效 type', id, row.type);
return null;
}
let kind: DailyShopKind;
if (slotType === BattleBuffSlotType.Active) {
kind = DailyShopKind.Active;
} else if (slotType === BattleBuffSlotType.Passive) {
kind = DailyShopKind.Passive;
} else {
// Auto:不入槽,kind 仅占位(购买/抽奖走即时分支)
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.log('[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.log('[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 = Math.floor(Number(row.type) || 0);
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 Math.floor(Number(row.type) || 0) === BattleBuffSlotType.Auto;
}
/** 配表 type → 槽位类型 */
export function battleBuffSlotType(row: ITableBattlebuff | null | undefined): BattleBuffSlotType | null {
if (!row) return null;
const slotType = Math.floor(Number(row.type) || 0);
if (slotType === BattleBuffSlotType.Active) return BattleBuffSlotType.Active;
if (slotType === BattleBuffSlotType.Passive) return BattleBuffSlotType.Passive;
if (slotType === BattleBuffSlotType.Auto) return BattleBuffSlotType.Auto;
return null;
}