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/DailyShopParse.ts

152 lines
6.0 KiB

import {
DailyShopActiveEffect,
DailyShopActiveSkill,
DailyShopActiveType,
DailyShopGlobalAttr,
DailyShopKind,
DailyShopParsed,
DailyShopPassiveEffect,
DailyShopPassiveType,
isDailyShopGlobalAttr,
} from './DailyShopTypes';
function splitNums(raw: string | undefined | null): number[] {
if (!raw) return [];
return String(raw)
.split(',')
.map((s) => Number(String(s).trim()))
.filter((n) => Number.isFinite(n));
}
export function parseDailyShopPassive(functionStr: string): DailyShopPassiveEffect | null {
const nums = splitNums(functionStr);
if (nums.length < 1) return null;
const type = nums[0] | 0;
switch (type) {
case DailyShopPassiveType.FreeRevealAfterSec:
return { type: DailyShopPassiveType.FreeRevealAfterSec, sec: nums[1] ?? 0 };
case DailyShopPassiveType.BarrackLv2Chance:
return { type: DailyShopPassiveType.BarrackLv2Chance, chanceWan: nums[1] ?? 0 };
case DailyShopPassiveType.MeteorDamage:
// 3,X:X 为每个单位固定伤害点数,不是攻击倍率 / 万分比
return { type: DailyShopPassiveType.MeteorDamage, damage: nums[1] ?? 0 };
case DailyShopPassiveType.MetaVigour:
return { type: DailyShopPassiveType.MetaVigour, vigour: nums[1] ?? 0 };
case DailyShopPassiveType.DeathSplash:
return {
type: DailyShopPassiveType.DeathSplash,
radiusPx: nums[1] ?? 0, // 表像素 76=1格
atkPctWan: nums[2] ?? 0,
};
case DailyShopPassiveType.DeathGrain:
return { type: DailyShopPassiveType.DeathGrain, grain: nums[1] ?? 0 };
case DailyShopPassiveType.RangedRangePx:
return { type: DailyShopPassiveType.RangedRangePx, rangePx: nums[1] ?? 0 }; // 152=2格
case DailyShopPassiveType.HorseAdjacent:
return { type: DailyShopPassiveType.HorseAdjacent, atkWan: nums[1] ?? 0 };
case DailyShopPassiveType.HorseFrontCannonBack:
return {
type: DailyShopPassiveType.HorseFrontCannonBack,
horseAtkWan: nums[1] ?? 0,
cannonRangeTiles: nums[2] ?? 0,
};
case DailyShopPassiveType.RookAdjacent:
return { type: DailyShopPassiveType.RookAdjacent, sizeWan: nums[1] ?? 0 };
case DailyShopPassiveType.RookCannonLastRow:
return {
type: DailyShopPassiveType.RookCannonLastRow,
produceWanA: nums[1] ?? 0,
produceWanB: nums[2] ?? nums[1] ?? 0,
};
case DailyShopPassiveType.PawnAdjacent:
return { type: DailyShopPassiveType.PawnAdjacent, hpWan: nums[1] ?? 0 };
case DailyShopPassiveType.PawnFrontCannonBack:
return {
type: DailyShopPassiveType.PawnFrontCannonBack,
pawnHpWan: nums[1] ?? 0,
cannonAtkWan: nums[2] ?? 0,
};
case DailyShopPassiveType.GrainSurrounded:
return { type: DailyShopPassiveType.GrainSurrounded, produceWan: nums[1] ?? 0 };
default:
return null;
}
}
export function parseDailyShopActive(functionActive: string, _cd: number): DailyShopActiveEffect | null {
const nums = splitNums(functionActive);
if (nums.length < 1) return null;
const type = nums[0] | 0;
switch (type) {
case DailyShopActiveType.Fireball:
// 1,范围,伤害,击退:伤害为固定点数,不是攻击倍率
return {
type: DailyShopActiveType.Fireball,
range: nums[1] ?? 0,
damage: nums[2] ?? 0,
knockbackPx: nums[3] ?? 0,
};
case DailyShopActiveType.TeamAttrBuff: {
const attrRaw = nums[1] ?? 0;
if (!isDailyShopGlobalAttr(attrRaw)) {
console.log('[DailyShop] type2 属性码无效', attrRaw, functionActive);
return null;
}
return {
type: DailyShopActiveType.TeamAttrBuff,
attr: attrRaw,
valueWan: nums[2] ?? 0,
durationSec: nums[3] ?? 0,
};
}
case DailyShopActiveType.ProduceSpeed:
// 3,万分比,持续秒(第三段缺省则整局)
return {
type: DailyShopActiveType.ProduceSpeed,
produceWan: nums[1] ?? 0,
durationSec: nums[2] ?? 0,
};
case DailyShopActiveType.BarrackUpgradeWeight:
return {
type: DailyShopActiveType.BarrackUpgradeWeight,
successWeight: nums[1] ?? 0,
failWeight: nums[2] ?? 0,
};
case DailyShopActiveType.Mine:
// 5,触发范围,延迟秒,爆炸范围,爆炸伤害:伤害为固定点数
return {
type: DailyShopActiveType.Mine,
detectRange: nums[1] ?? 0,
delaySec: nums[2] ?? 0,
boomRange: nums[3] ?? 0,
boomDamage: nums[4] ?? 0,
};
case DailyShopActiveType.EnemyAttrDebuff: {
const attrRaw = nums[1] ?? 0;
if (!isDailyShopGlobalAttr(attrRaw)) {
console.log('[DailyShop] type6 属性码无效', attrRaw, functionActive);
return null;
}
return {
type: DailyShopActiveType.EnemyAttrDebuff,
attr: attrRaw,
valueWan: nums[2] ?? 0,
durationSec: nums[3] ?? 0,
};
}
default:
return null;
}
}
/** 解析行 → 可施放主动视图(被动行返回 null) */
export function toDailyShopActiveSkill(parsed: DailyShopParsed | null | undefined): DailyShopActiveSkill | null {
if (!parsed?.active || parsed.kind !== DailyShopKind.Active) return null;
return {
id: parsed.id,
name: parsed.name,
quality: parsed.quality,
cd: Math.max(0, parsed.cd | 0),
effect: parsed.active,
};
}