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/battle/bond/BondConfigParser.ts

25 lines
865 B

3 weeks ago
import type { ParsedBondGroup } from './BondTypes';
/** 解析 Skill.group:`partnerWeapon1Id,targetType,attrType,attrValue,...` */
export function parseSkillGroup(raw: string): ParsedBondGroup | null {
const trimmed = String(raw ?? '').trim();
if (!trimmed) return null;
const nums = trimmed.split(',').map(Number);
if (nums.length < 4 || !Number.isFinite(nums[0]) || !Number.isFinite(nums[1])) return null;
const attrs: Array<{ type: number; value: number }> = [];
for (let i = 2; i + 1 < nums.length; i += 2) {
const type = nums[i];
const value = nums[i + 1];
if (!Number.isFinite(type) || !Number.isFinite(value)) continue;
attrs.push({ type, value });
}
if (attrs.length === 0) return null;
return {
partnerWeapon1Id: nums[0],
targetType: nums[1],
attrs,
};
}